rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rust: xarray: optimize lock functions with inline attribute
@ 2025-08-18  1:16 lingfuyi
  2025-08-20  3:33 ` Elle Rhumsaa
  0 siblings, 1 reply; 8+ messages in thread
From: lingfuyi @ 2025-08-18  1:16 UTC (permalink / raw)
  To: rust-for-linux; +Cc: lingfuyi

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


^ permalink raw reply related	[flat|nested] 8+ messages in thread
* [PATCH] rust: xarray: optimize lock functions with inline attribute
@ 2025-08-18  1:26 lingfuyi
  2025-08-18  8:04 ` Alice Ryhl
  2025-08-18  8:05 ` Miguel Ojeda
  0 siblings, 2 replies; 8+ messages in thread
From: lingfuyi @ 2025-08-18  1:26 UTC (permalink / raw)
  To: Tamir Duberstein, Andreas Hindborg
  Cc: Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Alice Ryhl, Trevor Gross,
	Danilo Krummrich, rust-for-linux, linux-kernel, lingfuyi

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


^ permalink raw reply related	[flat|nested] 8+ messages in thread
* [PATCH] rust: xarray: optimize lock functions with inline attribute
@ 2025-08-16  9:45 凌福义
  2025-08-16  9:58 ` Greg KH
  0 siblings, 1 reply; 8+ messages in thread
From: 凌福义 @ 2025-08-16  9:45 UTC (permalink / raw)
  To: rust-for-linux

[-- Attachment #1: Type: text/html, Size: 1697 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-08-20  3:34 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-18  1:16 [PATCH] rust: xarray: optimize lock functions with inline attribute lingfuyi
2025-08-20  3:33 ` Elle Rhumsaa
  -- strict thread matches above, loose matches on Subject: below --
2025-08-18  1:26 lingfuyi
2025-08-18  8:04 ` Alice Ryhl
2025-08-18  8:05 ` Miguel Ojeda
2025-08-18  8:10   ` Miguel Ojeda
2025-08-16  9:45 凌福义
2025-08-16  9:58 ` Greg KH

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).