[PATCH] rust: page: mark Page::nid as inline

Nakamura Shuta posted 1 patch 1 week, 3 days ago
rust/kernel/page.rs | 1 +
1 file changed, 1 insertion(+)
[PATCH] rust: page: mark Page::nid as inline
Posted by Nakamura Shuta 1 week, 3 days ago
When building the kernel, the following Rust symbol is generated:

  $ nm vmlinux | grep ' _R'.*Page | rustfilt
  <kernel::page::Page>::nid

`Page::nid` is a trivial wrapper around the C function `page_to_nid`.
It does not make sense to go through a trivial wrapper for this function,
so mark it inline.

This follows commit 878620c5a93a ("rust: page: optimize rust symbol
generation for Page"), which did the same for `alloc_page` and `drop`.

Link: https://github.com/Rust-for-Linux/linux/issues/1145
Signed-off-by: Nakamura Shuta <nakamura.shuta@gmail.com>
---
 rust/kernel/page.rs | 1 +
 1 file changed, 1 insertion(+)

diff --git a/rust/kernel/page.rs b/rust/kernel/page.rs
index adecb200c654..764bb5acc90a 100644
--- a/rust/kernel/page.rs
+++ b/rust/kernel/page.rs
@@ -193,6 +193,7 @@ pub fn as_ptr(&self) -> *mut bindings::page {
     }
 
     /// Get the node id containing this page.
+    #[inline]
     pub fn nid(&self) -> i32 {
         // SAFETY: Always safe to call with a valid page.
         unsafe { bindings::page_to_nid(self.as_ptr()) }

base-commit: 72d33b8bfeacbfdccf2cda4650e8e002def036f8
-- 
2.51.0
Re: [PATCH] rust: page: mark Page::nid as inline
Posted by Gary Guo 1 week, 2 days ago
On Fri May 29, 2026 at 9:53 AM BST, Nakamura Shuta wrote:
> When building the kernel, the following Rust symbol is generated:
> 
>   $ nm vmlinux | grep ' _R'.*Page | rustfilt
>   <kernel::page::Page>::nid
> 
> `Page::nid` is a trivial wrapper around the C function `page_to_nid`.
> It does not make sense to go through a trivial wrapper for this function,
> so mark it inline.
> 
> This follows commit 878620c5a93a ("rust: page: optimize rust symbol
> generation for Page"), which did the same for `alloc_page` and `drop`.
> 
> Link: https://github.com/Rust-for-Linux/linux/issues/1145
> Signed-off-by: Nakamura Shuta <nakamura.shuta@gmail.com>

Reviewed-by: Gary Guo <gary@garyguo.net>

> ---
>  rust/kernel/page.rs | 1 +
>  1 file changed, 1 insertion(+)
Re: [PATCH] rust: page: mark Page::nid as inline
Posted by Alice Ryhl 1 week, 3 days ago
On Fri, May 29, 2026 at 10:55 AM Nakamura Shuta
<nakamura.shuta@gmail.com> wrote:
>
> When building the kernel, the following Rust symbol is generated:
>
>   $ nm vmlinux | grep ' _R'.*Page | rustfilt
>   <kernel::page::Page>::nid
>
> `Page::nid` is a trivial wrapper around the C function `page_to_nid`.
> It does not make sense to go through a trivial wrapper for this function,
> so mark it inline.
>
> This follows commit 878620c5a93a ("rust: page: optimize rust symbol
> generation for Page"), which did the same for `alloc_page` and `drop`.
>
> Link: https://github.com/Rust-for-Linux/linux/issues/1145
> Signed-off-by: Nakamura Shuta <nakamura.shuta@gmail.com>

Reviewed-by: Alice Ryhl <aliceryhl@google.com>

Andrew, can you pick this? Thanks!