memcg: warn when memory cgroup IDs run out
Subsystems (3)
Shakeel Butt
maintainerPATCH 1/1 memcg: warn when memory cgroup IDs run out
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.
--- mm/memcontrol.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
mm/memcontrol.c +5 -1
@@ -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);
Signature · 1 line
2.53.1-Meta
Quoted 20 lines · Shakeel Butt
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
-EBUSYfrom mkdir.
- Since commit8290f45995f5("memcg: move memcg private ID refcount to objcg"), a dead memcg is freed even while swap still holds its ID. Sonr_dying_subsys_memoryin cgroup.stat can be 0 while the IDs run out.
Quoted 4 lines
Print a rate limited warning when the ID allocation fails because all IDs are in use.
Signed-off-by Shakeel Butt <[email protected]>
Thanks.
+ memcg-warn-when-memory-cgroup-ids-run-out.patch added to mm-new branch
In reply to Shakeel ButtThe patch titled Subject: memcg: warn when memory cgroup IDs run out has been added to the -mm mm-new branch. Its filename is memcg-warn-when-memory-cgroup-ids-run-out.patch
The patch titled
Subject: memcg: warn when memory cgroup IDs run out
has been added to the -mm mm-new branch. Its filename is
memcg-warn-when-memory-cgroup-ids-run-out.patch
This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/memcg-warn-when-memory-cgroup-ids-run-out.patch
This patch will later appear in the mm-new branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Note, mm-new is a provisional staging ground for work-in-progress patches, and acceptance into mm-new is a notification for others take notice and to finish up reviews. Please do not hesitate to respond to review feedback and post updated versions to replace or incrementally fixup patches in mm-new.
The mm-new branch of mm.git is not included in linux-next
If a few days of testing in mm-new is successful, the patch will me moved into mm.git's mm-unstable branch, which is included in linux-next
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next via various branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there most days
------------------------------------------------------
From: Shakeel Butt <[email protected]>
Subject: memcg: warn when memory cgroup IDs run out
Date: Mon, 23 Nov 2026 18:08:00 -0800
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.
mm/memcontrol.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
mm/memcontrol.c renamed from mm/memcontrol.c~memcg-warn-when-memory-cgroup-ids-run-out +5 -1
@@ -4307,8 +4307,12 @@ static struct mem_cgroup *mem_cgroup_all 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);
_
Patches currently in -mm which might be from [email protected] are
memcg-free-the-private-id-of-a-memcg-that-never-comes-online.patch memcg-move-memoryhigh-enforcement-out-of-try_charge_memcg.patch memcg-force-charges-from-reclaim-before-trying-the-limits.patch memcg-use-high_work-for-kernel-threads.patch memcg-use-high_work-for-remote-charges.patch memcg-simplify-high-limit-handling-after-a-charge.patch memcg-warn-when-memory-cgroup-ids-run-out.patch