From patchwork Thu Apr 15 03:29:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Gongyi X-Patchwork-Id: 1466463 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=) 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) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FLPwM0Tczz9sRK for ; Thu, 15 Apr 2021 13:29:38 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id F3B9D3C714C for ; Thu, 15 Apr 2021 05:29:33 +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]) (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 D627D3C04B0 for ; Thu, 15 Apr 2021 05:29:31 +0200 (CEST) Received: from szxga07-in.huawei.com (szxga07-in.huawei.com [45.249.212.35]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-2.smtp.seeweb.it (Postfix) with ESMTPS id D2C186018B8 for ; Thu, 15 Apr 2021 05:29:29 +0200 (CEST) Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4FLPsR4DH6zB163 for ; Thu, 15 Apr 2021 11:27:07 +0800 (CST) Received: from ubuntu1804.huawei.com (10.67.174.63) by DGGEMS410-HUB.china.huawei.com (10.3.19.210) with Microsoft SMTP Server id 14.3.498.0; Thu, 15 Apr 2021 11:29:17 +0800 From: Zhao Gongyi To: Date: Thu, 15 Apr 2021 11:29:11 +0800 Message-ID: <20210415032911.7542-1-zhaogongyi@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-Originating-IP: [10.67.174.63] X-CFilter-Loop: Reflected X-Virus-Scanned: clamav-milter 0.102.4 at in-2.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.0 required=7.0 tests=SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-2.smtp.seeweb.it Subject: [LTP] [PATCH v3] controllers/memcg: Add testcase for kmem_limit_in_bytes of memory cgroup 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" Add memory cgroup testcase for checking that kmem overflow is controlled by kmem.limit_in_bytes. Signed-off-by: Zhao Gongyi --- v2->v3: remove the calling of tst_res/tst_brk in test process to avoid kmem allocation --- runtest/controllers | 1 + testcases/kernel/controllers/memcg/.gitignore | 1 + .../functional/memcg_kmem_limit_in_bytes.c | 76 +++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 testcases/kernel/controllers/memcg/functional/memcg_kmem_limit_in_bytes.c -- 2.17.1 diff --git a/runtest/controllers b/runtest/controllers index e3d0243f1..f13a112c7 100644 --- a/runtest/controllers +++ b/runtest/controllers @@ -15,6 +15,7 @@ memcg_use_hierarchy memcg_use_hierarchy_test.sh memcg_usage_in_bytes memcg_usage_in_bytes_test.sh memcg_stress memcg_stress_test.sh memcg_control memcg_control_test.sh +memcg_kmem_limit_in_bytes memcg_kmem_limit_in_bytes 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 c0b6d0714..dce8412de 100644 --- a/testcases/kernel/controllers/memcg/.gitignore +++ b/testcases/kernel/controllers/memcg/.gitignore @@ -1,5 +1,6 @@ /control/mem_process /functional/memcg_process +/functional/memcg_kmem_limit_in_bytes /regression/memcg_test_1 /regression/memcg_test_2 /regression/memcg_test_3 diff --git a/testcases/kernel/controllers/memcg/functional/memcg_kmem_limit_in_bytes.c b/testcases/kernel/controllers/memcg/functional/memcg_kmem_limit_in_bytes.c new file mode 100644 index 000000000..4521d299c --- /dev/null +++ b/testcases/kernel/controllers/memcg/functional/memcg_kmem_limit_in_bytes.c @@ -0,0 +1,76 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2021 HUAWEI LIMITED + * Author: Zhao Gongyi + */ + +/*\ + * [Description] + * Check that kmem overflow is controlled by kmem.limit_in_bytes. + * + * [Algorithm] + * 1) mount memory cgroup + * 2) set 0 to memory.kmem.limit_in_bytes + * 3) set test process id to cgroup.procs + * 4) fork in test process to trig kmem overflow + */ + +#include +#include "tst_test.h" + +#define MNT_POINT "memcg" +#define TESTDIR "memcg/ltpmemcg" +#define CGROUP_PROCS "memcg/ltpmemcg/cgroup.procs" +#define KMEM_LIMIT_IN_BYTES "memcg/ltpmemcg/memory.kmem.limit_in_bytes" + +static void cleanup(void) +{ + SAFE_RMDIR(TESTDIR); + SAFE_UMOUNT(MNT_POINT); + SAFE_RMDIR(MNT_POINT); +} + +static void setup(void) +{ + SAFE_MKDIR(MNT_POINT, 0755); + SAFE_MOUNT("memcg", MNT_POINT, "cgroup", 0, "memory"); + SAFE_MKDIR(TESTDIR, 0755); +} + +static void run(void) +{ + pid_t pid; + int st; + + pid = SAFE_FORK(); + if (!pid) { + SAFE_FILE_PRINTF(KMEM_LIMIT_IN_BYTES, "%d", 0); + SAFE_FILE_PRINTF(CGROUP_PROCS, "%d", getpid()); + + TEST(fork()); + if (TST_RET == -1 && TST_ERR == ENOMEM) + _exit(TPASS); + else + _exit(TFAIL); + } else { + SAFE_WAIT(&st); + if (WIFEXITED(st)) + if (!WEXITSTATUS(st)) { + tst_res(TPASS, "kmem alloc is controled " + "by memory.kmem.limit_in_bytes"); + return; + } + + tst_res(TFAIL,"kmem alloc is not controled " + "by memory.kmem.limit_in_bytes"); + } +} + +static struct tst_test test = { + .needs_root = 1, + .needs_tmpdir = 1, + .forks_child = 1, + .setup = setup, + .test_all = run, + .cleanup = cleanup, +};