[PATCH] memcg: warn when memory cgroup IDs run out
From: Shakeel Butt
Date: Mon Nov 23 2026 - 21:08:27 EST
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@xxxxxxxxx>
---
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