Re: [PATCH 2/3] mm/slab: add own entry points for kmem_buckets_alloc() family
From: Harry Yoo
Date: Fri Nov 27 2026 - 08:56:43 EST
On Thu, Nov 26, 2026 at 08:59:23PM +0100, Marco Elver wrote:
> On Thu, 26 Nov 2026 at 20:04, Vlastimil Babka (SUSE) <vbabka@xxxxxxxxxx> wrote:
> >
> > On 11/26/26 15:22, Harry Yoo wrote:
> > > On Tue, Nov 24, 2026 at 05:30:03PM +0100, Vlastimil Babka (SUSE) wrote:
> > >> The way buckets have been implemented was to extend
> > >> __kmalloc_node_noprof() and two more functions with the kmem_buckets
> > >> pointer parameter, which means all kmalloc_node() callers now have to
> > >> pass NULL. To avoid this extra parameter with CONFIG_SLAB_BUCKETS=n,
> > >> we added macros for parameter declaring and passing.
> > >>
> > >> This can be avoided by creating own entry points for kmem_buckets
> > >> allocations and not using the kmalloc ones. They all end up performing
> > >> __do_kmalloc_node() internally.
> > >>
> > >> Since it's just 3 functions with few callers, do not try to do anything
> > >> special to eliminate code with CONFIG_SLAB_BUCKETS=n. Only make sure the
> > >> bucket parameter is changed to NULL in that case because it would be
> > >> ZERO_SIZE_PTR otherwise.
> > >>
> > >> The removal of the now-unnecessary parameter macros is done separately
> > >> next.
> > >>
> > >> Signed-off-by: Vlastimil Babka (SUSE) <vbabka@xxxxxxxxxx>
> > >> ---
> > >> include/linux/slab.h | 16 +++++++--
> > >> mm/slub.c | 100 +++++++++++++++++++++++++++++++++++++++++----------
> > >> 2 files changed, 94 insertions(+), 22 deletions(-)
> > >>
> > >> diff --git a/mm/slub.c b/mm/slub.c
> > >> index 70df0a2e3876..6674caabbb6e 100644
> > >> --- a/mm/slub.c
> > >> +++ b/mm/slub.c
> > >> @@ -5732,6 +5732,34 @@ void *__kmalloc_flags_noprof(DECL_TOKEN_PARAMS(size, token), gfp_t flags,
> > >> }
> > >> }
> > >>
> > >> +void *__kmem_buckets_alloc_noprof(kmem_buckets *b, size_t size, gfp_t flags)
> > >> +{
> > >> + const struct slab_alloc_context ac = {
> > >> + .caller_addr = _RET_IP_,
> > >> + .orig_size = size,
> > >> + .alloc_flags = SLAB_ALLOC_DEFAULT,
> > >> + };
> > >> +
> > >> + if (!IS_ENABLED(CONFIG_SLAB_BUCKETS))
> > >> + b = NULL;
> > >> +
> > >> + return __do_kmalloc_node(b, flags, NUMA_NO_NODE, (kmalloc_token_t){}, &ac);
> > >
> > > No type-based or random kmalloc partitioning w/o SLAB_BUCKETS?
> >
> > Hm that's right, that excludes it. I didn't realize that,
> > but also I wonder
> > if anyone would really choose to have partitioning enabled but buckets
> > disabled.
Dunno :)
> > It should be straigtforward to add it though.
> > But as long as
> > buckets are not disabled, the token parameter will be effectively unused. Kees?
That's fine as buckets provide its own isolation.
> This falls back to normal kmalloc caches, right?
Yeah.
> If so, if
> partitioning is enabled, it should choose one of the partitions just
> like normal kmalloc.
So we need to pass proper token
--
Cheers,
Harry / Hyeonggon