public inbox for rust-for-linux@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1] rust: list: Use AtomicFlag in AtomicTracker
@ 2026-01-19 23:17 FUJITA Tomonori
  2026-01-20 13:54 ` Gary Guo
  0 siblings, 1 reply; 2+ messages in thread
From: FUJITA Tomonori @ 2026-01-19 23:17 UTC (permalink / raw)
  To: aliceryhl, boqun.feng
  Cc: ojeda, a.hindborg, bjorn3_gh, dakr, gary, lossin, tmgross,
	rust-for-linux

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);
     }
 
     unsafe fn on_drop_list_arc(&self) {

base-commit: 47f079b9ac97c4b0c673bbbf57245952e9edf8a2
-- 
2.43.0


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

end of thread, other threads:[~2026-01-20 13:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-19 23:17 [PATCH v1] rust: list: Use AtomicFlag in AtomicTracker FUJITA Tomonori
2026-01-20 13:54 ` Gary Guo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox