Skip to content

Commit 2232ba9

Browse files
committed
mm: add gpu active/reclaim per-node stat counters (v2)
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 <christian.koenig@amd.com> Cc: Matthew Brost <matthew.brost@intel.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: linux-mm@kvack.org Cc: Andrew Morton <akpm@linux-foundation.org> Acked-by: Zi Yan <ziy@nvidia.com> Acked-by: Shakeel Butt <shakeel.butt@linux.dev> Acked-by: Andrew Morton <akpm@linux-foundation.org> Acked-by: Christian König <christian.koenig@amd.com> Signed-off-by: Dave Airlie <airlied@redhat.com>
1 parent 322e411 commit 2232ba9

6 files changed

Lines changed: 28 additions & 1 deletion

File tree

Documentation/filesystems/proc.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,6 +1089,8 @@ Example output. You may not have all of these fields.
10891089
CmaFree: 0 kB
10901090
Unaccepted: 0 kB
10911091
Balloon: 0 kB
1092+
GPUActive: 0 kB
1093+
GPUReclaim: 0 kB
10921094
HugePages_Total: 0
10931095
HugePages_Free: 0
10941096
HugePages_Rsvd: 0
@@ -1269,6 +1271,12 @@ Unaccepted
12691271
Memory that has not been accepted by the guest
12701272
Balloon
12711273
Memory returned to Host by VM Balloon Drivers
1274+
GPUActive
1275+
System memory allocated to active GPU objects
1276+
GPUReclaim
1277+
System memory stored in GPU pools for reuse. This memory is not
1278+
counted in GPUActive. It is shrinker reclaimable memory kept in a reuse
1279+
pool because it has non-standard page table attributes, like WC or UC.
12721280
HugePages_Total, HugePages_Free, HugePages_Rsvd, HugePages_Surp, Hugepagesize, Hugetlb
12731281
See Documentation/admin-guide/mm/hugetlbpage.rst.
12741282
DirectMap4k, DirectMap2M, DirectMap1G

drivers/base/node.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,8 @@ static ssize_t node_read_meminfo(struct device *dev,
523523
#ifdef CONFIG_UNACCEPTED_MEMORY
524524
"Node %d Unaccepted: %8lu kB\n"
525525
#endif
526+
"Node %d GPUActive: %8lu kB\n"
527+
"Node %d GPUReclaim: %8lu kB\n"
526528
,
527529
nid, K(node_page_state(pgdat, NR_FILE_DIRTY)),
528530
nid, K(node_page_state(pgdat, NR_WRITEBACK)),
@@ -556,6 +558,9 @@ static ssize_t node_read_meminfo(struct device *dev,
556558
,
557559
nid, K(sum_zone_node_page_state(nid, NR_UNACCEPTED))
558560
#endif
561+
,
562+
nid, K(node_page_state(pgdat, NR_GPU_ACTIVE)),
563+
nid, K(node_page_state(pgdat, NR_GPU_RECLAIM))
559564
);
560565
len += hugetlb_report_node_meminfo(buf, len, nid);
561566
return len;

fs/proc/meminfo.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,12 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
163163
show_val_kb(m, "Balloon: ",
164164
global_node_page_state(NR_BALLOON_PAGES));
165165

166+
show_val_kb(m, "GPUActive: ",
167+
global_node_page_state(NR_GPU_ACTIVE));
168+
169+
show_val_kb(m, "GPUReclaim: ",
170+
global_node_page_state(NR_GPU_RECLAIM));
171+
166172
hugetlb_report_meminfo(m);
167173

168174
arch_report_meminfo(m);

include/linux/mmzone.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,8 @@ enum node_stat_item {
260260
#endif
261261
NR_BALLOON_PAGES,
262262
NR_KERNEL_FILE_PAGES,
263+
NR_GPU_ACTIVE, /* Pages assigned to GPU objects */
264+
NR_GPU_RECLAIM, /* Pages in shrinkable GPU pools */
263265
NR_VM_NODE_STAT_ITEMS
264266
};
265267

mm/show_mem.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@ static void show_free_areas(unsigned int filter, nodemask_t *nodemask, int max_z
254254
" sec_pagetables:%lukB"
255255
" all_unreclaimable? %s"
256256
" Balloon:%lukB"
257+
" gpu_active:%lukB"
258+
" gpu_reclaim:%lukB"
257259
"\n",
258260
pgdat->node_id,
259261
K(node_page_state(pgdat, NR_ACTIVE_ANON)),
@@ -279,7 +281,9 @@ static void show_free_areas(unsigned int filter, nodemask_t *nodemask, int max_z
279281
K(node_page_state(pgdat, NR_PAGETABLE)),
280282
K(node_page_state(pgdat, NR_SECONDARY_PAGETABLE)),
281283
str_yes_no(kswapd_test_hopeless(pgdat)),
282-
K(node_page_state(pgdat, NR_BALLOON_PAGES)));
284+
K(node_page_state(pgdat, NR_BALLOON_PAGES)),
285+
K(node_page_state(pgdat, NR_GPU_ACTIVE)),
286+
K(node_page_state(pgdat, NR_GPU_RECLAIM)));
283287
}
284288

285289
for_each_populated_zone(zone) {

mm/vmstat.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,6 +1281,8 @@ const char * const vmstat_text[] = {
12811281
#endif
12821282
[I(NR_BALLOON_PAGES)] = "nr_balloon_pages",
12831283
[I(NR_KERNEL_FILE_PAGES)] = "nr_kernel_file_pages",
1284+
[I(NR_GPU_ACTIVE)] = "nr_gpu_active",
1285+
[I(NR_GPU_RECLAIM)] = "nr_gpu_reclaim",
12841286
#undef I
12851287

12861288
/* system-wide enum vm_stat_item counters */

0 commit comments

Comments
 (0)