From nobody Sun May 10 21:55:02 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 83859C433EF for ; Sat, 23 Apr 2022 15:57:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236194AbiDWQAH (ORCPT ); Sat, 23 Apr 2022 12:00:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236166AbiDWQAA (ORCPT ); Sat, 23 Apr 2022 12:00:00 -0400 Received: from mail-qt1-f175.google.com (mail-qt1-f175.google.com [209.85.160.175]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4AC21145; Sat, 23 Apr 2022 08:57:01 -0700 (PDT) Received: by mail-qt1-f175.google.com with SMTP id v2so927839qto.6; Sat, 23 Apr 2022 08:57:01 -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=mhe+ozq+IV2MAwRrDsZ/ZSWkxzhsnE8j2jwM5MH+fqc=; b=zZV3quggxejnjOnrsWlVA1DhXC+sVce67ifxZU/DbO+6mQf/MgGAVn4Ka61IEkV9xi 1NfqDLQr+aFImqTW8GNpthOFR1wLYbdPRor3vnMuTzS+FFCj3oQgcbl5tL/TkLbqEIKH y8gniPYKZ/rljx2Yr32uwcgIHXKWaHA2gvSc7OgMedLTBDt7kYjJV8IKleSa+WU+a26Z mBVtaTn2PM4EAnN4BQ49V0ZD9jmO/f7b6bJMfrpED2px0ll5tzggoNtfRkdbGPjh1rys zFel0sJG6bD6ZkugsY8U00cg7jtpFJPU+NqDNs3VCXt3Y0QZtDYhbfEmNiklTCgcgY9p stVA== X-Gm-Message-State: AOAM533wXp+pXLzU2Y16BbaQppdneN0wX9mP9XeiQPbViy6w+BSTlqgG Qox2jyjvMTZwuRKgAf0ynAw= X-Google-Smtp-Source: ABdhPJytoSPlwHitp9twoxnBZ7MxFhgDBzJwzRKymTJHRnKFhp6540h96jk3b/p131t+VpieODtcCw== X-Received: by 2002:a05:622a:342:b0:2f3:5c21:1bed with SMTP id r2-20020a05622a034200b002f35c211bedmr4829541qtw.123.1650729420904; Sat, 23 Apr 2022 08:57:00 -0700 (PDT) Received: from localhost (fwdproxy-ash-119.fbsv.net. [2a03:2880:20ff:77::face:b00c]) by smtp.gmail.com with ESMTPSA id a1-20020ac844a1000000b002f364521df2sm149742qto.21.2022.04.23.08.57.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Apr 2022 08:57:00 -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 1/5] cgroups: Refactor children cgroups in memcg tests Date: Sat, 23 Apr 2022 08:56:17 -0700 Message-Id: <20220423155619.3669555-2-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 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 Acked-by: Roman Gushchin --- .../selftests/cgroup/test_memcontrol.c | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/tools/testing/selftests/cgroup/test_memcontrol.c b/tools/testi= ng/selftests/cgroup/test_memcontrol.c index 6b5259394e68..284d912e7d3e 100644 --- a/tools/testing/selftests/cgroup/test_memcontrol.c +++ b/tools/testing/selftests/cgroup/test_memcontrol.c @@ -244,8 +244,8 @@ static int cg_test_proc_killed(const char *cgroup) * A/B memory.min =3D 50M, memory.current =3D 50M * A/B/C memory.min =3D 75M, memory.current =3D 50M * A/B/D memory.min =3D 25M, memory.current =3D 50M - * A/B/E memory.min =3D 500M, memory.current =3D 0 - * A/B/F memory.min =3D 0, memory.current =3D 50M + * A/B/E memory.min =3D 0, memory.current =3D 50M + * A/B/F memory.min =3D 500M, memory.current =3D 0 * * Usages are pagecache, but the test keeps a running * process in every leaf cgroup. @@ -255,7 +255,7 @@ static int cg_test_proc_killed(const char *cgroup) * A/B memory.current ~=3D 50M * A/B/C memory.current ~=3D 33M * A/B/D memory.current ~=3D 17M - * A/B/E memory.current ~=3D 0 + * A/B/F memory.current ~=3D 0 * * After that it tries to allocate more than there is * unprotected memory in A available, and checks @@ -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))) @@ -401,8 +401,8 @@ static int test_memcg_min(const char *root) * A/B memory.low =3D 50M, memory.current =3D 50M * A/B/C memory.low =3D 75M, memory.current =3D 50M * A/B/D memory.low =3D 25M, memory.current =3D 50M - * A/B/E memory.low =3D 500M, memory.current =3D 0 - * A/B/F memory.low =3D 0, memory.current =3D 50M + * A/B/E memory.low =3D 0, memory.current =3D 50M + * A/B/F memory.low =3D 500M, memory.current =3D 0 * * Usages are pagecache. * Then it creates A/G an creates a significant @@ -412,7 +412,7 @@ static int test_memcg_min(const char *root) * A/B memory.current ~=3D 50M * A/B/ memory.current ~=3D 33M * A/B/D memory.current ~=3D 17M - * A/B/E memory.current ~=3D 0 + * A/B/F memory.current ~=3D 0 * * After that it tries to allocate more than there is * unprotected memory in A available, @@ -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:55:02 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 D65E9C433EF for ; Sat, 23 Apr 2022 15:57:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236212AbiDWQAP (ORCPT ); Sat, 23 Apr 2022 12:00:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236188AbiDWQAJ (ORCPT ); Sat, 23 Apr 2022 12:00:09 -0400 Received: from mail-qv1-f48.google.com (mail-qv1-f48.google.com [209.85.219.48]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8050921A4; Sat, 23 Apr 2022 08:57:11 -0700 (PDT) Received: by mail-qv1-f48.google.com with SMTP id kk26so456435qvb.6; 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=TNApHOUFp29vFX7xQvUjZvtiR8cuXrP5PFwpwJE8Qy/uKuNh1RfOylEF2KJekdY7SE +7uMgmyGjTCeTZTdijTN+BviJs7NMCsJV83LaZ60hrX9CDw/oOtQxzJW7ZUI/fPVy+Ld TrTPIHw4OeCn0QW8sLa+wfKScuNyvpLFEXfs/8PW/s9oGVznPODaYyCv9+irGmLF+s88 UvhPnI49TBJZgmEcCoeJJRW2U75I850kzdhosGwLqLbx0/DacUE+koIMeqb9yu2oRmNQ w5simRdiOPW7fsxs7eczfVWHqVn9EJyz3U0+kL8mJGa4qOwIcinfz2J6PMGZ8x/1i/ca 9jig== X-Gm-Message-State: AOAM530r0yU0RYPkiyTH6tPdHsHlYuTFkTPjrvHukmsiKH/TkY8wujxj qnIZqG+52yayVxVi+xvIWuk= 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 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 Reported-by: Richard Palethorpe --- 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 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" =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:55:02 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 E2357C433EF for ; Sat, 23 Apr 2022 15:57:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236230AbiDWQAi (ORCPT ); Sat, 23 Apr 2022 12:00:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236185AbiDWQAJ (ORCPT ); Sat, 23 Apr 2022 12:00:09 -0400 Received: from mail-qt1-f180.google.com (mail-qt1-f180.google.com [209.85.160.180]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79955115D; Sat, 23 Apr 2022 08:57:12 -0700 (PDT) Received: by mail-qt1-f180.google.com with SMTP id hf18so7622929qtb.0; Sat, 23 Apr 2022 08:57:12 -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=3Tpzhq0+TI5H5bdvK5Vbm+VLYv/+B/98xqWutaPHg68=; b=YalIeLBAMpRNzq8xlnQ2CIEV933BYDUGRMwJlLIrAfPD5SjOv77i8IYwxj3s9JBJYr OKgnL3MJxmopPCgecn9FLF76gXTfJFzDCZFPVu1HUrW5N7RClSB9/Cn3cXI7u4ppdeGq 7vPkNDWpvExDHO/fsz4OBoYkgdduEXQKJi49PaOUi6nt2uRl4HEWFGjO1wkVZYYnnxQj GR0kK5qKwE4sYVmx+WrkSCiBGNzxU6TBpuOx5rQd8JFMNjQnDRtm/2scq2Q9HKSlUEt9 54OYRPOQhqm7P9XxFLnqLGKqo7XWPVQ4N9QNTaffaKufAbUpljlYaiMnbFLCWL4N7ycy awJg== X-Gm-Message-State: AOAM531E6Uv/D2C2hd9bU7qcQNdC+xhcXdjUO2bPmEkqVtp3mWiBLydA FoP4JU19Cs4expT117FgOGU= X-Google-Smtp-Source: ABdhPJy3crThvLR/oO0Mz5YJCL0+y4Sy/Jx7i2E9UGDNE2Y8oLiSfFfMWXH4+Nf8j3wVjv8GhAHcBA== X-Received: by 2002:ac8:7a8a:0:b0:2f1:de6a:c044 with SMTP id x10-20020ac87a8a000000b002f1de6ac044mr6873334qtr.243.1650729431500; Sat, 23 Apr 2022 08:57:11 -0700 (PDT) Received: from localhost (fwdproxy-ash-006.fbsv.net. [2a03:2880:20ff:6::face:b00c]) by smtp.gmail.com with ESMTPSA id w15-20020ac857cf000000b002f33f220c76sm2959583qta.32.2022.04.23.08.57.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Apr 2022 08:57:11 -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 3/5] cgroup: Account for memory_localevents in test_memcg_oom_group_leaf_events() Date: Sat, 23 Apr 2022 08:56:20 -0700 Message-Id: <20220423155619.3669555-4-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 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 --- .../selftests/cgroup/test_memcontrol.c | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/cgroup/test_memcontrol.c b/tools/testi= ng/selftests/cgroup/test_memcontrol.c index d37e8dfb1248..e899b3f28c22 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,10 +1130,16 @@ static int test_memcg_oom_group_leaf_events(const c= har *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) - goto cleanup; - - ret =3D KSFT_PASS; + 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 && parent_oom_events =3D=3D 0) || + parent_oom_events > 0) + ret =3D KSFT_PASS; =20 cleanup: if (child) @@ -1298,6 +1306,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:55:02 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 2C9A3C433EF for ; Sat, 23 Apr 2022 15:57:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236235AbiDWQAl (ORCPT ); Sat, 23 Apr 2022 12:00:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236196AbiDWQAM (ORCPT ); Sat, 23 Apr 2022 12:00:12 -0400 Received: from mail-qt1-f182.google.com (mail-qt1-f182.google.com [209.85.160.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40704260F; Sat, 23 Apr 2022 08:57:13 -0700 (PDT) Received: by mail-qt1-f182.google.com with SMTP id f22so7573996qtp.13; Sat, 23 Apr 2022 08:57:13 -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=feBO+KbcIht+BPtu2AkAQpokc7FT3Bt17XhQc38rY6I=; b=Joa6bmM+0gvNBp9oBUlhTxR8ZPxs/9eAbHbOEsWovmEaQHfNDnOVwPcKDPfCcCuxdy 76oFJIQ+bW95H9niQwNAoIIFCCWUNb3bCeTjXcgAPog8cBZ6EdlpLNlklbX8Fgm/BqTQ gU9Uauzrf3O3q+ns4PTxeQRLidvplH0lf6jjny8dUmVCsePCpcl3pBUd87HtLnzLMmgd cCwZIoE2+X1k23EeBJe8QLxH4w1vZatcyGArDZp94Zj7NaZXzBcrj9fbU8WJrOu2odLC Ko82xmphao59BHrycD4/45q+/4A4/eNnzOGP5ONwlSguoFvLOEl0x3Cx7OYNcdj0LHzP zt5A== X-Gm-Message-State: AOAM532JEMmGhtk67ka1LX3072PcPr07zvR6wN7lwnsBfsuQQACmdWm3 RnTHmHyERML1KqKEc14saVk= X-Google-Smtp-Source: ABdhPJxIXud5TfSFIhMm/UhJy9PJtx0SRoz2tqQh0wV2kl2SWYF7ZeJPEXsR6zpNHVRdizGPzQIUjw== X-Received: by 2002:ac8:5956:0:b0:2f2:521:7195 with SMTP id 22-20020ac85956000000b002f205217195mr6834676qtz.409.1650729432349; Sat, 23 Apr 2022 08:57:12 -0700 (PDT) Received: from localhost (fwdproxy-ash-014.fbsv.net. [2a03:2880:20ff:e::face:b00c]) by smtp.gmail.com with ESMTPSA id i68-20020a375447000000b006809e0adfffsm2529753qkb.25.2022.04.23.08.57.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Apr 2022 08:57:12 -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 4/5] cgroup: Removing racy check in test_memcg_sock() Date: Sat, 23 Apr 2022 08:56:21 -0700 Message-Id: <20220423155619.3669555-5-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 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 e899b3f28c22..38d2054eefe6 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:55:02 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 E39A8C433F5 for ; Sat, 23 Apr 2022 15:57:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236225AbiDWQAe (ORCPT ); Sat, 23 Apr 2022 12:00:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236193AbiDWQAM (ORCPT ); Sat, 23 Apr 2022 12:00:12 -0400 Received: from mail-qk1-f171.google.com (mail-qk1-f171.google.com [209.85.222.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53A4D2626; Sat, 23 Apr 2022 08:57:14 -0700 (PDT) Received: by mail-qk1-f171.google.com with SMTP id b68so7960491qkc.4; Sat, 23 Apr 2022 08:57:14 -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=gmXNl4tIfL5wRbTrjuvKfaCU9MK0lOXp83omTUSrSMo=; b=RqYcKbwdqymvvBUcZsqs2449ogL1+J5xlvDJt3JhwCZln//N/ASrDT/R/AsaDi4r5W cIyOVCbsVpPi/SMbtnKam77lZMmMXxm9wLpnJBdJi/HllZEC2KQiJYrGcW17reB32E54 ku+/2abwX9sE/cQp5p7y95LwjCInYWf/PuEm1+9jJa8GmEgcnvTCIx7C246S0wt0brbM IJgdz59Ydq00nA13w6Mblr78h/uNX+FOOUhhm3rqqL+/dIC/t5+7RfKdrIdBRQy6/lWA 8jl+qDzgEVcBy2wNfZ9eccDkleiFjXgCCdLv9JKEJntYEOhy5LTMNg+nvHMOpmhSXgD5 x2tw== X-Gm-Message-State: AOAM530fcqYnQojJzgxWl3pQ39U0MPI9ieIcXsNi8GwxbBLydcYne6SW W7onRlfVvmLEvZOoX0OFoic= X-Google-Smtp-Source: ABdhPJxrka55ASWkCj+31Zq8g/DCOT2vSRE9a3/Q38M+L6ijF+65YD0/feALRFzYTD/HSx0KMyH5Rg== X-Received: by 2002:a05:620a:2588:b0:680:f657:fbd6 with SMTP id x8-20020a05620a258800b00680f657fbd6mr5649398qko.287.1650729433397; Sat, 23 Apr 2022 08:57:13 -0700 (PDT) Received: from localhost (fwdproxy-ash-119.fbsv.net. [2a03:2880:20ff:77::face:b00c]) by smtp.gmail.com with ESMTPSA id w4-20020a05620a0e8400b0067b1bcd081csm2321762qkm.66.2022.04.23.08.57.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Apr 2022 08:57:13 -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 5/5] cgroup: Fix racy check in alloc_pagecache_max_30M() helper function Date: Sat, 23 Apr 2022 08:56:22 -0700 Message-Id: <20220423155619.3669555-6-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 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 38d2054eefe6..3bac06999354 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