[PATCH 6/7] selftests: memcg: Don't call reclaim_until() if already in target
From: Waiman Long
Date: Thu Mar 19 2026 - 13:43:14 EST
Near the end of test_memcg_protection(), reclaim_until() is called
to reduce memory.current of children[0] to 10M. It was found that
with larger page size (e.g. 64k) the various memory cgroups in
test_memcg_protection() would deviate further from the expected values
especially for the test_memcg_low test. As a result, children[0] might
have reached the target already without reclamation. The will cause the
reclaim_until() function to report failure as no reclamation is needed.
Avoid this unexpected failure by skipping the reclaim_until() call if
memory.current of children[0] has already reached the target size for
kernel with non-4k page size.
Signed-off-by: Waiman Long <longman@xxxxxxxxxx>
---
tools/testing/selftests/cgroup/test_memcontrol.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/cgroup/test_memcontrol.c b/tools/testing/selftests/cgroup/test_memcontrol.c
index 4f12d4b4f9f8..0ef09bafa68c 100644
--- a/tools/testing/selftests/cgroup/test_memcontrol.c
+++ b/tools/testing/selftests/cgroup/test_memcontrol.c
@@ -490,6 +490,7 @@ static int test_memcg_protection(const char *root, bool min)
long current;
int i, attempts;
int fd;
+ bool do_reclaim;
fd = get_temp_fd();
if (fd < 0)
@@ -602,7 +603,15 @@ static int test_memcg_protection(const char *root, bool min)
9 + (min ? 0 : 6) * pscale_factor))
goto cleanup;
- if (!reclaim_until(children[0], MB(10)))
+ /*
+ * With larger page size, it is possible that memory.current of
+ * children[0] is close to 10M. Skip the reclaim_until() call if
+ * that is the case.
+ */
+ current = cg_read_long(children[0], "memory.current");
+ do_reclaim = (page_size == KB(4)) ||
+ ((current > MB(10)) && !values_close(current, MB(10), 3));
+ if (do_reclaim && !reclaim_until(children[0], MB(10)))
goto cleanup;
if (min) {
--
2.53.0