From patchwork Wed May 27 03:14:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Wang X-Patchwork-Id: 1298564 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=ATTBcOvw; 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 49Wwtv132Cz9sSW for ; Wed, 27 May 2020 13:15:19 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 639B73C32CB for ; Wed, 27 May 2020 05:15:16 +0200 (CEST) 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 [217.194.8.7]) by picard.linux.it (Postfix) with ESMTP id 65AE63C3293 for ; Wed, 27 May 2020 05:14:42 +0200 (CEST) Received: from us-smtp-delivery-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by in-7.smtp.seeweb.it (Postfix) with ESMTP id 634102010B4 for ; Wed, 27 May 2020 05:14:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590549280; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jwpc9Ajk9pOeYKeDgDSGY4EBbFoiPs0wn6iF+8qy6SI=; b=ATTBcOvwqhc3OyUQEeW7T41O9aHc4nP1q3XrhidMd6htUXPwQF4R2dAO4oLZK1iA8jwMA/ w7FfB5/pOs+1xXbOj/EcwgUNuSS9r0xF8GotpDYY0Pwl8lMPano4s45C9PQIo0ZPIzIruG UYluiH9LAZZ3abChx67UOHXGMdWIE9U= 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-253-SAGw6jgWMr6rveeUwxCzYw-1; Tue, 26 May 2020 23:14:35 -0400 X-MC-Unique: SAGw6jgWMr6rveeUwxCzYw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 03E2A1005510 for ; Wed, 27 May 2020 03:14:35 +0000 (UTC) Received: from liwang-workstation.nay.redhat.com (unknown [10.66.81.246]) by smtp.corp.redhat.com (Postfix) with ESMTP id E58F35C1B0; Wed, 27 May 2020 03:14:33 +0000 (UTC) From: Li Wang To: ltp@lists.linux.it Date: Wed, 27 May 2020 11:14:28 +0800 Message-Id: <20200527031430.22144-2-liwang@redhat.com> In-Reply-To: <20200527031430.22144-1-liwang@redhat.com> References: <20200527031430.22144-1-liwang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Virus-Scanned: clamav-milter 0.99.2 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,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-7.smtp.seeweb.it Subject: [LTP] [PATCH v1 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 | 6 ++---- testcases/kernel/mem/ksm/ksm03.c | 11 +++-------- testcases/kernel/mem/ksm/ksm04.c | 14 +++++--------- testcases/kernel/mem/lib/mem.c | 8 ++++---- testcases/kernel/mem/oom/oom03.c | 17 +++++++---------- testcases/kernel/mem/oom/oom04.c | 10 +++------- testcases/kernel/mem/oom/oom05.c | 26 ++++++++++---------------- 9 files changed, 45 insertions(+), 67 deletions(-) diff --git a/testcases/kernel/mem/cpuset/cpuset01.c b/testcases/kernel/mem/cpuset/cpuset01.c index 853f7fe55..cecc4ba86 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()); + read_cpuset_files(PATH_TMP_CG1_CST, "cpus", buf); + write_cpuset_files(PATH_CG1_CST_LTP, "cpus", buf); + read_cpuset_files(PATH_TMP_CG1_CST, "mems", mems); + write_cpuset_files(PATH_CG1_CST_LTP, "mems", mems); + tst_cgroup_move_current(TST_CGROUP_CPUSET); 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(PATH_CG1_CST_LTP, "mems", buf); snprintf(buf, BUFSIZ, "%d", nodes[1]); - write_cpuset_files(CPATH_NEW, "mems", buf); + write_cpuset_files(PATH_CG1_CST_LTP, "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); 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(TST_CGROUP_CPUSET); } 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..9f8b782cf 100644 --- a/testcases/kernel/mem/ksm/ksm02.c +++ b/testcases/kernel/mem/ksm/ksm02.c @@ -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(TST_CGROUP_CPUSET); } 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); } static struct tst_test test = { diff --git a/testcases/kernel/mem/ksm/ksm03.c b/testcases/kernel/mem/ksm/ksm03.c index 0e5131654..c2c8ab529 100644 --- a/testcases/kernel/mem/ksm/ksm03.c +++ b/testcases/kernel/mem/ksm/ksm03.c @@ -59,11 +59,9 @@ #include "mem.h" #include "ksm_common.h" -static int memcg_mounted; - static void verify_ksm(void) { - write_memcg(); + tst_cgroup_mem_set_maxbytes(TESTMEM); create_same_memory(size, num, unit); } @@ -79,8 +77,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); } static void cleanup(void) @@ -88,9 +85,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(TST_CGROUP_MEMCG); } static struct tst_test test = { diff --git a/testcases/kernel/mem/ksm/ksm04.c b/testcases/kernel/mem/ksm/ksm04.c index e393dbd40..6dc36b35a 100644 --- a/testcases/kernel/mem/ksm/ksm04.c +++ b/testcases/kernel/mem/ksm/ksm04.c @@ -70,7 +70,7 @@ static void verify_ksm(void) node = get_a_numa_node(); set_node(nmask, node); - write_memcg(); + tst_cgroup_mem_set_maxbytes(TESTMEM); if (set_mempolicy(MPOL_BIND, nmask, MAXNODES) == -1) { if (errno != ENOSYS) @@ -91,10 +91,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(TST_CGROUP_CPUSET); + tst_cgroup_umount(TST_CGROUP_MEMCG); } static void setup(void) @@ -110,10 +108,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); + tst_cgroup_mount(TST_CGROUP_CPUSET); } static struct tst_test test = { diff --git a/testcases/kernel/mem/lib/mem.c b/testcases/kernel/mem/lib/mem.c index eca4c61c8..df1baa42a 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(PATH_CG1_CST_LTP, "mems", buf); gather_node_cpus(cpus, nd); /* @@ -701,14 +701,14 @@ void write_cpusets(long nd) * the value of cpuset.cpus. */ if (strlen(cpus) != 0) { - write_cpuset_files(CPATH_NEW, "cpus", cpus); + write_cpuset_files(PATH_CG1_CST_LTP, "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(PATH_CG1_CST_LTP, "cpus", "0"); } - SAFE_FILE_PRINTF(CPATH_NEW "/tasks", "%d", getpid()); + SAFE_FILE_PRINTF(PATH_CG1_CST_LTP "/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..af3a565ce 100644 --- a/testcases/kernel/mem/oom/oom03.c +++ b/testcases/kernel/mem/oom/oom03.c @@ -36,27 +36,26 @@ #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_mem_set_maxbytes(TESTMEM); testoom(0, 0, ENOMEM, 1); - if (access(MEMCG_SW_LIMIT, F_OK) == -1) { + if ((access(PATH_MEMORY_SW_LIMIT, F_OK) == -1) || + (access(PATH_MEMORY_SW_MAX, 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); + tst_cgroup_mem_set_maxswap(TESTMEM); + testoom(0, 1, ENOMEM, 1); } @@ -73,16 +72,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); } 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(TST_CGROUP_MEMCG); } static struct tst_test test = { diff --git a/testcases/kernel/mem/oom/oom04.c b/testcases/kernel/mem/oom/oom04.c index 7185ef973..553e6fc0a 100644 --- a/testcases/kernel/mem/oom/oom04.c +++ b/testcases/kernel/mem/oom/oom04.c @@ -36,8 +36,6 @@ #ifdef HAVE_NUMA_V2 -static int cpuset_mounted; - static void verify_oom(void) { #ifdef TST_ABI32 @@ -53,7 +51,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(PATH_CG1_CST_LTP, "memory_migrate", "1"); tst_res(TINFO, "OOM on CPUSET with mem migrate:"); testoom(0, 0, ENOMEM, 1); } @@ -69,8 +67,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); /* * Some nodes do not contain memory, so use @@ -89,8 +86,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(TST_CGROUP_CPUSET); } static struct tst_test test = { diff --git a/testcases/kernel/mem/oom/oom05.c b/testcases/kernel/mem/oom/oom05.c index db24df6de..7a33edef2 100644 --- a/testcases/kernel/mem/oom/oom05.c +++ b/testcases/kernel/mem/oom/oom05.c @@ -36,9 +36,6 @@ #ifdef HAVE_NUMA_V2 -static int memcg_mounted; -static int cpuset_mounted; - static void verify_oom(void) { int swap_acc_on = 1; @@ -48,6 +45,7 @@ static void verify_oom(void) #endif tst_res(TINFO, "OOM on CPUSET & MEMCG..."); + tst_cgroup_mem_set_maxbytes(TESTMEM); testoom(0, 0, ENOMEM, 1); /* @@ -56,13 +54,14 @@ 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"); + write_cpuset_files(PATH_CG1_CST_LTP, "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 ((access(PATH_MEMORY_SW_LIMIT, F_OK) == -1) || + (access(PATH_MEMORY_SW_MAX, F_OK) == -1)) { if (errno == ENOENT) { tst_res(TCONF, "memcg swap accounting is disabled"); swap_acc_on = 0; @@ -73,12 +72,12 @@ static void verify_oom(void) if (swap_acc_on) { tst_res(TINFO, "OOM on CPUSET & MEMCG with " "special memswap limitation:"); - SAFE_FILE_PRINTF(MEMCG_SW_LIMIT, "%ld", TESTMEM); + tst_cgroup_mem_set_maxswap(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(-1); testoom(0, 0, ENOMEM, 1); } } @@ -93,11 +92,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); + tst_cgroup_mount(TST_CGROUP_CPUSET); /* * Some nodes do not contain memory, so use @@ -116,10 +112,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(TST_CGROUP_CPUSET); + tst_cgroup_umount(TST_CGROUP_MEMCG); } static struct tst_test test = {