linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] selftests/mm: use asm volatile to not optimize mmap read variable
@ 2024-06-06 20:36 Pankaj Raghav (Samsung)
  2024-06-06 20:52 ` Zi Yan
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Pankaj Raghav (Samsung) @ 2024-06-06 20:36 UTC (permalink / raw)
  To: Andrew Morton, Shuah Khan
  Cc: linux-mm, gost.dev, David Hildenbrand, willy, mcgrof,
	linux-kselftest, linux-kernel, Zi Yan, kernel, Pankaj Raghav

From: Pankaj Raghav <p.raghav@samsung.com>

create_pagecache_thp_and_fd() in split_huge_page_test.c used the
variable dummy to perform mmap read.

However, this test was skipped even on XFS which has large folio
support. The issue was compiler (gcc 13.2.0) was optimizing out the
dummy variable, therefore, not creating huge page in the page cache.

Use asm volatile() trick to force the compiler not to optimize out
the loop where we read from the mmaped addr. This is similar to what is
being done in other tests (cow.c, etc)

As the variable is now used in the asm statement, remove the unused
attribute.

Signed-off-by: Pankaj Raghav <p.raghav@samsung.com>
---
Changes since v2:
- Use the asm volatile trick to force the compiler to not optimize the
  read into dummy variable. (David)

 tools/testing/selftests/mm/split_huge_page_test.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/mm/split_huge_page_test.c b/tools/testing/selftests/mm/split_huge_page_test.c
index d3c7f5fb3e7b..e5e8dafc9d94 100644
--- a/tools/testing/selftests/mm/split_huge_page_test.c
+++ b/tools/testing/selftests/mm/split_huge_page_test.c
@@ -300,7 +300,7 @@ int create_pagecache_thp_and_fd(const char *testfile, size_t fd_size, int *fd,
 		char **addr)
 {
 	size_t i;
-	int __attribute__((unused)) dummy = 0;
+	int dummy = 0;
 
 	srand(time(NULL));
 
@@ -341,6 +341,7 @@ int create_pagecache_thp_and_fd(const char *testfile, size_t fd_size, int *fd,
 
 	for (size_t i = 0; i < fd_size; i++)
 		dummy += *(*addr + i);
+	asm volatile("" : "+r" (dummy));
 
 	if (!check_huge_file(*addr, fd_size / pmd_pagesize, pmd_pagesize)) {
 		ksft_print_msg("No large pagecache folio generated, please provide a filesystem supporting large folio\n");

base-commit: d97496ca23a2d4ee80b7302849404859d9058bcd
-- 
2.44.1



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

* Re: [PATCH v3] selftests/mm: use asm volatile to not optimize mmap read variable
  2024-06-06 20:36 [PATCH v3] selftests/mm: use asm volatile to not optimize mmap read variable Pankaj Raghav (Samsung)
@ 2024-06-06 20:52 ` Zi Yan
  2024-06-06 21:09 ` David Hildenbrand
  2024-06-08  4:39 ` Andrew Morton
  2 siblings, 0 replies; 5+ messages in thread
From: Zi Yan @ 2024-06-06 20:52 UTC (permalink / raw)
  To: Pankaj Raghav (Samsung)
  Cc: Andrew Morton, Shuah Khan, linux-mm, gost.dev, David Hildenbrand,
	willy, mcgrof, linux-kselftest, linux-kernel, Pankaj Raghav

[-- Attachment #1: Type: text/plain, Size: 1065 bytes --]

On 6 Jun 2024, at 13:36, Pankaj Raghav (Samsung) wrote:

> From: Pankaj Raghav <p.raghav@samsung.com>
>
> create_pagecache_thp_and_fd() in split_huge_page_test.c used the
> variable dummy to perform mmap read.
>
> However, this test was skipped even on XFS which has large folio
> support. The issue was compiler (gcc 13.2.0) was optimizing out the
> dummy variable, therefore, not creating huge page in the page cache.
>
> Use asm volatile() trick to force the compiler not to optimize out
> the loop where we read from the mmaped addr. This is similar to what is
> being done in other tests (cow.c, etc)
>
> As the variable is now used in the asm statement, remove the unused
> attribute.
>
> Signed-off-by: Pankaj Raghav <p.raghav@samsung.com>
> ---
> Changes since v2:
> - Use the asm volatile trick to force the compiler to not optimize the
>   read into dummy variable. (David)
>
>  tools/testing/selftests/mm/split_huge_page_test.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
LGTM. Reviewed-by: Zi Yan <ziy@nvidia.com>

Best Regards,
Yan, Zi

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 854 bytes --]

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

