[LTP] [PATCH v2 2/2] memcontrol03, memcontrol04: Bind test process to a single CPU

Wei Gao wegao@suse.com
Wed Sep 30 05:53:15 CEST 2026


On multi-CPU systems, memcontrol03 and memcontrol04 can intermittently
fail with over-reclaim of protected pagecache under trunk_B:

  memcontrol03.c:104: TINFO: Child 142113 in trunk_G: Allocating anon: 150994944
  memcontrol03.c:121: TPASS: Child 142113 exited
  memcontrol03.c:214: TPASS: Expect: (A/B memory.current=54394880) ~= 52428800
  ...
  memcontrol03.c:104: TINFO: Child 142114 in trunk_G: Allocating anon: 174063616
  memcontrol03.c:116: TPASS: Child 142114 killed by OOM
  memcontrol03.c:230: TFAIL: Expect: (A/B memory.current=43319296) ~= 52428800

In the kernel, per-CPU charge batching (MEMCG_CHARGE_BATCH = 64 pages)
caches charges in per-CPU memcg_stock. On multi-CPU systems (especially
with large page sizes like 64KB on ppc64le where each CPU caches up to
4MB), allocating memory across CPUs allows cached stock charges to
accumulate in ancestor trunk_A. Because trunk_A has memory.max = 200M,
this extra stock pressure forces the reclaimer to evict pagecache in
trunk_B down to ~35-43MB instead of the expected ~50MB.

Set .setup = bind_to_current_cpu in both tests. Since child processes
inherit CPU affinity on fork(), this confines stock batching to a
single CPU across all test children, preventing multi-CPU stock
accumulation and ensuring reproducible reclaim behavior.

Signed-off-by: Wei Gao <wegao@suse.com>
---
 testcases/kernel/controllers/memcg/memcontrol03.c | 1 +
 testcases/kernel/controllers/memcg/memcontrol04.c | 1 +
 2 files changed, 2 insertions(+)

diff --git a/testcases/kernel/controllers/memcg/memcontrol03.c b/testcases/kernel/controllers/memcg/memcontrol03.c
index 96224c4ee..d65c03c0d 100644
--- a/testcases/kernel/controllers/memcg/memcontrol03.c
+++ b/testcases/kernel/controllers/memcg/memcontrol03.c
@@ -243,6 +243,7 @@ static void cleanup(void)
 }
 
 static struct tst_test test = {
+	.setup = bind_to_current_cpu,
 	.cleanup = cleanup,
 	.test_all = test_memcg_min,
 	.mount_device = 1,
diff --git a/testcases/kernel/controllers/memcg/memcontrol04.c b/testcases/kernel/controllers/memcg/memcontrol04.c
index 22ca1df8c..28ceaf8c1 100644
--- a/testcases/kernel/controllers/memcg/memcontrol04.c
+++ b/testcases/kernel/controllers/memcg/memcontrol04.c
@@ -242,6 +242,7 @@ static void cleanup(void)
 }
 
 static struct tst_test test = {
+	.setup = bind_to_current_cpu,
 	.cleanup = cleanup,
 	.test_all = test_memcg_low,
 	.mount_device = 1,
-- 
2.55.0



More information about the ltp mailing list