From: Elle Rhumsaa <elle@weathered-steel.dev>
To: lingfuyi@126.com
Cc: rust-for-linux@vger.kernel.org, lingfuyi <lingfuyi@kylinos.cn>
Subject: Re: [PATCH] rust: xarray: optimize lock functions with inline attribute
Date: Wed, 20 Aug 2025 03:33:52 +0000 [thread overview]
Message-ID: <aKVBx2HWamyG0SeD@archiso> (raw)
In-Reply-To: <20250818011612.1839789-1-lingfuyi@126.com>
On Mon, Aug 18, 2025 at 01:16:12AM +0000, 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>
> ---
> 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
Reviewed-by: Elle Rhumsaa <elle@weathered-steel.dev>
next prev parent reply other threads:[~2025-08-20 3:34 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-18 1:16 [PATCH] rust: xarray: optimize lock functions with inline attribute lingfuyi
2025-08-20 3:33 ` Elle Rhumsaa [this message]
-- 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
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=aKVBx2HWamyG0SeD@archiso \
--to=elle@weathered-steel.dev \
--cc=lingfuyi@126.com \
--cc=lingfuyi@kylinos.cn \
--cc=rust-for-linux@vger.kernel.org \
/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 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).