mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Zi Yan <ziy@nvidia.com>
To: Andreas Hindborg <a.hindborg@kernel.org>
Cc: "Andrew Morton" <akpm@linux-foundation.org>,
	"Vlastimil Babka" <vbabka@kernel.org>,
	"Lorenzo Stoakes" <ljs@kernel.org>,
	"Liam R. Howlett" <liam@infradead.org>,
	"Uladzislau Rezki" <urezki@gmail.com>,
	"David Hildenbrand" <david@kernel.org>,
	"Suren Baghdasaryan" <surenb@google.com>,
	"Michal Hocko" <mhocko@suse.com>,
	"Brendan Jackman" <brendan.jackman@linux.dev>,
	"Johannes Weiner" <hannes@cmpxchg.org>,
	"Mike Rapoport" <rppt@kernel.org>,
	"Joshua Hahn" <joshua.hahnjy@gmail.com>,
	"Rakie Kim" <rakie.kim@sk.com>,
	"Gregory Price" <gourry@gourry.net>,
	"Ying Huang" <ying.huang@linux.alibaba.com>,
	"Matthew Wilcox" <willy@infradead.org>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <lossin@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Daniel Almeida" <daniel.almeida@collabora.com>,
	"Tamir Duberstein" <tamird@kernel.org>,
	"Alexandre Courbot" <acourbot@nvidia.com>,
	"Onur Özkan" <work@onurozkan.dev>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Arve Hjønnevåg" <arve@android.com>,
	"Todd Kjos" <tkjos@android.com>,
	"Christian Brauner" <brauner@kernel.org>,
	"Carlos Llamas" <cmllamas@google.com>,
	"Igor B" <igor.b@beldev.am>,
	"Vitaly Wool" <vitaly.wool@konsulko.se>,
	linux-mm@kvack.org, rust-for-linux@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v22 0/6] rust: page: add page kinds
Date: Wed, 18 Nov 2026 12:02:01 -0500	[thread overview]
Message-ID: <37B6D4A8-288E-40E8-9214-EDABBFE49C39@nvidia.com> (raw)
In-Reply-To: <20261118-page-ownable-v22-0-d63ff73f4075@kernel.org>

On 18 Nov 2026, at 11:18, Andreas Hindborg wrote:

> Note: The page patches were part of the `Ownable` series [1] until v21.
> This series continues the version numbering of that series, and it depends
> on v22 of that series for `Ownable`, `Owned` and the split of `RefCounted`
> and `AlwaysRefCounted`.
>
> Not all pages can be treated the same way. A page allocated with
> `alloc_pages()` is managed by the page reference count, and kernel C code
> routinely takes its own references to such a page. A page owned by the
> slab allocator must not have references taken to it, but it can still
> show up in places such as a bio vector. A frozen page has a reference
> count of zero and is exclusively owned by the party that allocated it.
>
> A single `Page` type cannot describe all of these. This series makes
> `Page` generic over a sealed `PageKind` that describes what is known about
> the page:
>
>  - `Page<Base>` is the base kind. Nothing is known about the page
>    beyond the validity of the `struct page`.
>  - `Page<RefCounted>` is the default kind. The page is managed by the
>    page reference count, and `Page<RefCounted>` implements
>    `AlwaysRefCounted`.
>  - `Page<Exclusive>` is a uniquely owned frozen page whose data area
>    follows standard Rust aliasing rules, so the data is available as
>    `&[u8]` and `&mut [u8]`. It is handled through
>    `Owned<Page<Exclusive>>` and is the first in-tree user of `Owned`.
>  - `Page<Frozen>` is a frozen page whose allocation is uniquely owned.
>    Unlike for `Page<Exclusive>`, nothing is known about who accesses the
>    data of the page, so the data is only available through the unsafe
>    raw accessors.

Why do we need to allocate Page<Frozen> when we can allocate Page<Exclusive>?
To me, Page<Frozen> is an observed page state from a non-owner point
of view.

