linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1] selftests/mm: Set allocated memory to non-zero content in cow test
@ 2025-01-07 14:25 Ryan Roberts
  2025-01-07 14:44 ` David Hildenbrand
  2025-01-08  4:56 ` Andrew Morton
  0 siblings, 2 replies; 4+ messages in thread
From: Ryan Roberts @ 2025-01-07 14:25 UTC (permalink / raw)
  To: Andrew Morton, Shuah Khan, David Hildenbrand
  Cc: Ryan Roberts, linux-mm, linux-kselftest

After commit b1f202060afe ("mm: remap unused subpages to shared zeropage
when splitting isolated thp"), cow test cases involving swapping out
THPs via madvise(MADV_PAGEOUT) started to be skipped due to the
subsequent check via pagemap determining that the memory was not
actually swapped out. Logs similar to this were emitted:

   ...

   # [RUN] Basic COW after fork() ... with swapped-out, PTE-mapped THP (16 kB)
   ok 2 # SKIP MADV_PAGEOUT did not work, is swap enabled?
   # [RUN] Basic COW after fork() ... with single PTE of swapped-out THP (16 kB)
   ok 3 # SKIP MADV_PAGEOUT did not work, is swap enabled?
   # [RUN] Basic COW after fork() ... with swapped-out, PTE-mapped THP (32 kB)
   ok 4 # SKIP MADV_PAGEOUT did not work, is swap enabled?

   ...

The commit in question introduces the behaviour of scanning THPs and if
their content is predominantly zero, it splits them and replaces the
pages which are wholly zero with the zero page. These cow test cases
were getting caught up in this.

So let's avoid that by filling the contents of all allocated memory with
a non-zero value. With this in place, the tests are passing again.

Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
---

Applies on top of mm-unstable (f349e79bfbf3)

Thanks,
Ryan

 tools/testing/selftests/mm/cow.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/mm/cow.c b/tools/testing/selftests/mm/cow.c
index 32c6ccc2a6be..1238e1c5aae1 100644
--- a/tools/testing/selftests/mm/cow.c
+++ b/tools/testing/selftests/mm/cow.c
@@ -758,7 +758,7 @@ static void do_run_with_base_page(test_fn fn, bool swapout)
 	}

 	/* Populate a base page. */
