]> www.infradead.org Git - users/willy/linux.git/commitdiff
memcg: avoid refill_stock for root memcg
authorShakeel Butt <shakeel.butt@linux.dev>
Thu, 13 Mar 2025 05:48:12 +0000 (22:48 -0700)
committerAndrew Morton <akpm@linux-foundation.org>
Sat, 22 Mar 2025 05:03:11 +0000 (22:03 -0700)
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.

Link: https://lkml.kernel.org/r/20250313054812.2185900-1-shakeel.butt@linux.dev
Signed-off-by: Shakeel Butt <shakeel.butt@linux.dev>
Acked-by: Michal Hocko <mhockoc@suse.com>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Roman Gushchin <roman.gushchin@linux.dev>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/memcontrol.c

index b07eff78414becd748ab10370c8737808b9a4743..ce57660bf5a2c29993b7a24abdecb4c5e1acf58e 100644 (file)
@@ -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);
 }