From: Alice Ryhl <aliceryhl@google.com>
To: Boqun Feng <boqun.feng@gmail.com>
Cc: FUJITA Tomonori <fujita.tomonori@gmail.com>,
arve@android.com, brauner@kernel.org, cmllamas@google.com,
gregkh@linuxfoundation.org, ojeda@kernel.org, tkjos@android.com,
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 1/3] rust: revocable: Switch to kernel::sync atomic primitives
Date: Wed, 31 Dec 2025 10:12:07 +0000 [thread overview]
Message-ID: <aVT296MBoaSzYqAd@google.com> (raw)
In-Reply-To: <aVRgTQWhqjKB6xpK@tardis-2.local>
On Wed, Dec 31, 2025 at 07:29:17AM +0800, Boqun Feng wrote:
> On Tue, Dec 30, 2025 at 06:37:16PM +0900, FUJITA Tomonori wrote:
> > Convert uses of `AtomicBool` to `Atomic<bool>`.
> >
> > Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
> > ---
> > rust/kernel/revocable.rs | 24 ++++++++++++++++--------
> > 1 file changed, 16 insertions(+), 8 deletions(-)
> >
> > diff --git a/rust/kernel/revocable.rs b/rust/kernel/revocable.rs
> > index 0f4ae673256d..47cd2b45eada 100644
> > --- a/rust/kernel/revocable.rs
> > +++ b/rust/kernel/revocable.rs
> > @@ -7,12 +7,20 @@
> >
> > use pin_init::Wrapper;
> >
> > -use crate::{bindings, prelude::*, sync::rcu, types::Opaque};
> > +use crate::{
> > + bindings,
> > + prelude::*,
> > + sync::atomic::{
> > + ordering::Relaxed,
> > + Atomic, //
> > + },
> > + sync::rcu,
> > + types::Opaque, //
> > +};
> > use core::{
> > marker::PhantomData,
> > ops::Deref,
> > - ptr::drop_in_place,
> > - sync::atomic::{AtomicBool, Ordering},
> > + ptr::drop_in_place, //
> > };
> >
> > /// An object that can become inaccessible at runtime.
> > @@ -65,7 +73,7 @@
> > /// ```
> > #[pin_data(PinnedDrop)]
> > pub struct Revocable<T> {
> > - is_available: AtomicBool,
> > + is_available: Atomic<bool>,
> > #[pin]
> > data: Opaque<T>,
>
> I actually think we should use Atomic<i32> instead of Atomic<bool> here,
> because in most of the cases `T` is a aligned to at least 4-bytes (e.g.
> Devres uses a Revocable<IoMem>) And in that case, using Atomic<bool>
> doesn't save extra memory but makes the xchg() operation slower on
> architectures that don't support byte-wise RmW instructions (e.g.
> riscv).
>
> My rule of thumb for using Atomic<bool> is: when you really care about
> the memory usage, and you can guarantee using Atomic<bool> is saving
> memory. For a general "flag" usage, Atomic<bool> is not strictly better
> than Atomic<i32> in most cases imo.
In Binder I believe we only use load/store with Atomic<bool>. Does it
matter in that case?
Alice
next prev parent reply other threads:[~2025-12-31 10:12 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-30 9:37 [PATCH v1 0/3] rust: Switch to kernel::sync atomic primitives FUJITA Tomonori
2025-12-30 9:37 ` [PATCH v1 1/3] rust: revocable: " FUJITA Tomonori
2025-12-30 23:29 ` Boqun Feng
2025-12-31 9:35 ` FUJITA Tomonori
2025-12-31 23:41 ` Boqun Feng
2026-01-01 4:34 ` Gary Guo
2025-12-31 10:12 ` Alice Ryhl [this message]
2025-12-31 10:33 ` FUJITA Tomonori
2025-12-31 10:54 ` Alice Ryhl
2025-12-30 9:37 ` [PATCH v1 2/3] rust: list: " FUJITA Tomonori
2025-12-31 10:53 ` Alice Ryhl
2025-12-30 9:37 ` [PATCH v1 3/3] rust_binder: " FUJITA Tomonori
2025-12-31 10:52 ` Alice Ryhl
2026-01-05 13:34 ` [PATCH v1 0/3] rust: " Boqun Feng
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=aVT296MBoaSzYqAd@google.com \
--to=aliceryhl@google.com \
--cc=a.hindborg@kernel.org \
--cc=arve@android.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=brauner@kernel.org \
--cc=cmllamas@google.com \
--cc=dakr@kernel.org \
--cc=fujita.tomonori@gmail.com \
--cc=gary@garyguo.net \
--cc=gregkh@linuxfoundation.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tkjos@android.com \
--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