Re: [PATCH v22 0/6] rust: page: add page kinds
From: Andreas Hindborg
Date: Fri Dec 04 2026 - 08:24:39 EST
Zi Yan <ziy@xxxxxxxxxx> writes:
<cut>
>>>>>> - Pages used for backing storage like in the null block driver. These
>>>>>> are modeled as `Page<Exclusive>`.
>>>>>
>>>>> null_alloc_page() uses alloc_pages() and gets refcount == 1 pages.
>>>>> unless you mean struct nullb_page.
>>>>
>>>> Yes, the C null block driver uses reference counted pages. The Rust null
>>>> block driver implementation will use frozen pages. Matthew suggested
>>>> this approach.
>>>
>>> This worries me, because
>>> 1. willy, David, and I have been talking about a new page type for
>>> device allocated memory to separate it from rmappable folio (anon
>>> or pagecache folios) and this using frozen pages is different;
>>>
>>> 2. it introduces a new long-live frozen page (exclude zone device memory), whereas existing frozen pages without a page type are either transient or
>>> marked by PG_hwpoison. The transient ones are
>>> a) PCP pages,
>>> b) compaction’s cc->freepages[],
>>> c) temporarily isolated free pages.
>>>
>>> I am not sure core-mm has code properly handles this new long-live
>>> frozen page. At least, page_is_unmovable() used by memory offline
>>> needs to handle this kind of frozen page, since it assumes
>>> frozen and untyped pages are free or about to be freed and can lead
>>> offline_pages() looping on them. See commit 213268869301f ("mm:
>>> page_isolation: do not take slab pages for free") for more context.
>>>
>>> David and willy, what is your take on this? Either we assign a
>>> page type to Page<Exclusive> or still uses refcounted pages.
>>
>> If this is the wrong approach, I can just as well use the refcounted
>> page underneath. I picked the frozen one because of Willy's suggestion
>> on an earlier version of this series.
>>
>
> I talked to willy and David in today’s THP cabal meeting about this.
> The consensus is that in the memdesc world, refcount should be only
> used by userspace memory like anon folio and pagecache folio and
> other kernel and driver allocations do not need it, unless there
> is something special. But we are not there yet.
>
> To get to the memdesc world, we need to understand why drivers want
> to use alloc_pages() instead of kmalloc(). kmalloc() can return
> up to MAX_PAGE_ORDER memory, the same as alloc_pages(). And why
> Rust chooses Page as a data access abstraction? Maybe we should
> discuss this in LSFMM.
The concrete reason for rnull to use page allocation rather than kmalloc
and friends, is that this is what C null_blk does. rnull is a reference
Rust implementation of null_blk, meant to facilitate an apples to apples
comparison between the same functionality implemented in two different
languages. If we use backing memory allocated via a different allocator,
the comparison becomes less useful.
Best regards,
Andreas Hindborg