Re: [PATCH v22 0/6] rust: page: add page kinds

From: Zi Yan

Date: Wed Nov 18 2026 - 12:08:51 EST


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