public inbox for rust-for-linux@vger.kernel.org
 help / color / mirror / Atom feed
From: "Gary Guo" <gary@garyguo.net>
To: "FUJITA Tomonori" <fujita.tomonori@gmail.com>,
	<aliceryhl@google.com>, <boqun.feng@gmail.com>
Cc: <ojeda@kernel.org>, <a.hindborg@kernel.org>,
	<bjorn3_gh@protonmail.com>, <dakr@kernel.org>, <gary@garyguo.net>,
	<lossin@kernel.org>, <tmgross@umich.edu>,
	<rust-for-linux@vger.kernel.org>
Subject: Re: [PATCH v1] rust: list: Use AtomicFlag in AtomicTracker
Date: Tue, 20 Jan 2026 13:54:38 +0000	[thread overview]
Message-ID: <DFTGUBC2K4G8.3HSMNEUI24RGX@garyguo.net> (raw)
In-Reply-To: <20260119231757.3460885-1-fujita.tomonori@gmail.com>

On Mon Jan 19, 2026 at 11:17 PM GMT, FUJITA Tomonori wrote:
> Make AtomicTracker use AtomicFlag instead of Atomic<bool> to avoid
> slow byte-sized RMWs on architectures that don't support them.
>
> Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
> ---
>  rust/kernel/list/arc.rs | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/rust/kernel/list/arc.rs b/rust/kernel/list/arc.rs
> index 2282f33913ee..3296726e07d9 100644
> --- a/rust/kernel/list/arc.rs
> +++ b/rust/kernel/list/arc.rs
> @@ -6,7 +6,7 @@
>  
>  use crate::alloc::{AllocError, Flags};
>  use crate::prelude::*;
> -use crate::sync::atomic::{ordering, Atomic};
> +use crate::sync::atomic::{ordering, AtomicFlag};
>  use crate::sync::{Arc, ArcBorrow, UniqueArc};
>  use core::marker::PhantomPinned;
>  use core::ops::Deref;
> @@ -469,7 +469,7 @@ impl<T, U, const ID: u64> core::ops::DispatchFromDyn<ListArc<U, ID>> for ListArc
>  /// If the boolean is `false`, then there is no [`ListArc`] for this value.
>  #[repr(transparent)]
>  pub struct AtomicTracker<const ID: u64 = 0> {
> -    inner: Atomic<bool>,
> +    inner: AtomicFlag,
>      // This value needs to be pinned to justify the INVARIANT: comment in `AtomicTracker::new`.
>      _pin: PhantomPinned,
>  }
> @@ -480,12 +480,12 @@ pub fn new() -> impl PinInit<Self> {
>          // INVARIANT: Pin-init initializers can't be used on an existing `Arc`, so this value will
>          // not be constructed in an `Arc` that already has a `ListArc`.
>          Self {
> -            inner: Atomic::new(false),
> +            inner: AtomicFlag::new(false),
>              _pin: PhantomPinned,
>          }
>      }
>  
> -    fn project_inner(self: Pin<&mut Self>) -> &mut Atomic<bool> {
> +    fn project_inner(self: Pin<&mut Self>) -> &mut AtomicFlag {
>          // SAFETY: The `inner` field is not structurally pinned, so we may obtain a mutable
>          // reference to it even if we only have a pinned reference to `self`.
>          unsafe { &mut Pin::into_inner_unchecked(self).inner }
> @@ -495,7 +495,7 @@ fn project_inner(self: Pin<&mut Self>) -> &mut Atomic<bool> {
>  impl<const ID: u64> ListArcSafe<ID> for AtomicTracker<ID> {
>      unsafe fn on_create_list_arc_from_unique(self: Pin<&mut Self>) {
>          // INVARIANT: We just created a ListArc, so the boolean should be true.
> -        *self.project_inner().get_mut() = true;
> +        self.project_inner().store(true, ordering::Relaxed);

I would if we can still provide `get_mut()`. You can just hand out a reference
to the LSB of the flag (of course, this is a different byte depending on
endianness..).

Best,
Gary

>      }
>  
>      unsafe fn on_drop_list_arc(&self) {
>
> base-commit: 47f079b9ac97c4b0c673bbbf57245952e9edf8a2


      reply	other threads:[~2026-01-20 13:54 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-19 23:17 [PATCH v1] rust: list: Use AtomicFlag in AtomicTracker FUJITA Tomonori
2026-01-20 13:54 ` Gary Guo [this message]

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=DFTGUBC2K4G8.3HSMNEUI24RGX@garyguo.net \
    --to=gary@garyguo.net \
    --cc=a.hindborg@kernel.org \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=dakr@kernel.org \
    --cc=fujita.tomonori@gmail.com \
    --cc=lossin@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tmgross@umich.edu \
    /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