From: Alice Ryhl <aliceryhl@google.com>
To: Danilo Krummrich <dakr@kernel.org>
Cc: lorenzo.stoakes@oracle.com, vbabka@suse.cz,
Liam.Howlett@oracle.com, urezki@gmail.com, ojeda@kernel.org,
alex.gaynor@gmail.com, boqun.feng@gmail.com, gary@garyguo.net,
bjorn3_gh@protonmail.com, lossin@kernel.org,
a.hindborg@kernel.org, tmgross@umich.edu,
abdiel.janulgue@gmail.com, acourbot@nvidia.com,
rust-for-linux@vger.kernel.org
Subject: Re: [PATCH v2 2/6] rust: page: define PageOwner trait
Date: Fri, 8 Aug 2025 08:54:50 +0000 [thread overview]
Message-ID: <aJW7WnWWfCDbGsWp@google.com> (raw)
In-Reply-To: <20250806205044.85085-3-dakr@kernel.org>
On Wed, Aug 06, 2025 at 10:50:11PM +0200, Danilo Krummrich wrote:
> Introduce the PageOwner trait, which can be implemented by any entity
> that potentially owns one or multiple pages and allow users to borrow
> them.
>
> For instance, this is useful to access and borrow the backing pages of
> allocation primitives, such as Box and Vec, backing a scatterlist.
>
> Signed-off-by: Danilo Krummrich <dakr@kernel.org>
> ---
> rust/kernel/page.rs | 12 ++++++++++++
> 1 file changed, 12 insertions(+)
>
> diff --git a/rust/kernel/page.rs b/rust/kernel/page.rs
> index 631718a6ad7d..93ce4956f782 100644
> --- a/rust/kernel/page.rs
> +++ b/rust/kernel/page.rs
> @@ -103,6 +103,18 @@ fn deref(&self) -> &Self::Target {
> }
> }
>
> +/// Represents a potential owner of one or multiple [`Page`]s.
> +///
> +/// This trait may be implemented by types that potentially hold ownership of memory pages. It
> +/// allows users to iterate over those pages and borrow them as [`BorrowedPage`].
> +pub trait PageOwner {
> + /// Returns an [`Iterator`] of [`BorrowedPage`] items over all pages owned by `self`.
> + fn page_iter<'a>(&'a mut self) -> impl Iterator<Item = BorrowedPage<'a>>;
> +
> + /// Returns the number of pages currently owned by `self`.
> + fn page_count(&self) -> usize;
> +}
Honestly, I don't entirely love this trait on its own merits. But I'd
need to know more about how it will be used to give a clearer opinion.
Either way, I think the implementation of VBox and VVec could be merged
to some shared VmallocPageIter that iterates a region of pages.
Alice
next prev parent reply other threads:[~2025-08-08 8:54 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-06 20:50 [PATCH v2 0/6] BorrowedPage and PageOwner Danilo Krummrich
2025-08-06 20:50 ` [PATCH v2 1/6] rust: page: implement BorrowedPage Danilo Krummrich
2025-08-06 20:50 ` [PATCH v2 2/6] rust: page: define PageOwner trait Danilo Krummrich
2025-08-08 3:32 ` Alexandre Courbot
2025-08-08 8:54 ` Alice Ryhl [this message]
2025-08-08 9:08 ` Danilo Krummrich
2025-08-06 20:50 ` [PATCH v2 3/6] rust: alloc: vmalloc: implement Vmalloc::to_page() Danilo Krummrich
2025-08-08 3:37 ` Alexandre Courbot
2025-08-06 20:50 ` [PATCH v2 4/6] rust: alloc: layout: implement ArrayLayout::size() Danilo Krummrich
2025-08-08 3:42 ` Alexandre Courbot
2025-08-08 8:45 ` Abdiel Janulgue
2025-08-08 9:37 ` Alice Ryhl
2025-08-06 20:50 ` [PATCH v2 5/6] rust: alloc: kbox: implement PageOwner for VBox Danilo Krummrich
2025-08-08 3:49 ` Alexandre Courbot
2025-08-08 8:44 ` Abdiel Janulgue
2025-08-06 20:50 ` [PATCH v2 6/6] rust: alloc: kvec: implement PageOwner for VVec Danilo Krummrich
2025-08-08 3:54 ` Alexandre Courbot
2025-08-08 8:44 ` Abdiel Janulgue
2025-08-07 9:12 ` [PATCH v2 0/6] BorrowedPage and PageOwner Vlastimil Babka
2025-08-07 9:46 ` Danilo Krummrich
2025-08-08 8:41 ` Abdiel Janulgue
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=aJW7WnWWfCDbGsWp@google.com \
--to=aliceryhl@google.com \
--cc=Liam.Howlett@oracle.com \
--cc=a.hindborg@kernel.org \
--cc=abdiel.janulgue@gmail.com \
--cc=acourbot@nvidia.com \
--cc=alex.gaynor@gmail.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=dakr@kernel.org \
--cc=gary@garyguo.net \
--cc=lorenzo.stoakes@oracle.com \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
--cc=urezki@gmail.com \
--cc=vbabka@suse.cz \
/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).