From: Zi Yan <ziy@nvidia.com>
To: Balbir Singh <balbirs@nvidia.com>
Cc: Jason Gunthorpe <jgg@nvidia.com>,
David Hildenbrand <david@kernel.org>,
Matthew Wilcox <willy@infradead.org>,
Alistair Popple <apopple@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: Wed, 04 Feb 2026 13:29:45 -0500 [thread overview]
Message-ID: <33B161E0-5468-4A31-A5BC-B4F1FCE72CEC@nvidia.com> (raw)
In-Reply-To: <2EF8F5BB-7CEB-431C-B9CB-00B1E3E44E1E@nvidia.com>
On 4 Feb 2026, at 11:21, Zi Yan wrote:
> On 2 Feb 2026, at 23:30, Balbir Singh wrote:
>
>> On 1/30/26 14:48, Zi Yan wrote:
>>> Hi all,
>>>
>>> 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.
>>>
>>> Since these fields are only used by folios that are rmappable. The code
>>> setting these fields is moved to page_rmappable_folio(). To make the
>>> code move, this patchset also needs to changes several places, where
>>> folio and compound page are used interchangably or unusual folio use:
>>>
>>> 1. in io_mem_alloc_compound(), a compound page is allocated, but later
>>> it is mapped via vm_insert_pages() like a rmappable folio;
>>> 2. __split_folio_to_order() sets large_rmappable flag directly instead
>>> of using page_rmappable_folio() for after-split folios;
>>> 3. hugetlb unsets large_rmappable to escape deferred_list unqueue
>>> operation.
>>>
>>> At last, the page freeing path is also changed to have different checks
>>> for compound page and folio.
>>>
>>
>> Thanks for doing this!
>>
>>
>>> One thing to note is that for compound page, I do not store compound
>>> order in folio->_nr_pages, which overlaps with page[1].memcg_data and
>>> use 1 << compound_order() instead, since I do not want to add a new
>>> union to struct page and compound_nr() is not as widely used as
>>> folio_nr_pages(). But let me know if there is a performance concern for
>>> this.
>>>
>>> Comments and suggestions are welcome.
>>>
>>
>> What does this mean for treating compound pages as folios, does this break
>> code that makes any assumptions about their interop?
>
> Yes. All folio initialization code is moved from prep_compound_page() to
> page_rmappable_folio(), so such users will see warnings on some folio fields
> are not set properly. They should call page_rmappable_folio() on compound
> pages they are planning to use as folios. A common use case is to
> vm_insert_page(s)() on subpages of a folio.
>
> For in-tree users, I am converting them all in this series.
Considering a recent report[1], where drivers/scsi/sg.c allocates compound
pages with __GFP_COMP and maps them into userspace via sg_vma_fault(),
I guess almost all __GFP_COMP users are really using folios instead of
compound pages.
[1] https://lore.kernel.org/all/PS1PPF7E1D7501F1E4F4441E7ECD056DEADAB98A@PS1PPF7E1D7501F.apcprd02.prod.outlook.com/
>
>>
>>>
>>>
>>> Link: https://lore.kernel.org/all/F7E3DF24-A37B-40A0-A507-CEF4AB76C44D@nvidia.com/ [1]
>>>
>>> Zi Yan (5):
>>> io_uring: allocate folio in io_mem_alloc_compound() and function
>>> rename
>>> mm/huge_memory: use page_rmappable_folio() to convert after-split
>>> folios
>>> mm/hugetlb: set large_rmappable on hugetlb and avoid deferred_list
>>> handling
>>> mm: only use struct page in compound_nr() and compound_order()
>>> mm: code separation for compound page and folio
>>>
>>> include/linux/mm.h | 12 ++++--------
>>> io_uring/memmap.c | 12 ++++++------
>>> mm/huge_memory.c | 5 ++---
>>> mm/hugetlb.c | 8 ++++----
>>> mm/hugetlb_cma.c | 2 +-
>>> mm/internal.h | 47 +++++++++++++++++++++++++++-------------------
>>> mm/mm_init.c | 2 +-
>>> mm/page_alloc.c | 23 ++++++++++++++++++-----
>>> 8 files changed, 64 insertions(+), 47 deletions(-)
>>>
>
>
> Best Regards,
> Yan, Zi
Best Regards,
Yan, Zi
next prev parent reply other threads:[~2026-02-04 18:29 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-30 3:48 [RFC PATCH 0/5] Separate compound page from folio 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 [this message]
2026-02-04 18:49 ` Jason Gunthorpe
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=33B161E0-5468-4A31-A5BC-B4F1FCE72CEC@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