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 CD997C83000 for ; Mon, 30 Jun 2025 04:50:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 72D066B009E; Mon, 30 Jun 2025 00:50:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6DDF56B009F; Mon, 30 Jun 2025 00:50:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 61B066B00A0; Mon, 30 Jun 2025 00:50:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 4C6C86B009E for ; Mon, 30 Jun 2025 00:50:35 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 19CBEB931B for ; Mon, 30 Jun 2025 04:50:35 +0000 (UTC) X-FDA: 83610841230.01.256F308 Received: from us-smtp-delivery-44.mimecast.com (us-smtp-delivery-44.mimecast.com [205.139.111.44]) by imf07.hostedemail.com (Postfix) with ESMTP id 3D14940006 for ; Mon, 30 Jun 2025 04:50:33 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=none; spf=softfail (imf07.hostedemail.com: 205.139.111.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=1751259033; 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=H0f8WvqyFgUMrLh1STg/TNSb+shPLqDAHnkvi+DvGqypIZa7lJsIK+zlQ/zzQEEpk9sGzt wD1iRusVYUAwiLikOo/oo00fCLJFfikGFgbuWzecxpzKTZvV1pj88A1spdIccr+1OVAoiA h8jgsW4xSRR5h7MjROk7yK3rYmlPq0c= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=none; spf=softfail (imf07.hostedemail.com: 205.139.111.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1751259033; a=rsa-sha256; cv=none; b=aAQm0jx9xkxf1cAAf5p5Jzv/LgUwT4HuMTbHwAiqrPTT2/tZ9mmX1tjt73kl2weVdV1KI3 QqQxUzpg404Z8+CZfaxZm0kHpxsCi6D+kSPsXoON/y5jHo5A6UYVhYNjMU5u2in0eRlj9a Tz6Klx7/UlumCKguKfxnao9KcXtX5WA= Received: from mx-prod-mc-08.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-20-RHW0GtXQOkmRrDdfWYshhQ-1; Mon, 30 Jun 2025 00:50:29 -0400 X-MC-Unique: RHW0GtXQOkmRrDdfWYshhQ-1 X-Mimecast-MFC-AGG-ID: RHW0GtXQOkmRrDdfWYshhQ_1751259027 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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 29BCC180135B; Mon, 30 Jun 2025 04:50:27 +0000 (UTC) Received: from dreadlord.redhat.com (unknown [10.67.24.96]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id BEFA319560AB; Mon, 30 Jun 2025 04:50:18 +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/17] mm: add gpu active/reclaim per-node stat counters (v2) Date: Mon, 30 Jun 2025 14:49:20 +1000 Message-ID: <20250630045005.1337339-2-airlied@gmail.com> In-Reply-To: <20250630045005.1337339-1-airlied@gmail.com> References: <20250630045005.1337339-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: zHhaeQPBCTgX-vnR-yCTU5O_v2VHPjZgorKu1cf6lHk_1751259027 X-Mimecast-Originator: gmail.com Content-Transfer-Encoding: quoted-printable content-type: text/plain; charset=WINDOWS-1252; x-default=true X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 3D14940006 X-Stat-Signature: 3eg9hk39r9rh7f5gnqmx1ya9hang4id3 X-HE-Tag: 1751259033-594879 X-HE-Meta: U2FsdGVkX18jg99aVvJNa8w0zry5H3G6iVXMYlzUFWJqM6RooREPzstS66ve8h/uLCj7NdMjqzoCb+RuB3rxi9xaQP6fosB2GGclyjJMOSF8iVnHY50eTFTXsJ9QCVj/T+rWJJ3JLnqyy5BaskKcaRyU66iUeXY79pyMgy18DoSbLydheFwybReyJ6eUALsAkcyuDI/PKD2ZJgeJoeGWkcWam4G/jD+fw1SPX5Tctgoxw4k4RsJVNs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K8ANjrpisx9yog3ak2kXsdn2ql5P8aLc2e6pRPwxlcdNIkZ0wshZ4oXO/F/AyDOLKhMYYW4JHE5CoWuBU8i0e9gWlhej4/ctNH/yNorovg3PAzPweLma7x34SNNREhh8UrqcJz6rf4n/04vvBZvG+rgTl+et5MxfSv5wqZsJwqhXiGPdA0YnjVH3S59W8uKx6oTXZcHnUSugOqdAHFVZd6gk7dMOk5QporVZJv/zEeDeCFBBBaBFxVWcip+KkIb1cPCxoudFcFlcOaf9bm9L4xxVifQ7noHdgtYRLaJG/CnC7Bkc2g8dg0ulJnpt6dwsZwPfKi2DJvDCElT 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