[Devel] [PATCH RHEL8 COMMIT] memcg: Show correct values of slab_[un]reclaimable in memory.stat files

Konstantin Khorenko khorenko at virtuozzo.com
Fri Sep 10 20:13:20 MSK 2021


The commit is pushed to "branch-rh8-4.18.0-305.3.1.vz8.7.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh8-4.18.0-305.3.1.vz8.7.11
------>
commit 3c286fc674d95dd76850083166ff0ac4e24b4d4b
Author: Evgenii Shatokhin <eshatokhin at virtuozzo.com>
Date:   Fri Sep 10 20:13:20 2021 +0300

    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
    Fixes: cf89dfa06ebe ("mm: memcontrol: add stats for reclaimable and unreclaimable stats")
    
    Signed-off-by: Evgenii Shatokhin <eshatokhin at virtuozzo.com>
---
 mm/memcontrol.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 989dc23d05b8..3f6f59ac8746 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -4727,7 +4727,9 @@ static int memcg_stat_show(struct seq_file *m, void *v)
 		if (memcg1_stats[i] == NR_ANON_THPS)
 			nr *= HPAGE_PMD_NR;
 #endif
-		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 %lu\n", memcg1_stat_names[i], nr);
 	}
 
 	for (i = 0; i < ARRAY_SIZE(memcg1_events); i++)
@@ -4767,17 +4769,18 @@ 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]);
+		nr = (u64)memcg_page_state(memcg, memcg1_stats[i]);
 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
 		if (memcg1_stats[i] == NR_ANON_THPS)
 			nr *= HPAGE_PMD_NR;
 #endif
-		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++)


More information about the Devel mailing list