All of lore.kernel.org
 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
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ 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 related	[flat|nested] 5+ 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
  2026-11-24  5:09 ` + memcg-warn-when-memory-cgroup-ids-run-out.patch added to mm-new branch Andrew Morton
  2026-11-24  8:52 ` [PATCH] memcg: warn when memory cgroup IDs run out Michal Hocko
  2 siblings, 0 replies; 5+ 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] 5+ messages in thread

* + memcg-warn-when-memory-cgroup-ids-run-out.patch added to mm-new branch
  2026-11-24  2:08 [PATCH] memcg: warn when memory cgroup IDs run out Shakeel Butt
  2026-11-24  2:19 ` Muchun Song
@ 2026-11-24  5:09 ` Andrew Morton
  2026-11-24  8:52 ` [PATCH] memcg: warn when memory cgroup IDs run out Michal Hocko
  2 siblings, 0 replies; 5+ messages in thread
From: Andrew Morton @ 2026-11-24  5:09 UTC (permalink / raw)
  To: mm-commits, tj, roman.gushchin, muchun.song, mkoutny, mhocko,
	hannes, shakeel.butt, akpm

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 4080 bytes --]


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 <shakeel.butt@linux.dev>
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.

Link: https://patch.msgid.link/20261124020800.2313930-1-shakeel.butt@linux.dev
Signed-off-by: Shakeel Butt <shakeel.butt@linux.dev>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: Muchun Song (ByteDance) <muchun.song@linux.dev>
Cc: Tejun Heo <tj@kernel.org>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Koutný <mkoutny@suse.com>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Roman Gushchin <roman.gushchin@linux.dev>

 mm/memcontrol.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

--- a/mm/memcontrol.c~memcg-warn-when-memory-cgroup-ids-run-out
+++ a/mm/memcontrol.c
@@ -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 shakeel.butt@linux.dev 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


^ permalink raw reply	[flat|nested] 5+ 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
  2026-11-24  5:09 ` + memcg-warn-when-memory-cgroup-ids-run-out.patch added to mm-new branch Andrew Morton
@ 2026-11-24  8:52 ` Michal Hocko
  2026-11-24 18:09   ` Shakeel Butt
  2 siblings, 1 reply; 5+ messages in thread
From: Michal Hocko @ 2026-11-24  8:52 UTC (permalink / raw)
  To: Shakeel Butt
  Cc: Andrew Morton, Tejun Heo, Johannes Weiner, Michal Koutny,
	Roman Gushchin, Muchun Song, Meta kernel team, cgroups, linux-mm,
	linux-kernel

On Mon 23-11-26 18:08:00, Shakeel Butt 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.

Not that I am against but isn't the issue clear by observing EBUSY from
mkdir?

-- 
Michal Hocko
SUSE Labs


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

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

On Tue, Nov 24, 2026 at 09:52:26AM +0100, Michal Hocko wrote:
> On Mon 23-11-26 18:08:00, Shakeel Butt 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.
> 
> Not that I am against but isn't the issue clear by observing EBUSY from
> mkdir?

There are multiple software layers (binaries and libraries) between mkdir
operation and the folks debugging the failures. Not all software creating
cgroups log the returned errors. Also I am not sure EBUSY can only be when
we are out of memcg IDs. These errors can be transient as well. Initially I was
thinking of adding a vmstat but decided to go with a warning first.


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

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

Thread overview: 5+ 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
2026-11-24  5:09 ` + memcg-warn-when-memory-cgroup-ids-run-out.patch added to mm-new branch Andrew Morton
2026-11-24  8:52 ` [PATCH] memcg: warn when memory cgroup IDs run out Michal Hocko
2026-11-24 18:09   ` Shakeel Butt

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.