[Devel] [PATCH vz10 v3 3/2] mm/memcontrol: do not uncharge cache folio for root memcg

Konstantin Khorenko khorenko at virtuozzo.com
Tue Jul 29 15:39:06 MSK 2025


We do not account/limit memcg::memory,::memsw for root memcg,
so don't we do that for cache.

And memory.cache.current,memory.cache.max files are not available for
root memcg as well.

But there is one place - uncharge_folio() - where we forgot to put cache
accounting under !mem_cgroup_is_root() check, so fix this.

Fixes: 6a2ca4d515c5 ("mm: Memory cgroup page cache limit")
https://virtuozzo.atlassian.net/browse/VSTOR-111756

Signed-off-by: Konstantin Khorenko <khorenko at virtuozzo.com>

Feature: mm: Memory cgroup page cache limit
---
 mm/memcontrol.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index f0b53e5f4d243..8a4fdef58743e 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -5499,11 +5499,12 @@ static void uncharge_folio(struct folio *folio, struct uncharge_gather *ug)
 		folio->memcg_data = 0;
 		obj_cgroup_put(objcg);
 	} else {
-		if (folio_memcg_cache(folio))
-			ug->nr_pgcache += nr_pages;
 		/* LRU pages aren't accounted at the root level */
-		if (!mem_cgroup_is_root(memcg))
+		if (!mem_cgroup_is_root(memcg)) {
 			ug->nr_memory += nr_pages;
+			if (folio_memcg_cache(folio))
+				ug->nr_pgcache += nr_pages;
+		}
 		ug->pgpgout++;
 
 		WARN_ON_ONCE(folio_unqueue_deferred_split(folio));
-- 
2.43.0



More information about the Devel mailing list