[PATCH v3 0/2] __folio_split() clean up.

Zi Yan posted 2 patches 2 months, 3 weeks ago
mm/huge_memory.c | 289 +++++++++++++++++++++++------------------------
1 file changed, 142 insertions(+), 147 deletions(-)
[PATCH v3 0/2] __folio_split() clean up.
Posted by Zi Yan 2 months, 3 weeks ago
Based on the prior discussion[1], this patch improves
__split_unmapped_folio() by making it reusable for splitting unmapped
folios. This helps avoid the need for a new boolean unmapped parameter
to guard mapping-related code.

An additional benefit is that __split_unmapped_folio() could be
called on after-split folios by __folio_split(). It can enable new split
methods. For example, at deferred split time, unmapped subpages can
scatter arbitrarily within a large folio, neither uniform nor non-uniform
split can maximize after-split folio orders for mapped subpages.
The hope is that by calling __split_unmapped_folio() multiple times,
a better split result can be achieved.

It passed mm selftests.


Changelog
===
From V2[3]:
1. Code format fixes
2. Restructured code to remove after_split goto label.

From V1[2]:
1. Fixed indentations.
2. Used folio_expected_ref_count() to calculate ref_count instead of
   open coding.


[1] https://lore.kernel.org/linux-mm/94D8C1A4-780C-4BEC-A336-7D3613B54845@nvidia.com/
[2] https://lore.kernel.org/linux-mm/20250711030259.3574392-1-ziy@nvidia.com/
[2] https://lore.kernel.org/linux-mm/20250711182355.3592618-1-ziy@nvidia.com/

Zi Yan (2):
  mm/huge_memory: move unrelated code out of __split_unmapped_folio()
  mm/huge_memory: use folio_expected_ref_count() to calculate ref_count.

 mm/huge_memory.c | 289 +++++++++++++++++++++++------------------------
 1 file changed, 142 insertions(+), 147 deletions(-)

-- 
2.47.2
Re: [PATCH v3 0/2] __folio_split() clean up.
Posted by Lorenzo Stoakes 2 months, 3 weeks ago
Hm something has gone weird in mm-new with this.

The patches are in the correct order, but the 2/2 patch, 'mm/huge_memory: use
folio_expected_ref_count() to calculate ref_count.' contains the cover letter
and has the suffix:

    This patch (of 2):

    Instead of open coding the ref_count calculation, use
    folio_expected_ref_count()

But immediately prior to it is 1/2 - mm/huge_memory: move unrelated code
out of __split_unmapped_folio() but with no cover letter reference.

Andrew - has quilt got confused here? :)

Thanks, Lorenzo

On Mon, Jul 14, 2025 at 01:18:21PM -0400, Zi Yan wrote:
> Based on the prior discussion[1], this patch improves
> __split_unmapped_folio() by making it reusable for splitting unmapped
> folios. This helps avoid the need for a new boolean unmapped parameter
> to guard mapping-related code.
>
> An additional benefit is that __split_unmapped_folio() could be
> called on after-split folios by __folio_split(). It can enable new split
> methods. For example, at deferred split time, unmapped subpages can
> scatter arbitrarily within a large folio, neither uniform nor non-uniform
> split can maximize after-split folio orders for mapped subpages.
> The hope is that by calling __split_unmapped_folio() multiple times,
> a better split result can be achieved.
>
> It passed mm selftests.
>
>
> Changelog
> ===
> From V2[3]:
> 1. Code format fixes
> 2. Restructured code to remove after_split goto label.
>
> From V1[2]:
> 1. Fixed indentations.
> 2. Used folio_expected_ref_count() to calculate ref_count instead of
>    open coding.
>
>
> [1] https://lore.kernel.org/linux-mm/94D8C1A4-780C-4BEC-A336-7D3613B54845@nvidia.com/
> [2] https://lore.kernel.org/linux-mm/20250711030259.3574392-1-ziy@nvidia.com/
> [2] https://lore.kernel.org/linux-mm/20250711182355.3592618-1-ziy@nvidia.com/
>
> Zi Yan (2):
>   mm/huge_memory: move unrelated code out of __split_unmapped_folio()
>   mm/huge_memory: use folio_expected_ref_count() to calculate ref_count.
>
>  mm/huge_memory.c | 289 +++++++++++++++++++++++------------------------
>  1 file changed, 142 insertions(+), 147 deletions(-)
>
> --
> 2.47.2
>
Re: [PATCH v3 0/2] __folio_split() clean up.
Posted by Andrew Morton 2 months, 3 weeks ago
On Thu, 17 Jul 2025 13:40:55 +0100 Lorenzo Stoakes <lorenzo.stoakes@oracle.com> wrote:

