From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5F932C83F1B for ; Mon, 14 Jul 2025 05:23:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0093E6B008A; Mon, 14 Jul 2025 01:23:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F22C86B0092; Mon, 14 Jul 2025 01:23:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E38FC6B008C; Mon, 14 Jul 2025 01:23:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id D23296B0089 for ; Mon, 14 Jul 2025 01:23:12 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 5EDF7140516 for ; Mon, 14 Jul 2025 05:23:11 +0000 (UTC) X-FDA: 83661726582.15.9662618 Received: from us-smtp-delivery-44.mimecast.com (us-smtp-delivery-44.mimecast.com [207.211.30.44]) by imf06.hostedemail.com (Postfix) with ESMTP id A5518180008 for ; Mon, 14 Jul 2025 05:23:09 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=none; spf=softfail (imf06.hostedemail.com: 207.211.30.44 is neither permitted nor denied by domain of airlied@gmail.com) smtp.mailfrom=airlied@gmail.com; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=gmail.com (policy=none) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1752470589; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=D0aqEj9OT70jPDSRdjFemFelI46QIvaA4Gno6WtFiJY=; b=njx8fVvj6xqW/R/KGe0FHNeiK1wlkUwkPsc4OdO59FtRZP+yFF219usIX6DD0TLbtGaea4 pWt2OEmU47WHXB3WC7Tc2/EKUYQLh+epeynqZzVTIb2B++07RSJnBL7sqQdYNIcz45xrf1 WKIjYXlgtq+CZpHHyeVMdQ0e3nSA5HI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1752470589; a=rsa-sha256; cv=none; b=xzRnwnPdrLbEqiQB14f/HJJsDeriyUr7VCOF/71WSBQ2hzsdi0kAXqxsNvU54BFrPgnM/w 7kwisBlh0QoH3JIGnFph1heT78rCrcL+tLKsoqcY5Xifu2ZcXZABjV+VW85Cz+oFy4oN18 iJ7Hyy8nEwvMdkp1v+TF4heKTbE6xCc= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=none; spf=softfail (imf06.hostedemail.com: 207.211.30.44 is neither permitted nor denied by domain of airlied@gmail.com) smtp.mailfrom=airlied@gmail.com; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=gmail.com (policy=none) Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-515--wpw2E8hOpuJnXfQbXXwpg-1; Mon, 14 Jul 2025 01:23:07 -0400 X-MC-Unique: -wpw2E8hOpuJnXfQbXXwpg-1 X-Mimecast-MFC-AGG-ID: -wpw2E8hOpuJnXfQbXXwpg_1752470586 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3A3F81801212; Mon, 14 Jul 2025 05:23:05 +0000 (UTC) Received: from dreadlord.redhat.com (unknown [10.67.32.31]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 076A81977000; Mon, 14 Jul 2025 05:22:57 +0000 (UTC) From: Dave Airlie To: dri-devel@lists.freedesktop.org, linux-mm@kvack.org, Johannes Weiner , Christian Koenig Cc: Dave Chinner , Kairui Song , Dave Airlie , Matthew Brost , Andrew Morton , Zi Yan , Shakeel Butt Subject: [PATCH 01/18] mm: add gpu active/reclaim per-node stat counters (v2) Date: Mon, 14 Jul 2025 15:18:16 +1000 Message-ID: <20250714052243.1149732-2-airlied@gmail.com> In-Reply-To: <20250714052243.1149732-1-airlied@gmail.com> References: <20250714052243.1149732-1-airlied@gmail.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: bKL0mkPobJh37xZeaX-4K1_2xbxlTJpn95NN7nkMHxY_1752470586 X-Mimecast-Originator: gmail.com Content-Transfer-Encoding: quoted-printable content-type: text/plain; charset=WINDOWS-1252; x-default=true X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: A5518180008 X-Stat-Signature: y69nnp6s8n7zgfasqzko5xxmw9sgo6eh X-Rspam-User: X-HE-Tag: 1752470589-697460 X-HE-Meta: U2FsdGVkX19LqQR250tKQ+Ne6iVu88ZNMc4WH1cyYeIU6bUBY+HNngW2t84Nqd1rKXP4TvI9WBQbyknGjgHw2SmDiWRzltuwEIxz/sSVOojIXGY8AocR3Pr4sLQ84yiS8/Nzj8ZnIoRCQHd8Wv6o7fk26x0eAT2I44ZgO4x1yR7D8ZHxUCM2yGmrHvjxKDZSeA1Qb1em2ROVD6SAqT2CzmETZs9bmzbd2wcJ2788IptFwd1pA5a0OB/P2qJ8607xSXJNDA/ldFFIwaAy2X88DvfJWGpX0hqc9Sz3gtWp9Zy3ryjPo5F8li2Oez26Kwmwg16kqXVND53a1vEdi89gh1fSKIVfmEuoAmM4Jrs7ITkGy+Prt3eT8NLZ5F1qEIcxPMrPB1mU+uHFPHLKulheGI8z3pG+WQ5iFYp/Xr4VmSyvAyO0hBYkQDcETYl/xZ+mt4fbNJBZcFY9y/0eHQVRIYtdovcGZhI5Tc18xk42bzHAb31UHqizNlRtSnEVOZTvJaOJy/tCnjinuI6DiuKgzLAoAZdLEU/RAowzYTi6b6rvj3M6VXDHwu0TsaA1fxkR+rO9zRehi4lO9ME3ZXQO+mGCD5yGxlQpRfQN4g+tR68XzxNeRfLC+I3d5pIXgOEa5jDvInPdThJWAPljmEc8f7MmUgPzUcQvyuCzQo+Si68Lp9UyK98iN9iJr1iEEyLPd9K/AbtN4M3z3cira/USBJZnKpqIt7jD1nso0rKsVJYvhYEEpmX7Ho/ldxhshSPcieoRRfHKwC6f3gRfr1u0i3rWM0iGB6xHJMUdDO5u1PS/2ZCTjb1TGCFTVJ/QGRrl66Fdhhja1PTOQPreaIlPc5w1xbrl+CsLx4aoKBOi7qcdBXh2eC6eghyp8KHqT6eliHDhBN8QQIgbkYhCy/Z2dBFldJy/UAKsVBgP1XvtvvdzyqLEPxD5ibmGMjfaD9IuUsQGlFXToQz1g+GpjZh ubQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Dave Airlie While discussing memcg intergration with gpu memory allocations, it was pointed out that there was no numa/system counters for GPU memory allocations. With more integrated memory GPU server systems turning up, and more requirements for memory tracking it seems we should start closing the gap. Add two counters to track GPU per-node system memory allocations. The first is currently allocated to GPU objects, and the second is for memory that is stored in GPU page pools that can be reclaimed, by the shrinker. Cc: Christian Koenig Cc: Matthew Brost Cc: Johannes Weiner Cc: linux-mm@kvack.org Cc: Andrew Morton Acked-by: Zi Yan Acked-by: Shakeel Butt Acked-by: Andrew Morton Signed-off-by: Dave Airlie --- v2: add more info to the documentation on this memory. I'd like to get acks to merge this via the drm tree, if possible, Dave. --- Documentation/filesystems/proc.rst | 8 ++++++++ drivers/base/node.c | 5 +++++ fs/proc/meminfo.c | 6 ++++++ include/linux/mmzone.h | 2 ++ mm/show_mem.c | 9 +++++++-- mm/vmstat.c | 2 ++ 6 files changed, 30 insertions(+), 2 deletions(-) diff --git a/Documentation/filesystems/proc.rst b/Documentation/filesystems= /proc.rst index 2a17865dfe39..4d9c65b303cc 100644 --- a/Documentation/filesystems/proc.rst +++ b/Documentation/filesystems/proc.rst @@ -1093,6 +1093,8 @@ Example output. You may not have all of these fields. CmaFree: 0 kB Unaccepted: 0 kB Balloon: 0 kB + GPUActive: 0 kB + GPUReclaim: 0 kB HugePages_Total: 0 HugePages_Free: 0 HugePages_Rsvd: 0 @@ -1271,6 +1273,12 @@ Unaccepted Memory that has not been accepted by the guest Balloon Memory returned to Host by VM Balloon Drivers +GPUActive + System memory allocated to active GPU objects +GPUReclaim + System memory stored in GPU pools for reuse. This memory is = not + counted in GPUActive. It is shrinker reclaimable memory kept= in a reuse + pool because it has non-standard page table attributes, like= WC or UC. HugePages_Total, HugePages_Free, HugePages_Rsvd, HugePages_Surp, Hugepages= ize, Hugetlb See Documentation/admin-guide/mm/hugetlbpage.rst. DirectMap4k, DirectMap2M, DirectMap1G diff --git a/drivers/base/node.c b/drivers/base/node.c index c19094481630..64406862314b 100644 --- a/drivers/base/node.c +++ b/drivers/base/node.c @@ -463,6 +463,8 @@ static ssize_t node_read_meminfo(struct device *dev, #ifdef CONFIG_UNACCEPTED_MEMORY =09=09=09 "Node %d Unaccepted: %8lu kB\n" #endif +=09=09=09 "Node %d GPUActive: %8lu kB\n" +=09=09=09 "Node %d GPUReclaim: %8lu kB\n" =09=09=09 , =09=09=09 nid, K(node_page_state(pgdat, NR_FILE_DIRTY)), =09=09=09 nid, K(node_page_state(pgdat, NR_WRITEBACK)), @@ -496,6 +498,9 @@ static ssize_t node_read_meminfo(struct device *dev, =09=09=09 , =09=09=09 nid, K(sum_zone_node_page_state(nid, NR_UNACCEPTED)) #endif +=09=09=09 , +=09=09=09 nid, K(node_page_state(pgdat, NR_GPU_ACTIVE)), +=09=09=09 nid, K(node_page_state(pgdat, NR_GPU_RECLAIM)) =09=09=09 ); =09len +=3D hugetlb_report_node_meminfo(buf, len, nid); =09return len; diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c index bc2bc60c36cc..334948744e55 100644 --- a/fs/proc/meminfo.c +++ b/fs/proc/meminfo.c @@ -164,6 +164,12 @@ static int meminfo_proc_show(struct seq_file *m, void = *v) =09show_val_kb(m, "Balloon: ", =09=09 global_node_page_state(NR_BALLOON_PAGES)); =20 +=09show_val_kb(m, "GPUActive: ", +=09=09 global_node_page_state(NR_GPU_ACTIVE)); + +=09show_val_kb(m, "GPUReclaim: ", +=09=09 global_node_page_state(NR_GPU_RECLAIM)); + =09hugetlb_report_meminfo(m); =20 =09arch_report_meminfo(m); diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index 283913d42d7b..81f3e368fd91 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -241,6 +241,8 @@ enum node_stat_item { =09NR_HUGETLB, #endif =09NR_BALLOON_PAGES, +=09NR_GPU_ACTIVE, /* Pages assigned to GPU objects */ +=09NR_GPU_RECLAIM, /* Pages in shrinkable GPU pools */ =09NR_VM_NODE_STAT_ITEMS }; =20 diff --git a/mm/show_mem.c b/mm/show_mem.c index 0cf8bf5d832d..072d33a50148 100644 --- a/mm/show_mem.c +++ b/mm/show_mem.c @@ -255,7 +255,9 @@ static void show_free_areas(unsigned int filter, nodema= sk_t *nodemask, int max_z =09=09=09" sec_pagetables:%lukB" =09=09=09" all_unreclaimable? %s" =09=09=09" Balloon:%lukB" -=09=09=09"\n", +=09=09 " gpu_active:%lukB" +=09=09 " gpu_reclaim:%lukB" +=09=09 "\n", =09=09=09pgdat->node_id, =09=09=09K(node_page_state(pgdat, NR_ACTIVE_ANON)), =09=09=09K(node_page_state(pgdat, NR_INACTIVE_ANON)), @@ -281,7 +283,10 @@ static void show_free_areas(unsigned int filter, nodem= ask_t *nodemask, int max_z =09=09=09K(node_page_state(pgdat, NR_PAGETABLE)), =09=09=09K(node_page_state(pgdat, NR_SECONDARY_PAGETABLE)), =09=09=09str_yes_no(pgdat->kswapd_failures >=3D MAX_RECLAIM_RETRIES), -=09=09=09K(node_page_state(pgdat, NR_BALLOON_PAGES))); +=09=09 K(node_page_state(pgdat, NR_BALLOON_PAGES)), +=09=09 K(node_page_state(pgdat, NR_GPU_ACTIVE)), +=09=09=09K(node_page_state(pgdat, NR_GPU_RECLAIM))); + =09} =20 =09for_each_populated_zone(zone) { diff --git a/mm/vmstat.c b/mm/vmstat.c index 429ae5339bfe..25a74cf29473 100644 --- a/mm/vmstat.c +++ b/mm/vmstat.c @@ -1281,6 +1281,8 @@ const char * const vmstat_text[] =3D { =09"nr_hugetlb", #endif =09"nr_balloon_pages", +=09"nr_gpu_active", +=09"nr_gpu_reclaim", =09/* system-wide enum vm_stat_item counters */ =09"nr_dirty_threshold", =09"nr_dirty_background_threshold", --=20 2.49.0