Skip to content

Commit c1a31a2

Browse files
Byte-Labakpm00
authored andcommitted
cgroup: fix racy check in alloc_pagecache_max_30M() helper function
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. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: David Vernet <[email protected]> Acked-by: Roman Gushchin <[email protected]> Cc: Johannes Weiner <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Shakeel Butt <[email protected]> Cc: Tejun Heo <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 8303168 commit c1a31a2

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

tools/testing/selftests/cgroup/test_memcontrol.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,9 +568,14 @@ static int alloc_pagecache_max_30M(const char *cgroup, void *arg)
568568
{
569569
size_t size = MB(50);
570570
int ret = -1;
571-
long current;
571+
long current, high, max;
572572
int fd;
573573

574+
high = cg_read_long(cgroup, "memory.high");
575+
max = cg_read_long(cgroup, "memory.max");
576+
if (high != MB(30) && max != MB(30))
577+
goto cleanup;
578+
574579
fd = get_temp_fd();
575580
if (fd < 0)
576581
return -1;
@@ -579,7 +584,7 @@ static int alloc_pagecache_max_30M(const char *cgroup, void *arg)
579584
goto cleanup;
580585

581586
current = cg_read_long(cgroup, "memory.current");
582-
if (current <= MB(29) || current > MB(30))
587+
if (!values_close(current, MB(30), 5))
583588
goto cleanup;
584589

585590
ret = 0;

0 commit comments

Comments
 (0)