linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] memcg: avoid refill_stock for root memcg
@ 2025-03-13  5:48 Shakeel Butt
  2025-03-13  7:52 ` Michal Hocko
  2025-03-13 15:39 ` Johannes Weiner
  0 siblings, 2 replies; 3+ messages in thread
From: Shakeel Butt @ 2025-03-13  5:48 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Johannes Weiner, Michal Hocko, Roman Gushchin, Muchun Song,
	linux-mm, cgroups, linux-kernel, Meta kernel team

We never charge the page counters of root memcg, so there is no need to
put root memcg in the memcg stock. At the moment, refill_stock() can be
called from try_charge_memcg(), obj_cgroup_uncharge_pages() and
mem_cgroup_uncharge_skmem().

The try_charge_memcg() and mem_cgroup_uncharge_skmem() are never called
with root memcg, so those are fine. However obj_cgroup_uncharge_pages()
can potentially call refill_stock() with root memcg if the objcg object
has been reparented over to the root memcg. Let's just avoid
refill_stock() from obj_cgroup_uncharge_pages() for root memcg.

Signed-off-by: Shakeel Butt <shakeel.butt@linux.dev>
---
 mm/memcontrol.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index e08ce52caabd..393b73aec6dd 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -2643,7 +2643,8 @@ static void obj_cgroup_uncharge_pages(struct obj_cgroup *objcg,
 
 	mod_memcg_state(memcg, MEMCG_KMEM, -nr_pages);
 	memcg1_account_kmem(memcg, -nr_pages);
-	refill_stock(memcg, nr_pages);
+	if (!mem_cgroup_is_root(memcg))
+		refill_stock(memcg, nr_pages);
 
 	css_put(&memcg->css);
 }
-- 
2.47.1



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-03-13 15:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-13  5:48 [PATCH] memcg: avoid refill_stock for root memcg Shakeel Butt
2025-03-13  7:52 ` Michal Hocko
2025-03-13 15:39 ` Johannes Weiner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox