From patchwork Sat Apr 23 15:56:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: David Vernet X-Patchwork-Id: 12824632 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8938FC433F5 for ; Sat, 23 Apr 2022 15:57:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 13A026B0078; Sat, 23 Apr 2022 11:57:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0E95E6B007B; Sat, 23 Apr 2022 11:57:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ECC9B6B007D; Sat, 23 Apr 2022 11:57:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.27]) by kanga.kvack.org (Postfix) with ESMTP id DD0786B0078 for ; Sat, 23 Apr 2022 11:57:11 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id B44DB61979 for ; Sat, 23 Apr 2022 15:57:11 +0000 (UTC) X-FDA: 79388597862.12.F5D9DDF Received: from mail-qv1-f54.google.com (mail-qv1-f54.google.com [209.85.219.54]) by imf02.hostedemail.com (Postfix) with ESMTP id 7B3BF80040 for ; Sat, 23 Apr 2022 15:57:09 +0000 (UTC) Received: by mail-qv1-f54.google.com with SMTP id a5so8428456qvx.1 for ; Sat, 23 Apr 2022 08:57:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pdJh19mhSXyLFACX22MoCTE0boFuYhA324nOqBiKz+c=; b=4hyXoqv2V7KPrmUZIUuc2nyVnU8LDEeTqqUwYvG+8AiAatqGfEYMDxGHlxBLLoPtoJ kv0fw601pyEAPFU4OcLZDqQy7S3aw2jMnAlHZOgwpewj8KPxCEJf+8mZpxHEcl9bo/yN HY5VsINXN6/OOwCDaH9EQRbrnuqGKIktXUtOGTgtsuwJg+mFnFyM6QRgYQIfErAnxvI0 A3Gde942gX3hUyHkqmc0/l8JkwJJY7KT9kDz57UItu3GU1aVTcJjYle83JG+oB367PdI n5z413cbBmBscWq3ld6kzLHrMMK0aP9gGCZuIN9ZsY/KAPttV6jUJOFb3PXnSZVkL2Uw Po5w== X-Gm-Message-State: AOAM5303Zj3l5ECK6+i4ZvSlc2mQhbeNncXSgKjif2v3UU9AIM6NlKG9 ElIlG256POHsSEUr8eXvOYo= X-Google-Smtp-Source: ABdhPJzbIDyOnNIorYlI1wtlV5sgI0Le0m3m9xvp1ptF9YqnSRqNAZwZr0/K9T9eNh/Y3MXhnku5Rg== X-Received: by 2002:a05:6214:3001:b0:443:bb87:7f9a with SMTP id ke1-20020a056214300100b00443bb877f9amr7134623qvb.13.1650729430518; Sat, 23 Apr 2022 08:57:10 -0700 (PDT) Received: from localhost (fwdproxy-ash-022.fbsv.net. [2a03:2880:20ff:16::face:b00c]) by smtp.gmail.com with ESMTPSA id z15-20020a05622a060f00b002e2070bf899sm3048888qta.90.2022.04.23.08.57.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Apr 2022 08:57:10 -0700 (PDT) From: David Vernet To: akpm@linux-foundation.org Cc: tj@kernel.org, roman.gushchin@linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org, cgroups@vger.kernel.org, hannes@cmpxchg.org, mhocko@kernel.org, shakeelb@google.com, kernel-team@fb.com, void@manifault.com Subject: [PATCH v2 2/5] cgroup: Account for memory_recursiveprot in test_memcg_low() Date: Sat, 23 Apr 2022 08:56:19 -0700 Message-Id: <20220423155619.3669555-3-void@manifault.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220423155619.3669555-1-void@manifault.com> References: <20220423155619.3669555-1-void@manifault.com> MIME-Version: 1.0 X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 7B3BF80040 X-Stat-Signature: kskzded33t84xyuta9auh6w33uez39ot X-Rspam-User: Authentication-Results: imf02.hostedemail.com; dkim=none; spf=pass (imf02.hostedemail.com: domain of dcvernet@gmail.com designates 209.85.219.54 as permitted sender) smtp.mailfrom=dcvernet@gmail.com; dmarc=none X-HE-Tag: 1650729429-819314 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000021, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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. Signed-off-by: David Vernet Acked-by: Roman Gushchin Reported-by: Richard Palethorpe Signed-off-by: Michal Koutný --- tools/testing/selftests/cgroup/cgroup_util.c | 12 ++++++++++++ tools/testing/selftests/cgroup/cgroup_util.h | 1 + tools/testing/selftests/cgroup/test_memcontrol.c | 16 +++++++++++++--- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/cgroup/cgroup_util.c b/tools/testing/selftests/cgroup/cgroup_util.c index dbaa7aabbb4a..e5d8d727bdcf 100644 --- a/tools/testing/selftests/cgroup/cgroup_util.c +++ b/tools/testing/selftests/cgroup/cgroup_util.c @@ -535,6 +535,18 @@ int set_oom_adj_score(int pid, int score) return 0; } +int proc_mount_contains(const char *option) +{ + char buf[4 * PAGE_SIZE]; + ssize_t read; + + read = read_text("/proc/mounts", buf, sizeof(buf)); + if (read < 0) + return read; + + return strstr(buf, option) != NULL; +} + ssize_t proc_read_text(int pid, bool thread, const char *item, char *buf, size_t size) { char path[PATH_MAX]; diff --git a/tools/testing/selftests/cgroup/cgroup_util.h b/tools/testing/selftests/cgroup/cgroup_util.h index 628738532ac9..756f76052b44 100644 --- a/tools/testing/selftests/cgroup/cgroup_util.h +++ b/tools/testing/selftests/cgroup/cgroup_util.h @@ -48,6 +48,7 @@ extern int is_swap_enabled(void); extern int set_oom_adj_score(int pid, int score); extern int cg_wait_for_proc_count(const char *cgroup, int count); extern int cg_killall(const char *cgroup); +int proc_mount_contains(const char *option); extern ssize_t proc_read_text(int pid, bool thread, const char *item, char *buf, size_t size); extern int proc_read_strstr(int pid, bool thread, const char *item, const char *needle); extern pid_t clone_into_cgroup(int cgroup_fd); diff --git a/tools/testing/selftests/cgroup/test_memcontrol.c b/tools/testing/selftests/cgroup/test_memcontrol.c index 284d912e7d3e..d37e8dfb1248 100644 --- a/tools/testing/selftests/cgroup/test_memcontrol.c +++ b/tools/testing/selftests/cgroup/test_memcontrol.c @@ -21,6 +21,8 @@ #include "../kselftest.h" #include "cgroup_util.h" +static bool has_recursiveprot; + /* * This test creates two nested cgroups with and without enabling * the memory controller. @@ -521,15 +523,18 @@ static int test_memcg_low(const char *root) } for (i = 0; i < ARRAY_SIZE(children); i++) { + int no_low_events_index = has_recursiveprot ? 2 : 1; + oom = cg_read_key_long(children[i], "memory.events", "oom "); low = cg_read_key_long(children[i], "memory.events", "low "); if (oom) goto cleanup; - if (i < 2 && low <= 0) + if (i <= no_low_events_index && low <= 0) goto cleanup; - if (i >= 2 && low) + if (i > no_low_events_index && low) goto cleanup; + } ret = KSFT_PASS; @@ -1272,7 +1277,7 @@ struct memcg_test { int main(int argc, char **argv) { char root[PATH_MAX]; - int i, ret = EXIT_SUCCESS; + int i, proc_status, ret = EXIT_SUCCESS; if (cg_find_unified_root(root, sizeof(root))) ksft_exit_skip("cgroup v2 isn't mounted\n"); @@ -1288,6 +1293,11 @@ int main(int argc, char **argv) if (cg_write(root, "cgroup.subtree_control", "+memory")) ksft_exit_skip("Failed to set memory controller\n"); + proc_status = proc_mount_contains("memory_recursiveprot"); + if (proc_status < 0) + ksft_exit_skip("Failed to query cgroup mount option\n"); + has_recursiveprot = proc_status; + for (i = 0; i < ARRAY_SIZE(tests); i++) { switch (tests[i].fn(root)) { case KSFT_PASS: