mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] memcg: warn when memory cgroup IDs run out
@ 2026-11-24  2:08 Shakeel Butt
  2026-11-24  2:19 ` Muchun Song
  0 siblings, 1 reply; 2+ messages in thread
From: Shakeel Butt @ 2026-11-24  2:08 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Tejun Heo, Johannes Weiner, Michal Koutny, Michal Hocko,
	Roman Gushchin, Muchun Song, Meta kernel team, cgroups, linux-mm,
	linux-kernel

Every memory cgroup gets a 16-bit private ID, so a host can have at most
65,535 of them at a time, counting dead ones. A dead memcg keeps its ID
as long as any swap slot still records it. On Meta hosts that create
many short-lived cgroups, dead cgroups held this way filled the whole ID
space. After that, every mkdir of a cgroup with the memory controller
failed with -EBUSY: systemd could not start units, and container setup
failed.

This was hard to see:

- Nothing is logged when the ID allocation fails. The only sign is
  -EBUSY from mkdir.
- Since commit 8290f45995f5 ("memcg: move memcg private ID refcount to
  objcg"), a dead memcg is freed even while swap still holds its ID. So
  nr_dying_subsys_memory in cgroup.stat can be 0 while the IDs run out.

Print a rate limited warning when the ID allocation fails because all
IDs are in use.

Signed-off-by: Shakeel Butt <shakeel.butt@linux.dev>
---
 mm/memcontrol.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 84f4a8fd4d16..206c910cf3dc 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -4271,8 +4271,12 @@ static struct mem_cgroup *mem_cgroup_alloc(struct mem_cgroup *parent)
 
 	error = xa_alloc(&mem_cgroup_private_ids, &memcg->private_id, NULL,
 			 XA_LIMIT(1, MEM_CGROUP_ID_MAX), GFP_KERNEL);
-	if (error)
+	if (error) {
+		if (error == -EBUSY)
+			pr_warn_ratelimited("memcg: all %lu memory cgroup IDs are in use, cannot create a new memory cgroup\n",
+					    MEM_CGROUP_ID_MAX);
 		goto fail;
+	}
 	error = -ENOMEM;
 
 	memcg->vmstats = kzalloc_obj(struct memcg_vmstats, GFP_KERNEL_ACCOUNT);
-- 
2.53.1-Meta


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

* Re: [PATCH] memcg: warn when memory cgroup IDs run out
  2026-11-24  2:08 [PATCH] memcg: warn when memory cgroup IDs run out Shakeel Butt
@ 2026-11-24  2:19 ` Muchun Song
  0 siblings, 0 replies; 2+ messages in thread
From: Muchun Song @ 2026-11-24  2:19 UTC (permalink / raw)
  To: Shakeel Butt
  Cc: Muchun Song, Andrew Morton, Tejun Heo, Johannes Weiner,
	Michal Koutny, Michal Hocko, Roman Gushchin, Meta kernel team,
	cgroups, linux-mm, linux-kernel



> On Nov 24, 2026, at 10:08, Shakeel Butt <shakeel.butt@linux.dev> wrote:
> 
> Every memory cgroup gets a 16-bit private ID, so a host can have at most
> 65,535 of them at a time, counting dead ones. A dead memcg keeps its ID
> as long as any swap slot still records it. On Meta hosts that create
> many short-lived cgroups, dead cgroups held this way filled the whole ID
> space. After that, every mkdir of a cgroup with the memory controller
> failed with -EBUSY: systemd could not start units, and container setup
> failed.
> 
> This was hard to see:
> 
> - Nothing is logged when the ID allocation fails. The only sign is
>  -EBUSY from mkdir.
> - Since commit 8290f45995f5 ("memcg: move memcg private ID refcount to
>  objcg"), a dead memcg is freed even while swap still holds its ID. So
>  nr_dying_subsys_memory in cgroup.stat can be 0 while the IDs run out.
> 
> Print a rate limited warning when the ID allocation fails because all
> IDs are in use.
> 
> Signed-off-by: Shakeel Butt <shakeel.butt@linux.dev>

Reviewed-by: Muchun Song (ByteDance) <muchun.song@linux.dev>

Thanks.


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

end of thread, other threads:[~2026-11-24  2:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-24  2:08 [PATCH] memcg: warn when memory cgroup IDs run out Shakeel Butt
2026-11-24  2:19 ` Muchun Song

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

all inboxes | Powered by JetHome®