Re: [PATCH 2/3] rust: page: add reference counting, raw pointers and a private bit lock

From: Andreas Hindborg

Date: Wed Nov 18 2026 - 10:24:31 EST


"Vitaly Wool" <vitaly.wool@xxxxxxxxxxx> writes:

> From: Igor B <igor.b@xxxxxxxxx>
>
> A `Page` always owns its page exclusively, with no way to take another
> reference or keep it as a raw pointer. Add:
>
> - `Page::get()`, which takes another reference with `get_page()`;
> - `Page::into_raw()` and `Page::from_raw()`, to convert a `Page` to and
> from the `struct page` pointer it holds a reference to;
> - `Page::try_get_raw()`, which takes a reference from a possibly stale
> pointer with `get_page_unless_zero()`, for lock-free lookups like
> brd_lookup_page(). This is sound because a `struct page` is never
> freed, even once its memory is;
> - `Page::lock_private_bit()`, which takes a bit spinlock in the page's
> `private` field and returns a guard that releases it. This gives a
> page used as plain memory a lock of its own at no memory cost.
>
> Add Rust helpers for `get_page()`, `get_page_unless_zero()`,
> `bit_spin_lock()` and `bit_spin_unlock()`.
>
> This patch was tested with the help of Claude Code AI coding assistant.
>
> Signed-off-by: Igor Belousov <igor.b@xxxxxxxxx>
> Signed-off-by: Vitaly Wool <vitaly.wool@xxxxxxxxxxx>

I already submitted most of this as part of the `Ownable` work [1]. I
sent v22 of the `Ownable` series a few days ago [2]. I stripped out the
page stuff to send as a separate series. I plan to send the page things
this week. It covers both reference counted pages and frozen pages.

Best regards,
Andreas Hindborg

[1] https://lore.kernel.org/all/20260910-unique-ref-v21-0-e83257373062@xxxxxxxxxx/
[2] https://lore.kernel.org/all/20261116-unique-ref-v22-0-12029383206d@xxxxxxxxxx/