[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250818012648.1841387-1-lingfuyi@126.com>
Date: Mon, 18 Aug 2025 01:26:48 +0000
From: lingfuyi@....com
To: Tamir Duberstein <tamird@...il.com>,
Andreas Hindborg <a.hindborg@...nel.org>
Cc: Miguel Ojeda <ojeda@...nel.org>,
Alex Gaynor <alex.gaynor@...il.com>,
Boqun Feng <boqun.feng@...il.com>,
Gary Guo <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Benno Lossin <lossin@...nel.org>,
Alice Ryhl <aliceryhl@...gle.com>,
Trevor Gross <tmgross@...ch.edu>,
Danilo Krummrich <dakr@...nel.org>,
rust-for-linux@...r.kernel.org,
linux-kernel@...r.kernel.org,
lingfuyi <lingfuyi@...inos.cn>
Subject: [PATCH] rust: xarray: optimize lock functions with inline attribute
From: lingfuyi <lingfuyi@...inos.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@...inos.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
Powered by blists - more mailing lists