On Wed, Apr 27, 2022 at 1:27 PM Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> wrote: > > On Wed, 27 Apr 2022 12:58:20 -0700 Peter Collingbourne <pcc@xxxxxxxxxx> wrote: > > > When CONFIG_KASAN_HW_TAGS is enabled we currently increase the minimum > > slab alignment to 16. This happens even if MTE is not supported in > > hardware or disabled via kasan=off, which creates an unnecessary > > memory overhead in those cases. Eliminate this overhead by making > > the minimum slab alignment a runtime property and only aligning to > > 16 if KASAN is enabled at runtime. > > > > On a DragonBoard 845c (non-MTE hardware) with a kernel built with > > CONFIG_KASAN_HW_TAGS, waiting for quiescence after a full Android > > boot I see the following Slab measurements in /proc/meminfo (median > > of 3 reboots): > > > > ... > > > > --- a/mm/slab.c > > +++ b/mm/slab.c > > @@ -3009,10 +3009,9 @@ static void *cache_alloc_debugcheck_after(struct kmem_cache *cachep, > > objp += obj_offset(cachep); > > if (cachep->ctor && cachep->flags & SLAB_POISON) > > cachep->ctor(objp); > > - if (ARCH_SLAB_MINALIGN && > > - ((unsigned long)objp & (ARCH_SLAB_MINALIGN-1))) { > > - pr_err("0x%px: not aligned to ARCH_SLAB_MINALIGN=%d\n", > > - objp, (int)ARCH_SLAB_MINALIGN); > > + if ((unsigned long)objp & (arch_slab_minalign() - 1)) { > > + pr_err("0x%px: not aligned to arch_slab_minalign()=%d\n", objp, > > + (int)arch_slab_minalign()); > > printf/printk know about size_t. Use %zu, no cast needed. But... > > > } > > return objp; > > } > > diff --git a/mm/slab_common.c b/mm/slab_common.c > > index 2b3206a2c3b5..33cc49810a54 100644 > > --- a/mm/slab_common.c > > +++ b/mm/slab_common.c > > @@ -154,8 +154,7 @@ static unsigned int calculate_alignment(slab_flags_t flags, > > align = max(align, ralign); > > } > > > > - if (align < ARCH_SLAB_MINALIGN) > > - align = ARCH_SLAB_MINALIGN; > > + align = max_t(size_t, align, arch_slab_minalign()); > > max_t/min_t are nature's way of telling us "you screwed up the types". > > So what type _is_ slab alignment? size_t seems sensible, but the code > prefers unsigned int. So how about we stick with that? > > > This compiles. Still some max_t's in slob.c because I was too lazy to > go fix the type of ARCH_KMALLOC_MINALIGN. > > Shrug, I don't know if we can be bothered. You decide :) Hi Andrew, No strong opinions here. I'm happy with the fixup that you added to your tree on top of my patch. Peter