From: "Kiryl Shutsemau (Meta)" __madvise_collapse() turns THP off before each MADV_COLLAPSE, both to keep khugepaged out of the range and to prove MADV_COLLAPSE ignores the setting. It clears the global controls only, which is no longer enough. A per-order control overrides them, and -s leaves the source order at "always", so khugepaged collapses the very range the case is working on. The case then fails on a collapse that was interfered with rather than refused. Clear the per-order controls too. Set them to "inherit", not "never". khugepaged honours the global never and stays out. A forced shmem collapse takes the order it builds from these very controls, and still finds one. Fixes: 9f0704eae8a4 ("selftests/mm/khugepaged: enlighten for multi-size THP") Assisted-by: Claude-Code:claude-opus-5 Signed-off-by: Kiryl Shutsemau (Meta) --- tools/testing/selftests/mm/khugepaged.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/mm/khugepaged.c b/tools/testing/selftests/mm/khugepaged.c index 7eb9db0005a0..0008862e7cbc 100644 --- a/tools/testing/selftests/mm/khugepaged.c +++ b/tools/testing/selftests/mm/khugepaged.c @@ -550,8 +550,8 @@ static bool is_anon(struct mem_ops *ops) static void __madvise_collapse(const char *msg, char *p, int nr_hpages, struct mem_ops *ops, bool expect) { - int ret; struct thp_settings settings = *thp_current_settings(); + int ret, i; ksft_print_msg("%s...", msg); @@ -564,9 +564,20 @@ static void __madvise_collapse(const char *msg, char *p, int nr_hpages, /* * Prevent khugepaged interference and tests that MADV_COLLAPSE * ignores /sys/kernel/mm/transparent_hugepage/enabled + * + * The per-order controls have to go too, not just the global one: a + * source order left at "always" -- which -s does -- lets khugepaged + * collapse the very range the case is working on. Set them to + * "inherit", not "never". khugepaged honours the global never and + * stays out. A forced shmem collapse takes the order it builds from + * these very controls, and still finds one. */ settings.thp_enabled = THP_NEVER; settings.shmem_enabled = SHMEM_NEVER; + for (i = 0; i < NR_ORDERS; i++) { + settings.hugepages[i].enabled = THP_INHERIT; + settings.shmem_hugepages[i].enabled = SHMEM_INHERIT; + } thp_push_settings(&settings); /* Clear VM_NOHUGEPAGE */ -- 2.54.0