From: Yeoreum Yun <yeoreum.yun@arm.com>
To: "David Hildenbrand (Arm)" <david@kernel.org>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>,
Yeoreum Yun <yeoreum.yun@arm.com>, Zi Yan <ziy@nvidia.com>,
"Liam R. Howlett" <liam@infradead.org>,
Nico Pache <nico.pache@linux.dev>,
Ryan Roberts <ryan.roberts@arm.com>, Dev Jain <dev.jain@arm.com>,
Barry Song <baohua@kernel.org>, Lance Yang <lance.yang@linux.dev>,
Usama Arif <usama.arif@linux.dev>,
Kiryl Shutsemau <kas@kernel.org>,
Lorenzo Stoakes <ljs@kernel.org>,
Vlastimil Babka <vbabka@kernel.org>,
Mike Rapoport <rppt@kernel.org>,
Suren Baghdasaryan <surenb@google.com>,
Michal Hocko <mhocko@suse.com>,
linux-mm@kvack.org, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org,
Andrew Morton <akpm@linux-foundation.org>,
Shuah Khan <shuah@kernel.org>
Subject: Re: [PATCH v3 2/2] kselftest: mm: fix intermittent failure khugepaged test
Date: Tue, 29 Sep 2026 11:08:29 +0100 [thread overview]
Message-ID: <aruOHat9wlu1H8la@e129823.arm.com> (raw)
In-Reply-To: <dcf6fb14-7048-481b-83c6-9e8da6d874f5@kernel.org>
On Tue, Sep 29, 2026 at 10:46:50AM +0200, David Hildenbrand (Arm) wrote:
> On 9/29/26 10:43, Baolin Wang wrote:
> >
> >
> > On 9/29/26 4:38 PM, David Hildenbrand (Arm) wrote:
> >> On 9/23/26 17:29, Yeoreum Yun wrote:
> >>> There are intermittent failures in collapse_max_ptes_swap() and
> >>> collapse_max_ptes_shared() when using the khugepaged_context:
> >>>
> >>> // while running ./khugepaged -s 2
> >>>
> >>> # Run test: collapse_max_ptes_shared (khugepaged:anon)
> >>> # Allocate huge page... OK
> >>> # Share huge page over fork()... OK
> >>> # Trigger CoW on page 1023 of 2048... OK
> >>> # Maybe collapse with max_ptes_shared exceeded.... OK
> >>> # Trigger CoW on page 1024 of 2048... Fail
> >>> Bail out! Unexpected huge page
> >>> # Planned tests != run tests (26 != 23)
> >>> # Totals: pass:23 fail:0 xfail:0 xpass:0 skip:0 error:0
> >>>
> >>> # Run test: collapse_max_ptes_swap (khugepaged:anon)
> >>> # Swapout 257 of 2048 pages... OK
> >>> # Maybe collapse with max_ptes_swap exceeded.... OK
> >>> # Swapout 256 of 2048 pages... OK
> >>> Bail out! Unexpected huge page
> >>> # Planned tests != run tests (26 != 17)
> >>> # Totals: pass:17 fail:0 xfail:0 xpass:0 skip:0 error:0
> >>>
> >>> This happens because khugepaged may collapse the pages before wait_for_scan()
> >>> is called, causing a sanity check that expects uncollapsed pages to fail.
> >>>
> >>> For example, in collapse_max_ptes_swap(), after faulting the pages back in
> >>> and paging out up to max_ptes_swap pages, khugepaged may collapse them again
> >>> before c->collapse() is called.
> >>>
> >>> To prevent this, mark the VMA with MADV_NOHUGEPAGE after it has been
> >>> collapsed by wait_for_scan() for anon. This prevents khugepaged from
> >>> collapsing it again before c->collapse() is called.
> >>>
> >>> This failure was observed on NVIDIA Spark with 16KB page.
> >>>
> >>> Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
> >>> Tested-by: Baolin Wang <baolin.wang@linux.alibaba.com>
> >>> Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
> >>> ---
> >>> tools/testing/selftests/mm/khugepaged.c | 3 +++
> >>> 1 file changed, 3 insertions(+)
> >>>
> >>> diff --git a/tools/testing/selftests/mm/khugepaged.c b/tools/testing/
> >>> selftests/mm/khugepaged.c
> >>> index 2aa7c9197158..b0cb02bf1a73 100644
> >>> --- a/tools/testing/selftests/mm/khugepaged.c
> >>> +++ b/tools/testing/selftests/mm/khugepaged.c
> >>> @@ -618,6 +618,9 @@ static bool wait_for_scan(const char *msg, char *p,
> >>> size_t len,
> >>> usleep(TICK);
> >>> }
> >>> + if (is_anon(ops))
> >>> + madvise(p, len, MADV_NOHUGEPAGE);
> >>> +
> >>
> >> Any reason we just do that unconditionally?
> >
> > Although it's a bit messy, as I mentioned before [1], unconditionally setting
> > MADV_NOHUGEPAGE will break shmem testing. Maybe add some comments.
>
> Ah, thanks for clarifying. The problem really is that we cannot undo a
> MADV_HUGEPAGE (give me hugepages) cleanly. We can only go to the other extreme
> (no huge pages).
>
> Yes, let's please add a comment describing why we limit it to anon.
Okay.
--
Sincerely,
Yeoreum Yun
prev parent reply other threads:[~2026-09-29 10:08 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-23 15:29 [PATCH v3 0/2] kselftest: mm: fix intermittent failure khugepaged test Yeoreum Yun
2026-09-23 15:29 ` [PATCH v3 1/2] kselftest: mm: return fail when child test result is fail in khugepaged Yeoreum Yun
2026-09-23 21:31 ` Gregory Price
2026-09-29 8:21 ` David Hildenbrand (Arm)
2026-09-29 8:32 ` Lorenzo Stoakes (ARM)
2026-09-23 15:29 ` [PATCH v3 2/2] kselftest: mm: fix intermittent failure khugepaged test Yeoreum Yun
2026-09-23 21:33 ` Gregory Price
2026-09-29 8:38 ` David Hildenbrand (Arm)
2026-09-29 8:43 ` Baolin Wang
2026-09-29 8:46 ` David Hildenbrand (Arm)
2026-09-29 10:08 ` Yeoreum Yun [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aruOHat9wlu1H8la@e129823.arm.com \
--to=yeoreum.yun@arm.com \
--cc=akpm@linux-foundation.org \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=david@kernel.org \
--cc=dev.jain@arm.com \
--cc=kas@kernel.org \
--cc=lance.yang@linux.dev \
--cc=liam@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=mhocko@suse.com \
--cc=nico.pache@linux.dev \
--cc=rppt@kernel.org \
--cc=ryan.roberts@arm.com \
--cc=shuah@kernel.org \
--cc=surenb@google.com \
--cc=usama.arif@linux.dev \
--cc=vbabka@kernel.org \
--cc=ziy@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.