On 9/8/26 8:50 PM, Kiryl Shutsemau wrote:
From: "Kiryl Shutsemau (Meta)" <[email protected]>

collapse_order_mixed_sources() faults its region as order-2 folios and
collapses them to the -c target.  Order 2 is below the contpte size on
every arm64 page size, so nothing in this suite collapses a contpte-mapped
source on purpose.

Let -s name the source order alongside -c.  The case then faults at that
order, keeping order 2 when -s is absent, and the source order has to be a
supported mTHP order below the target.  The other mTHP cases are
unaffected: mthp_push_target_order() enables only the target order.

"-s 5 -c 7" on arm64/64K then collapses contpte-mapped sources into a
larger mTHP.

Make sense. But we should validate invalid parameter combinations for '-s' and '-c'. For example, when I set the following unreasonable parameters, some test cases fail, so such invalid configurations should be rejected.

[root@]# ./khugepaged -s 7 -c 6 mthp_khugepaged:anon
TAP version 13
# Save THP and khugepaged settings... OK
1..8
# Allocate huge page on fault... OK
# Split huge PMD on MADV_DONTNEED... OK
ok 1 allocate on fault and split
#
# Run test: collapse_full (mthp_khugepaged:anon)
# Collapse multiple fully populated PTE table.... Fail
not ok 2 collapse_full
#
# Run test: collapse_empty (mthp_khugepaged:anon)
# Do not collapse empty PTE table.... OK
ok 3 collapse_empty
#
# Run test: collapse_single_mthp (mthp_khugepaged:anon)
# Collapse PTE table with half PTE entries present.... Fail
not ok 4 collapse_single_mthp
#
# Run test: collapse_order_single_window (mthp_khugepaged:anon)
# Collapse one fully populated window... OK
ok 5 collapse_order_single_window
#
# Run test: collapse_order_partial_window (mthp_khugepaged:anon)
# Collapse window with single PTE entry present... OK
ok 6 collapse_order_partial_window
#
# Run test: collapse_order_max_ptes_none (mthp_khugepaged:anon)
# Collapse full window, not the one missing a page... OK
ok 7 collapse_order_max_ptes_none
#
# Run test: collapse_order_mixed_sources (mthp_khugepaged:anon)
ok 8 # SKIP collapse_order_mixed_sources: no supported source order below target # 1 skipped test(s) detected. Consider enabling relevant config options to improve coverage.
# Totals: pass:5 fail:2 xfail:0 xpass:0 skip:1 error:0

Assisted-by: LLM
Acked-by: Lorenzo Stoakes (ARM) <[email protected]>
Tested-by: Muhammad Usama Anjum <[email protected]>
Signed-off-by: Kiryl Shutsemau (Meta) <[email protected]>
---
  tools/testing/selftests/mm/khugepaged.c | 17 ++++++++++-------
  1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/tools/testing/selftests/mm/khugepaged.c 
b/tools/testing/selftests/mm/khugepaged.c
index fb4efaf67c40..b15cd07fc0b3 100644
--- a/tools/testing/selftests/mm/khugepaged.c
+++ b/tools/testing/selftests/mm/khugepaged.c
@@ -1352,11 +1352,13 @@ static void collapse_order_max_ptes_none(struct 
collapse_context *c,
  static void collapse_order_mixed_sources(struct collapse_context *c,
                                         struct mem_ops *ops)
  {
+       int source_order = anon_order ? anon_order : MIN_MTHP_ORDER;
        struct thp_settings settings;
        void *p;
- if (collapse_order <= MIN_MTHP_ORDER) {
-               ksft_test_result_skip("%s: no source order below target\n",
+       if (source_order >= collapse_order ||
+           !(thp_supported_orders() & (1UL << source_order))) {
+               ksft_test_result_skip("%s: no supported source order below 
target\n",
                                      __func__);
                return;
        }
@@ -1364,7 +1366,7 @@ static void collapse_order_mixed_sources(struct 
collapse_context *c,
        mthp_push_target_order();
settings = *thp_current_settings();
-       settings.hugepages[MIN_MTHP_ORDER].enabled = THP_ALWAYS;
+       settings.hugepages[source_order].enabled = THP_ALWAYS;
        thp_push_settings(&settings);
        p = ops->setup_area(1);
        ops->fault(p, 0, hpage_pmd_size);
@@ -1374,10 +1376,9 @@ static void collapse_order_mixed_sources(struct 
collapse_context *c,
         * The allocator can fall back to smaller folios under fragmentation;
         * having nothing to collapse from is not a failure.
         */
-       if (!is_range_backed_by_order(p, hpage_pmd_size, MIN_MTHP_ORDER,
+       if (!is_range_backed_by_order(p, hpage_pmd_size, source_order,
                                      pagemap_fd, kpageflags_fd)) {
-               ksft_print_msg("No order-%d sources to collapse...",
-                              MIN_MTHP_ORDER);
+               ksft_print_msg("No order-%d sources to collapse...", 
source_order);
                skip("Skip");
                ops->cleanup_area(p, hpage_pmd_size);
                thp_pop_settings();
@@ -1387,7 +1388,8 @@ static void collapse_order_mixed_sources(struct 
collapse_context *c,
if (madvise(p, hpage_pmd_size, MADV_HUGEPAGE))
                ksft_exit_fail_perror("madvise(MADV_HUGEPAGE)");
-       ksft_print_msg("Collapse region backed by smaller large folios...");
+       ksft_print_msg("Collapse region backed by order-%d sources...",
+                      source_order);
        if (!khugepaged_full_pass(MTHP_PASS_TIMEOUT_S))
                fail("Timeout");
        else if (all_windows_at_order(p, hpage_pmd_size))
@@ -1418,6 +1420,7 @@ static void usage(void)
        fprintf(stderr, "\t\t-s: mTHP size, expressed as page order.\n");
        fprintf(stderr, "\t\t    Defaults to 0. Use this size for anon or shmem 
allocations.\n");
        fprintf(stderr, "\t\t-c: collapse order for mTHP collapse, expressed as page 
order.\n");
+       fprintf(stderr, "\t\t    -s, if set, is the source order for the 
mixed-source case.\n");
        exit(1);
  }


Reply via email to