From nobody Sun May 10 21:54:57 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D7A3FC433EF for ; Fri, 22 Apr 2022 15:57:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1449640AbiDVQAu (ORCPT ); Fri, 22 Apr 2022 12:00:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381209AbiDVQAm (ORCPT ); Fri, 22 Apr 2022 12:00:42 -0400 Received: from mail-qk1-f170.google.com (mail-qk1-f170.google.com [209.85.222.170]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A37475DA6E; Fri, 22 Apr 2022 08:57:48 -0700 (PDT) Received: by mail-qk1-f170.google.com with SMTP id d19so6104293qko.3; 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=ZTRR8ZyJg0/xKhY+1K/lXzFZh+gjLPLsRYyoLIfe9ix7pYCQNqLMLYIRxebWhsMI3u Zrsii/M940gIHnCWkY+4fQ26cJRHD89LNGC6kQ8ueZuoPeuMYmX+3Nfk84mt9Zjqaaxh iKr/pqLPFmgmxyaxw4Gyrjxqd3C7MOr82jeiAiZCwUkiyXR/wTLnKk16BG+zaxucmOkc GnXP4gOgdfm1CxzsevU5vohk5r6WNZRravNwFVyQU7uyafzHnGt3nzaKnn/jo2brpglq N7ZWSfpJQ8s0mHiQgiCy+rpNCgql7o+z1ZdrHdnNSfmsFM+WEzdKnbDGpCSXsiZC7EtM okQA== X-Gm-Message-State: AOAM532xVYuO52+k9/hiv/qeWWKez9bqqaJpOEGBnMn+lnKYl91Z3ZIN icedKSeEl06jnhBbCkchR2Y= 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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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/testi= ng/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; =20 - if (i =3D=3D 2) + if (i > 2) continue; =20 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; =20 attempts =3D 0; @@ -364,7 +364,7 @@ static int test_memcg_min(const char *root) if (!values_close(c[1], MB(17), 20)) goto cleanup; =20 - if (!values_close(c[2], 0, 1)) + if (c[3] !=3D 0) goto cleanup; =20 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; =20 - if (i =3D=3D 2) + if (i > 2) continue; =20 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; =20 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; =20 - if (!values_close(c[2], 0, 1)) + if (c[3] !=3D 0) goto cleanup; =20 if (cg_run(parent[2], alloc_anon, (void *)MB(166))) { --=20 2.30.2 From nobody Sun May 10 21:54:57 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C2654C433F5 for ; Fri, 22 Apr 2022 15:58:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1449666AbiDVQA5 (ORCPT ); Fri, 22 Apr 2022 12:00:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1445256AbiDVQAo (ORCPT ); Fri, 22 Apr 2022 12:00:44 -0400 Received: from mail-qk1-f181.google.com (mail-qk1-f181.google.com [209.85.222.181]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD4C75DA74; Fri, 22 Apr 2022 08:57:49 -0700 (PDT) Received: by mail-qk1-f181.google.com with SMTP id c1so6070291qkf.13; 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=qQmv8Zl/8vm3BB+HY4FmWdQk9xvLjNVtehdtbAjM6pBjtBWMxjdfJX6fiDgZcCvN8s YTFywQkuBKDld0/Pq39pW7uJDtHMFC6eDw5x/MDY+lKonmRfCME9AumMPJzciNOthWuE eo3ucRUOVymhIh4ThxdDHxW7YgcRxw7rN/R4w6xydOdWkQwr2YITjhIkON3zGeWdz5Y0 ruPO4pPsUJABIdguUauqwaqjjAOpIu5i27rBAI+FlsMdGlUSBOFPWaTe0Mb7lb+bvXjt VchYlWt+XY2PTIgyt9el5e1nHelipq4+IBHtCuG0Ad0DP7+EokHdZmuwRprvLysMxCMX x5xA== X-Gm-Message-State: AOAM533MI6qR2ZIkVc9pz1QsJkRN/9eeMx4yDJj84K+EXDmsHjV72Uqj zPZlg2iAkni0+kBXSzurVSU= 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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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/s= elftests/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; } =20 +int proc_mount_contains(const char *option) +{ + char buf[4 * PAGE_SIZE]; + ssize_t read; + + read =3D read_text("/proc/mounts", buf, sizeof(buf)); + if (read < 0) + return read; + + return strstr(buf, option) !=3D 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/s= elftests/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/testi= ng/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" =20 +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) } =20 for (i =3D 0; i < ARRAY_SIZE(children); i++) { + int no_low_events_index =3D has_recursiveprot ? 2 : 1; + oom =3D cg_read_key_long(children[i], "memory.events", "oom "); low =3D cg_read_key_long(children[i], "memory.events", "low "); =20 if (oom) goto cleanup; - if (i < 2 && low <=3D 0) + if (i <=3D no_low_events_index && low <=3D 0) goto cleanup; - if (i >=3D 2 && low) + if (i > no_low_events_index && low) goto cleanup; + } =20 ret =3D KSFT_PASS; @@ -1272,7 +1277,7 @@ struct memcg_test { int main(int argc, char **argv) { char root[PATH_MAX]; - int i, ret =3D EXIT_SUCCESS; + int i, proc_status, ret =3D EXIT_SUCCESS; =20 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"); =20 + proc_status =3D proc_mount_contains("memory_recursiveprot"); + if (proc_status < 0) + ksft_exit_skip("Failed to query cgroup mount option\n"); + has_recursiveprot =3D proc_status; + for (i =3D 0; i < ARRAY_SIZE(tests); i++) { switch (tests[i].fn(root)) { case KSFT_PASS: --=20 2.30.2 From nobody Sun May 10 21:54:57 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7E124C433F5 for ; Fri, 22 Apr 2022 15:58:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1449672AbiDVQBA (ORCPT ); Fri, 22 Apr 2022 12:01:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1445236AbiDVQAo (ORCPT ); Fri, 22 Apr 2022 12:00:44 -0400 Received: from mail-qv1-f46.google.com (mail-qv1-f46.google.com [209.85.219.46]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F72D5DA7D; Fri, 22 Apr 2022 08:57:50 -0700 (PDT) Received: by mail-qv1-f46.google.com with SMTP id kj29so1732538qvb.8; 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=n6qQIsjGcz8EUS1w/9x585HqxDwKbOrOzYf9+ohpG/Iylj4DfCp6Dnmj6hr1D+iOzt 2TDoX8/jpW5v/WErpRxJ6ZCZ+Ke83aXylH4/Rppg9C+iU8DT8eQDMlsf3ail4lPMuMGS qm6NJwt92L6KrXpWBZGnVeU6ISXaOojm7Xx6IJwra9Iqd8i0AmcR6l9Zf4L2gUB3d8ep F72mhsiJz8yZdzE/b3EQpB496KRrwKCN6A3ZkzFJxFPR2QuNtUhHLxPJVEjVeI2a+UK2 l25k38gl0juczRdFI3E0e6/H7jyrd33Pt4bodmsLyesm5eH2mir3kXgT8shQj6oO1/yZ 3AGw== X-Gm-Message-State: AOAM533d/jPnewfBJE3EhPjWuMe5PAdtX2jPEZlprx1plYSG4abJxeIV Lr3HT2vePNF3sw/dGd7fI3w= 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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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/testi= ng/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" =20 +static bool has_localevents; static bool has_recursiveprot; =20 /* @@ -1091,6 +1092,7 @@ static int test_memcg_oom_group_leaf_events(const cha= r *root) { int ret =3D KSFT_FAIL; char *parent, *child; + long parent_oom_events; =20 parent =3D cg_name(root, "memcg_test_0"); child =3D cg_name(root, "memcg_test_0/memcg_test_1"); @@ -1128,7 +1130,15 @@ static int test_memcg_oom_group_leaf_events(const ch= ar *root) if (cg_read_key_long(child, "memory.events", "oom_kill ") <=3D 0) goto cleanup; =20 - if (cg_read_key_long(parent, "memory.events", "oom_kill ") <=3D 0) + parent_oom_events =3D 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 !=3D 0) + goto cleanup; + } else if (parent_oom_events <=3D 0) goto cleanup; =20 ret =3D KSFT_PASS; @@ -1298,6 +1308,11 @@ int main(int argc, char **argv) ksft_exit_skip("Failed to query cgroup mount option\n"); has_recursiveprot =3D proc_status; =20 + proc_status =3D proc_mount_contains("memory_localevents"); + if (proc_status < 0) + ksft_exit_skip("Failed to query cgroup mount option\n"); + has_localevents =3D proc_status; + for (i =3D 0; i < ARRAY_SIZE(tests); i++) { switch (tests[i].fn(root)) { case KSFT_PASS: --=20 2.30.2 From nobody Sun May 10 21:54:57 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2C263C433F5 for ; Fri, 22 Apr 2022 15:58:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1449660AbiDVQAy (ORCPT ); Fri, 22 Apr 2022 12:00:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1444635AbiDVQAo (ORCPT ); Fri, 22 Apr 2022 12:00:44 -0400 Received: from mail-qk1-f177.google.com (mail-qk1-f177.google.com [209.85.222.177]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F41C5DA6E; Fri, 22 Apr 2022 08:57:51 -0700 (PDT) Received: by mail-qk1-f177.google.com with SMTP id d19so6104392qko.3; 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=SQtAE3ZcQpFqrp+bASWhDiZvk53BS0iYnbojqFdBn7s=; b=pUjL1i8FFKphbX3iLrEFzRe2/oR2hgqiTKaefu4wZn8iGy41GnogA69Drqw75RHLA9 oVuJ3MvA7U4NCea6LQzpVHoKL6oQVvv9OAEXDg9+Fx1h/BBrKhp9m3AllcGgPgX9hrLu bp8098AD2I8S2SjUne27p3UizmsYi1wDUkYUPt/jju86dwbpf1FU6KdLCM2MwPpjQpLz IQ46RP9PW5MhP473tLGqLYmCuxfOkE6E4uOO3GzYE68I+/C89v/W3300ssKgtelg92tv Rv3FqlGMVHE9LmftXi8LkVrEXcaZUwaFimvN41VlqM7Y7Zqj0mFpk/Xkc89E8//OO/I4 dVQw== X-Gm-Message-State: AOAM530X5HrPKHw+aCjiSIJZkK/THfeTEuYfbwEuGCHIZcyuzp2cAQSQ DIN5NJEFtYs1KlLyRTHJ+SP6uqnkcrOXNg== 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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 >= =3D 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/testi= ng/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 shor= t port) if (current < 0 || sock < 0) goto close_sk; =20 - if (current < sock) - goto close_sk; - if (values_close(current, sock, 10)) { ret =3D KSFT_PASS; break; --=20 2.30.2 From nobody Sun May 10 21:54:57 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E670CC433F5 for ; Fri, 22 Apr 2022 15:58:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1449677AbiDVQBF (ORCPT ); Fri, 22 Apr 2022 12:01:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1387797AbiDVQAq (ORCPT ); Fri, 22 Apr 2022 12:00:46 -0400 Received: from mail-qt1-f181.google.com (mail-qt1-f181.google.com [209.85.160.181]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 394AF5DA7E; Fri, 22 Apr 2022 08:57:52 -0700 (PDT) Received: by mail-qt1-f181.google.com with SMTP id ay11so5792186qtb.4; Fri, 22 Apr 2022 08:57:52 -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=RMnclBJpofBE2r8P2miIAfi/VDQE7JgeJUsa+zGbk2fMfn1c+T3FkSjluxfia5EX0i w/Aexa9TzXzNliEV2dt36Jgo3gohyQ/ttWjSvh8NZBGmLxPn/ZQj7yBqGVkiFbrR1nQZ NMuJiqiPUy/6f/lxBOUyj/4f5BHs44z3qAab0xRXzj4qtJzIDghJS7lRkFPPpgzy3l5n PlXtN9XxI2WtGnltoewmvr8yyct7rHDYZtQpNSQOh1oY+OVy3ihPQprBMwPr5PRh2/qU PZI7C1NdYbkY81lIYe0VJVTGmvpXNX+gb7sFxQsoRf452msJYSEAISDmJ5CLl36Jv7UM 3ZlQ== X-Gm-Message-State: AOAM531CBKz+5UwLaxCkXzd32kTDefRtawAmb2514NPziJHQ9/dCOd4Z tj58qfYw3HTNmYn8ag+SRVQ= 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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 <= =3D 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/testi= ng/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 =3D MB(50); int ret =3D -1; - long current; + long current, high, max; int fd; =20 + high =3D cg_read_long(cgroup, "memory.high"); + max =3D cg_read_long(cgroup, "memory.max"); + if (high !=3D MB(30) && max !=3D MB(30)) + goto cleanup; + fd =3D 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; =20 current =3D cg_read_long(cgroup, "memory.current"); - if (current <=3D MB(29) || current > MB(30)) + if (!values_close(current, MB(30), 5)) goto cleanup; =20 ret =3D 0; --=20 2.30.2