memcg: no stock lock for cpu hot-unplug
authorShakeel Butt <shakeel.butt@linux.dev>
Wed, 14 May 2025 18:41:57 +0000 (11:41 -0700)
committerAndrew Morton <akpm@linux-foundation.org>
Thu, 22 May 2025 21:55:38 +0000 (14:55 -0700)
Previously on the cpu hot-unplug, the kernel would call drain_obj_stock()
with objcg local lock.  However local lock was not needed as the stock
which was accessed belongs to a dead cpu but we kept it there to disable
irqs as drain_obj_stock() may call mod_objcg_mlstate() which required irqs
disabled.  However there is no need to disable irqs now for
mod_objcg_mlstate(), so we can remove the local lock altogether from cpu
hot-unplug path.

Link: https://lkml.kernel.org/r/20250514184158.3471331-7-shakeel.butt@linux.dev
Signed-off-by: Shakeel Butt <shakeel.butt@linux.dev>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Roman Gushchin <roman.gushchin@linux.dev>
Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/memcontrol.c

index f66cacb6f2a003f0b73dd554c8327a427fae5336..d8508b57d0fa90b2d552f371edfd8eeb8ee781c3 100644 (file)
@@ -2023,17 +2023,8 @@ void drain_all_stock(struct mem_cgroup *root_memcg)
 
 static int memcg_hotplug_cpu_dead(unsigned int cpu)
 {
-       struct obj_stock_pcp *obj_st;
-       unsigned long flags;
-
-       obj_st = &per_cpu(obj_stock, cpu);
-
-       /* drain_obj_stock requires objstock.lock */
-       local_lock_irqsave(&obj_stock.lock, flags);
-       drain_obj_stock(obj_st);
-       local_unlock_irqrestore(&obj_stock.lock, flags);
-
        /* no need for the local lock */
+       drain_obj_stock(&per_cpu(obj_stock, cpu));
        drain_stock_fully(&per_cpu(memcg_stock, cpu));
 
        return 0;