From patchwork Fri Feb 2 07:22:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "He, Hongbo" X-Patchwork-Id: 10196325 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0DAAF603D7 for ; Fri, 2 Feb 2018 07:22:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6108E28D24 for ; Fri, 2 Feb 2018 07:22:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 503A328D26; Fri, 2 Feb 2018 07:22:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id F2C3628D24 for ; Fri, 2 Feb 2018 07:22:39 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 740AB6EFAB; Fri, 2 Feb 2018 07:22:37 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on0055.outbound.protection.outlook.com [104.47.36.55]) by gabe.freedesktop.org (Postfix) with ESMTPS id 96CBA6EFA9 for ; Fri, 2 Feb 2018 07:22:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=ieKcKcLKVTI4Vqh10Wlx2QFX2OFmmaK1r8y1B54sJwY=; b=rPJhrOnf89rSydzuxZJ6RZyGsK5i3b8bVr3PxXQtj9+tzzUD+YUcvGqUDGJF+iRyzXZF/DFx4Dyx6e0n8YnLx5K2olIHDcMdEm5N5Im5WfGOv8c1H6T9X9iY2gdf/YqpSeTN8b68mjp+nnhGFxBSH9LDWEKZnzOEYnrjJQQqtnM= Received: from MWHPR1201CA0013.namprd12.prod.outlook.com (10.174.253.23) by BN6PR1201MB0051.namprd12.prod.outlook.com (10.174.114.13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.464.11; Fri, 2 Feb 2018 07:22:33 +0000 Received: from DM3NAM03FT061.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e49::202) by MWHPR1201CA0013.outlook.office365.com (2603:10b6:301:4a::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.464.11 via Frontend Transport; Fri, 2 Feb 2018 07:22:33 +0000 Authentication-Results: spf=none (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; lists.freedesktop.org; dkim=none (message not signed) header.d=none;lists.freedesktop.org; dmarc=permerror action=none header.from=amd.com; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) Received: from SATLEXCHOV02.amd.com (165.204.84.17) by DM3NAM03FT061.mail.protection.outlook.com (10.152.83.123) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.20.464.13 via Frontend Transport; Fri, 2 Feb 2018 07:22:32 +0000 Received: from roger-build-server.amd.com (10.34.1.3) by SATLEXCHOV02.amd.com (10.181.40.72) with Microsoft SMTP Server id 14.3.361.1; Fri, 2 Feb 2018 01:22:31 -0600 From: Roger He To: Subject: [PATCH 1/5] drm/ttm: add max_swap_mem in ttm_mem_global Date: Fri, 2 Feb 2018 15:22:21 +0800 Message-ID: <1517556145-23505-1-git-send-email-Hongbo.He@amd.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:165.204.84.17; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(376002)(396003)(39380400002)(39860400002)(346002)(2980300002)(428003)(199004)(189003)(50466002)(53936002)(2351001)(106466001)(105586002)(7696005)(575784001)(86362001)(48376002)(51416003)(68736007)(47776003)(4326008)(16586007)(54906003)(2906002)(316002)(6666003)(8936002)(5660300001)(50226002)(81156014)(8676002)(81166006)(104016004)(305945005)(53416004)(356003)(72206003)(478600001)(336011)(186003)(77096007)(26005)(59450400001)(97736004)(36756003)(6916009); DIR:OUT; SFP:1101; SCL:1; SRVR:BN6PR1201MB0051; H:SATLEXCHOV02.amd.com; FPR:; SPF:None; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; DM3NAM03FT061; 1:9ELRIhvszxoGTZrnJR2WLEnIHgRS7NcK3WD7TUewrPSBHZkFrpTR+I0QiepUWWVSQw9tR8y9ZXbpIXnWQxSNzQiJyIKuQpV19i5koNB3x67yrH6xr5qcKSk5aUwLdfsz X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c34ae9f0-df47-4177-c329-08d56a0db9c8 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(4604075)(2017052603307)(7153060); SRVR:BN6PR1201MB0051; X-Microsoft-Exchange-Diagnostics: 1; BN6PR1201MB0051; 3:Go1izcd4rw3ImzIyF9A5BbNfhSbn1mB6hDK+KfA6MAiLc9+Rx0mkQxbb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bllEcDOop7L0Cge+acWZ3uVNcIrIj+CSuRuHFj1LO0WDoPZjpqluww8sdkuLrALDHqHTExNTu3rGJAvkKRNU3zTxfJW/9jbhoBLVYBXH4Hj3lYhT1HHD/qYcsFRXXTM9BvWBc3+SGuokyV1NMQ28JYi8L/QAOMkT51+upsJcYs98RL8J/hkunrwaVuVSKVUDnEiU0pQ8xriGUI6qFjsgcy32z556sot+xstNEmrsL7DVy6RoJklmhx336Fc/qFTi5nIXraq2qmKgYtfjLsfadPzMVoQ2okP2ygXpkSsbYCr4zySrhh1VDWWtPFKX1X6w/pI5vkqaldr8Os9UqAODS8JnfLOjdxH8ByiKGKJ6lDg8axCQc+U3Q3jdic/+LZ57XHayW8ns3rJQEaZR2JV4IZPk+fkgK3HvB+oazj6zm X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040501)(2401047)(5005006)(8121501046)(10201501046)(3002001)(3231101)(2400082)(944501161)(93006095)(93003095)(6055026)(6041288)(20161123558120)(20161123562045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(6072148)(201708071742011); SRVR:BN6PR1201MB0051; BCL:0; PCL:0; RULEID:; SRVR:BN6PR1201MB0051; X-Microsoft-Exchange-Diagnostics: 1; BN6PR1201MB0051; 4:HrZcIbRiJMkcLMPQzSIpSDOPWD27Xgk12ukIMmEFXPO8syRW6vZ3ms/LBHdo2Li814Ky/C1BrMFvMhMe1v8ilg+0ZEWnWTe8aJVh9apYhR600MXspD0FqreEfQI+PDbmL8q8kyo2kKDsHOZzEm53TK/V7n2yd6cQfZxxJRMt8xL8AKUqG7oWgX8YdKVO6QRodW86DqmtGhSyM1CVDzIrwc/7hsUJ12paqnNiXYqTnfN9e2tnqDfTvn1O9i0WyguLzJTwx76qMPkdy1nr6Jm1gdLNgKjgIVZT/K+3mw6JYrIQLkFBPkz1uGVVFpSp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OIUYrvtAzG6irax5zUMaZsfnlrnlYpPl+aFAWGJksM6iq10Ve3CwNV/169w3e5PMpN4Tpu3I7Xv3grwYIzReoHqTfrp3q4HlrAMrgjf3N9lOUduOSgTRLHUgWI0Ls678zbdgKASo4klV3EMbfcr2g+bFm7Qhf3/BaNCTerr/MKsOATEjmwQIdDGNef+jWQ3ZUheSemG962JTHZde1d7RnU3G0d7HU82fX+x2Ph4PNT7IxN+PZhG8JkZA SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BN6PR1201MB0051; 20:ERJf7VsqKyWU2hOzQOoXOfSD2L05cTwgRYqCxNz2ayDLpm8d1KySbLbLDVaBrQThZHBjwTRCZL7tkWMGYIB+bR0dM1zQiz+DIBXLNpTCSFhSh6PVlLg0ZskKdv71yTbuozOiqW9FSArl/3Qtk1dAFbxbtZwxZA5Q7rdWul0STUJ4r3btcIeMcs2ZPA0YLcAzqij3b6t2zyrCCmc7o8YjMPf6NkbxqEV5f3FkMJLMYvCGo8qsT9Wm3yG0GVJKOeSy X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Feb 2018 07:22:32.2948 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c34ae9f0-df47-4177-c329-08d56a0db9c8 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXCHOV02.amd.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR1201MB0051 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Roger He , Christian.Koenig@amd.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP set its initial value as 1/2 * free swap cache size when module initial. and adjust this value when allocate TTM memory Signed-off-by: Roger He --- drivers/gpu/drm/ttm/ttm_memory.c | 10 ++++++++-- include/drm/ttm/ttm_memory.h | 2 ++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c index aa0c381..b48931d 100644 --- a/drivers/gpu/drm/ttm/ttm_memory.c +++ b/drivers/gpu/drm/ttm/ttm_memory.c @@ -36,6 +36,7 @@ #include #include #include +#include #define TTM_MEMORY_ALLOC_RETRIES 4 @@ -372,9 +373,9 @@ int ttm_mem_global_init(struct ttm_mem_global *glob) kobject_put(&glob->kobj); return ret; } - + /* set it as 1/2 * swap free space we can get at that time */ + glob->max_swap_mem = get_nr_swap_pages() << (PAGE_SHIFT - 1); si_meminfo(&si); - ret = ttm_mem_init_kernel_zone(glob, &si); if (unlikely(ret != 0)) goto out_no_zone; @@ -473,12 +474,17 @@ static int ttm_mem_global_reserve(struct ttm_mem_global *glob, struct ttm_mem_zone *single_zone, uint64_t amount, bool reserve) { + uint64_t free_swap_mem = get_nr_swap_pages() << (PAGE_SHIFT - 1); uint64_t limit; int ret = -ENOMEM; unsigned int i; struct ttm_mem_zone *zone; spin_lock(&glob->lock); + /* adjust the max_swap_mem to cover the new inserted swap space */ + if (glob->max_swap_mem < free_swap_mem) + glob->max_swap_mem = free_swap_mem; + for (i = 0; i < glob->num_zones; ++i) { zone = glob->zones[i]; if (single_zone && zone != single_zone) diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h index 8936285..ad5a557 100644 --- a/include/drm/ttm/ttm_memory.h +++ b/include/drm/ttm/ttm_memory.h @@ -49,6 +49,7 @@ * @work: The workqueue callback for the shrink queue. * @lock: Lock to protect the @shrink - and the memory accounting members, * that is, essentially the whole structure with some exceptions. + * @max_swap_mem: upper limit of swap space TTM can use * @zones: Array of pointers to accounting zones. * @num_zones: Number of populated entries in the @zones array. * @zone_kernel: Pointer to the kernel zone. @@ -67,6 +68,7 @@ struct ttm_mem_global { struct workqueue_struct *swap_queue; struct work_struct work; spinlock_t lock; + uint64_t max_swap_mem; struct ttm_mem_zone *zones[TTM_MEM_MAX_ZONES]; unsigned int num_zones; struct ttm_mem_zone *zone_kernel;