* Re: [PATCH] selftests/bpf: Page out as late a possible in file_reader
2026-04-20 13:46 [PATCH] selftests/bpf: Page out as late a possible in file_reader Jerome Marchand
@ 2026-04-20 16:52 ` Mykyta Yatsenko
2026-04-21 5:59 ` Jerome Marchand
2026-04-20 23:13 ` sashiko-bot
` (2 subsequent siblings)
3 siblings, 1 reply; 6+ messages in thread
From: Mykyta Yatsenko @ 2026-04-20 16:52 UTC (permalink / raw)
To: Jerome Marchand, bpf
Cc: Andrii Nakryiko, Eduard Zingerman, Alexei Starovoitov,
Daniel Borkmann, Martin KaFai Lau, Kumar Kartikeya Dwivedi,
Song Liu, Yonghong Song, Jiri Olsa, Shuah Khan, Mykyta Yatsenko,
linux-kselftest, linux-kernel
On 4/20/26 2:46 PM, Jerome Marchand wrote:
> The file_reader/on_open_expect_fault fails consistently on my system.
> It expects a page fault on first dynptr read of some range the exe
> file of the current process because it has paged out that page range
> earlier. However a lot can happen to that range (which depending on
> the actual memory layout could contain text section, data section,
> sections )related to dynamic linking...) between the moment it was
> paged out and the moment the bpf program expected to hit a pagefault
> actually run.
>
> A bit of instrumentation with mincore() shows that pages from that
> range were accessed several times before the program is run. In
> particular the call of file_reader__load() seems to fault all the
> range in.
>
> Move the call to madvise(MADV_PAGEOUT) to just before attaching the
> program to minimize the risk of having those page pulled back in from
> under our feet.
>
> Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
> ---
Thank you for the patch, the change looks good. Does it fail
consistently on 4K page size?
Acked-by: Mykyta Yatsenko <yatsenko@meta.com>
> .../selftests/bpf/prog_tests/file_reader.c | 22 +++++++++----------
> 1 file changed, 10 insertions(+), 12 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/file_reader.c b/tools/testing/selftests/bpf/prog_tests/file_reader.c
> index 5cde32b35da44..48aae7ea0e4bb 100644
> --- a/tools/testing/selftests/bpf/prog_tests/file_reader.c
> +++ b/tools/testing/selftests/bpf/prog_tests/file_reader.c
> @@ -10,6 +10,7 @@
>
> const char *user_ptr = "hello world";
> char file_contents[256000];
> +void *addr;
>
> void *get_executable_base_addr(void)
> {
> @@ -26,8 +27,7 @@ void *get_executable_base_addr(void)
> static int initialize_file_contents(void)
> {
> int fd, page_sz = sysconf(_SC_PAGESIZE);
> - ssize_t n = 0, cur, off;
> - void *addr;
> + ssize_t n = 0, cur;
>
> fd = open("/proc/self/exe", O_RDONLY);
> if (!ASSERT_OK_FD(fd, "Open /proc/self/exe\n"))
> @@ -52,16 +52,6 @@ static int initialize_file_contents(void)
> /* page-align base file address */
> addr = (void *)((unsigned long)addr & ~(page_sz - 1));
>
> - /*
> - * Page out range 0..512K, use 0..256K for positive tests and
> - * 256K..512K for negative tests expecting page faults
> - */
> - for (off = 0; off < sizeof(file_contents) * 2; off += page_sz) {
> - if (!ASSERT_OK(madvise(addr + off, page_sz, MADV_PAGEOUT),
> - "madvise pageout"))
> - return errno;
> - }
> -
> return 0;
> }
>
> @@ -90,6 +80,14 @@ static void run_test(const char *prog_name)
> if (!ASSERT_OK(err, "file_reader__load"))
> goto cleanup;
>
> + /*
> + * Page out range 0..512K, use 0..256K for positive tests and
> + * 256K..512K for negative tests expecting page faults
> + */
> + if (!ASSERT_OK(madvise(addr, sizeof(file_contents) * 2, MADV_PAGEOUT),
> + "madvise pageout"))
> + goto cleanup;
> +
> err = file_reader__attach(skel);
> if (!ASSERT_OK(err, "file_reader__attach"))
> goto cleanup;
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] selftests/bpf: Page out as late a possible in file_reader
2026-04-20 16:52 ` Mykyta Yatsenko
@ 2026-04-21 5:59 ` Jerome Marchand
0 siblings, 0 replies; 6+ messages in thread
From: Jerome Marchand @ 2026-04-21 5:59 UTC (permalink / raw)
To: Mykyta Yatsenko, bpf
Cc: Andrii Nakryiko, Eduard Zingerman, Alexei Starovoitov,
Daniel Borkmann, Martin KaFai Lau, Kumar Kartikeya Dwivedi,
Song Liu, Yonghong Song, Jiri Olsa, Shuah Khan, Mykyta Yatsenko,
linux-kselftest, linux-kernel
On 4/20/26 6:52 PM, Mykyta Yatsenko wrote:
> On 4/20/26 2:46 PM, Jerome Marchand wrote:
>> The file_reader/on_open_expect_fault fails consistently on my system.
>> It expects a page fault on first dynptr read of some range the exe
>> file of the current process because it has paged out that page range
>> earlier. However a lot can happen to that range (which depending on
>> the actual memory layout could contain text section, data section,
>> sections )related to dynamic linking...) between the moment it was
>> paged out and the moment the bpf program expected to hit a pagefault
>> actually run.
>>
>> A bit of instrumentation with mincore() shows that pages from that
>> range were accessed several times before the program is run. In
>> particular the call of file_reader__load() seems to fault all the
>> range in.
>>
>> Move the call to madvise(MADV_PAGEOUT) to just before attaching the
>> program to minimize the risk of having those page pulled back in from
>> under our feet.
>>
>> Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
>> ---
>
> Thank you for the patch, the change looks good. Does it fail
> consistently on 4K page size?
It did when I ran the test manually. On our automated testing system, it
failed intermittently.
Regards,
Jerome
>
> Acked-by: Mykyta Yatsenko <yatsenko@meta.com>
>
>> .../selftests/bpf/prog_tests/file_reader.c | 22 +++++++++----------
>> 1 file changed, 10 insertions(+), 12 deletions(-)
>>
>> diff --git a/tools/testing/selftests/bpf/prog_tests/file_reader.c b/
>> tools/testing/selftests/bpf/prog_tests/file_reader.c
>> index 5cde32b35da44..48aae7ea0e4bb 100644
>> --- a/tools/testing/selftests/bpf/prog_tests/file_reader.c
>> +++ b/tools/testing/selftests/bpf/prog_tests/file_reader.c
>> @@ -10,6 +10,7 @@
>> const char *user_ptr = "hello world";
>> char file_contents[256000];
>> +void *addr;
>> void *get_executable_base_addr(void)
>> {
>> @@ -26,8 +27,7 @@ void *get_executable_base_addr(void)
>> static int initialize_file_contents(void)
>> {
>> int fd, page_sz = sysconf(_SC_PAGESIZE);
>> - ssize_t n = 0, cur, off;
>> - void *addr;
>> + ssize_t n = 0, cur;
>> fd = open("/proc/self/exe", O_RDONLY);
>> if (!ASSERT_OK_FD(fd, "Open /proc/self/exe\n"))
>> @@ -52,16 +52,6 @@ static int initialize_file_contents(void)
>> /* page-align base file address */
>> addr = (void *)((unsigned long)addr & ~(page_sz - 1));
>> - /*
>> - * Page out range 0..512K, use 0..256K for positive tests and
>> - * 256K..512K for negative tests expecting page faults
>> - */
>> - for (off = 0; off < sizeof(file_contents) * 2; off += page_sz) {
>> - if (!ASSERT_OK(madvise(addr + off, page_sz, MADV_PAGEOUT),
>> - "madvise pageout"))
>> - return errno;
>> - }
>> -
>> return 0;
>> }
>> @@ -90,6 +80,14 @@ static void run_test(const char *prog_name)
>> if (!ASSERT_OK(err, "file_reader__load"))
>> goto cleanup;
>> + /*
>> + * Page out range 0..512K, use 0..256K for positive tests and
>> + * 256K..512K for negative tests expecting page faults
>> + */
>> + if (!ASSERT_OK(madvise(addr, sizeof(file_contents) * 2,
>> MADV_PAGEOUT),
>> + "madvise pageout"))
>> + goto cleanup;
>> +
>> err = file_reader__attach(skel);
>> if (!ASSERT_OK(err, "file_reader__attach"))
>> goto cleanup;
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] selftests/bpf: Page out as late a possible in file_reader
2026-04-20 13:46 [PATCH] selftests/bpf: Page out as late a possible in file_reader Jerome Marchand
2026-04-20 16:52 ` Mykyta Yatsenko
@ 2026-04-20 23:13 ` sashiko-bot
2026-04-21 10:52 ` Jiri Olsa
2026-04-22 21:20 ` patchwork-bot+netdevbpf
3 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-04-20 23:13 UTC (permalink / raw)
To: Jerome Marchand; +Cc: bpf
Sashiko AI review found 1 potential issue(s):
- [Low] The newly promoted global variable `addr` is declared without the `static` keyword, polluting the global namespace.
--
commit e2c581de007abac2e6985b4f49f6c9786c3263b0
Author: Jerome Marchand <jmarchan@redhat.com>
selftests/bpf: Page out as late a possible in file_reader
The file_reader/on_open_expect_fault fails consistently on my system.
This commit moves the call to madvise(MADV_PAGEOUT) to just before
attaching the program to minimize the risk of having those pages pulled
back in.
> diff --git a/tools/testing/selftests/bpf/prog_tests/file_reader.c b/tools/testing/selftests/bpf/prog_tests/file_reader.c
> index 5cde32b35da44..48aae7ea0e4bb 100644
> --- a/tools/testing/selftests/bpf/prog_tests/file_reader.c
> +++ b/tools/testing/selftests/bpf/prog_tests/file_reader.c
> @@ -10,6 +10,7 @@
>
> const char *user_ptr = "hello world";
> char file_contents[256000];
> +void *addr;
This isn't a bug, but BPF selftests link all prog_tests/*.c files together
into a single test_progs executable.
Since modern compilers use -fno-common by default, could this un-prefixed
global variable cause a multiple definition linker error if another test
introduces a global variable with the same name?
Should addr be declared as static to safely restrict its linkage to
file_reader.c?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260420134637.2513867-1-jmarchan@redhat.com?part=1
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] selftests/bpf: Page out as late a possible in file_reader
2026-04-20 13:46 [PATCH] selftests/bpf: Page out as late a possible in file_reader Jerome Marchand
2026-04-20 16:52 ` Mykyta Yatsenko
2026-04-20 23:13 ` sashiko-bot
@ 2026-04-21 10:52 ` Jiri Olsa
2026-04-22 21:20 ` patchwork-bot+netdevbpf
3 siblings, 0 replies; 6+ messages in thread
From: Jiri Olsa @ 2026-04-21 10:52 UTC (permalink / raw)
To: Jerome Marchand
Cc: bpf, Andrii Nakryiko, Eduard Zingerman, Alexei Starovoitov,
Daniel Borkmann, Martin KaFai Lau, Kumar Kartikeya Dwivedi,
Song Liu, Yonghong Song, Shuah Khan, Mykyta Yatsenko,
linux-kselftest, linux-kernel
On Mon, Apr 20, 2026 at 03:46:37PM +0200, Jerome Marchand wrote:
> The file_reader/on_open_expect_fault fails consistently on my system.
> It expects a page fault on first dynptr read of some range the exe
> file of the current process because it has paged out that page range
> earlier. However a lot can happen to that range (which depending on
> the actual memory layout could contain text section, data section,
> sections )related to dynamic linking...) between the moment it was
> paged out and the moment the bpf program expected to hit a pagefault
> actually run.
>
> A bit of instrumentation with mincore() shows that pages from that
> range were accessed several times before the program is run. In
> particular the call of file_reader__load() seems to fault all the
> range in.
>
> Move the call to madvise(MADV_PAGEOUT) to just before attaching the
> program to minimize the risk of having those page pulled back in from
> under our feet.
>
> Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
nit typo in the subject a -> as
Acked-by: Jiri Olsa <jolsa@kernel.org>
jirka
> ---
> .../selftests/bpf/prog_tests/file_reader.c | 22 +++++++++----------
> 1 file changed, 10 insertions(+), 12 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/file_reader.c b/tools/testing/selftests/bpf/prog_tests/file_reader.c
> index 5cde32b35da44..48aae7ea0e4bb 100644
> --- a/tools/testing/selftests/bpf/prog_tests/file_reader.c
> +++ b/tools/testing/selftests/bpf/prog_tests/file_reader.c
> @@ -10,6 +10,7 @@
>
> const char *user_ptr = "hello world";
> char file_contents[256000];
> +void *addr;
>
> void *get_executable_base_addr(void)
> {
> @@ -26,8 +27,7 @@ void *get_executable_base_addr(void)
> static int initialize_file_contents(void)
> {
> int fd, page_sz = sysconf(_SC_PAGESIZE);
> - ssize_t n = 0, cur, off;
> - void *addr;
> + ssize_t n = 0, cur;
>
> fd = open("/proc/self/exe", O_RDONLY);
> if (!ASSERT_OK_FD(fd, "Open /proc/self/exe\n"))
> @@ -52,16 +52,6 @@ static int initialize_file_contents(void)
> /* page-align base file address */
> addr = (void *)((unsigned long)addr & ~(page_sz - 1));
>
> - /*
> - * Page out range 0..512K, use 0..256K for positive tests and
> - * 256K..512K for negative tests expecting page faults
> - */
> - for (off = 0; off < sizeof(file_contents) * 2; off += page_sz) {
> - if (!ASSERT_OK(madvise(addr + off, page_sz, MADV_PAGEOUT),
> - "madvise pageout"))
> - return errno;
> - }
> -
> return 0;
> }
>
> @@ -90,6 +80,14 @@ static void run_test(const char *prog_name)
> if (!ASSERT_OK(err, "file_reader__load"))
> goto cleanup;
>
> + /*
> + * Page out range 0..512K, use 0..256K for positive tests and
> + * 256K..512K for negative tests expecting page faults
> + */
> + if (!ASSERT_OK(madvise(addr, sizeof(file_contents) * 2, MADV_PAGEOUT),
> + "madvise pageout"))
> + goto cleanup;
> +
> err = file_reader__attach(skel);
> if (!ASSERT_OK(err, "file_reader__attach"))
> goto cleanup;
> --
> 2.53.0
>
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] selftests/bpf: Page out as late a possible in file_reader
2026-04-20 13:46 [PATCH] selftests/bpf: Page out as late a possible in file_reader Jerome Marchand
` (2 preceding siblings ...)
2026-04-21 10:52 ` Jiri Olsa
@ 2026-04-22 21:20 ` patchwork-bot+netdevbpf
3 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-04-22 21:20 UTC (permalink / raw)
To: Jerome Marchand
Cc: bpf, andrii, eddyz87, ast, daniel, martin.lau, memxor, song,
yonghong.song, jolsa, shuah, yatsenko, linux-kselftest,
linux-kernel
Hello:
This patch was applied to bpf/bpf-next.git (master)
by Kumar Kartikeya Dwivedi <memxor@gmail.com>:
On Mon, 20 Apr 2026 15:46:37 +0200 you wrote:
> The file_reader/on_open_expect_fault fails consistently on my system.
> It expects a page fault on first dynptr read of some range the exe
> file of the current process because it has paged out that page range
> earlier. However a lot can happen to that range (which depending on
> the actual memory layout could contain text section, data section,
> sections )related to dynamic linking...) between the moment it was
> paged out and the moment the bpf program expected to hit a pagefault
> actually run.
>
> [...]
Here is the summary with links:
- selftests/bpf: Page out as late a possible in file_reader
https://git.kernel.org/bpf/bpf-next/c/a20f97791a78
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 6+ messages in thread