* Re: [PATCH v3] selftests/mm: use asm volatile to not optimize mmap read variable
  2024-06-06 20:36 [PATCH v3] selftests/mm: use asm volatile to not optimize mmap read variable Pankaj Raghav (Samsung)
  2024-06-06 20:52 ` Zi Yan
@ 2024-06-06 21:09 ` David Hildenbrand
  2024-06-08  4:39 ` Andrew Morton
  2 siblings, 0 replies; 5+ messages in thread
From: David Hildenbrand @ 2024-06-06 21:09 UTC (permalink / raw)
  To: Pankaj Raghav (Samsung), Andrew Morton, Shuah Khan
  Cc: linux-mm, gost.dev, willy, mcgrof, linux-kselftest, linux-kernel,
	Zi Yan, Pankaj Raghav

On 06.06.24 22:36, Pankaj Raghav (Samsung) wrote:
> From: Pankaj Raghav <p.raghav@samsung.com>
> 
> create_pagecache_thp_and_fd() in split_huge_page_test.c used the
> variable dummy to perform mmap read.
> 
> However, this test was skipped even on XFS which has large folio
> support. The issue was compiler (gcc 13.2.0) was optimizing out the
> dummy variable, therefore, not creating huge page in the page cache.
> 
> Use asm volatile() trick to force the compiler not to optimize out
> the loop where we read from the mmaped addr. This is similar to what is
> being done in other tests (cow.c, etc)
> 
> As the variable is now used in the asm statement, remove the unused
> attribute.
> 
> Signed-off-by: Pankaj Raghav <p.raghav@samsung.com>
> ---
> Changes since v2:
> - Use the asm volatile trick to force the compiler to not optimize the
>    read into dummy variable. (David)
> 
>   tools/testing/selftests/mm/split_huge_page_test.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/testing/selftests/mm/split_huge_page_test.c b/tools/testing/selftests/mm/split_huge_page_test.c
> index d3c7f5fb3e7b..e5e8dafc9d94 100644
> --- a/tools/testing/selftests/mm/split_huge_page_test.c
> +++ b/tools/testing/selftests/mm/split_huge_page_test.c
> @@ -300,7 +300,7 @@ int create_pagecache_thp_and_fd(const char *testfile, size_t fd_size, int *fd,
>   		char **addr)
>   {
>   	size_t i;
> -	int __attribute__((unused)) dummy = 0;
> +	int dummy = 0;
>   
>   	srand(time(NULL));
>   
> @@ -341,6 +341,7 @@ int create_pagecache_thp_and_fd(const char *testfile, size_t fd_size, int *fd,
>   
>   	for (size_t i = 0; i < fd_size; i++)
>   		dummy += *(*addr + i);
> +	asm volatile("" : "+r" (dummy));
>   
>   	if (!check_huge_file(*addr, fd_size / pmd_pagesize, pmd_pagesize)) {
>   		ksft_print_msg("No large pagecache folio generated, please provide a filesystem supporting large folio\n");
> 
> base-commit: d97496ca23a2d4ee80b7302849404859d9058bcd

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

I was wondering if we should factor that out into a mm-selftest helper 
function, but that can be done later.

-- 
Cheers,

David / dhildenb



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

* Re: [PATCH v3] selftests/mm: use asm volatile to not optimize mmap read variable
  2024-06-06 20:36 [PATCH v3] selftests/mm: use asm volatile to not optimize mmap read variable Pankaj Raghav (Samsung)
  2024-06-06 20:52 ` Zi Yan
  2024-06-06 21:09 ` David Hildenbrand
@ 2024-06-08  4:39 ` Andrew Morton
  2024-06-08 10:22   ` Pankaj Raghav (Samsung)
  2 siblings, 1 reply; 5+ messages in thread
From: Andrew Morton @ 2024-06-08  4:39 UTC (permalink / raw)
  To: Pankaj Raghav (Samsung)
  Cc: Shuah Khan, linux-mm, gost.dev, David Hildenbrand, willy, mcgrof,
	linux-kselftest, linux-kernel, Zi Yan, Pankaj Raghav

On Thu,  6 Jun 2024 20:36:19 +0000 "Pankaj Raghav (Samsung)" <kernel@pankajraghav.com> wrote:

> From: Pankaj Raghav <p.raghav@samsung.com>
> 
> create_pagecache_thp_and_fd() in split_huge_page_test.c used the
> variable dummy to perform mmap read.
> 
> However, this test was skipped even on XFS which has large folio
> support. The issue was compiler (gcc 13.2.0) was optimizing out the
> dummy variable, therefore, not creating huge page in the page cache.
> 
> Use asm volatile() trick to force the compiler not to optimize out
> the loop where we read from the mmaped addr. This is similar to what is
> being done in other tests (cow.c, etc)
> 
> As the variable is now used in the asm statement, remove the unused
> attribute.
> 

What are the runtime effects of this change?  An inappropriate test
failure?  If so, shouldn't we fix 6.9.x kernels also?  And is
fc4d182316bd ("mm: huge_memory: enable debugfs to split huge pages to
any order") an appropriate Fixes: target?



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

* Re: [PATCH v3] selftests/mm: use asm volatile to not optimize mmap read variable
  2024-06-08  4:39 ` Andrew Morton