In core-mm, a page is frozen, when its refcount == 0. The code looking
at the page knows the page is exclusively owned by others. If the code
allocates a frozen page, it will not check its refcount, because
the code knows it has the exclusive ownership of the page. To reflect
this, the code calling alloc_frozen_pages() should just get Page<Exclusive>
and if the code encounters a Page<Base> and finds it has no refcount,
it should convert it to Page<Frozen> or there should be a method
that accepts PFN and return Page<Frozen> if the page of the PFN has no
refcount, for PFN walkers.

“the data” mentioned in Page<Exclusive> and Page<Frozen> is struct page
data or the data in the physical frame pointed by Page<...>? If it
is the former, is it better to use metadata?

I am new to Rust, so feel free to correct me. Thanks. :)

>
> Operations that are valid for any page are available for all page kinds.
> All other page kinds dereference to `Page<Base>`. The purpose of the
> dereference is coercion: a reference to a page of any kind can be passed
> to code that takes a `&Page<Base>`.
>
> `Page<Exclusive>` is backed by a frozen page, as suggested by Matthew
> Wilcox in the review of v21. References cannot be taken to a frozen page,
> so the exclusive ownership is upheld by mm rather than only by the Rust
> type system.
>


Best Regards,
Yan, Zi

  parent reply	other threads:[~2026-11-18 17:02 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 16:18 Andreas Hindborg
2026-11-18 16:18 ` [PATCH v22 1/6] rust: page: add page kinds and make `Page` reference counted Andreas Hindborg
2026-11-18 16:18 ` [PATCH v22 2/6] rust: page: add `from_raw()` Andreas Hindborg
2026-11-18 16:18 ` [PATCH v22 3/6] mm/page_alloc: make alloc_frozen_pages() available outside of mm Andreas Hindborg
2026-11-18 16:18 ` [PATCH v22 4/6] rust: page: add `Exclusive` page kind for race-free page access Andreas Hindborg
2026-11-18 16:18 ` [PATCH v22 5/6] rust: page: add `Frozen` page kind Andreas Hindborg
2026-11-18 16:18 ` [PATCH v22 6/6] rust: page: add slice access to `Page<Exclusive>` Andreas Hindborg
2026-11-18 17:02 ` Zi Yan [this message]
2026-11-18 19:34   ` [PATCH v22 0/6] rust: page: add page kinds Andreas Hindborg
2026-11-19 16:58     ` Zi Yan

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=37B6D4A8-288E-40E8-9214-EDABBFE49C39@nvidia.com \
    --to=ziy@nvidia.com \
    --cc=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=akpm@linux-foundation.org \
    --cc=aliceryhl@google.com \
    --cc=arve@android.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun@kernel.org \
    --cc=brauner@kernel.org \
    --cc=brendan.jackman@linux.dev \
    --cc=cmllamas@google.com \
    --cc=dakr@kernel.org \
    --cc=daniel.almeida@collabora.com \
    --cc=david@kernel.org \
    --cc=gary@garyguo.net \
    --cc=gourry@gourry.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=hannes@cmpxchg.org \
    --cc=igor.b@beldev.am \
    --cc=joshua.hahnjy@gmail.com \
    --cc=liam@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=lossin@kernel.org \
    --cc=mhocko@suse.com \
    --cc=ojeda@kernel.org \
    --cc=rakie.kim@sk.com \
    --cc=rppt@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=surenb@google.com \
    --cc=tamird@kernel.org \
    --cc=tkjos@android.com \
    --cc=tmgross@umich.edu \
    --cc=urezki@gmail.com \
    --cc=vbabka@kernel.org \
    --cc=vitaly.wool@konsulko.se \
    --cc=willy@infradead.org \
    --cc=work@onurozkan.dev \
    --cc=ying.huang@linux.alibaba.com \
    /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

all inboxes | Powered by JetHome®