[PATCH] rust: xarray: optimize lock functions with inline attribute

lingfuyi@126.com posted 1 patch 1 month, 2 weeks ago
rust/kernel/xarray.rs | 2 ++
1 file changed, 2 insertions(+)
[PATCH] rust: xarray: optimize lock functions with inline attribute
Posted by lingfuyi@126.com 1 month, 2 weeks ago
From: lingfuyi <lingfuyi@kylinos.cn>

The XArray lock and try_lock functions are simple wrappers around
the C functions xa_lock and xa_trylock. These Rust functions don't
add significant logic beyond the unsafe FFI calls and safety guarantees.

Mark them as inline to avoid unnecessary function call overhead in
hot paths where XArray locking is frequent, such as in page cache
operations and other kernel data structure management.

This follows the same optimization pattern as other Rust kernel
modules where simple C function wrappers are marked inline to
improve performance.

Signed-off-by: lingfuyi <lingfuyi@kylinos.cn>
---
 rust/kernel/xarray.rs | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/rust/kernel/xarray.rs b/rust/kernel/xarray.rs
index a49d6db28845..c96589f92927 100644
--- a/rust/kernel/xarray.rs
+++ b/rust/kernel/xarray.rs
@@ -119,6 +119,7 @@ fn iter(&self) -> impl Iterator<Item = NonNull<c_void>> + '_ {
     }
 
     /// Attempts to lock the [`XArray`] for exclusive access.
+    #[inline]
     pub fn try_lock(&self) -> Option<Guard<'_, T>> {
         // SAFETY: `self.xa` is always valid by the type invariant.
         if (unsafe { bindings::xa_trylock(self.xa.get()) } != 0) {
@@ -132,6 +133,7 @@ pub fn try_lock(&self) -> Option<Guard<'_, T>> {
     }
 
     /// Locks the [`XArray`] for exclusive access.
+    #[inline]
     pub fn lock(&self) -> Guard<'_, T> {
         // SAFETY: `self.xa` is always valid by the type invariant.
         unsafe { bindings::xa_lock(self.xa.get()) };
-- 
2.34.1
Re: [PATCH] rust: xarray: optimize lock functions with inline attribute
Posted by Miguel Ojeda 1 month, 2 weeks ago
On Mon, Aug 18, 2025 at 3:27 AM <lingfuyi@126.com> wrote:
>
> Signed-off-by: lingfuyi <lingfuyi@kylinos.cn>

The kernel requires using a "known identity" (typically meaning the
full/real name) -- please see
https://docs.kernel.org/process/submitting-patches.html#developer-s-certificate-of-origin-1-1

Also, please do not resend patches with the same title -- you should
increase the version number if you do so (or, in this case, if you
just wanted to Cc people, you can do that replying to the patch,
saying who you are Cc'ing).

Cheers,
Miguel
Re: [PATCH] rust: xarray: optimize lock functions with inline attribute
Posted by Miguel Ojeda 1 month, 2 weeks ago
On Mon, Aug 18, 2025 at 10:05 AM Miguel Ojeda
<miguel.ojeda.sandonis@gmail.com> wrote:
>
> The kernel requires using a "known identity" (typically meaning the
> full/real name) -- please see
> https://docs.kernel.org/process/submitting-patches.html#developer-s-certificate-of-origin-1-1
>
> Also, please do not resend patches with the same title -- you should
> increase the version number if you do so (or, in this case, if you
> just wanted to Cc people, you can do that replying to the patch,
> saying who you are Cc'ing).

By the way, the From header, generally, should match that too
(otherwise the "From" line gets added in the body, here because you
use a different domain).

Thanks!

Cheers,
Miguel
Re: [PATCH] rust: xarray: optimize lock functions with inline attribute
Posted by Alice Ryhl 1 month, 2 weeks ago
On Mon, Aug 18, 2025 at 3:27 AM <lingfuyi@126.com> wrote:
>
> From: lingfuyi <lingfuyi@kylinos.cn>
>
> The XArray lock and try_lock functions are simple wrappers around
> the C functions xa_lock and xa_trylock. These Rust functions don't
> add significant logic beyond the unsafe FFI calls and safety guarantees.
>
> Mark them as inline to avoid unnecessary function call overhead in
> hot paths where XArray locking is frequent, such as in page cache
> operations and other kernel data structure management.
>
> This follows the same optimization pattern as other Rust kernel
> modules where simple C function wrappers are marked inline to
> improve performance.
>
> Signed-off-by: lingfuyi <lingfuyi@kylinos.cn>

Thanks for the patch. Please see the Developer’s Certificate of Origin 1.1
https://docs.kernel.org/process/submitting-patches.html#developer-s-certificate-of-origin-1-1

You need to use a known identity such as your real name to submit
patches to the kernel. Anonymous contributions aren't possible.

Also please include a version number in the email subject when sending
a new version of a patch.

Alice