From patchwork Fri Dec 28 18:32:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cristian Marussi X-Patchwork-Id: 1019226 X-Patchwork-Delegate: petr.vorel@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) 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=none (p=none dis=none) header.from=arm.com Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43RFgl5zmDz9sBQ for ; Sat, 29 Dec 2018 05:32:50 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id C53063E71B7 for ; Fri, 28 Dec 2018 19:32:47 +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 [IPv6:2001:4b78:1:20::6]) by picard.linux.it (Postfix) with ESMTP id 988FA3E716E for ; Fri, 28 Dec 2018 19:32:45 +0100 (CET) Received: from foss.arm.com (usa-sjc-mx-foss1.foss.arm.com [217.140.101.70]) by in-6.smtp.seeweb.it (Postfix) with ESMTP id 10A741400E49 for ; Fri, 28 Dec 2018 19:32:43 +0100 (CET) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4CEF7A78 for ; Fri, 28 Dec 2018 10:32:42 -0800 (PST) Received: from e120937-lin.cambridge.arm.com (e120937-lin.cambridge.arm.com [10.1.197.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A4D213F675 for ; Fri, 28 Dec 2018 10:32:41 -0800 (PST) From: Cristian Marussi To: ltp@lists.linux.it Date: Fri, 28 Dec 2018 18:32:12 +0000 Message-Id: <20181228183213.36339-2-cristian.marussi@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181228183213.36339-1-cristian.marussi@arm.com> References: <20181228183213.36339-1-cristian.marussi@arm.com> X-Virus-Scanned: clamav-milter 0.99.2 at in-6.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=-0.0 required=7.0 tests=SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-6.smtp.seeweb.it Subject: [LTP] [PATCH 1/2] memcg_stress_test.sh: ported to newlib X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Ported to newlib framework and general cleanup. Moved an helper function out into cgroup_lib.sh. Signed-off-by: Cristian Marussi --- testcases/kernel/controllers/cgroup_lib.sh | 27 ++++ .../kernel/controllers/memcg/stress/Makefile | 21 +-- .../memcg/stress/memcg_process_stress.c | 27 +--- .../memcg/stress/memcg_stress_test.sh | 137 ++++++++---------- 4 files changed, 100 insertions(+), 112 deletions(-) diff --git a/testcases/kernel/controllers/cgroup_lib.sh b/testcases/kernel/controllers/cgroup_lib.sh index 5cdf55363..74fb8f845 100644 --- a/testcases/kernel/controllers/cgroup_lib.sh +++ b/testcases/kernel/controllers/cgroup_lib.sh @@ -31,3 +31,30 @@ get_cgroup_mountpoint() return $ret } +# +# Helper to check /proc/cgroups to verify if the cgroup subsytem +# provided as param is supported and enabled in Kernel. +# +# It expects as single argument the cgroup subsytem for +# which to check in /proc/cgroups +# +# - returns true if subsystem is supported and enabled +# +is_cgroup_subsystem_available_and_enabled() +{ + local line + local val + local ret=1 + local subsystem=$1 + + # fail straight away with no args + [ $# -eq 0 ] && return $ret + + line=$(grep -w $subsystem /proc/cgroups) + if [ $? = 0 ];then + val=$(echo $line | awk '{print $4 }') + [ $val = 1 ] && ret=0 + fi + + return $ret +} diff --git a/testcases/kernel/controllers/memcg/stress/Makefile b/testcases/kernel/controllers/memcg/stress/Makefile index a0456ac5d..773363cfc 100644 --- a/testcases/kernel/controllers/memcg/stress/Makefile +++ b/testcases/kernel/controllers/memcg/stress/Makefile @@ -1,24 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (C) 2009, Cisco Systems Inc. +# Author: Ngie Cooper, September 2009 # # kernel/controllers/memcg/stress testcase suite Makefile. # -# Copyright (C) 2009, Cisco Systems Inc. -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -# -# Ngie Cooper, September 2009 -# top_srcdir ?= ../../../../.. diff --git a/testcases/kernel/controllers/memcg/stress/memcg_process_stress.c b/testcases/kernel/controllers/memcg/stress/memcg_process_stress.c index 870575c26..ef260594d 100644 --- a/testcases/kernel/controllers/memcg/stress/memcg_process_stress.c +++ b/testcases/kernel/controllers/memcg/stress/memcg_process_stress.c @@ -1,24 +1,9 @@ -/******************************************************************************/ -/* */ -/* Copyright (c) 2009 FUJITSU LIMITED */ -/* */ -/* This program is free software; you can redistribute it and/or modify */ -/* it under the terms of the GNU General Public License as published by */ -/* the Free Software Foundation; either version 2 of the License, or */ -/* (at your option) any later version. */ -/* */ -/* This program is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See */ -/* the GNU General Public License for more details. */ -/* */ -/* You should have received a copy of the GNU General Public License */ -/* along with this program; if not, write to the Free Software */ -/* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -/* */ -/* Author: Li Zefan */ -/* */ -/******************************************************************************/ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2009 FUJITSU LIMITED + * + * Author: Li Zefan + */ #include #include diff --git a/testcases/kernel/controllers/memcg/stress/memcg_stress_test.sh b/testcases/kernel/controllers/memcg/stress/memcg_stress_test.sh index af1a708a8..2c5c13e3e 100755 --- a/testcases/kernel/controllers/memcg/stress/memcg_stress_test.sh +++ b/testcases/kernel/controllers/memcg/stress/memcg_stress_test.sh @@ -1,56 +1,56 @@ -#! /bin/sh - -################################################################################ -## ## -## Copyright (c) 2009 FUJITSU LIMITED ## -## ## -## This program is free software; you can redistribute it and#or modify ## -## it under the terms of the GNU General Public License as published by ## -## the Free Software Foundation; either version 2 of the License, or ## -## (at your option) any later version. ## -## ## -## This program is distributed in the hope that it will be useful, but ## -## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## -## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## -## for more details. ## -## ## -## You should have received a copy of the GNU General Public License ## -## along with this program; if not, write to the Free Software ## -## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ## -## ## -## Author: Li Zefan ## -## Restructure for LTP: Shi Weihua ## -## Added memcg enable/disable functinality: Rishikesh K Rajak ## -## +# Restructure for LTP: Shi Weihua +# Added memcg enable/disable functionality: Rishikesh K Rajak /dev/null - rmdir /dev/memcg 2>/dev/null + if ! is_cgroup_subsystem_available_and_enabled "memory";then + tst_res TWARN "Either Kernel does not support MEMORY resource controller or feature not enabled" + tst_brk TCONF ignored "Skipping all memory cgroup testcases...." fi + + echo 3 > /proc/sys/vm/drop_caches + sleep 2 + local mem_free=`cat /proc/meminfo | grep MemFree | awk '{ print $2 }'` + local swap_free=`cat /proc/meminfo | grep SwapFree | awk '{ print $2 }'` + + MEM=$(( $mem_free + $swap_free / 2 )) + MEM=$(( MEM / 1024 )) + RUN_TIME=$(( 15 * 60 )) + + tst_res TINFO "Using up to $MEM MBytes or memory." } +do_cleanup() +{ + if [ -e /dev/memcg ]; then + umount /dev/memcg 2> /dev/null + rmdir /dev/memcg 2> /dev/null + fi +} do_mount() { - cleanup; + do_cleanup mkdir /dev/memcg 2> /dev/null mount -t cgroup -omemory memcg /dev/memcg @@ -65,12 +65,14 @@ do_mount() # $4 - How long does this test run ? in second run_stress() { - do_mount; + local i + + do_mount for i in $(seq 0 $(($1-1))) do mkdir /dev/memcg/$i 2> /dev/null - ./memcg_process_stress $2 $3 & + memcg_process_stress $2 $3 & eval pid$i=$! eval echo \$pid$i > /dev/memcg/$i/tasks @@ -78,49 +80,38 @@ run_stress() for i in $(seq 0 $(($1-1))) do - eval /bin/kill -s SIGUSR1 \$pid$i 2> /dev/null + eval kill -USR1 \$pid$i 2> /dev/null done sleep $4 for i in $(seq 0 $(($1-1))) do - eval /bin/kill -s SIGKILL \$pid$i 2> /dev/null + eval kill -KILL \$pid$i 2> /dev/null eval wait \$pid$i rmdir /dev/memcg/$i 2> /dev/null done - cleanup; + do_cleanup } -testcase_1() +testcase1() { - run_stress 150 $(( ($mem-150) / 150 )) 5 $RUN_TIME + tst_res TINFO "testcase 1 started...it will run for $RUN_TIME secs" - tst_resm TPASS "stress test 1 passed" -} + run_stress 150 $(( $MEM / 150 )) 5 $RUN_TIME -testcase_2() -{ - run_stress 1 $mem 5 $RUN_TIME - - tst_resm TPASS "stress test 2 passed" + tst_res TPASS "stress test 1 passed" } -echo 3 > /proc/sys/vm/drop_caches -sleep 2 -mem_free=`cat /proc/meminfo | grep MemFree | awk '{ print $2 }'` -swap_free=`cat /proc/meminfo | grep SwapFree | awk '{ print $2 }'` +testcase2() +{ + tst_res TINFO "testcase 2 started...it will run for $RUN_TIME secs" -mem=$(( $mem_free + $swap_free / 2 )) -mem=$(( mem / 1024 )) + run_stress 1 $MEM 5 $RUN_TIME -date -export TST_COUNT=$(( $TST_COUNT + 1 )) -testcase_1 -export TST_COUNT=$(( $TST_COUNT + 1 )) -testcase_2 -date + tst_res TPASS "stress test 2 passed" +} -exit 0 +tst_run From patchwork Fri Dec 28 18:32:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cristian Marussi X-Patchwork-Id: 1019227 X-Patchwork-Delegate: petr.vorel@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) 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=none (p=none dis=none) header.from=arm.com Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43RFgq1YHcz9sBQ for ; Sat, 29 Dec 2018 05:32:54 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 5DBF43E7631 for ; Fri, 28 Dec 2018 19:32:52 +0100 (CET) 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 C267E3E717B for ; Fri, 28 Dec 2018 19:32:49 +0100 (CET) Received: from foss.arm.com (foss.arm.com [217.140.101.70]) by in-2.smtp.seeweb.it (Postfix) with ESMTP id B06BD600F24 for ; Fri, 28 Dec 2018 19:32:48 +0100 (CET) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 61A84A78 for ; Fri, 28 Dec 2018 10:32:47 -0800 (PST) Received: from e120937-lin.cambridge.arm.com (e120937-lin.cambridge.arm.com [10.1.197.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id DD6373F675 for ; Fri, 28 Dec 2018 10:32:46 -0800 (PST) From: Cristian Marussi To: ltp@lists.linux.it Date: Fri, 28 Dec 2018 18:32:13 +0000 Message-Id: <20181228183213.36339-3-cristian.marussi@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181228183213.36339-1-cristian.marussi@arm.com> References: <20181228183213.36339-1-cristian.marussi@arm.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.0 required=7.0 tests=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 2/2] memcg_stress_test.sh: fix memory usage X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" When this test was run on a 'swap-less' system, the max quantity of memory to allocate for the test runners was wrongly set as the whole amount of free memory. This caused the test to fail badly without even properly cleanup all the memcg related configurations, so impacting also a lot of following memcg related test-cases. With this fix, when the available swap space is zero, the test limit itself to use only half of all the available free memory. Signed-off-by: Cristian Marussi --- testcases/kernel/controllers/memcg/stress/memcg_stress_test.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/testcases/kernel/controllers/memcg/stress/memcg_stress_test.sh b/testcases/kernel/controllers/memcg/stress/memcg_stress_test.sh index 2c5c13e3e..507d17a3d 100755 --- a/testcases/kernel/controllers/memcg/stress/memcg_stress_test.sh +++ b/testcases/kernel/controllers/memcg/stress/memcg_stress_test.sh @@ -33,7 +33,8 @@ do_setup() local mem_free=`cat /proc/meminfo | grep MemFree | awk '{ print $2 }'` local swap_free=`cat /proc/meminfo | grep SwapFree | awk '{ print $2 }'` - MEM=$(( $mem_free + $swap_free / 2 )) + # Limit the maximum amount of memory to use depending on swap space + [ $swap_free -gt 0 ] && MEM=$(( $mem_free + $swap_free / 2 )) || MEM=$(( $mem_free / 2 )) MEM=$(( MEM / 1024 )) RUN_TIME=$(( 15 * 60 ))