Skip to content

Commit 9f01b49

Browse files
shakeelbakpm00
authored andcommitted
memcg: drain obj stock on cpu hotplug teardown
Currently on cpu hotplug teardown, only memcg stock is drained but we need to drain the obj stock as well otherwise we will miss the stats accumulated on the target cpu as well as the nr_bytes cached. The stats include MEMCG_KMEM, NR_SLAB_RECLAIMABLE_B & NR_SLAB_UNRECLAIMABLE_B. In addition we are leaking reference to struct obj_cgroup object. Link: https://lkml.kernel.org/r/20250310230934.2913113-1-shakeel.butt@linux.dev Fixes: bf4f059 ("mm: memcg/slab: obj_cgroup API") Signed-off-by: Shakeel Butt <shakeel.butt@linux.dev> Reviewed-by: Roman Gushchin <roman.gushchin@linux.dev> Acked-by: Johannes Weiner <hannes@cmpxchg.org> Cc: Michal Hocko <mhocko@kernel.org> Cc: Muchun Song <muchun.song@linux.dev> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 14efb47 commit 9f01b49

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

mm/memcontrol.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1921,9 +1921,18 @@ void drain_all_stock(struct mem_cgroup *root_memcg)
19211921
static int memcg_hotplug_cpu_dead(unsigned int cpu)
19221922
{
19231923
struct memcg_stock_pcp *stock;
1924+
struct obj_cgroup *old;
1925+
unsigned long flags;
19241926

19251927
stock = &per_cpu(memcg_stock, cpu);
1928+
1929+
/* drain_obj_stock requires stock_lock */
1930+
local_lock_irqsave(&memcg_stock.stock_lock, flags);
1931+
old = drain_obj_stock(stock);
1932+
local_unlock_irqrestore(&memcg_stock.stock_lock, flags);
1933+
19261934
drain_stock(stock);
1935+
obj_cgroup_put(old);
19271936

19281937
return 0;
19291938
}

0 commit comments

Comments
 (0)