All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Gary Guo" <gary@garyguo.net>
To: "Andreas Hindborg" <a.hindborg@kernel.org>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <lossin@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"Daniel Almeida" <daniel.almeida@collabora.com>,
	"Tamir Duberstein" <tamird@kernel.org>,
	"Alexandre Courbot" <acourbot@nvidia.com>,
	"Onur Özkan" <work@onurozkan.dev>,
	"Thomas Gleixner" <tglx@kernel.org>,
	"Peter Zijlstra" <peterz@infradead.org>,
	"Lorenzo Stoakes" <ljs@kernel.org>,
	"Vlastimil Babka" <vbabka@kernel.org>,
	"Liam R. Howlett" <liam@infradead.org>,
	"Uladzislau Rezki" <urezki@gmail.com>
Cc: <linux-kernel@vger.kernel.org>, <rust-for-linux@vger.kernel.org>
Subject: Re: [PATCH v3 3/3] rust: alloc: move `NumaNode` to the `numa` module
Date: Wed, 30 Sep 2026 16:12:54 +0100	[thread overview]
Message-ID: <DLSQY2IKU5IO.3BFLXTCTJ5I6U@garyguo.net> (raw)
In-Reply-To: <20260929-cpu-helpers-v3-3-e968ce5ee613@kernel.org>

