[PATCH RFC v2 1/6] mm/memcg: add a helper to kill the memcgid on offlining

From: Bingfang Guo via B4 Relay

Date: Tue Sep 01 2026 - 05:02:44 EST


From: Bingfang Guo <bingfangguo@xxxxxxxxxxx>

The online state holds one reference on the memcg private id; it is
released when the memcg goes offline. Put that release behind a small
helper, mem_cgroup_private_id_kill(), so css_offline() reads clearly
and the id refcount helpers stay symmetric: get_online() / kill() /
put().

Signed-off-by: Bingfang Guo <bingfangguo@xxxxxxxxxxx>
---
mm/memcontrol.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 256b68ffca70e..31cec9dde55f0 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -4048,6 +4048,11 @@ static inline void mem_cgroup_private_id_put(struct mem_cgroup *memcg, unsigned
}
}

+static void mem_cgroup_private_id_kill(struct mem_cgroup *memcg)
+{
+ mem_cgroup_private_id_put(memcg, 1);
+}
+
struct mem_cgroup *mem_cgroup_private_id_get_online(struct mem_cgroup *memcg, unsigned int n)
{
while (!refcount_add_not_zero(n, &memcg->id.ref)) {
@@ -4385,7 +4390,7 @@ static void mem_cgroup_css_offline(struct cgroup_subsys_state *css)

drain_all_stock(memcg);

- mem_cgroup_private_id_put(memcg, 1);
+ mem_cgroup_private_id_kill(memcg);
}

static void mem_cgroup_css_released(struct cgroup_subsys_state *css)

--
2.43.7