linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] selftests: khugepaged: fix the shmem collapse failure
@ 2025-06-12  3:54 Baolin Wang
  2025-06-12  3:54 ` [PATCH 2/2] selftests: mm: add shmem collpase as a default test item Baolin Wang
                   ` (4 more replies)
  0 siblings, 5 replies; 17+ messages in thread
From: Baolin Wang @ 2025-06-12  3:54 UTC (permalink / raw)
  To: akpm, david
  Cc: lorenzo.stoakes, Liam.Howlett, npache, ryan.roberts, dev.jain,
	baohua, shuah, ziy, baolin.wang, linux-mm, linux-kselftest,
	linux-kernel

When running the khugepaged selftest for shmem (./khugepaged all:shmem),
I encountered the following test failures:
"
Run test: collapse_full (khugepaged:shmem)
Collapse multiple fully populated PTE table.... Fail
...
Run test: collapse_single_pte_entry (khugepaged:shmem)
Collapse PTE table with single PTE entry present.... Fail
...
Run test: collapse_full_of_compound (khugepaged:shmem)
Allocate huge page... OK
Split huge page leaving single PTE page table full of compound pages... OK
Collapse PTE table full of compound pages.... Fail
"

The reason for the failure is that, it will set MADV_NOHUGEPAGE to prevent
khugepaged from continuing to scan shmem VMA after khugepaged finishes
scanning in the wait_for_scan() function. Moreover, shmem requires a refault
to establish PMD mappings.

However, after commit 2b0f922323cc, PMD mappings are prevented if the VMA is
set with MADV_NOHUGEPAGE flag, so shmem cannot establish PMD mappings during
refault.

To fix this issue, we can set the MADV_NOHUGEPAGE flag after the shmem refault.
With this fix, the shmem test case passes.

Fixes: 2b0f922323cc ("mm: don't install PMD mappings when THPs are disabled by the hw/process/vma")
Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
---
 tools/testing/selftests/mm/khugepaged.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/tools/testing/selftests/mm/khugepaged.c b/tools/testing/selftests/mm/khugepaged.c
index 8a4d34cce36b..d462f62d8116 100644
--- a/tools/testing/selftests/mm/khugepaged.c
+++ b/tools/testing/selftests/mm/khugepaged.c
@@ -561,8 +561,6 @@ static bool wait_for_scan(const char *msg, char *p, int nr_hpages,
 		usleep(TICK);
 	}
 
-	madvise(p, nr_hpages * hpage_pmd_size, MADV_NOHUGEPAGE);
-
 	return timeout == -1;
 }
 
@@ -585,6 +583,7 @@ static void khugepaged_collapse(const char *msg, char *p, int nr_hpages,
 	if (ops != &__anon_ops)
 		ops->fault(p, 0, nr_hpages * hpage_pmd_size);
 
+	madvise(p, nr_hpages * hpage_pmd_size, MADV_NOHUGEPAGE);
 	if (ops->check_huge(p, expect ? nr_hpages : 0))
 		success("OK");
 	else
-- 
2.43.5



^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2025-06-20  6:13 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-06-12  3:54 [PATCH 1/2] selftests: khugepaged: fix the shmem collapse failure Baolin Wang
2025-06-12  3:54 ` [PATCH 2/2] selftests: mm: add shmem collpase as a default test item Baolin Wang
2025-06-12  4:20   ` Bird, Tim
2025-06-12  5:33     ` Baolin Wang
2025-06-12  5:14   ` Dev Jain
2025-06-12 10:24   ` David Hildenbrand
2025-06-12 15:47   ` Zi Yan
2025-06-12  5:10 ` [PATCH 1/2] selftests: khugepaged: fix the shmem collapse failure Dev Jain
2025-06-12  5:18   ` Baolin Wang
2025-06-12 10:08 ` David Hildenbrand
2025-06-12 11:37   ` Baolin Wang
2025-06-12 11:45     ` David Hildenbrand
2025-06-12 12:14       ` Baolin Wang
2025-06-12 15:46 ` Zi Yan
2025-06-12 15:48   ` David Hildenbrand
2025-06-13  1:41   ` Baolin Wang
2025-06-20  6:13 ` Mario Casquero

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox