From: "Vlastimil Babka (SUSE)" <vbabka@kernel.org>
To: Harry Yoo <harry@kernel.org>
Cc: Chris Down <chris@chrisdown.name>, Kees Cook <kees@kernel.org>,
Hao Li <hao.li@linux.dev>, Christoph Lameter <cl@gentwo.org>,
David Rientjes <rientjes@google.com>,
Roman Gushchin <roman.gushchin@linux.dev>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
"Vlastimil Babka (SUSE)" <vbabka@kernel.org>
Subject: [PATCH v2 1/3] mm/slab: add ___do_kmalloc_node() to deduplicate code
Date: Thu, 03 Dec 2026 14:42:18 +0100 [thread overview]
Message-ID: <20261203-kmalloc-entry-rework-v2-1-d718dc4fd906@kernel.org> (raw)
In-Reply-To: <20261203-kmalloc-entry-rework-v2-0-d718dc4fd906@kernel.org>
Most kmalloc family entry points end up performing __do_kmalloc_node().
What it does are roughly two phases. First, selecting the right cache
via kmalloc_slab(). Second, performing slab_alloc_node(),
kasan_kmalloc() and trace_kmalloc().
__kmalloc_cache_noprof() and __kmalloc_cache_node_noprof() already have
the cache pointer, so they both opencode the second phase. Add
___do_kmalloc_node() for the second phase, called by both of those and
__do_kmalloc_node().
Make it also inline so the whole kmalloc fast path keeps being inlined.
An attempt to not make it inlined resulted in a visible slab kunit
benchmark regression.
Signed-off-by: Vlastimil Babka (SUSE) <vbabka@kernel.org>
---
mm/slub.c | 35 +++++++++++++++++------------------
1 file changed, 17 insertions(+), 18 deletions(-)
diff --git a/mm/slub.c b/mm/slub.c
index 145a32c334cb..ff69988204c1 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -5512,6 +5512,19 @@ void *__kmalloc_large_node_noprof(size_t size, gfp_t flags, int node)
}
EXPORT_SYMBOL(__kmalloc_large_node_noprof);
+static __always_inline
+void *___do_kmalloc_node(struct kmem_cache *s, gfp_t flags, int node,
+ const struct slab_alloc_context *ac)
+{
+ void *ret;
+
+ ret = slab_alloc_node(s, flags, node, ac);
+ ret = kasan_kmalloc(s, ret, ac->orig_size, flags);
+ trace_kmalloc(ac->caller_addr, ret, ac->orig_size, s->size, flags, node);
+
+ return ret;
+}
+
static __always_inline
void *__do_kmalloc_node(kmem_buckets *b, gfp_t flags, int node,
kmalloc_token_t token, const struct slab_alloc_context *ac)
@@ -5532,11 +5545,9 @@ void *__do_kmalloc_node(kmem_buckets *b, gfp_t flags, int node,
s = kmalloc_slab(size, b, flags, token, ac->alloc_flags);
- ret = slab_alloc_node(s, flags, node, ac);
- ret = kasan_kmalloc(s, ret, size, flags);
- trace_kmalloc(ac->caller_addr, ret, size, s->size, flags, node);
- return ret;
+ return ___do_kmalloc_node(s, flags, node, ac);
}
+
void *__kmalloc_node_noprof(DECL_KMALLOC_PARAMS(size, b, token), gfp_t flags, int node)
{
const struct slab_alloc_context ac = {
@@ -5671,38 +5682,26 @@ EXPORT_SYMBOL(__kmalloc_node_track_caller_noprof);
void *__kmalloc_cache_noprof(struct kmem_cache *s, gfp_t gfpflags, size_t size)
{
- void *ret;
const struct slab_alloc_context ac = {
.caller_addr = _RET_IP_,
.orig_size = size,
.alloc_flags = SLAB_ALLOC_DEFAULT,
};
- ret = slab_alloc_node(s, gfpflags, NUMA_NO_NODE, &ac);
-
- trace_kmalloc(_RET_IP_, ret, size, s->size, gfpflags, NUMA_NO_NODE);
-
- ret = kasan_kmalloc(s, ret, size, gfpflags);
- return ret;
+ return ___do_kmalloc_node(s, gfpflags, NUMA_NO_NODE, &ac);
}
EXPORT_SYMBOL(__kmalloc_cache_noprof);
void *__kmalloc_cache_node_noprof(struct kmem_cache *s, gfp_t gfpflags,
int node, size_t size)
{
- void *ret;
const struct slab_alloc_context ac = {
.caller_addr = _RET_IP_,
.orig_size = size,
.alloc_flags = SLAB_ALLOC_DEFAULT,
};
- ret = slab_alloc_node(s, gfpflags, node, &ac);
-
- trace_kmalloc(_RET_IP_, ret, size, s->size, gfpflags, node);
-
- ret = kasan_kmalloc(s, ret, size, gfpflags);
- return ret;
+ return ___do_kmalloc_node(s, gfpflags, node, &ac);
}
EXPORT_SYMBOL(__kmalloc_cache_node_noprof);
--
2.56.1
next prev parent reply other threads:[~2026-12-03 13:43 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 13:42 [PATCH v2 0/3] kmem_buckets entry point rework Vlastimil Babka (SUSE)
2026-12-03 13:42 ` Vlastimil Babka (SUSE) [this message]
2026-12-03 13:42 ` [PATCH v2 2/3] mm/slab: add own entry points for kmem_buckets_alloc() family Vlastimil Babka (SUSE)
2026-12-03 13:42 ` [PATCH v2 3/3] mm/slab: drop BUCKET_PARAMS and KMALLOC_PARAMS macros Vlastimil Babka (SUSE)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261203-kmalloc-entry-rework-v2-1-d718dc4fd906@kernel.org \
--to=vbabka@kernel.org \
--cc=chris@chrisdown.name \
--cc=cl@gentwo.org \
--cc=hao.li@linux.dev \
--cc=harry@kernel.org \
--cc=kees@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=rientjes@google.com \
--cc=roman.gushchin@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox