Re: [PATCH V5 4/8] mm/slab: abstract slabobj_ext access via new slab_obj_ext() helper
From: Harry Yoo
Date: Thu Jan 08 2026 - 02:23:00 EST
On Wed, Jan 07, 2026 at 10:53:48PM +0800, Hao Li wrote:
> On Mon, Jan 05, 2026 at 05:02:26PM +0900, Harry Yoo wrote:
> > Currently, the slab allocator assumes that slab->obj_exts is a pointer
> > to an array of struct slabobj_ext objects. However, to support storage
> > methods where struct slabobj_ext is embedded within objects, the slab
> > allocator should not make this assumption. Instead of directly
> > dereferencing the slabobj_exts array, abstract access to
> > struct slabobj_ext via helper functions.
> >
> > Introduce a new API slabobj_ext metadata access:
> >
> > slab_obj_ext(slab, obj_exts, index) - returns the pointer to
> > struct slabobj_ext element at the given index.
> >
> > Directly dereferencing the return value of slab_obj_exts() is no longer
> > allowed. Instead, slab_obj_ext() must always be used to access
> > individual struct slabobj_ext objects.
> >
> > Convert all users to use these APIs.
> > No functional changes intended.
> >
> > Signed-off-by: Harry Yoo <harry.yoo@xxxxxxxxxx>
> > ---
> > mm/memcontrol.c | 23 +++++++++++++++-------
> > mm/slab.h | 43 +++++++++++++++++++++++++++++++++++------
> > mm/slub.c | 51 ++++++++++++++++++++++++++++---------------------
> > 3 files changed, 82 insertions(+), 35 deletions(-)
> >
> > diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> > index be810c1fbfc3..fd9105a953b0 100644
> > --- a/mm/memcontrol.c
> > +++ b/mm/memcontrol.c
> > @@ -533,7 +558,13 @@ int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s,
> >
> > #else /* CONFIG_SLAB_OBJ_EXT */
> >
> > -static inline struct slabobj_ext *slab_obj_exts(struct slab *slab)
> > +static inline unsigned long slab_obj_exts(struct slab *slab)
> > +{
> > + return 0;
> > +}
> > +
> > +static inline struct slabobj_ext *slab_obj_ext(struct slab *slab,
> > + unsigned int index)
>
> Hi Harry,
Hi Hao, thank you so much for reviewing it!
> just a small nit: the parameter list of slab_obj_ext() should
> include `unsigned long obj_exts`.
Ouch, made a silly mistake.
You're right.
Interestingly it didn't break CONFIG_SLAB_OBJ_EXT=n builds perhaps
because it was unreachable as Vlastimil mentioned it elsewhere.
I'll fix it anyway in the next version.
--
Cheers,
Harry / Hyeonggon