From: Danilo Krummrich <dakr@kernel.org>
To: Vitaly Wool <vitaly.wool@konsulko.se>
Cc: linux-mm@kvack.org, akpm@linux-foundation.org,
linux-kernel@vger.kernel.org, Uladzislau Rezki <urezki@gmail.com>,
Alice Ryhl <aliceryhl@google.com>,
rust-for-linux@vger.kernel.org
Subject: Re: [PATCH v4 4/4] rust: support NUMA ids in allocations
Date: Thu, 26 Jun 2025 14:40:22 +0200 [thread overview]
Message-ID: <aF0_tm04Y8MsqVzZ@pollux> (raw)
In-Reply-To: <20250626083653.3596424-1-vitaly.wool@konsulko.se>
On Thu, Jun 26, 2025 at 10:36:53AM +0200, Vitaly Wool wrote:
> Add support for specifying NUMA ids in Rust allocators as an Option
> (i. e. providing `None` as nid corresponds to NUMA_NO_NODE). This
> will allow to specify node to use for allocation of e. g. {KV}Box.
>
> Signed-off-by: Vitaly Wool <vitaly.wool@konsulko.se>
> ---
> rust/helpers/slab.c | 9 +++++----
> rust/helpers/vmalloc.c | 4 ++--
> rust/kernel/alloc.rs | 28 ++++++++++++++++++++++++++--
> rust/kernel/alloc/allocator.rs | 26 ++++++++++++++++++--------
> rust/kernel/alloc/kvec.rs | 3 ++-
> 5 files changed, 53 insertions(+), 17 deletions(-)
>
> diff --git a/rust/helpers/slab.c b/rust/helpers/slab.c
> index 5e9e8dd2bba0..ab1cf72f8353 100644
> --- a/rust/helpers/slab.c
> +++ b/rust/helpers/slab.c
> @@ -3,13 +3,14 @@
> #include <linux/slab.h>
>
> void * __must_check __realloc_size(2)
> -rust_helper_krealloc(const void *objp, size_t new_size, unsigned long align, gfp_t flags)
> +rust_helper_krealloc_node(const void *objp, size_t new_size, unsigned long align, gfp_t flags,
> + int nid)
> {
> - return krealloc(objp, new_size, flags);
> + return krealloc_node(objp, new_size, flags, nid);
> }
>
> void * __must_check __realloc_size(2)
> -rust_helper_kvrealloc(const void *p, size_t size, unsigned long align, gfp_t flags)
> +rust_helper_kvrealloc_node(const void *p, size_t size, unsigned long align, gfp_t flags, int nid)
> {
> - return kvrealloc(p, size, flags);
> + return kvrealloc_node(p, size, flags, nid);
> }
Same as in the previous patch, please keep those as "normal" helpers for
*realloc_node() and create the corresponding *realloc_node_align() helpers
discarding the argument on the Rust side.
> diff --git a/rust/kernel/alloc.rs b/rust/kernel/alloc.rs
> index a2c49e5494d3..1e26c2a7f47c 100644
> --- a/rust/kernel/alloc.rs
> +++ b/rust/kernel/alloc.rs
> @@ -156,7 +156,30 @@ pub unsafe trait Allocator {
> fn alloc(layout: Layout, flags: Flags) -> Result<NonNull<[u8]>, AllocError> {
> // SAFETY: Passing `None` to `realloc` is valid by its safety requirements and asks for a
> // new memory allocation.
> - unsafe { Self::realloc(None, layout, Layout::new::<()>(), flags) }
> + unsafe { Self::realloc(None, layout, Layout::new::<()>(), flags, None) }
> + }
> +
> + /// Allocate memory based on `layout`, `flags` and `nid`.
> + ///
> + /// On success, returns a buffer represented as `NonNull<[u8]>` that satisfies the layout
> + /// constraints (i.e. minimum size and alignment as specified by `layout`).
> + ///
> + /// This function is equivalent to `realloc` when called with `None`.
> + ///
> + /// # Guarantees
> + ///
> + /// When the return value is `Ok(ptr)`, then `ptr` is
> + /// - valid for reads and writes for `layout.size()` bytes, until it is passed to
> + /// [`Allocator::free`] or [`Allocator::realloc`],
> + /// - aligned to `layout.align()`,
> + ///
> + /// Additionally, `Flags` are honored as documented in
> + /// <https://docs.kernel.org/core-api/mm-api.html#mm-api-gfp-flags>.
> + fn alloc_node(layout: Layout, flags: Flags, nid: Option<i32>)
> + -> Result<NonNull<[u8]>, AllocError> {
> + // SAFETY: Passing `None` to `realloc` is valid by its safety requirements and asks for a
> + // new memory allocation.
> + unsafe { Self::realloc(None, layout, Layout::new::<()>(), flags, nid) }
> }
>
> /// Re-allocate an existing memory allocation to satisfy the requested `layout`.
> @@ -196,6 +219,7 @@ unsafe fn realloc(
> layout: Layout,
> old_layout: Layout,
> flags: Flags,
> + nid: Option<i32>,
> ) -> Result<NonNull<[u8]>, AllocError>;
I think you did forget to add realloc_node() as requested in the last iteration.
prev parent reply other threads:[~2025-06-26 12:40 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-26 8:35 [PATCH v4 0/4] support large align and nid in Rust allocators Vitaly Wool
2025-06-26 8:36 ` [PATCHi v4 1/4] mm/vmalloc: allow to set node and align in vrealloc Vitaly Wool
2025-06-26 8:36 ` [PATCH v4 2/4] mm/slub: allow to set node and align in k[v]realloc Vitaly Wool
2025-06-26 20:53 ` Tamir Duberstein
2025-06-27 18:10 ` Vitaly Wool
2025-06-26 8:36 ` [PATCH v4 3/4] rust: support large alignments in allocations Vitaly Wool
2025-06-26 12:36 ` Danilo Krummrich
2025-06-26 16:29 ` Vitaly Wool
2025-06-26 17:58 ` Danilo Krummrich
2025-06-26 8:36 ` [PATCH v4 4/4] rust: support NUMA ids " Vitaly Wool
2025-06-26 12:40 ` Danilo Krummrich [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=aF0_tm04Y8MsqVzZ@pollux \
--to=dakr@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=aliceryhl@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=urezki@gmail.com \
--cc=vitaly.wool@konsulko.se \
/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;
as well as URLs for NNTP newsgroup(s).