selftests/bpf: Keep memcg test page cache off overlayfs
Subsystems (3)
PATCH v3 1/1 selftests/bpf: Keep memcg test page cache off overlayfs
memcg_proactive_reclaim and arena_memcg keep their page cache off tmpfs, because shmem cannot be reclaimed without swap. But statfs() only sees the top of a stacking filesystem: with /tmp on overlayfs over tmpfs, as in virtme-ng guests, the check passes and the data is still charged as shmem. memcg_proactive_reclaim then fails in a full test_progs run with:
test_memcg_proactive_reclaim:FAIL:reclaimed unexpected reclaimed: actual 0 <= expected 0
and arena_memcg, run from such a directory, with:
serial_test_arena_memcg:FAIL:child faulted the arena in unexpected child faulted the arena in: got FALSE
Reject overlayfs as well, so that memcg_proactive_reclaim moves on to the next candidate directory and arena_memcg skips.
An AI coding assistant (Claude) was used to find and analyze the failure and to draft this changelog.
---
Notes:
Changes in v3:
- Drop the memory.stat check, the polling and the per-directory cgroups, and reject overlayfs in the statfs() checks instead (Alexei).
- Apply the same fix to arena_memcg.
Changes in v2:
- Fall back to the next candidate directory instead of skipping.
- Poll memory.stat until the write shows up.
- Fail when memory.stat cannot be read.
Tested in virtme-ng guests without swap (/tmp is overlayfs over tmpfs, the working directory is virtiofs):
- memcg_proactive_reclaim passes from the default setup, from a tmpfs /tmp and from an ext4 working directory, and skips when the working directory is read-only or also overlayfs over tmpfs.
- arena_memcg passes from an ext4 working directory and now skips from overlayfs over tmpfs, where it failed before.
- A full test_progs run passes memcg_proactive_reclaim; the only failures are fs_kfuncs (no xattrs on the overlayfs /tmp) and xdp_synproxy (no iptables-legacy on the host), both unrelated.
v2: https://lore.kernel.org/bpf/[email protected]/
v1: https://lore.kernel.org/bpf/[email protected]/
tools/testing/selftests/bpf/prog_tests/arena_memcg.c | 8 ++++++-- .../selftests/bpf/prog_tests/memcg_proactive_reclaim.c | 6 ++++-- 2 files changed, 10 insertions(+), 4 deletions(-)
tools/testing/selftests/bpf/prog_tests/arena_memcg.c +6 -2
@@ -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 ; }
tools/testing/selftests/bpf/prog_tests/memcg_proactive_reclaim.c +4 -2
@@ -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 ;
base-commit: 0021f17128de5dc0b19f1a523f448df2440d8088
Signature · 1 line
2.56.1
This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:
Hello:
This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:
Quoted 9 lines · On Fri, 20 Nov 2026 02:39:25 +0800 you wrote:
memcg_proactive_reclaimandarena_memcgkeep their page cache off tmpfs, because shmem cannot be reclaimed without swap. Butstatfs()only sees the top of a stacking filesystem: with /tmp on overlayfs over tmpfs, as in virtme-ng guests, the check passes and the data is still charged as shmem.memcg_proactive_reclaimthen fails in a fulltest_progsrun with:test_memcg_proactive_reclaim:FAIL:reclaimed unexpected reclaimed: actual 0 <= expected 0
[...]
Here is the summary with links:
- [bpf-next,v3] selftests/bpf: Keep memcg test page cache off overlayfs
https://git.kernel.org/bpf/bpf-next/c/82cc2b4383e3
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html