Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

cgroup: account for memory_recursiveprot in test_memcg_low()

The test_memcg_low() testcase in test_memcontrol.c verifies the expected
behavior of groups using the memory.low knob. Part of the testcase
verifies that a group with memory.low that experiences reclaim due to
memory pressure elsewhere in the system, observes memory.events.low events
as a result of that reclaim.

In commit 8a931f801340 ("mm: memcontrol: recursive memory.low
protection"), the memory controller was updated to propagate memory.low
and memory.min protection from a parent group to its children via a
configurable memory_recursiveprot mount option. This unfortunately broke
the memcg tests, which asserts that a sibling that experienced reclaim but
had a memory.low value of 0, would not observe any memory.low events.
This patch updates test_memcg_low() to account for the new behavior
introduced by memory_recursiveprot.

So as to make the test resilient to multiple configurations, the patch
also adds a new proc_mount_contains() helper that checks for a string in
/proc/mounts, and is used to toggle behavior based on whether the default
memory_recursiveprot was present.

Link: https://lkml.kernel.org/r/20220423155619.3669555-3-void@manifault.com
Signed-off-by: David Vernet <void@manifault.com>
Acked-by: Roman Gushchin <roman.gushchin@linux.dev>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Shakeel Butt <shakeelb@google.com>
Cc: Tejun Heo <tj@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

David Vernet and committed by
Andrew Morton
cdc69458 f0cdaa56

+26 -3
+12
tools/testing/selftests/cgroup/cgroup_util.c
··· 528 528 return 0; 529 529 } 530 530 531 + int proc_mount_contains(const char *option) 532 + { 533 + char buf[4 * PAGE_SIZE]; 534 + ssize_t read; 535 + 536 + read = read_text("/proc/mounts", buf, sizeof(buf)); 537 + if (read < 0) 538 + return read; 539 + 540 + return strstr(buf, option) != NULL; 541 + } 542 + 531 543 ssize_t proc_read_text(int pid, bool thread, const char *item, char *buf, size_t size) 532 544 { 533 545 char path[PATH_MAX];
+1
tools/testing/selftests/cgroup/cgroup_util.h
··· 48 48 extern int set_oom_adj_score(int pid, int score); 49 49 extern int cg_wait_for_proc_count(const char *cgroup, int count); 50 50 extern int cg_killall(const char *cgroup); 51 + int proc_mount_contains(const char *option); 51 52 extern ssize_t proc_read_text(int pid, bool thread, const char *item, char *buf, size_t size); 52 53 extern int proc_read_strstr(int pid, bool thread, const char *item, const char *needle); 53 54 extern pid_t clone_into_cgroup(int cgroup_fd);
+13 -3
tools/testing/selftests/cgroup/test_memcontrol.c
··· 21 21 #include "../kselftest.h" 22 22 #include "cgroup_util.h" 23 23 24 + static bool has_recursiveprot; 25 + 24 26 /* 25 27 * This test creates two nested cgroups with and without enabling 26 28 * the memory controller. ··· 527 525 } 528 526 529 527 for (i = 0; i < ARRAY_SIZE(children); i++) { 528 + int no_low_events_index = has_recursiveprot ? 2 : 1; 529 + 530 530 oom = cg_read_key_long(children[i], "memory.events", "oom "); 531 531 low = cg_read_key_long(children[i], "memory.events", "low "); 532 532 533 533 if (oom) 534 534 goto cleanup; 535 - if (i < 2 && low <= 0) 535 + if (i <= no_low_events_index && low <= 0) 536 536 goto cleanup; 537 - if (i >= 2 && low) 537 + if (i > no_low_events_index && low) 538 538 goto cleanup; 539 + 539 540 } 540 541 541 542 ret = KSFT_PASS; ··· 1387 1382 int main(int argc, char **argv) 1388 1383 { 1389 1384 char root[PATH_MAX]; 1390 - int i, ret = EXIT_SUCCESS; 1385 + int i, proc_status, ret = EXIT_SUCCESS; 1391 1386 1392 1387 if (cg_find_unified_root(root, sizeof(root))) 1393 1388 ksft_exit_skip("cgroup v2 isn't mounted\n"); ··· 1402 1397 if (cg_read_strstr(root, "cgroup.subtree_control", "memory")) 1403 1398 if (cg_write(root, "cgroup.subtree_control", "+memory")) 1404 1399 ksft_exit_skip("Failed to set memory controller\n"); 1400 + 1401 + proc_status = proc_mount_contains("memory_recursiveprot"); 1402 + if (proc_status < 0) 1403 + ksft_exit_skip("Failed to query cgroup mount option\n"); 1404 + has_recursiveprot = proc_status; 1405 1405 1406 1406 for (i = 0; i < ARRAY_SIZE(tests); i++) { 1407 1407 switch (tests[i].fn(root)) {