mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH bpf-next v3] selftests/bpf: Keep memcg test page cache off overlayfs
@ 2026-11-19 18:39 Kurt Lin
  0 siblings, 0 replies; only message in thread
From: Kurt Lin @ 2026-11-19 18:39 UTC (permalink / raw)
  To: Hui Zhu, Hui Zhu, Kumar Kartikeya Dwivedi, bpf
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Martin KaFai Lau, Eduard Zingerman, Song Liu, Yonghong Song,
	Jiri Olsa, Ihor Solodrai, Emil Tsalapatis, Barry Song,
	Shuah Khan, Jiayuan Chen, linux-kselftest, linux-kernel,
	Kurt Lin

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.

Fixes: 0f9b1e9ef584 ("selftests/bpf: Add bpf_proactive_reclaim test")
Fixes: 1fe5a5cd01e4 ("selftests/bpf: Add a test for arena fault-in under memory.max")
Suggested-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Kurt Lin <lylin1023@gmail.com>
---

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/20261117170704.1146730-1-lylin1023@gmail.com/
    v1: https://lore.kernel.org/bpf/20261113180159.602033-1-lylin1023@gmail.com/

 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(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/arena_memcg.c b/tools/testing/selftests/bpf/prog_tests/arena_memcg.c
index c76a7eb2f01d..334bfa61be76 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 c22dcfabe856..2ba07916bdc9 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;

base-commit: 0021f17128de5dc0b19f1a523f448df2440d8088
-- 
2.56.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-19 18:39 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-19 18:39 [PATCH bpf-next v3] selftests/bpf: Keep memcg test page cache off overlayfs Kurt Lin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®