[Devel] [PATCH vz9 07/16] mm: memcontrol: add stats for reclaimable and unreclaimable stats

Nikita Yushchenko nikita.yushchenko at virtuozzo.com
Wed Sep 29 10:00:08 MSK 2021


From: Vladimir Davydov <vdavydov at virtuozzo.com>

Required by vcmmd for estimating the size of available memory, which in
turn is used for calculating the lower boundary for memory limit.

Also, these counters will be used by the following patches.

Signed-off-by: Vladimir Davydov <vdavydov at virtuozzo.com>
Signed-off-by: Andrey Ryabinin <aryabinin at virtuozzo.com>

+++
memcg: Show correct values of slab_[un]reclaimable in memory.stat files

The values of NR_SLAB_RECLAIMABLE_B and NR_SLAB_UNRECLAIMABLE_B counters
are in bytes rather than in pages. So, one should not multiply them by
PAGE_SIZE when preparing the records for 'memory.stat' files in the memory
cgroups.

This also applies to 'total_slab_[un]reclaimable' stats in those files.

https://jira.sw.ru/browse/PSBM-132728

Signed-off-by: Evgenii Shatokhin <eshatokhin at virtuozzo.com>

Cherry-picked from vz8 commit 6ee44bfbd469 ("mm: memcontrol: add stats
for reclaimable and unreclaimable stats")).

Applied cosmetic fixes: remove unneeded cast, make type of 'nr' same
in both loops inside memcg_stat_show().

Signed-off-by: Nikita Yushchenko <nikita.yushchenko at virtuozzo.com>
---
 mm/memcontrol.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index d51f09a70bcd..c2b527cf73dc 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -4076,6 +4076,8 @@ static const unsigned int memcg1_stats[] = {
 	NR_FILE_MAPPED,
 	NR_FILE_DIRTY,
 	NR_WRITEBACK,
+	NR_SLAB_RECLAIMABLE_B,
+	NR_SLAB_UNRECLAIMABLE_B,
 	MEMCG_SWAP,
 };
 
@@ -4089,6 +4091,8 @@ static const char *const memcg1_stat_names[] = {
 	"mapped_file",
 	"dirty",
 	"writeback",
+	"slab_reclaimable",
+	"slab_unreclaimable",
 	"swap",
 };
 
@@ -4112,12 +4116,14 @@ static int memcg_stat_show(struct seq_file *m, void *v)
 	cgroup_rstat_flush(memcg->css.cgroup);
 
 	for (i = 0; i < ARRAY_SIZE(memcg1_stats); i++) {
-		unsigned long nr;
+		u64 nr;
 
 		if (memcg1_stats[i] == MEMCG_SWAP && !do_memsw_account())
 			continue;
 		nr = memcg_page_state_local(memcg, memcg1_stats[i]);
-		seq_printf(m, "%s %lu\n", memcg1_stat_names[i], nr * PAGE_SIZE);
+		if (!vmstat_item_in_bytes(memcg1_stats[i]))
+			nr *= PAGE_SIZE;
+		seq_printf(m, "%s %llu\n", memcg1_stat_names[i], nr);
 	}
 
 	for (i = 0; i < ARRAY_SIZE(memcg1_events); i++)
@@ -4142,13 +4148,14 @@ static int memcg_stat_show(struct seq_file *m, void *v)
 			   (u64)memsw * PAGE_SIZE);
 
 	for (i = 0; i < ARRAY_SIZE(memcg1_stats); i++) {
-		unsigned long nr;
+		u64 nr;
 
 		if (memcg1_stats[i] == MEMCG_SWAP && !do_memsw_account())
 			continue;
 		nr = memcg_page_state(memcg, memcg1_stats[i]);
-		seq_printf(m, "total_%s %llu\n", memcg1_stat_names[i],
-						(u64)nr * PAGE_SIZE);
+		if (!vmstat_item_in_bytes(memcg1_stats[i]))
+			nr *= PAGE_SIZE;
+		seq_printf(m, "total_%s %llu\n", memcg1_stat_names[i], nr);
 	}
 
 	for (i = 0; i < ARRAY_SIZE(memcg1_events); i++)
-- 
2.30.2



More information about the Devel mailing list