On Wed, Nov 25, 2026 at 09:37:14PM +0000, Harry Yoo (Meta) wrote:
> Objects of a cache without SLAB_MAY_ACCOUNT cannot store the objcg > pointer once slabobj_ext space is no longer reserved for every cache. > Skip charging when __GFP_ACCOUNT hits such a cache, and warn once under > CONFIG_DEBUG_VM to catch callers that did not opt in. > > Refusing the charge here is sufficient for correctness: an object that > is never charged does not access the objcg slot again, and the free > path already skips such caches via slab_needs_objcg(). > > Cc: Johannes Weiner <hann…@cmpxchg.org> > Cc: Michal Hocko <mhoc…@kernel.org> > Cc: Shakeel Butt <shak…@linux.dev> > Cc: Muchun Song <much…@linux.dev> > Cc: cgro…@vger.kernel.org > Signed-off-by: Harry Yoo (Meta) <har…@kernel.org> > --- > mm/memcontrol.c | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > index a07cc73acfc7..0eddb16173fd 100644 > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -3707,6 +3707,12 @@ bool __memcg_slab_post_alloc_hook(struct kmem_cache *s, struct list_lru *lru, > if (unlikely(*p == NULL)) > return true; > > + /* Do not allow __GFP_ACCOUNT without SLAB_MAY_ACCOUNT */ > + if (unlikely(!cache_needs_objcg(s))) { > + VM_WARN_ON_ONCE(1); > + return true; > + } > +
Would it be better to put this check before `if (!objcg || obj_cgroup_is_root(objcg))`, so we can catch abnormal cases more aggressively?
> flags &= gfp_allowed_mask; > > if (lru) { > > -- > 2.54.0 >
-- Thanks, Hao