@ 2024-06-08 10:22   ` Pankaj Raghav (Samsung)
  0 siblings, 0 replies; 5+ messages in thread
From: Pankaj Raghav (Samsung) @ 2024-06-08 10:22 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Shuah Khan, linux-mm, gost.dev, David Hildenbrand, willy, mcgrof,
	linux-kselftest, linux-kernel, Zi Yan, Pankaj Raghav

On Fri, Jun 07, 2024 at 09:39:36PM -0700, Andrew Morton wrote:
> On Thu,  6 Jun 2024 20:36:19 +0000 "Pankaj Raghav (Samsung)" <kernel@pankajraghav.com> wrote:
> 
> > From: Pankaj Raghav <p.raghav@samsung.com>
> > 
> > create_pagecache_thp_and_fd() in split_huge_page_test.c used the
> > variable dummy to perform mmap read.
> > 
> > However, this test was skipped even on XFS which has large folio
> > support. The issue was compiler (gcc 13.2.0) was optimizing out the
> > dummy variable, therefore, not creating huge page in the page cache.
> > 
> > Use asm volatile() trick to force the compiler not to optimize out
> > the loop where we read from the mmaped addr. This is similar to what is
> > being done in other tests (cow.c, etc)
> > 
> > As the variable is now used in the asm statement, remove the unused
> > attribute.
> > 
> 
> What are the runtime effects of this change?  An inappropriate test
> failure?  If so, shouldn't we fix 6.9.x kernels also?  And is
> fc4d182316bd ("mm: huge_memory: enable debugfs to split huge pages to
> any order") an appropriate Fixes: target?

I mentioned it here in the commit message:

However, this test was skipped even on XFS which has large folio
support.

So the test just skip these cases and does not fail. That is why I
didn't use the Fixes tag. Let me know if it needs one.

--
Pankaj


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

end of thread, other threads:[~2024-06-08 10:23 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-06 20:36 [PATCH v3] selftests/mm: use asm volatile to not optimize mmap read variable Pankaj Raghav (Samsung)
2024-06-06 20:52 ` Zi Yan
2024-06-06 21:09 ` David Hildenbrand
2024-06-08  4:39 ` Andrew Morton
2024-06-08 10:22   ` Pankaj Raghav (Samsung)

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