* [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
* [PATCH 2/2] selftests: mm: add shmem collpase as a default test item
2025-06-12 3:54 [PATCH 1/2] selftests: khugepaged: fix the shmem collapse failure Baolin Wang
@ 2025-06-12 3:54 ` Baolin Wang
2025-06-12 4:20 ` Bird, Tim
` (3 more replies)
2025-06-12 5:10 ` [PATCH 1/2] selftests: khugepaged: fix the shmem collapse failure Dev Jain
` (3 subsequent siblings)
4 siblings, 4 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
Currently, we only test anonymous memory collapse by default. We should also
add shmem collapse as a default test item to catch issues that could break
the test cases.
Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
---
tools/testing/selftests/mm/run_vmtests.sh | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/tools/testing/selftests/mm/run_vmtests.sh b/tools/testing/selftests/mm/run_vmtests.sh
index 33fc7fafa8f9..a38c984103ce 100755
--- a/tools/testing/selftests/mm/run_vmtests.sh
+++ b/tools/testing/selftests/mm/run_vmtests.sh
@@ -485,6 +485,10 @@ CATEGORY="thp" run_test ./khugepaged
CATEGORY="thp" run_test ./khugepaged -s 2
+CATEGORY="thp" run_test ./khugepaged all:shmem
+
+CATEGORY="thp" run_test ./khugepaged -s 4 all:shmem
+
CATEGORY="thp" run_test ./transhuge-stress -d 20
# Try to create XFS if not provided
--
2.43.5
^ permalink raw reply [flat|nested] 17+ messages in thread
* RE: [PATCH 2/2] selftests: mm: add shmem collpase as a default test item
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
` (2 subsequent siblings)
3 siblings, 1 reply; 17+ messages in thread
From: Bird, Tim @ 2025-06-12 4:20 UTC (permalink / raw)
To: Baolin Wang, akpm, david
Cc: lorenzo.stoakes, Liam.Howlett, npache, ryan.roberts, dev.jain,
baohua, shuah, ziy, linux-mm, linux-kselftest, linux-kernel
collpase in the subject line should be collapse
-- Tim
> -----Original Message-----
> From: Baolin Wang <baolin.wang@linux.alibaba.com>
> Subject: [PATCH 2/2] selftests: mm: add shmem collpase as a default test item
>
> Currently, we only test anonymous memory collapse by default. We should also add shmem collapse as a default test item to catch issues that
> could break the test cases. Signed-off-by: Baolin Wang <baolin. wang@ linux. alibaba. com> --- tools/testing/selftests/mm/run_vmtests. sh
>
> Currently, we only test anonymous memory collapse by default. We should also
> add shmem collapse as a default test item to catch issues that could break
> the test cases.
>
> Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
> ---
> tools/testing/selftests/mm/run_vmtests.sh | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/tools/testing/selftests/mm/run_vmtests.sh b/tools/testing/selftests/mm/run_vmtests.sh
> index 33fc7fafa8f9..a38c984103ce 100755
> --- a/tools/testing/selftests/mm/run_vmtests.sh
> +++ b/tools/testing/selftests/mm/run_vmtests.sh
> @@ -485,6 +485,10 @@ CATEGORY="thp" run_test ./khugepaged
>
> CATEGORY="thp" run_test ./khugepaged -s 2
>
> +CATEGORY="thp" run_test ./khugepaged all:shmem
> +
> +CATEGORY="thp" run_test ./khugepaged -s 4 all:shmem
> +
> CATEGORY="thp" run_test ./transhuge-stress -d 20
>
> # Try to create XFS if not provided
> --
> 2.43.5
>
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 1/2] selftests: khugepaged: fix the shmem collapse failure
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 5:10 ` Dev Jain
2025-06-12 5:18 ` Baolin Wang
2025-06-12 10:08 ` David Hildenbrand
` (2 subsequent siblings)
4 siblings, 1 reply; 17+ messages in thread
From: Dev Jain @ 2025-06-12 5:10 UTC (permalink / raw)
To: Baolin Wang, akpm, david
Cc: lorenzo.stoakes, Liam.Howlett, npache, ryan.roberts, baohua,
shuah, ziy, linux-mm, linux-kselftest, linux-kernel
On 12/06/25 9:24 am, Baolin Wang wrote:
> 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
The idea looks sane to me, but do we need to add the madvise call to
madvise_retracted_page_tables() too, since that also calls wait_for_scan()?
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 2/2] selftests: mm: add shmem collpase as a default test item
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:14 ` Dev Jain
2025-06-12 10:24 ` David Hildenbrand
2025-06-12 15:47 ` Zi Yan
3 siblings, 0 replies; 17+ messages in thread
From: Dev Jain @ 2025-06-12 5:14 UTC (permalink / raw)
To: Baolin Wang, akpm, david
Cc: lorenzo.stoakes, Liam.Howlett, npache, ryan.roberts, baohua,
shuah, ziy, linux-mm, linux-kselftest, linux-kernel
On 12/06/25 9:24 am, Baolin Wang wrote:
> Currently, we only test anonymous memory collapse by default. We should also
> add shmem collapse as a default test item to catch issues that could break
> the test cases.
>
> Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
> ---
> tools/testing/selftests/mm/run_vmtests.sh | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/tools/testing/selftests/mm/run_vmtests.sh b/tools/testing/selftests/mm/run_vmtests.sh
> index 33fc7fafa8f9..a38c984103ce 100755
> --- a/tools/testing/selftests/mm/run_vmtests.sh
> +++ b/tools/testing/selftests/mm/run_vmtests.sh
> @@ -485,6 +485,10 @@ CATEGORY="thp" run_test ./khugepaged
>
> CATEGORY="thp" run_test ./khugepaged -s 2
>
> +CATEGORY="thp" run_test ./khugepaged all:shmem
> +
> +CATEGORY="thp" run_test ./khugepaged -s 4 all:shmem
> +
> CATEGORY="thp" run_test ./transhuge-stress -d 20
>
> # Try to create XFS if not provided
Reviewed-by: Dev Jain <dev.jain@arm.com>
Tested-by: Dev Jain <dev.jain@arm.com>
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 1/2] selftests: khugepaged: fix the shmem collapse failure
2025-06-12 5:10 ` [PATCH 1/2] selftests: khugepaged: fix the shmem collapse failure Dev Jain
@ 2025-06-12 5:18 ` Baolin Wang
0 siblings, 0 replies; 17+ messages in thread
From: Baolin Wang @ 2025-06-12 5:18 UTC (permalink / raw)
To: Dev Jain, akpm, david
Cc: lorenzo.stoakes, Liam.Howlett, npache, ryan.roberts, baohua,
shuah, ziy, linux-mm, linux-kselftest, linux-kernel
On 2025/6/12 13:10, Dev Jain wrote:
>
> On 12/06/25 9:24 am, Baolin Wang wrote:
>> 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
>
> The idea looks sane to me, but do we need to add the madvise call to
> madvise_retracted_page_tables() too, since that also calls wait_for_scan()?
Yes, I also realized this after sending the patches:) Thanks.
To keep the original logic:
diff --git a/tools/testing/selftests/mm/khugepaged.c
b/tools/testing/selftests/mm/khugepaged.c
index d462f62d8116..3452763e2fe3 100644
--- a/tools/testing/selftests/mm/khugepaged.c
+++ b/tools/testing/selftests/mm/khugepaged.c
@@ -1074,6 +1074,7 @@ static void madvise_retracted_page_tables(struct
collapse_context *c,
return;
}
success("OK");
+ madvise(p, nr_hpages * hpage_pmd_size, MADV_NOHUGEPAGE);
c->collapse("Install huge PMD from page cache", p, nr_hpages, ops,
true);
validate_memory(p, 0, size);
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 2/2] selftests: mm: add shmem collpase as a default test item
2025-06-12 4:20 ` Bird, Tim
@ 2025-06-12 5:33 ` Baolin Wang
0 siblings, 0 replies; 17+ messages in thread
From: Baolin Wang @ 2025-06-12 5:33 UTC (permalink / raw)
To: Bird, Tim, akpm, david
Cc: lorenzo.stoakes, Liam.Howlett, npache, ryan.roberts, dev.jain,
baohua, shuah, ziy, linux-mm, linux-kselftest, linux-kernel
On 2025/6/12 12:20, Bird, Tim wrote:
> collpase in the subject line should be collapse
Good catch. Will fix the typo. Thanks.
>> -----Original Message-----
>> From: Baolin Wang <baolin.wang@linux.alibaba.com>
>> Subject: [PATCH 2/2] selftests: mm: add shmem collpase as a default test item
>>
>> Currently, we only test anonymous memory collapse by default. We should also add shmem collapse as a default test item to catch issues that
>> could break the test cases. Signed-off-by: Baolin Wang <baolin. wang@ linux. alibaba. com> --- tools/testing/selftests/mm/run_vmtests. sh
>>
>> Currently, we only test anonymous memory collapse by default. We should also
>> add shmem collapse as a default test item to catch issues that could break
>> the test cases.
>>
>> Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
>> ---
>> tools/testing/selftests/mm/run_vmtests.sh | 4 ++++
>> 1 file changed, 4 insertions(+)
>>
>> diff --git a/tools/testing/selftests/mm/run_vmtests.sh b/tools/testing/selftests/mm/run_vmtests.sh
>> index 33fc7fafa8f9..a38c984103ce 100755
>> --- a/tools/testing/selftests/mm/run_vmtests.sh
>> +++ b/tools/testing/selftests/mm/run_vmtests.sh
>> @@ -485,6 +485,10 @@ CATEGORY="thp" run_test ./khugepaged
>>
>> CATEGORY="thp" run_test ./khugepaged -s 2
>>
>> +CATEGORY="thp" run_test ./khugepaged all:shmem
>> +
>> +CATEGORY="thp" run_test ./khugepaged -s 4 all:shmem
>> +
>> CATEGORY="thp" run_test ./transhuge-stress -d 20
>>
>> # Try to create XFS if not provided
>> --
>> 2.43.5
>>
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 1/2] selftests: khugepaged: fix the shmem collapse failure
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 5:10 ` [PATCH 1/2] selftests: khugepaged: fix the shmem collapse failure Dev Jain
@ 2025-06-12 10:08 ` David Hildenbrand
2025-06-12 11:37 ` Baolin Wang
2025-06-12 15:46 ` Zi Yan
2025-06-20 6:13 ` Mario Casquero
4 siblings, 1 reply; 17+ messages in thread
From: David Hildenbrand @ 2025-06-12 10:08 UTC (permalink / raw)
To: Baolin Wang, akpm
Cc: lorenzo.stoakes, Liam.Howlett, npache, ryan.roberts, dev.jain,
baohua, shuah, ziy, linux-mm, linux-kselftest, linux-kernel
On 12.06.25 05:54, Baolin Wang wrote:
> When running the khugepaged selftest for shmem (./khugepaged all:shmem),
Hmm, this combination is not run automatically through run_tests.sh,
right? IIUC, it only runs "./khugepaged" which tests anon only ...
Should we add it there? Then I would probably have noticed that myself
earlier :)
> 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.
Right. It's always problematic when we have some contradicting
information in the VMA vs. pagecache.
>
> 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
It's a shame we have this weird interface: there is no way we can clear
VM_HUGEPAGE without setting VM_NOHUGEPAGE :(
But, do we even care about setting MADV_NOHUGEPAGE at all? IIUC, we'll
almost immediately later call cleanup_area() where we munmap(), right?
--
Cheers,
David / dhildenb
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 2/2] selftests: mm: add shmem collpase as a default test item
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:14 ` Dev Jain
@ 2025-06-12 10:24 ` David Hildenbrand
2025-06-12 15:47 ` Zi Yan
3 siblings, 0 replies; 17+ messages in thread
From: David Hildenbrand @ 2025-06-12 10:24 UTC (permalink / raw)
To: Baolin Wang, akpm
Cc: lorenzo.stoakes, Liam.Howlett, npache, ryan.roberts, dev.jain,
baohua, shuah, ziy, linux-mm, linux-kselftest, linux-kernel
On 12.06.25 05:54, Baolin Wang wrote:
> Currently, we only test anonymous memory collapse by default. We should also
> add shmem collapse as a default test item to catch issues that could break
> the test cases.
>
> Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
> ---
> tools/testing/selftests/mm/run_vmtests.sh | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/tools/testing/selftests/mm/run_vmtests.sh b/tools/testing/selftests/mm/run_vmtests.sh
> index 33fc7fafa8f9..a38c984103ce 100755
> --- a/tools/testing/selftests/mm/run_vmtests.sh
> +++ b/tools/testing/selftests/mm/run_vmtests.sh
> @@ -485,6 +485,10 @@ CATEGORY="thp" run_test ./khugepaged
>
> CATEGORY="thp" run_test ./khugepaged -s 2
>
> +CATEGORY="thp" run_test ./khugepaged all:shmem
> +
> +CATEGORY="thp" run_test ./khugepaged -s 4 all:shmem
Ahh, there we have it already, nice :)
Acked-by: David Hildenbrand <david@redhat.com>
--
Cheers,
David / dhildenb
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 1/2] selftests: khugepaged: fix the shmem collapse failure
2025-06-12 10:08 ` David Hildenbrand
@ 2025-06-12 11:37 ` Baolin Wang
2025-06-12 11:45 ` David Hildenbrand
0 siblings, 1 reply; 17+ messages in thread
From: Baolin Wang @ 2025-06-12 11:37 UTC (permalink / raw)
To: David Hildenbrand, akpm
Cc: lorenzo.stoakes, Liam.Howlett, npache, ryan.roberts, dev.jain,
baohua, shuah, ziy, linux-mm, linux-kselftest, linux-kernel
On 2025/6/12 18:08, David Hildenbrand wrote:
> On 12.06.25 05:54, Baolin Wang wrote:
>> When running the khugepaged selftest for shmem (./khugepaged all:shmem),
>
> Hmm, this combination is not run automatically through run_tests.sh,
> right? IIUC, it only runs "./khugepaged" which tests anon only ...
>
> Should we add it there? Then I would probably have noticed that myself
> earlier :)
Yes, see patch 2.
>> 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.
>
> Right. It's always problematic when we have some contradicting
> information in the VMA vs. pagecache.
>
>>
>> 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
>
> It's a shame we have this weird interface: there is no way we can clear
> VM_HUGEPAGE without setting VM_NOHUGEPAGE :(
Right.
> But, do we even care about setting MADV_NOHUGEPAGE at all? IIUC, we'll
> almost immediately later call cleanup_area() where we munmap(), right?
I tested removing the MADV_NOHUGEPAGE setting, and the khugepaged test
cases all passed.
However, a potential impact of removing MADV_NOHUGEPAGE is that,
khugepaged might report 'timeout', but check_huge() would still report
'success' (assuming khugepaged tries to scan the VMA and successfully
collapses it after the timeout). Such test result could be confusing.
I know this kind of case is very rare and may not even be detectable in
tests. At least, I couldn't reproduce it. But I prefer to keep the
original test logic and fix the issue without making further changes.
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 1/2] selftests: khugepaged: fix the shmem collapse failure
2025-06-12 11:37 ` Baolin Wang
@ 2025-06-12 11:45 ` David Hildenbrand
2025-06-12 12:14 ` Baolin Wang
0 siblings, 1 reply; 17+ messages in thread
From: David Hildenbrand @ 2025-06-12 11:45 UTC (permalink / raw)
To: Baolin Wang, akpm
Cc: lorenzo.stoakes, Liam.Howlett, npache, ryan.roberts, dev.jain,
baohua, shuah, ziy, linux-mm, linux-kselftest, linux-kernel
On 12.06.25 13:37, Baolin Wang wrote:
>
>
> On 2025/6/12 18:08, David Hildenbrand wrote:
>> On 12.06.25 05:54, Baolin Wang wrote:
>>> When running the khugepaged selftest for shmem (./khugepaged all:shmem),
>>
>> Hmm, this combination is not run automatically through run_tests.sh,
>> right? IIUC, it only runs "./khugepaged" which tests anon only ...
>>
>> Should we add it there? Then I would probably have noticed that myself
>> earlier :)
>
> Yes, see patch 2.
Yes, was pleasantly surprised when I found that :)
>
>>> 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.
>>
>> Right. It's always problematic when we have some contradicting
>> information in the VMA vs. pagecache.
>>
>>>
>>> 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
>>
>> It's a shame we have this weird interface: there is no way we can clear
>> VM_HUGEPAGE without setting VM_NOHUGEPAGE :(
>
> Right.
>
>> But, do we even care about setting MADV_NOHUGEPAGE at all? IIUC, we'll
>> almost immediately later call cleanup_area() where we munmap(), right?
>
> I tested removing the MADV_NOHUGEPAGE setting, and the khugepaged test
> cases all passed.
>
> However, a potential impact of removing MADV_NOHUGEPAGE is that,
> khugepaged might report 'timeout', but check_huge() would still report
> 'success' (assuming khugepaged tries to scan the VMA and successfully
> collapses it after the timeout). Such test result could be confusing.
If we run into the timeout, we return "true" from wait_for_scan(), and
in khugepaged_collapse() returns immediately.
So we wouldn't issue another check_huge() call in khugepaged_collapse().
Did I miss something?
--
Cheers,
David / dhildenb
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 1/2] selftests: khugepaged: fix the shmem collapse failure
2025-06-12 11:45 ` David Hildenbrand
@ 2025-06-12 12:14 ` Baolin Wang
0 siblings, 0 replies; 17+ messages in thread
From: Baolin Wang @ 2025-06-12 12:14 UTC (permalink / raw)
To: David Hildenbrand, akpm
Cc: lorenzo.stoakes, Liam.Howlett, npache, ryan.roberts, dev.jain,
baohua, shuah, ziy, linux-mm, linux-kselftest, linux-kernel
On 2025/6/12 19:45, David Hildenbrand wrote:
> On 12.06.25 13:37, Baolin Wang wrote:
>>
>>
>> On 2025/6/12 18:08, David Hildenbrand wrote:
>>> On 12.06.25 05:54, Baolin Wang wrote:
>>>> When running the khugepaged selftest for shmem (./khugepaged
>>>> all:shmem),
>>>
>>> Hmm, this combination is not run automatically through run_tests.sh,
>>> right? IIUC, it only runs "./khugepaged" which tests anon only ...
>>>
>>> Should we add it there? Then I would probably have noticed that myself
>>> earlier :)
>>
>> Yes, see patch 2.
>
> Yes, was pleasantly surprised when I found that :)
>
>>
>>>> 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.
>>>
>>> Right. It's always problematic when we have some contradicting
>>> information in the VMA vs. pagecache.
>>>
>>>>
>>>> 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
>>>
>>> It's a shame we have this weird interface: there is no way we can clear
>>> VM_HUGEPAGE without setting VM_NOHUGEPAGE :(
>>
>> Right.
>>
>>> But, do we even care about setting MADV_NOHUGEPAGE at all? IIUC, we'll
>>> almost immediately later call cleanup_area() where we munmap(), right?
>>
>> I tested removing the MADV_NOHUGEPAGE setting, and the khugepaged test
>> cases all passed.
>>
>> However, a potential impact of removing MADV_NOHUGEPAGE is that,
>> khugepaged might report 'timeout', but check_huge() would still report
>> 'success' (assuming khugepaged tries to scan the VMA and successfully
>> collapses it after the timeout). Such test result could be confusing.
>
> If we run into the timeout, we return "true" from wait_for_scan(), and
> in khugepaged_collapse() returns immediately.
>
> So we wouldn't issue another check_huge() call in khugepaged_collapse().
>
> Did I miss something?
Ah, right. Sorry for the wrong example. Now I'm fine to drop the
MADV_NOHUGEPAGE settiing. Thanks.
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 1/2] selftests: khugepaged: fix the shmem collapse failure
2025-06-12 3:54 [PATCH 1/2] selftests: khugepaged: fix the shmem collapse failure Baolin Wang
` (2 preceding siblings ...)
2025-06-12 10:08 ` David Hildenbrand
@ 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
4 siblings, 2 replies; 17+ messages in thread
From: Zi Yan @ 2025-06-12 15:46 UTC (permalink / raw)
To: Baolin Wang
Cc: akpm, david, lorenzo.stoakes, Liam.Howlett, npache, ryan.roberts,
dev.jain, baohua, shuah, linux-mm, linux-kselftest, linux-kernel
On 11 Jun 2025, at 23:54, Baolin Wang wrote:
> 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
Can you add the title of the commit? It is easier to understand the context.
2b0f922323cc ("mm: don't install PMD mappings when THPs are disabled by the hw/process/vma")
> 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;
> }
>
I assume you are going to just remove this madvise based on your discussion
with David. With that, feel free to add Reviewed-by: Zi Yan <ziy@nvidia.com>
Thanks.
Best Regards,
Yan, Zi
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 2/2] selftests: mm: add shmem collpase as a default test item
2025-06-12 3:54 ` [PATCH 2/2] selftests: mm: add shmem collpase as a default test item Baolin Wang
` (2 preceding siblings ...)
2025-06-12 10:24 ` David Hildenbrand
@ 2025-06-12 15:47 ` Zi Yan
3 siblings, 0 replies; 17+ messages in thread
From: Zi Yan @ 2025-06-12 15:47 UTC (permalink / raw)
To: Baolin Wang
Cc: akpm, david, lorenzo.stoakes, Liam.Howlett, npache, ryan.roberts,
dev.jain, baohua, shuah, linux-mm, linux-kselftest, linux-kernel
On 11 Jun 2025, at 23:54, Baolin Wang wrote:
> Currently, we only test anonymous memory collapse by default. We should also
> add shmem collapse as a default test item to catch issues that could break
> the test cases.
>
> Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
> ---
> tools/testing/selftests/mm/run_vmtests.sh | 4 ++++
> 1 file changed, 4 insertions(+)
>
Acked-by: Zi Yan <ziy@nvidia.com>
Best Regards,
Yan, Zi
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 1/2] selftests: khugepaged: fix the shmem collapse failure
2025-06-12 15:46 ` Zi Yan
@ 2025-06-12 15:48 ` David Hildenbrand
2025-06-13 1:41 ` Baolin Wang
1 sibling, 0 replies; 17+ messages in thread
From: David Hildenbrand @ 2025-06-12 15:48 UTC (permalink / raw)
To: Zi Yan, Baolin Wang
Cc: akpm, lorenzo.stoakes, Liam.Howlett, npache, ryan.roberts,
dev.jain, baohua, shuah, linux-mm, linux-kselftest, linux-kernel
On 12.06.25 17:46, Zi Yan wrote:
> On 11 Jun 2025, at 23:54, Baolin Wang wrote:
>
>> 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
>
> Can you add the title of the commit? It is easier to understand the context.
>
> 2b0f922323cc ("mm: don't install PMD mappings when THPs are disabled by the hw/process/vma")
>
Probably checkpatch.pl would point out the same :)
--
Cheers,
David / dhildenb
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 1/2] selftests: khugepaged: fix the shmem collapse failure
2025-06-12 15:46 ` Zi Yan
2025-06-12 15:48 ` David Hildenbrand
@ 2025-06-13 1:41 ` Baolin Wang
1 sibling, 0 replies; 17+ messages in thread
From: Baolin Wang @ 2025-06-13 1:41 UTC (permalink / raw)
To: Zi Yan
Cc: akpm, david, lorenzo.stoakes, Liam.Howlett, npache, ryan.roberts,
dev.jain, baohua, shuah, linux-mm, linux-kselftest, linux-kernel
On 2025/6/12 23:46, Zi Yan wrote:
> On 11 Jun 2025, at 23:54, Baolin Wang wrote:
>
>> 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
>
> Can you add the title of the commit? It is easier to understand the context.
>
> 2b0f922323cc ("mm: don't install PMD mappings when THPs are disabled by the hw/process/vma")
Sure.
>
>> 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;
>> }
>>
> I assume you are going to just remove this madvise based on your discussion
> with David. With that, feel free to add Reviewed-by: Zi Yan <ziy@nvidia.com>
Thanks.
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 1/2] selftests: khugepaged: fix the shmem collapse failure
2025-06-12 3:54 [PATCH 1/2] selftests: khugepaged: fix the shmem collapse failure Baolin Wang
` (3 preceding siblings ...)
2025-06-12 15:46 ` Zi Yan
@ 2025-06-20 6:13 ` Mario Casquero
4 siblings, 0 replies; 17+ messages in thread
From: Mario Casquero @ 2025-06-20 6:13 UTC (permalink / raw)
To: Baolin Wang
Cc: akpm, david, lorenzo.stoakes, Liam.Howlett, npache, ryan.roberts,
dev.jain, baohua, shuah, ziy, linux-mm, linux-kselftest,
linux-kernel
This patch has been successfully tested. All the khugepaged shmem tests passed.
# ./khugepaged khugepaged:shmem
Save THP and khugepaged settings... OK
Allocate huge page on fault... OK
Split huge PMD on MADV_DONTNEED... OK
Run test: collapse_full (khugepaged:shmem)
Collapse multiple fully populated PTE table.... OK
Run test: collapse_single_pte_entry (khugepaged:shmem)
Collapse PTE table with single PTE entry present.... OK
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.... OK
Restore THP and khugepaged settings... OK
Tested-by: Mario Casquero <mcasquer@redhat.com>
On Thu, Jun 12, 2025 at 5:55 AM Baolin Wang
<baolin.wang@linux.alibaba.com> wrote:
>
> 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