From: Dev Jain <dev.jain@arm.com>
To: Kevin Brodsky <kevin.brodsky@arm.com>,
linux-mm@kvack.org, linux-kselftest@vger.kernel.org
Cc: linux-kernel@vger.kernel.org,
Andrew Morton <akpm@linux-foundation.org>,
David Hildenbrand <david@kernel.org>,
Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
Mark Brown <broonie@kernel.org>,
Ryan Roberts <ryan.roberts@arm.com>,
Shuah Khan <shuah@kernel.org>
Subject: Re: [PATCH v2 5/8] selftests/mm: introduce helper to read every page in range
Date: Thu, 22 Jan 2026 11:35:27 +0530 [thread overview]
Message-ID: <a2549671-da39-4827-a534-32f128f233a1@arm.com> (raw)
In-Reply-To: <20260107164842.3289559-6-kevin.brodsky@arm.com>
On 07/01/26 10:18 pm, Kevin Brodsky wrote:
> FORCE_READ(*addr) ensures that the compiler will emit a load from
> addr. Several tests need to trigger such a load for every page in
> the range [addr, addr + len), ensuring that every page is faulted
> in, if it wasn't already.
>
> Introduce a new helper force_read_pages_in_range() that does exactly
> that and replace existing loops with a call to it. Some of those
> loops have a different step size, but reading from every page is
> appropriate in all cases.
>
> Signed-off-by: Kevin Brodsky <kevin.brodsky@arm.com>
> ---
> tools/testing/selftests/mm/hugetlb-madvise.c | 9 +--------
> tools/testing/selftests/mm/pfnmap.c | 16 ++++++----------
> .../testing/selftests/mm/split_huge_page_test.c | 6 +-----
> tools/testing/selftests/mm/vm_util.h | 6 ++++++
> 4 files changed, 14 insertions(+), 23 deletions(-)
>
> diff --git a/tools/testing/selftests/mm/hugetlb-madvise.c b/tools/testing/selftests/mm/hugetlb-madvise.c
> index 05d9d2805ae4..1f82568ae262 100644
> --- a/tools/testing/selftests/mm/hugetlb-madvise.c
> +++ b/tools/testing/selftests/mm/hugetlb-madvise.c
> @@ -47,14 +47,7 @@ void write_fault_pages(void *addr, unsigned long nr_pages)
>
> void read_fault_pages(void *addr, unsigned long nr_pages)
> {
> - unsigned long i;
> -
> - for (i = 0; i < nr_pages; i++) {
> - unsigned long *addr2 =
> - ((unsigned long *)(addr + (i * huge_page_size)));
> - /* Prevent the compiler from optimizing out the entire loop: */
> - FORCE_READ(*addr2);
> - }
> + force_read_pages_in_range(addr, nr_pages * huge_page_size);
> }
Yeah this should be fine to do.
>
> int main(int argc, char **argv)
> diff --git a/tools/testing/selftests/mm/pfnmap.c b/tools/testing/selftests/mm/pfnmap.c
> index f546dfb10cae..35b0e3ed54cd 100644
> --- a/tools/testing/selftests/mm/pfnmap.c
> +++ b/tools/testing/selftests/mm/pfnmap.c
> @@ -33,20 +33,17 @@ static void signal_handler(int sig)
> siglongjmp(sigjmp_buf_env, -EFAULT);
> }
>
> -static int test_read_access(char *addr, size_t size, size_t pagesize)
> +static int test_read_access(char *addr, size_t size)
> {
> - size_t offs;
> int ret;
>
> if (signal(SIGSEGV, signal_handler) == SIG_ERR)
> return -EINVAL;
>
> ret = sigsetjmp(sigjmp_buf_env, 1);
> - if (!ret) {
> - for (offs = 0; offs < size; offs += pagesize)
> - /* Force a read that the compiler cannot optimize out. */
> - *((volatile char *)(addr + offs));
> - }
> + if (!ret)
> + force_read_pages_in_range(addr, size);
> +
LGTM
> if (signal(SIGSEGV, SIG_DFL) == SIG_ERR)
> return -EINVAL;
>
> @@ -138,7 +135,7 @@ FIXTURE_SETUP(pfnmap)
> SKIP(return, "Invalid file: '%s'. Not pfnmap'ed\n", file);
>
> /* ... and want to be able to read from them. */
> - if (test_read_access(self->addr1, self->size1, self->pagesize))
> + if (test_read_access(self->addr1, self->size1))
> SKIP(return, "Cannot read-access mmap'ed '%s'\n", file);
>
> self->size2 = 0;
> @@ -243,8 +240,7 @@ TEST_F(pfnmap, fork)
> ASSERT_GE(pid, 0);
>
> if (!pid) {
> - EXPECT_EQ(test_read_access(self->addr1, self->size1,
> - self->pagesize), 0);
> + EXPECT_EQ(test_read_access(self->addr1, self->size1), 0);
> exit(0);
> }
>
> diff --git a/tools/testing/selftests/mm/split_huge_page_test.c b/tools/testing/selftests/mm/split_huge_page_test.c
> index 40799f3f0213..65a89ceca4a5 100644
> --- a/tools/testing/selftests/mm/split_huge_page_test.c
> +++ b/tools/testing/selftests/mm/split_huge_page_test.c
> @@ -652,11 +652,7 @@ static int create_pagecache_thp_and_fd(const char *testfile, size_t fd_size,
> }
> madvise(*addr, fd_size, MADV_HUGEPAGE);
>
> - for (size_t i = 0; i < fd_size; i++) {
> - char *addr2 = *addr + i;
> -
> - FORCE_READ(*addr2);
> - }
> + force_read_pages_in_range(*addr, fd_size);
LGTM
>
> 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");
> diff --git a/tools/testing/selftests/mm/vm_util.h b/tools/testing/selftests/mm/vm_util.h
> index 6ad32b1830f1..74bdf96161d7 100644
> --- a/tools/testing/selftests/mm/vm_util.h
> +++ b/tools/testing/selftests/mm/vm_util.h
> @@ -54,6 +54,12 @@ static inline unsigned int pshift(void)
> return __page_shift;
> }
>
> +static inline void force_read_pages_in_range(char *addr, size_t len)
> +{
> + for (size_t i = 0; i < len; i += psize())
> + FORCE_READ(addr[i]);
> +}
> +
Reviewed-by: Dev Jain <dev.jain@arm.com>
> bool detect_huge_zeropage(void);
>
> /*
next prev parent reply other threads:[~2026-01-22 6:05 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-07 16:48 [PATCH v2 0/8] Various mm kselftests improvements/fixes Kevin Brodsky
2026-01-07 16:48 ` [PATCH v2 1/8] selftests/mm: default KDIR to build directory Kevin Brodsky
2026-01-07 16:48 ` [PATCH v2 2/8] selftests/mm: remove flaky header check Kevin Brodsky
2026-01-07 16:48 ` [PATCH v2 3/8] selftests/mm: pass down full CC and CFLAGS to check_config.sh Kevin Brodsky
2026-01-07 16:59 ` Mark Brown
2026-01-07 16:48 ` [PATCH v2 4/8] selftests/mm: fix usage of FORCE_READ() in cow tests Kevin Brodsky
2026-01-08 0:56 ` SeongJae Park
2026-01-08 2:04 ` wang lian
2026-01-08 2:07 ` [PATCH v2 7/8] selftests/mm: fix exit code in pagemap_ioctl wang lian
2026-01-19 10:50 ` [PATCH v2 4/8] selftests/mm: fix usage of FORCE_READ() in cow tests David Hildenbrand (Red Hat)
2026-01-19 13:24 ` Kevin Brodsky
2026-01-22 5:40 ` Dev Jain
2026-01-07 16:48 ` [PATCH v2 5/8] selftests/mm: introduce helper to read every page in range Kevin Brodsky
2026-01-09 1:30 ` SeongJae Park
2026-01-12 9:37 ` Kevin Brodsky
2026-01-13 0:55 ` SeongJae Park
2026-01-19 10:55 ` David Hildenbrand (Red Hat)
2026-01-19 13:29 ` Kevin Brodsky
2026-01-22 6:05 ` Dev Jain [this message]
2026-01-07 16:48 ` [PATCH v2 6/8] selftests/mm: fix faulting-in code in pagemap_ioctl test Kevin Brodsky
2026-01-19 11:09 ` David Hildenbrand (Red Hat)
2026-01-19 13:30 ` Kevin Brodsky
2026-01-22 6:16 ` Dev Jain
2026-01-07 16:48 ` [PATCH v2 7/8] selftests/mm: fix exit code in pagemap_ioctl Kevin Brodsky
2026-01-08 1:06 ` SeongJae Park
2026-01-08 2:12 ` wang lian
2026-01-22 6:22 ` Dev Jain
2026-01-07 16:48 ` [PATCH v2 8/8] selftests/mm: report SKIP in pfnmap if a check fails Kevin Brodsky
2026-01-12 9:34 ` Ryan Roberts
2026-01-12 10:03 ` Kevin Brodsky
2026-01-12 10:25 ` Ryan Roberts
2026-01-19 11:16 ` David Hildenbrand (Red Hat)
2026-01-19 14:26 ` Ryan Roberts
2026-01-19 14:32 ` David Hildenbrand (Red Hat)
2026-01-20 16:27 ` Ryan Roberts
2026-01-21 13:45 ` Kevin Brodsky
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a2549671-da39-4827-a534-32f128f233a1@arm.com \
--to=dev.jain@arm.com \
--cc=akpm@linux-foundation.org \
--cc=broonie@kernel.org \
--cc=david@kernel.org \
--cc=kevin.brodsky@arm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=ryan.roberts@arm.com \
--cc=shuah@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox