[PATCH 2/2] kselftests: cgroup: account for slab memory in test_percpu_basic
From: ranxiaokai627
Date: Tue Apr 14 2026 - 07:12:22 EST
From: Ran Xiaokai <ran.xiaokai@xxxxxxxxxx>
The test verifies memory.current approximates memory.stat.percpu within
a tolerance. However, memory.current includes slab overhead. On systems
with few CPUs(<= 4), slab consumption exceeds percpu usage. While percpu
usage grows linearly and dominates as CPU count increases, the
significant slab portion on such few CPU systems causes the difference
to exceed MAX_VMSTAT_ERROR, leading to false test failures.
Fix this by including slab memory in the calculation.
Signed-off-by: Ran Xiaokai <ran.xiaokai@xxxxxxxxxx>
---
tools/testing/selftests/cgroup/test_kmem.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/cgroup/test_kmem.c b/tools/testing/selftests/cgroup/test_kmem.c
index 15b8bb424cb5..263aedb0727a 100644
--- a/tools/testing/selftests/cgroup/test_kmem.c
+++ b/tools/testing/selftests/cgroup/test_kmem.c
@@ -360,7 +360,7 @@ static int test_percpu_basic(const char *root)
{
int ret = KSFT_FAIL;
char *parent, *child;
- long current, percpu;
+ long current, percpu, slab;
int i;
parent = cg_name(root, "percpu_basic_test");
@@ -386,8 +386,9 @@ static int test_percpu_basic(const char *root)
current = cg_read_long(parent, "memory.current");
percpu = cg_read_key_long(parent, "memory.stat", "percpu ");
+ slab = cg_read_key_long(parent, "memory.stat", "slab ");
- if (current > 0 && percpu > 0 && labs(current - percpu) <
+ if (current > 0 && percpu > 0 && labs(current - percpu - slab) <
MAX_VMSTAT_ERROR)
ret = KSFT_PASS;
else
--
2.25.1