memcg/memcontrol0[34]: Align with the kselftest protection model
cover memcg/memcontrol0[34]: Align with the kselftest protection model
From: Sebastian Chlad <[email protected]>
memcontrol03 (memory.min) and memcontrol04 (memory.low) were ported from the kselftest test_memcontrol.c in 2022, but they still follow the 2018 version of it. The kselftest has since reworked this exact test three times, and none of that reached LTP:
- f10b6e9a8e66 ("selftests: memcg: adjust expected reclaim values of protected cgroups") replaced the hand-picked A/B/C ~= 33M and A/B/D ~= 17M with values from a simulation of the kernel's protection distribution (memcg_protection.m): 29M and 21M.
- 6a35919005d4 ("selftests: memcg: remove protection from top level memcg") dropped memory.min/memory.low on A, which has no effect since A is the reclaim root.
- d2def68ae06a ("selftests: memcg: increase error tolerance of child memory.current check in test_memcg_protection()") widened the tolerances to 15% (C) and 20% (D) because of sporadic failures.
The first one is what matters here. Kernels behave as the model says, so D ends up close to 21M and sits right at the edge of the old 17M +/- 20% range. On x86_64 D was at ~90% of the upper limit in every run, and small variations in reclaim are enough to fail it. With the model values both C and D sit in the middle of their ranges (~8M of margin each, 50+ iterations per test). LTP's tolerance is already 20% for both, so the third commit needs no change.
Patch 1 updates the expected values, patch 2 removes the top level protection. Both apply to memcontrol03 and memcontrol04.
This does not make every failure go away. On ppc64le we also see runs where the most protected group C is reclaimed down to a few MB while the unprotected A/B/F keeps its pagecache. That is protection working the wrong way round, not a tolerance problem, and the tests should keep reporting it.
Sebastian Chlad (2):
memcg/memcontrol0[34]: Use expected values from the protection model memcg/memcontrol0[34]: Remove protection from the top level group
.../kernel/controllers/memcg/memcontrol03.c | 18 +++++++++--------- .../kernel/controllers/memcg/memcontrol04.c | 18 +++++++++--------- 2 files changed, 18 insertions(+), 18 deletions(-)
Signature · 5 lines
2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 1/2 memcg/memcontrol0[34]: Use expected values from the protection model
From: Sebastian Chlad <[email protected]>
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.
--- testcases/kernel/controllers/memcg/memcontrol03.c | 13 +++++++------ testcases/kernel/controllers/memcg/memcontrol04.c | 13 +++++++------ 2 files changed, 14 insertions(+), 12 deletions(-)
testcases/kernel/controllers/memcg/memcontrol03.c +7 -6
@@ -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 ]);
testcases/kernel/controllers/memcg/memcontrol04.c +7 -6
@@ -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 ]);
Signature · 5 lines
2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 1/2] memcg/memcontrol0[34]: Use expected values from the protection model
Quoted 109 lines · Sebastian Chlad
From: Sebastian Chlad <[email protected]>
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.mfor 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 intest_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 <[email protected]>--- testcases/kernel/controllers/memcg/memcontrol03.c | 13 +++++++------ testcases/kernel/controllers/memcg/memcontrol04.c | 13 +++++++------ 2 files changed, 14 insertions(+), 12 deletions(-)testcases/kernel/controllers/memcg/memcontrol03.c +7
-6@@ -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 ]);testcases/kernel/controllers/memcg/memcontrol04.c +7
-6@@ -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 ]);Signature · 1 line
2.51.0
Quoted 4 lines
Signature · 2 lines
-- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] memcg/memcontrol0[34]: Use expected values from the protection model
In reply to Sebastian ChladHi Sebastian,
Quoted 1 line · Sebastian Chlad
memcg/memcontrol0[34]: Use expected values from the protection model
Verdict - Reviewed
---
Note:
The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.
Regards,
LTP AI Reviewer
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 1/2] memcg/memcontrol0[34]: Use expected values from the protection model
In reply to Sebastian ChladHello.
Quoted 10 lines · Sebastian Chlad
From: Sebastian Chlad <[email protected]>
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"):
Quoted 6 lines
A/B/C memory.current ~= 29M
A/B/D memory.current ~= 21M(see
tools/testing/selftests/cgroup/memcg_protection.mfor the model).Real kernels match the model,
Note: this was true at the time of the model introduction but the contemporary kernels may diverge slightly from it. (Not conceptually AFAIR, although some rounding / effective values caching could possibly affect the final values.)
Quoted 11 lines
so the old D target leaves very little
room below the upper bound of the 20% tolerance. On 6.12x86_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).
Quoted 5 lines
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 intest_memcg_protection()") raised the kselftest tolerances to 15% (C) and 20% (D) for the same kind of sporadic failures.
Makes sense to sync this with the kernel variant.
Quoted 4 lines
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.
I presume you refer the same reclaim mode "collapse" that was tackled in 7e19705f7 ("memcg/memcontrol04: Fix judgment for recursive_protection") (there it was only for unexpected events but that could be connected with the unexpected final F.memory.current). It is nothing new, correct?
Thanks,
Michal
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 2/2 memcg/memcontrol0[34]: Remove protection from the top level group
In reply to Sebastian ChladFrom: Sebastian Chlad <[email protected]>
The memory pressure in both tests comes from A/G hitting the memory.max of A, so A is the reclaim root. Protection of the reclaim root is ignored by the kernel and the direct children of the root (A/B and A/G) use their own memory.min/memory.low as is, see page_counter_calculate_protection(). The 50M of memory.min (memcontrol03) and memory.low (memcontrol04) set on A thus has no effect on what the tests check; it would only protect the whole hierarchy against reclaim from outside, which the tests don't need.
The kselftest the tests are ported from dropped it for the same reason in kernel commit 6a35919005d4 ("selftests: memcg: remove protection from top level memcg"). Do the same and correct the descriptions, as the pressure is created in A, not in A/G.
--- testcases/kernel/controllers/memcg/memcontrol03.c | 5 ++--- testcases/kernel/controllers/memcg/memcontrol04.c | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-)
testcases/kernel/controllers/memcg/memcontrol03.c +2 -3
@@ -5,7 +5,7 @@* * Original description: * "First, this test creates the following hierarchy: -* A memory.min = 50M, memory.max = 200M +* A memory.min = 0, memory.max = 200M * A/B memory.min = 50M, memory.current = 50M * A/B/C memory.min = 75M, memory.current = 50M * A/B/D memory.min = 25M, memory.current = 50M
@@ -15,7 +15,7 @@* Usages are pagecache, but the test keeps a running * process in every leaf cgroup. * Then it creates A/G and creates a significant -* memory pressure in it. +* memory pressure in A. * * A/B memory.current ~= 50M * A/B/C memory.current ~= 29M
@@ -194,7 +194,6 @@ static void test_memcg_min(void)alloc_pagecache_in_child (leaf_cg[i],MB (50 )); } -SAFE_CG_PRINT (trunk_cg[A ],"memory.min" ,"50M" );SAFE_CG_PRINT (trunk_cg[B ],"memory.min" ,"50M" );SAFE_CG_PRINT (leaf_cg[C ],"memory.min" ,"75M" );SAFE_CG_PRINT (leaf_cg[D ],"memory.min" ,"25M" );
testcases/kernel/controllers/memcg/memcontrol04.c +2 -3
@@ -5,7 +5,7 @@* * Original description: * "First, this test creates the following hierarchy: -* A memory.low = 50M, memory.max = 200M +* A memory.low = 0, memory.max = 200M * A/B memory.low = 50M, memory.current = 50M * A/B/C memory.low = 75M, memory.current = 50M * A/B/D memory.low = 25M, memory.current = 50M
@@ -14,7 +14,7 @@* * Usages are pagecache * Then it creates A/G and creates a significant -* memory pressure in it. +* memory pressure in A. * * A/B memory.current ~= 50M * A/B/C memory.current ~= 29M
@@ -167,7 +167,6 @@ static void test_memcg_low(void)alloc_pagecache_in_child (leaf_cg[i],MB (50 )); } -SAFE_CG_PRINT (trunk_cg[A ],"memory.low" ,"50M" );SAFE_CG_PRINT (trunk_cg[B ],"memory.low" ,"50M" );SAFE_CG_PRINT (leaf_cg[C ],"memory.low" ,"75M" );SAFE_CG_PRINT (leaf_cg[D ],"memory.low" ,"25M" );
Signature · 5 lines
2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 2/2] memcg/memcontrol0[34]: Remove protection from the top level group
Quoted 84 lines · Sebastian Chlad
From: Sebastian Chlad <[email protected]>
The memory pressure in both tests comes from A/G hitting the memory.max of A, so A is the reclaim root. Protection of the reclaim root is ignored by the kernel and the direct children of the root (A/B and A/G) use their own memory.min/memory.low as is, see
page_counter_calculate_protection(). The 50M of memory.min (memcontrol03) and memory.low (memcontrol04) set on A thus has no effect on what the tests check; it would only protect the whole hierarchy against reclaim from outside, which the tests don't need.The kselftest the tests are ported from dropped it for the same reason in kernel commit
6a35919005d4("selftests: memcg: remove protection from top level memcg"). Do the same and correct the descriptions, as the pressure is created in A, not in A/G.Signed-off-by Sebastian Chlad <[email protected]>--- testcases/kernel/controllers/memcg/memcontrol03.c | 5 ++--- testcases/kernel/controllers/memcg/memcontrol04.c | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-)testcases/kernel/controllers/memcg/memcontrol03.c +2
-3@@ -5,7 +5,7 @@* * Original description: * "First, this test creates the following hierarchy: -* A memory.min = 50M, memory.max = 200M +* A memory.min = 0, memory.max = 200M * A/B memory.min = 50M, memory.current = 50M * A/B/C memory.min = 75M, memory.current = 50M * A/B/D memory.min = 25M, memory.current = 50M @@ -15,7 +15,7 @@* Usages are pagecache, but the test keeps a running * process in every leaf cgroup. * Then it creates A/G and creates a significant -* memory pressure in it. +* memory pressure in A. * * A/B memory.current ~= 50M * A/B/C memory.current ~= 29M @@ -194,7 +194,6 @@ static void test_memcg_min(void)alloc_pagecache_in_child (leaf_cg[i],MB (50 )); } -SAFE_CG_PRINT (trunk_cg[A ],"memory.min" ,"50M" );SAFE_CG_PRINT (trunk_cg[B ],"memory.min" ,"50M" );SAFE_CG_PRINT (leaf_cg[C ],"memory.min" ,"75M" );SAFE_CG_PRINT (leaf_cg[D ],"memory.min" ,"25M" );testcases/kernel/controllers/memcg/memcontrol04.c +2
-3@@ -5,7 +5,7 @@* * Original description: * "First, this test creates the following hierarchy: -* A memory.low = 50M, memory.max = 200M +* A memory.low = 0, memory.max = 200M * A/B memory.low = 50M, memory.current = 50M * A/B/C memory.low = 75M, memory.current = 50M * A/B/D memory.low = 25M, memory.current = 50M @@ -14,7 +14,7 @@* * Usages are pagecache * Then it creates A/G and creates a significant -* memory pressure in it. +* memory pressure in A. * * A/B memory.current ~= 50M * A/B/C memory.current ~= 29M @@ -167,7 +167,6 @@ static void test_memcg_low(void)alloc_pagecache_in_child (leaf_cg[i],MB (50 )); } -SAFE_CG_PRINT (trunk_cg[A ],"memory.low" ,"50M" );SAFE_CG_PRINT (trunk_cg[B ],"memory.low" ,"50M" );SAFE_CG_PRINT (leaf_cg[C ],"memory.low" ,"75M" );SAFE_CG_PRINT (leaf_cg[D ],"memory.low" ,"25M" );Signature · 1 line
2.51.0
Quoted 4 lines
Signature · 2 lines
-- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 2/2] memcg/memcontrol0[34]: Remove protection from the top level group
In reply to Sebastian ChladQuoted 16 lines · Sebastian Chlad
From: Sebastian Chlad <[email protected]>
The memory pressure in both tests comes from A/G hitting the memory.max of A, so A is the reclaim root. Protection of the reclaim root is ignored by the kernel and the direct children of the root (A/B and A/G) use their own memory.min/memory.low as is, see
page_counter_calculate_protection(). The 50M of memory.min (memcontrol03) and memory.low (memcontrol04) set on A thus has no effect on what the tests check; it would only protect the whole hierarchy against reclaim from outside, which the tests don't need.The kselftest the tests are ported from dropped it for the same reason in kernel commit
6a35919005d4("selftests: memcg: remove protection from top level memcg"). Do the same and correct the descriptions, as the pressure is created in A, not in A/G.
Quoted 5 lines
Signed-off-by Sebastian Chlad <[email protected]>--- testcases/kernel/controllers/memcg/memcontrol03.c | 5 ++--- testcases/kernel/controllers/memcg/memcontrol04.c | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-)
Yes, this patch is easily tranferred.
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
I've pushed this as a last fixes before the release. Thanks.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp