aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/mm/split_huge_page_test.c
diff options
context:
space:
mode:
authorwang lian <[email protected]>2025-07-17 13:18:56 +0000
committerAndrew Morton <[email protected]>2025-07-25 02:12:41 +0000
commit3f6bfd4789a0f396b8c0dfb8713c1f3eeed3b2d7 (patch)
treefbf08ae1259ee14be9ede49d08679cb0cc38138b /tools/testing/selftests/mm/split_huge_page_test.c
parentarm64: add batched versions of ptep_modify_prot_start/commit (diff)
downloadkernel-3f6bfd4789a0f396b8c0dfb8713c1f3eeed3b2d7.tar.gz
kernel-3f6bfd4789a0f396b8c0dfb8713c1f3eeed3b2d7.zip
selftests/mm: reuse FORCE_READ to replace "asm volatile("" : "+r" (XXX));"
Patch series "selftests/mm: reuse FORCE_READ to replace "asm volatile("" : "+r" (XXX));" and some cleanup", v2. This series introduces a common FORCE_READ() macro to replace the cryptic asm volatile("" : "+r" (variable)); construct used in several mm selftests. This improves code readability and maintainability by removing duplicated, hard-to-understand code. This patch (of 2): Several mm selftests use the `asm volatile("" : "+r" (variable));` construct to force a read of a variable, preventing the compiler from optimizing away the memory access. This idiom is cryptic and duplicated across multiple test files. Following a suggestion from David[1], this patch refactors this common pattern into a FORCE_READ() macro Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] Link: https://lore.kernel.org/lkml/[email protected]/ [1] Signed-off-by: wang lian <[email protected]> Reviewed-by: Lorenzo Stoakes <[email protected]> Acked-by: David Hildenbrand <[email protected]> Reviewed-by: Zi Yan <[email protected]> Reviewed-by: Wei Yang <[email protected]> Cc: Christian Brauner <[email protected]> Cc: Jann Horn <[email protected]> Cc: Kairui Song <[email protected]> Cc: Liam Howlett <[email protected]> Cc: Mark Brown <[email protected]> Cc: SeongJae Park <[email protected]> Cc: Shuah Khan <[email protected]> Cc: Vlastimil Babka <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
Diffstat (limited to 'tools/testing/selftests/mm/split_huge_page_test.c')
-rw-r--r--tools/testing/selftests/mm/split_huge_page_test.c4
1 files changed, 1 insertions, 3 deletions
diff --git a/tools/testing/selftests/mm/split_huge_page_test.c b/tools/testing/selftests/mm/split_huge_page_test.c
index aa7400ed0e99..6640748ff221 100644
--- a/tools/testing/selftests/mm/split_huge_page_test.c
+++ b/tools/testing/selftests/mm/split_huge_page_test.c
@@ -398,7 +398,6 @@ int create_pagecache_thp_and_fd(const char *testfile, size_t fd_size, int *fd,
char **addr)
{
size_t i;
- int dummy = 0;
unsigned char buf[1024];
srand(time(NULL));
@@ -440,8 +439,7 @@ int create_pagecache_thp_and_fd(const char *testfile, size_t fd_size, int *fd,
madvise(*addr, fd_size, MADV_HUGEPAGE);
for (size_t i = 0; i < fd_size; i++)
- dummy += *(*addr + i);
- asm volatile("" : "+r" (dummy));
+ FORCE_READ((*addr + i));
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");