> The patches are in the correct order, but the 2/2 patch, 'mm/huge_memory: use
> folio_expected_ref_count() to calculate ref_count.' contains the cover letter
> and has the suffix:
> 
>     This patch (of 2):
> 
>     Instead of open coding the ref_count calculation, use
>     folio_expected_ref_count()
> 
> But immediately prior to it is 1/2 - mm/huge_memory: move unrelated code
> out of __split_unmapped_folio() but with no cover letter reference.

Doh, I placed the [0/2] inside [2/2] instead of [1/2].

Fixed, I'll hang onto the v3 series - it already has a TBU (to be
updated) akpm-note-to-self.
Re: [PATCH v3 0/2] __folio_split() clean up.
Posted by Zi Yan 2 months, 3 weeks ago
On 17 Jul 2025, at 8:40, Lorenzo Stoakes wrote:

> Hm something has gone weird in mm-new with this.
>
> The patches are in the correct order, but the 2/2 patch, 'mm/huge_memory: use
> folio_expected_ref_count() to calculate ref_count.' contains the cover letter
> and has the suffix:
>
>     This patch (of 2):
>
>     Instead of open coding the ref_count calculation, use
>     folio_expected_ref_count()
>
> But immediately prior to it is 1/2 - mm/huge_memory: move unrelated code
> out of __split_unmapped_folio() but with no cover letter reference.
>
> Andrew - has quilt got confused here? :)

Since I am going to send V3 (also include after-split page cache code patch),
maybe Andrew can drop this series and
“mm/huge_memory: refactor after-split (page) cache code”. Hopefully
we can get everything right in V3.

>
> Thanks, Lorenzo
>
> On Mon, Jul 14, 2025 at 01:18:21PM -0400, Zi Yan wrote:
>> Based on the prior discussion[1], this patch improves
>> __split_unmapped_folio() by making it reusable for splitting unmapped
>> folios. This helps avoid the need for a new boolean unmapped parameter
>> to guard mapping-related code.
>>
>> An additional benefit is that __split_unmapped_folio() could be
>> called on after-split folios by __folio_split(). It can enable new split
>> methods. For example, at deferred split time, unmapped subpages can
>> scatter arbitrarily within a large folio, neither uniform nor non-uniform
>> split can maximize after-split folio orders for mapped subpages.
>> The hope is that by calling __split_unmapped_folio() multiple times,
>> a better split result can be achieved.
>>
>> It passed mm selftests.
>>
>>
>> Changelog
>> ===
>> From V2[3]:
>> 1. Code format fixes
>> 2. Restructured code to remove after_split goto label.
>>
>> From V1[2]:
>> 1. Fixed indentations.
>> 2. Used folio_expected_ref_count() to calculate ref_count instead of
>>    open coding.
>>
>>
>> [1] https://lore.kernel.org/linux-mm/94D8C1A4-780C-4BEC-A336-7D3613B54845@nvidia.com/
>> [2] https://lore.kernel.org/linux-mm/20250711030259.3574392-1-ziy@nvidia.com/
>> [2] https://lore.kernel.org/linux-mm/20250711182355.3592618-1-ziy@nvidia.com/
>>
>> Zi Yan (2):
>>   mm/huge_memory: move unrelated code out of __split_unmapped_folio()
>>   mm/huge_memory: use folio_expected_ref_count() to calculate ref_count.
>>
>>  mm/huge_memory.c | 289 +++++++++++++++++++++++------------------------
>>  1 file changed, 142 insertions(+), 147 deletions(-)
>>
>> --
>> 2.47.2
>>


Best Regards,
Yan, Zi
Re: [PATCH v3 0/2] __folio_split() clean up.
Posted by Lorenzo Stoakes 2 months, 3 weeks ago
On Thu, Jul 17, 2025 at 11:54:36AM -0400, Zi Yan wrote:
> On 17 Jul 2025, at 8:40, Lorenzo Stoakes wrote:
>
> > Hm something has gone weird in mm-new with this.
> >
> > The patches are in the correct order, but the 2/2 patch, 'mm/huge_memory: use
> > folio_expected_ref_count() to calculate ref_count.' contains the cover letter
> > and has the suffix:
> >
> >     This patch (of 2):
> >
> >     Instead of open coding the ref_count calculation, use
> >     folio_expected_ref_count()
> >
> > But immediately prior to it is 1/2 - mm/huge_memory: move unrelated code
> > out of __split_unmapped_folio() but with no cover letter reference.
> >
> > Andrew - has quilt got confused here? :)
>
> Since I am going to send V3 (also include after-split page cache code patch),
> maybe Andrew can drop this series and
> “mm/huge_memory: refactor after-split (page) cache code”. Hopefully
> we can get everything right in V3.

Cool yeah simpler :)