Re: [PATCH V5 1/8] mm/slab: use unsigned long for orig_size to ensure proper metadata align

From: Harry Yoo

Date: Mon Jan 12 2026 - 01:29:11 EST


On Fri, Jan 09, 2026 at 10:30:47AM +0100, Alexander Potapenko wrote:
> > > Instead of calculating the offset of the original size in several
> > > places, should we maybe introduce a function that returns a pointer to
> > > it?
> >
> > Good point.
> >
> > The calculation of various metadata offset (including the original size)
> > is repeated in several places, and perhaps it's worth cleaning up,
> > something like this:
> >
> > enum {
> > FREE_POINTER_OFFSET,
> > ALLOC_TRACK_OFFSET,
> > FREE_TRACK_OFFSET,
> > ORIG_SIZE_OFFSET,
> > KASAN_ALLOC_META_OFFSET,
> > OBJ_EXT_OFFSET,
> > FINAL_ALIGNMENT_PADDING_OFFSET,
> > ...
> > };
> >
> > orig_size = *(unsigned long *)get_metadata_ptr(p, ORIG_SIZE_OFFSET);
>
> An alternative would be to declare a struct containing all the
> metadata fields and use offsetof() (or simply do a cast and access the
> fields via the struct pointer)

But considering that a cache may enable only a subset of those debugging
features, I'm not sure determining that offset for all caches at build
time is possible.

--
Cheers,
Harry / Hyeonggon