Skip to content

Commit 673520f

Browse files
Qi Zhengakpm00
authored andcommitted
mm: memcontrol: add {pgscan,pgsteal}_{kswapd,direct} items in memory.stat of cgroup v2
There are already statistics of {pgscan,pgsteal}_kswapd and {pgscan,pgsteal}_direct of memcg event here, but now only the sum of the two is displayed in memory.stat of cgroup v2. In order to obtain more accurate information during monitoring and debugging, and to align with the display in /proc/vmstat, it better to display {pgscan,pgsteal}_kswapd and {pgscan,pgsteal}_direct separately. Also, for forward compatibility, we still display pgscan and pgsteal items so that it won't break existing applications. [[email protected]: add comment for memcg_vm_event_stat (suggested by Michal)] Link: https://lkml.kernel.org/r/[email protected] [[email protected]: fix the doc, thanks to Johannes] Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Qi Zheng <[email protected]> Acked-by: Johannes Weiner <[email protected]> Acked-by: Roman Gushchin <[email protected]> Acked-by: Muchun Song <[email protected]> Acked-by: Shakeel Butt <[email protected]> Acked-by: Michal Hocko <[email protected]> Cc: Muchun Song <[email protected]> Cc: Jonathan Corbet <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 153090f commit 673520f

File tree

2 files changed

+45
-34
lines changed

2 files changed

+45
-34
lines changed

Documentation/admin-guide/cgroup-v2.rst

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,6 +1433,24 @@ PAGE_SIZE multiple when read back.
14331433
workingset_nodereclaim
14341434
Number of times a shadow node has been reclaimed
14351435

1436+
pgscan (npn)
1437+
Amount of scanned pages (in an inactive LRU list)
1438+
1439+
pgsteal (npn)
1440+
Amount of reclaimed pages
1441+
1442+
pgscan_kswapd (npn)
1443+
Amount of scanned pages by kswapd (in an inactive LRU list)
1444+
1445+
pgscan_direct (npn)
1446+
Amount of scanned pages directly (in an inactive LRU list)
1447+
1448+
pgsteal_kswapd (npn)
1449+
Amount of reclaimed pages by kswapd
1450+
1451+
pgsteal_direct (npn)
1452+
Amount of reclaimed pages directly
1453+
14361454
pgfault (npn)
14371455
Total number of page faults incurred
14381456

@@ -1442,12 +1460,6 @@ PAGE_SIZE multiple when read back.
14421460
pgrefill (npn)
14431461
Amount of scanned pages (in an active LRU list)
14441462

1445-
pgscan (npn)
1446-
Amount of scanned pages (in an inactive LRU list)
1447-
1448-
pgsteal (npn)
1449-
Amount of reclaimed pages
1450-
14511463
pgactivate (npn)
14521464
Amount of pages moved to the active LRU list
14531465

mm/memcontrol.c

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,6 +1460,29 @@ static inline unsigned long memcg_page_state_output(struct mem_cgroup *memcg,
14601460
return memcg_page_state(memcg, item) * memcg_page_state_unit(item);
14611461
}
14621462

1463+
/* Subset of vm_event_item to report for memcg event stats */
1464+
static const unsigned int memcg_vm_event_stat[] = {
1465+
PGSCAN_KSWAPD,
1466+
PGSCAN_DIRECT,
1467+
PGSTEAL_KSWAPD,
1468+
PGSTEAL_DIRECT,
1469+
PGFAULT,
1470+
PGMAJFAULT,
1471+
PGREFILL,
1472+
PGACTIVATE,
1473+
PGDEACTIVATE,
1474+
PGLAZYFREE,
1475+
PGLAZYFREED,
1476+
#if defined(CONFIG_MEMCG_KMEM) && defined(CONFIG_ZSWAP)
1477+
ZSWPIN,
1478+
ZSWPOUT,
1479+
#endif
1480+
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
1481+
THP_FAULT_ALLOC,
1482+
THP_COLLAPSE_ALLOC,
1483+
#endif
1484+
};
1485+
14631486
static char *memory_stat_format(struct mem_cgroup *memcg)
14641487
{
14651488
struct seq_buf s;
@@ -1495,41 +1518,17 @@ static char *memory_stat_format(struct mem_cgroup *memcg)
14951518
}
14961519

14971520
/* Accumulated memory events */
1498-
1499-
seq_buf_printf(&s, "%s %lu\n", vm_event_name(PGFAULT),
1500-
memcg_events(memcg, PGFAULT));
1501-
seq_buf_printf(&s, "%s %lu\n", vm_event_name(PGMAJFAULT),
1502-
memcg_events(memcg, PGMAJFAULT));
1503-
seq_buf_printf(&s, "%s %lu\n", vm_event_name(PGREFILL),
1504-
memcg_events(memcg, PGREFILL));
15051521
seq_buf_printf(&s, "pgscan %lu\n",
15061522
memcg_events(memcg, PGSCAN_KSWAPD) +
15071523
memcg_events(memcg, PGSCAN_DIRECT));
15081524
seq_buf_printf(&s, "pgsteal %lu\n",
15091525
memcg_events(memcg, PGSTEAL_KSWAPD) +
15101526
memcg_events(memcg, PGSTEAL_DIRECT));
1511-
seq_buf_printf(&s, "%s %lu\n", vm_event_name(PGACTIVATE),
1512-
memcg_events(memcg, PGACTIVATE));
1513-
seq_buf_printf(&s, "%s %lu\n", vm_event_name(PGDEACTIVATE),
1514-
memcg_events(memcg, PGDEACTIVATE));
1515-
seq_buf_printf(&s, "%s %lu\n", vm_event_name(PGLAZYFREE),
1516-
memcg_events(memcg, PGLAZYFREE));
1517-
seq_buf_printf(&s, "%s %lu\n", vm_event_name(PGLAZYFREED),
1518-
memcg_events(memcg, PGLAZYFREED));
1519-
1520-
#if defined(CONFIG_MEMCG_KMEM) && defined(CONFIG_ZSWAP)
1521-
seq_buf_printf(&s, "%s %lu\n", vm_event_name(ZSWPIN),
1522-
memcg_events(memcg, ZSWPIN));
1523-
seq_buf_printf(&s, "%s %lu\n", vm_event_name(ZSWPOUT),
1524-
memcg_events(memcg, ZSWPOUT));
1525-
#endif
15261527

1527-
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
1528-
seq_buf_printf(&s, "%s %lu\n", vm_event_name(THP_FAULT_ALLOC),
1529-
memcg_events(memcg, THP_FAULT_ALLOC));
1530-
seq_buf_printf(&s, "%s %lu\n", vm_event_name(THP_COLLAPSE_ALLOC),
1531-
memcg_events(memcg, THP_COLLAPSE_ALLOC));
1532-
#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
1528+
for (i = 0; i < ARRAY_SIZE(memcg_vm_event_stat); i++)
1529+
seq_buf_printf(&s, "%s %lu\n",
1530+
vm_event_name(memcg_vm_event_stat[i]),
1531+
memcg_events(memcg, memcg_vm_event_stat[i]));
15331532

15341533
/* The above should easily fit into one page */
15351534
WARN_ON_ONCE(seq_buf_has_overflowed(&s));

0 commit comments

Comments
 (0)