[PATCH bpf-next v2 3/3] bpf: selftests: Skip kmem test when cgroup.memory=nokmem is set
From: Hui Zhu
Date: Fri Feb 13 2026 - 02:26:18 EST
From: Hui Zhu <zhuhui@xxxxxxxxxx>
When cgroup.memory=nokmem is set in the kernel command line, kmem
accounting is disabled. This causes the test_kmem subtest in
cgroup_iter_memcg to fail because it expects non-zero kmem values.
Fix this by checking /proc/cmdline for the nokmem parameter. If
found, verify that kmem value is zero and return early, skipping
the pipe creation test that would otherwise fail.
Signed-off-by: Hui Zhu <zhuhui@xxxxxxxxxx>
---
.../bpf/prog_tests/cgroup_iter_memcg.c | 30 +++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/tools/testing/selftests/bpf/prog_tests/cgroup_iter_memcg.c b/tools/testing/selftests/bpf/prog_tests/cgroup_iter_memcg.c
index 897b17b58df3..2b9c148cebf0 100644
--- a/tools/testing/selftests/bpf/prog_tests/cgroup_iter_memcg.c
+++ b/tools/testing/selftests/bpf/prog_tests/cgroup_iter_memcg.c
@@ -134,11 +134,41 @@ static void test_shmem(struct bpf_link *link, struct memcg_query *memcg_query)
shm_unlink("/tmp_shmem");
}
+static bool cmdline_has(const char *arg)
+{
+ char cmdline[4096];
+ int fd;
+ ssize_t len;
+ bool ret = false;
+
+ fd = open("/proc/cmdline", O_RDONLY);
+ if (fd < 0)
+ return false;
+
+ len = read(fd, cmdline, sizeof(cmdline) - 1);
+ close(fd);
+ if (len < 0)
+ return false;
+
+ cmdline[len] = '\0';
+ if (strstr(cmdline, arg))
+ ret = true;
+
+ return ret;
+}
+
#define NR_PIPES 64
static void test_kmem(struct bpf_link *link, struct memcg_query *memcg_query)
{
int fds[NR_PIPES][2], i;
+ if (cmdline_has("cgroup.memory=nokmem")) {
+ if (!ASSERT_OK(read_stats(link), "read stats"))
+ return;
+ ASSERT_EQ(memcg_query->memcg_kmem, 0, "kmem value");
+ return;
+ }
+
/*
* Increase kmem value by creating pipes which will allocate some
* kernel buffers.
--
2.43.0