All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] Testcase to validate the memory usage limit imposed by the topmost memory cgroup
@ 2009-12-25  9:22 Mohamed Naufal
  2010-01-06 16:45 ` Mohamed Naufal
                   ` (2 more replies)
  0 siblings, 3 replies; 20+ messages in thread
From: Mohamed Naufal @ 2009-12-25  9:22 UTC (permalink / raw)
  To: ltp-list


[-- Attachment #1.1: Type: text/plain, Size: 245 bytes --]

Hi

I am a student who attended the FOSS.IN LTP workout (Bangalore, India). I
have attached one of the testcases we were working on. Thought I would get
it reviewed before making a patch. More testcases to follow.

Comments appreciated.

Naufal

[-- Attachment #1.2: Type: text/html, Size: 297 bytes --]

[-- Attachment #2: mem_process.c --]
[-- Type: text/x-csrc, Size: 1458 bytes --]

#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include <sys/mman.h>

int flag_exit;
int flag_allocated;
unsigned int memsize;

/*
process_options: process user specified options
*/
void process_options(int argc, char **argv) {
  int c;

  opterr = 0;
  while ((c = getopt(argc, argv, "m:")) != -1) {
    switch(c) {
    case 'm':
      memsize = atoi(optarg) * 1024 * 1024;
      break;
    default:
      errx(1, "Invalid option specifed");
    }
  }

  if(!memsize)
    errx(1, "Memory size not specified");
}

/*
touch_memory: force physical memory allocation
*/
void touch_memory(char *p, int 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(1, "mmap failed");
    touch_memory(p, memsize);
  }
  else {;
    if (munmap(p, memsize) == -1)
      errx(1, "munmap failed");
  }
}

/*
sigint: set the exit flag on receiving SIGINT
*/
void sigint(int num) {
  flag_exit = 1;
}

/*
sigusr1: allocate/free memory on receving SIGUSR1
*/
void sigusr1(int num) {
  mem_map();
  flag_allocated = !flag_allocated;
}


int main(int argc, char **argv) {
  signal(SIGINT, sigint);
  signal(SIGUSR1, sigusr1);

  process_options(argc, argv);

  while(!flag_exit)
    sleep(1);

  return 0;
}

[-- Attachment #3: test_mem_fun.sh --]
[-- Type: application/x-sh, Size: 2581 bytes --]

[-- Attachment #4: Type: text/plain, Size: 390 bytes --]

------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 

[-- Attachment #5: Type: text/plain, Size: 155 bytes --]

_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [LTP] Testcase to validate the memory usage limit imposed by the topmost memory cgroup
  2009-12-25  9:22 [LTP] Testcase to validate the memory usage limit imposed by the topmost memory cgroup Mohamed Naufal
@ 2010-01-06 16:45 ` Mohamed Naufal
  2010-01-07  8:50 ` Subrata Modak
  2010-01-11 16:22 ` Cyril Hrubis
  2 siblings, 0 replies; 20+ messages in thread
From: Mohamed Naufal @ 2010-01-06 16:45 UTC (permalink / raw)
  To: ltp-list


[-- Attachment #1.1: Type: text/plain, Size: 5 bytes --]

ping

[-- Attachment #1.2: Type: text/html, Size: 38 bytes --]

[-- Attachment #2: Type: text/plain, Size: 390 bytes --]

------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 

[-- Attachment #3: Type: text/plain, Size: 155 bytes --]

_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [LTP] Testcase to validate the memory usage limit imposed by the topmost memory cgroup
  2009-12-25  9:22 [LTP] Testcase to validate the memory usage limit imposed by the topmost memory cgroup Mohamed Naufal
  2010-01-06 16:45 ` Mohamed Naufal
@ 2010-01-07  8:50 ` Subrata Modak
  2010-01-11 16:22 ` Cyril Hrubis
  2 siblings, 0 replies; 20+ messages in thread
From: Subrata Modak @ 2010-01-07  8:50 UTC (permalink / raw)
  To: Mohamed Naufal; +Cc: ltp-list

On Fri, 2009-12-25 at 14:52 +0530, Mohamed Naufal wrote:
> Hi
> 
> I am a student who attended the FOSS.IN LTP workout (Bangalore,
> India). I have attached one of the testcases we were working on.
> Thought I would get it reviewed before making a patch. More testcases
> to follow.
> 
> Comments appreciated.

Seems that the Script is trying to test some Memory Controllers.
However, i am not sure about the C program. Can you please try to
improve the documentation and see if you can fit you controller test
somewhere inside ltp/testcases/kernel/controllers/ ?

Regards--
Subrata

> 
> Naufal 
> ------------------------------------------------------------------------------
> This SF.Net email is sponsored by the Verizon Developer Community
> Take advantage of Verizon's best-in-class app development support
> A streamlined, 14 day to market process makes app distribution fast and easy
> Join now and get one step closer to millions of Verizon customers
> http://p.sf.net/sfu/verizon-dev2dev 
> _______________________________________________ Ltp-list mailing list Ltp-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ltp-list


------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [LTP] Testcase to validate the memory usage limit imposed by the topmost memory cgroup
  2009-12-25  9:22 [LTP] Testcase to validate the memory usage limit imposed by the topmost memory cgroup Mohamed Naufal
  2010-01-06 16:45 ` Mohamed Naufal
  2010-01-07  8:50 ` Subrata Modak
@ 2010-01-11 16:22 ` Cyril Hrubis
       [not found]   ` <20100128041619.GB16209@malik-laptop.in.ibm.com>
  2 siblings, 1 reply; 20+ messages in thread
From: Cyril Hrubis @ 2010-01-11 16:22 UTC (permalink / raw)
  To: Mohamed Naufal; +Cc: ltp-list

Hi!

> /*
> sigusr1: allocate/free memory on receving SIGUSR1
> */
> void sigusr1(int num) {
>   mem_map();
>   flag_allocated = !flag_allocated;
> }
> 
> int main(int argc, char **argv) {
>   signal(SIGINT, sigint);
>   signal(SIGUSR1, sigusr1);
> 
>   process_options(argc, argv);
> 
>   while(!flag_exit)
>     sleep(1);
> 
>   return 0;
> }


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)').

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [LTP] Testcase to validate the memory usage limit imposed by the topmost memory cgroup
       [not found]   ` <20100128041619.GB16209@malik-laptop.in.ibm.com>
@ 2010-02-21  7:53     ` Mohamed Naufal
  2010-02-21  8:05       ` Mohamed Naufal
  2010-02-26 20:13       ` Garrett Cooper
  0 siblings, 2 replies; 20+ messages in thread
From: Mohamed Naufal @ 2010-02-21  7:53 UTC (permalink / raw)
  To: ltp-list, skumar


[-- Attachment #1.1: Type: text/plain, Size: 1883 bytes --]

On 28 January 2010 09:46, Sudhir Kumar <skumar@linux.vnet.ibm.com> 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

[-- Attachment #1.2: Type: text/html, Size: 2691 bytes --]

[-- Attachment #2: memcg_control.patch --]
[-- Type: text/x-patch, Size: 12934 bytes --]

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 <naufal11@gmail.com>                     ##
+##                                                                            ##
+################################################################################
+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 <naufal11@gmail.com >                      */
+/*                                                                             */
+/*******************************************************************************/
+#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.

[-- Attachment #3: Type: text/plain, Size: 345 bytes --]

------------------------------------------------------------------------------
Download Intel&#174; 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

[-- Attachment #4: Type: text/plain, Size: 155 bytes --]

_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [LTP] Testcase to validate the memory usage limit imposed by the topmost memory cgroup
  2010-02-21  7:53     ` Mohamed Naufal
@ 2010-02-21  8:05       ` Mohamed Naufal
  2010-02-26 19:05         ` Mohamed Naufal
  2010-02-26 20:13       ` Garrett Cooper
  1 sibling, 1 reply; 20+ messages in thread
From: Mohamed Naufal @ 2010-02-21  8:05 UTC (permalink / raw)
  To: ltp-list, skumar

Signed-off-by Mohamed Naufal Basheer <naufal11@gmail.com>

Naufal

------------------------------------------------------------------------------
Download Intel&#174; 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
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [LTP] Testcase to validate the memory usage limit imposed by the topmost memory cgroup
  2010-02-21  8:05       ` Mohamed Naufal
@ 2010-02-26 19:05         ` Mohamed Naufal
  0 siblings, 0 replies; 20+ messages in thread
From: Mohamed Naufal @ 2010-02-26 19:05 UTC (permalink / raw)
  To: ltp-list

ping

------------------------------------------------------------------------------
Download Intel&#174; 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
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [LTP] Testcase to validate the memory usage limit imposed by the topmost memory cgroup
  2010-02-21  7:53     ` Mohamed Naufal
  2010-02-21  8:05       ` Mohamed Naufal
@ 2010-02-26 20:13       ` Garrett Cooper
  2010-02-27 13:05         ` Mohamed Naufal
  1 sibling, 1 reply; 20+ messages in thread
From: Garrett Cooper @ 2010-02-26 20:13 UTC (permalink / raw)
  To: Mohamed Naufal; +Cc: ltp-list

On Sat, Feb 20, 2010 at 11:53 PM, Mohamed Naufal <naufal11@gmail.com> wrote:
>
>
> On 28 January 2010 09:46, Sudhir Kumar <skumar@linux.vnet.ibm.com> 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.

Next time please attach and also paste the diff inline in the email as
some MTAs will remove attachments.

1. Avoid for i in $(seq ). Use i=0; while [ $i -lt $TST_TOTAL ] ; do
... : $(( i += 1 )); done (it's POSIXly correct and doesn't require
external utilities).
2. Use hard tabs instead of 4 space tabs.
3. Semi-colons at the end of lines in bourne shell aren't required;
please remove them.
4. Why are you doing this?

+    pushd $TST_PATH/mnt > /dev/null
+    mkdir $TST_PATH/mnt/$i 2> /dev/null
+    pushd $i > /dev/null

mkdir $TST_PATH/mnt/$i should be enough. Don't do 2> /dev/null please!

5. This isn't standard:

+    popd > /dev/null
+    rmdir $i 2> /dev/null
+    popd > /dev/null

Please use rm -Rf $i

6. sleep 1 may not be long enough is mmapping a large section of memory.
7. What if I specified a negative value via -m ?

+  if(!memsize)
+      errx(3, "Invalid usage");

8. Run through a spellchecker.
9. You can assume that $LTPROOT/testcases/bin is automatically added
to $PATH; thus implicitly hardcoding the path to the executable seems
rather silly.
10. if [ ! $(grep -w memory /proc/cgroups | cut -f4) == "1" ] <-- a.
`==' is a bashism. b. you can do != in place of ! $(grep ... ) c.
please quote the value that you're grabbing on the left via grep so it
doesn't emit nasty noise from test(1).
11. KILLED_CNT=$(($KILLED_CNT + 1)) could be : $(( KILLED_CNT += 1 ))
(POSIXly correct).
12. #define STATUS_PIPE "/tmp/status_pipe" is poorly hardcoded. Set
$TMP in the script like so:

export TMP=${TMP:-/tmp}

cd to $TMP at the start of the test.

Remove /tmp/ from the constant above.

Thanks,
-Garrett

------------------------------------------------------------------------------
Download Intel&#174; 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
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [LTP] Testcase to validate the memory usage limit imposed by the topmost memory cgroup
  2010-02-26 20:13       ` Garrett Cooper
@ 2010-02-27 13:05         ` Mohamed Naufal
  2010-02-27 14:06           ` Mohamed Naufal
  0 siblings, 1 reply; 20+ messages in thread
From: Mohamed Naufal @ 2010-02-27 13:05 UTC (permalink / raw)
  To: ltp-list

On 27 February 2010 01:43, Garrett Cooper <yanegomi@gmail.com> wrote:


[...]


Thank you for your comments. Here is the updated patch.

<patch>
diff -Naru ltpv/runtest/controllers ltpd/runtest/controllers
--- ltpv/runtest/controllers    2010-02-20 15:42:13.000000000 +0530
+++ ltpd/runtest/controllers    2010-02-27 17:51:10.358553399 +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 -Naru ltpv/testcases/kernel/controllers/memcg/control/Makefile
ltpd/testcases/kernel/controllers/memcg/control/Makefile
--- ltpv/testcases/kernel/controllers/memcg/control/Makefile
1970-01-01 05:30:00.000000000 +0530
+++ ltpd/testcases/kernel/controllers/memcg/control/Makefile
2010-02-27 17:51:10.359555806 +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 -Naru ltpv/testcases/kernel/controllers/memcg/control/memcg_control_test.sh
ltpd/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
+++ ltpd/testcases/kernel/controllers/memcg/control/memcg_control_test.sh
   2010-02-27 18:17:08.668300711 +0530
@@ -0,0 +1,166 @@
+#!/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 program;  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 <naufal11@gmail.com>
        ##
+##
        ##
+################################################################################
+
+if [ "$(grep -w memory /proc/cgroups | cut -f4)" -ne "1" ]; then
+    echo "WARNING:"
+    echo "Either kernel does not support 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
+
+export TMP=${TMP:-/tmp}
+cd $TMP
+
+TOT_MEM_LIMIT=$1
+ACTIVE_MEM_LIMIT=$2
+PROC_MEM=$3
+
+TST_PATH=$PWD
+STATUS_PIPE="$TMP/status_pipe"
+
+PASS=0
+FAIL=1
+
+# Check if the test process is killed on crossing boundary
+test_proc_kill()
+{
+    pushd $TMP > /dev/null
+    mem_process -m $PROC_MEM &
+    popd > /dev/null
+    sleep 1
+    echo $! > tasks
+
+    #Instruct the test process to start acquiring memory
+    echo m > $STATUS_PIPE
+    sleep 5
+
+    #Check if killed
+    ps -p $! > /dev/null 2> /dev/null
+    if [ $? -eq 0 ]; then
+        echo m > $STATUS_PIPE
+        echo x > $STATUS_PIPE
+    else
+        : $((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/$TST_NUM/memory.limit_in_bytes
+    echo "$TOT_MEM_LIMIT" > $TST_PATH/mnt/$TST_NUM/memory.memsw.limit_in_bytes
+
+    mkdir sub
+    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
+}
+
+# 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 += 1))
+        tst_resm TFAIL "$INFO"
+    fi
+}
+
+cleanup()
+{
+    if [ -e $TST_PATH/mnt ]; then
+        umount $TST_PATH/mnt 2> /dev/null
+        rm -rf $TST_PATH/mnt
+    fi
+}
+
+do_mount()
+{
+    cleanup
+
+    mkdir $TST_PATH/mnt
+    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
+        exit 1
+    fi
+}
+
+do_mount
+
+echo 1 > mnt/memory.use_hierarchy 2> /dev/null
+
+FAILED_CNT=0
+
+TST_NUM=1
+while [ $TST_NUM -le $TST_TOTAL ]; do
+    mkdir $TST_PATH/mnt/$TST_NUM
+    pushd $TST_PATH/mnt/$TST_NUM > /dev/null
+
+    testcase_$TST_NUM;
+
+    popd > /dev/null
+    rmdir $TST_PATH/mnt/$TST_NUM
+    : $((TST_NUM += 1))
+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 -Naru ltpv/testcases/kernel/controllers/memcg/control/mem_process.c
ltpd/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
+++ ltpd/testcases/kernel/controllers/memcg/control/mem_process.c
2010-02-27 18:22:43.246178794 +0530
@@ -0,0 +1,141 @@
+/*******************************************************************************/
+/*
         */
+/*  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 <naufal11@gmail.com >
         */
+/*
         */
+/*******************************************************************************/
+#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 "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 <= 0)
+        errx(3, "Invalid usage");
+}
+
+/*
+ * touch_memory: force physical memory allocation
+ */
+void touch_memory(char *p)
+{
+    int i;
+    int pagesize = getpagesize();
+
+    for (i = 0; i < memsize; i += pagesize)
+        p[i] = 0xef;
+}
+
+void mem_map()
+{
+    static char *p;
+
+    if (!flag_allocated) {
+        p = mmap(NULL, memsize, PROT_READ | PROT_WRITE, MAP_SHARED |
MAP_ANONYMOUS, 0, 0);
+        if(p == MAP_FAILED)
+            errx(4, "mmap failed");
+        touch_memory(p);
+    }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 -Naru ltpv/testcases/kernel/controllers/memcg/README
ltpd/testcases/kernel/controllers/memcg/README
--- ltpv/testcases/kernel/controllers/memcg/README    2010-02-20
15:42:13.000000000 +0530
+++ ltpd/testcases/kernel/controllers/memcg/README    2010-02-27
17:51:10.361554968 +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 received
+through the named pipe "status_pipe" and frees it on receiving 'm' again.
+It exits on receiving '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.
</patch>

Naufal

------------------------------------------------------------------------------
Download Intel&#174; 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
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [LTP] Testcase to validate the memory usage limit imposed by the topmost memory cgroup
  2010-02-27 13:05         ` Mohamed Naufal
@ 2010-02-27 14:06           ` Mohamed Naufal
  2010-02-27 20:24             ` Garrett Cooper
  0 siblings, 1 reply; 20+ messages in thread
From: Mohamed Naufal @ 2010-02-27 14:06 UTC (permalink / raw)
  To: ltp-list

[-- Attachment #1: Type: text/plain, Size: 74 bytes --]

It seems my mailer screws up the formatting. Attaching the patch.

Naufal

[-- Attachment #2: mem.patch --]
[-- Type: text/x-patch, Size: 12415 bytes --]

diff -Naru ltpv/runtest/controllers ltpd/runtest/controllers
--- ltpv/runtest/controllers	2010-02-20 15:42:13.000000000 +0530
+++ ltpd/runtest/controllers	2010-02-27 17:51:10.358553399 +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 -Naru ltpv/testcases/kernel/controllers/memcg/control/Makefile ltpd/testcases/kernel/controllers/memcg/control/Makefile
--- ltpv/testcases/kernel/controllers/memcg/control/Makefile	1970-01-01 05:30:00.000000000 +0530
+++ ltpd/testcases/kernel/controllers/memcg/control/Makefile	2010-02-27 17:51:10.359555806 +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 -Naru ltpv/testcases/kernel/controllers/memcg/control/memcg_control_test.sh ltpd/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
+++ ltpd/testcases/kernel/controllers/memcg/control/memcg_control_test.sh	2010-02-27 18:17:08.668300711 +0530
@@ -0,0 +1,166 @@
+#!/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 program;  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 <naufal11@gmail.com>                     ##
+##                                                                            ##
+################################################################################
+
+if [ "$(grep -w memory /proc/cgroups | cut -f4)" -ne "1" ]; then
+	echo "WARNING:"
+	echo "Either kernel does not support 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
+
+export TMP=${TMP:-/tmp}
+cd $TMP
+
+TOT_MEM_LIMIT=$1
+ACTIVE_MEM_LIMIT=$2
+PROC_MEM=$3
+
+TST_PATH=$PWD
+STATUS_PIPE="$TMP/status_pipe"
+
+PASS=0
+FAIL=1
+
+# Check if the test process is killed on crossing boundary
+test_proc_kill()
+{
+	pushd $TMP > /dev/null
+	mem_process -m $PROC_MEM &
+	popd > /dev/null
+	sleep 1
+	echo $! > tasks
+ 
+	#Instruct the test process to start acquiring memory
+	echo m > $STATUS_PIPE
+	sleep 5
+
+	#Check if killed
+	ps -p $! > /dev/null 2> /dev/null
+	if [ $? -eq 0 ]; then
+		echo m > $STATUS_PIPE
+		echo x > $STATUS_PIPE
+	else
+		: $((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/$TST_NUM/memory.limit_in_bytes
+	echo "$TOT_MEM_LIMIT" > $TST_PATH/mnt/$TST_NUM/memory.memsw.limit_in_bytes
+
+	mkdir sub
+	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
+}
+
+# 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 += 1))
+		tst_resm TFAIL "$INFO"
+	fi
+}
+
+cleanup()
+{
+	if [ -e $TST_PATH/mnt ]; then
+		umount $TST_PATH/mnt 2> /dev/null
+		rm -rf $TST_PATH/mnt
+	fi
+}
+
+do_mount()
+{
+	cleanup
+
+	mkdir $TST_PATH/mnt
+	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
+		exit 1
+	fi
+}
+
+do_mount
+
+echo 1 > mnt/memory.use_hierarchy 2> /dev/null
+
+FAILED_CNT=0
+
+TST_NUM=1
+while [ $TST_NUM -le $TST_TOTAL ]; do
+	mkdir $TST_PATH/mnt/$TST_NUM
+	pushd $TST_PATH/mnt/$TST_NUM > /dev/null
+
+	testcase_$TST_NUM;
+
+	popd > /dev/null
+	rmdir $TST_PATH/mnt/$TST_NUM
+	: $((TST_NUM += 1))
+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 -Naru ltpv/testcases/kernel/controllers/memcg/control/mem_process.c ltpd/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
+++ ltpd/testcases/kernel/controllers/memcg/control/mem_process.c	2010-02-27 18:22:43.246178794 +0530
@@ -0,0 +1,141 @@
+/*******************************************************************************/
+/*                                                                             */
+/*  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 <naufal11@gmail.com >                      */
+/*                                                                             */
+/*******************************************************************************/
+#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 "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 <= 0)
+		errx(3, "Invalid usage");
+}
+
+/*
+ * touch_memory: force physical memory allocation
+ */
+void touch_memory(char *p)
+{
+	int i;
+	int pagesize = getpagesize();
+
+	for (i = 0; i < memsize; i += pagesize)
+		p[i] = 0xef;
+}
+
+void mem_map()
+{
+	static char *p;
+
+	if (!flag_allocated) {
+		p = mmap(NULL, memsize, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, 0, 0);
+		if(p == MAP_FAILED)
+			errx(4, "mmap failed");
+		touch_memory(p);
+	}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 -Naru ltpv/testcases/kernel/controllers/memcg/README ltpd/testcases/kernel/controllers/memcg/README
--- ltpv/testcases/kernel/controllers/memcg/README	2010-02-20 15:42:13.000000000 +0530
+++ ltpd/testcases/kernel/controllers/memcg/README	2010-02-27 17:51:10.361554968 +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 received 
+through the named pipe "status_pipe" and frees it on receiving 'm' again. 
+It exits on receiving '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.

[-- Attachment #3: Type: text/plain, Size: 345 bytes --]

------------------------------------------------------------------------------
Download Intel&#174; 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

[-- Attachment #4: Type: text/plain, Size: 155 bytes --]

_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [LTP] Testcase to validate the memory usage limit imposed by the topmost memory cgroup
  2010-02-27 14:06           ` Mohamed Naufal
@ 2010-02-27 20:24             ` Garrett Cooper
  2010-02-28 18:14               ` Rishikesh K Rajak
  0 siblings, 1 reply; 20+ messages in thread
From: Garrett Cooper @ 2010-02-27 20:24 UTC (permalink / raw)
  To: Mohamed Naufal; +Cc: ltp-list


[-- Attachment #1.1: Type: text/plain, Size: 300 bytes --]

On Sat, Feb 27, 2010 at 6:06 AM, Mohamed Naufal <naufal11@gmail.com> wrote:

> It seems my mailer screws up the formatting. Attaching the patch.
>

    This looks good (minus the unnecessary dependency on libcontrollers,
that I'll yank after commit). Rishi, are we ready for commit?
Thanks,
-Garrett

[-- Attachment #1.2: Type: text/html, Size: 616 bytes --]

[-- Attachment #2: Type: text/plain, Size: 345 bytes --]

------------------------------------------------------------------------------
Download Intel&#174; 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

[-- Attachment #3: Type: text/plain, Size: 155 bytes --]

_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [LTP] Testcase to validate the memory usage limit imposed by the topmost memory cgroup
  2010-02-27 20:24             ` Garrett Cooper
@ 2010-02-28 18:14               ` Rishikesh K Rajak
  2010-03-01  2:37                 ` Mohamed Naufal
  0 siblings, 1 reply; 20+ messages in thread
From: Rishikesh K Rajak @ 2010-02-28 18:14 UTC (permalink / raw)
  To: Garrett Cooper, i; +Cc: ltp-list

>>Rishi, are we ready for commit?

Yes committed to next branch, let me test for any regression, and then
will commit to maint/master branch.

Thanks
-Rishi
On Sat, Feb 27, 2010 at 12:24:58PM -0800, Garrett Cooper wrote:

-- 
Thanks & Regards
Rishi
LTP Maintainer
IBM, LTC, Bangalore
Please join IRC #ltp @ irc.freenode.net

------------------------------------------------------------------------------
Download Intel&#174; 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
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [LTP] Testcase to validate the memory usage limit imposed by the topmost memory cgroup
  2010-02-28 18:14               ` Rishikesh K Rajak
@ 2010-03-01  2:37                 ` Mohamed Naufal
  2010-03-01  4:29                   ` Rishikesh K Rajak
  2010-03-01  5:21                   ` Rishikesh K Rajak
  0 siblings, 2 replies; 20+ messages in thread
From: Mohamed Naufal @ 2010-03-01  2:37 UTC (permalink / raw)
  To: ltp-list, risrajak

On 28 February 2010 23:44, Rishikesh K Rajak
<risrajak@linux.vnet.ibm.com> wrote:
>>>Rishi, are we ready for commit?
>
> Yes committed to next branch, let me test for any regression, and then
> will commit to maint/master branch.
>
>

[...]

Hi

The new source files in my patch doesn't appear in the next branch.

Naufal

------------------------------------------------------------------------------
Download Intel&#174; 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
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [LTP] Testcase to validate the memory usage limit imposed by the topmost memory cgroup
  2010-03-01  2:37                 ` Mohamed Naufal
@ 2010-03-01  4:29                   ` Rishikesh K Rajak
  2010-03-01  5:21                   ` Rishikesh K Rajak
  1 sibling, 0 replies; 20+ messages in thread
From: Rishikesh K Rajak @ 2010-03-01  4:29 UTC (permalink / raw)
  To: Mohamed Naufal; +Cc: ltp-list

On Mon, Mar 01, 2010 at 08:07:50AM +0530, Mohamed Naufal wrote:
> On 28 February 2010 23:44, Rishikesh K Rajak
> <risrajak@linux.vnet.ibm.com> wrote:
> >>>Rishi, are we ready for commit?
> >
> > Yes committed to next branch, let me test for any regression, and then
> > will commit to maint/master branch.
> >
> >
> 
> [...]
> 
> Hi
> 
> The new source files in my patch doesn't appear in the next branch.

HI Naufal,

can you please clone with -b <branchname> ?

e.g: git clone -b next
git://ltp.git.sourceforge.net/gitroot/ltp/ltp-dev.git ltp

And let me know that your patch is in. I can see it as commit:
3bc8ecdb69b29436e2987173ffdd7244d8897942

Thanks
Rishi

> 
> Naufal

-- 
Thanks & Regards
Rishi
LTP Maintainer
IBM, LTC, Bangalore
Please join IRC #ltp @ irc.freenode.net

------------------------------------------------------------------------------
Download Intel&#174; 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
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [LTP] Testcase to validate the memory usage limit imposed by the topmost memory cgroup
  2010-03-01  2:37                 ` Mohamed Naufal
  2010-03-01  4:29                   ` Rishikesh K Rajak
@ 2010-03-01  5:21                   ` Rishikesh K Rajak
  2010-03-01  6:28                     ` Rishikesh K Rajak
  1 sibling, 1 reply; 20+ messages in thread
From: Rishikesh K Rajak @ 2010-03-01  5:21 UTC (permalink / raw)
  To: Mohamed Naufal; +Cc: ltp-list

On Mon, Mar 01, 2010 at 08:07:50AM +0530, Mohamed Naufal wrote:
> On 28 February 2010 23:44, Rishikesh K Rajak
> <risrajak@linux.vnet.ibm.com> wrote:
> >>>Rishi, are we ready for commit?
> >
> > Yes committed to next branch, let me test for any regression, and then
> > will commit to maint/master branch.
> >
> >
> 
> [...]
> 
> Hi
> 
> The new source files in my patch doesn't appear in the next branch.


Something really has got screwed with your patch can you please resend
your patch against next branch as attachment ?

Thanks
Rishi
> 
> Naufal

-- 
Thanks & Regards
Rishi
LTP Maintainer
IBM, LTC, Bangalore
Please join IRC #ltp @ irc.freenode.net

------------------------------------------------------------------------------
Download Intel&#174; 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
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [LTP] Testcase to validate the memory usage limit imposed by the topmost memory cgroup
  2010-03-01  5:21                   ` Rishikesh K Rajak
@ 2010-03-01  6:28                     ` Rishikesh K Rajak
  2010-03-01  7:40                       ` Mohamed Naufal
  0 siblings, 1 reply; 20+ messages in thread
From: Rishikesh K Rajak @ 2010-03-01  6:28 UTC (permalink / raw)
  To: Mohamed Naufal; +Cc: ltp-list

On Mon, Mar 01, 2010 at 10:51:00AM +0530, Rishikesh K Rajak wrote:
> On Mon, Mar 01, 2010 at 08:07:50AM +0530, Mohamed Naufal wrote:
> > On 28 February 2010 23:44, Rishikesh K Rajak
> > <risrajak@linux.vnet.ibm.com> wrote:
> > >>>Rishi, are we ready for commit?
> > >
> > > Yes committed to next branch, let me test for any regression, and then
> > > will commit to maint/master branch.
> > >
> > >
> > 
> > [...]
> > 
> > Hi
> > 
> > The new source files in my patch doesn't appear in the next branch.
> 
> 
> Something really has got screwed with your patch can you please resend
> your patch against next branch as attachment ?

ahhh !!! got the problem. Your patch seems to be taken as wrong diff for
new source file addition, so it will never add the new source file.

For new file it should be always /dev/null , but your patch reflects
something else as(Here Makefile is newly created by you):

===============================
diff -Naru ltpv/testcases/kernel/controllers/memcg/control/Makefile
ltpd/testcases/kernel/controllers/memcg/control/Makefile
--- ltpv/testcases/kernel/controllers/memcg/control/Makefile
1970-01-01 05:30:00.000000000 +0530
+++ ltpd/testcases/kernel/controllers/memcg/control/Makefile
2010-02-27 17:51:10.359555806 +0530
@@ -0,0 +1,33 @@

================================

Please create your patch against next tree or attach the source file
here as text, i will create a patch.

Thanks
Rishi
> 
> Thanks
> Rishi
> > 
> > Naufal
> 
> -- 
> Thanks & Regards
> Rishi
> LTP Maintainer
> IBM, LTC, Bangalore
> Please join IRC #ltp @ irc.freenode.net
> 
> ------------------------------------------------------------------------------
> Download Intel&#174; 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
> Ltp-list@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/ltp-list

-- 
Thanks & Regards
Rishi
LTP Maintainer
IBM, LTC, Bangalore
Please join IRC #ltp @ irc.freenode.net

------------------------------------------------------------------------------
Download Intel&#174; 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
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [LTP] Testcase to validate the memory usage limit imposed by the topmost memory cgroup
  2010-03-01  6:28                     ` Rishikesh K Rajak
@ 2010-03-01  7:40                       ` Mohamed Naufal
  2010-03-01  8:58                         ` Rishikesh K Rajak
       [not found]                         ` <20100302120239.GA2845@malik-laptop.in.ibm.com>
  0 siblings, 2 replies; 20+ messages in thread
From: Mohamed Naufal @ 2010-03-01  7:40 UTC (permalink / raw)
  To: ltp-list, risrajak

[-- Attachment #1: Type: text/plain, Size: 276 bytes --]

On 1 March 2010 11:58, Rishikesh K Rajak <risrajak@linux.vnet.ibm.com> wrote:


[...]


>
> Please create your patch against next tree or attach the source file
> here as text, i will create a patch.
>

[...]

Please find the patch attached. Hope this is good enough.

Naufal

[-- Attachment #2: memcg.patch --]
[-- Type: text/x-patch, Size: 12077 bytes --]

diff --git a/runtest/controllers b/runtest/controllers
index 2df958e..d495010 100644
--- a/runtest/controllers
+++ b/runtest/controllers
@@ -3,5 +3,6 @@ cgroup		cgroup_regression_test.sh
 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 --git a/testcases/kernel/controllers/memcg/README b/testcases/kernel/controllers/memcg/README
index 4082f12..ea4df68 100644
--- a/testcases/kernel/controllers/memcg/README
+++ b/testcases/kernel/controllers/memcg/README
@@ -15,6 +15,16 @@ of memctl..
 
 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 received 
+through the named pipe /tmp/status_pipe and frees it on receiving 'm' again. 
+It exits on receiving '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.
diff --git a/testcases/kernel/controllers/memcg/control/Makefile b/testcases/kernel/controllers/memcg/control/Makefile
new file mode 100644
index 0000000..0dbc994
--- /dev/null
+++ b/testcases/kernel/controllers/memcg/control/Makefile
@@ -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 --git a/testcases/kernel/controllers/memcg/control/mem_process.c b/testcases/kernel/controllers/memcg/control/mem_process.c
new file mode 100644
index 0000000..60361aa
--- /dev/null
+++ b/testcases/kernel/controllers/memcg/control/mem_process.c
@@ -0,0 +1,141 @@
+/*******************************************************************************/
+/*                                                                             */
+/*  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 <naufal11@gmail.com >                      */
+/*                                                                             */
+/*******************************************************************************/
+#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 "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 <= 0)
+		errx(3, "Invalid usage");
+}
+
+/*
+ * touch_memory: force physical memory allocation
+ */
+void touch_memory(char *p)
+{
+	int i;
+	int pagesize = getpagesize();
+
+	for (i = 0; i < memsize; i += pagesize)
+		p[i] = 0xef;
+}
+
+void mem_map()
+{
+	static char *p;
+
+	if (!flag_allocated) {
+		p = mmap(NULL, memsize, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, 0, 0);
+		if(p == MAP_FAILED)
+			errx(4, "mmap failed");
+		touch_memory(p);
+	}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 --git a/testcases/kernel/controllers/memcg/control/memcg_control_test.sh b/testcases/kernel/controllers/memcg/control/memcg_control_test.sh
new file mode 100644
index 0000000..da36e05
--- /dev/null
+++ b/testcases/kernel/controllers/memcg/control/memcg_control_test.sh
@@ -0,0 +1,166 @@
+#!/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 program;  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 <naufal11@gmail.com>                     ##
+##                                                                            ##
+################################################################################
+
+if [ "$(grep -w memory /proc/cgroups | cut -f4)" -ne "1" ]; then
+	echo "WARNING:"
+	echo "Either kernel does not support 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
+
+export TMP=${TMP:-/tmp}
+cd $TMP
+
+TOT_MEM_LIMIT=$1
+ACTIVE_MEM_LIMIT=$2
+PROC_MEM=$3
+
+TST_PATH=$PWD
+STATUS_PIPE="$TMP/status_pipe"
+
+PASS=0
+FAIL=1
+
+# Check if the test process is killed on crossing boundary
+test_proc_kill()
+{
+	pushd $TMP > /dev/null
+	mem_process -m $PROC_MEM &
+	popd > /dev/null
+	sleep 1
+	echo $! > tasks
+ 
+	#Instruct the test process to start acquiring memory
+	echo m > $STATUS_PIPE
+	sleep 5
+
+	#Check if killed
+	ps -p $! > /dev/null 2> /dev/null
+	if [ $? -eq 0 ]; then
+		echo m > $STATUS_PIPE
+		echo x > $STATUS_PIPE
+	else
+		: $((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/$TST_NUM/memory.limit_in_bytes
+	echo "$TOT_MEM_LIMIT" > $TST_PATH/mnt/$TST_NUM/memory.memsw.limit_in_bytes
+
+	mkdir sub
+	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
+}
+
+# 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 += 1))
+		tst_resm TFAIL "$INFO"
+	fi
+}
+
+cleanup()
+{
+	if [ -e $TST_PATH/mnt ]; then
+		umount $TST_PATH/mnt 2> /dev/null
+		rm -rf $TST_PATH/mnt
+	fi
+}
+
+do_mount()
+{
+	cleanup
+
+	mkdir $TST_PATH/mnt
+	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
+		exit 1
+	fi
+}
+
+do_mount
+
+echo 1 > mnt/memory.use_hierarchy 2> /dev/null
+
+FAILED_CNT=0
+
+TST_NUM=1
+while [ $TST_NUM -le $TST_TOTAL ]; do
+	mkdir $TST_PATH/mnt/$TST_NUM
+	pushd $TST_PATH/mnt/$TST_NUM > /dev/null
+
+	testcase_$TST_NUM
+
+	popd > /dev/null
+	rmdir $TST_PATH/mnt/$TST_NUM
+	: $((TST_NUM += 1))
+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

[-- Attachment #3: Type: text/plain, Size: 345 bytes --]

------------------------------------------------------------------------------
Download Intel&#174; 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

[-- Attachment #4: Type: text/plain, Size: 155 bytes --]

_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: [LTP] Testcase to validate the memory usage limit imposed by the topmost memory cgroup
  2010-03-01  7:40                       ` Mohamed Naufal
@ 2010-03-01  8:58                         ` Rishikesh K Rajak
       [not found]                         ` <20100302120239.GA2845@malik-laptop.in.ibm.com>
  1 sibling, 0 replies; 20+ messages in thread
From: Rishikesh K Rajak @ 2010-03-01  8:58 UTC (permalink / raw)
  To: Mohamed Naufal; +Cc: ltp-list

On Mon, Mar 01, 2010 at 01:10:31PM +0530, Mohamed Naufal wrote:
> On 1 March 2010 11:58, Rishikesh K Rajak <risrajak@linux.vnet.ibm.com> wrote:
> 
> 
> [...]
> 
> 
> >
> > Please create your patch against next tree or attach the source file
> > here as text, i will create a patch.
> >
> 
> [...]
> 
> Please find the patch attached. Hope this is good enough.


Yes commited now to next branch. It will be evaluated in future, once it
is tagged as tested and no regression found will include it to master
branch and followed by month end tar ball release. Let somebody test it
here and find it useful through next branch only till now.
 
Thanks for working on this patch, much appreciable.

You can find as commit id:
c0b8157365beb18a627fe197be6ab111e8281e86

http://ltp.git.sourceforge.net/git/gitweb.cgi?p=ltp/ltp-dev.git;a=commit;h=c0b8157365beb18a627fe197be6ab111e8281e86

Thanks for your patch

-Rishi

> 
> Naufal



-- 
Thanks & Regards
Rishi
LTP Maintainer
IBM, LTC, Bangalore
Please join IRC #ltp @ irc.freenode.net

------------------------------------------------------------------------------
Download Intel&#174; 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
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [LTP] Testcase to validate the memory usage limit imposed by the topmost memory cgroup
       [not found]                         ` <20100302120239.GA2845@malik-laptop.in.ibm.com>
@ 2010-03-04 13:18                           ` Rishikesh K Rajak
  2010-03-06 12:14                             ` Mohamed Naufal
  0 siblings, 1 reply; 20+ messages in thread
From: Rishikesh K Rajak @ 2010-03-04 13:18 UTC (permalink / raw)
  To: Sudhir Kumar, Mohamed Naufal; +Cc: ltp-list

On Tue, Mar 02, 2010 at 05:32:39PM +0530, Sudhir Kumar wrote:
> On Mon, Mar 01, 2010 at 01:10:31PM +0530, Mohamed Naufal wrote:
> > On 1 March 2010 11:58, Rishikesh K Rajak <risrajak@linux.vnet.ibm.com> wrote:
> 
> The patch looks fair enough.
> Naufel, good job!
> I avoided review and comments as I wanted you to learn the way Linux
> community works, yourself. Now you being well faimiliar, we expect
> future contribution too :)
> 
> Acked-By: Sudhir Kumar <skumar@linux.vnet.ibm.com>
> Thanks Risi, for committing in the next branch.


Tested-By: Rishikesh K Rajak <risrajak@linux.vnet.ibm.com>

Merging to maste branch now...

Thanks
Rishi
> 
-- 
Thanks & Regards
Rishi
LTP Maintainer
IBM, LTC, Bangalore
Please join IRC #ltp @ irc.freenode.net

------------------------------------------------------------------------------
Download Intel&#174; 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
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [LTP] Testcase to validate the memory usage limit imposed by the topmost memory cgroup
  2010-03-04 13:18                           ` Rishikesh K Rajak
@ 2010-03-06 12:14                             ` Mohamed Naufal
  0 siblings, 0 replies; 20+ messages in thread
From: Mohamed Naufal @ 2010-03-06 12:14 UTC (permalink / raw)
  To: Sudhir Kumar, Mohamed Naufal, ltp-list


[-- Attachment #1.1: Type: text/plain, Size: 834 bytes --]

On 4 March 2010 18:48, Rishikesh K Rajak <risrajak@linux.vnet.ibm.com>wrote:

> On Tue, Mar 02, 2010 at 05:32:39PM +0530, Sudhir Kumar wrote:
> > On Mon, Mar 01, 2010 at 01:10:31PM +0530, Mohamed Naufal wrote:
> > > On 1 March 2010 11:58, Rishikesh K Rajak <risrajak@linux.vnet.ibm.com>
> wrote:
> >
> > The patch looks fair enough.
> > Naufel, good job!
> > I avoided review and comments as I wanted you to learn the way Linux
> > community works, yourself. Now you being well faimiliar, we expect
> > future contribution too :)
> >
> > Acked-By: Sudhir Kumar <skumar@linux.vnet.ibm.com>
> > Thanks Risi, for committing in the next branch.
>
>
> Tested-By: Rishikesh K Rajak <risrajak@linux.vnet.ibm.com>
>
> Merging to maste branch now...
>
> Thanks
> Rishi
> >
>

[...]

Maybe LTP should apply for Google Summer of Code ;)

Naufal

[-- Attachment #1.2: Type: text/html, Size: 1469 bytes --]

[-- Attachment #2: Type: text/plain, Size: 345 bytes --]

------------------------------------------------------------------------------
Download Intel&#174; 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

[-- Attachment #3: Type: text/plain, Size: 155 bytes --]

_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2010-03-06 12:15 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-12-25  9:22 [LTP] Testcase to validate the memory usage limit imposed by the topmost memory cgroup Mohamed Naufal
2010-01-06 16:45 ` Mohamed Naufal
2010-01-07  8:50 ` Subrata Modak
2010-01-11 16:22 ` Cyril Hrubis
     [not found]   ` <20100128041619.GB16209@malik-laptop.in.ibm.com>
2010-02-21  7:53     ` Mohamed Naufal
2010-02-21  8:05       ` Mohamed Naufal
2010-02-26 19:05         ` Mohamed Naufal
2010-02-26 20:13       ` Garrett Cooper
2010-02-27 13:05         ` Mohamed Naufal
2010-02-27 14:06           ` Mohamed Naufal
2010-02-27 20:24             ` Garrett Cooper
2010-02-28 18:14               ` Rishikesh K Rajak
2010-03-01  2:37                 ` Mohamed Naufal
2010-03-01  4:29                   ` Rishikesh K Rajak
2010-03-01  5:21                   ` Rishikesh K Rajak
2010-03-01  6:28                     ` Rishikesh K Rajak
2010-03-01  7:40                       ` Mohamed Naufal
2010-03-01  8:58                         ` Rishikesh K Rajak
     [not found]                         ` <20100302120239.GA2845@malik-laptop.in.ibm.com>
2010-03-04 13:18                           ` Rishikesh K Rajak
2010-03-06 12:14                             ` Mohamed Naufal

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.