On 28 January 2010 09:46, Sudhir Kumar <[email protected]> wrote:
> On Mon, Jan 11, 2010 at 05:22:56PM +0100, Cyril Hrubis wrote:
> > Hi!
> >
>
>
[...]
> >
> > You can't allocate memory from signal handler. There is a list of signal
> safe
> > functions in 'man 7 signal'. The correct solution for this is to create
> > something like named pipe and sleep in read() on it (instead of
> > 'while(!flag_exit) sleep(1)').
> Naufel,
> You might like to address the comments by Cyril. For named pipes you can
> see man mkfifo in bash or open in c where you can specify the file as a
> pipe or FIFO. A busy wait like you implemented is not a good practice.
> Repost your patches with the comments addressed.
>
>
[...]
These are the testcases I plan to implement (taken from
http://workouts.foss.in/2009/index.php/Hacking_Linux_Kernel_Through_testing)
1. Validate the upper limit imposed by the topmost hierarchy.
2. Test the testcase no 1 for subgroups far below in hierarchy.
3. A group has n siblings. They start consuming memory and the total
increases to more than parent's limit. Check if the group with max memory
consumption gets it's task killed.
4. Write a test which uses lots of memory, reaches swap limits and ensure it
gets killed.
5. A task is running in a group which has a limit N on memory.limit_in_bytes
but no limit on memory.memsw.limit_in_bytes. The system has swap memory in
use and the task's memory consumption is >> N. Therefore the task should be
using a big amount of swap memory(say M) > N. Try to set the
memory.memsw.limit_in_bytes to a low value say N. It should fail to change
the limits.
6. In test no 5 instead of changing the mem+swap limits turn the swap off.
Since the memory usage of the task is more than the current limits the task
should be killed.
The first testcase has been attached. Reimplemented using named pipes.
Naufal
diff -NarU3 ltpv/runtest/controllers ltpt/runtest/controllers
--- ltpv/runtest/controllers 2009-09-14 12:44:25.000000000 +0530
+++ ltpt/runtest/controllers 2010-02-21 12:18:42.738933533 +0530
@@ -3,5 +3,6 @@
memcg_regression memcg_regression_test.sh
memcg_function memcg_function_test.sh
memcg_stress memcg_stress_test.sh
+memcg_control PAGESIZE=$(./mem_process -p);memcg_control_test.sh $PAGESIZE $PAGESIZE $((PAGESIZE*2))
cgroup_fj run_cgroup_test_fj.sh
controllers test_controllers.sh
diff -NarU3 ltpv/testcases/kernel/controllers/memcg/control/Makefile ltpt/testcases/kernel/controllers/memcg/control/Makefile
--- ltpv/testcases/kernel/controllers/memcg/control/Makefile 1970-01-01 05:30:00.000000000 +0530
+++ ltpt/testcases/kernel/controllers/memcg/control/Makefile 2009-10-09 23:25:47.000000000 +0530
@@ -0,0 +1,33 @@
+#
+# 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.
+#
+# Garrett Cooper, September 2009
+#
+
+top_srcdir ?= ../../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+
+CPPFLAGS += -I$(abs_srcdir)/../../libcontrollers
+
+INSTALL_TARGETS := *.sh
+
+LDLIBS += -lm
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff -NarU3 ltpv/testcases/kernel/controllers/memcg/control/memcg_control_test.sh ltpt/testcases/kernel/controllers/memcg/control/memcg_control_test.sh
--- ltpv/testcases/kernel/controllers/memcg/control/memcg_control_test.sh 1970-01-01 05:30:00.000000000 +0530
+++ ltpt/testcases/kernel/controllers/memcg/control/memcg_control_test.sh 2010-02-21 11:07:30.492933513 +0530
@@ -0,0 +1,159 @@
+#!/bin/sh
+
+################################################################################
+## ##
+## Copyright (c) 2010 Mohamed Naufal Basheer ##
+## ##
+## 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 pronram; if not, write to the Free Software ##
+## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ##
+## ##
+## ##
+## File: memcg_control_test.sh ##
+## ##
+## Purpose: Implement various memory controller tests ##
+## ##
+## Author: Mohamed Naufal Basheer <[email protected]> ##
+## ##
+################################################################################
+cd $LTPROOT/testcases/bin
+
+if [ ! $(grep -w memory /proc/cgroups | cut -f4) == "1" ]
+then
+ echo "WARNING:";
+ echo "Either Kernel does not support for memory resource controller or feature not enabled";
+ echo "Skipping all memcg_control testcases....";
+ exit 0
+fi
+
+export TCID="memcg_control"
+export TST_TOTAL=1
+export TST_COUNT=0
+
+TOT_MEM_LIMIT=$1
+ACTIVE_MEM_LIMIT=$2
+PROC_MEM=$3
+
+TST_PATH=$PWD
+
+PASS=0
+FAIL=1
+
+# Check if the test process is killed on crossing boundary
+test_proc_kill() {
+ $TST_PATH/mem_process -m $PROC_MEM &
+ sleep 1
+ echo $! > tasks
+
+ #Instruct the test process to start acquiring memory
+ echo m > /tmp/status_pipe
+ sleep 1
+
+ #Check if killed
+ ps -p $! > /dev/null 2> /dev/null
+ if [ $? -eq 0 ]; then
+ echo m > /tmp/status_pipe
+ echo x > /tmp/status_pipe
+ else
+ KILLED_CNT=$(($KILLED_CNT + 1))
+ fi
+}
+
+# Validate the memory usage limit imposed by the hierarchically topmost group
+testcase_1() {
+ TST_COUNT=1
+ tst_resm TINFO "Test #1: Checking if the memory usage limit imposed by the topmost group is enforced"
+
+ echo "$ACTIVE_MEM_LIMIT" > $TST_PATH/mnt/$i/memory.limit_in_bytes
+ echo "$TOT_MEM_LIMIT" > $TST_PATH/mnt/$i/memory.memsw.limit_in_bytes
+
+ mkdir sub 2> /dev/null
+ pushd sub > /dev/null
+
+ KILLED_CNT=0
+ test_proc_kill;
+
+ if [ $PROC_MEM -gt $TOT_MEM_LIMIT ] && [ $KILLED_CNT -eq 0 ]; then
+ result $FAIL "Test #1: failed"
+ else
+ result $PASS "Test #1: passed"
+ fi
+
+ popd > /dev/null
+ rmdir sub 2> /dev/null
+}
+
+
+# Record the test results
+#
+# $1: Result of the test case, $PASS or $FAIL
+# $2: Output information
+result() {
+ RES=$1
+ INFO=$2
+
+ if [ $RES -eq $PASS ]; then
+ tst_resm TPASS "$INFO"
+ else
+ FAILED_CNT=$(($FAILED_CNT + 1))
+ tst_resm TFAIL "$INFO"
+ fi
+}
+
+cleanup() {
+ if [ -e mnt ]; then
+ umount $TST_PATH/mnt 2> /dev/null
+ rm -rf mnt 2> /dev/null
+ fi
+}
+
+do_mount() {
+ cleanup;
+
+ mkdir $TST_PATH/mnt 2> /dev/null
+ mount -t cgroup -o memory cgroup $TST_PATH/mnt 2> /dev/null
+ if [ $? -ne 0 ]; then
+ tst_brkm TBROK NULL "Mounting cgroup to temp dir failed"
+ rmdir $TST_PATH/mnt 2> /dev/null
+ exit 1
+ fi
+}
+
+do_mount;
+
+echo 1 > mnt/memory.use_hierarchy 2> /dev/null
+
+FAILED_CNT=0
+
+for i in $(seq 1 $TST_TOTAL)
+do
+ pushd $TST_PATH/mnt > /dev/null
+ mkdir $TST_PATH/mnt/$i 2> /dev/null
+ pushd $i > /dev/null
+
+ testcase_$i;
+
+ popd > /dev/null
+ rmdir $i 2> /dev/null
+ popd > /dev/null
+done
+
+cleanup;
+
+if [ "$FAILED_CNT" -ne 0 ]; then
+ tst_resm TFAIL "memcg_control: failed"
+ exit 1
+else
+ tst_resm TPASS "memcg_control: passed"
+ exit 0
+fi
diff -NarU3 ltpv/testcases/kernel/controllers/memcg/control/mem_process.c ltpt/testcases/kernel/controllers/memcg/control/mem_process.c
--- ltpv/testcases/kernel/controllers/memcg/control/mem_process.c 1970-01-01 05:30:00.000000000 +0530
+++ ltpt/testcases/kernel/controllers/memcg/control/mem_process.c 2010-02-21 11:10:59.436932382 +0530
@@ -0,0 +1,140 @@
+/*******************************************************************************/
+/* */
+/* Copyright (c) 2010 Mohamed Naufal Basheer */
+/* */
+/* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+/* */
+/* File: mem_process.c */
+/* */
+/* Purpose: act as a memory hog for the memcg_control tests */
+/* */
+/* Author: Mohamed Naufal Basheer <[email protected] > */
+/* */
+/*******************************************************************************/
+#include <stdio.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/mman.h>
+
+/*
+ * Named pipe to act as a communication channel between
+ * shell script & this process
+ */
+#define STATUS_PIPE "/tmp/status_pipe"
+
+int flag_exit;
+int flag_allocated;
+unsigned long memsize;
+
+/*
+ * process_options: process user specified options
+ */
+void process_options(int argc, char **argv)
+{
+ int c;
+ char *end;
+
+ opterr = 0;
+ while ((c = getopt(argc, argv, "pm:")) != -1) {
+ switch(c) {
+ case 'p':
+ printf("%d\n",getpagesize());
+ exit(0);
+ case 'm':
+ memsize = strtoul(optarg, &end, 10);
+ if (*end)
+ errx(2, "Invalid -m usage");
+ break;
+ default:
+ errx(2, "Invalid option specifed");
+ }
+ }
+
+ if(!memsize)
+ errx(3, "Invalid usage");
+}
+
+/*
+ * touch_memory: force physical memory allocation
+ */
+void touch_memory(char *p, unsigned long size)
+{
+ int i;
+ int pagesize = getpagesize();
+
+ for (i = 0; i < size; i += pagesize)
+ p[i] = 0xef;
+}
+
+void mem_map()
+{
+ static char *p;
+
+ if (!flag_allocated) {
+ if ((p = mmap(NULL, memsize, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, 0, 0)) == MAP_FAILED)
+ errx(4, "mmap failed");
+ touch_memory(p, memsize);
+ }else {
+ if (munmap(p, memsize) == -1)
+ errx(5, "munmap failed");
+ }
+ flag_allocated ^= 1;
+}
+
+/*
+ * done: retrieve instructions from the named pipe
+ */
+char action()
+{
+ char ch;
+ int fd;
+
+ fd = open(STATUS_PIPE, O_RDONLY);
+ if (fd < 0)
+ errx(6, "Error opening named pipe");
+
+ if (read(fd, &ch, 1) < 0)
+ errx(7, "Error reading named pipe");
+
+ close(fd);
+
+ return ch;
+}
+
+int main(int argc, char **argv)
+{
+ int ret;
+ char ch;
+
+ process_options(argc, argv);
+
+ ret = mkfifo(STATUS_PIPE, 0666);
+
+ if (ret == -1 && errno != EEXIST)
+ errx(1, "Error creating named pipe");
+
+ do {
+ ch = action();
+
+ if (ch == 'm')
+ mem_map();
+ }while(ch != 'x');
+
+ remove(STATUS_PIPE);
+
+ return 0;
+}
diff -NarU3 ltpv/testcases/kernel/controllers/memcg/README ltpt/testcases/kernel/controllers/memcg/README
--- ltpv/testcases/kernel/controllers/memcg/README 2009-09-14 12:44:25.000000000 +0530
+++ ltpt/testcases/kernel/controllers/memcg/README 2010-02-21 02:16:00.406481000 +0530
@@ -15,6 +15,16 @@
FILES DESCRIPTION:
+control/memcg_control_test.sh
+--------------------
+This script runs the testcases of control test.
+
+control/mem_process.c
+--------------------
+The program allocates memory specified using the '-m' option when 'm' is recieved
+through the named pipe /tmp/status_pipe and frees it on receiving 'm' again.
+It exits on receiveing 'x'. It gets the page size on specifying the '-p' option.
+
functional/memcgroup_function_test.sh
--------------------
This script runs all the 38 testcases of basis operation.
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list