From: "Onur Özkan" <work@onurozkan.dev>
To: Alice Ryhl <aliceryhl@google.com>
Cc: Benno Lossin <lossin@kernel.org>,
rust-for-linux@vger.kernel.org, ojeda@kernel.org,
alex.gaynor@gmail.com, boqun.feng@gmail.com, gary@garyguo.net,
bjorn3_gh@protonmail.com, tmgross@umich.edu, dakr@kernel.org,
linux-kernel@vger.kernel.org, acourbot@nvidia.com,
airlied@gmail.com, simona@ffwll.ch,
maarten.lankhorst@linux.intel.com, mripard@kernel.org,
tzimmermann@suse.de, corbet@lwn.net, lyude@redhat.com,
linux-doc@vger.kernel.org
Subject: Re: [PATCH 1/3] rust: xarray: abstract `xa_alloc`
Date: Wed, 8 Oct 2025 16:22:01 +0300 [thread overview]
Message-ID: <20251008162201.79e76046@nimda.home> (raw)
In-Reply-To: <aOZgrhsNrKpxM_PW@google.com>
On Wed, 8 Oct 2025 13:01:34 +0000
Alice Ryhl <aliceryhl@google.com> wrote:
> On Wed, Oct 08, 2025 at 12:18:24PM +0200, Benno Lossin wrote:
> > On Tue Oct 7, 2025 at 12:58 PM CEST, Alice Ryhl wrote:
> > > On Mon, Oct 06, 2025 at 09:31:43PM +0200, Benno Lossin wrote:
> > >> On Mon Oct 6, 2025 at 6:30 PM CEST, Onur Özkan wrote:
> > >> > Implements `alloc` function to `XArray<T>` that wraps
> > >> > `xa_alloc` safely.
> > >> >
> > >> > Resolves a task from the nova/core task list under the "XArray
> > >> > bindings [XARR]" section in
> > >> > "Documentation/gpu/nova/core/todo.rst" file.
> > >> >
> > >> > Signed-off-by: Onur Özkan <work@onurozkan.dev>
> > >> > ---
> > >> > rust/kernel/xarray.rs | 39
> > >> > +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39
> > >> > insertions(+)
> > >> >
> > >> > diff --git a/rust/kernel/xarray.rs b/rust/kernel/xarray.rs
> > >> > index a49d6db28845..1b882cd2f58b 100644
> > >> > --- a/rust/kernel/xarray.rs
> > >> > +++ b/rust/kernel/xarray.rs
> > >> > @@ -266,6 +266,45 @@ pub fn store(
> > >> > Ok(unsafe { T::try_from_foreign(old) })
> > >> > }
> > >> > }
> > >> > +
> > >> > + /// Allocates an empty slot within the given limit range
> > >> > and stores `value` there.
> > >> > + ///
> > >> > + /// May drop the lock if needed to allocate memory, and
> > >> > then reacquire it afterwards.
> > >> > + ///
> > >> > + /// On success, returns the allocated id.
> > >> > + ///
> > >> > + /// On failure, returns the element which was attempted
> > >> > to be stored.
> > >> > + pub fn alloc(
> > >> > + &mut self,
> > >> > + limit: bindings::xa_limit,
> > >> > + value: T,
> > >> > + gfp: alloc::Flags,
> > >> > + ) -> Result<u32, StoreError<T>> {
> > >>
> > >> I think it would be a good idea to make the id a newtype wrapper
> > >> around u32. Maybe not even allow users to manually construct it
> > >> or even inspect it if possible.
> > >
> > > What? People need to know what the assigned index is.
> >
> > The documentation says "allocated id", so I assumed that it was some
> > internal, implementation-dependent thing, not an index. In that
> > case we should change the docs instead.
>
> An xarray is a map from integer to pointer. The allocated id the key
> in this map. The alloc method picks the smallest unused key in a given
> range.
>
> Alice
Perhaps we should document it as "allocated key" or "allocated id (key)"
?
-Onur
next prev parent reply other threads:[~2025-10-08 13:27 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-06 16:30 [PATCH 0/3] rust: xarray: abstract `xa_alloc` and `xa_alloc_cyclic` Onur Özkan
2025-10-06 16:30 ` [PATCH 1/3] rust: xarray: abstract `xa_alloc` Onur Özkan
2025-10-06 19:31 ` Benno Lossin
2025-10-07 10:58 ` Alice Ryhl
2025-10-08 10:18 ` Benno Lossin
2025-10-08 13:01 ` Alice Ryhl
2025-10-08 13:22 ` Onur Özkan [this message]
2025-10-08 16:01 ` Alice Ryhl
2025-10-06 23:09 ` Boqun Feng
2025-10-07 5:04 ` Onur Özkan
2025-10-06 16:30 ` [PATCH 2/3] rust: xarray: abstract `xa_alloc_cyclic` Onur Özkan
2025-10-07 10:56 ` Alice Ryhl
2025-10-07 12:31 ` Onur Özkan
2025-10-07 17:28 ` Miguel Ojeda
2025-10-08 5:26 ` Onur Özkan
2025-10-06 16:30 ` [PATCH 3/3] remove completed task from nova-core task list Onur Özkan
2025-10-07 11:01 ` [PATCH 0/3] rust: xarray: abstract `xa_alloc` and `xa_alloc_cyclic` Alice Ryhl
2025-10-07 12:37 ` Onur Özkan
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=20251008162201.79e76046@nimda.home \
--to=work@onurozkan.dev \
--cc=acourbot@nvidia.com \
--cc=airlied@gmail.com \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=corbet@lwn.net \
--cc=dakr@kernel.org \
--cc=gary@garyguo.net \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=lyude@redhat.com \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=simona@ffwll.ch \
--cc=tmgross@umich.edu \
--cc=tzimmermann@suse.de \
/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).