Skip to content

Commit ecc1793

Browse files
Panky-codesakpm00
authored andcommitted
selftests/mm: use asm volatile to not optimize mmap read variable
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. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Pankaj Raghav <[email protected]> Reviewed-by: Zi Yan <[email protected]> Acked-by: David Hildenbrand <[email protected]> Cc: Luis Chamberlain <[email protected]> Cc: Matthew Wilcox (Oracle) <[email protected]> Cc: Pankaj Raghav <[email protected]> Cc: Shuah Khan <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 20dfa5b commit ecc1793

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

tools/testing/selftests/mm/split_huge_page_test.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ int create_pagecache_thp_and_fd(const char *testfile, size_t fd_size, int *fd,
300300
char **addr)
301301
{
302302
size_t i;
303-
int __attribute__((unused)) dummy = 0;
303+
int dummy = 0;
304304

305305
srand(time(NULL));
306306

@@ -341,6 +341,7 @@ int create_pagecache_thp_and_fd(const char *testfile, size_t fd_size, int *fd,
341341

342342
for (size_t i = 0; i < fd_size; i++)
343343
dummy += *(*addr + i);
344+
asm volatile("" : "+r" (dummy));
344345

345346
if (!check_huge_file(*addr, fd_size / pmd_pagesize, pmd_pagesize)) {
346347
ksft_print_msg("No large pagecache folio generated, please provide a filesystem supporting large folio\n");

0 commit comments

Comments
 (0)