Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

selftests/mm: introduce helper to read every page

FORCE_READ(*addr) ensures that the compiler will emit a load from addr.
Several tests need to trigger such a load for a range of pages, ensuring
that every page is faulted in, if it wasn't already.

Introduce a new helper force_read_pages() that does exactly that and
replace existing loops with a call to it.

The step size (regular/huge page size) is preserved for all loops, except
in split_huge_page_test. Reading every byte is unnecessary; we now read
every huge page, matching the following call to check_huge_file().

Link: https://lkml.kernel.org/r/20260122170224.4056513-7-kevin.brodsky@arm.com
Signed-off-by: Kevin Brodsky <kevin.brodsky@arm.com>
Reviewed-by: Dev Jain <dev.jain@arm.com>
Reviewed-by: Muhammad Usama Anjum <usama.anjum@arm.com>
Acked-by: David Hildenbrand (Red Hat) <david@kernel.org>
Cc: Jason Gunthorpe <jgg@nvidia.com>
Cc: John Hubbard <jhubbard@nvidia.com>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Mark Brown <broonie@kernel.org>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: SeongJae Park <sj@kernel.org>
Cc: Shuah Khan <shuah@kernel.org>
Cc: wang lian <lianux.mm@gmail.com>
Cc: Yunsheng Lin <linyunsheng@huawei.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Kevin Brodsky and committed by
Andrew Morton
dd2b4e04 20d3fac4

+12 -19
+1 -8
tools/testing/selftests/mm/hugetlb-madvise.c
··· 47 47 48 48 void read_fault_pages(void *addr, unsigned long nr_pages) 49 49 { 50 - unsigned long i; 51 - 52 - for (i = 0; i < nr_pages; i++) { 53 - unsigned long *addr2 = 54 - ((unsigned long *)(addr + (i * huge_page_size))); 55 - /* Prevent the compiler from optimizing out the entire loop: */ 56 - FORCE_READ(*addr2); 57 - } 50 + force_read_pages(addr, nr_pages, huge_page_size); 58 51 } 59 52 60 53 int main(int argc, char **argv)
+3 -6
tools/testing/selftests/mm/pfnmap.c
··· 35 35 36 36 static int test_read_access(char *addr, size_t size, size_t pagesize) 37 37 { 38 - size_t offs; 39 38 int ret; 40 39 41 40 if (signal(SIGSEGV, signal_handler) == SIG_ERR) 42 41 return -EINVAL; 43 42 44 43 ret = sigsetjmp(sigjmp_buf_env, 1); 45 - if (!ret) { 46 - for (offs = 0; offs < size; offs += pagesize) 47 - /* Force a read that the compiler cannot optimize out. */ 48 - *((volatile char *)(addr + offs)); 49 - } 44 + if (!ret) 45 + force_read_pages(addr, size/pagesize, pagesize); 46 + 50 47 if (signal(SIGSEGV, SIG_DFL) == SIG_ERR) 51 48 return -EINVAL; 52 49
+1 -5
tools/testing/selftests/mm/split_huge_page_test.c
··· 652 652 } 653 653 madvise(*addr, fd_size, MADV_HUGEPAGE); 654 654 655 - for (size_t i = 0; i < fd_size; i++) { 656 - char *addr2 = *addr + i; 657 - 658 - FORCE_READ(*addr2); 659 - } 655 + force_read_pages(*addr, fd_size / pmd_pagesize, pmd_pagesize); 660 656 661 657 if (!check_huge_file(*addr, fd_size / pmd_pagesize, pmd_pagesize)) { 662 658 ksft_print_msg("No large pagecache folio generated, please provide a filesystem supporting large folio\n");
+7
tools/testing/selftests/mm/vm_util.h
··· 54 54 return __page_shift; 55 55 } 56 56 57 + static inline void force_read_pages(char *addr, unsigned int nr_pages, 58 + size_t pagesize) 59 + { 60 + for (unsigned int i = 0; i < nr_pages; i++) 61 + FORCE_READ(addr[i * pagesize]); 62 + } 63 + 57 64 bool detect_huge_zeropage(void); 58 65 59 66 /*