From: Zi Yan <ziy@nvidia.com>
To: "David Hildenbrand (Arm)" <david@kernel.org>
Cc: Jason Gunthorpe <jgg@nvidia.com>,
Matthew Wilcox <willy@infradead.org>,
Alistair Popple <apopple@nvidia.com>,
Balbir Singh <balbirs@nvidia.com>,
Andrew Morton <akpm@linux-foundation.org>,
Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
"Liam R. Howlett" <Liam.Howlett@oracle.com>,
Vlastimil Babka <vbabka@suse.cz>, Mike Rapoport <rppt@kernel.org>,
Suren Baghdasaryan <surenb@google.com>,
Michal Hocko <mhocko@suse.com>, Jens Axboe <axboe@kernel.dk>,
Baolin Wang <baolin.wang@linux.alibaba.com>,
Nico Pache <npache@redhat.com>,
Ryan Roberts <ryan.roberts@arm.com>, Dev Jain <dev.jain@arm.com>,
Barry Song <baohua@kernel.org>, Lance Yang <lance.yang@linux.dev>,
Muchun Song <muchun.song@linux.dev>,
Oscar Salvador <osalvador@suse.de>,
Brendan Jackman <jackmanb@google.com>,
Johannes Weiner <hannes@cmpxchg.org>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
io-uring@vger.kernel.org
Subject: Re: [RFC PATCH 0/5] Separate compound page from folio
Date: Mon, 23 Mar 2026 22:42:45 -0400 [thread overview]
Message-ID: <3C342301-A8E4-4EC4-BB9E-9C8246F8D6F7@nvidia.com> (raw)
In-Reply-To: <c1a2a49b-8141-418f-b239-167ef031451b@kernel.org>
On 20 Mar 2026, at 6:21, David Hildenbrand (Arm) wrote:
> On 1/30/26 04:48, Zi Yan wrote:
>> Hi all,
>
> Hi,
>
> sorry for only going over that now.
>
>>
>> Based on my discussion with Jason about device private folio
>> reinitialization[1], I realize that the concepts of compound page and folio
>> are mixed together and confusing, as people think a compound page is equal
>> to a folio. This is not true, since a compound page means a group of
>> pages is managed as a whole and it can be something other than a folio,
>> for example, a slab page. To avoid further confusing people, this
>> patchset separates compound page from folio by moving any folio related
>> code out of compound page functions.
>>
>> The code is on top of mm-new (2026-01-28-20-27) and all mm selftests
>> passed.
>>
>> The key change is that a compound page no longer sets:
>> 1. folio->_nr_pages,
>> 2. folio->_large_mapcount,
>> 3. folio->_nr_pages_mapped,
>> 4. folio->_mm_ids,
>> 5. folio->_mm_id_mapcount,
>> 6. folio->_pincount,
>> 7. folio->_entire_mapcount,
>> 8. folio->_deferred_list.
>
> Noble goal! :)
>
> As discussed, the issue is still that interpret non-folio page
> allocations as folios, which can also be compound pages.
>
> Now, there are PFN walkers that do that, but also page table handling code.
>
> Most prominently, when mapping such pages through vm_insert_pages(), we
> will call into folio_add_file_rmap_pte() and essentially touch mapcount
> related stuff.
>
> Once in the page tables, users can GUP them and modify the pincount.
> Other page table walkers can just similarly find them and look them up.
>
> To stop messing with mapcounts is easy once we can reliably identify
> such pages when mapping/unmapping them.
My current way of doing that is to mark every page “NotRmappable” page_type
in post_alloc_hook() and clear this page_type at page_rmappable_folio().
Any user wants to set their own page_type can overwrite “NotRmappable”.
And folio_test_rmappable() is just !folio_has_type(). One exception
is hugetlb, since it has page_type and is rmappable. Fortunately or
unfortunately, rmap.c has special handling code for hugetlb, so there
should be no problem.
I did some test using io_uring (via nvim), which uses compound page instead of
folio and does vm_insert*(). At least no crash was present.
>
> GUP and other page table walkers are more problematic and need more
> thought (and work :( ).
>
> Essentially, vm_normal_folio() would have to fail on these pages. But
> what to do about vm_normal_page() users? The page_folio() would have to
> fail. But then we must keep some page table walkers working.
>
> And we have to figure out what to do with GUP.
Since _pincount will not be present after my change, GUP cannot be applied
on these pages.
OK, my memory comes back. I think my original proposal of separating
compound page from folio might not be right, since that defeats the
purpose of folio, which is a group of pages managed as a whole.
Basically a compound page should still be regarded as a folio, but rmappable
related fields (e.g., _large_mapcount, _nr_pages_mapped, _mm_ids)
should not be initialized and user is free to use them differently.
In this way, _pincount can be a common folio field to initialize and use.
>
> So compound pages are just the tip of the iceberg :)
>
>
> We could maybe forbid mapping them through vm_insert_pages() in the
> first place, requiring all callers to do order-0 page allocations. Hm.
>
> Then at least they would not end up in user page tables.
Will it kill performance? If only order-0 pages are allowed.
>
> But there is other code where compound pages are interpreted as folios
> and the other way around that must be sorted out.
I think we might want to have some sub-class of folios, like rmappable folios,
not rmappable folios, and others, otherwise, we are going back
to mixing page and folio.
Best Regards,
Yan, Zi
prev parent reply other threads:[~2026-03-24 2:42 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-30 3:48 Zi Yan
2026-01-30 3:48 ` [RFC PATCH 1/5] io_uring: allocate folio in io_mem_alloc_compound() and function rename Zi Yan
2026-01-31 15:30 ` Lance Yang
2026-02-01 2:04 ` Zi Yan
2026-01-30 3:48 ` [RFC PATCH 2/5] mm/huge_memory: use page_rmappable_folio() to convert after-split folios Zi Yan
2026-01-30 3:48 ` [RFC PATCH 3/5] mm/hugetlb: set large_rmappable on hugetlb and avoid deferred_list handling Zi Yan
2026-02-02 3:59 ` Baolin Wang
2026-02-02 17:11 ` Zi Yan
2026-01-30 3:48 ` [RFC PATCH 4/5] mm: only use struct page in compound_nr() and compound_order() Zi Yan
2026-01-30 3:48 ` [RFC PATCH 5/5] mm: code separation for compound page and folio Zi Yan
2026-01-30 8:15 ` [syzbot ci] Re: Separate compound page from folio syzbot ci
2026-01-30 16:39 ` [syzbot ci] " Zi Yan
2026-01-30 16:41 ` syzbot ci
2026-02-03 4:30 ` [RFC PATCH 0/5] " Balbir Singh
2026-02-04 16:21 ` Zi Yan
2026-02-04 18:29 ` Zi Yan
2026-02-04 18:49 ` Jason Gunthorpe
2026-03-20 10:21 ` David Hildenbrand (Arm)
2026-03-24 2:42 ` Zi Yan [this message]
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=3C342301-A8E4-4EC4-BB9E-9C8246F8D6F7@nvidia.com \
--to=ziy@nvidia.com \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=apopple@nvidia.com \
--cc=axboe@kernel.dk \
--cc=balbirs@nvidia.com \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=david@kernel.org \
--cc=dev.jain@arm.com \
--cc=hannes@cmpxchg.org \
--cc=io-uring@vger.kernel.org \
--cc=jackmanb@google.com \
--cc=jgg@nvidia.com \
--cc=lance.yang@linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=mhocko@suse.com \
--cc=muchun.song@linux.dev \
--cc=npache@redhat.com \
--cc=osalvador@suse.de \
--cc=rppt@kernel.org \
--cc=ryan.roberts@arm.com \
--cc=surenb@google.com \
--cc=vbabka@suse.cz \
--cc=willy@infradead.org \
/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