1#! /bin/sh 2 3################################################################################ 4## ## 5## Copyright (c) 2009 FUJITSU LIMITED ## 6## ## 7## This program is free software; you can redistribute it and#or modify ## 8## it under the terms of the GNU General Public License as published by ## 9## the Free Software Foundation; either version 2 of the License, or ## 10## (at your option) any later version. ## 11## ## 12## This program is distributed in the hope that it will be useful, but ## 13## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## 14## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## 15## for more details. ## 16## ## 17## You should have received a copy of the GNU General Public License ## 18## along with this program; if not, write to the Free Software ## 19## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ## 20## ## 21## Author: Li Zefan <lizf@cn.fujitsu.com> ## 22## Restructure for LTP: Shi Weihua <shiwh@cn.fujitsu.com> ## 23## Added memcg enable/disable functinality: Rishikesh K Rajak ## 24## <risrajak@linux.vnet.ibm.com ## 25## ## 26################################################################################ 27 28cd $LTPROOT/testcases/bin 29export TCID="memcg_stress_test" 30export TST_TOTAL=2 31export TST_COUNT=0 32 33if [ "x$(grep -w memory /proc/cgroups | cut -f4)" != "x1" ]; then 34 echo "WARNING:"; 35 echo "Either Kernel does not support for memory resource controller or feature not enabled"; 36 echo "Skipping all memcgroup testcases...."; 37 exit 0 38fi 39 40RUN_TIME=$(( 15 * 60 )) 41 42cleanup() 43{ 44 if [ -e /dev/memcg ]; then 45 umount /dev/memcg 2>/dev/null 46 rmdir /dev/memcg 2>/dev/null 47 fi 48} 49 50 51do_mount() 52{ 53 cleanup; 54 55 mkdir /dev/memcg 2> /dev/null 56 mount -t cgroup -omemory memcg /dev/memcg 57} 58 59 60# Run the stress test 61# 62# $1 - Number of cgroups 63# $2 - Allocated how much memory in one process? in MB 64# $3 - The interval to touch memory in a process 65# $4 - How long does this test run ? in second 66run_stress() 67{ 68 do_mount; 69 70 for i in $(seq 0 $(($1-1))) 71 do 72 mkdir /dev/memcg/$i 2> /dev/null 73 ./memcg_process_stress $2 $3 & 74 eval pid$i=$! 75 76 eval echo \$pid$i > /dev/memcg/$i/tasks 77 done 78 79 for i in $(seq 0 $(($1-1))) 80 do 81 eval /bin/kill -s SIGUSR1 \$pid$i 2> /dev/null 82 done 83 84 sleep $4 85 86 for i in $(seq 0 $(($1-1))) 87 do 88 eval /bin/kill -s SIGKILL \$pid$i 2> /dev/null 89 eval wait \$pid$i 90 91 rmdir /dev/memcg/$i 2> /dev/null 92 done 93 94 cleanup; 95} 96 97testcase_1() 98{ 99 run_stress 150 $(( ($mem-150) / 150 )) 5 $RUN_TIME 100 101 tst_resm TPASS "stress test 1 passed" 102} 103 104testcase_2() 105{ 106 run_stress 1 $mem 5 $RUN_TIME 107 108 tst_resm TPASS "stress test 2 passed" 109} 110 111echo 3 > /proc/sys/vm/drop_caches 112sleep 2 113mem_free=`cat /proc/meminfo | grep MemFree | awk '{ print $2 }'` 114swap_free=`cat /proc/meminfo | grep SwapFree | awk '{ print $2 }'` 115 116mem=$(( $mem_free + $swap_free / 2 )) 117mem=$(( mem / 1024 )) 118 119date 120export TST_COUNT=$(( $TST_COUNT + 1 )) 121testcase_1 122export TST_COUNT=$(( $TST_COUNT + 1 )) 123testcase_2 124date 125 126exit 0 127