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>,
"Vlastimil Babka" <vbabka@suse.cz>,
<rust-for-linux@vger.kernel.org>,
"Lorenzo Stoakes" <lorenzo.stoakes@oracle.com>,
"Liam R . Howlett" <Liam.Howlett@oracle.com>,
"Kent Overstreet" <kent.overstreet@linux.dev>,
<linux-bcachefs@vger.kernel.org>, <bpf@vger.kernel.org>,
"Herbert Xu" <herbert@gondor.apana.org.au>,
"Jann Horn" <jannh@google.com>,
"Pedro Falcato" <pfalcato@suse.de>
Subject: Re: [PATCH v13 3/4] rust: add support for NUMA ids in allocations
Date: Tue, 29 Jul 2025 10:25:33 +0200 [thread overview]
Message-ID: <DBOE907J16WH.1IOU3M11RX5SH@kernel.org> (raw)
In-Reply-To: <20250715135827.2230267-1-vitaly.wool@konsulko.se>
On Tue Jul 15, 2025 at 3:58 PM CEST, Vitaly Wool wrote:
> pub unsafe trait Allocator {
> - /// Allocate memory based on `layout` and `flags`.
> + /// 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`).
> @@ -153,13 +180,21 @@ pub unsafe trait Allocator {
> ///
> /// Additionally, `Flags` are honored as documented in
> /// <https://docs.kernel.org/core-api/mm-api.html#mm-api-gfp-flags>.
> - fn alloc(layout: Layout, flags: Flags) -> Result<NonNull<[u8]>, AllocError> {
> + fn alloc(layout: Layout, flags: Flags, nid: NumaNode) -> 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, nid) }
> }
>
> - /// Re-allocate an existing memory allocation to satisfy the requested `layout`.
> + /// Re-allocate an existing memory allocation to satisfy the requested `layout` and
> + /// a specific NUMA node request to allocate the memory for.
> + ///
> + /// Systems employing a Non Uniform Memory Access (NUMA) architecture contain collections of
> + /// hardware resources including processors, memory, and I/O buses, that comprise what is
> + /// commonly known as a NUMA node.
> + ///
> + /// `nid` stands for NUMA id, i. e. NUMA node identifier, which is a non-negative integer
> + /// if a node needs to be specified, or [`NumaNode::NO_NODE`] if the caller doesn't care.
> ///
> /// If the requested size is zero, `realloc` behaves equivalent to `free`.
> ///
> @@ -196,6 +231,7 @@ unsafe fn realloc(
> layout: Layout,
> old_layout: Layout,
> flags: Flags,
> + nid: NumaNode,
> ) -> Result<NonNull<[u8]>, AllocError>;
>
> /// Free an existing memory allocation.
> @@ -211,7 +247,15 @@ unsafe fn free(ptr: NonNull<u8>, layout: Layout) {
> // SAFETY: The caller guarantees that `ptr` points at a valid allocation created by this
> // allocator. We are passing a `Layout` with the smallest possible alignment, so it is
> // smaller than or equal to the alignment previously used with this allocation.
> - let _ = unsafe { Self::realloc(Some(ptr), Layout::new::<()>(), layout, Flags(0)) };
> + let _ = unsafe {
> + Self::realloc(
> + Some(ptr),
> + Layout::new::<()>(),
> + layout,
> + Flags(0),
> + NumaNode::NO_NODE,
> + )
> + };
> }
> }
Regarding the change in the Allocator trait, we also have to consider
the Cmalloc allocator in rust/kernel/alloc/allocator_test.rs, which is there to
support userspace tests.
While we're planning to remove this (see also [1]), we still have to consider
it for now.
[1] https://lore.kernel.org/rust-for-linux/20250726180750.2735836-1-ojeda@kernel.org/
next prev parent reply other threads:[~2025-07-29 8:25 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-15 13:56 [PATCH v13 0/4] support large align and nid in Rust allocators Vitaly Wool
2025-07-15 13:57 ` [PATCH v13 1/4] :mm/vmalloc: allow to set node and align in vrealloc Vitaly Wool
2025-07-15 14:37 ` Matthew Wilcox
2025-07-30 17:25 ` Vitaly Wool
2025-07-15 13:58 ` [PATCH v13 1/4] mm/vmalloc: " Vitaly Wool
2025-07-15 14:25 ` Liam R. Howlett
2025-07-15 13:58 ` [PATCH v13 2/4] mm/slub: allow to set node and align in k[v]realloc Vitaly Wool
2025-07-15 14:33 ` Danilo Krummrich
2025-07-15 15:34 ` Vlastimil Babka
2025-07-15 15:48 ` Danilo Krummrich
2025-07-15 16:12 ` Danilo Krummrich
2025-07-25 8:47 ` Vlastimil Babka
2025-07-15 13:58 ` [PATCH v13 3/4] rust: add support for NUMA ids in allocations Vitaly Wool
2025-07-24 9:27 ` Alice Ryhl
2025-07-29 8:25 ` Danilo Krummrich [this message]
2025-07-15 13:58 ` [PATCH v13 4/4] rust: support large alignments " Vitaly Wool
2025-07-24 9:27 ` Alice Ryhl
2025-07-24 20:54 ` [PATCH v13 0/4] support large align and nid in Rust allocators Andrew Morton
2025-07-25 7:14 ` Alice Ryhl
2025-07-25 8:26 ` Vlastimil Babka
2025-07-25 10:00 ` Danilo Krummrich
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=DBOE907J16WH.1IOU3M11RX5SH@kernel.org \
--to=dakr@kernel.org \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=aliceryhl@google.com \
--cc=bpf@vger.kernel.org \
--cc=herbert@gondor.apana.org.au \
--cc=jannh@google.com \
--cc=kent.overstreet@linux.dev \
--cc=linux-bcachefs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=pfalcato@suse.de \
--cc=rust-for-linux@vger.kernel.org \
--cc=urezki@gmail.com \
--cc=vbabka@suse.cz \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.