From patchwork Fri Feb 2 08:04:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "He, Hongbo" X-Patchwork-Id: 10196345 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 0E25E603D7 for ; Fri, 2 Feb 2018 08:04:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DA7C828E0C for ; Fri, 2 Feb 2018 08:04:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CCE9728E14; Fri, 2 Feb 2018 08:04:24 +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=BAYES_00,DKIM_SIGNED, HTML_MESSAGE, 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 01A2D28E0C for ; Fri, 2 Feb 2018 08:04:24 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 073EE6EC1C; Fri, 2 Feb 2018 08:04:22 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM03-DM3-obe.outbound.protection.outlook.com (mail-dm3nam03on0046.outbound.protection.outlook.com [104.47.41.46]) by gabe.freedesktop.org (Postfix) with ESMTPS id C16F16E998 for ; Fri, 2 Feb 2018 08:04:19 +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=9h0SwMbT7zum34dTch39sUZTyyDLSzDdQx3b73ZJ+tU=; b=jM+BVgCR1fdnBkR08dSlb8bbcU5Rr2I5yfjYxhI0Dv6xD50Rh9lIjfOGT9PRErE//0nRDee5fVwTj2VYoPVQ2wY9jYV/p/ivLTsUWNe8Azlh+oCdSdLVofe7GPPIVmL9JZrmPDAUHnkTE8okl/nZOLzVxxMrfdZkCoYkYPmTVsQ= Received: from MWHPR1201MB0127.namprd12.prod.outlook.com (10.174.98.142) by MWHPR1201MB0110.namprd12.prod.outlook.com (10.174.98.137) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.444.14; Fri, 2 Feb 2018 08:04:17 +0000 Received: from MWHPR1201MB0127.namprd12.prod.outlook.com ([10.174.98.142]) by MWHPR1201MB0127.namprd12.prod.outlook.com ([10.174.98.142]) with mapi id 15.20.0444.021; Fri, 2 Feb 2018 08:04:17 +0000 From: "He, Roger" To: "Zhou, David(ChunMing)" , "dri-devel@lists.freedesktop.org" Subject: RE: [PATCH 1/5] drm/ttm: add max_swap_mem in ttm_mem_global Thread-Topic: [PATCH 1/5] drm/ttm: add max_swap_mem in ttm_mem_global Thread-Index: AQHTm/ac6yHy6WPfmkyxoql2gjz2uaOQuJYAgAAA/wCAAAa2UA== Date: Fri, 2 Feb 2018 08:04:17 +0000 Message-ID: References: <1517556145-23505-1-git-send-email-Hongbo.He@amd.com> <037a126e-b084-b5b9-7f7a-80006d84388d@amd.com> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [116.228.147.241] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; MWHPR1201MB0110; 7:1Yl0jhVWs6VAPUfwdJscZNEffAGTKwlfh0wl4/rkJGLMDk3OsuKlIXi065/JtXKLjt4U5v4GDG1n9z6fgavxjFKida5ay9DuL+9KGApE/qKElAoLFQkjiruKquvwaKhpkNHJRFkCZZbvAD+1lVl52Zo2LlY2K+x+2KKH30YngWUPFy6Vhryp11PUkoYel08P+LiX66YFjq1e7eM5tgBsuaXjGwJax55DNQhvqzq0bsITKMEZdDedjD3WaB3FbEhf; 20:zsgLjkyRSNHIkwDmMxntacORD0XdXU6NaGEZ7OkPQy4heq4OdLHV/n2gQYfq4yAJow7vcFdKAR7Y+1VXYsB+RtGeDo1p7XGv/Br7DMNsxkY0fQ4XRJUaSZhVUivwmL+LclToV430f15hGNDS7GqaZ9aa5D+vkzB21wBW0cxavd9uocjhxWAwt1pZ508xL40htA4cRf9osBnfoMKpu6ZqgYxT035DV1zLY6RkSdrSD70LthTyg0CLAcV/tlH1V8tP x-ms-exchange-antispam-srfa-diagnostics: SSOS;SSOR; x-forefront-antispam-report: SFV:SKI; SCL:-1; SFV:NSPM; SFS:(10009020)(346002)(376002)(39380400002)(366004)(39860400002)(396003)(189003)(199004)(105586002)(6506007)(53546011)(55016002)(5660300001)(2906002)(59450400001)(236005)(9686003)(53936002)(110136005)(4326008)(478600001)(2950100002)(33656002)(229853002)(77096007)(6306002)(54896002)(68736007)(26005)(316002)(72206003)(3660700001)(102836004)(8676002)(97736004)(8936002)(25786009)(74316002)(66066001)(2501003)(99286004)(6246003)(81166006)(81156014)(14454004)(2900100001)(575784001)(86362001)(7736002)(6116002)(790700001)(106356001)(6436002)(7696005)(76176011)(3280700002)(3846002); DIR:OUT; SFP:1101; SCL:1; SRVR:MWHPR1201MB0110; H:MWHPR1201MB0127.namprd12.prod.outlook.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: 251b355c-c9b3-43a2-3dde-08d56a138ea7 x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(2017052603307)(7153060)(7193020); SRVR:MWHPR1201MB0110; x-ms-traffictypediagnostic: MWHPR1201MB0110: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Hongbo.He@amd.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(767451399110)(217544274631240)(21748063052155); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(6040501)(2401047)(8121501046)(5005006)(3231101)(2400082)(944501161)(10201501046)(3002001)(93006095)(93001095)(6055026)(6041288)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123562045)(20161123558120)(6072148)(201708071742011); SRVR:MWHPR1201MB0110; BCL:0; PCL:0; RULEID:; SRVR:MWHPR1201MB0110; x-forefront-prvs: 05715BE7FD received-spf: None (protection.outlook.com: amd.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: 5b5BLL0/VmlsscxxiY7d6Vn9EpYBa/cBz29SQWSPUTkvA/pq0M9TXatKShBPKQMLTtqx/KWZ45c2A1m0LGbZNQ== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 251b355c-c9b3-43a2-3dde-08d56a138ea7 X-MS-Exchange-CrossTenant-originalarrivaltime: 02 Feb 2018 08:04:17.1947 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR1201MB0110 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: "Koenig, Christian" Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Need call si_swapinfo to fill those valules . void si_swapinfo(struct sysinfo *val) But that function is not exported as well. Thanks Roger(Hongbo.He) From: dri-devel [mailto:dri-devel-bounces@lists.freedesktop.org] On Behalf Of Chunming Zhou Sent: Friday, February 02, 2018 3:38 PM To: He, Roger ; dri-devel@lists.freedesktop.org Cc: Koenig, Christian Subject: Re: [PATCH 1/5] drm/ttm: add max_swap_mem in ttm_mem_global On 2018年02月02日 15:34, Chunming Zhou wrote: On 2018年02月02日 15:22, Roger He wrote: 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); Hi Roger, I just find si_meminfo can get total swap size, see struct sysinfo definition: struct sysinfo { __kernel_long_t uptime; /* Seconds since boot */ __kernel_ulong_t loads[3]; /* 1, 5, and 15 minute load averages */ __kernel_ulong_t totalram; /* Total usable main memory size */ __kernel_ulong_t freeram; /* Available memory size */ __kernel_ulong_t sharedram; /* Amount of shared memory */ __kernel_ulong_t bufferram; /* Memory used by buffers */ __kernel_ulong_t totalswap; /* Total swap space size */ __kernel_ulong_t freeswap; /* swap space still available */ __u16 procs; /* Number of current processes */ ... can sysinfo.totalswap be used for your change? Regards, David Zhou - 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; Seems using max() for exchange is more obvious, otherwise looks ok to me. Regards, David Zhou + 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;