[PATCH slab/for-next v2 14/14] mm/slab: do not set SLAB_MAY_ACCOUNT for all caches

Harry Yoo harry at kernel.org
Thu Dec 3 14:27:25 UTC 2026


On Thu, Dec 03, 2026 at 02:17:21PM +0000, Hao Li wrote:
> On Wed, Nov 25, 2026 at 09:37:15PM +0000, Harry Yoo (Meta) wrote:
> > Now that all caches whose objects may be allocated with __GFP_ACCOUNT
> > specify SLAB_MAY_ACCOUNT (or SLAB_ACCOUNT, which implies it), stop
> > assuming any cache may be used with __GFP_ACCOUNT. This avoids wasting
> > the objcg slot in slabobj_ext for caches that are never charged to a
> > memcg.
> > 
> > Signed-off-by: Harry Yoo (Meta) <harry at kernel.org>
> > ---
> > diff --git a/mm/slab_common.c b/mm/slab_common.c
> > index 193b5a03bc47..464695504248 100644
> > --- a/mm/slab_common.c
> > +++ b/mm/slab_common.c
> > @@ -367,12 +367,10 @@ struct kmem_cache *__kmem_cache_create_args(const char *name,
> >  		goto out_unlock;
> >  	}
> >  
> > -	/*
> > -	 * For now we assume any cache can be used with __GFP_ACCOUNT and thus
> > -	 * may need to store objcg pointers for objects
> > -	 */
> > -	if (!mem_cgroup_kmem_disabled())
> > +	if (flags & SLAB_ACCOUNT)
> >  		flags |= SLAB_MAY_ACCOUNT;
> > +	if (mem_cgroup_kmem_disabled())
> > +		flags &= ~SLAB_MAY_ACCOUNT;
> 
> Btw, say maple_node/sk_buff/... could be merged with cacheX before. After this
> patch, cacheX loses SLAB_MAY_ACCOUNT while we still set SLAB_MAY_ACCOUNT for
> maple_node explicitly, so they can't be merged anymore. Not sure if it matters,
> though.

Hmm you mean SLAB_ACCOUNT and SLAB_MAY_ACCOUNT should be cleared at
run-time during merging decision with cgroup.memory=nokmem? 

-- 
Cheers,
Harry / Hyeonggon



More information about the Linux-security-module-archive mailing list