On Tue Sep 29, 2026 at 6:56 PM BST, Andreas Hindborg wrote:
> `NumaNode` identifies a NUMA node and is not specific to the allocator API.
> Move it from the `alloc` module to the `numa` module so that NUMA related
> items live together.
>
> No functional change.
>
> Suggested-by: Alice Ryhl <aliceryhl@google.com>
> Link: https://lore.kernel.org/all/aiZvKPFCkqJUsP0a@google.com/
> Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
> ---
>  rust/kernel/alloc.rs           | 30 ++++--------------------------
>  rust/kernel/alloc/allocator.rs |  6 +++---
>  rust/kernel/alloc/kbox.rs      |  4 ++--
>  rust/kernel/alloc/kvec.rs      |  4 ++--
>  rust/kernel/numa.rs            | 35 ++++++++++++++++++++++++++++++++++-
>  5 files changed, 45 insertions(+), 34 deletions(-)
>
> diff --git a/rust/kernel/alloc.rs b/rust/kernel/alloc.rs
> index 21067bde6860..9daddf540e7d 100644
> --- a/rust/kernel/alloc.rs
> +++ b/rust/kernel/alloc.rs
> @@ -22,7 +22,10 @@
>  #[derive(Copy, Clone, PartialEq, Eq, Debug)]
>  pub struct AllocError;
>  
> -use crate::prelude::*;
> +use crate::{
> +    numa::NumaNode,
> +    prelude::*, //
> +};
>  
>  use core::{
>      alloc::Layout,
> @@ -114,31 +117,6 @@ pub mod flags {
>      pub const __GFP_NOWARN: Flags = Flags(bindings::__GFP_NOWARN);
>  }
>  
> -/// Non Uniform Memory Access (NUMA) node identifier.
> -#[derive(Clone, Copy, PartialEq)]
> -pub struct NumaNode(i32);
> -
> -impl NumaNode {
> -    /// Create a new NUMA node identifier (non-negative integer).
> -    ///
> -    /// Returns [`EINVAL`] if a negative id or an id exceeding [`bindings::MAX_NUMNODES`] is
> -    /// specified.
> -    pub fn new(node: i32) -> Result<Self> {
> -        // MAX_NUMNODES never exceeds 2**10 because NODES_SHIFT is 0..10.
> -        if node < 0 || node >= bindings::MAX_NUMNODES as i32 {
> -            return Err(EINVAL);
> -        }
> -        Ok(Self(node))
> -    }
> -}
> -
> -/// 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.
> -    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
> diff --git a/rust/kernel/alloc/allocator.rs b/rust/kernel/alloc/allocator.rs
> index cd4203f27aed..4af50e20933b 100644
> --- a/rust/kernel/alloc/allocator.rs
> +++ b/rust/kernel/alloc/allocator.rs
> @@ -11,12 +11,12 @@
>  use super::{
>      AllocError,
>      Allocator,
> -    Flags,
> -    NumaNode, //
> +    Flags, //
>  };
>  
>  use crate::{
>      bindings,
> +    numa::NumaNode,
>      page, //
>  };
>  
> @@ -122,7 +122,7 @@ unsafe fn call(
>          // - Those functions provide the guarantees of this function.
>          let raw_ptr = unsafe {
>              // If `size == 0` and `ptr != NULL` the memory behind the pointer is freed.
> -            self.0(ptr.cast(), size, layout.align(), flags.0, nid.0).cast()
> +            self.0(ptr.cast(), size, layout.align(), flags.0, nid.as_raw()).cast()
>          };
>  
>          let ptr = if size == 0 {
> diff --git a/rust/kernel/alloc/kbox.rs b/rust/kernel/alloc/kbox.rs
> index c63d6acdbb6f..0fa736c81287 100644
> --- a/rust/kernel/alloc/kbox.rs
> +++ b/rust/kernel/alloc/kbox.rs
> @@ -13,12 +13,12 @@
>  use super::{
>      AllocError,
>      Allocator,
> -    Flags,
> -    NumaNode, //
> +    Flags, //
>  };
>  
>  use crate::{
>      fmt,
> +    numa::NumaNode,
>      page::AsPageIter,
>      prelude::*,
>      types::ForeignOwnable, //
> diff --git a/rust/kernel/alloc/kvec.rs b/rust/kernel/alloc/kvec.rs
> index c7546b9da4fa..b669ca10b3f7 100644
> --- a/rust/kernel/alloc/kvec.rs
> +++ b/rust/kernel/alloc/kvec.rs
> @@ -14,12 +14,12 @@
>      AllocError,
>      Allocator,
>      Box,
> -    Flags,
> -    NumaNode, //
> +    Flags, //
>  };
>  
>  use crate::{
>      fmt,
> +    numa::NumaNode,
>      page::{
>          AsPageIter,
>          PAGE_SIZE, //
> diff --git a/rust/kernel/numa.rs b/rust/kernel/numa.rs
> index 164e622d325f..4a3a880308f3 100644
> --- a/rust/kernel/numa.rs
> +++ b/rust/kernel/numa.rs
> @@ -4,12 +4,15 @@
>  //!
>  //! C header: [`include/linux/nodemask.h`](srctree/include/linux/nodemask.h)
>  
> -use crate::bindings;
>  #[cfg(CONFIG_NUMA)]
>  use crate::sync::atomic::{
>      Atomic,
>      Relaxed, //
>  };
> +use crate::{
> +    bindings,
> +    prelude::*, //
> +};
>  
>  /// Returns the number of online NUMA nodes.
>  #[inline]
> @@ -27,3 +30,33 @@ pub fn num_online_nodes() -> u32 {
>          bindings::nr_online_nodes
>      }
>  }
> +
> +/// Non Uniform Memory Access (NUMA) node identifier.
> +#[derive(Clone, Copy, PartialEq)]
> +pub struct NumaNode(i32);

FWIW the C type is nodemask_t and this should have mask in the name too. It is
not an identifier. That said, this is an existing issue, so shouldn't block the
move.

Best,
Gary

> +
> +impl NumaNode {
> +    /// Create a new NUMA node identifier (non-negative integer).
> +    ///
> +    /// Returns [`EINVAL`] if a negative id or an id exceeding [`bindings::MAX_NUMNODES`] is
> +    /// specified.
> +    pub fn new(node: i32) -> Result<Self> {
> +        // MAX_NUMNODES never exceeds 2**10 because NODES_SHIFT is 0..10.
> +        if node < 0 || node >= bindings::MAX_NUMNODES as i32 {
> +            return Err(EINVAL);
> +        }
> +        Ok(Self(node))
> +    }
> +
> +    /// Get the raw representation of this node identifier.
> +    pub(crate) fn as_raw(self) -> i32 {
> +        self.0
> +    }
> +}
> +
> +/// 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.
> +    pub const NO_NODE: NumaNode = NumaNode(bindings::NUMA_NO_NODE);
> +}



      reply	other threads:[~2026-09-30 15:13 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-29 17:56 [PATCH v3 0/3] rust: add a few helpers Andreas Hindborg
2026-09-29 17:56 ` [PATCH v3 1/3] rust: add a wrapper for the `num_possible_cpus` C function Andreas Hindborg
2026-09-29 18:30   ` Miguel Ojeda
2026-09-30  7:46     ` Andreas Hindborg
2026-09-30 10:25       ` Miguel Ojeda
2026-09-30 11:34         ` Andreas Hindborg
2026-09-30 11:38           ` Miguel Ojeda
2026-10-01 20:15             ` Miguel Ojeda
2026-10-02  8:33               ` Andreas Hindborg
2026-10-02  9:07                 ` Miguel Ojeda
2026-10-02  9:24   ` Peter Zijlstra
2026-10-03 12:03     ` Andreas Hindborg
2026-09-29 17:56 ` [PATCH v3 2/3] rust: add a wrapper for the `nr_online_nodes` " Andreas Hindborg
2026-09-30 15:14   ` Gary Guo
2026-09-29 17:56 ` [PATCH v3 3/3] rust: alloc: move `NumaNode` to the `numa` module Andreas Hindborg
2026-09-30 15:12   ` Gary Guo [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=DLSQY2IKU5IO.3BFLXTCTJ5I6U@garyguo.net \
    --to=gary@garyguo.net \
    --cc=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun@kernel.org \
    --cc=dakr@kernel.org \
    --cc=daniel.almeida@collabora.com \
    --cc=liam@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ljs@kernel.org \
    --cc=lossin@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tamird@kernel.org \
    --cc=tglx@kernel.org \
    --cc=tmgross@umich.edu \
    --cc=urezki@gmail.com \
    --cc=vbabka@kernel.org \
    --cc=work@onurozkan.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 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.