rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andreas Hindborg <nmi@metaspace.dk>
To: Andreas Hindborg <nmi@metaspace.dk>
Cc: "Maíra Canal" <mcanal@igalia.com>,
	"Asahi Lina" <lina@asahilina.net>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Alex Gaynor" <alex.gaynor@gmail.com>,
	"Wedson Almeida Filho" <wedsonaf@gmail.com>,
	"Boqun Feng" <boqun.feng@gmail.com>,
	"Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <benno.lossin@proton.me>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Matthew Wilcox" <willy@infradead.org>,
	rust-for-linux@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	kernel-dev@igalia.com
Subject: Re: [PATCH v7 2/2] rust: xarray: Add an abstraction for XArray
Date: Wed, 28 Feb 2024 10:56:41 +0100	[thread overview]
Message-ID: <87cysgap0u.fsf@metaspace.dk> (raw)
In-Reply-To: <87plwi9waq.fsf@metaspace.dk>


Andreas Hindborg <nmi@metaspace.dk> writes:

> Maíra Canal <mcanal@igalia.com> writes:
>
>> From: Asahi Lina <lina@asahilina.net>
>>
>> The XArray is an abstract data type which behaves like a very large
>> array of pointers. Add a Rust abstraction for this data type.
>>
>> The initial implementation uses explicit locking on get operations and
>> returns a guard which blocks mutation, ensuring that the referenced
>> object remains alive. To avoid excessive serialization, users are
>> expected to use an inner type that can be efficiently cloned (such as
>> Arc<T>), and eagerly clone and drop the guard to unblock other users
>> after a lookup.
>>
>> Future variants may support using RCU instead to avoid mutex locking.
>>
>> This abstraction also introduces a reservation mechanism, which can be
>> used by alloc-capable XArrays to reserve a free slot without immediately
>> filling it, and then do so at a later time. If the reservation is
>> dropped without being filled, the slot is freed again for other users,
>> which eliminates the need for explicit cleanup code.
>>
>> Signed-off-by: Asahi Lina <lina@asahilina.net>
>> Co-developed-by: Maíra Canal <mcanal@igalia.com>
>> Signed-off-by: Maíra Canal <mcanal@igalia.com>
>> ---
>
>
> Reviewed-by: Andreas Hindborg <a.hindborg@samsung.com>

Actually clippy complains about use of the name `foo` for a variable in
the example. Fix:

diff --git a/rust/kernel/xarray.rs b/rust/kernel/xarray.rs
index 849915ea633c..aba09cf28c4b 100644
--- a/rust/kernel/xarray.rs
+++ b/rust/kernel/xarray.rs
@@ -185,8 +185,8 @@ fn drop(&mut self) {
 /// let arr = Box::pin_init(XArray::<Arc<Foo>>::new(flags::ALLOC1))
 ///                        .expect("Unable to allocate XArray");
 ///
-/// let foo = Arc::try_new(Foo { a : 1, b: 2 }).expect("Unable to allocate Foo");
-/// let index = arr.alloc(foo).expect("Error allocating Index");
+/// let item = Arc::try_new(Foo { a : 1, b: 2 }).expect("Unable to allocate Foo");
+/// let index = arr.alloc(item).expect("Error allocating Index");
 ///
 /// if let Some(guard) = arr.get_locked(index) {
 ///     assert_eq!(guard.borrow().a, 1);
@@ -195,8 +195,8 @@ fn drop(&mut self) {
 ///     pr_info!("No value found in index {}", index);
 /// }
 ///
-/// let foo = Arc::try_new(Foo { a : 3, b: 4 }).expect("Unable to allocate Foo");
-/// let index = arr.alloc(foo).expect("Error allocating Index");
+/// let item = Arc::try_new(Foo { a : 3, b: 4 }).expect("Unable to allocate Foo");
+/// let index = arr.alloc(item).expect("Error allocating Index");
 ///
 /// if let Some(removed_data) = arr.remove(index) {
 ///     assert_eq!(removed_data.a, 3);


BR Andreas

  reply	other threads:[~2024-02-28  9:58 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-09 22:31 [PATCH v7 0/2] rust: xarray: Add an abstraction for XArray Maíra Canal
2024-02-09 22:31 ` [PATCH v7 1/2] rust: types: add FOREIGN_ALIGN to ForeignOwnable Maíra Canal
2024-02-27  7:53   ` Andreas Hindborg
2024-02-28 10:09   ` Alice Ryhl
2024-02-09 22:31 ` [PATCH v7 2/2] rust: xarray: Add an abstraction for XArray Maíra Canal
2024-02-27  7:54   ` Andreas Hindborg
2024-02-28  9:56     ` Andreas Hindborg [this message]
2024-02-28 10:32   ` Alice Ryhl
2024-02-28 10:44   ` Miguel Ojeda

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=87cysgap0u.fsf@metaspace.dk \
    --to=nmi@metaspace.dk \
    --cc=alex.gaynor@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=benno.lossin@proton.me \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=gary@garyguo.net \
    --cc=kernel-dev@igalia.com \
    --cc=lina@asahilina.net \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=mcanal@igalia.com \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=wedsonaf@gmail.com \
    --cc=willy@infradead.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).