From: Hui Zhu <hui.zhu@linux.dev>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>,
Kurt Lin <lylin1023@gmail.com>, Hui Zhu <zhuhui@kylinos.cn>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>,
bpf@vger.kernel.org
Cc: Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Martin KaFai Lau <martin.lau@linux.dev>,
Eduard Zingerman <eddyz87@gmail.com>, Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
Jiri Olsa <jolsa@kernel.org>,
Ihor Solodrai <ihor.solodrai@linux.dev>,
Emil Tsalapatis <emil@etsalapatis.com>,
Barry Song <baohua@kernel.org>, Shuah Khan <shuah@kernel.org>,
linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH bpf-next v2] selftests/bpf: Fall back when memcg_proactive_reclaim data lands in shmem
Date: Thu, 19 Nov 2026 11:04:02 +0800 [thread overview]
Message-ID: <79797479-029f-4e9b-8076-6a92a2a70cdd@linux.dev> (raw)
In-Reply-To: <DMY136RTAL9Q.2WQSZ57W1YLV2@gmail.com>
2026/11/18 11:49, Alexei Starovoitov:
> On Tue, Nov 17, 2026 at 09:07 AM Kurt Lin <lylin1023@gmail.com> wrote:
>> After writing the file, check memory.stat and move on to the next
>> candidate directory if most of the data was charged as shmem; skip only
>> when none is left. Give each candidate its own cgroup so that stale
>> stats from a previous attempt cannot interfere, and poll memory.stat
>> until the write shows up, as reading it does not force a stats flush.
>> Fail the test if memory.stat cannot be read or never shows the write.
> This is overkill.
>
>> To exercise the polling, FILE_SIZE was temporarily cut to 2 MiB in a
>> 128-vCPU guest, which keeps the write below the flush threshold.
> So the test with 32 MiB didn't hit it.
> Pls don't add code just because a bot said so.
>
> Here is what I mean. I didn't compile it:
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/arena_memcg.c b/tools/testing/selftests/bpf/prog_tests/arena_memcg.c
> index c76a7eb..334bfa6 100644
> --- a/tools/testing/selftests/bpf/prog_tests/arena_memcg.c
> +++ b/tools/testing/selftests/bpf/prog_tests/arena_memcg.c
> @@ -53,8 +53,12 @@ static int alloc_pagecache(size_t size)
> fd = open(".", O_TMPFILE | O_RDWR | O_EXCL, 0600);
> if (fd < 0)
> return errno == EOPNOTSUPP ? -EOPNOTSUPP : -1;
> - /* tmpfs hands out shmem pages, which are not reclaimable without swap */
> - if (fstatfs(fd, &stfs) || stfs.f_type == TMPFS_MAGIC) {
> + /*
> + * tmpfs hands out shmem pages, which are not reclaimable without swap.
> + * overlayfs hides the type of its upper layer, which can be tmpfs.
> + */
> + if (fstatfs(fd, &stfs) || stfs.f_type == TMPFS_MAGIC ||
> + stfs.f_type == OVERLAYFS_SUPER_MAGIC) {
> close(fd);
> return -EOPNOTSUPP;
> }
> diff --git a/tools/testing/selftests/bpf/prog_tests/memcg_proactive_reclaim.c b/tools/testing/selftests/bpf/prog_tests/memcg_proactive_reclaim.c
> index c22dcfa..2ba0791 100644
> --- a/tools/testing/selftests/bpf/prog_tests/memcg_proactive_reclaim.c
> +++ b/tools/testing/selftests/bpf/prog_tests/memcg_proactive_reclaim.c
> @@ -30,7 +30,8 @@ struct reclaim_args {
> * being available, and a read-only mount cannot host the file at all (EROFS
> * applies to root too). /tmp is tmpfs on many systems, and test_progs is
> * routinely run from a tmpfs working directory, so both candidates need the
> - * check.
> + * check. overlayfs hides the type of its upper layer, which is tmpfs for /tmp
> + * in virtme-ng guests.
> */
> static const char *workload_dir(void)
> {
> @@ -40,7 +41,8 @@ static const char *workload_dir(void)
>
> for (i = 0; i < ARRAY_SIZE(dirs); i++)
> if (!statfs(dirs[i], &st) && st.f_type != TMPFS_MAGIC &&
> - st.f_type != RAMFS_MAGIC && !access(dirs[i], W_OK))
> + st.f_type != RAMFS_MAGIC &&
> + st.f_type != OVERLAYFS_SUPER_MAGIC && !access(dirs[i], W_OK))
> return dirs[i];
>
> return NULL;
>
> pw-bot: cr
Hi Alexei,
What about two things: only check when the test fails, and check
KPF_SWAPBACKED instead of f_type?
1. Check only when the test fails.
What the test needs is "these pages are reclaimable", not "these pages
are not shmem": with swap available shmem reclaims fine, and then
reclaimed == 0 is a real regression that must not be skipped. So probe on
the failure path only -- nothing is paid when the test passes, there is
no polling, and a regression cannot be masked.
2. Probe with KPF_SWAPBACKED.
f_type is a blacklist, so the next stacking filesystem repeats this.
shmem-ness is a property of the pages rather than of the mount, so ask
the pages: /proc/self/pagemap for VA -> PFN, /proc/kpageflags for
PFN -> flags, then test bit 14.
#define PAGEMAP_PRESENT(e) (((e) & (1ull << 63)) != 0)
#define PAGEMAP_PFN(e) ((e) & ((1ull << 55) - 1))
#define KPF_SWAPBACKED (1ull << 14)
/* 1 if fd is backed by shmem, 0 if not, -1 if it could not tell */
static int file_is_shmem(int fd)
{
unsigned long ps = getpagesize();
uint64_t ent = 0, flags = 0;
int pfd = -1, kfd = -1, ret = -1;
char *addr;
addr = mmap(NULL, ps, PROT_READ, MAP_SHARED, fd, 0);
if (addr == MAP_FAILED)
return -1;
*(volatile char *)addr;
pfd = open("/proc/self/pagemap", O_RDONLY);
kfd = open("/proc/kpageflags", O_RDONLY);
if (pfd < 0 || kfd < 0)
goto out;
if (pread(pfd, &ent, sizeof(ent),
((uintptr_t)addr / ps) * sizeof(ent)) != sizeof(ent))
goto out;
/* unprivileged readers see PM_PRESENT with the PFN zeroed */
if (!PAGEMAP_PRESENT(ent) || !PAGEMAP_PFN(ent))
goto out;
if (pread(kfd, &flags, sizeof(flags),
PAGEMAP_PFN(ent) * sizeof(flags)) != sizeof(flags))
goto out;
ret = !!(flags & KPF_SWAPBACKED);
out:
if (pfd >= 0)
close(pfd);
if (kfd >= 0)
close(kfd);
munmap(addr, ps);
return ret;
}
if (!skel->bss->reclaimed) {
struct sysinfo si;
sysinfo(&si);
if (!si.totalswap && file_is_shmem(data_fd) == 1) {
test__skip();
goto out;
}
}
ASSERT_GT(skel->bss->reclaimed, 0, "reclaimed");
What it buys: it sees through any stacking filesystem instead of only the
listed ones, it is per-page rather than inferred from a magic number, it
needs no polling and no extra cgroup, and it costs nothing on the success
path. Returning -1 when it cannot tell keeps the caller conservative --
a failure beats a silent pass. Both files are root-only, which these tests
already are, and selftests/mm/vm_util.c already pairs pagemap with
kpageflags.
Best,
Hui
next prev parent reply other threads:[~2026-11-19 3:04 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 17:07 [PATCH bpf-next v2] selftests/bpf: Fall back when memcg_proactive_reclaim data lands in shmem Kurt Lin
2026-11-18 3:49 ` Alexei Starovoitov
2026-11-19 3:04 ` Hui Zhu [this message]
2026-11-19 3:45 ` Alexei Starovoitov
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=79797479-029f-4e9b-8076-6a92a2a70cdd@linux.dev \
--to=hui.zhu@linux.dev \
--cc=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=baohua@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=ihor.solodrai@linux.dev \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=lylin1023@gmail.com \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=yonghong.song@linux.dev \
--cc=zhuhui@kylinos.cn \
/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