From patchwork Fri Apr 22 15:57:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Vernet X-Patchwork-Id: 12823692 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 BA6E7C433FE for ; Fri, 22 Apr 2022 15:57:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2A9416B009A; Fri, 22 Apr 2022 11:57:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1BCBB6B009B; Fri, 22 Apr 2022 11:57:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F2A3D6B009C; Fri, 22 Apr 2022 11:57:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.25]) by kanga.kvack.org (Postfix) with ESMTP id E3F386B009A for ; Fri, 22 Apr 2022 11:57:48 -0400 (EDT) Received: from smtpin31.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id D2CE36044E for ; Fri, 22 Apr 2022 15:57:48 +0000 (UTC) X-FDA: 79384970616.31.F105A2E Received: from mail-qk1-f178.google.com (mail-qk1-f178.google.com [209.85.222.178]) by imf30.hostedemail.com (Postfix) with ESMTP id C25AA80028 for ; Fri, 22 Apr 2022 15:57:44 +0000 (UTC) Received: by mail-qk1-f178.google.com with SMTP id s4so6141151qkh.0 for ; Fri, 22 Apr 2022 08:57:48 -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=aDaj3HkD7Ew7tdcTEWHSkCTuHU/M0CNYAq9mxNhKvus=; b=r9QZTsuurtkrgw+NazTAGVCcfZgoQ2bfaPScc4DsgyM9Znr7RnVyvUJh9ZvnOe4/NO kO3kMCAcqH3ph+LMapJu4WemT4Fl/EBuJjY38q1AeG2pKqXzcScTAbNNU2dZ5BUdoSqX XGFiYO3Wq6XWc085UgJrrRDd2WL8JE5/n2nou4/4wPIauW2kKNPoWdVALMHkuHqxVhgX XToI5PSJl9P0Mo+/+xHk1xdU/GY/ZdGaS4/Q5HHDM4ltTnbsAaa3ypK+oZmgd2QwbhT7 JsPIrwi14sR6Vm+3MYAfLIKX6c3vCjn78V7yhWcjp3fwp2A5bimExTV+rplx9A046F1+ bgzA== X-Gm-Message-State: AOAM533hBFHeGsHZBnC31S8zf3ZHpXtkKYrDGu1g6Wjw3TtkpJBwD1kk 6ZqMzWTvAe2SS2wbMM9scbo= X-Google-Smtp-Source: ABdhPJxdpQ0/gfPFcucO+d4vBu70jsUM1ghhPvnLz+9s0jqGGhgmbNt0obYZb9aYdEZfurgxOdo+OA== X-Received: by 2002:a37:6412:0:b0:69e:68cf:d889 with SMTP id y18-20020a376412000000b0069e68cfd889mr2945289qkb.443.1650643067440; Fri, 22 Apr 2022 08:57:47 -0700 (PDT) Received: from localhost (fwdproxy-ash-013.fbsv.net. [2a03:2880:20ff:d::face:b00c]) by smtp.gmail.com with ESMTPSA id o21-20020a37a515000000b0069e6c84e8basm1066994qke.117.2022.04.22.08.57.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 08:57:47 -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 1/5] cgroups: Refactor children cgroups in memcg tests Date: Fri, 22 Apr 2022 08:57:25 -0700 Message-Id: <20220422155728.3055914-2-void@manifault.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220422155728.3055914-1-void@manifault.com> References: <20220422155728.3055914-1-void@manifault.com> MIME-Version: 1.0 X-Stat-Signature: qt66b537jc4dxghgdoai73i4jix8dr6y Authentication-Results: imf30.hostedemail.com; dkim=none; spf=pass (imf30.hostedemail.com: domain of dcvernet@gmail.com designates 209.85.222.178 as permitted sender) smtp.mailfrom=dcvernet@gmail.com; dmarc=none X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: C25AA80028 X-HE-Tag: 1650643064-291944 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: In test_memcg_min() and test_memcg_low(), there is an array of four sibling cgroups. All but one of these sibling groups does a 50MB allocation, and the group that does no allocation is the third of four in the array. This is not a problem per se, but makes it a bit tricky to do some assertions in test_memcg_low(), as we want to make assertions on the siblings based on whether or not they performed allocations. Having a static index before which all groups have performed an allocation makes this cleaner. This patch therefore reorders the sibling groups so that the group that performs no allocations is the last in the array. A follow-on patch will leverage this to fix a bug in the test that incorrectly asserts that a sibling group that had performed an allocation, but only had protection from its parent, will not observe any memory.events.low events during reclaim. Signed-off-by: David Vernet --- tools/testing/selftests/cgroup/test_memcontrol.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tools/testing/selftests/cgroup/test_memcontrol.c b/tools/testing/selftests/cgroup/test_memcontrol.c index 6b5259394e68..aa50eaa8b157 100644 --- a/tools/testing/selftests/cgroup/test_memcontrol.c +++ b/tools/testing/selftests/cgroup/test_memcontrol.c @@ -321,7 +321,7 @@ static int test_memcg_min(const char *root) if (cg_create(children[i])) goto cleanup; - if (i == 2) + if (i > 2) continue; cg_run_nowait(children[i], alloc_pagecache_50M_noexit, @@ -336,9 +336,9 @@ static int test_memcg_min(const char *root) goto cleanup; if (cg_write(children[1], "memory.min", "25M")) goto cleanup; - if (cg_write(children[2], "memory.min", "500M")) + if (cg_write(children[2], "memory.min", "0")) goto cleanup; - if (cg_write(children[3], "memory.min", "0")) + if (cg_write(children[3], "memory.min", "500M")) goto cleanup; attempts = 0; @@ -364,7 +364,7 @@ static int test_memcg_min(const char *root) if (!values_close(c[1], MB(17), 20)) goto cleanup; - if (!values_close(c[2], 0, 1)) + if (c[3] != 0) goto cleanup; if (!cg_run(parent[2], alloc_anon, (void *)MB(170))) @@ -476,7 +476,7 @@ static int test_memcg_low(const char *root) if (cg_create(children[i])) goto cleanup; - if (i == 2) + if (i > 2) continue; if (cg_run(children[i], alloc_pagecache_50M, (void *)(long)fd)) @@ -491,9 +491,9 @@ static int test_memcg_low(const char *root) goto cleanup; if (cg_write(children[1], "memory.low", "25M")) goto cleanup; - if (cg_write(children[2], "memory.low", "500M")) + if (cg_write(children[2], "memory.low", "0")) goto cleanup; - if (cg_write(children[3], "memory.low", "0")) + if (cg_write(children[3], "memory.low", "500M")) goto cleanup; if (cg_run(parent[2], alloc_anon, (void *)MB(148))) @@ -511,7 +511,7 @@ static int test_memcg_low(const char *root) if (!values_close(c[1], MB(17), 20)) goto cleanup; - if (!values_close(c[2], 0, 1)) + if (c[3] != 0) goto cleanup; if (cg_run(parent[2], alloc_anon, (void *)MB(166))) { From patchwork Fri Apr 22 15:57:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Vernet X-Patchwork-Id: 12823693 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 6662EC433EF for ; Fri, 22 Apr 2022 15:57:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2F83A6B009B; Fri, 22 Apr 2022 11:57:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2A8498D0002; Fri, 22 Apr 2022 11:57:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0AA7F6B009E; Fri, 22 Apr 2022 11:57:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.28]) by kanga.kvack.org (Postfix) with ESMTP id EF5296B009B for ; Fri, 22 Apr 2022 11:57:49 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id B933C60D11 for ; Fri, 22 Apr 2022 15:57:49 +0000 (UTC) X-FDA: 79384970658.30.4FE600E Received: from mail-qk1-f181.google.com (mail-qk1-f181.google.com [209.85.222.181]) by imf12.hostedemail.com (Postfix) with ESMTP id D908540027 for ; Fri, 22 Apr 2022 15:57:44 +0000 (UTC) Received: by mail-qk1-f181.google.com with SMTP id 204so6102666qkg.5 for ; Fri, 22 Apr 2022 08:57:49 -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=PW4Cfe3gzU2X2eLDy0jiTeoCDEUPxOU6OZ0vGj0GnXM=; b=SmNzBZZx8XbflX/aKrX1u956JuzJN4FjkkO6SSGmMmCwNO4lfySaLPthc+fEdvicc8 eZFaBE5CxlsC9zWuhCYFHbj3JzwYGiYUhdBn28hII/m4RI+tCTt9EU1JzV0IgjF5iyHg kSU3UXEIh7t8B4OV84Srxq0vRdcqTsUzs3d+Mg8qKGeZfC8tIhPxoPEujIWmn0BdG+nY sztT2ZCenJ8EaUUBhuAzP4fv3ibMrxPOCwCofPCrmUFp5JfBmsSS5mxBGWEZDwemt53G avfvlJ4JDwzhGcEg0e7mRBHXXntXYxpTAUoHHRipUI9fPWcwyibi2bjhizI2rgTCjGWQ RFpg== X-Gm-Message-State: AOAM530JOj0Tlhz/8RfaXrXU/GCvBSW4IX1gXdUeORrnYffiinE3aGVX Iqc0w852IS8w1+o3sKqheTc= X-Google-Smtp-Source: ABdhPJyEfzOz0NSA20V3QRqlGWasmD0qunKSxHvrm87XPTeHqJJF4oBixYgfEbw/V2EBnAT1jug/Bg== X-Received: by 2002:a05:620a:460a:b0:69e:de07:29c4 with SMTP id br10-20020a05620a460a00b0069ede0729c4mr3018498qkb.277.1650643068537; Fri, 22 Apr 2022 08:57:48 -0700 (PDT) Received: from localhost (fwdproxy-ash-010.fbsv.net. [2a03:2880:20ff:a::face:b00c]) by smtp.gmail.com with ESMTPSA id s136-20020a37a98e000000b0069f0c30c0d3sm1079741qke.21.2022.04.22.08.57.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 08:57:48 -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 2/5] cgroup: Account for memory_recursiveprot in test_memcg_low() Date: Fri, 22 Apr 2022 08:57:26 -0700 Message-Id: <20220422155728.3055914-3-void@manifault.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220422155728.3055914-1-void@manifault.com> References: <20220422155728.3055914-1-void@manifault.com> MIME-Version: 1.0 X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: D908540027 X-Stat-Signature: 8d6i1zwtd8djmwjg5c4k385tdkeh7r1u X-Rspam-User: Authentication-Results: imf12.hostedemail.com; dkim=none; spf=pass (imf12.hostedemail.com: domain of dcvernet@gmail.com designates 209.85.222.181 as permitted sender) smtp.mailfrom=dcvernet@gmail.com; dmarc=none X-HE-Tag: 1650643064-49699 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000020, 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 --- 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 aa50eaa8b157..ea2fd27e52df 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: From patchwork Fri Apr 22 15:57:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Vernet X-Patchwork-Id: 12823694 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 1A400C433F5 for ; Fri, 22 Apr 2022 15:57:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 280E76B009E; Fri, 22 Apr 2022 11:57:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 238A76B009F; Fri, 22 Apr 2022 11:57:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E65F76B00A0; Fri, 22 Apr 2022 11:57:50 -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 D12BF6B009E for ; Fri, 22 Apr 2022 11:57:50 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id AF155208AF for ; Fri, 22 Apr 2022 15:57:50 +0000 (UTC) X-FDA: 79384970700.27.C530C50 Received: from mail-qv1-f46.google.com (mail-qv1-f46.google.com [209.85.219.46]) by imf18.hostedemail.com (Postfix) with ESMTP id EA6051C0029 for ; Fri, 22 Apr 2022 15:57:47 +0000 (UTC) Received: by mail-qv1-f46.google.com with SMTP id b17so6317551qvf.12 for ; Fri, 22 Apr 2022 08:57:50 -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=B3B1dGnzOmkr3L8TkEmHq2fqLk42IndbueuBAtAlDZs=; b=jFWlhvPBTBAyS5KerO36UBpbLIAqoXGB/dEqZisvMRY10A+rxABrCaacZDkrwJJf6l Pa+2B2wb4eaxsjwca4czScmJKmDBzx8JLrY2hKw/r318JXxnbnad3DAnma/Qeudr9u/9 Gfprnc2C+5o+VWAiXjGHwoj+BEk24hji8HVFp+GzCyuns01AbPMGSZbQ5n3hjGmudti+ vVdj7mtQkcxaP+RSbTS5MFd3PCR+lGdRKJWonpNGsX739/iAap6s79B0A0ykm+1vqhRz S/fqIn0oygQp8aj3FF0BSaSoOnLn2Zpp8pzc8rchdFUgTqxZzcttzjnprlsPKR046L+6 FP/A== X-Gm-Message-State: AOAM533Msy5qHGO/JaRsceo9s7xzyTtUnAWlbLf0iF28JtYOxqQ4zBjz m5qmubhQ3IUlHsxf1nsPJPE= X-Google-Smtp-Source: ABdhPJwkKpkXUXCGxEyQQ7dOCDVgeo3GrLKYQUje6jc+8FcwPX60dYm6Q9j05eHfCzT3CfeDA+rTMQ== X-Received: by 2002:a05:6214:2a8e:b0:443:8a10:c1ca with SMTP id jr14-20020a0562142a8e00b004438a10c1camr3917627qvb.88.1650643069480; Fri, 22 Apr 2022 08:57:49 -0700 (PDT) Received: from localhost (fwdproxy-ash-011.fbsv.net. [2a03:2880:20ff:b::face:b00c]) by smtp.gmail.com with ESMTPSA id f11-20020a05620a12eb00b0069c88d15b6asm1043746qkl.68.2022.04.22.08.57.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 08:57:49 -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 3/5] cgroup: Account for memory_localevents in test_memcg_oom_group_leaf_events() Date: Fri, 22 Apr 2022 08:57:27 -0700 Message-Id: <20220422155728.3055914-4-void@manifault.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220422155728.3055914-1-void@manifault.com> References: <20220422155728.3055914-1-void@manifault.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: EA6051C0029 X-Stat-Signature: s9picsyh8eon7s6x1jd8ykeyx7kp4z7t Authentication-Results: imf18.hostedemail.com; dkim=none; spf=pass (imf18.hostedemail.com: domain of dcvernet@gmail.com designates 209.85.219.46 as permitted sender) smtp.mailfrom=dcvernet@gmail.com; dmarc=none X-HE-Tag: 1650643067-440397 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000091, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The test_memcg_oom_group_leaf_events() testcase in the cgroup memcg tests validates that processes in a group that perform allocations exceeding memory.oom.group are killed. It also validates that the memory.events.oom_kill events are properly propagated in this case. Commit 06e11c907ea4 ("kselftests: memcg: update the oom group leaf events test") fixed test_memcg_oom_group_leaf_events() to account for the fact that the memory.events.oom_kill events in a child cgroup is propagated up to its parent. This behavior can actually be configured by the memory_localevents mount option, so this patch updates the testcase to properly account for the possible presence of this mount option. Signed-off-by: David Vernet Acked-by: Roman Gushchin --- .../testing/selftests/cgroup/test_memcontrol.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/cgroup/test_memcontrol.c b/tools/testing/selftests/cgroup/test_memcontrol.c index ea2fd27e52df..d88e0ca3f3d1 100644 --- a/tools/testing/selftests/cgroup/test_memcontrol.c +++ b/tools/testing/selftests/cgroup/test_memcontrol.c @@ -21,6 +21,7 @@ #include "../kselftest.h" #include "cgroup_util.h" +static bool has_localevents; static bool has_recursiveprot; /* @@ -1091,6 +1092,7 @@ static int test_memcg_oom_group_leaf_events(const char *root) { int ret = KSFT_FAIL; char *parent, *child; + long parent_oom_events; parent = cg_name(root, "memcg_test_0"); child = cg_name(root, "memcg_test_0/memcg_test_1"); @@ -1128,7 +1130,15 @@ static int test_memcg_oom_group_leaf_events(const char *root) if (cg_read_key_long(child, "memory.events", "oom_kill ") <= 0) goto cleanup; - if (cg_read_key_long(parent, "memory.events", "oom_kill ") <= 0) + parent_oom_events = cg_read_key_long( + parent, "memory.events", "oom_kill "); + // If memory_localevents is not enabled (the default), the parent should + // count OOM events in its children groups. Otherwise, it should not + // have observed any events. + if (has_localevents) { + if (parent_oom_events != 0) + goto cleanup; + } else if (parent_oom_events <= 0) goto cleanup; ret = KSFT_PASS; @@ -1298,6 +1308,11 @@ int main(int argc, char **argv) ksft_exit_skip("Failed to query cgroup mount option\n"); has_recursiveprot = proc_status; + proc_status = proc_mount_contains("memory_localevents"); + if (proc_status < 0) + ksft_exit_skip("Failed to query cgroup mount option\n"); + has_localevents = proc_status; + for (i = 0; i < ARRAY_SIZE(tests); i++) { switch (tests[i].fn(root)) { case KSFT_PASS: From patchwork Fri Apr 22 15:57:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Vernet X-Patchwork-Id: 12823695 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 B083AC4332F for ; Fri, 22 Apr 2022 15:57:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1E5A76B009F; Fri, 22 Apr 2022 11:57:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 197406B00A0; Fri, 22 Apr 2022 11:57:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E662F6B00A1; Fri, 22 Apr 2022 11:57:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.25]) by kanga.kvack.org (Postfix) with ESMTP id D57D66B009F for ; Fri, 22 Apr 2022 11:57:51 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id B73361206EE for ; Fri, 22 Apr 2022 15:57:51 +0000 (UTC) X-FDA: 79384970742.05.81B5DDA Received: from mail-qk1-f178.google.com (mail-qk1-f178.google.com [209.85.222.178]) by imf21.hostedemail.com (Postfix) with ESMTP id 762A11C002A for ; Fri, 22 Apr 2022 15:57:49 +0000 (UTC) Received: by mail-qk1-f178.google.com with SMTP id 204so6102725qkg.5 for ; Fri, 22 Apr 2022 08:57:50 -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=SQtAE3ZcQpFqrp+bASWhDiZvk53BS0iYnbojqFdBn7s=; b=jdMWpnEkeYx9mMFGUkId7KjH5l3jMxC+xfnYCW3qsOeFPPTHEc46Km7pt1OmFyF0Mj GhKkZICUfwP1qd9erSbv24Bu8MtsP5RLQN1p/YYxkT8Z8y8GOW1GvD9sE0jzSSy0Vly3 4GghbPNSwt5Pvnyox7Zbda/n6Jn6tq3jzKeUVMzooU9Ev9zmPBgD+9aJK9oF/fc/bCwb N8TwKtsIHXPsG35vGV2CF54y/UaGTIzt8J8AiuD7l9tg+9cKsPoA00Uk7dkHfzGVQwDF QIMi/8aH59SCAKNYt31HBukkPQAzGKkujXsH2Y8bklK7DiGNFiD0t5UdfuxPD59WwNTd KP6Q== X-Gm-Message-State: AOAM531LvYSqSoxB9KTJW+GfPfMEFzcRv1/bD8U0k59M+58UusKLfR57 Dh8iPCRwLIPGp3t1rrySI2E= X-Google-Smtp-Source: ABdhPJyEzJRX9vnV3+Z6TRD9kwrLPpVaz5L36ZFL4C9MSpyDrjP37pubNs3ib3cwHPc3pShEIIcIkA== X-Received: by 2002:a37:987:0:b0:69e:927e:756f with SMTP id 129-20020a370987000000b0069e927e756fmr3142409qkj.699.1650643070358; Fri, 22 Apr 2022 08:57:50 -0700 (PDT) Received: from localhost (fwdproxy-ash-018.fbsv.net. [2a03:2880:20ff:12::face:b00c]) by smtp.gmail.com with ESMTPSA id e23-20020a05620a12d700b0069ec181a0b2sm1033549qkl.69.2022.04.22.08.57.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 08:57:50 -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 4/5] cgroup: Removing racy check in test_memcg_sock() Date: Fri, 22 Apr 2022 08:57:28 -0700 Message-Id: <20220422155728.3055914-5-void@manifault.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220422155728.3055914-1-void@manifault.com> References: <20220422155728.3055914-1-void@manifault.com> MIME-Version: 1.0 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 762A11C002A X-Stat-Signature: iy7ctozqyr6qgqu7g5fk9tkmecxmzdnz Authentication-Results: imf21.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf21.hostedemail.com: domain of dcvernet@gmail.com designates 209.85.222.178 as permitted sender) smtp.mailfrom=dcvernet@gmail.com X-Rspam-User: X-HE-Tag: 1650643069-997498 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: test_memcg_sock() in the cgroup memcg tests, verifies expected memory accounting for sockets. The test forks a process which functions as a TCP server, and sends large buffers back and forth between itself (as the TCP client) and the forked TCP server. While doing so, it verifies that memory.current and memory.stat.sock look correct. There is currently a check in tcp_client() which asserts memory.current >= memory.stat.sock. This check is racy, as between memory.current and memory.stat.sock being queried, a packet could come in which causes mem_cgroup_charge_skmem() to be invoked. This could cause memory.stat.sock to exceed memory.current. Reversing the order of querying doesn't address the problem either, as memory may be reclaimed between the two calls. Instead, this patch just removes that assertion altogether, and instead relies on the values_close() check that follows to validate the expected accounting. Signed-off-by: David Vernet Acked-by: Roman Gushchin --- tools/testing/selftests/cgroup/test_memcontrol.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/tools/testing/selftests/cgroup/test_memcontrol.c b/tools/testing/selftests/cgroup/test_memcontrol.c index d88e0ca3f3d1..c4735fa36a3d 100644 --- a/tools/testing/selftests/cgroup/test_memcontrol.c +++ b/tools/testing/selftests/cgroup/test_memcontrol.c @@ -993,9 +993,6 @@ static int tcp_client(const char *cgroup, unsigned short port) if (current < 0 || sock < 0) goto close_sk; - if (current < sock) - goto close_sk; - if (values_close(current, sock, 10)) { ret = KSFT_PASS; break; From patchwork Fri Apr 22 15:57:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Vernet X-Patchwork-Id: 12823696 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 A9C8BC433EF for ; Fri, 22 Apr 2022 15:57:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C6FDD6B00A1; Fri, 22 Apr 2022 11:57:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C1C7E6B00A2; Fri, 22 Apr 2022 11:57:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A20416B00A3; Fri, 22 Apr 2022 11:57:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.25]) by kanga.kvack.org (Postfix) with ESMTP id 8F01A6B00A1 for ; Fri, 22 Apr 2022 11:57:52 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 5F6C860CF2 for ; Fri, 22 Apr 2022 15:57:52 +0000 (UTC) X-FDA: 79384970784.01.5D8507E Received: from mail-qt1-f170.google.com (mail-qt1-f170.google.com [209.85.160.170]) by imf13.hostedemail.com (Postfix) with ESMTP id DE1D620031 for ; Fri, 22 Apr 2022 15:57:48 +0000 (UTC) Received: by mail-qt1-f170.google.com with SMTP id f14so5805378qtq.1 for ; Fri, 22 Apr 2022 08:57:51 -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=ybM2/MebbmHh9Uk+Civ8p2eG1e4lJfObLB1b9VYbOt0=; b=dURcLMDe6OjgAo56PrZgThUyPkdWnAzrGcsRDXkbuE+ZRSm/FqcX/pWOFdaL33osLw Vbjg6BtwnKMIUu6ru3u5sQXm7NzYOPSjDbO8idKD4WkCH6v7IvYm/GhD4x917LGlrTM6 ytGo91BWSt51AVTHVUzQA92F/DqFY33vmm8OkNtsfl/xSvmLuhUPAoeyVKSFL+QSnUAL X6OFcwq2sZOIOyRzczlgolIceT9uDDB/MWZpVnOq6c6JCzwqOp4PAA6sTR4/LSVZZLDS 5BtWbOoIL7rBOOrgf7QJxu//jUIyzEUJH+y5DhqO9f4fCJQW6hzx9I+mcHNbXxKcn8dj NGNg== X-Gm-Message-State: AOAM532uHx8dRpKNf7d0ORR2m5Y/Hyz4WcPzIn5uuSwJeOUzRUU/t/x3 FJ6Cu7NgAOa+g/1jTwA5BfU= X-Google-Smtp-Source: ABdhPJyMRR8Jr7rZxhR2OLWQ5M5A2n4MOa9OS2dQPPKnynJcD2a5ME2ySPAE1TYdGztolYD7YY14HQ== X-Received: by 2002:a05:622a:151:b0:2f1:fe9f:9177 with SMTP id v17-20020a05622a015100b002f1fe9f9177mr3762575qtw.628.1650643071259; Fri, 22 Apr 2022 08:57:51 -0700 (PDT) Received: from localhost (fwdproxy-ash-019.fbsv.net. [2a03:2880:20ff:13::face:b00c]) by smtp.gmail.com with ESMTPSA id c17-20020a05622a025100b002f34db6a3a2sm1543874qtx.4.2022.04.22.08.57.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 08:57:51 -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 5/5] cgroup: Fix racy check in alloc_pagecache_max_30M() helper function Date: Fri, 22 Apr 2022 08:57:29 -0700 Message-Id: <20220422155728.3055914-6-void@manifault.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220422155728.3055914-1-void@manifault.com> References: <20220422155728.3055914-1-void@manifault.com> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: DE1D620031 X-Rspam-User: Authentication-Results: imf13.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf13.hostedemail.com: domain of dcvernet@gmail.com designates 209.85.160.170 as permitted sender) smtp.mailfrom=dcvernet@gmail.com X-Stat-Signature: mz51bpim9fix5gb6bjk8ub471773nyb9 X-HE-Tag: 1650643068-84987 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000048, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 Acked-by: Roman Gushchin --- tools/testing/selftests/cgroup/test_memcontrol.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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;