linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
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>
Subject: Re: [PATCH v11 3/4] rust: add support for NUMA ids in allocations
Date: Tue, 08 Jul 2025 14:15:49 +0200	[thread overview]
Message-ID: <DB6NZVF1X99Q.FWK3057UYE63@kernel.org> (raw)
In-Reply-To: <20250707164934.631500-1-vitaly.wool@konsulko.se>

On Mon Jul 7, 2025 at 6:49 PM CEST, Vitaly Wool wrote:
> +/// Specify necessary constant to pass the information to Allocator that the caller doesn't care
> +/// about the NUMA node to allocate memory from.
> +impl NumaNode {
> +    /// No node preference

Please end the comment with a period.

> +    pub const NO_NODE: NumaNode = NumaNode(bindings::NUMA_NO_NODE);
> +}
> +
>  /// The kernel's [`Allocator`] trait.
>  ///
>  /// An implementation of [`Allocator`] can allocate, re-allocate and free memory buffers described
> @@ -137,7 +162,7 @@ pub mod flags {
>  /// - Implementers must ensure that all trait functions abide by the guarantees documented in the
>  ///   `# Guarantees` sections.
>  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 +178,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

s/i. e./i.e./

> +    /// integer if a node needs to be specified, or NO_NODE if the caller doesn't care.

s/NO_NODE/[`NumaNode::NO_NODE`]/

>      ///
>      /// If the requested size is zero, `realloc` behaves equivalent to `free`.
>      ///
> @@ -196,6 +229,7 @@ unsafe fn realloc(

<snip>

> @@ -58,18 +58,23 @@ fn aligned_size(new_layout: Layout) -> usize {
>  ///
>  /// One of the following: `krealloc`, `vrealloc`, `kvrealloc`.

You have to adjust those as well, given that you refer to this invariant below.

>  struct ReallocFunc(
> -    unsafe extern "C" fn(*const crate::ffi::c_void, usize, u32) -> *mut crate::ffi::c_void,
> +    unsafe extern "C" fn(
> +        *const crate::ffi::c_void,
> +        usize,
> +        u32,
> +        crate::ffi::c_int,
> +    ) -> *mut crate::ffi::c_void,
>  );
>  
>  impl ReallocFunc {
> -    // INVARIANT: `krealloc` satisfies the type invariants.
> -    const KREALLOC: Self = Self(bindings::krealloc);
> +    // INVARIANT: `krealloc_node` satisfies the type invariants.
> +    const KREALLOC: Self = Self(bindings::krealloc_node);
>  
> -    // INVARIANT: `vrealloc` satisfies the type invariants.
> -    const VREALLOC: Self = Self(bindings::vrealloc);
> +    // INVARIANT: `vrealloc_node` satisfies the type invariants.
> +    const VREALLOC: Self = Self(bindings::vrealloc_node);
>  
> -    // INVARIANT: `kvrealloc` satisfies the type invariants.
> -    const KVREALLOC: Self = Self(bindings::kvrealloc);
> +    // INVARIANT: `kvrealloc_node` satisfies the type invariants.
> +    const KVREALLOC: Self = Self(bindings::kvrealloc_node);


  reply	other threads:[~2025-07-08 12:15 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-07 16:47 [PATCH v11 0/4] support large align and nid in Rust allocators Vitaly Wool
2025-07-07 16:48 ` [PATCH v11 1/4] mm/vmalloc: allow to set node and align in vrealloc Vitaly Wool
2025-07-08 12:12   ` Vlastimil Babka
2025-07-07 16:49 ` [PATCH v11 2/4] mm/slub: allow to set node and align in k[v]realloc Vitaly Wool
2025-07-08 12:52   ` Vlastimil Babka
2025-07-08 14:03     ` Vitaly Wool
2025-07-09 13:40       ` Vitaly Wool
2025-07-09 14:13         ` Vlastimil Babka
2025-07-07 16:49 ` [PATCH v11 3/4] rust: add support for NUMA ids in allocations Vitaly Wool
2025-07-08 12:15   ` Danilo Krummrich [this message]
2025-07-07 16:49 ` [PATCH v11 4/4] rust: support large alignments " Vitaly Wool
2025-07-08 12:16   ` Danilo Krummrich
2025-07-08 10:58 ` [PATCH v11 0/4] support large align and nid in Rust allocators Lorenzo Stoakes
2025-07-08 11:12   ` Lorenzo Stoakes
2025-07-08 11:55   ` Danilo Krummrich
2025-07-08 12:36     ` Lorenzo Stoakes
2025-07-08 13:41       ` Danilo Krummrich
2025-07-08 14:06         ` Lorenzo Stoakes
2025-07-08 13:19     ` Lorenzo Stoakes
2025-07-08 14:16       ` Danilo Krummrich
2025-07-08 14:39         ` Lorenzo Stoakes
2025-07-08 15:11           ` Danilo Krummrich
2025-07-08 15:40             ` Lorenzo Stoakes
2025-07-09 11:31       ` Alice Ryhl
2025-07-09 12:24         ` Lorenzo Stoakes

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=DB6NZVF1X99Q.FWK3057UYE63@kernel.org \
    --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=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 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).