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.

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);
 }
 
-- 
2.54.0


Reply via email to