[PATCH v2 0/3] kmem_buckets entry point rework

From: Vlastimil Babka (SUSE)

Date: Thu Dec 03 2026 - 08:43:20 EST


When pondering the boot-time slab hardening features patchset [1] it
occured to me that the kmem_buckets handling could be redone in a way
that there are no kmem_buckets pointers in kmalloc_node() and two more
functions, and we can drop some of the tedious parameter declaring and
passing macros (except those for randomizing tokens).

So instead add own entry points for kmem_buckets enabled allocations.

The first patch is a preparatory cleanup. In v1 it also attempted to
make the new entry points cheaper (in terms of binary size) by making a
bet that one extra call in the allocation fastpath is better than many
functions inlining the same code.

Since it was however visible as 10% slowdown in the proposed slab kunit
benchmark [2], in v2 the new intermediate function is also inlined. It
still removes some duplicated code) and we pay the binary size of the
new entry points (about 1k each). In the last patch we however save
passing an unnecessary bucket parameter in all the kmalloc_node()
callers.

With v2, the benchmark [2] shows no difference in performance.

If this is accepted, [1] should be rebased on it as it makes the
slab_buckets boot-time handling really straightforward. In fact
CONFIG_SLAB_BUCKETS could be repurposed to only control the default
behavior, while the code is always compiled in.

[1] https://lore.kernel.org/all/cover.1794506262.git.chris@xxxxxxxxxxxxxx/
[2] https://lore.kernel.org/all/20261129212551.1812084-3-rientjes@xxxxxxxxxx/

Signed-off-by: Vlastimil Babka (SUSE) <vbabka@xxxxxxxxxx>
---
Changes in v2:
- Make sure token parameter is passed to the new entry points (Harry).
- Inline ___do_kmalloc_node() as explained above.
- Link to v1: https://patch.msgid.link/20261124-kmalloc-entry-rework-v1-0-37b1631a67b5@xxxxxxxxxx

---
Vlastimil Babka (SUSE) (3):
mm/slab: add ___do_kmalloc_node() to deduplicate code
mm/slab: add own entry points for kmem_buckets_alloc() family
mm/slab: drop BUCKET_PARAMS and KMALLOC_PARAMS macros

include/linux/slab.h | 64 ++++++++++------------
mm/slub.c | 149 +++++++++++++++++++++++++++++++++++----------------
2 files changed, 133 insertions(+), 80 deletions(-)
---
base-commit: bc8dbe6c5b86e3e6331f589166afb7d310b604d2
change-id: 20261116-kmalloc-entry-rework-a0162912968b