linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] memcg: drain obj stock on cpu hotplug teardown
@ 2025-03-10 23:09 Shakeel Butt
  2025-03-11 15:30 ` Johannes Weiner
  2025-03-11 16:26 ` Roman Gushchin
  0 siblings, 2 replies; 7+ messages in thread
From: Shakeel Butt @ 2025-03-10 23:09 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Johannes Weiner, Michal Hocko, Roman Gushchin, Muchun Song,
	linux-mm, cgroups, linux-kernel, Meta kernel team, stable

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.

Fixes: bf4f059954dc ("mm: memcg/slab: obj_cgroup API")
Signed-off-by: Shakeel Butt <shakeel.butt@linux.dev>
Cc: <stable@vger.kernel.org>
---
 mm/memcontrol.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 4de6acb9b8ec..59dcaf6a3519 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -1921,9 +1921,18 @@ void drain_all_stock(struct mem_cgroup *root_memcg)
 static int memcg_hotplug_cpu_dead(unsigned int cpu)
 {
 	struct memcg_stock_pcp *stock;
+	struct obj_cgroup *old;
+	unsigned long flags;
 
 	stock = &per_cpu(memcg_stock, cpu);
+
+	/* drain_obj_stock requires stock_lock */
+	local_lock_irqsave(&memcg_stock.stock_lock, flags);
+	old = drain_obj_stock(stock);
+	local_unlock_irqrestore(&memcg_stock.stock_lock, flags);
+
 	drain_stock(stock);
+	obj_cgroup_put(old);
 
 	return 0;
 }
-- 
2.47.1



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

end of thread, other threads:[~2025-03-11 17:43 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-10 23:09 [PATCH] memcg: drain obj stock on cpu hotplug teardown Shakeel Butt
2025-03-11 15:30 ` Johannes Weiner
2025-03-11 15:57   ` Shakeel Butt
2025-03-11 16:28     ` Roman Gushchin
2025-03-11 17:43       ` Shakeel Butt
2025-03-11 17:29     ` Johannes Weiner
2025-03-11 16:26 ` Roman Gushchin

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