Re: [PATCH] mm: memcontrol: treat disabled memcg as kmem accounting disabled
From: Hao Li
Date: Thu Aug 27 2026 - 20:48:23 EST
On Thu, Aug 27, 2026 at 02:04:13PM +0200, Michal Hocko wrote:
> On Thu 27-08-26 17:17:50, Hao Li wrote:
> > mem_cgroup_kmem_disabled() currently only checks whether the
> > "cgroup.memory=nokmem" option is specified. However, kmem accounting is
> > also unavailable when memcg itself is disabled.
> >
> > Check both conditions to ensure the function accurately reflects the
> > kmem accounting state.
>
> It would be really great if you could describe how we could end up with
> the inconsistent memcg enabled but kmem enabled and what kind of effect
> does this have.
Yes, thanks for point out this.
>
> AFAICS the inconsistency is possible and it would lead some wastage but
> no functional problems but the changelog should be more descriptive.
Exactly! The most direct benefit is that when memcg is disabled,
new_kmalloc_cache() will not need to create a separate `KMALLOC_CGROUP` slub
cache, but can simply alias it to `KMALLOC_NORMAL`. This avoids wastage.
If this sounds reasonable, I would be happy to explain it in more detail
in v2.
>
> > Signed-off-by: Hao Li <hao.li@xxxxxxxxx>
> > ---
> > mm/memcontrol.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> > index 1ebceade4021..b28f6165c354 100644
> > --- a/mm/memcontrol.c
> > +++ b/mm/memcontrol.c
> > @@ -132,7 +132,7 @@ static DEFINE_SPINLOCK(objcg_lock);
> >
> > bool mem_cgroup_kmem_disabled(void)
> > {
> > - return cgroup_memory_nokmem;
> > + return cgroup_memory_nokmem || mem_cgroup_disabled();
> > }
> >
> > static void memcg_uncharge(struct mem_cgroup *memcg, unsigned int nr_pages);
> > --
> > 2.54.0
>
> --
> Michal Hocko
> SUSE Labs
--
Thanks,
Hao