> __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
Nit: description of '-s' would be nice :)
> 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) <[email protected]>
>
> diff --git a/tools/testing/selftests/mm/khugepaged.c
> b/tools/testing/selftests/mm/khugepaged.c
> index a3d14cc1a2bf..5aa92de93ec1 100644
> --- a/tools/testing/selftests/mm/khugepaged.c
> +++ b/tools/testing/selftests/mm/khugepaged.c
> @@ -572,8 +572,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);
>
> @@ -586,9 +586,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.
>From my experience LLMs tend to add lengthy comments that describe their
actions in the moment. Adding to the prompt an instruction to make
comments more concise and in the global context usually helps :)
--
Sincerely yours,
Mike.