[PATCH v5 0/6] __folio_split() clean up

Zi Yan posted 6 patches 2 months, 2 weeks ago
mm/huge_memory.c | 311 ++++++++++++++++++++++++-----------------------
1 file changed, 159 insertions(+), 152 deletions(-)
[PATCH v5 0/6] __folio_split() clean up
Posted by Zi Yan 2 months, 2 weeks ago
Hi Andrew,

This series replaces both [PATCH v3 0/2] __folio_split() clean up
and [PATCH] mm/huge_memory: refactor after-split (page) cache code.

Hi all,

This patchset refactors __folio_split() and __split_unmapped_folio() to:
1. make __split_unmapped_folio() reusable for splitting unmapped
   folios. It avoids the need for a new boolean unmapped parameter to guard
   mapping-related code when __split_unmapped_folio() is reused to split
   unmapped folios.
2. improve code readability and prevent smatch/coverity checkers from
   complaining about NULL mapping referencing.

An additional benefit for __split_unmapped_folio() refactoring 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.

The patchset is based on mm-new with aforementioned two patchsets
reverted. It passes mm selftests.

Changelog
===
From V4[6]:
1. Use VM_WARN_ONCE_ON_FOLIO() without return -EINVAL.

From V3[4]:
1. Split up Patch 1 into incremental changes:
    a. Patch 1 moves code out of __split_unmapped_folio();
    b. Patch 2 removes after_split label in __split_unmapped_folio();
    c. Patch 3 refactors __folio_split() to deduplicate code;
    d. Patch 4 converts VM_BUGs to VM_WARMs;
2. Added "mm/huge_memory: refactor after-split (page) cache code"
   patch[5] to this series.
3. Added remap_flags to make remap_page() call easier to read.
4. Updated Patch 1 commit log to include variable rename information.
5. Converted additional VM_BUGs in __folio_split().
6. Renamed next_folio to end_folio to avoid confusion.
7. Added a comment about start for loop with folio_next(folio) instead
   of just folio plus skipping folio in the loop body.
8. Dropped swapcache folio split check code from __split_unmapped_folio(),
   since the check is already done at the beginning of __folio_split().

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/
[3] https://lore.kernel.org/linux-mm/20250711182355.3592618-1-ziy@nvidia.com/
[4] https://lore.kernel.org/linux-mm/20250714171823.3626213-1-ziy@nvidia.com/
[5] https://lore.kernel.org/linux-mm/20250716171112.3666150-1-ziy@nvidia.com/
[6] https://lore.kernel.org/linux-mm/20250718023000.4044406-1-ziy@nvidia.com/

Zi Yan (6):
  mm/huge_memory: move unrelated code out of __split_unmapped_folio()
  mm/huge_memory: remove after_split label in __split_unmapped_folio().
  mm/huge_memory: deduplicate code in __folio_split().
  mm/huge_memory: convert VM_BUG* to VM_WARN* in __folio_split.
  mm/huge_memory: get frozen folio refcount with
    folio_expected_ref_count()
  mm/huge_memory: refactor after-split (page) cache code.

 mm/huge_memory.c | 311 ++++++++++++++++++++++++-----------------------
 1 file changed, 159 insertions(+), 152 deletions(-)

-- 
2.47.2