linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Baolin Wang <baolin.wang@linux.alibaba.com>
To: David Hildenbrand <david@redhat.com>, akpm@linux-foundation.org
Cc: lorenzo.stoakes@oracle.com, Liam.Howlett@oracle.com,
	npache@redhat.com, ryan.roberts@arm.com, dev.jain@arm.com,
	baohua@kernel.org, shuah@kernel.org, ziy@nvidia.com,
	linux-mm@kvack.org, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] selftests: khugepaged: fix the shmem collapse failure
Date: Thu, 12 Jun 2025 19:37:23 +0800	[thread overview]
Message-ID: <42b76dbc-d1a1-4d00-b139-c50e0abf8b0c@linux.alibaba.com> (raw)
In-Reply-To: <e06530f6-5c2e-4b6f-b175-c7aaab79aa4e@redhat.com>



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.


  reply	other threads:[~2025-06-12 11:37 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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
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 [this message]
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

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=42b76dbc-d1a1-4d00-b139-c50e0abf8b0c@linux.alibaba.com \
    --to=baolin.wang@linux.alibaba.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=baohua@kernel.org \
    --cc=david@redhat.com \
    --cc=dev.jain@arm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=npache@redhat.com \
    --cc=ryan.roberts@arm.com \
    --cc=shuah@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox