[LTP] [PATCH 1/2] memcg/memcontrol0[34]: Use expected values from the protection model

Wei Gao wegao@suse.com
Mon Sep 28 08:27:36 CEST 2026


On Sat, Sep 26, 2026 at 10:44:53PM +0200, Sebastian Chlad wrote:
> From: Sebastian Chlad <sebastian.chlad@suse.com>
> 
> memcontrol03 (memory.min) and memcontrol04 (memory.low) still expect
> A/B/C ~= 33M and A/B/D ~= 17M after reclaim, which are the values from
> the original kselftest. These were never derived from how the kernel
> distributes protection among siblings, and the kselftest replaced them
> with simulated values for both tests in kernel commit f10b6e9a8e66
> ("selftests: memcg: adjust expected reclaim values of protected
> cgroups"):
> 
>   A/B/C  memory.current ~= 29M
>   A/B/D  memory.current ~= 21M
> 
> (see tools/testing/selftests/cgroup/memcg_protection.m for the model).
> 
> Real kernels match the model, so the old D target leaves very little
> room below the upper bound of the 20% tolerance. On 6.12 x86_64, 105
> iterations of memcontrol03 across ext2, ext3, ext4, xfs and btrfs gave:
> 
>   A/B/C  27.5M - 27.9M  (old range 22.0M - 49.5M)
>   A/B/D  22.7M - 23.0M  (old range 11.3M - 25.5M)
> 
> so A/B/D is already at ~90% of the old limit and small variations in
> reclaim push it over. Passing runs on 6.4 ppc64le show the same
> picture for both tests (C 22.6M - 32.0M, D 17.6M - 24.2M).
> 
> Switch to the model values. Keep the 20% tolerance, which is already
> at least as wide as the kselftest's; kernel commit d2def68ae06a
> ("selftests: memcg: increase error tolerance of child memory.current
> check in test_memcg_protection()") raised the kselftest tolerances to
> 15% (C) and 20% (D) for the same kind of sporadic failures.
> 
> This doesn't change the outcome where C is reclaimed far below D while
> the unprotected A/B/F keeps its pagecache (seen e.g. on ppc64le with
> C ~= 6M and F ~= 13M). That is a protection failure the tests should
> keep reporting.
> 
> Signed-off-by: Sebastian Chlad <sebastian.chlad@suse.com>
> ---
>  testcases/kernel/controllers/memcg/memcontrol03.c | 13 +++++++------
>  testcases/kernel/controllers/memcg/memcontrol04.c | 13 +++++++------
>  2 files changed, 14 insertions(+), 12 deletions(-)
> 
> diff --git a/testcases/kernel/controllers/memcg/memcontrol03.c b/testcases/kernel/controllers/memcg/memcontrol03.c
> index 96224c4ee..aa94f4999 100644
> --- a/testcases/kernel/controllers/memcg/memcontrol03.c
> +++ b/testcases/kernel/controllers/memcg/memcontrol03.c
> @@ -18,9 +18,10 @@
>   * memory pressure in it.
>   *
>   * A/B    memory.current ~= 50M
> - * A/B/C  memory.current ~= 33M
> - * A/B/D  memory.current ~= 17M
> + * A/B/C  memory.current ~= 29M
> + * A/B/D  memory.current ~= 21M
>   * A/B/E  memory.current ~= 0
> + * (for origin of the numbers, see model in memcg_protection.m.)
>   *
>   * After that it tries to allocate more than there is unprotected
>   * memory in A available, and checks that memory.min protects
> @@ -217,10 +218,10 @@ static void test_memcg_min(void)
>  	for (i = 0; i < ARRAY_SIZE(leaf_cg); i++)
>  		SAFE_CG_SCANF(leaf_cg[i], "memory.current", "%ld", c + i);
>  
> -	TST_EXP_EXPR(values_close(c[0], MB(33), 20),
> -		     "(A/B/C memory.current=%ld) ~= %d", c[0], MB(33));
> -	TST_EXP_EXPR(values_close(c[1], MB(17), 20),
> -		     "(A/B/D memory.current=%ld) ~= %d", c[1], MB(17));
> +	TST_EXP_EXPR(values_close(c[0], MB(29), 20),
> +		     "(A/B/C memory.current=%ld) ~= %d", c[0], MB(29));
> +	TST_EXP_EXPR(values_close(c[1], MB(21), 20),
> +		     "(A/B/D memory.current=%ld) ~= %d", c[1], MB(21));
>  	TST_EXP_EXPR(values_close(c[2], 0, 1),
>  		     "(A/B/E memory.current=%ld) ~= 0", c[2]);
>  
> diff --git a/testcases/kernel/controllers/memcg/memcontrol04.c b/testcases/kernel/controllers/memcg/memcontrol04.c
> index 22ca1df8c..92ab53a51 100644
> --- a/testcases/kernel/controllers/memcg/memcontrol04.c
> +++ b/testcases/kernel/controllers/memcg/memcontrol04.c
> @@ -17,9 +17,10 @@
>   * memory pressure in it.
>   *
>   * A/B    memory.current ~= 50M
> - * A/B/C  memory.current ~= 33M
> - * A/B/D  memory.current ~= 17M
> + * A/B/C  memory.current ~= 29M
> + * A/B/D  memory.current ~= 21M
>   * A/B/E  memory.current ~= 0
> + * (for origin of the numbers, see model in memcg_protection.m.)
>   *
>   * After that it tries to allocate more than there is unprotected
>   * memory in A available, and checks that memory.low protects
> @@ -182,10 +183,10 @@ static void test_memcg_low(void)
>  	for (i = 0; i < ARRAY_SIZE(leaf_cg); i++)
>  		SAFE_CG_SCANF(leaf_cg[i], "memory.current", "%ld", c + i);
>  
> -	TST_EXP_EXPR(values_close(c[0], MB(33), 20),
> -		     "(A/B/C memory.current=%ld) ~= %d", c[C], MB(33));
> -	TST_EXP_EXPR(values_close(c[1], MB(17), 20),
> -		     "(A/B/D memory.current=%ld) ~= %d", c[D], MB(17));
> +	TST_EXP_EXPR(values_close(c[0], MB(29), 20),
> +		     "(A/B/C memory.current=%ld) ~= %d", c[C], MB(29));
> +	TST_EXP_EXPR(values_close(c[1], MB(21), 20),
> +		     "(A/B/D memory.current=%ld) ~= %d", c[D], MB(21));
>  	TST_EXP_EXPR(values_close(c[2], 0, 1),
>  		     "(A/B/E memory.current=%ld) ~= 0", c[E]);
>  	tst_res(TINFO, "A/B/F memory.current=%ld", c[F]);
> -- 
> 2.51.0
Reviewed-by: Wei Gao <wegao@suse.com>
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp


More information about the ltp mailing list