Re: [PATCH v2 5/7] selftests: memcg: Reduce the expected swap.peak with larger page size

Li Wang
2026-03-23T08:24:38Z

On Fri, Mar 20, 2026 at 04:42:39PM -0400, Waiman Long wrote:
> When running the test_memcg_swap_max_peak test which sets swap.max
> to 30M on an arm64 system with 64k page size, the test failed as the
> swap.peak could only reach up only to 27,328,512 bytes (about 25.45
> MB which is lower than the expected 29M) before the allocating task
> got oom-killed.
>
> It is likely due to the fact that it takes longer to write out a larger
> page to swap and hence a lower swap.peak is being reached. Setting
> memory.high to 29M to throttle memory allocation when nearing memory.max
> helps, but it still could only reach up to 29,032,448 bytes (about
> 27.04M). As a result, we have to reduce the expected swap.peak with
> larger page size. Now swap.peak is expected to reach only 27M with 64k
> page, 29M with 4k page and 28M with 16k page.
>
> Signed-off-by: Waiman Long <longman@redhat.com>
> ---
> .../selftests/cgroup/test_memcontrol.c | 26 ++++++++++++++++---
> 1 file changed, 22 insertions(+), 4 deletions(-)
>
> diff --git a/tools/testing/selftests/cgroup/test_memcontrol.c b/tools/testing/selftests/cgroup/test_memcontrol.c
> index c078fc458def..3832ded1e47b 100644
> --- a/tools/testing/selftests/cgroup/test_memcontrol.c
> +++ b/tools/testing/selftests/cgroup/test_memcontrol.c
> @@ -1032,6 +1032,7 @@ static int test_memcg_swap_max_peak(const char *root)
> char *memcg;
> long max, peak;
> struct stat ss;
> + long swap_peak;
> int swap_peak_fd = -1, mem_peak_fd = -1;
>
> /* any non-empty string resets */
> @@ -1119,6 +1120,23 @@ static int test_memcg_swap_max_peak(const char *root)
> if (cg_write(memcg, "memory.max", "30M"))
> goto cleanup;
>
> + /*
> + * The swap.peak that can be reached will depend on the system page
> + * size. With larger page size (e.g. 64k), it takes more time to write
> + * the anonymous memory page to swap and so the peak reached will be
> + * lower before the memory allocation process get oom-killed. One way
> + * to allow the swap.peak to go higher is to throttle memory allocation
> + * by setting memory.high to, say, 29M to give more time to swap out the
> + * memory before oom-kill. This is still not enough for it to reach
> + * 29M reachable with 4k page. So we still need to reduce the expected
> + * swap.peak accordingly.
> + */
> + swap_peak = (page_size == KB(4)) ? MB(29) :
> + ((page_size <= KB(16)) ? MB(28) : MB(27));

Or, go with a dynamic adjustment based on page size?

swap_peak = MB(29) - ilog2(page_size / KB(4)) * MB(1);

--
Regards,
Li Wang