From: "Harry Yoo (Oracle)" <harry@kernel.org>
To: Marco Elver <elver@google.com>
Cc: Vlastimil Babka <vbabka@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Nathan Chancellor <nathan@kernel.org>,
Nicolas Schier <nsc@kernel.org>, Dennis Zhou <dennis@kernel.org>,
Tejun Heo <tj@kernel.org>, Christoph Lameter <cl@gentwo.org>,
Hao Li <hao.li@linux.dev>, David Rientjes <rientjes@google.com>,
Roman Gushchin <roman.gushchin@linux.dev>,
Kees Cook <kees@kernel.org>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
David Hildenbrand <david@kernel.org>,
Lorenzo Stoakes <ljs@kernel.org>,
"Liam R. Howlett" <Liam.Howlett@oracle.com>,
Mike Rapoport <rppt@kernel.org>,
Suren Baghdasaryan <surenb@google.com>,
Michal Hocko <mhocko@suse.com>,
Alexander Potapenko <glider@google.com>,
Dmitry Vyukov <dvyukov@google.com>,
Nick Desaulniers <nick.desaulniers+lkml@gmail.com>,
Bill Wendling <morbo@google.com>,
Justin Stitt <justinstitt@google.com>,
linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-mm@kvack.org, linux-hardening@vger.kernel.org,
kasan-dev@googlegroups.com, llvm@lists.linux.dev,
Andrey Konovalov <andreyknvl@gmail.com>,
Florent Revest <revest@google.com>, Jann Horn <jannh@google.com>,
KP Singh <kpsingh@kernel.org>,
Matteo Rizzo <matteorizzo@google.com>,
GONG Ruiqi <gongruiqi1@huawei.com>,
Danilo Krummrich <dakr@kernel.org>,
Uladzislau Rezki <urezki@gmail.com>,
rust-for-linux@vger.kernel.org
Subject: Re: [PATCH v2] slab: support for compiler-assisted type-based slab cache partitioning
Date: Mon, 20 Apr 2026 19:28:17 +0900 [thread overview]
Message-ID: <aeX_wbOBX3l8PJqi@hyeyoo> (raw)
In-Reply-To: <CANpmjNN0dYD8MB3PpPoxpz4ey2U9xA0w6oVO9hambtRwzSSkiQ@mail.gmail.com>
On Mon, Apr 20, 2026 at 11:30:23AM +0200, Marco Elver wrote:
> On Mon, 20 Apr 2026 at 09:25, Harry Yoo (Oracle) <harry@kernel.org> wrote:
> > [CC'ing RUST ALLOC folks for rust bindings]
> > On Wed, Apr 15, 2026 at 04:37:05PM +0200, Marco Elver wrote:
> > A few comments on V2:
> >
> > # comment 1
> >
> > I'm not a big fan of how k[v]realloc_node_align()
> > and kmalloc_nolock() define and pass the token parameter.
> >
> > IMHO it'll be fine to use {DECL,PASS}_KMALLOC_PARAMS() in those
> > functions, since SLAB_BUCKETS users already passes NULL bucket
> > to most of __kmalloc*() calls anyway.
>
> I'm not sure I agree. 2 reasons:
>
> 1. Even though it's "just" k[v]realloc_node_align() and
> kmalloc_nolock() - despite their relatively less frequent use - just
> put one of them in a hot path and you're sacrificing performance even
> further. There are only so many arguments that can be passed in
> registers (depending on arch), and may cause more stack spilling.
>
> 2. We'd misleadingly declare that these functions do something with
> the bucket arg. This is wrong.
Both are valid points. But it still feels wrong to have:
void *krealloc_node_align_noprof(const void *objp, size_t new_size,
unsigned long align,
gfp_t flags, int nid DECL_TOKEN_PARAM(token));
n = krealloc_node_align_noprof(p, size, align, kmalloc_gfp_adjust(flags, size), nid _PASS_TOKEN_PARAM(token));
Actually the problem here is that some of parameters in
DECL_KMALLOC_PARAMS() are not necessary in some functions.
Perhaps we could have
DECL_KMALLOC_PARAMS(size, b, token) # declare size, bucket, token
DECL_BUCKET_PARAMS(size, token) # declare size, bucket;
# but, actually, we don't need this!
DECL_TOKEN_PARAMS(size, b) # declare size, token only;
# for kmalloc_nolock and k[v]realloc_node_align()
and use DECL_TOKEN_PARAMS(), PASS_TOKEN_PARAMS() for those functions?
(just like how DECL_BUCKET_PARAMS() worked before)
What do you think?
> Both feels wrong, and would only make this change if you confirm both
> are trade-offs that you strongly prefer.
>
> > # comment 2
> >
> > This breaks Documentation/.
> >
> > Problems:
> >
> > - The document generator doesn't handle DECL_KMALLOC_PARAMS() well.
> >
> > - The signature of the function that users call (krealloc_node_align())
> > and the function that has kerneldoc (krealloc_node_align_noprof())
> > don't match.
> >
> > - Even worse, moving kerneldoc to the macro doesn't work because
> > it uses variable arguments (...)
>
> Well, some were broken before, now it's just broken more. :-)
Ouch... ;-)
> We could move the documentation to macros and switch to explicit args
> instead of (...).
That works for me!
> Otherwise, I don't see any way to fix this. Preferences?
>
> > # comment 3
> >
> > Looking at how rust generates helper functions,
> > in rust/helpers/slab.c:
> > | // SPDX-License-Identifier: GPL-2.0
> > |
> > | #include <linux/slab.h>
> > |
> > | __rust_helper void *__must_check __realloc_size(2)
> > | rust_helper_krealloc_node_align(const void *objp, size_t new_size, unsigned long align,
> > | gfp_t flags, int node)
> > | {
> > | return krealloc_node_align(objp, new_size, align, flags, node);
> > | }
> > |
> > | __rust_helper void *__must_check __realloc_size(2)
> > | rust_helper_kvrealloc_node_align(const void *p, size_t size, unsigned long align,
> > | gfp_t flags, int node)
> > | {
> > | return kvrealloc_node_align(p, size, align, flags, node);
> > | }
> >
> > Rust code probably won't pass any meaningful token?
> > (something you may want to address in the future)
>
> Yes, it'll just pass '0' by default. We could force Rust's allocation
> to be in the pointer-containing range - if we assume Rust code is less
> prone to contain bugs, but the assumption is that such allocations
> both originate and are confined to the Rust side. One easy way to do
> this is to write:
>
> return kvrealloc_node_align(p, size + 0 * sizeof(long*), align,
> flags, node);
>
> But I'd defer that for now, until we're sure the above assumption
> holds (Rust originated + confined).
Ack.
By the way, since Allocator trait uses realloc() to allocate new memory,
IIUC all k[v]malloc, k[v]realloc usage from Rust will be affected.
--
Cheers,
Harry / Hyeonggon
prev parent reply other threads:[~2026-04-20 10:28 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-15 14:37 Marco Elver
2026-04-16 13:42 ` Marco Elver
2026-04-20 7:25 ` Harry Yoo (Oracle)
2026-04-20 9:30 ` Marco Elver
2026-04-20 10:28 ` Harry Yoo (Oracle) [this message]
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=aeX_wbOBX3l8PJqi@hyeyoo \
--to=harry@kernel.org \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=andreyknvl@gmail.com \
--cc=cl@gentwo.org \
--cc=dakr@kernel.org \
--cc=david@kernel.org \
--cc=dennis@kernel.org \
--cc=dvyukov@google.com \
--cc=elver@google.com \
--cc=glider@google.com \
--cc=gongruiqi1@huawei.com \
--cc=gustavoars@kernel.org \
--cc=hao.li@linux.dev \
--cc=jannh@google.com \
--cc=justinstitt@google.com \
--cc=kasan-dev@googlegroups.com \
--cc=kees@kernel.org \
--cc=kpsingh@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=llvm@lists.linux.dev \
--cc=matteorizzo@google.com \
--cc=mhocko@suse.com \
--cc=morbo@google.com \
--cc=nathan@kernel.org \
--cc=nick.desaulniers+lkml@gmail.com \
--cc=nsc@kernel.org \
--cc=revest@google.com \
--cc=rientjes@google.com \
--cc=roman.gushchin@linux.dev \
--cc=rppt@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=surenb@google.com \
--cc=tj@kernel.org \
--cc=urezki@gmail.com \
--cc=vbabka@kernel.org \
/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