test_no_invasive_cgroup_shrink uses fixed zswap/memory limits and
allocation sizes that are too small on systems with large PAGE_SIZE
(e.g. 64K). In that case, the test may fail to build enough pressure
to trigger zswap writeback reliably, leading to false failures.

Make the test size parameters PAGE_SIZE-aware and consistent:
  - set control_allocation_size to PAGE_SIZE * 1024,
  - set memory.zswap.max to PAGE_SIZE,
  - set memory.max of both cgroups to control_allocation_size / 2,
  - allocate control_allocation_size in wb_group (2x memory.max).

This keeps the test behavior stable across 4K and 64K PAGE_SIZE
configurations and avoids spurious failures in
test_no_invasive_cgroup_shrink.

=== Error Log ===
 # getconf PAGESIZE
 65536

 # ./test_zswap
 TAP version 13
 ...
 ok 5 test_zswap_writeback_disabled
 ok 6 # SKIP test_no_kmem_bypass
 not ok 7 test_no_invasive_cgroup_shrink

Signed-off-by: Li Wang <[email protected]>
Cc: Johannes Weiner <[email protected]>
Cc: Michal Hocko <[email protected]>
Cc: Michal Koutný <[email protected]>
Cc: Muchun Song <[email protected]>
Cc: Nhat Pham <[email protected]>
Cc: Tejun Heo <[email protected]>
Cc: Roman Gushchin <[email protected]>
Cc: Shakeel Butt <[email protected]>
Cc: Yosry Ahmed <[email protected]>
---

Notes:
    v3:
        - Make PAGE_SIZE aware instead of using fixed sizing.
        - Set memory.max for  wb_group/control_group to 
control_allocation_size/2.
        - Update wb_group pressure allocation to control_allocation_size.
        - Clarify commit message to focus on this test's sizing issue.
    v2:
        - No change.

 tools/testing/selftests/cgroup/test_zswap.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/cgroup/test_zswap.c 
b/tools/testing/selftests/cgroup/test_zswap.c
index cf5b1531c827..f84e84c3e7c8 100644
--- a/tools/testing/selftests/cgroup/test_zswap.c
+++ b/tools/testing/selftests/cgroup/test_zswap.c
@@ -421,17 +421,26 @@ static int test_zswap_writeback_disabled(const char *root)
 static int test_no_invasive_cgroup_shrink(const char *root)
 {
        int ret = KSFT_FAIL;
-       size_t control_allocation_size = MB(10);
+       size_t control_allocation_size = pagesize * 1024;
+       char zswap_max_buf[32], mem_max_buf[32];
        char *control_allocation = NULL, *wb_group = NULL, *control_group = 
NULL;
 
+       snprintf(zswap_max_buf, sizeof(zswap_max_buf), "%ld", pagesize);
+       snprintf(mem_max_buf, sizeof(mem_max_buf), "%zu", 
control_allocation_size / 2);
+
        wb_group = setup_test_group_1M(root, "per_memcg_wb_test1");
        if (!wb_group)
                return KSFT_FAIL;
-       if (cg_write(wb_group, "memory.zswap.max", "10K"))
+       if (cg_write(wb_group, "memory.zswap.max", zswap_max_buf))
+               goto out;
+       if (cg_write(wb_group, "memory.max", mem_max_buf))
                goto out;
+
        control_group = setup_test_group_1M(root, "per_memcg_wb_test2");
        if (!control_group)
                goto out;
+       if (cg_write(control_group, "memory.max", mem_max_buf))
+               goto out;
 
        /* Push some test_group2 memory into zswap */
        if (cg_enter_current(control_group))
@@ -442,8 +451,8 @@ static int test_no_invasive_cgroup_shrink(const char *root)
        if (cg_read_key_long(control_group, "memory.stat", "zswapped") < 1)
                goto out;
 
-       /* Allocate 10x memory.max to push wb_group memory into zswap and 
trigger wb */
-       if (cg_run(wb_group, allocate_bytes, (void *)MB(10)))
+       /* Allocate 2x memory.max to push wb_group memory into zswap and 
trigger wb */
+       if (cg_run(wb_group, allocate_bytes, (void *)control_allocation_size))
                goto out;
 
        /* Verify that only zswapped memory from gwb_group has been written 
back */
-- 
2.53.0


Reply via email to