From patchwork Fri Jun 5 09:13:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Li Wang X-Patchwork-Id: 1303984 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=BnwgKSYS; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (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 ozlabs.org (Postfix) with ESMTPS id 49dcQ21zmFz9sT8 for ; Fri, 5 Jun 2020 19:13:30 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 1C78D3C2F69 for ; Fri, 5 Jun 2020 11:13:27 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-2.smtp.seeweb.it (in-2.smtp.seeweb.it [217.194.8.2]) by picard.linux.it (Postfix) with ESMTP id 8C1603C013A for ; Fri, 5 Jun 2020 11:13:25 +0200 (CEST) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by in-2.smtp.seeweb.it (Postfix) with ESMTP id 8FD6060274E for ; Fri, 5 Jun 2020 11:13:24 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1591348403; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=VPfo+WuL37zYQUx3VMdPIZx6OeHMoc7qoMU7fmIMHoU=; b=BnwgKSYSql47mA+0V8s4ZLs9pMsHD8nKOhZSyGwiYCb6fNzGnKOrk6OS4hLkaYeg+aCt61 ca8D5JM3Kojt2FahHXefh6RLTtjPBEMuEO1oB/PJGWk1b2DMPlzdnEwWWFFTm6X8ufhISq o6uiqiaRc67ptrhvEdTCDnBdszuTPVw= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-397-BpvBhX-OPKOhMC6lEYKXgA-1; Fri, 05 Jun 2020 05:13:20 -0400 X-MC-Unique: BpvBhX-OPKOhMC6lEYKXgA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CFF7D8797F0 for ; Fri, 5 Jun 2020 09:13:19 +0000 (UTC) Received: from liwang-workstation.nay.redhat.com (unknown [10.66.81.246]) by smtp.corp.redhat.com (Postfix) with ESMTP id BEC915D9D7 for ; Fri, 5 Jun 2020 09:13:17 +0000 (UTC) From: Li Wang To: ltp@lists.linux.it Date: Fri, 5 Jun 2020 17:13:13 +0800 Message-Id: <20200605091316.27546-1-liwang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Virus-Scanned: clamav-milter 0.99.2 at in-2.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,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-2.smtp.seeweb.it Subject: [LTP] [PATCH v3 1/4] lib: add new cgroup test API 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: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Many of our LTP tests need Control Group in the configuration, this patch makes cgroup unified mounting at setup phase to be possible. The method is extracted from mem.h with the purpose of extendible for further developing, and trying to compatible the current two versions of cgroup, It's hard to make all APIs be strictly consistent because there are many differences between v1 and v2. But it capsulate the detail of cgroup mounting in high-level functions, which will be easier to use cgroup without considering too much technical thing.    Btw, test get passed on RHEL7(x86_64), RHEL8(ppc64le), Fedora32(x86_64). Signed-off-by: Li Wang --- Notes: v2 --> v3 * fix mount path macros definition * use private memory for paths list * set tst_cgroup_ctl_knob as local variable doc/test-writing-guidelines.txt | 44 +++++ include/tst_cgroup.h | 36 ++++ include/tst_test.h | 1 + lib/newlib_tests/test21.c | 76 +++++++ lib/tst_cgroup.c | 339 ++++++++++++++++++++++++++++++++ 5 files changed, 496 insertions(+) create mode 100644 include/tst_cgroup.h create mode 100644 lib/newlib_tests/test21.c create mode 100644 lib/tst_cgroup.c diff --git a/doc/test-writing-guidelines.txt b/doc/test-writing-guidelines.txt index 93ca506d9..42b360da0 100644 --- a/doc/test-writing-guidelines.txt +++ b/doc/test-writing-guidelines.txt @@ -2053,6 +2053,50 @@ the prefix field of file pointed by path equals to the value passed to this func Also having a similar api pair TST_ASSERT_FILE_INT/STR(path, prefix, val) to assert the field value of file. +2.2.36 Using Control Group +^^^^^^^^^^^^^^^^^^^^^^^^^^ +Some of LTP tests need Control Group in their configuration, tst_cgroup.h provides +APIs to make cgroup unified mounting at setup phase to be possible. The method is +extracted from mem.h with the purpose of extendible for further developing, and +trying to compatible the current two versions of cgroup. + +Considering there are many differences between cgroup v1 and v2, here we capsulate +the detail of cgroup mounting in high-level functions, which will be easier to use +cgroup without caring about too much technical thing.    + +Also, we do cgroup mount/umount work for the different hierarchy automatically. + +[source,c] +------------------------------------------------------------------------------- +#include "tst_test.h" + +static void run(void) +{ + ... + + tst_cgroup_move_current(PATH_TMP_CG_MEM); + tst_cgroup_mem_set_maxbytes(PATH_TMP_CG_MEM, MEMSIZE); + + // do test under cgroup + ... +} + +static void setup(void) +{ + tst_cgroup_mount(TST_CGROUP_MEMCG, PATH_TMP_CG_MEM); +} + +static void cleanup(void) +{ + tst_cgroup_umount(PATH_TMP_CG_MEM); +} + +struct tst_test test = { + .test_all = run, + ... +}; + +------------------------------------------------------------------------------- 2.3 Writing a testcase in shell ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/include/tst_cgroup.h b/include/tst_cgroup.h new file mode 100644 index 000000000..068636803 --- /dev/null +++ b/include/tst_cgroup.h @@ -0,0 +1,36 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2020 Red Hat, Inc. + * Copyright (c) 2020 Li Wang + */ + +#ifndef TST_CGROUP_H +#define TST_CGROUP_H + +#define PATH_TMP_CG_MEM "/tmp/cgroup_mem" +#define PATH_TMP_CG_CST "/tmp/cgroup_cst" + +enum tst_cgroup_ver { + TST_CGROUP_V1 = 1, + TST_CGROUP_V2 = 2, +}; + +enum tst_cgroup_ctrl { + TST_CGROUP_MEMCG = 1, + TST_CGROUP_CPUSET = 2, + /* add cgroup controller */ +}; + +extern char tst_cgroup_mnt_path[PATH_MAX]; +extern char tst_cgroup_new_path[PATH_MAX]; + +enum tst_cgroup_ver tst_cgroup_version(void); +void tst_cgroup_mount(enum tst_cgroup_ctrl ctrl, const char *cgroup_dir); +void tst_cgroup_umount(const char *cgroup_dir); +void tst_cgroup_set_knob(const char *cgroup_dir, const char *knob, long value); +void tst_cgroup_move_current(const char *cgroup_dir); +void tst_cgroup_mem_set_maxbytes(const char *cgroup_dir, long memsz); +int tst_cgroup_mem_swapacct_enabled(const char *cgroup_dir); +void tst_cgroup_mem_set_maxswap(const char *cgroup_dir, long memsz); + +#endif /* TST_CGROUP_H */ diff --git a/include/tst_test.h b/include/tst_test.h index 5bedb4f6f..b84f7b9dd 100644 --- a/include/tst_test.h +++ b/include/tst_test.h @@ -39,6 +39,7 @@ #include "tst_capability.h" #include "tst_hugepage.h" #include "tst_assert.h" +#include "tst_cgroup.h" /* * Reports testcase result. diff --git a/lib/newlib_tests/test21.c b/lib/newlib_tests/test21.c new file mode 100644 index 000000000..c3fa5584e --- /dev/null +++ b/lib/newlib_tests/test21.c @@ -0,0 +1,76 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2020 Red Hat, Inc. + * Copyright (c) 2020 Li Wang + */ + +/* + * Tests tst_cgroup.h APIs + */ + +#include "tst_test.h" +#include "tst_cgroup.h" + +#define PATH_CGROUP1 "/mnt/liwang1" +#define PATH_CGROUP2 "/mnt/liwang2" +#define MEMSIZE 1024 * 1024 + +static void do_test(void) +{ + /* we should assign one or more memory nodes to cpuset.mems + * and cpuset.cpus, otherwise, echo $$ > tasks gives “no space + * left on device” when trying to use cpuset. + * + * Or, setting cgroup.clone_children to 1 can help in automatically + * inheriting memory and node setting from parent cgroup when + * a child cgroup is created. + */ + tst_cgroup_set_knob(PATH_TMP_CG_CST, "../cgroup.clone_children", 1); + + pid_t pid = SAFE_FORK(); + + switch (pid) { + case 0: + tst_cgroup_move_current(PATH_CGROUP1); + tst_cgroup_mem_set_maxbytes(PATH_CGROUP1, MEMSIZE); + tst_cgroup_mem_set_maxswap(PATH_CGROUP1, MEMSIZE); + + tst_cgroup_move_current(PATH_CGROUP2); + + break; + default: + tst_cgroup_move_current(PATH_TMP_CG_CST); + + tst_cgroup_move_current(PATH_TMP_CG_MEM); + tst_cgroup_mem_set_maxbytes(PATH_TMP_CG_MEM, MEMSIZE); + tst_cgroup_mem_set_maxswap(PATH_TMP_CG_MEM, MEMSIZE); + break; + } + + tst_res(TPASS, "Cgroup mount test"); +} + +static void setup(void) +{ + tst_cgroup_mount(TST_CGROUP_MEMCG, PATH_TMP_CG_MEM); + tst_cgroup_mount(TST_CGROUP_MEMCG, PATH_CGROUP1); + + tst_cgroup_mount(TST_CGROUP_CPUSET, PATH_TMP_CG_CST); + tst_cgroup_mount(TST_CGROUP_CPUSET, PATH_CGROUP2); +} + +static void cleanup(void) +{ + tst_cgroup_umount(PATH_TMP_CG_MEM); + tst_cgroup_umount(PATH_CGROUP1); + + tst_cgroup_umount(PATH_TMP_CG_CST); + tst_cgroup_umount(PATH_CGROUP2); +} + +static struct tst_test test = { + .test_all = do_test, + .setup = setup, + .cleanup = cleanup, + .forks_child = 1, +}; diff --git a/lib/tst_cgroup.c b/lib/tst_cgroup.c new file mode 100644 index 000000000..031345a4d --- /dev/null +++ b/lib/tst_cgroup.c @@ -0,0 +1,339 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2020 Red Hat, Inc. + * Copyright (c) 2020 Li Wang + */ + +#define TST_NO_DEFAULT_MAIN + +#include +#include +#include + +#include "tst_test.h" +#include "tst_safe_macros.h" +#include "tst_safe_stdio.h" +#include "tst_cgroup.h" +#include "tst_device.h" + +char tst_cgroup_mnt_path[PATH_MAX]; +char tst_cgroup_new_path[PATH_MAX]; + +static char tst_cgroup_ctl_knob[PATH_MAX]; +static enum tst_cgroup_ver tst_cg_ver; + +struct tst_cgroup_path { + char *mnt_path; + char *new_path; + struct tst_cgroup_path *next; +}; + +static struct tst_cgroup_path *tst_cgroup_paths; + +static int tst_cgroup_check(const char *cgroup) +{ + char line[PATH_MAX]; + FILE *file; + int cg_check = 0; + + file = SAFE_FOPEN("/proc/filesystems", "r"); + while (fgets(line, sizeof(line), file)) { + if (strstr(line, cgroup) != NULL) { + cg_check = 1; + break; + } + } + SAFE_FCLOSE(file); + + return cg_check; +} + +enum tst_cgroup_ver tst_cgroup_version(void) +{ + if (tst_cgroup_check("cgroup2")) { + if (!tst_is_mounted("cgroup2") && tst_is_mounted("cgroup")) + return TST_CGROUP_V1; + else + return TST_CGROUP_V2; + } + + if (tst_cgroup_check("cgroup")) + return TST_CGROUP_V1; + + tst_brk(TCONF, "Cgroup is not configured"); +} + +static void tst_cgroup1_mount(const char *name, const char *option, + const char *mnt_path, const char *new_path) +{ + if (tst_is_mounted(mnt_path)) + goto out; + + SAFE_MKDIR(mnt_path, 0777); + if (mount(name, mnt_path, "cgroup", 0, option) == -1) { + if (errno == ENODEV) { + if (rmdir(mnt_path) == -1) + tst_res(TWARN | TERRNO, "rmdir %s failed", mnt_path); + tst_brk(TCONF, + "Cgroup v1 is not configured in kernel"); + } + tst_brk(TBROK | TERRNO, "mount %s", mnt_path); + } + +out: + SAFE_MKDIR(new_path, 0777); + + tst_res(TINFO, "Cgroup(%s) v1 mount at %s success", option, mnt_path); +} + +static void tst_cgroup2_mount(const char *mnt_path, const char *new_path) +{ + if (tst_is_mounted(mnt_path)) + goto out; + + SAFE_MKDIR(mnt_path, 0777); + if (mount("cgroup2", mnt_path, "cgroup2", 0, NULL) == -1) { + if (errno == ENODEV) { + if (rmdir(mnt_path) == -1) + tst_res(TWARN | TERRNO, "rmdir %s failed", mnt_path); + tst_brk(TCONF, + "Cgroup v2 is not configured in kernel"); + } + tst_brk(TBROK | TERRNO, "mount %s", mnt_path); + } + +out: + SAFE_MKDIR(new_path, 0777); + + tst_res(TINFO, "Cgroup v2 mount at %s success", mnt_path); +} + +static void tst_cgroupN_umount(const char *mnt_path, const char *new_path) +{ + FILE *fp; + int fd; + char s_new[BUFSIZ], s[BUFSIZ], value[BUFSIZ]; + + if (!tst_is_mounted(mnt_path)) + return; + + /* Move all processes in task(v2: cgroup.procs) to its parent node. */ + if (tst_cg_ver & TST_CGROUP_V1) + sprintf(s, "%s/tasks", mnt_path); + if (tst_cg_ver & TST_CGROUP_V2) + sprintf(s, "%s/cgroup.procs", mnt_path); + + fd = open(s, O_WRONLY); + if (fd == -1) + tst_res(TWARN | TERRNO, "open %s", s); + + if (tst_cg_ver & TST_CGROUP_V1) + snprintf(s_new, BUFSIZ, "%s/tasks", new_path); + if (tst_cg_ver & TST_CGROUP_V2) + snprintf(s_new, BUFSIZ, "%s/cgroup.procs", new_path); + + fp = fopen(s_new, "r"); + if (fp == NULL) + tst_res(TWARN | TERRNO, "fopen %s", s_new); + if ((fd != -1) && (fp != NULL)) { + while (fgets(value, BUFSIZ, fp) != NULL) + if (write(fd, value, strlen(value) - 1) + != (ssize_t)strlen(value) - 1) + tst_res(TWARN | TERRNO, "write %s", s); + } + if (fd != -1) + close(fd); + if (fp != NULL) + fclose(fp); + if (rmdir(new_path) == -1) + tst_res(TWARN | TERRNO, "rmdir %s", new_path); + if (umount(mnt_path) == -1) + tst_res(TWARN | TERRNO, "umount %s", mnt_path); + if (rmdir(mnt_path) == -1) + tst_res(TWARN | TERRNO, "rmdir %s", mnt_path); + + if (tst_cg_ver & TST_CGROUP_V1) + tst_res(TINFO, "Cgroup v1 unmount success"); + if (tst_cg_ver & TST_CGROUP_V2) + tst_res(TINFO, "Cgroup v2 unmount success"); +} + +static void tst_cgroup_set_path(const char *cgroup_dir) +{ + struct tst_cgroup_path *tst_cgroup_path, *a; + + if (!cgroup_dir) + tst_brk(TBROK, "Invalid cgroup dir, plese check cgroup_dir"); + + sprintf(tst_cgroup_mnt_path, "%s", cgroup_dir); + sprintf(tst_cgroup_new_path, "%s/ltp_%d", cgroup_dir, rand()); + + /* To store cgroup path in the 'path' list */ + tst_cgroup_path = SAFE_MMAP(NULL, (sizeof(struct tst_cgroup_path)), + PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + tst_cgroup_path->mnt_path = SAFE_MMAP(NULL, (strlen(tst_cgroup_mnt_path) + 1), + PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + tst_cgroup_path->new_path = SAFE_MMAP(NULL, (strlen(tst_cgroup_new_path) + 1), + PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + + if (!tst_cgroup_paths) { + tst_cgroup_paths = tst_cgroup_path; + } else { + a = tst_cgroup_paths; + do { + if (!a->next) { + a->next = tst_cgroup_path; + break; + } + a = a->next; + } while (a); + } + + sprintf(tst_cgroup_path->mnt_path, "%s", tst_cgroup_mnt_path); + sprintf(tst_cgroup_path->new_path, "%s", tst_cgroup_new_path); +} + +static void tst_cgroup_get_path(const char *cgroup_dir) +{ + struct tst_cgroup_path *a = tst_cgroup_paths; + + while (strcmp(a->mnt_path, cgroup_dir) != 0){ + a = a->next; + }; + + sprintf(tst_cgroup_mnt_path, "%s", a->mnt_path); + sprintf(tst_cgroup_new_path, "%s", a->new_path); +} + +static void tst_cgroup_del_path(const char *cgroup_dir) +{ + struct tst_cgroup_path *a, *b; + a = b = tst_cgroup_paths; + + while (strcmp(b->mnt_path, cgroup_dir) != 0){ + a = b; + b = b->next; + }; + + if (b == tst_cgroup_paths) + tst_cgroup_paths = b->next; + else + a->next = b->next; + + SAFE_MUNMAP(b->mnt_path, sizeof(b->mnt_path)); + SAFE_MUNMAP(b->new_path, sizeof(b->new_path)); + SAFE_MUNMAP(b, sizeof(b)); +} + +void tst_cgroup_mount(enum tst_cgroup_ctrl ctrl, const char *cgroup_dir) +{ + tst_cg_ver = tst_cgroup_version(); + + tst_cgroup_set_path(cgroup_dir); + + if (tst_cg_ver & TST_CGROUP_V1) { + switch(ctrl) { + case TST_CGROUP_MEMCG: + tst_cgroup1_mount("memcg", "memory", tst_cgroup_mnt_path, tst_cgroup_new_path); + break; + case TST_CGROUP_CPUSET: + tst_cgroup1_mount("cpusetcg", "cpuset", tst_cgroup_mnt_path, tst_cgroup_new_path); + break; + default: + tst_brk(TBROK, "Invalid cgroup controller: %d", ctrl); + } + } + + if (tst_cg_ver & TST_CGROUP_V2) { + tst_cgroup2_mount(tst_cgroup_mnt_path, tst_cgroup_new_path); + + switch(ctrl) { + case TST_CGROUP_MEMCG: + sprintf(tst_cgroup_ctl_knob, "%s/cgroup.subtree_control", tst_cgroup_mnt_path); + SAFE_FILE_PRINTF(tst_cgroup_ctl_knob, "%s", "+memory"); + break; + case TST_CGROUP_CPUSET: + tst_brk(TCONF, "Cgroup v2 hasn't achieve cpuset subsystem"); + break; + default: + tst_brk(TBROK, "Invalid cgroup controller: %d", ctrl); + } + } +} + +void tst_cgroup_umount(const char *cgroup_dir) +{ + tst_cgroup_get_path(cgroup_dir); + tst_cgroup_del_path(cgroup_dir); + tst_cgroupN_umount(tst_cgroup_mnt_path, tst_cgroup_new_path); +} + +void tst_cgroup_set_knob(const char *cgroup_dir, const char *knob, long value) +{ + tst_cgroup_get_path(cgroup_dir); + + sprintf(tst_cgroup_ctl_knob, "%s/%s", tst_cgroup_new_path, knob); + SAFE_FILE_PRINTF(tst_cgroup_ctl_knob, "%ld", value); +} + +void tst_cgroup_move_current(const char *cgroup_dir) +{ + if (tst_cg_ver & TST_CGROUP_V1) + tst_cgroup_set_knob(cgroup_dir, "tasks", getpid()); + + if (tst_cg_ver & TST_CGROUP_V2) + tst_cgroup_set_knob(cgroup_dir, "cgroup.procs", getpid()); +} + +void tst_cgroup_mem_set_maxbytes(const char *cgroup_dir, long memsz) +{ + if (tst_cg_ver & TST_CGROUP_V1) + tst_cgroup_set_knob(cgroup_dir, "memory.limit_in_bytes", memsz); + + if (tst_cg_ver & TST_CGROUP_V2) + tst_cgroup_set_knob(cgroup_dir, "memory.max", memsz); +} + +int tst_cgroup_mem_swapacct_enabled(const char *cgroup_dir) +{ + tst_cgroup_get_path(cgroup_dir); + + if (tst_cg_ver & TST_CGROUP_V1) { + sprintf(tst_cgroup_ctl_knob, "%s/%s", + tst_cgroup_new_path, "/memory.memsw.limit_in_bytes"); + + if ((access(tst_cgroup_ctl_knob, F_OK) == -1)) { + if (errno == ENOENT) + tst_res(TCONF, "memcg swap accounting is disabled"); + else + tst_brk(TBROK | TERRNO, "failed to access %s", tst_cgroup_ctl_knob); + } else { + return 1; + } + } + + if (tst_cg_ver & TST_CGROUP_V2) { + sprintf(tst_cgroup_ctl_knob, "%s/%s", + tst_cgroup_new_path, "/memory.swap.max"); + + if ((access(tst_cgroup_ctl_knob, F_OK) == -1)) { + if (errno == ENOENT) + tst_res(TCONF, "memcg swap accounting is disabled"); + else + tst_brk(TBROK | TERRNO, "failed to access %s", tst_cgroup_ctl_knob); + } else { + return 1; + } + } + + return 0; +} + +void tst_cgroup_mem_set_maxswap(const char *cgroup_dir, long memsz) +{ + if (tst_cg_ver & TST_CGROUP_V1) + tst_cgroup_set_knob(cgroup_dir, "memory.memsw.limit_in_bytes", memsz); + + if (tst_cg_ver & TST_CGROUP_V2) + tst_cgroup_set_knob(cgroup_dir, "memory.swap.max", memsz); +} From patchwork Fri Jun 5 09:13:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Wang X-Patchwork-Id: 1303987 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=T2Wj26ju; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 49dcQd3RdTz9sT8 for ; Fri, 5 Jun 2020 19:14:01 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id A32133C2F7B for ; Fri, 5 Jun 2020 11:13:58 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-2.smtp.seeweb.it (in-2.smtp.seeweb.it [IPv6:2001:4b78:1:20::2]) by picard.linux.it (Postfix) with ESMTP id ADE753C2F81 for ; Fri, 5 Jun 2020 11:13:28 +0200 (CEST) Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by in-2.smtp.seeweb.it (Postfix) with ESMTP id EA5A960111C for ; Fri, 5 Jun 2020 11:13:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1591348406; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ryx2pFWWjuUBaM6iymPCBF/5ZXJShHM9ZCx+kpcmg1o=; b=T2Wj26judnmFoMEFwskpl5zHGMnCl1Na9fW/kooNuUSbytgtYhufPrVSbp6s1YGheSp3kr XdPWtM6JqrbCdP+atglGnUL1ew+4FDytayWyoeR/UzpLKXYFNuu11vq28XwSvn9CziQIkC 6wlDtHEX0nwWbDT6xnhn3O3VByIusmo= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-169-wHd6bTrIMMSk4bPC67tk3A-1; Fri, 05 Jun 2020 05:13:22 -0400 X-MC-Unique: wHd6bTrIMMSk4bPC67tk3A-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2BE2E80B725 for ; Fri, 5 Jun 2020 09:13:21 +0000 (UTC) Received: from liwang-workstation.nay.redhat.com (unknown [10.66.81.246]) by smtp.corp.redhat.com (Postfix) with ESMTP id 59EA55D9D7 for ; Fri, 5 Jun 2020 09:13:20 +0000 (UTC) From: Li Wang To: ltp@lists.linux.it Date: Fri, 5 Jun 2020 17:13:14 +0800 Message-Id: <20200605091316.27546-2-liwang@redhat.com> In-Reply-To: <20200605091316.27546-1-liwang@redhat.com> References: <20200605091316.27546-1-liwang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Virus-Scanned: clamav-milter 0.99.2 at in-2.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,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-2.smtp.seeweb.it Subject: [LTP] [PATCH v3 2/4] mem: take use of new cgroup API 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: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" For issue #611: https://github.com/linux-test-project/ltp/issues/611 Signed-off-by: Li Wang --- testcases/kernel/mem/cpuset/cpuset01.c | 19 +++++++------ testcases/kernel/mem/include/mem.h | 1 + testcases/kernel/mem/ksm/ksm02.c | 10 +++---- testcases/kernel/mem/ksm/ksm03.c | 12 +++----- testcases/kernel/mem/ksm/ksm04.c | 19 +++++-------- testcases/kernel/mem/lib/mem.c | 8 ++---- testcases/kernel/mem/oom/oom03.c | 22 ++++----------- testcases/kernel/mem/oom/oom04.c | 12 ++++---- testcases/kernel/mem/oom/oom05.c | 38 ++++++++------------------ 9 files changed, 52 insertions(+), 89 deletions(-) diff --git a/testcases/kernel/mem/cpuset/cpuset01.c b/testcases/kernel/mem/cpuset/cpuset01.c index 853f7fe55..77f6e4dca 100644 --- a/testcases/kernel/mem/cpuset/cpuset01.c +++ b/testcases/kernel/mem/cpuset/cpuset01.c @@ -51,11 +51,11 @@ static void test_cpuset(void) unsigned long nmask[MAXNODES / BITS_PER_LONG] = { 0 }; char mems[BUFSIZ], buf[BUFSIZ]; - read_cpuset_files(CPATH, "cpus", buf); - write_cpuset_files(CPATH_NEW, "cpus", buf); - read_cpuset_files(CPATH, "mems", mems); - write_cpuset_files(CPATH_NEW, "mems", mems); - SAFE_FILE_PRINTF(CPATH_NEW "/tasks", "%d", getpid()); + tst_cgroup_move_current(PATH_TMP_CG_CST); + read_cpuset_files(tst_cgroup_mnt_path, "cpus", buf); + write_cpuset_files(tst_cgroup_new_path, "cpus", buf); + read_cpuset_files(tst_cgroup_mnt_path, "mems", mems); + write_cpuset_files(tst_cgroup_new_path, "mems", mems); child = SAFE_FORK(); if (child == 0) { @@ -70,9 +70,9 @@ static void test_cpuset(void) } snprintf(buf, BUFSIZ, "%d", nodes[0]); - write_cpuset_files(CPATH_NEW, "mems", buf); + write_cpuset_files(tst_cgroup_new_path, "mems", buf); snprintf(buf, BUFSIZ, "%d", nodes[1]); - write_cpuset_files(CPATH_NEW, "mems", buf); + write_cpuset_files(tst_cgroup_new_path, "mems", buf); SAFE_WAITPID(child, &status, WUNTRACED | WCONTINUED); if (WEXITSTATUS(status) != 0) { @@ -85,7 +85,7 @@ static void test_cpuset(void) static void setup(void) { - mount_mem("cpuset", "cpuset", NULL, CPATH, CPATH_NEW); + tst_cgroup_mount(TST_CGROUP_CPUSET, PATH_TMP_CG_CST); ncpus = count_cpu(); if (get_allowed_nodes_arr(NH_MEMS | NH_CPUS, &nnodes, &nodes) < 0) tst_brk(TBROK | TERRNO, "get_allowed_nodes_arr"); @@ -95,7 +95,7 @@ static void setup(void) static void cleanup(void) { - umount_mem(CPATH, CPATH_NEW); + tst_cgroup_umount(PATH_TMP_CG_CST); } static void sighandler(int signo LTP_ATTRIBUTE_UNUSED) @@ -183,6 +183,7 @@ static long count_cpu(void) static struct tst_test test = { .needs_root = 1, + .forks_child = 1, .setup = setup, .cleanup = cleanup, .test_all = test_cpuset, diff --git a/testcases/kernel/mem/include/mem.h b/testcases/kernel/mem/include/mem.h index cce9c0497..f553651c2 100644 --- a/testcases/kernel/mem/include/mem.h +++ b/testcases/kernel/mem/include/mem.h @@ -2,6 +2,7 @@ #define _MEM_H #include "config.h" #include "tst_test.h" +#include "tst_cgroup.h" #include "ksm_helper.h" #if defined(__powerpc__) || defined(__powerpc64__) diff --git a/testcases/kernel/mem/ksm/ksm02.c b/testcases/kernel/mem/ksm/ksm02.c index 3d4c19deb..72e650a53 100644 --- a/testcases/kernel/mem/ksm/ksm02.c +++ b/testcases/kernel/mem/ksm/ksm02.c @@ -59,13 +59,13 @@ #ifdef HAVE_NUMA_V2 #include -static int cpuset_mounted; - static void verify_ksm(void) { unsigned long nmask[MAXNODES / BITS_PER_LONG] = { 0 }; unsigned int node; + tst_cgroup_move_current(PATH_TMP_CG_CST); + node = get_a_numa_node(); set_node(nmask, node); @@ -88,8 +88,7 @@ static void cleanup(void) FILE_PRINTF(PATH_KSM "merge_across_nodes", "%d", merge_across_nodes); - if (cpuset_mounted) - umount_mem(CPATH, CPATH_NEW); + tst_cgroup_umount(PATH_TMP_CG_CST); } static void setup(void) @@ -105,8 +104,7 @@ static void setup(void) SAFE_FILE_PRINTF(PATH_KSM "merge_across_nodes", "1"); } - mount_mem("cpuset", "cpuset", NULL, CPATH, CPATH_NEW); - cpuset_mounted = 1; + tst_cgroup_mount(TST_CGROUP_CPUSET, PATH_TMP_CG_CST); } static struct tst_test test = { diff --git a/testcases/kernel/mem/ksm/ksm03.c b/testcases/kernel/mem/ksm/ksm03.c index 0e5131654..cc3695e95 100644 --- a/testcases/kernel/mem/ksm/ksm03.c +++ b/testcases/kernel/mem/ksm/ksm03.c @@ -59,11 +59,10 @@ #include "mem.h" #include "ksm_common.h" -static int memcg_mounted; - static void verify_ksm(void) { - write_memcg(); + tst_cgroup_move_current(PATH_TMP_CG_MEM); + tst_cgroup_mem_set_maxbytes(PATH_TMP_CG_MEM, TESTMEM); create_same_memory(size, num, unit); } @@ -79,8 +78,7 @@ static void setup(void) } parse_ksm_options(opt_sizestr, &size, opt_numstr, &num, opt_unitstr, &unit); - mount_mem("memcg", "cgroup", "memory", MEMCG_PATH, MEMCG_PATH_NEW); - memcg_mounted = 1; + tst_cgroup_mount(TST_CGROUP_MEMCG, PATH_TMP_CG_MEM); } static void cleanup(void) @@ -88,9 +86,7 @@ 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); - - if (memcg_mounted) - umount_mem(MEMCG_PATH, MEMCG_PATH_NEW); + tst_cgroup_umount(PATH_TMP_CG_MEM); } static struct tst_test test = { diff --git a/testcases/kernel/mem/ksm/ksm04.c b/testcases/kernel/mem/ksm/ksm04.c index e393dbd40..cafab479c 100644 --- a/testcases/kernel/mem/ksm/ksm04.c +++ b/testcases/kernel/mem/ksm/ksm04.c @@ -59,9 +59,6 @@ #ifdef HAVE_NUMA_V2 #include -static int cpuset_mounted; -static int memcg_mounted; - static void verify_ksm(void) { unsigned long nmask[MAXNODES / BITS_PER_LONG] = { 0 }; @@ -70,7 +67,8 @@ static void verify_ksm(void) node = get_a_numa_node(); set_node(nmask, node); - write_memcg(); + tst_cgroup_move_current(PATH_TMP_CG_MEM); + tst_cgroup_mem_set_maxbytes(PATH_TMP_CG_MEM, TESTMEM); if (set_mempolicy(MPOL_BIND, nmask, MAXNODES) == -1) { if (errno != ENOSYS) @@ -81,6 +79,7 @@ static void verify_ksm(void) } create_same_memory(size, num, unit); + tst_cgroup_move_current(PATH_TMP_CG_CST); write_cpusets(node); create_same_memory(size, num, unit); } @@ -91,10 +90,8 @@ static void cleanup(void) FILE_PRINTF(PATH_KSM "merge_across_nodes", "%d", merge_across_nodes); - if (cpuset_mounted) - umount_mem(CPATH, CPATH_NEW); - if (memcg_mounted) - umount_mem(MEMCG_PATH, MEMCG_PATH_NEW); + tst_cgroup_umount(PATH_TMP_CG_MEM); + tst_cgroup_umount(PATH_TMP_CG_CST); } static void setup(void) @@ -110,10 +107,8 @@ static void setup(void) parse_ksm_options(opt_sizestr, &size, opt_numstr, &num, opt_unitstr, &unit); - mount_mem("cpuset", "cpuset", NULL, CPATH, CPATH_NEW); - cpuset_mounted = 1; - mount_mem("memcg", "cgroup", "memory", MEMCG_PATH, MEMCG_PATH_NEW); - memcg_mounted = 1; + tst_cgroup_mount(TST_CGROUP_MEMCG, PATH_TMP_CG_MEM); + tst_cgroup_mount(TST_CGROUP_CPUSET, PATH_TMP_CG_CST); } static struct tst_test test = { diff --git a/testcases/kernel/mem/lib/mem.c b/testcases/kernel/mem/lib/mem.c index eca4c61c8..45f155922 100644 --- a/testcases/kernel/mem/lib/mem.c +++ b/testcases/kernel/mem/lib/mem.c @@ -692,7 +692,7 @@ void write_cpusets(long nd) char cpus[BUFSIZ] = ""; snprintf(buf, BUFSIZ, "%ld", nd); - write_cpuset_files(CPATH_NEW, "mems", buf); + write_cpuset_files(tst_cgroup_new_path, "mems", buf); gather_node_cpus(cpus, nd); /* @@ -701,14 +701,12 @@ void write_cpusets(long nd) * the value of cpuset.cpus. */ if (strlen(cpus) != 0) { - write_cpuset_files(CPATH_NEW, "cpus", cpus); + write_cpuset_files(tst_cgroup_new_path, "cpus", cpus); } else { tst_res(TINFO, "No CPUs in the node%ld; " "using only CPU0", nd); - write_cpuset_files(CPATH_NEW, "cpus", "0"); + write_cpuset_files(tst_cgroup_new_path, "cpus", "0"); } - - SAFE_FILE_PRINTF(CPATH_NEW "/tasks", "%d", getpid()); } void umount_mem(char *path, char *path_new) diff --git a/testcases/kernel/mem/oom/oom03.c b/testcases/kernel/mem/oom/oom03.c index ce0b34c31..fc860c660 100644 --- a/testcases/kernel/mem/oom/oom03.c +++ b/testcases/kernel/mem/oom/oom03.c @@ -36,27 +36,19 @@ #ifdef HAVE_NUMA_V2 -static int memcg_mounted; - static void verify_oom(void) { #ifdef TST_ABI32 tst_brk(TCONF, "test is not designed for 32-bit system."); #endif - SAFE_FILE_PRINTF(MEMCG_PATH_NEW "/tasks", "%d", getpid()); - SAFE_FILE_PRINTF(MEMCG_LIMIT, "%ld", TESTMEM); + tst_cgroup_move_current(PATH_TMP_CG_MEM); + tst_cgroup_mem_set_maxbytes(PATH_TMP_CG_MEM, TESTMEM); testoom(0, 0, ENOMEM, 1); - if (access(MEMCG_SW_LIMIT, F_OK) == -1) { - if (errno == ENOENT) - tst_res(TCONF, - "memcg swap accounting is disabled"); - else - tst_brk(TBROK | TERRNO, "access"); - } else { - SAFE_FILE_PRINTF(MEMCG_SW_LIMIT, "%ld", TESTMEM); + if (tst_cgroup_mem_swapacct_enabled(PATH_TMP_CG_MEM)) { + tst_cgroup_mem_set_maxswap(PATH_TMP_CG_MEM, TESTMEM); testoom(0, 1, ENOMEM, 1); } @@ -73,16 +65,14 @@ static void setup(void) { overcommit = get_sys_tune("overcommit_memory"); set_sys_tune("overcommit_memory", 1, 1); - mount_mem("memcg", "cgroup", "memory", MEMCG_PATH, MEMCG_PATH_NEW); - memcg_mounted = 1; + tst_cgroup_mount(TST_CGROUP_MEMCG, PATH_TMP_CG_MEM); } static void cleanup(void) { if (overcommit != -1) set_sys_tune("overcommit_memory", overcommit, 0); - if (memcg_mounted) - umount_mem(MEMCG_PATH, MEMCG_PATH_NEW); + tst_cgroup_umount(PATH_TMP_CG_MEM); } static struct tst_test test = { diff --git a/testcases/kernel/mem/oom/oom04.c b/testcases/kernel/mem/oom/oom04.c index 7185ef973..c1c809b63 100644 --- a/testcases/kernel/mem/oom/oom04.c +++ b/testcases/kernel/mem/oom/oom04.c @@ -36,14 +36,14 @@ #ifdef HAVE_NUMA_V2 -static int cpuset_mounted; - static void verify_oom(void) { #ifdef TST_ABI32 tst_brk(TCONF, "test is not designed for 32-bit system."); #endif + tst_cgroup_move_current(PATH_TMP_CG_CST); + tst_res(TINFO, "OOM on CPUSET..."); testoom(0, 0, ENOMEM, 1); @@ -53,7 +53,7 @@ static void verify_oom(void) * is in charge of cpuset.memory_migrate, we can write * 1 to cpuset.memory_migrate to enable the migration. */ - write_cpuset_files(CPATH_NEW, "memory_migrate", "1"); + write_cpuset_files(tst_cgroup_new_path, "memory_migrate", "1"); tst_res(TINFO, "OOM on CPUSET with mem migrate:"); testoom(0, 0, ENOMEM, 1); } @@ -69,8 +69,7 @@ static void setup(void) overcommit = get_sys_tune("overcommit_memory"); set_sys_tune("overcommit_memory", 1, 1); - mount_mem("cpuset", "cpuset", NULL, CPATH, CPATH_NEW); - cpuset_mounted = 1; + tst_cgroup_mount(TST_CGROUP_CPUSET, PATH_TMP_CG_CST); /* * Some nodes do not contain memory, so use @@ -89,8 +88,7 @@ static void cleanup(void) { if (overcommit != -1) set_sys_tune("overcommit_memory", overcommit, 0); - if (cpuset_mounted) - umount_mem(CPATH, CPATH_NEW); + tst_cgroup_umount(PATH_TMP_CG_CST); } static struct tst_test test = { diff --git a/testcases/kernel/mem/oom/oom05.c b/testcases/kernel/mem/oom/oom05.c index db24df6de..ef70864ff 100644 --- a/testcases/kernel/mem/oom/oom05.c +++ b/testcases/kernel/mem/oom/oom05.c @@ -36,18 +36,16 @@ #ifdef HAVE_NUMA_V2 -static int memcg_mounted; -static int cpuset_mounted; - static void verify_oom(void) { - int swap_acc_on = 1; - #ifdef TST_ABI32 tst_brk(TCONF, "test is not designed for 32-bit system."); #endif tst_res(TINFO, "OOM on CPUSET & MEMCG..."); + tst_cgroup_move_current(PATH_TMP_CG_MEM); + tst_cgroup_move_current(PATH_TMP_CG_CST); + tst_cgroup_mem_set_maxbytes(PATH_TMP_CG_MEM, TESTMEM); testoom(0, 0, ENOMEM, 1); /* @@ -56,29 +54,22 @@ static void verify_oom(void) * 1 to cpuset.memory_migrate to enable the migration. */ if (is_numa(NULL, NH_MEMS, 2)) { - write_cpuset_files(CPATH_NEW, "memory_migrate", "1"); + tst_cgroup_move_current(PATH_TMP_CG_CST); + write_cpuset_files(tst_cgroup_new_path, "memory_migrate", "1"); tst_res(TINFO, "OOM on CPUSET & MEMCG with " "cpuset.memory_migrate=1"); testoom(0, 0, ENOMEM, 1); } - if (access(MEMCG_SW_LIMIT, F_OK) == -1) { - if (errno == ENOENT) { - tst_res(TCONF, "memcg swap accounting is disabled"); - swap_acc_on = 0; - } else - tst_brk(TBROK|TERRNO, "access"); - } - - if (swap_acc_on) { + if (tst_cgroup_mem_swapacct_enabled(PATH_TMP_CG_MEM)) { tst_res(TINFO, "OOM on CPUSET & MEMCG with " "special memswap limitation:"); - SAFE_FILE_PRINTF(MEMCG_SW_LIMIT, "%ld", TESTMEM); + tst_cgroup_mem_set_maxswap(PATH_TMP_CG_MEM, TESTMEM); testoom(0, 0, ENOMEM, 1); tst_res(TINFO, "OOM on CPUSET & MEMCG with " "disabled memswap limitation:"); - SAFE_FILE_PRINTF(MEMCG_SW_LIMIT, "-1"); + tst_cgroup_mem_set_maxswap(PATH_TMP_CG_MEM, -1); testoom(0, 0, ENOMEM, 1); } } @@ -93,11 +84,8 @@ void setup(void) overcommit = get_sys_tune("overcommit_memory"); set_sys_tune("overcommit_memory", 1, 1); - mount_mem("memcg", "cgroup", "memory", MEMCG_PATH, MEMCG_PATH_NEW); - memcg_mounted = 1; - mount_mem("cpuset", "cpuset", NULL, CPATH, CPATH_NEW); - cpuset_mounted = 1; - write_memcg(); + tst_cgroup_mount(TST_CGROUP_MEMCG, PATH_TMP_CG_MEM); + tst_cgroup_mount(TST_CGROUP_CPUSET, PATH_TMP_CG_CST); /* * Some nodes do not contain memory, so use @@ -116,10 +104,8 @@ void cleanup(void) { if (overcommit != -1) set_sys_tune("overcommit_memory", overcommit, 0); - if (cpuset_mounted) - umount_mem(CPATH, CPATH_NEW); - if (memcg_mounted) - umount_mem(MEMCG_PATH, MEMCG_PATH_NEW); + tst_cgroup_umount(PATH_TMP_CG_MEM); + tst_cgroup_umount(PATH_TMP_CG_CST); } static struct tst_test test = { From patchwork Fri Jun 5 09:13:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Wang X-Patchwork-Id: 1303985 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=KhP6b2B0; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 49dcQG0Fw4z9sSJ for ; Fri, 5 Jun 2020 19:13:41 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 3BBA43C2F7B for ; Fri, 5 Jun 2020 11:13:38 +0200 (CEST) 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]) by picard.linux.it (Postfix) with ESMTP id 6D4DF3C2F5F for ; Fri, 5 Jun 2020 11:13:26 +0200 (CEST) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by in-5.smtp.seeweb.it (Postfix) with ESMTP id 7B47A61709C for ; Fri, 5 Jun 2020 11:12:48 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1591348404; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=H7oHTENROxwIMUULmjIzur4bL/8t1MmqrB4fpcavMAA=; b=KhP6b2B0DySmocr0i6IR7mDLf52CnR2jm5I8J01v1ifHjkX/unKh1EZC3SLvy+JXtP7beY OgQuZhwmSrjXplJQjnXdLFdW+tfyo7eR0CXdq/HLqD0dnnQheoAlOM3AR0Fb1UqauyTc96 zLtOBP2FgCyl6yazFZcIX1Aue4z7Hd4= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-131-RRNhaGDPNomB2bicYVC9Wg-1; Fri, 05 Jun 2020 05:13:23 -0400 X-MC-Unique: RRNhaGDPNomB2bicYVC9Wg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 79DF6800685 for ; Fri, 5 Jun 2020 09:13:22 +0000 (UTC) Received: from liwang-workstation.nay.redhat.com (unknown [10.66.81.246]) by smtp.corp.redhat.com (Postfix) with ESMTP id A93F45D9D7 for ; Fri, 5 Jun 2020 09:13:21 +0000 (UTC) From: Li Wang To: ltp@lists.linux.it Date: Fri, 5 Jun 2020 17:13:15 +0800 Message-Id: <20200605091316.27546-3-liwang@redhat.com> In-Reply-To: <20200605091316.27546-1-liwang@redhat.com> References: <20200605091316.27546-1-liwang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Virus-Scanned: clamav-milter 0.99.2 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,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-5.smtp.seeweb.it Subject: [LTP] [PATCH v3 3/4] mem: remove the old cgroup API 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: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: Li Wang --- testcases/kernel/mem/include/mem.h | 16 +-------- testcases/kernel/mem/lib/mem.c | 58 ------------------------------ 2 files changed, 1 insertion(+), 73 deletions(-) diff --git a/testcases/kernel/mem/include/mem.h b/testcases/kernel/mem/include/mem.h index f553651c2..0e089fae2 100644 --- a/testcases/kernel/mem/include/mem.h +++ b/testcases/kernel/mem/include/mem.h @@ -60,24 +60,10 @@ void test_ksm_merge_across_nodes(unsigned long nr_pages); void check_hugepage(void); void write_memcg(void); -/* cpuset/memcg */ - -#define CPATH "/dev/cpuset" -#define CPATH_NEW CPATH "/1" -#define MEMCG_PATH "/dev/cgroup" -#define MEMCG_PATH_NEW MEMCG_PATH "/1" -#define MEMCG_LIMIT MEMCG_PATH_NEW "/memory.limit_in_bytes" -#define MEMCG_SW_LIMIT MEMCG_PATH_NEW "/memory.memsw.limit_in_bytes" -#if HAVE_SYS_EVENTFD_H -#define PATH_OOMCTRL MEMCG_PATH_NEW "/memory.oom_control" -#define PATH_EVTCTRL MEMCG_PATH_NEW "/cgroup.event_control" -#endif - +/* cpuset/memcg - include/tst_cgroup.h */ void read_cpuset_files(char *prefix, char *filename, char *retbuf); void write_cpuset_files(char *prefix, char *filename, char *buf); void write_cpusets(long nd); -void mount_mem(char *name, char *fs, char *options, char *path, char *path_new); -void umount_mem(char *path, char *path_new); /* shared */ unsigned int get_a_numa_node(void); diff --git a/testcases/kernel/mem/lib/mem.c b/testcases/kernel/mem/lib/mem.c index 45f155922..7a911f8b3 100644 --- a/testcases/kernel/mem/lib/mem.c +++ b/testcases/kernel/mem/lib/mem.c @@ -312,13 +312,6 @@ void check_hugepage(void) tst_brk(TCONF, "Huge page is not supported."); } -void write_memcg(void) -{ - SAFE_FILE_PRINTF(MEMCG_LIMIT, "%ld", TESTMEM); - - SAFE_FILE_PRINTF(MEMCG_PATH_NEW "/tasks", "%d", getpid()); -} - struct ksm_merge_data { char data; unsigned int mergeable_size; @@ -709,57 +702,6 @@ void write_cpusets(long nd) } } -void umount_mem(char *path, char *path_new) -{ - FILE *fp; - int fd; - char s_new[BUFSIZ], s[BUFSIZ], value[BUFSIZ]; - - /* Move all processes in task to its parent node. */ - sprintf(s, "%s/tasks", path); - fd = open(s, O_WRONLY); - if (fd == -1) - tst_res(TWARN | TERRNO, "open %s", s); - - snprintf(s_new, BUFSIZ, "%s/tasks", path_new); - fp = fopen(s_new, "r"); - if (fp == NULL) - tst_res(TWARN | TERRNO, "fopen %s", s_new); - if ((fd != -1) && (fp != NULL)) { - while (fgets(value, BUFSIZ, fp) != NULL) - if (write(fd, value, strlen(value) - 1) - != (ssize_t)strlen(value) - 1) - tst_res(TWARN | TERRNO, "write %s", s); - } - if (fd != -1) - close(fd); - if (fp != NULL) - fclose(fp); - if (rmdir(path_new) == -1) - tst_res(TWARN | TERRNO, "rmdir %s", path_new); - if (umount(path) == -1) - tst_res(TWARN | TERRNO, "umount %s", path); - if (rmdir(path) == -1) - tst_res(TWARN | TERRNO, "rmdir %s", path); -} - -void mount_mem(char *name, char *fs, char *options, char *path, char *path_new) -{ - SAFE_MKDIR(path, 0777); - if (mount(name, path, fs, 0, options) == -1) { - if (errno == ENODEV) { - if (rmdir(path) == -1) - tst_res(TWARN | TERRNO, "rmdir %s failed", - path); - tst_brk(TCONF, - "file system %s is not configured in kernel", - fs); - } - tst_brk(TBROK | TERRNO, "mount %s", path); - } - SAFE_MKDIR(path_new, 0777); -} - /* shared */ /* Warning: *DO NOT* use this function in child */ From patchwork Fri Jun 5 09:13:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Wang X-Patchwork-Id: 1303986 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=IudzSTXw; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (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 ozlabs.org (Postfix) with ESMTPS id 49dcQR3p5Yz9sT8 for ; Fri, 5 Jun 2020 19:13:51 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id E3B9F3C2F5C for ; Fri, 5 Jun 2020 11:13:48 +0200 (CEST) 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]) by picard.linux.it (Postfix) with ESMTP id 870753C2F65 for ; Fri, 5 Jun 2020 11:13:27 +0200 (CEST) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by in-3.smtp.seeweb.it (Postfix) with ESMTP id 207A51A01227 for ; Fri, 5 Jun 2020 11:13:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1591348406; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UTz+r9ZQtFKCpb8oFl0jewtU8u62a4TUk5koZzTraEw=; b=IudzSTXwxwJxPNXRSv9waz6fr/DeCw84w1XHnPvsQ3IXY+wrxMUZtlYoomhD+ajdhqG0I0 JuWyfrge6jNgms4NHj1O5EjTqQMqpZFCMBXPe8Or2e9b8tBndiE5dFsNfnDp7dLzLuLxx+ Y3b0JHLVCKhT+0cteSk53NAxq5F80oY= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-473-RtwsSXdDMhmb56swNWC6Ow-1; Fri, 05 Jun 2020 05:13:24 -0400 X-MC-Unique: RtwsSXdDMhmb56swNWC6Ow-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C97BB801503 for ; Fri, 5 Jun 2020 09:13:23 +0000 (UTC) Received: from liwang-workstation.nay.redhat.com (unknown [10.66.81.246]) by smtp.corp.redhat.com (Postfix) with ESMTP id 030AF5D9D7 for ; Fri, 5 Jun 2020 09:13:22 +0000 (UTC) From: Li Wang To: ltp@lists.linux.it Date: Fri, 5 Jun 2020 17:13:16 +0800 Message-Id: <20200605091316.27546-4-liwang@redhat.com> In-Reply-To: <20200605091316.27546-1-liwang@redhat.com> References: <20200605091316.27546-1-liwang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Virus-Scanned: clamav-milter 0.99.2 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,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-3.smtp.seeweb.it Subject: [LTP] [PATCH v3 4/4] mm: add cpuset01 to runtest file 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: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" This test was moved to stress test since commit ae8fa55a8, but stress runtest has been removed from commit e752f7c19674 :). Here adding back it as a general memory test without '-I 3600'. Signed-off-by: Li Wang --- runtest/mm | 2 ++ 1 file changed, 2 insertions(+) diff --git a/runtest/mm b/runtest/mm index a09f39c1e..612a4d066 100644 --- a/runtest/mm +++ b/runtest/mm @@ -73,6 +73,8 @@ ksm06 ksm06 ksm06_1 ksm06 -n 10 ksm06_2 ksm06 -n 10000 +cpuset01 cpuset01 + oom01 oom01 oom02 oom02 oom03 oom03