This patchset uses kpageflags to get after-split folio orders for a better split_huge_page_test result check[1]. The added gather_after_split_folio_orders() scans through a VPN range and collects the numbers of folios at different orders. check_after_split_folio_orders() compares the result of gather_after_split_folio_orders() to a given list of numbers of different orders.
This patchset also added new order and in folio offset to the split huge page debugfs's pr_debug()s;
Changelog === From V3[4]: 1. Renamed {gather,check}_folio_orders() to {gather,check}_after_split_folio_orders() and moved them to split_huge_page_test.c, since both functions are not general enough for arbitrary folio order checks in any virtual address range. Comments are added to clarify the purpose of these functions. 2. Fixed file descriptor error check. 3. Removed unnecessary statements. 4. Fixed is_backed_by_folio() tail PFN off-by-one check issue. 5. Added a check in is_backed_by_folio() to detect if the order of the backing large folio is larger than the given order. 6. Moved misplaced comments in is_backed_by_folio(). 7. Added a comment and a commit message to clarify why the split range of folio_split() tests is changed.
From V2[3]: 1. Added two missing free()s in check_folio_orders(). 2. Reimplemented is_backed_by_thp() to use kpageflags to get precise folio order information and renamed it to is_backed_by_folio() in new Patch 3. 3. Renamed *_file to *_fd in Patch 2. 4. Indentation fixes. 5. Fixed vaddr stepping issue in gather_folio_orders() when a compound tail page is encountered. 6. Used pmd_order in place of max_order in split_huge_page_test.c. 7. Documented gather_folio_orders().
From V1[2]: 1. Dropped split_huge_pages_pid() for loop step change to avoid messing up with PTE-mapped THP handling. split_huge_page_test.c is changed to perform split at [addr, addr + pagesize) range to limit one folio_split() per folio. 2. Moved pr_debug changes in Patch 2 to Patch 1. 3. Moved KPF_* to vm_util.h and used PAGEMAP_PFN instead of local PFN_MASK. 4. Used pagemap_get_pfn() helper. 5. Used char *vaddr and size_t len as inputs to gather_folio_orders() and check_folio_orders() instead of vpn and nr_pages. 6. Removed variable length variables and used malloc instead.
[1] https://lore.kernel.org/linux-mm/e2f32bdb-e4a4-447c-867c-31405cbba151@redhat... [2] https://lore.kernel.org/linux-mm/20250806022045.342824-1-ziy@nvidia.com/ [3] https://lore.kernel.org/linux-mm/20250808190144.797076-1-ziy@nvidia.com/ [4] https://lore.kernel.org/linux-mm/20250812155512.926011-1-ziy@nvidia.com/
Zi Yan (5): mm/huge_memory: add new_order and offset to split_huge_pages*() pr_debug. selftests/mm: mark all functions static in split_huge_page_test.c selftests/mm: reimplement is_backed_by_thp() with more precise check selftests/mm: add check_after_split_folio_orders() helper. selftests/mm: check after-split folio orders in split_huge_page_test.
mm/huge_memory.c | 8 +- .../selftests/mm/split_huge_page_test.c | 345 +++++++++++++++--- tools/testing/selftests/mm/vm_util.c | 13 + tools/testing/selftests/mm/vm_util.h | 4 + 4 files changed, 311 insertions(+), 59 deletions(-)