Message ID | 20220422155728.3055914-6-void@manifault.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | Fix bugs in memcontroller cgroup tests | expand |
On Fri, Apr 22, 2022 at 08:57:29AM -0700, David Vernet wrote: > alloc_pagecache_max_30M() in the cgroup memcg tests performs a 50MB > pagecache allocation, which it expects to be capped at 30MB due to the > calling process having a memory.high setting of 30MB. After the allocation, > the function contains a check that verifies that MB(29) < memory.current <= > MB(30). This check can actually fail non-deterministically. > > The testcases that use this function are test_memcg_high() and > test_memcg_max(), which set memory.min and memory.max to 30MB respectively > for the cgroup under test. The allocation can slightly exceed this number > in both cases, and for memory.max, the process performing the allocation > will not have the OOM killer invoked as it's performing a pagecache > allocation. This patchset therefore updates the above check to instead use > the verify_close() helper function. > > Signed-off-by: David Vernet <void@manifault.com> Acked-by: Roman Gushchin <roman.gushchin@linux.dev> Thanks, David!
diff --git a/tools/testing/selftests/cgroup/test_memcontrol.c b/tools/testing/selftests/cgroup/test_memcontrol.c index c4735fa36a3d..088850f01ae7 100644 --- a/tools/testing/selftests/cgroup/test_memcontrol.c +++ b/tools/testing/selftests/cgroup/test_memcontrol.c @@ -564,9 +564,14 @@ static int alloc_pagecache_max_30M(const char *cgroup, void *arg) { size_t size = MB(50); int ret = -1; - long current; + long current, high, max; int fd; + high = cg_read_long(cgroup, "memory.high"); + max = cg_read_long(cgroup, "memory.max"); + if (high != MB(30) && max != MB(30)) + goto cleanup; + fd = get_temp_fd(); if (fd < 0) return -1; @@ -575,7 +580,7 @@ static int alloc_pagecache_max_30M(const char *cgroup, void *arg) goto cleanup; current = cg_read_long(cgroup, "memory.current"); - if (current <= MB(29) || current > MB(30)) + if (!values_close(current, MB(30), 5)) goto cleanup; ret = 0;
alloc_pagecache_max_30M() in the cgroup memcg tests performs a 50MB pagecache allocation, which it expects to be capped at 30MB due to the calling process having a memory.high setting of 30MB. After the allocation, the function contains a check that verifies that MB(29) < memory.current <= MB(30). This check can actually fail non-deterministically. The testcases that use this function are test_memcg_high() and test_memcg_max(), which set memory.min and memory.max to 30MB respectively for the cgroup under test. The allocation can slightly exceed this number in both cases, and for memory.max, the process performing the allocation will not have the OOM killer invoked as it's performing a pagecache allocation. This patchset therefore updates the above check to instead use the verify_close() helper function. Signed-off-by: David Vernet <void@manifault.com> --- tools/testing/selftests/cgroup/test_memcontrol.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)