-	memset(mem, 0, pagesize);
+	memset(mem, 1, pagesize);

 	if (swapout) {
 		madvise(mem, pagesize, MADV_PAGEOUT);
@@ -824,12 +824,12 @@ static void do_run_with_thp(test_fn fn, enum thp_run thp_run, size_t thpsize)
 	 * Try to populate a THP. Touch the first sub-page and test if
 	 * we get the last sub-page populated automatically.
 	 */
-	mem[0] = 0;
+	mem[0] = 1;
 	if (!pagemap_is_populated(pagemap_fd, mem + thpsize - pagesize)) {
 		ksft_test_result_skip("Did not get a THP populated\n");
 		goto munmap;
 	}
-	memset(mem, 0, thpsize);
+	memset(mem, 1, thpsize);

 	size = thpsize;
 	switch (thp_run) {
@@ -1012,7 +1012,7 @@ static void run_with_hugetlb(test_fn fn, const char *desc, size_t hugetlbsize)
 	}

 	/* Populate an huge page. */
-	memset(mem, 0, hugetlbsize);
+	memset(mem, 1, hugetlbsize);

 	/*
 	 * We need a total of two hugetlb pages to handle COW/unsharing
--
2.43.0



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

* Re: [PATCH v1] selftests/mm: Set allocated memory to non-zero content in cow test
  2025-01-07 14:25 [PATCH v1] selftests/mm: Set allocated memory to non-zero content in cow test Ryan Roberts
@ 2025-01-07 14:44 ` David Hildenbrand
  2025-01-08  4:56 ` Andrew Morton
  1 sibling, 0 replies; 4+ messages in thread
From: David Hildenbrand @ 2025-01-07 14:44 UTC (permalink / raw)
  To: Ryan Roberts, Andrew Morton, Shuah Khan; +Cc: linux-mm, linux-kselftest

On 07.01.25 15:25, Ryan Roberts wrote:
> After commit b1f202060afe ("mm: remap unused subpages to shared zeropage
> when splitting isolated thp"), cow test cases involving swapping out
> THPs via madvise(MADV_PAGEOUT) started to be skipped due to the
> subsequent check via pagemap determining that the memory was not
> actually swapped out. Logs similar to this were emitted:
> 
>     ...
> 
>     # [RUN] Basic COW after fork() ... with swapped-out, PTE-mapped THP (16 kB)
>     ok 2 # SKIP MADV_PAGEOUT did not work, is swap enabled?
>     # [RUN] Basic COW after fork() ... with single PTE of swapped-out THP (16 kB)
>     ok 3 # SKIP MADV_PAGEOUT did not work, is swap enabled?
>     # [RUN] Basic COW after fork() ... with swapped-out, PTE-mapped THP (32 kB)
>     ok 4 # SKIP MADV_PAGEOUT did not work, is swap enabled?
> 
>     ...
> 
> The commit in question introduces the behaviour of scanning THPs and if
> their content is predominantly zero, it splits them and replaces the
> pages which are wholly zero with the zero page. These cow test cases
> were getting caught up in this.
> 
> So let's avoid that by filling the contents of all allocated memory with
> a non-zero value. With this in place, the tests are passing again.
> 
> Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
> ---
> 
> Applies on top of mm-unstable (f349e79bfbf3)
> 
> Thanks,
> Ryan
> 
>   tools/testing/selftests/mm/cow.c | 8 ++++----
>   1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/tools/testing/selftests/mm/cow.c b/tools/testing/selftests/mm/cow.c
> index 32c6ccc2a6be..1238e1c5aae1 100644
> --- a/tools/testing/selftests/mm/cow.c
> +++ b/tools/testing/selftests/mm/cow.c
> @@ -758,7 +758,7 @@ static void do_run_with_base_page(test_fn fn, bool swapout)
>   	}
> 
>   	/* Populate a base page. */
> -	memset(mem, 0, pagesize);
> +	memset(mem, 1, pagesize);
> 
>   	if (swapout) {
>   		madvise(mem, pagesize, MADV_PAGEOUT);
> @@ -824,12 +824,12 @@ static void do_run_with_thp(test_fn fn, enum thp_run thp_run, size_t thpsize)
>   	 * Try to populate a THP. Touch the first sub-page and test if
>   	 * we get the last sub-page populated automatically.
>   	 */
> -	mem[0] = 0;
> +	mem[0] = 1;
>   	if (!pagemap_is_populated(pagemap_fd, mem + thpsize - pagesize)) {
>   		ksft_test_result_skip("Did not get a THP populated\n");
>   		goto munmap;
>   	}
> -	memset(mem, 0, thpsize);
> +	memset(mem, 1, thpsize);
> 
>   	size = thpsize;
>   	switch (thp_run) {
> @@ -1012,7 +1012,7 @@ static void run_with_hugetlb(test_fn fn, const char *desc, size_t hugetlbsize)
>   	}
> 
>   	/* Populate an huge page. */
> -	memset(mem, 0, hugetlbsize);
> +	memset(mem, 1, hugetlbsize);

Interesting, thanks!

"1" should work, because we use "0xff" to detect modifications.

Acked-by: David Hildenbrand <david@redhat.com>

-- 
Cheers,

David / dhildenb



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

* Re: [PATCH v1] selftests/mm: Set allocated memory to non-zero content in cow test
  2025-01-07 14:25 [PATCH v1] selftests/mm: Set allocated memory to non-zero content in cow test Ryan Roberts
  2025-01-07 14:44 ` David Hildenbrand
@ 2025-01-08  4:56 ` Andrew Morton
  2025-01-08  8:02   ` Ryan Roberts
  1 sibling, 1 reply; 4+ messages in thread
From: Andrew Morton @ 2025-01-08  4:56 UTC (permalink / raw)
  To: Ryan Roberts
  Cc: Shuah Khan, David Hildenbrand, linux-mm, linux-kselftest,
	Usama Arif, Yu Zhao

On Tue,  7 Jan 2025 14:25:53 +0000 Ryan Roberts <ryan.roberts@arm.com> wrote:

> After commit b1f202060afe ("mm: remap unused subpages to shared zeropage
> when splitting isolated thp"), cow test cases involving swapping out
> THPs via madvise(MADV_PAGEOUT) started to be skipped due to the
> subsequent check via pagemap determining that the memory was not
> actually swapped out. Logs similar to this were emitted:
> 
> ...
>
> The commit in question introduces the behaviour of scanning THPs and if
> their content is predominantly zero, it splits them and replaces the
> pages which are wholly zero with the zero page. These cow test cases
> were getting caught up in this.
> 
> So let's avoid that by filling the contents of all allocated memory with
> a non-zero value. With this in place, the tests are passing again.
> 

Thanks, I'll add

Fixes: b1f202060afe ("mm: remap unused subpages to shared zeropage when splitting isolated thp")
...
Cc: Usama Arif <usamaarif642@gmail.com>
Cc: Yu Zhao <yuzhao@google.com>
Cc: <stable@vger.kernel.org>


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

* Re: [PATCH v1] selftests/mm: Set allocated memory to non-zero content in cow test
  2025-01-08  4:56 ` Andrew Morton
@ 2025-01-08  8:02   ` Ryan Roberts
  0 siblings, 0 replies; 4+ messages in thread
From: Ryan Roberts @ 2025-01-08  8:02 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Shuah Khan, David Hildenbrand, linux-mm, linux-kselftest,
	Usama Arif, Yu Zhao

On 08/01/2025 04:56, Andrew Morton wrote:
> On Tue,  7 Jan 2025 14:25:53 +0000 Ryan Roberts <ryan.roberts@arm.com> wrote:
> 
>> After commit b1f202060afe ("mm: remap unused subpages to shared zeropage
>> when splitting isolated thp"), cow test cases involving swapping out
>> THPs via madvise(MADV_PAGEOUT) started to be skipped due to the
>> subsequent check via pagemap determining that the memory was not
>> actually swapped out. Logs similar to this were emitted:
>>
>> ...
>>
>> The commit in question introduces the behaviour of scanning THPs and if
>> their content is predominantly zero, it splits them and replaces the
>> pages which are wholly zero with the zero page. These cow test cases
>> were getting caught up in this.
>>
>> So let's avoid that by filling the contents of all allocated memory with
>> a non-zero value. With this in place, the tests are passing again.
>>
> 
> Thanks, I'll add
> 
> Fixes: b1f202060afe ("mm: remap unused subpages to shared zeropage when splitting isolated thp")

Thanks, given it's not really a bug but a deliberate change of behaviour I
wasn't sure that a Fixes tag was appropriate, but thanks for seting me straight.

> ...
> Cc: Usama Arif <usamaarif642@gmail.com>
> Cc: Yu Zhao <yuzhao@google.com>
> Cc: <stable@vger.kernel.org>



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

end of thread, other threads:[~2025-01-08  8:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-01-07 14:25 [PATCH v1] selftests/mm: Set allocated memory to non-zero content in cow test Ryan Roberts
2025-01-07 14:44 ` David Hildenbrand
2025-01-08  4:56 ` Andrew Morton
2025-01-08  8:02   ` Ryan Roberts

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