diff mbox series

[v2] selftests/mm: use global variable to not optimize mmap read variable

Message ID 20240606154428.672643-1-kernel@pankajraghav.com (mailing list archive)
State New
Headers show
Series [v2] selftests/mm: use global variable to not optimize mmap read variable | expand

Commit Message

Pankaj Raghav (Samsung) June 6, 2024, 3:44 p.m. UTC
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.

Make it as a global variable to force the compiler not to optimize out
the loop where we read from the mmaped addr.

Signed-off-by: Pankaj Raghav <p.raghav@samsung.com>
---
Changes since v1:
- Make the dummy variable as a global variable(willy).

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


base-commit: d97496ca23a2d4ee80b7302849404859d9058bcd

Comments

Zi Yan June 6, 2024, 3:47 p.m. UTC | #1
On 6 Jun 2024, at 8:44, 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.
>
> Make it as a global variable to force the compiler not to optimize out
> the loop where we read from the mmaped addr.
>
> Signed-off-by: Pankaj Raghav <p.raghav@samsung.com>
> ---
> Changes since v1:
> - Make the dummy variable as a global variable(willy).
>
>  tools/testing/selftests/mm/split_huge_page_test.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
>

Reviewed-by: Zi Yan <ziy@nvidia.com>

Thanks.

Best Regards,
Yan, Zi
diff mbox series

Patch

diff --git a/tools/testing/selftests/mm/split_huge_page_test.c b/tools/testing/selftests/mm/split_huge_page_test.c
index d3c7f5fb3e7b..c4857de2c042 100644
--- a/tools/testing/selftests/mm/split_huge_page_test.c
+++ b/tools/testing/selftests/mm/split_huge_page_test.c
@@ -23,6 +23,11 @@ 
 uint64_t pagesize;
 unsigned int pageshift;
 uint64_t pmd_pagesize;
+/*
+ * Used by create_pagecache_thp_and_fd() to do mmap read.
+ * Made it as global to avoid compiler optimizing out the variable.
+ */
+int dummy;
 
 #define SPLIT_DEBUGFS "/sys/kernel/debug/split_huge_pages"
 #define SMAP_PATH "/proc/self/smaps"
@@ -300,7 +305,6 @@  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;
 
 	srand(time(NULL));