From patchwork Mon Feb 7 14:16:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Palethorpe X-Patchwork-Id: 1589304 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.com header.i=@suse.com header.a=rsa-sha256 header.s=susede1 header.b=kyb5rXUi; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Jsp9W3MNyz9s8q for ; Tue, 8 Feb 2022 01:16:47 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 2014C3C9B2B for ; Mon, 7 Feb 2022 15:16:45 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-3.smtp.seeweb.it (in-3.smtp.seeweb.it [IPv6:2001:4b78:1:20::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 9C7783C0720 for ; Mon, 7 Feb 2022 15:16:33 +0100 (CET) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-3.smtp.seeweb.it (Postfix) with ESMTPS id 2B9E61A0014C for ; Mon, 7 Feb 2022 15:16:33 +0100 (CET) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id BE658210FE; Mon, 7 Feb 2022 14:16:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1644243392; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=me+7zoVKJp0HYLI4nnapXPAFKVGzKYBf/9XVFM15OaM=; b=kyb5rXUijkoQrvZLLxEPxKZIy0qeJqMBGFUs4jcjNuhYZU21ROmWw9ezuUIgVijDmTmquw pBDsFybEZybkmfm9Bj/FD8belCokAT2hq+g0henPfAyPlXfk3lo1GTKAPkzx77jvl3mgYG ygoXe6q3SaU+ovxaAQAwExDZxjAXkeo= Received: from g78.suse.de (unknown [10.163.24.138]) by relay2.suse.de (Postfix) with ESMTP id ECFA8A3B81; Mon, 7 Feb 2022 14:16:31 +0000 (UTC) To: ltp@lists.linux.it Date: Mon, 7 Feb 2022 14:16:14 +0000 Message-Id: <20220207141618.2844-2-rpalethorpe@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220207141618.2844-1-rpalethorpe@suse.com> References: <20220207141618.2844-1-rpalethorpe@suse.com> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-3.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-3.smtp.seeweb.it Subject: [LTP] [PATCH v3 1/5] memcontrol: Lift out some common definitions into a shared header X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Richard Palethorpe via ltp From: Richard Palethorpe Reply-To: Richard Palethorpe Cc: Richard Palethorpe Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Some simple functions can be shared between tests. The original selftests share a bit more. However this doesn't make as much sense in LTP due to library differences. Signed-off-by: Richard Palethorpe Reviewed-by: Cyril Hrubis Reviewed-by: Li Wang --- .../kernel/controllers/memcg/memcontrol02.c | 32 +------------ .../controllers/memcg/memcontrol_common.h | 48 +++++++++++++++++++ 2 files changed, 49 insertions(+), 31 deletions(-) create mode 100644 testcases/kernel/controllers/memcg/memcontrol_common.h diff --git a/testcases/kernel/controllers/memcg/memcontrol02.c b/testcases/kernel/controllers/memcg/memcontrol02.c index 548f36829..d5a24cc0a 100644 --- a/testcases/kernel/controllers/memcg/memcontrol02.c +++ b/testcases/kernel/controllers/memcg/memcontrol02.c @@ -23,14 +23,7 @@ */ #define _GNU_SOURCE -#include -#include - -#include "tst_test.h" -#include "tst_cgroup.h" - -#define TMPDIR "mntdir" -#define MB(x) (x << 20) +#include "memcontrol_common.h" static size_t page_size; static const struct tst_cgroup_group *cg_test; @@ -38,20 +31,6 @@ static struct tst_cgroup_group *cg_child; static int fd; static int file_to_all_error = 10; -/* - * Checks if two given values differ by less than err% of their - * sum. An extra percent is added for every doubling of the page size - * to compensate for wastage in page sized allocations. - */ -static inline int values_close(const ssize_t a, - const ssize_t b, - const ssize_t err) -{ - const ssize_t page_adjusted_err = ffs(page_size >> 13) + err; - - return 100 * labs(a - b) <= (a + b) * page_adjusted_err; -} - static void alloc_anon_50M_check(void) { const ssize_t size = MB(50); @@ -78,15 +57,6 @@ static void alloc_anon_50M_check(void) current, anon); } -static void alloc_pagecache(const int fd, size_t size) -{ - char buf[BUFSIZ]; - size_t i; - - for (i = 0; i < size; i += sizeof(buf)) - SAFE_WRITE(1, fd, buf, sizeof(buf)); -} - static void alloc_pagecache_50M_check(void) { const size_t size = MB(50); diff --git a/testcases/kernel/controllers/memcg/memcontrol_common.h b/testcases/kernel/controllers/memcg/memcontrol_common.h new file mode 100644 index 000000000..67f3ca318 --- /dev/null +++ b/testcases/kernel/controllers/memcg/memcontrol_common.h @@ -0,0 +1,48 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include + +#include "tst_test.h" +#include "tst_cgroup.h" + +#define TMPDIR "mntdir" +#define MB(x) (x << 20) + +/* + * Checks if two given values differ by less than err% of their + * sum. An extra percent is added for every doubling of the page size + * to compensate for wastage in page sized allocations. + */ +static inline int values_close(const ssize_t a, + const ssize_t b, + const ssize_t err) +{ + const size_t page_size = SAFE_SYSCONF(_SC_PAGESIZE); + const ssize_t page_adjusted_err = ffs(page_size >> 13) + err; + + return 100 * labs(a - b) <= (a + b) * page_adjusted_err; +} + +static inline void alloc_pagecache(const int fd, size_t size) +{ + char buf[BUFSIZ]; + size_t i; + + SAFE_LSEEK(fd, 0, SEEK_END); + + for (i = 0; i < size; i += sizeof(buf)) + SAFE_WRITE(1, fd, buf, sizeof(buf)); +} + +static inline void alloc_anon(const size_t size) +{ + const size_t page_size = SAFE_SYSCONF(_SC_PAGESIZE); + char *const buf = SAFE_MALLOC(size); + size_t i; + + for (i = 0; i < size; i += page_size) + buf[i] = 0; + + free(buf); +} From patchwork Mon Feb 7 14:16:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Palethorpe X-Patchwork-Id: 1589308 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.com header.i=@suse.com header.a=rsa-sha256 header.s=susede1 header.b=SH/wDwSR; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JspBG5hD3z9s8q for ; Tue, 8 Feb 2022 01:17:26 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id C566C3C9B10 for ; Mon, 7 Feb 2022 15:17:24 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-6.smtp.seeweb.it (in-6.smtp.seeweb.it [217.194.8.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id AC8CE3C9B18 for ; Mon, 7 Feb 2022 15:16:38 +0100 (CET) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-6.smtp.seeweb.it (Postfix) with ESMTPS id 616121400B89 for ; Mon, 7 Feb 2022 15:16:36 +0100 (CET) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id A94851F386; Mon, 7 Feb 2022 14:16:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1644243395; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GPoTa0NUBFn4H/Yq8yKgYxfRX59YcjJMtp/Gzf/3KAw=; b=SH/wDwSRPo2rugDfn8pAYxzMFmPfgeBlfOGhWIqrfUE9h8jMzsvCZKNgp2sfeCi6OI+sfL Apo3j57pTqvTQIu/Uk3tXzGEuQtkIMZ9OLb7y4xOLjdpvjC0lH7uk1ZWQhOxSxHlDaIGVt M2dwTNj90arSm4xsqlk+NxlwUNe+Y1U= Received: from g78.suse.de (unknown [10.163.24.138]) by relay2.suse.de (Postfix) with ESMTP id 71517A3B94; Mon, 7 Feb 2022 14:16:33 +0000 (UTC) To: ltp@lists.linux.it Date: Mon, 7 Feb 2022 14:16:15 +0000 Message-Id: <20220207141618.2844-3-rpalethorpe@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220207141618.2844-1-rpalethorpe@suse.com> References: <20220207141618.2844-1-rpalethorpe@suse.com> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-6.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-6.smtp.seeweb.it Subject: [LTP] [PATCH v3 2/5] API/cgroup: Declare required controllers and version in test struct X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Richard Palethorpe via ltp From: Richard Palethorpe Reply-To: Richard Palethorpe Cc: Richard Palethorpe Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" This allows the test author to declaratively specify the required CGroup controllers in struct tst_test. Also they can optionally specify the CGroup API version. In some cases this removes any need for a setup function. It also adds CGroup information to the meta-data. In theory its possible to require that only one controller is on a particular version while others are free to be on any. Currently this would still need to be handled by calling tst_cgroup_require() and checking the controller version. So far we do not have any tests which need to be run in such a hybrid scenario. Usually if V2 and V1 are mounted at once, V2 is empty. So this does not complicate the declaration by allowing the version to be specified on a per controller basis. Signed-off-by: Richard Palethorpe Reviewed-by: Cyril Hrubis Reviewed-by: Li Wang --- doc/c-test-api.txt | 102 ++++++++---------- include/tst_cgroup.h | 29 ++--- include/tst_test.h | 7 ++ lib/newlib_tests/tst_cgroup01.c | 3 +- lib/newlib_tests/tst_cgroup02.c | 27 +++-- lib/tst_cgroup.c | 59 +++++----- lib/tst_test.c | 21 ++++ .../kernel/controllers/memcg/memcontrol01.c | 20 +--- .../kernel/controllers/memcg/memcontrol02.c | 13 +-- .../controllers/memcg/memcontrol_common.h | 1 - testcases/kernel/mem/cpuset/cpuset01.c | 25 ++--- testcases/kernel/mem/include/mem.h | 1 - testcases/kernel/mem/ksm/ksm02.c | 19 ++-- testcases/kernel/mem/ksm/ksm03.c | 13 +-- testcases/kernel/mem/ksm/ksm04.c | 16 ++- testcases/kernel/mem/oom/oom03.c | 24 ++--- testcases/kernel/mem/oom/oom04.c | 15 +-- testcases/kernel/mem/oom/oom05.c | 34 +++--- .../sched/cfs-scheduler/cfs_bandwidth01.c | 11 +- testcases/kernel/syscalls/madvise/madvise06.c | 29 ++--- 20 files changed, 209 insertions(+), 260 deletions(-) diff --git a/doc/c-test-api.txt b/doc/c-test-api.txt index 6f4de3f80..9b516bb38 100644 --- a/doc/c-test-api.txt +++ b/doc/c-test-api.txt @@ -2056,11 +2056,13 @@ the field value of file. 1.36 Using Control Group ~~~~~~~~~~~~~~~~~~~~~~~~ -Some LTP tests need specific Control Group configurations. tst_cgroup.h provides -APIs to discover and use CGroups. There are many differences between CGroups API -V1 and V2. We encapsulate the details of configuring CGroups in high-level -functions which follow the V2 kernel API. Allowing one to use CGroups without -caring too much about the current system's configuration. +Some LTP tests need specific Control Group configurations. 'tst_cgroup.h' +provides APIs to discover and use CGroups. There are many differences between +CGroups API V1 and V2. We encapsulate the details of configuring CGroups in +high-level functions which follow the V2 kernel API where possible. Allowing one +to write code that works on both V1 or V2. At least some of the time anyway; +often the behavioural differences between V1 and V2 are too great. In such cases +we revert to branching on the CGroup version. Also, the LTP library will automatically mount/umount and configure the CGroup hierarchies if that is required (e.g. if you run the tests from init with no @@ -2069,9 +2071,6 @@ system manager). [source,c] ------------------------------------------------------------------------------- #include "tst_test.h" -#include "tst_cgroup.h" - -static const struct tst_cgroup_group *cg; static void run(void) { @@ -2082,34 +2081,24 @@ static void run(void) static void setup(void) { - tst_cgroup_require("memory", NULL); - cg = tst_cgroup_get_test_group(); - SAFE_CGROUP_PRINTF(cg, "cgroup.procs", "%d", getpid()); - SAFE_CGROUP_PRINTF(cg, "memory.max", "%lu", MEMSIZE); - if (SAFE_CGROUP_HAS(cg, "memory.swap.max")) - SAFE_CGROUP_PRINTF(cg, "memory.swap.max", "%zu", memsw); -} - -static void cleanup(void) -{ - tst_cgroup_cleanup(); + SAFE_CGROUP_PRINTF(tst_cgroup, "cgroup.procs", "%d", getpid()); + SAFE_CGROUP_PRINTF(tst_cgroup, "memory.max", "%lu", MEMSIZE); + if (SAFE_CGROUP_HAS(tst_cgroup, "memory.swap.max")) + SAFE_CGROUP_PRINTF(tst_cgroup, "memory.swap.max", "%zu", memsw); } struct tst_test test = { .setup = setup, .test_all = run, .cleanup = cleanup, + .needs_cgroup_controllers = (const char *const []){ "memory", NULL }, ... }; ------------------------------------------------------------------------------- Above, we first ensure the memory controller is available on the -test's CGroup with 'tst_cgroup_require'. We then get a structure, -'cg', which represents the test's CGroup. Note that -'tst_cgroup_get_test_group' should not be called many times, as it is -allocated in a guarded buffer (See section 2.2.31). Therefor it is -best to call it once in 'setup' and not 'run' because 'run' may be -repeated with the '-i' option. +test's CGroup with '.needs_cgroup_controllers'. This populates a structure, +'tst_cgroup', which represents the test's CGroup. We then write the current processes PID into 'cgroup.procs', which moves the current process into the test's CGroup. After which we set @@ -2129,8 +2118,6 @@ cleanup is also mostly hidden. However things can get much worse. [source,c] ------------------------------------------------------------------------------- -static const struct tst_cgroup_group *cg; -static const struct tst_cgroup_group *cg_drain; static struct tst_cgroup_group *cg_child; static void run(void) @@ -2138,19 +2125,21 @@ static void run(void) char buf[BUFSIZ]; size_t mem = 0; - cg_child = tst_cgroup_group_mk(cg, "child"); + cg_child = tst_cgroup_group_mk(tst_cgroup, "child"); SAFE_CGROUP_PRINTF(cg_child, "cgroup.procs", "%d", getpid()); - if (!TST_CGROUP_VER_IS_V1(cg, "memory")) - SAFE_CGROUP_PRINT(cg, "cgroup.subtree_control", "+memory"); - if (!TST_CGROUP_VER_IS_V1(cg, "cpuset")) - SAFE_CGROUP_PRINT(cg, "cgroup.subtree_control", "+cpuset"); + if (!TST_CGROUP_VER_IS_V1(tst_cgroup, "memory")) + SAFE_CGROUP_PRINT(tst_cgroup, "cgroup.subtree_control", "+memory"); + if (!TST_CGROUP_VER_IS_V1(tst_cgroup, "cpuset")) + SAFE_CGROUP_PRINT(tst_cgroup, "cgroup.subtree_control", "+cpuset"); if (!SAFE_FORK()) { SAFE_CGROUP_PRINTF(cg_child, "cgroup.procs", "%d", getpid()); - if (SAFE_CGROUP_HAS(cg_child, "memory.swap")) - SAFE_CGROUP_SCANF(cg_child, "memory.swap.current", "%zu", &mem); + if (SAFE_CGROUP_HAS(cg_child, "memory.swap")) { + SAFE_CGROUP_SCANF(cg_child, + "memory.swap.current", "%zu", &mem); + } SAFE_CGROUP_READ(cg_child, "cpuset.mems", buf, sizeof(buf)); // Do something with cpuset.mems and memory.current values @@ -2160,44 +2149,42 @@ static void run(void) } tst_reap_children(); - SAFE_CGROUP_PRINTF(cg_drain, "cgroup.procs", "%d", getpid()); + SAFE_CGROUP_PRINTF(tst_cgroup_drain, "cgroup.procs", "%d", getpid()); cg_child = tst_cgroup_group_rm(cg_child); } -static void setup(void) -{ - tst_cgroup_require("memory", NULL); - tst_cgroup_require("cpuset", NULL); - - cg = tst_cgroup_get_test_group(); - cg_drain = tst_cgroup_get_drain_group(); -} - static void cleanup(void) { if (cg_child) { - SAFE_CGROUP_PRINTF(cg_drain, "cgroup.procs", "%d", getpid()); + SAFE_CGROUP_PRINTF(tst_cgroup_drain, "cgroup.procs", "%d", getpid()); cg_child = tst_cgroup_group_rm(cg_child); } - - tst_cgroup_cleanup(); } struct tst_test test = { .setup = setup, .test_all = run, - .cleanup = cleanup, + .needs_cgroup_controllers = (const char *const []){ + "cpuset", + "memory", + NULL + }, ... }; ------------------------------------------------------------------------------- -Starting with setup; we can see here that we also fetch the 'drain' +Starting with setup; we can see here that we fetch the 'drain' CGroup. This is a shared group (between parallel tests) which may -contain processes from other tests. It should have default settings and -these should not be changed by the test. It can be used to remove +contain processes from other tests. It should have default settings +and these should not be changed by the test. It can be used to remove processes from other CGroups incase the hierarchy root is not accessible. +Note that 'tst_cgroup_get_drain_group' should not be called many times, +as it is allocated in a guarded buffer (See section 2.2.31). Therefor +it is best to call it once in 'setup' and not 'run' because 'run' may +be repeated with the '-i' option. + In 'run', we first create a child CGroup with 'tst_cgroup_mk'. As we create this CGroup in 'run' we should also remove it at the end of run. We also need to check if it exists and remove it in cleanup as @@ -2229,22 +2216,23 @@ destroying the child CGroup. So there is no need to transfer the child to drain. However the parent process must be moved otherwise we will get 'EBUSY' when trying to remove the child CGroup. -Another example of an edge case is the following. +Another example of a behavioral difference between versions is shown below. [source,c] ------------------------------------------------------------------------------- - if (TST_CGROUP_VER_IS_V1(cg, "memory")) - SAFE_CGROUP_PRINTF(cg, "memory.swap.max", "%lu", ~0UL); + if (TST_CGROUP_VER_IS_V1(tst_cgroup, "memory")) + SAFE_CGROUP_PRINTF(tst_cgroup, "memory.swap.max", "%lu", ~0UL); else - SAFE_CGROUP_PRINT(cg, "memory.swap.max", "max"); + SAFE_CGROUP_PRINT(tst_cgroup, "memory.swap.max", "max"); ------------------------------------------------------------------------------- CGroups V2 introduced a feature where 'memory[.swap].max' could be set to "max". This does not appear to work on V1 'limit_in_bytes' however. For most tests, simply using a large number is sufficient and there is no need to use "max". Importantly though, one should be careful to read both the V1 and V2 -kernel docs. The LTP library can not handle all edge cases. It does the minimal -amount of work to make testing on both V1 and V2 feasible. +kernel docs. Presently the LTP library does not attempt to handle most +differences in semantics. It does the minimal amount of work to make testing on +both V1 and V2 feasible. 1.37 Require minimum numbers of CPU for a testcase ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/include/tst_cgroup.h b/include/tst_cgroup.h index 5190d8794..83bdb4b0d 100644 --- a/include/tst_cgroup.h +++ b/include/tst_cgroup.h @@ -93,16 +93,19 @@ enum tst_cgroup_ver { * test to request a particular CGroup structure. */ struct tst_cgroup_opts { - /* Only try to mount V1 CGroup controllers. This will not - * prevent V2 from being used if it is already mounted, it - * only indicates that we should mount V1 controllers if - * nothing is present. By default we try to mount V2 first. */ - int only_mount_v1:1; + /* Call tst_brk with TCONF if the controller is not on this + * version. Defautls to zero to accept any version. + */ + enum tst_cgroup_ver needs_ver; }; /* A Control Group in LTP's aggregated hierarchy */ struct tst_cgroup_group; +/* Populated with a reference to this tests's CGroup */ +extern const struct tst_cgroup_group *const tst_cgroup; +extern const struct tst_cgroup_group *const tst_cgroup_drain; + /* Search the system for mounted cgroups and available * controllers. Called automatically by tst_cgroup_require. */ @@ -111,22 +114,20 @@ void tst_cgroup_scan(void); void tst_cgroup_print_config(void); /* Ensure the specified controller is available in the test's default - * CGroup, mounting/enabling it if necessary */ + * CGroup, mounting/enabling it if necessary. Usually this is not + * necesary use tst_test.needs_cgroup_controllers instead. + */ void tst_cgroup_require(const char *const ctrl_name, const struct tst_cgroup_opts *const options) - __attribute__ ((nonnull (1))); + __attribute__ ((nonnull)); /* Tear down any CGroups created by calls to tst_cgroup_require */ void tst_cgroup_cleanup(void); -/* Get the default CGroup for the test. It allocates memory (in a - * guarded buffer) so should always be called from setup +/* Call this in setup after you call tst_cgroup_require and want to + * initialize tst_cgroup and tst_cgroup_drain. See tst_cgroup_require. */ -const struct tst_cgroup_group *tst_cgroup_get_test_group(void) - __attribute__ ((warn_unused_result)); -/* Get the shared drain group. Also should be called from setup */ -const struct tst_cgroup_group *tst_cgroup_get_drain_group(void) - __attribute__ ((warn_unused_result)); +void tst_cgroup_init(void); /* Create a descendant CGroup */ struct tst_cgroup_group * diff --git a/include/tst_test.h b/include/tst_test.h index 450ddf086..a7aaedcff 100644 --- a/include/tst_test.h +++ b/include/tst_test.h @@ -99,6 +99,7 @@ pid_t safe_fork(const char *filename, unsigned int lineno); #include "tst_safe_file_ops.h" #include "tst_safe_net.h" #include "tst_clone.h" +#include "tst_cgroup.h" /* * Wait for all children and exit with TBROK if @@ -280,6 +281,12 @@ struct tst_test { /* NULL terminated array of required commands */ const char *const *needs_cmds; + + /* Requires a particular CGroup API version. */ + const enum tst_cgroup_ver needs_cgroup_ver; + + /* {} terminated array of required CGroup controllers */ + const char *const *needs_cgroup_ctrls; }; /* diff --git a/lib/newlib_tests/tst_cgroup01.c b/lib/newlib_tests/tst_cgroup01.c index 54a370362..0fdc57e2e 100644 --- a/lib/newlib_tests/tst_cgroup01.c +++ b/lib/newlib_tests/tst_cgroup01.c @@ -4,7 +4,6 @@ #include #include "tst_test.h" -#include "tst_cgroup.h" static char *only_mount_v1; static char *no_cleanup; @@ -22,7 +21,7 @@ static void do_test(void) static void setup(void) { - cgopts.only_mount_v1 = !!only_mount_v1, + cgopts.needs_ver = !!only_mount_v1 ? TST_CGROUP_V1 : 0; tst_cgroup_scan(); tst_cgroup_print_config(); diff --git a/lib/newlib_tests/tst_cgroup02.c b/lib/newlib_tests/tst_cgroup02.c index 64b0a1e94..257bc8f35 100644 --- a/lib/newlib_tests/tst_cgroup02.c +++ b/lib/newlib_tests/tst_cgroup02.c @@ -5,7 +5,6 @@ #include #include "tst_test.h" -#include "tst_cgroup.h" static char *only_mount_v1; static char *no_cleanup; @@ -15,8 +14,6 @@ static struct tst_option opts[] = { {NULL, NULL, NULL}, }; static struct tst_cgroup_opts cgopts; -static const struct tst_cgroup_group *cg; -static const struct tst_cgroup_group *cg_drain; static struct tst_cgroup_group *cg_child; static void do_test(void) @@ -24,12 +21,12 @@ static void do_test(void) char buf[BUFSIZ]; size_t mem; - if (!TST_CGROUP_VER_IS_V1(cg, "memory")) - SAFE_CGROUP_PRINT(cg, "cgroup.subtree_control", "+memory"); - if (!TST_CGROUP_VER_IS_V1(cg, "cpuset")) - SAFE_CGROUP_PRINT(cg, "cgroup.subtree_control", "+cpuset"); + if (!TST_CGROUP_VER_IS_V1(tst_cgroup, "memory")) + SAFE_CGROUP_PRINT(tst_cgroup, "cgroup.subtree_control", "+memory"); + if (!TST_CGROUP_VER_IS_V1(tst_cgroup, "cpuset")) + SAFE_CGROUP_PRINT(tst_cgroup, "cgroup.subtree_control", "+cpuset"); - cg_child = tst_cgroup_group_mk(cg, "child"); + cg_child = tst_cgroup_group_mk(tst_cgroup, "child"); if (!SAFE_FORK()) { SAFE_CGROUP_PRINTF(cg_child, "cgroup.procs", "%d", getpid()); @@ -47,19 +44,19 @@ static void do_test(void) exit(0); } - SAFE_CGROUP_PRINTF(cg, "memory.max", "%zu", (1UL << 24) - 1); + SAFE_CGROUP_PRINTF(tst_cgroup, "memory.max", "%zu", (1UL << 24) - 1); SAFE_CGROUP_PRINTF(cg_child, "cgroup.procs", "%d", getpid()); - SAFE_CGROUP_SCANF(cg, "memory.current", "%zu", &mem); + SAFE_CGROUP_SCANF(tst_cgroup, "memory.current", "%zu", &mem); tst_res(TPASS, "memory.current = %zu", mem); tst_reap_children(); - SAFE_CGROUP_PRINTF(cg_drain, "cgroup.procs", "%d", getpid()); + SAFE_CGROUP_PRINTF(tst_cgroup_drain, "cgroup.procs", "%d", getpid()); cg_child = tst_cgroup_group_rm(cg_child); } static void setup(void) { - cgopts.only_mount_v1 = !!only_mount_v1, + cgopts.needs_ver = !!only_mount_v1 ? TST_CGROUP_V1 : 0; tst_cgroup_scan(); tst_cgroup_print_config(); @@ -67,14 +64,14 @@ static void setup(void) tst_cgroup_require("memory", &cgopts); tst_cgroup_require("cpuset", &cgopts); - cg = tst_cgroup_get_test_group(); - cg_drain = tst_cgroup_get_drain_group(); + tst_cgroup_init(); } static void cleanup(void) { if (cg_child) { - SAFE_CGROUP_PRINTF(cg_drain, "cgroup.procs", "%d", getpid()); + SAFE_CGROUP_PRINTF(tst_cgroup_drain, + "cgroup.procs", "%d", getpid()); cg_child = tst_cgroup_group_rm(cg_child); } if (!no_cleanup) diff --git a/lib/tst_cgroup.c b/lib/tst_cgroup.c index 10b65364b..51b523b80 100644 --- a/lib/tst_cgroup.c +++ b/lib/tst_cgroup.c @@ -18,7 +18,6 @@ #include "lapi/mount.h" #include "lapi/mkdirat.h" #include "tst_safe_file_at.h" -#include "tst_cgroup.h" struct cgroup_root; @@ -138,6 +137,14 @@ struct tst_cgroup_group { struct cgroup_dir *dirs[ROOTS_MAX + 1]; }; +/* If controllers are required via the tst_test struct then this is + * populated with the test's CGroup. + */ +static struct tst_cgroup_group test_group; +static struct tst_cgroup_group drain_group; +const struct tst_cgroup_group *const tst_cgroup = &test_group; +const struct tst_cgroup_group *const tst_cgroup_drain = &drain_group; + /* Always use first item for unified hierarchy */ static struct cgroup_root roots[ROOTS_MAX + 1]; @@ -196,8 +203,6 @@ static struct cgroup_ctrl controllers[] = { { } }; -static const struct tst_cgroup_opts default_opts = { 0 }; - /* We should probably allow these to be set in environment * variables */ @@ -607,9 +612,6 @@ void tst_cgroup_require(const char *const ctrl_name, return; } - if (!options) - options = &default_opts; - if (ctrl->we_require_it) tst_res(TWARN, "Duplicate %s(%s, )", __func__, ctrl->ctrl_name); @@ -623,13 +625,14 @@ void tst_cgroup_require(const char *const ctrl_name, if (ctrl->ctrl_root) goto mkdirs; - if (!cgroup_v2_mounted() && !options->only_mount_v1) + if (!cgroup_v2_mounted() && options->needs_ver != TST_CGROUP_V1) cgroup_mount_v2(); if (ctrl->ctrl_root) goto mkdirs; - cgroup_mount_v1(ctrl); + if (options->needs_ver != TST_CGROUP_V2) + cgroup_mount_v1(ctrl); if (!ctrl->ctrl_root) { tst_brk(TCONF, @@ -642,6 +645,17 @@ mkdirs: root = ctrl->ctrl_root; add_ctrl(&root->mnt_dir.ctrl_field, ctrl); + if (cgroup_ctrl_on_v2(ctrl) && options->needs_ver == TST_CGROUP_V1) { + tst_brk(TCONF, + "V1 '%s' controller required, but it's mounted on V2", + ctrl->ctrl_name); + } + if (!cgroup_ctrl_on_v2(ctrl) && options->needs_ver == TST_CGROUP_V2) { + tst_brk(TCONF, + "V2 '%s' controller required, but it's mounted on V1", + ctrl->ctrl_name); + } + if (cgroup_ctrl_on_v2(ctrl)) { if (root->we_mounted_it) { SAFE_FILE_PRINTFAT(root->mnt_dir.dir_fd, @@ -1028,18 +1042,19 @@ int safe_cgroup_has(const char *const file, const int lineno, return 0; } -__attribute__ ((warn_unused_result)) -static struct tst_cgroup_group *cgroup_group_from_roots(const size_t tree_off) +static void group_from_roots(struct tst_cgroup_group *const cg) { struct cgroup_root *root; - struct cgroup_dir *dir; - struct tst_cgroup_group *cg; - cg = tst_alloc(sizeof(*cg)); - cgroup_group_init(cg, NULL); + if (cg->group_name[0]) { + tst_brk(TBROK, + "%s CGroup already initialized", + cg == &test_group ? "Test" : "Drain"); + } for_each_root(root) { - dir = (typeof(dir))(((char *)root) + tree_off); + struct cgroup_dir *dir = + cg == &test_group ? &root->test_dir : &root->drain_dir; if (dir->ctrl_field) cgroup_group_add_dir(NULL, cg, dir); @@ -1047,23 +1062,17 @@ static struct tst_cgroup_group *cgroup_group_from_roots(const size_t tree_off) if (cg->dirs[0]) { strncpy(cg->group_name, cg->dirs[0]->dir_name, NAME_MAX); - return cg; + return; } tst_brk(TBROK, "No CGroups found; maybe you forgot to call tst_cgroup_require?"); - - return cg; -} - -const struct tst_cgroup_group *tst_cgroup_get_test_group(void) -{ - return cgroup_group_from_roots(offsetof(struct cgroup_root, test_dir)); } -const struct tst_cgroup_group *tst_cgroup_get_drain_group(void) +void tst_cgroup_init(void) { - return cgroup_group_from_roots(offsetof(struct cgroup_root, drain_dir)); + group_from_roots(&test_group); + group_from_roots(&drain_group); } ssize_t safe_cgroup_read(const char *const file, const int lineno, diff --git a/lib/tst_test.c b/lib/tst_test.c index 844756fbd..1fd238cf5 100644 --- a/lib/tst_test.c +++ b/lib/tst_test.c @@ -1013,6 +1013,19 @@ static void prepare_device(void) } } +static void do_cgroup_requires(void) +{ + const struct tst_cgroup_opts cg_opts = { + .needs_ver = tst_test->needs_cgroup_ver, + }; + const char *const *ctrl_names = tst_test->needs_cgroup_ctrls; + + for (; *ctrl_names; ctrl_names++) + tst_cgroup_require(*ctrl_names, &cg_opts); + + tst_cgroup_init(); +} + static void do_setup(int argc, char *argv[]) { if (!tst_test) @@ -1165,6 +1178,11 @@ static void do_setup(int argc, char *argv[]) if (tst_test->taint_check) tst_taint_init(tst_test->taint_check); + + if (tst_test->needs_cgroup_ctrls) + do_cgroup_requires(); + else if (tst_test->needs_cgroup_ver) + tst_brk(TBROK, "needs_cgroup_ver only works with needs_cgroup_controllers"); } static void do_test_setup(void) @@ -1198,6 +1216,9 @@ static void do_test_setup(void) static void do_cleanup(void) { + if (tst_test->needs_cgroup_ctrls) + tst_cgroup_cleanup(); + if (ovl_mounted) SAFE_UMOUNT(OVL_MNT); diff --git a/testcases/kernel/controllers/memcg/memcontrol01.c b/testcases/kernel/controllers/memcg/memcontrol01.c index f3b45610e..595192437 100644 --- a/testcases/kernel/controllers/memcg/memcontrol01.c +++ b/testcases/kernel/controllers/memcg/memcontrol01.c @@ -16,17 +16,15 @@ #include #include "tst_test.h" -#include "tst_cgroup.h" -static const struct tst_cgroup_group *cg_test; static struct tst_cgroup_group *parent, *child; static struct tst_cgroup_group *parent2, *child2; static void test_memcg_subtree_control(void) { - parent = tst_cgroup_group_mk(cg_test, "memcg_test_0"); + parent = tst_cgroup_group_mk(tst_cgroup, "memcg_test_0"); child = tst_cgroup_group_mk(parent, "memcg_test_1"); - parent2 = tst_cgroup_group_mk(cg_test, "memcg_test_2"); + parent2 = tst_cgroup_group_mk(tst_cgroup, "memcg_test_2"); child2 = tst_cgroup_group_mk(parent2, "memcg_test_3"); SAFE_CGROUP_PRINT(parent2, "cgroup.subtree_control", "-memory"); @@ -44,15 +42,6 @@ static void test_memcg_subtree_control(void) parent = tst_cgroup_group_rm(parent); } -static void setup(void) -{ - tst_cgroup_require("memory", NULL); - cg_test = tst_cgroup_get_test_group(); - - if (TST_CGROUP_VER_IS_V1(cg_test, "memory")) - tst_brk(TCONF, "V1 controllers do not have subtree control"); -} - static void cleanup(void) { if (child2) @@ -63,12 +52,11 @@ static void cleanup(void) child = tst_cgroup_group_rm(child); if (parent) parent = tst_cgroup_group_rm(parent); - - tst_cgroup_cleanup(); } static struct tst_test test = { - .setup = setup, .cleanup = cleanup, .test_all = test_memcg_subtree_control, + .needs_cgroup_ver = TST_CGROUP_V2, + .needs_cgroup_ctrls = (const char *const []){ "memory", NULL }, }; diff --git a/testcases/kernel/controllers/memcg/memcontrol02.c b/testcases/kernel/controllers/memcg/memcontrol02.c index d5a24cc0a..4adb31512 100644 --- a/testcases/kernel/controllers/memcg/memcontrol02.c +++ b/testcases/kernel/controllers/memcg/memcontrol02.c @@ -26,7 +26,6 @@ #include "memcontrol_common.h" static size_t page_size; -static const struct tst_cgroup_group *cg_test; static struct tst_cgroup_group *cg_child; static int fd; static int file_to_all_error = 10; @@ -37,7 +36,7 @@ static void alloc_anon_50M_check(void) char *buf, *ptr; ssize_t anon, current; const char *const anon_key_fmt = - TST_CGROUP_VER_IS_V1(cg_test, "memory") ? "rss %zd" : "anon %zd"; + TST_CGROUP_VER_IS_V1(tst_cgroup, "memory") ? "rss %zd" : "anon %zd"; buf = SAFE_MALLOC(size); for (ptr = buf; ptr < buf + size; ptr += page_size) @@ -62,7 +61,7 @@ static void alloc_pagecache_50M_check(void) const size_t size = MB(50); size_t current, file; const char *const file_key_fmt = - TST_CGROUP_VER_IS_V1(cg_test, "memory") ? "cache %zd" : "file %zd"; + TST_CGROUP_VER_IS_V1(tst_cgroup, "memory") ? "cache %zd" : "file %zd"; fd = SAFE_OPEN(TMPDIR"/tmpfile", O_RDWR | O_CREAT, 0600); @@ -89,7 +88,7 @@ static void test_memcg_current(unsigned int n) { size_t current; - cg_child = tst_cgroup_group_mk(cg_test, "child"); + cg_child = tst_cgroup_group_mk(tst_cgroup, "child"); SAFE_CGROUP_SCANF(cg_child, "memory.current", "%zu", ¤t); TST_EXP_EXPR(current == 0, "(current=%zu) == 0", current); @@ -114,9 +113,6 @@ static void setup(void) { page_size = SAFE_SYSCONF(_SC_PAGESIZE); - tst_cgroup_require("memory", NULL); - cg_test = tst_cgroup_get_test_group(); - switch (tst_fs_type(TMPDIR)) { case TST_VFAT_MAGIC: case TST_EXFAT_MAGIC: @@ -130,8 +126,6 @@ static void cleanup(void) { if (cg_child) cg_child = tst_cgroup_group_rm(cg_child); - - tst_cgroup_cleanup(); } static struct tst_test test = { @@ -145,4 +139,5 @@ static struct tst_test test = { .all_filesystems = 1, .forks_child = 1, .needs_root = 1, + .needs_cgroup_ctrls = (const char *const []){ "memory", NULL }, }; diff --git a/testcases/kernel/controllers/memcg/memcontrol_common.h b/testcases/kernel/controllers/memcg/memcontrol_common.h index 67f3ca318..63df719a6 100644 --- a/testcases/kernel/controllers/memcg/memcontrol_common.h +++ b/testcases/kernel/controllers/memcg/memcontrol_common.h @@ -4,7 +4,6 @@ #include #include "tst_test.h" -#include "tst_cgroup.h" #define TMPDIR "mntdir" #define MB(x) (x << 20) diff --git a/testcases/kernel/mem/cpuset/cpuset01.c b/testcases/kernel/mem/cpuset/cpuset01.c index 66c18f6ab..6383187d7 100644 --- a/testcases/kernel/mem/cpuset/cpuset01.c +++ b/testcases/kernel/mem/cpuset/cpuset01.c @@ -35,8 +35,6 @@ #ifdef HAVE_NUMA_V2 -static const struct tst_cgroup_group *cg; - volatile int end; static int *nodes; static int nnodes; @@ -53,10 +51,10 @@ static void test_cpuset(void) unsigned long nmask[MAXNODES / BITS_PER_LONG] = { 0 }; char buf[BUFSIZ]; - SAFE_CGROUP_READ(cg, "cpuset.cpus", buf, sizeof(buf)); - SAFE_CGROUP_PRINT(cg, "cpuset.cpus", buf); - SAFE_CGROUP_READ(cg, "cpuset.mems", buf, sizeof(buf)); - SAFE_CGROUP_PRINT(cg, "cpuset.mems", buf); + SAFE_CGROUP_READ(tst_cgroup, "cpuset.cpus", buf, sizeof(buf)); + SAFE_CGROUP_PRINT(tst_cgroup, "cpuset.cpus", buf); + SAFE_CGROUP_READ(tst_cgroup, "cpuset.mems", buf, sizeof(buf)); + SAFE_CGROUP_PRINT(tst_cgroup, "cpuset.mems", buf); child = SAFE_FORK(); if (child == 0) { @@ -70,8 +68,8 @@ static void test_cpuset(void) exit(mem_hog_cpuset(ncpus > 1 ? ncpus : 1)); } - SAFE_CGROUP_PRINTF(cg, "cpuset.mems", "%d", nodes[0]); - SAFE_CGROUP_PRINTF(cg, "cpuset.mems", "%d", nodes[1]); + SAFE_CGROUP_PRINTF(tst_cgroup, "cpuset.mems", "%d", nodes[0]); + SAFE_CGROUP_PRINTF(tst_cgroup, "cpuset.mems", "%d", nodes[1]); tst_reap_children(); @@ -80,20 +78,13 @@ static void test_cpuset(void) static void setup(void) { - tst_cgroup_require("cpuset", NULL); ncpus = count_cpu(); if (get_allowed_nodes_arr(NH_MEMS | NH_CPUS, &nnodes, &nodes) < 0) tst_brk(TBROK | TERRNO, "get_allowed_nodes_arr"); if (nnodes <= 1) tst_brk(TCONF, "requires a NUMA system."); - cg = tst_cgroup_get_test_group(); - SAFE_CGROUP_PRINTF(cg, "cgroup.procs", "%d", getpid()); -} - -static void cleanup(void) -{ - tst_cgroup_cleanup(); + SAFE_CGROUP_PRINTF(tst_cgroup, "cgroup.procs", "%d", getpid()); } static void sighandler(int signo LTP_ATTRIBUTE_UNUSED) @@ -183,9 +174,9 @@ static struct tst_test test = { .needs_root = 1, .forks_child = 1, .setup = setup, - .cleanup = cleanup, .test_all = test_cpuset, .min_kver = "2.6.32", + .needs_cgroup_ctrls = (const char *const []){ "cpuset", NULL }, }; #else diff --git a/testcases/kernel/mem/include/mem.h b/testcases/kernel/mem/include/mem.h index 38a1e8879..47a180d7e 100644 --- a/testcases/kernel/mem/include/mem.h +++ b/testcases/kernel/mem/include/mem.h @@ -6,7 +6,6 @@ #define _MEM_H #include "config.h" #include "tst_test.h" -#include "tst_cgroup.h" #include "ksm_helper.h" #include "tst_memutils.h" diff --git a/testcases/kernel/mem/ksm/ksm02.c b/testcases/kernel/mem/ksm/ksm02.c index c578cfb7f..2a890f025 100644 --- a/testcases/kernel/mem/ksm/ksm02.c +++ b/testcases/kernel/mem/ksm/ksm02.c @@ -59,9 +59,6 @@ #ifdef HAVE_NUMA_V2 #include -static const struct tst_cgroup_group *cg; -static const struct tst_cgroup_group *cg_drain; - static void verify_ksm(void) { unsigned long nmask[MAXNODES / BITS_PER_LONG] = { 0 }; @@ -79,19 +76,18 @@ static void verify_ksm(void) } create_same_memory(size, num, unit); - write_cpusets(cg, node); - SAFE_CGROUP_PRINTF(cg, "cgroup.procs", "%d", getpid()); + write_cpusets(tst_cgroup, node); + SAFE_CGROUP_PRINTF(tst_cgroup, "cgroup.procs", "%d", getpid()); create_same_memory(size, num, unit); - SAFE_CGROUP_PRINTF(cg_drain, "cgroup.procs", "%d", getpid()); + SAFE_CGROUP_PRINTF(tst_cgroup_drain, "cgroup.procs", "%d", getpid()); } static void cleanup(void) { - if (access(PATH_KSM "merge_across_nodes", F_OK) == 0) + if (access(PATH_KSM "merge_across_nodes", F_OK) == 0) { FILE_PRINTF(PATH_KSM "merge_across_nodes", "%d", merge_across_nodes); - - tst_cgroup_cleanup(); + } } static void setup(void) @@ -106,10 +102,6 @@ static void setup(void) "%d", &merge_across_nodes); SAFE_FILE_PRINTF(PATH_KSM "merge_across_nodes", "1"); } - - tst_cgroup_require("cpuset", NULL); - cg = tst_cgroup_get_test_group(); - cg_drain = tst_cgroup_get_drain_group(); } static struct tst_test test = { @@ -129,6 +121,7 @@ static struct tst_test test = { }, .test_all = verify_ksm, .min_kver = "2.6.32", + .needs_cgroup_ctrls = (const char *const []){ "cpuset", NULL }, }; #else diff --git a/testcases/kernel/mem/ksm/ksm03.c b/testcases/kernel/mem/ksm/ksm03.c index df847cf95..03fad2ee2 100644 --- a/testcases/kernel/mem/ksm/ksm03.c +++ b/testcases/kernel/mem/ksm/ksm03.c @@ -59,8 +59,6 @@ #include "mem.h" #include "ksm_common.h" -static const struct tst_cgroup_group *cg; - static void verify_ksm(void) { create_same_memory(size, num, unit); @@ -79,18 +77,16 @@ static void setup(void) parse_ksm_options(opt_sizestr, &size, opt_numstr, &num, opt_unitstr, &unit); - tst_cgroup_require("memory", NULL); - cg = tst_cgroup_get_test_group(); - SAFE_CGROUP_PRINTF(cg, "cgroup.procs", "%d", getpid()); - SAFE_CGROUP_PRINTF(cg, "memory.max", "%lu", TESTMEM); + SAFE_CGROUP_PRINTF(tst_cgroup, "cgroup.procs", "%d", getpid()); + SAFE_CGROUP_PRINTF(tst_cgroup, "memory.max", "%lu", TESTMEM); } static void cleanup(void) { - if (access(PATH_KSM "merge_across_nodes", F_OK) == 0) + if (access(PATH_KSM "merge_across_nodes", F_OK) == 0) { FILE_PRINTF(PATH_KSM "merge_across_nodes", "%d", merge_across_nodes); - tst_cgroup_cleanup(); + } } static struct tst_test test = { @@ -110,4 +106,5 @@ static struct tst_test test = { }, .test_all = verify_ksm, .min_kver = "2.6.32", + .needs_cgroup_ctrls = (const char *const []){ "memory", NULL }, }; diff --git a/testcases/kernel/mem/ksm/ksm04.c b/testcases/kernel/mem/ksm/ksm04.c index e8bc1de85..683780907 100644 --- a/testcases/kernel/mem/ksm/ksm04.c +++ b/testcases/kernel/mem/ksm/ksm04.c @@ -59,8 +59,6 @@ #ifdef HAVE_NUMA_V2 #include -static const struct tst_cgroup_group *cg; - static void verify_ksm(void) { unsigned long nmask[MAXNODES / BITS_PER_LONG] = { 0 }; @@ -69,7 +67,7 @@ static void verify_ksm(void) node = get_a_numa_node(); set_node(nmask, node); - SAFE_CGROUP_PRINTF(cg, "memory.max", "%lu", TESTMEM); + SAFE_CGROUP_PRINTF(tst_cgroup, "memory.max", "%lu", TESTMEM); if (set_mempolicy(MPOL_BIND, nmask, MAXNODES) == -1) { if (errno != ENOSYS) @@ -80,7 +78,7 @@ static void verify_ksm(void) } create_same_memory(size, num, unit); - write_cpusets(cg, node); + write_cpusets(tst_cgroup, node); create_same_memory(size, num, unit); } @@ -89,8 +87,6 @@ static void cleanup(void) if (access(PATH_KSM "merge_across_nodes", F_OK) == 0) FILE_PRINTF(PATH_KSM "merge_across_nodes", "%d", merge_across_nodes); - - tst_cgroup_cleanup(); } static void setup(void) @@ -106,10 +102,7 @@ static void setup(void) parse_ksm_options(opt_sizestr, &size, opt_numstr, &num, opt_unitstr, &unit); - tst_cgroup_require("memory", NULL); - tst_cgroup_require("cpuset", NULL); - cg = tst_cgroup_get_test_group(); - SAFE_CGROUP_PRINTF(cg, "cgroup.procs", "%d", getpid()); + SAFE_CGROUP_PRINTF(tst_cgroup, "cgroup.procs", "%d", getpid()); } static struct tst_test test = { @@ -129,6 +122,9 @@ static struct tst_test test = { }, .test_all = verify_ksm, .min_kver = "2.6.32", + .needs_cgroup_ctrls = (const char *const []){ + "memory", "cpuset", NULL + }, }; #else diff --git a/testcases/kernel/mem/oom/oom03.c b/testcases/kernel/mem/oom/oom03.c index 451119166..8b4fb47c7 100644 --- a/testcases/kernel/mem/oom/oom03.c +++ b/testcases/kernel/mem/oom/oom03.c @@ -36,8 +36,6 @@ #ifdef HAVE_NUMA_V2 -static const struct tst_cgroup_group *cg; - static void verify_oom(void) { #ifdef TST_ABI32 @@ -45,7 +43,7 @@ static void verify_oom(void) #endif testoom(0, 0, ENOMEM, 1); - if (SAFE_CGROUP_HAS(cg, "memory.swap.max")) { + if (SAFE_CGROUP_HAS(tst_cgroup, "memory.swap.max")) { tst_res(TINFO, "OOM on MEMCG with special memswap limitation:"); /* * Cgroup v2 tracks memory and swap in separate, which splits @@ -57,17 +55,17 @@ static void verify_oom(void) * let's scale down the value of 'memory.swap.max' to only * 1MB for CGroup v2. */ - if (!TST_CGROUP_VER_IS_V1(cg, "memory")) - SAFE_CGROUP_PRINTF(cg, "memory.swap.max", "%lu", MB); + if (!TST_CGROUP_VER_IS_V1(tst_cgroup, "memory")) + SAFE_CGROUP_PRINTF(tst_cgroup, "memory.swap.max", "%lu", MB); else - SAFE_CGROUP_PRINTF(cg, "memory.swap.max", "%lu", TESTMEM + MB); + SAFE_CGROUP_PRINTF(tst_cgroup, "memory.swap.max", "%lu", TESTMEM + MB); testoom(0, 1, ENOMEM, 1); - if (TST_CGROUP_VER_IS_V1(cg, "memory")) - SAFE_CGROUP_PRINTF(cg, "memory.swap.max", "%lu", ~0UL); + if (TST_CGROUP_VER_IS_V1(tst_cgroup, "memory")) + SAFE_CGROUP_PRINTF(tst_cgroup, "memory.swap.max", "%lu", ~0UL); else - SAFE_CGROUP_PRINT(cg, "memory.swap.max", "max"); + SAFE_CGROUP_PRINT(tst_cgroup, "memory.swap.max", "max"); } /* OOM for MEMCG with mempolicy */ @@ -84,17 +82,14 @@ static void setup(void) overcommit = get_sys_tune("overcommit_memory"); set_sys_tune("overcommit_memory", 1, 1); - tst_cgroup_require("memory", NULL); - cg = tst_cgroup_get_test_group(); - SAFE_CGROUP_PRINTF(cg, "cgroup.procs", "%d", getpid()); - SAFE_CGROUP_PRINTF(cg, "memory.max", "%lu", TESTMEM); + SAFE_CGROUP_PRINTF(tst_cgroup, "cgroup.procs", "%d", getpid()); + SAFE_CGROUP_PRINTF(tst_cgroup, "memory.max", "%lu", TESTMEM); } static void cleanup(void) { if (overcommit != -1) set_sys_tune("overcommit_memory", overcommit, 0); - tst_cgroup_cleanup(); } static struct tst_test test = { @@ -104,6 +99,7 @@ static struct tst_test test = { .setup = setup, .cleanup = cleanup, .test_all = verify_oom, + .needs_cgroup_ctrls = (const char *const []){ "memory", NULL }, }; #else diff --git a/testcases/kernel/mem/oom/oom04.c b/testcases/kernel/mem/oom/oom04.c index f84328f5b..8e8902b76 100644 --- a/testcases/kernel/mem/oom/oom04.c +++ b/testcases/kernel/mem/oom/oom04.c @@ -36,8 +36,6 @@ #ifdef HAVE_NUMA_V2 -static const struct tst_cgroup_group *cg; - static void verify_oom(void) { #ifdef TST_ABI32 @@ -47,13 +45,13 @@ static void verify_oom(void) testoom(0, 0, ENOMEM, 1); if (is_numa(NULL, NH_MEMS, 2) && - SAFE_CGROUP_HAS(cg, "cpuset.memory_migrate")) { + SAFE_CGROUP_HAS(tst_cgroup, "cpuset.memory_migrate")) { /* * Under NUMA system, the migration of cpuset's memory * is in charge of cpuset.memory_migrate, we can write * 1 to cpuset.memory_migrate to enable the migration. */ - SAFE_CGROUP_PRINT(cg, "cpuset.memory_migrate", "1"); + SAFE_CGROUP_PRINT(tst_cgroup, "cpuset.memory_migrate", "1"); tst_res(TINFO, "OOM on CPUSET with mem migrate:"); testoom(0, 0, ENOMEM, 1); @@ -70,9 +68,6 @@ static void setup(void) overcommit = get_sys_tune("overcommit_memory"); set_sys_tune("overcommit_memory", 1, 1); - tst_cgroup_require("cpuset", NULL); - cg = tst_cgroup_get_test_group(); - /* * Some nodes do not contain memory, so use * get_allowed_nodes(NH_MEMS) to get a memory @@ -83,15 +78,14 @@ static void setup(void) if (ret < 0) tst_brk(TBROK, "Failed to get a memory node " "using get_allowed_nodes()"); - write_cpusets(cg, memnode); - SAFE_CGROUP_PRINTF(cg, "cgroup.procs", "%d", getpid()); + write_cpusets(tst_cgroup, memnode); + SAFE_CGROUP_PRINTF(tst_cgroup, "cgroup.procs", "%d", getpid()); } static void cleanup(void) { if (overcommit != -1) set_sys_tune("overcommit_memory", overcommit, 0); - tst_cgroup_cleanup(); } static struct tst_test test = { @@ -101,6 +95,7 @@ static struct tst_test test = { .setup = setup, .cleanup = cleanup, .test_all = verify_oom, + .needs_cgroup_ctrls = (const char *const []){ "cpuset", NULL }, }; #else diff --git a/testcases/kernel/mem/oom/oom05.c b/testcases/kernel/mem/oom/oom05.c index 06497261e..ca60f1101 100644 --- a/testcases/kernel/mem/oom/oom05.c +++ b/testcases/kernel/mem/oom/oom05.c @@ -36,8 +36,6 @@ #ifdef HAVE_NUMA_V2 -static const struct tst_cgroup_group *cg; - static void verify_oom(void) { #ifdef TST_ABI32 @@ -53,29 +51,29 @@ static void verify_oom(void) * 1 to cpuset.memory_migrate to enable the migration. */ if (is_numa(NULL, NH_MEMS, 2) && - SAFE_CGROUP_HAS(cg, "cpuset.memory_migrate")) { - SAFE_CGROUP_PRINT(cg, "cpuset.memory_migrate", "1"); + SAFE_CGROUP_HAS(tst_cgroup, "cpuset.memory_migrate")) { + SAFE_CGROUP_PRINT(tst_cgroup, "cpuset.memory_migrate", "1"); tst_res(TINFO, "OOM on CPUSET & MEMCG with " "cpuset.memory_migrate=1"); testoom(0, 0, ENOMEM, 1); } - if (SAFE_CGROUP_HAS(cg, "memory.swap.max")) { + if (SAFE_CGROUP_HAS(tst_cgroup, "memory.swap.max")) { tst_res(TINFO, "OOM on CPUSET & MEMCG with " "special memswap limitation:"); - if (!TST_CGROUP_VER_IS_V1(cg, "memory")) - SAFE_CGROUP_PRINTF(cg, "memory.swap.max", "%lu", MB); + if (!TST_CGROUP_VER_IS_V1(tst_cgroup, "memory")) + SAFE_CGROUP_PRINTF(tst_cgroup, "memory.swap.max", "%lu", MB); else - SAFE_CGROUP_PRINTF(cg, "memory.swap.max", "%lu", TESTMEM + MB); + SAFE_CGROUP_PRINTF(tst_cgroup, "memory.swap.max", "%lu", TESTMEM + MB); testoom(0, 1, ENOMEM, 1); tst_res(TINFO, "OOM on CPUSET & MEMCG with " "disabled memswap limitation:"); - if (TST_CGROUP_VER_IS_V1(cg, "memory")) - SAFE_CGROUP_PRINTF(cg, "memory.swap.max", "%lu", ~0UL); + if (TST_CGROUP_VER_IS_V1(tst_cgroup, "memory")) + SAFE_CGROUP_PRINTF(tst_cgroup, "memory.swap.max", "%lu", ~0UL); else - SAFE_CGROUP_PRINT(cg, "memory.swap.max", "max"); + SAFE_CGROUP_PRINT(tst_cgroup, "memory.swap.max", "max"); testoom(0, 0, ENOMEM, 1); } } @@ -90,10 +88,6 @@ void setup(void) overcommit = get_sys_tune("overcommit_memory"); set_sys_tune("overcommit_memory", 1, 1); - tst_cgroup_require("memory", NULL); - tst_cgroup_require("cpuset", NULL); - cg = tst_cgroup_get_test_group(); - /* * Some nodes do not contain memory, so use * get_allowed_nodes(NH_MEMS) to get a memory @@ -105,16 +99,15 @@ void setup(void) tst_brk(TBROK, "Failed to get a memory node " "using get_allowed_nodes()"); - write_cpusets(cg, memnode); - SAFE_CGROUP_PRINTF(cg, "cgroup.procs", "%d", getpid()); - SAFE_CGROUP_PRINTF(cg, "memory.max", "%lu", TESTMEM); + write_cpusets(tst_cgroup, memnode); + SAFE_CGROUP_PRINTF(tst_cgroup, "cgroup.procs", "%d", getpid()); + SAFE_CGROUP_PRINTF(tst_cgroup, "memory.max", "%lu", TESTMEM); } void cleanup(void) { if (overcommit != -1) set_sys_tune("overcommit_memory", overcommit, 0); - tst_cgroup_cleanup(); } static struct tst_test test = { @@ -124,6 +117,9 @@ static struct tst_test test = { .setup = setup, .cleanup = cleanup, .test_all = verify_oom, + .needs_cgroup_ctrls = (const char *const []){ + "memory", "cpuset", NULL + }, }; #else diff --git a/testcases/kernel/sched/cfs-scheduler/cfs_bandwidth01.c b/testcases/kernel/sched/cfs-scheduler/cfs_bandwidth01.c index e3eb237da..aae1e321b 100644 --- a/testcases/kernel/sched/cfs-scheduler/cfs_bandwidth01.c +++ b/testcases/kernel/sched/cfs-scheduler/cfs_bandwidth01.c @@ -29,10 +29,8 @@ #include #include "tst_test.h" -#include "tst_cgroup.h" #include "tst_timer.h" -static const struct tst_cgroup_group *cg_test; static struct tst_cgroup_group *cg_level2, *cg_level3a, *cg_level3b; static struct tst_cgroup_group *cg_workers[3]; static int may_have_waiters = 0; @@ -132,11 +130,7 @@ static void do_test(void) static void setup(void) { - tst_cgroup_require("cpu", NULL); - - cg_test = tst_cgroup_get_test_group(); - - cg_level2 = tst_cgroup_group_mk(cg_test, "level2"); + cg_level2 = tst_cgroup_group_mk(tst_cgroup, "level2"); cg_level3a = tst_cgroup_group_mk(cg_level2, "level3a"); mk_cpu_cgroup(&cg_workers[0], cg_level3a, "worker1", 30); @@ -167,8 +161,6 @@ static void cleanup(void) cg_level3b = tst_cgroup_group_rm(cg_level3b); if (cg_level2) cg_level2 = tst_cgroup_group_rm(cg_level2); - - tst_cgroup_cleanup(); } static struct tst_test test = { @@ -182,6 +174,7 @@ static struct tst_test test = { "CONFIG_CFS_BANDWIDTH", NULL }, + .needs_cgroup_ctrls = (const char *const []){"cpu", NULL}, .tags = (const struct tst_tag[]) { {"linux-git", "39f23ce07b93"}, {"linux-git", "b34cb07dde7c"}, diff --git a/testcases/kernel/syscalls/madvise/madvise06.c b/testcases/kernel/syscalls/madvise/madvise06.c index 263b8e78b..a2f32f733 100644 --- a/testcases/kernel/syscalls/madvise/madvise06.c +++ b/testcases/kernel/syscalls/madvise/madvise06.c @@ -48,7 +48,6 @@ #include #include #include "tst_test.h" -#include "tst_cgroup.h" #define CHUNK_SZ (400*1024*1024L) #define MEM_LIMIT (CHUNK_SZ / 2) @@ -56,8 +55,6 @@ #define PASS_THRESHOLD (CHUNK_SZ / 4) #define PASS_THRESHOLD_KB (PASS_THRESHOLD / 1024) -static const struct tst_cgroup_group *cg; - static const char drop_caches_fname[] = "/proc/sys/vm/drop_caches"; static int pg_sz, stat_refresh_sup; @@ -73,10 +70,10 @@ static void print_cgmem(const char *name) { long ret; - if (!SAFE_CGROUP_HAS(cg, name)) + if (!SAFE_CGROUP_HAS(tst_cgroup, name)) return; - SAFE_CGROUP_SCANF(cg, name, "%ld", &ret); + SAFE_CGROUP_SCANF(tst_cgroup, name, "%ld", &ret); tst_res(TINFO, "\t%s: %ld Kb", name, ret / 1024); } @@ -121,21 +118,18 @@ static void setup(void) check_path("/proc/self/oom_score_adj"); SAFE_FILE_PRINTF("/proc/self/oom_score_adj", "%d", -1000); - tst_cgroup_require("memory", NULL); - cg = tst_cgroup_get_test_group(); - - SAFE_CGROUP_PRINTF(cg, "memory.max", "%ld", MEM_LIMIT); - if (SAFE_CGROUP_HAS(cg, "memory.swap.max")) - SAFE_CGROUP_PRINTF(cg, "memory.swap.max", "%ld", MEMSW_LIMIT); + SAFE_CGROUP_PRINTF(tst_cgroup, "memory.max", "%ld", MEM_LIMIT); + if (SAFE_CGROUP_HAS(tst_cgroup, "memory.swap.max")) + SAFE_CGROUP_PRINTF(tst_cgroup, "memory.swap.max", "%ld", MEMSW_LIMIT); - if (SAFE_CGROUP_HAS(cg, "memory.swappiness")) { - SAFE_CGROUP_PRINT(cg, "memory.swappiness", "60"); + if (SAFE_CGROUP_HAS(tst_cgroup, "memory.swappiness")) { + SAFE_CGROUP_PRINT(tst_cgroup, "memory.swappiness", "60"); } else { check_path("/proc/sys/vm/swappiness"); SAFE_FILE_PRINTF("/proc/sys/vm/swappiness", "%d", 60); } - SAFE_CGROUP_PRINTF(cg, "cgroup.procs", "%d", getpid()); + SAFE_CGROUP_PRINTF(tst_cgroup, "cgroup.procs", "%d", getpid()); meminfo_diag("Initial meminfo, later values are relative to this (except memcg)"); init_swap = SAFE_READ_MEMINFO("SwapTotal:") - SAFE_READ_MEMINFO("SwapFree:"); @@ -149,11 +143,6 @@ static void setup(void) CHUNK_SZ / 1024, CHUNK_SZ / pg_sz, MEM_LIMIT / 1024, PASS_THRESHOLD_KB); } -static void cleanup(void) -{ - tst_cgroup_cleanup(); -} - static void dirty_pages(char *ptr, long size) { long i; @@ -237,7 +226,6 @@ static void test_advice_willneed(void) static struct tst_test test = { .test_all = test_advice_willneed, .setup = setup, - .cleanup = cleanup, .min_kver = "3.10.0", .needs_tmpdir = 1, .needs_root = 1, @@ -245,6 +233,7 @@ static struct tst_test test = { "?/proc/sys/vm/swappiness", NULL }, + .needs_cgroup_ctrls = (const char *const []){ "memory", NULL }, .tags = (const struct tst_tag[]) { {"linux-git", "55231e5c898c"}, {"linux-git", "8de15e920dc8"}, From patchwork Mon Feb 7 14:16:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Palethorpe X-Patchwork-Id: 1589305 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.com header.i=@suse.com header.a=rsa-sha256 header.s=susede1 header.b=F6OrOBkU; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Jsp9k2Fhlz9s8q for ; Tue, 8 Feb 2022 01:16:58 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 2A0B13C9B1B for ; Mon, 7 Feb 2022 15:16:56 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-7.smtp.seeweb.it (in-7.smtp.seeweb.it [IPv6:2001:4b78:1:20::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 1A9FD3C9AF8 for ; Mon, 7 Feb 2022 15:16:37 +0100 (CET) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-7.smtp.seeweb.it (Postfix) with ESMTPS id 7E57920097D for ; Mon, 7 Feb 2022 15:16:36 +0100 (CET) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 2ECB71F388; Mon, 7 Feb 2022 14:16:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1644243396; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zBQvP2fSVZcaG7RHfkoGX1tCtIlUX3sRq4hZVhuiJ6s=; b=F6OrOBkUaZfx8C8FVdwI4JjKHvid6E41Ce5zUSOH5EnQ0Nb7fMkGOZMtpAwmQcoh94QIVG KAB8+C1kILfVvxUjLqjuMcsyOpDq8ZYU6KrWjfNMtL6zWjWnQGafTI+nK82OsJbnO4dIX/ LcTgDEcfjkqwrV9sDuroNeau8Aj+AVU= Received: from g78.suse.de (unknown [10.163.24.138]) by relay2.suse.de (Postfix) with ESMTP id BD0C4A3B88; Mon, 7 Feb 2022 14:16:35 +0000 (UTC) To: ltp@lists.linux.it Date: Mon, 7 Feb 2022 14:16:16 +0000 Message-Id: <20220207141618.2844-4-rpalethorpe@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220207141618.2844-1-rpalethorpe@suse.com> References: <20220207141618.2844-1-rpalethorpe@suse.com> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-7.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-7.smtp.seeweb.it Subject: [LTP] [PATCH v3 3/5] API/cgroup: Add memory.min X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Richard Palethorpe via ltp From: Richard Palethorpe Reply-To: Richard Palethorpe Cc: Richard Palethorpe Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: Richard Palethorpe Reviewed-by: Cyril Hrubis Reviewed-by: Li Wang --- lib/tst_cgroup.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/tst_cgroup.c b/lib/tst_cgroup.c index 51b523b80..bb379caf5 100644 --- a/lib/tst_cgroup.c +++ b/lib/tst_cgroup.c @@ -159,6 +159,7 @@ static const struct cgroup_file cgroup_ctrl_files[] = { static const struct cgroup_file memory_ctrl_files[] = { { "memory.current", "memory.usage_in_bytes", CTRL_MEMORY }, + { "memory.min", NULL, CTRL_MEMORY }, { "memory.max", "memory.limit_in_bytes", CTRL_MEMORY }, { "memory.stat", "memory.stat", CTRL_MEMORY }, { "memory.swappiness", "memory.swappiness", CTRL_MEMORY }, From patchwork Mon Feb 7 14:16:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Palethorpe X-Patchwork-Id: 1589306 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.com header.i=@suse.com header.a=rsa-sha256 header.s=susede1 header.b=R94BKvOr; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Jsp9w0vv4z9s8q for ; Tue, 8 Feb 2022 01:17:08 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 1711A3C9AA6 for ; Mon, 7 Feb 2022 15:17:06 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-5.smtp.seeweb.it (in-5.smtp.seeweb.it [IPv6:2001:4b78:1:20::5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 9D35D3C9B1D for ; Mon, 7 Feb 2022 15:16:37 +0100 (CET) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-5.smtp.seeweb.it (Postfix) with ESMTPS id 26427600768 for ; Mon, 7 Feb 2022 15:16:36 +0100 (CET) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 8C20E210E3; Mon, 7 Feb 2022 14:16:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1644243396; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WAILJJNZx4YwXXwNUukmbOzgUezciJ1a++Z1lhrA59Y=; b=R94BKvOryRbzrux7hrcRvs+qizPphrgWQGc3EoE8EGfOvteI2rzOO2NE9W75NoG4ZGph8g 3X+OR3X97fJRva1egsGfOQcX0qU5grDR6Udz+6zWEqvV2zf6Sjh3BNe/uCbSNsSOvmeWLf 7eUkLrNYIrd4YeGlt9+0HEn2sJSZ6mU= Received: from g78.suse.de (unknown [10.163.24.138]) by relay2.suse.de (Postfix) with ESMTP id 44B74A3B96; Mon, 7 Feb 2022 14:16:36 +0000 (UTC) To: ltp@lists.linux.it Date: Mon, 7 Feb 2022 14:16:17 +0000 Message-Id: <20220207141618.2844-5-rpalethorpe@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220207141618.2844-1-rpalethorpe@suse.com> References: <20220207141618.2844-1-rpalethorpe@suse.com> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-5.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-5.smtp.seeweb.it Subject: [LTP] [PATCH v3 4/5] API/cgroup: Make tst_cgroup_group_mk sprintf like X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Richard Palethorpe via ltp From: Richard Palethorpe Reply-To: Richard Palethorpe Cc: Richard Palethorpe Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Allows the name to be formatted which is trivial because we already copy it into a buffer. Also this removes the init function which is now just unnecessary verbiage. Signed-off-by: Richard Palethorpe Suggested-by: Cyril Hrubis Reviewed-by: Cyril Hrubis Reviewed-by: Li Wang --- include/tst_cgroup.h | 5 +-- lib/tst_cgroup.c | 31 ++++++++----------- .../sched/cfs-scheduler/cfs_bandwidth01.c | 9 +++--- 3 files changed, 21 insertions(+), 24 deletions(-) diff --git a/include/tst_cgroup.h b/include/tst_cgroup.h index 83bdb4b0d..39aa95a88 100644 --- a/include/tst_cgroup.h +++ b/include/tst_cgroup.h @@ -132,8 +132,9 @@ void tst_cgroup_init(void); /* Create a descendant CGroup */ struct tst_cgroup_group * tst_cgroup_group_mk(const struct tst_cgroup_group *const parent, - const char *const group_name) - __attribute__ ((nonnull, warn_unused_result)); + const char *const group_name_fmt, ...) + __attribute__ ((nonnull, warn_unused_result, format (printf, 2, 3))); + const char * tst_cgroup_group_name(const struct tst_cgroup_group *const cg) __attribute__ ((nonnull, warn_unused_result)); diff --git a/lib/tst_cgroup.c b/lib/tst_cgroup.c index bb379caf5..93d374c56 100644 --- a/lib/tst_cgroup.c +++ b/lib/tst_cgroup.c @@ -834,21 +834,6 @@ clear_data: memset(roots, 0, sizeof(roots)); } -__attribute__((nonnull(1))) -static void cgroup_group_init(struct tst_cgroup_group *const cg, - const char *const group_name) -{ - memset(cg, 0, sizeof(*cg)); - - if (!group_name) - return; - - if (strlen(group_name) > NAME_MAX) - tst_brk(TBROK, "Group name is too long"); - - strcpy(cg->group_name, group_name); -} - __attribute__((nonnull(2, 3))) static void cgroup_group_add_dir(const struct tst_cgroup_group *const parent, struct tst_cgroup_group *const cg, @@ -880,18 +865,28 @@ static void cgroup_group_add_dir(const struct tst_cgroup_group *const parent, struct tst_cgroup_group * tst_cgroup_group_mk(const struct tst_cgroup_group *const parent, - const char *const group_name) + const char *const group_name_fmt, ...) { struct tst_cgroup_group *cg; struct cgroup_dir *const *dir; struct cgroup_dir *new_dir; + va_list ap; + size_t name_len; cg = SAFE_MALLOC(sizeof(*cg)); - cgroup_group_init(cg, group_name); + memset(cg, 0, sizeof(*cg)); + + va_start(ap, group_name_fmt); + name_len = vsnprintf(cg->group_name, NAME_MAX, + group_name_fmt, ap); + va_end(ap); + + if (name_len >= NAME_MAX) + tst_brk(TBROK, "CGroup name is too long"); for_each_dir(parent, 0, dir) { new_dir = SAFE_MALLOC(sizeof(*new_dir)); - cgroup_dir_mk(*dir, group_name, new_dir); + cgroup_dir_mk(*dir, cg->group_name, new_dir); cgroup_group_add_dir(parent, cg, new_dir); } diff --git a/testcases/kernel/sched/cfs-scheduler/cfs_bandwidth01.c b/testcases/kernel/sched/cfs-scheduler/cfs_bandwidth01.c index aae1e321b..2c28b83a2 100644 --- a/testcases/kernel/sched/cfs-scheduler/cfs_bandwidth01.c +++ b/testcases/kernel/sched/cfs-scheduler/cfs_bandwidth01.c @@ -56,11 +56,12 @@ static void set_cpu_quota(const struct tst_cgroup_group *const cg, } static void mk_cpu_cgroup(struct tst_cgroup_group **cg, - const struct tst_cgroup_group *const cg_parent, - const char *const cg_child_name, - const float quota_percent) + const struct tst_cgroup_group *const cg_parent, + const char *const cg_child_name, + const float quota_percent) + { - *cg = tst_cgroup_group_mk(cg_parent, cg_child_name); + *cg = tst_cgroup_group_mk(cg_parent, "%s", cg_child_name); set_cpu_quota(*cg, quota_percent); } From patchwork Mon Feb 7 14:16:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Palethorpe X-Patchwork-Id: 1589307 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.com header.i=@suse.com header.a=rsa-sha256 header.s=susede1 header.b=UTUpfNf1; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JspB52ZbVz9s8q for ; Tue, 8 Feb 2022 01:17:17 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 413F43C9B00 for ; Mon, 7 Feb 2022 15:17:15 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-7.smtp.seeweb.it (in-7.smtp.seeweb.it [IPv6:2001:4b78:1:20::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id E63223C9AED for ; Mon, 7 Feb 2022 15:16:37 +0100 (CET) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-7.smtp.seeweb.it (Postfix) with ESMTPS id 39931200985 for ; Mon, 7 Feb 2022 15:16:37 +0100 (CET) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id DD6811F38D; Mon, 7 Feb 2022 14:16:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1644243396; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fn9SORGmSznnOWo4xunOAW2vj6xxZUqrNrUdONh7WSA=; b=UTUpfNf1/qLNN/1hfgfe4UITvnBW7z3PLIss4037BYgCs3ghC2lEBQG/v0bhe3lrdOZctt a6BO+ovL1xU0dZuKM/QYhIX+ewQnz5vJFTTokavnVgOAPyRVHnX6o14bxeTjEQSLJRpFYf cYWpfUWaQ2bGOcGsCpw+dE/W950P3uM= Received: from g78.suse.de (unknown [10.163.24.138]) by relay2.suse.de (Postfix) with ESMTP id 9CB7FA3B89; Mon, 7 Feb 2022 14:16:36 +0000 (UTC) To: ltp@lists.linux.it Date: Mon, 7 Feb 2022 14:16:18 +0000 Message-Id: <20220207141618.2844-6-rpalethorpe@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220207141618.2844-1-rpalethorpe@suse.com> References: <20220207141618.2844-1-rpalethorpe@suse.com> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-7.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-7.smtp.seeweb.it Subject: [LTP] [PATCH v3 5/5] memcontrol03: Copy from kselftest X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Richard Palethorpe via ltp From: Richard Palethorpe Reply-To: Richard Palethorpe Cc: Richard Palethorpe Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Note that the tolerances had to be increased slightly otherwise the test only passed on ext4 in upstream 5.16 on x86_64. In all cases it seems more memory is evicted from C than expected and not enough from D. This may indicate some tuning is possible, but does not look like a serious regression. Signed-off-by: Richard Palethorpe Reviewed-by: Li Wang --- runtest/controllers | 1 + testcases/kernel/controllers/memcg/.gitignore | 1 + .../kernel/controllers/memcg/memcontrol03.c | 253 ++++++++++++++++++ 3 files changed, 255 insertions(+) create mode 100644 testcases/kernel/controllers/memcg/memcontrol03.c diff --git a/runtest/controllers b/runtest/controllers index 09e0107e4..4a6f919af 100644 --- a/runtest/controllers +++ b/runtest/controllers @@ -19,6 +19,7 @@ memcg_control memcg_control_test.sh # kselftest ports memcontrol01 memcontrol01 memcontrol02 memcontrol02 +memcontrol03 memcontrol03 cgroup_fj_function_debug cgroup_fj_function.sh debug cgroup_fj_function_cpuset cgroup_fj_function.sh cpuset diff --git a/testcases/kernel/controllers/memcg/.gitignore b/testcases/kernel/controllers/memcg/.gitignore index f7de40d53..49df1582c 100644 --- a/testcases/kernel/controllers/memcg/.gitignore +++ b/testcases/kernel/controllers/memcg/.gitignore @@ -7,3 +7,4 @@ /stress/memcg_process_stress memcontrol01 memcontrol02 +memcontrol03 diff --git a/testcases/kernel/controllers/memcg/memcontrol03.c b/testcases/kernel/controllers/memcg/memcontrol03.c new file mode 100644 index 000000000..1c14d6766 --- /dev/null +++ b/testcases/kernel/controllers/memcg/memcontrol03.c @@ -0,0 +1,253 @@ +// SPDX-License-Identifier: GPL-2.0 +/*\ + * + * [Description] + * + * Conversion of the third kself test in cgroup/test_memcontrol.c. + * + * Original description: + * "First, this test creates the following hierarchy: + * A memory.min = 50M, memory.max = 200M + * A/B memory.min = 50M, memory.current = 50M + * A/B/C memory.min = 75M, memory.current = 50M + * A/B/D memory.min = 25M, memory.current = 50M + * A/B/E memory.min = 500M, memory.current = 0 + * A/B/F memory.min = 0, memory.current = 50M + * + * Usages are pagecache, but the test keeps a running + * process in every leaf cgroup. + * Then it creates A/G and creates a significant + * memory pressure in it. + * + * A/B memory.current ~= 50M + * A/B/C memory.current ~= 33M + * A/B/D memory.current ~= 17M + * A/B/E memory.current ~= 0 + * + * After that it tries to allocate more than there is unprotected + * memory in A available, and checks that memory.min protects + * pagecache even in this case." + * + * memory.min doesn't appear to exist on V1 so we only test on V2 like + * the selftest. We do test on more file systems, but not tempfs + * becaue it can't evict the page cache without swap. Also we avoid + * filesystems which allocate extra memory for buffer heads. + * + * The tolerances have been increased from the self tests. + */ + +#define _GNU_SOURCE + +#include + +#include "memcontrol_common.h" + +#define TMPDIR "mntdir" + +static struct tst_cgroup_group *trunk_cg[3]; +static struct tst_cgroup_group *leaf_cg[4]; +static int fd = -1; + +enum checkpoints { + CHILD_IDLE, + TEST_DONE, +}; + +enum trunk_cg { + A, + B, + G +}; + +enum leaf_cg { + C, + D, + E, + F +}; + +static void cleanup_sub_groups(void) +{ + size_t i; + + for (i = ARRAY_SIZE(leaf_cg); i > 0; i--) { + if (!leaf_cg[i - 1]) + continue; + + TST_CHECKPOINT_WAKE2(TEST_DONE, + ARRAY_SIZE(leaf_cg) - 1); + tst_reap_children(); + break; + } + + for (i = ARRAY_SIZE(leaf_cg); i > 0; i--) { + if (!leaf_cg[i - 1]) + continue; + + leaf_cg[i - 1] = tst_cgroup_group_rm(leaf_cg[i - 1]); + } + + for (i = ARRAY_SIZE(trunk_cg); i > 0; i--) { + if (!trunk_cg[i - 1]) + continue; + + trunk_cg[i - 1] = tst_cgroup_group_rm(trunk_cg[i - 1]); + } +} + +static void alloc_anon_in_child(const struct tst_cgroup_group *const cg, + const size_t size, const int expect_oom) +{ + int status; + const pid_t pid = SAFE_FORK(); + + if (!pid) { + SAFE_CGROUP_PRINTF(cg, "cgroup.procs", "%d", getpid()); + + tst_res(TINFO, "Child %d in %s: Allocating anon: %"PRIdPTR, + getpid(), tst_cgroup_group_name(cg), size); + alloc_anon(size); + exit(0); + } + + SAFE_WAITPID(pid, &status, 0); + + if (expect_oom && WIFSIGNALED(status) && WTERMSIG(status) == SIGKILL) { + tst_res(TPASS, "Child %d killed by OOM", pid); + return; + } + + if (!expect_oom && WIFEXITED(status) && WEXITSTATUS(status) == 0) { + tst_res(TPASS, "Child %d exited", pid); + return; + } + + tst_res(TFAIL, + "Expected child %d to %s, but instead %s", + pid, + expect_oom ? "be killed" : "exit(0)", + tst_strstatus(status)); +} + +static void alloc_pagecache_in_child(const struct tst_cgroup_group *const cg, + const size_t size) +{ + const pid_t pid = SAFE_FORK(); + + if (pid) { + TST_CHECKPOINT_WAIT(CHILD_IDLE); + return; + } + + SAFE_CGROUP_PRINTF(cg, "cgroup.procs", "%d", getpid()); + + tst_res(TINFO, "Child %d in %s: Allocating pagecache: %"PRIdPTR, + getpid(), tst_cgroup_group_name(cg), size); + alloc_pagecache(fd, size); + + TST_CHECKPOINT_WAKE(CHILD_IDLE); + TST_CHECKPOINT_WAIT(TEST_DONE); + exit(0); +} + +static void test_memcg_min(void) +{ + long c[4]; + unsigned int i; + size_t attempts; + + fd = SAFE_OPEN(TMPDIR"/tmpfile", O_RDWR | O_CREAT, 0600); + trunk_cg[A] = tst_cgroup_group_mk(tst_cgroup, "trunk_A"); + + SAFE_CGROUP_SCANF(trunk_cg[A], "memory.min", "%ld", c); + if (c[0]) { + tst_brk(TCONF, + "memory.min already set to %ld on parent group", c[0]); + } + + SAFE_CGROUP_PRINT(trunk_cg[A], "cgroup.subtree_control", "+memory"); + + SAFE_CGROUP_PRINT(trunk_cg[A], "memory.max", "200M"); + SAFE_CGROUP_PRINT(trunk_cg[A], "memory.swap.max", "0"); + + trunk_cg[B] = tst_cgroup_group_mk(trunk_cg[A], "trunk_B"); + + SAFE_CGROUP_PRINT(trunk_cg[B], "cgroup.subtree_control", "+memory"); + + trunk_cg[G] = tst_cgroup_group_mk(trunk_cg[A], "trunk_G"); + + for (i = 0; i < ARRAY_SIZE(leaf_cg); i++) { + leaf_cg[i] = tst_cgroup_group_mk(trunk_cg[B], + "leaf_%c", 'C' + i); + + if (i == E) + continue; + + alloc_pagecache_in_child(leaf_cg[i], MB(50)); + } + + SAFE_CGROUP_PRINT(trunk_cg[A], "memory.min", "50M"); + SAFE_CGROUP_PRINT(trunk_cg[B], "memory.min", "50M"); + SAFE_CGROUP_PRINT(leaf_cg[C], "memory.min", "75M"); + SAFE_CGROUP_PRINT(leaf_cg[D], "memory.min", "25M"); + SAFE_CGROUP_PRINT(leaf_cg[E], "memory.min", "500M"); + SAFE_CGROUP_PRINT(leaf_cg[F], "memory.min", "0"); + + for (attempts = 0; attempts < 5; attempts++) { + SAFE_CGROUP_SCANF(trunk_cg[B], "memory.current", "%ld", c); + if (values_close(c[0], MB(150), 3)) + break; + + sleep(1); + } + + alloc_anon_in_child(trunk_cg[G], MB(148), 0); + + SAFE_CGROUP_SCANF(trunk_cg[B], "memory.current", "%ld", c); + TST_EXP_EXPR(values_close(c[0], MB(50), 5), + "(A/B memory.current=%ld) ~= %d", c[0], MB(50)); + + for (i = 0; i < ARRAY_SIZE(leaf_cg); i++) + SAFE_CGROUP_SCANF(leaf_cg[i], "memory.current", "%ld", c + i); + + TST_EXP_EXPR(values_close(c[0], MB(33), 20), + "(A/B/C memory.current=%ld) ~= %d", c[0], MB(33)); + TST_EXP_EXPR(values_close(c[1], MB(17), 20), + "(A/B/D memory.current=%ld) ~= %d", c[1], MB(17)); + TST_EXP_EXPR(values_close(c[2], 0, 1), + "(A/B/E memory.current=%ld) ~= 0", c[2]); + + alloc_anon_in_child(trunk_cg[G], MB(170), 1); + + SAFE_CGROUP_SCANF(trunk_cg[B], "memory.current", "%ld", c); + TST_EXP_EXPR(values_close(c[0], MB(50), 5), + "(A/B memory.current=%ld) ~= %d", c[0], MB(50)); + + cleanup_sub_groups(); + SAFE_CLOSE(fd); + SAFE_UNLINK(TMPDIR"/tmpfile"); +} + +static void cleanup(void) +{ + cleanup_sub_groups(); + if (fd > -1) + SAFE_CLOSE(fd); +} + +static struct tst_test test = { + .cleanup = cleanup, + .test_all = test_memcg_min, + .mount_device = 1, + .dev_min_size = 256, + .mntpoint = TMPDIR, + .all_filesystems = 1, + .skip_filesystems = (const char *const[]){ + "exfat", "vfat", "fuse", "ntfs", "tmpfs", NULL + }, + .forks_child = 1, + .needs_root = 1, + .needs_checkpoints = 1, + .needs_cgroup_ver = TST_CGROUP_V2, + .needs_cgroup_ctrls = (const char *const[]){ "memory", NULL }, +};