Skip to contentSkip to conversation

memcg/functional: rewrite

PATCH New Stanislav Kholmanskikh 2 participants 7 messages Aug 23, 2016 – Aug 25, 2016

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/4 memcg/functional: rewrite

* Use the LTP API for shell tests
* Remove memcg_getpagesize binary, since its functionality can be provided by 'getconf PAGESIZE'
* Move common code to memcg_lib.sh

---
Changes since V1:
* Substituted the result() function with tst_resm and EXPECT_*
* Added a message for the situation when a pid dies after warm up

 testcases/kernel/controllers/memcg/.gitignore      |    1 -
 .../memcg/functional/memcg_function_test.sh        |  100 ++++---------
 .../memcg/functional/memcg_getpagesize.c           |   30 ----
 .../controllers/memcg/functional/memcg_lib.sh      |  168 ++++++++++++--------
 .../functional/memcg_max_usage_in_bytes_test.sh    |   49 +-----
 .../functional/memcg_memsw_limit_in_bytes_test.sh  |   70 ++-------
 .../memcg_move_charge_at_immigrate_test.sh         |   40 +----
 .../memcg/functional/memcg_stat_test.sh            |   49 +-----
 .../memcg/functional/memcg_usage_in_bytes_test.sh  |   47 +-----
 .../memcg/functional/memcg_use_hierarchy_test.sh   |   45 +-----
 10 files changed, 178 insertions(+), 421 deletions(-)
 delete mode 100644 testcases/kernel/controllers/memcg/functional/memcg_getpagesize.c
testcases/kernel/controllers/memcg/.gitignore +0 -1
index 6f62034..8730251 100644
@@ -1,5 +1,4 @@
 /control/mem_process
-/functional/memcg_getpagesize
 /functional/memcg_process
 /regression/memcg_test_1
 /regression/memcg_test_2
testcases/kernel/controllers/memcg/functional/memcg_function_test.sh +28 -72

182 lines not on this page · raw message

testcases/kernel/controllers/memcg/functional/memcg_getpagesize.c deleted +0 -30
deleted file mode 100644
index 557b540..0000000
@@ -1,30 +0,0 @@
-/******************************************************************************/
-/*                                                                            */
-/* Copyright (c) 2009 FUJITSU LIMITED                                         */
-/*                                                                            */
-/* This program is free software;  you can redistribute it and/or modify      */
-/* it under the terms of the GNU General Public License as published by       */
-/* the Free Software Foundation; either version 2 of the License, or          */
-/* (at your option) any later version.                                        */
-/*                                                                            */
-/* This program is distributed in the hope that it will be useful,            */
-/* but WITHOUT ANY WARRANTY;  without even the implied warranty of            */
-/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See                  */
-/* the GNU General Public License for more details.                           */
-/*                                                                            */
-/* You should have received a copy of the GNU General Public License          */
-/* along with this program;  if not, write to the Free Software               */
-/* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    */
-/*                                                                            */
-/* Author: Li Zefan <[email protected]>                                     */
-/*                                                                            */
-/******************************************************************************/
-
-#include <unistd.h>
-#include <stdio.h>
-
-int main(void)
-{
-	printf("%d\n", getpagesize());
-	return 0;
-}
testcases/kernel/controllers/memcg/functional/memcg_lib.sh +103 -65

323 lines not on this page · raw message

testcases/kernel/controllers/memcg/functional/memcg_max_usage_in_bytes_test.sh +7 -42

73 lines not on this page · raw message

testcases/kernel/controllers/memcg/functional/memcg_memsw_limit_in_bytes_test.sh +15 -55

119 lines not on this page · raw message

testcases/kernel/controllers/memcg/functional/memcg_move_charge_at_immigrate_test.sh +5 -35
index 406bd07..aeb7d0f 100755
@@ -26,11 +26,10 @@
 # History:      2012/01/16 - Created.
 #
 
-export TCID="memcg_move_charge_at_immigrate_test"
-export TST_TOTAL=4
-export TST_COUNT=0
+TCID="memcg_move_charge_at_immigrate_test"
+TST_TOTAL=4
 
-. memcg_lib.sh || exit 1
+. memcg_lib.sh
 
 # Test disable moving charges
 testcase_1()
@@ -58,35 +57,6 @@ testcase_4()
 	test_move_charge "--mmap-anon --shm" $PAGESIZE 3 $PAGESIZE $PAGESIZE 0 0
 }
 
-# Run all the test cases
-for i in $(seq 1 $TST_TOTAL)
-do
-	export TST_COUNT=$(( $TST_COUNT + 1 ))
-	cur_id=$i
+run_tests
 
-	do_mount
-	if [ $? -ne 0 ]; then
-		echo "Cannot create memcg"
-		exit 1
-	fi
-
-	# prepare
-	mkdir /dev/memcg/$i 2> /dev/null
-	cd /dev/memcg/$i
-
-	# run the case
-	testcase_$i
-
-	# clean up
-	sleep 1
-	cd $TEST_PATH
-	rmdir /dev/memcg/$i
-
-	cleanup
-done
-
-if [ $failed -ne 0 ]; then
-	exit $failed
-else
-	exit 0
-fi
+tst_exit
testcases/kernel/controllers/memcg/functional/memcg_stat_test.sh +7 -42

73 lines not on this page · raw message

testcases/kernel/controllers/memcg/functional/memcg_usage_in_bytes_test.sh +6 -41

65 lines not on this page · raw message

testcases/kernel/controllers/memcg/functional/memcg_use_hierarchy_test.sh +7 -38

67 lines not on this page · raw message

Signature · 1 line
1.7.1
#1 lore raw

PATCH v2 2/4 memcg/functional/memcg_process: cleanup

---
No changes since V1.

 .../controllers/memcg/functional/memcg_process.c   |   49 ++++++++++----------
 1 files changed, 25 insertions(+), 24 deletions(-)
testcases/kernel/controllers/memcg/functional/memcg_process.c +25 -24
index c12fae1..4ad2d6f 100644
@@ -35,20 +35,20 @@
 #include <string.h>
 #include <unistd.h>
 
-int fd;
+static int fd;
 
-int flag_exit;
-int flag_allocated;
+static volatile int flag_exit;
+static volatile int flag_allocated;
 
-int opt_mmap_anon;
-int opt_mmap_file;
-int opt_mmap_lock1;
-int opt_mmap_lock2;
-int opt_shm;
-int opt_hugepage;
+static int opt_mmap_anon;
+static int opt_mmap_file;
+static int opt_mmap_lock1;
+static int opt_mmap_lock2;
+static int opt_shm;
+static int opt_hugepage;
 
-int key_id;			/* used with opt_shm */
-unsigned long memsize;
+static int key_id;			/* used with opt_shm */
+static unsigned long memsize;
 
 #define FILE_HUGEPAGE	"/hugetlb/hugepagefile"
 
@@ -59,7 +59,7 @@ unsigned long memsize;
 #define SHM		(SCHAR_MAX + 5)
 #define HUGEPAGE	(SCHAR_MAX + 6)
 
-const struct option long_opts[] = {
+static const struct option long_opts[] = {
 	{"mmap-anon", 0, NULL, MMAP_ANON},
 	{"mmap-file", 0, NULL, MMAP_FILE},
 	{"mmap-lock1", 0, NULL, MMAP_LOCK1},
@@ -74,7 +74,7 @@ const struct option long_opts[] = {
 /*
  * process_options: read options from user input
  */
-void process_options(int argc, char *argv[])
+static void process_options(int argc, char *argv[])
 {
 	int c;
 	char *end;
@@ -117,7 +117,7 @@ void process_options(int argc, char *argv[])
 /*
  * touch_memory: force allocating phy memory
  */
-void touch_memory(char *p, int size)
+static void touch_memory(char *p, int size)
 {
 	int i;
 	int pagesize = getpagesize();
@@ -126,7 +126,7 @@ void touch_memory(char *p, int size)
 		p[i] = 0xef;
 }
 
-void mmap_anon()
+static void mmap_anon(void)
 {
 	static char *p;
 
@@ -142,7 +142,7 @@ void mmap_anon()
 	}
 }
 
-void mmap_file()
+static void mmap_file(void)
 {
 	static char *p;
 	static int fd_hugepage;
@@ -177,7 +177,7 @@ void mmap_file()
 	}
 }
 
-void mmap_lock1()
+static void mmap_lock1(void)
 {
 	static char *p;
 
@@ -193,7 +193,7 @@ void mmap_lock1()
 	}
 }
 
-void mmap_lock2()
+static void mmap_lock2(void)
 {
 	static char *p;
 
@@ -215,7 +215,7 @@ void mmap_lock2()
 	}
 }
 
-void shm()
+static void shm(void)
 {
 	static char *p;
 	static int shmid;
@@ -258,7 +258,7 @@ void shm()
 /*
  * sigint_handler: handle SIGINT by set the exit flag.
  */
-void sigint_handler(int __attribute__ ((unused)) signo)
+static void sigint_handler(int __attribute__ ((unused)) signo)
 {
 	flag_exit = 1;
 }
@@ -272,7 +272,7 @@ void sigint_handler(int __attribute__ ((unused)) signo)
  * When we receive SIGUSR again, we will free all the allocated
  * memory.
  */
-void sigusr_handler(int __attribute__ ((unused)) signo)
+static void sigusr_handler(int __attribute__ ((unused)) signo)
 {
 	if (opt_mmap_anon)
 		mmap_anon();
@@ -303,14 +303,15 @@ int main(int argc, char *argv[])
 	memset(&sigint_action, 0, sizeof(sigint_action));
 	memset(&sigusr_action, 0, sizeof(sigusr_action));
 
-	/* TODO: add error handling below. */
 	sigemptyset(&sigint_action.sa_mask);
 	sigint_action.sa_handler = &sigint_handler;
-	sigaction(SIGINT, &sigint_action, NULL);
+	if (sigaction(SIGINT, &sigint_action, NULL))
+		err(1, "sigaction(SIGINT)");
 
 	sigemptyset(&sigusr_action.sa_mask);
 	sigusr_action.sa_handler = &sigusr_handler;
-	sigaction(SIGUSR1, &sigusr_action, NULL);
+	if (sigaction(SIGUSR1, &sigusr_action, NULL))
+		err(1, "sigaction(SIGUSR1)");
 
 	process_options(argc, argv);
 
Signature · 1 line
1.7.1
#2 lore raw

PATCH v2 3/4 memcg/functional: use checkpoints

This patch implements the idea proposed in [1], [2], that we use the checkpoint interface to let memcg_process inform the parent process that it's ready.

In my enviroment it saves ~50 secs of time.

[1] http://lists.linux.it/pipermail/ltp/2016-May/001841.html
[2] http://lists.linux.it/pipermail/ltp/2016-May/001846.html

---
Changes since V1:
* Added necessary links for [1], [2] in the commit message

 .../memcg/functional/memcg_function_test.sh        |    4 ++--
 .../controllers/memcg/functional/memcg_lib.sh      |   15 ++++++++-------
 .../controllers/memcg/functional/memcg_process.c   |    6 ++++++
 3 files changed, 16 insertions(+), 9 deletions(-)
testcases/kernel/controllers/memcg/functional/memcg_function_test.sh +2 -2
index 24d02ae..cd32cf2 100755
@@ -209,7 +209,7 @@ testcase_29()
 {
 	memcg_process --mmap-anon -s $PAGESIZE &
 	pid=$!
-	sleep 1
+	TST_CHECKPOINT_WAIT 0
 	echo $pid > tasks
 	kill -s USR1 $pid 2> /dev/null
 	sleep 1
@@ -225,7 +225,7 @@ testcase_30()
 {
 	memcg_process --mmap-lock2 -s $PAGESIZE &
 	pid=$!
-	sleep 1
+	TST_CHECKPOINT_WAIT 0
 	echo $pid > tasks
 	kill -s USR1 $pid 2> /dev/null
 	sleep 1
testcases/kernel/controllers/memcg/functional/memcg_lib.sh +8 -7
index 46e6c7f..8822f48 100755
@@ -22,6 +22,7 @@
 ##                                                                            ##
 ################################################################################
 
+TST_NEEDS_CHECKPOINTS=1
 . test.sh
 
 if [ "x$(grep -w memory /proc/cgroups | cut -f4)" != "x1" ]; then
@@ -119,7 +120,7 @@ test_mem_stat()
 {
 	tst_resm TINFO "Running memcg_process $1 -s $2"
 	memcg_process $1 -s $2 &
-	sleep 1
+	TST_CHECKPOINT_WAIT 0
 
 	warmup $!
 	if [ $? -ne 0 ]; then
@@ -152,7 +153,7 @@ test_max_usage_in_bytes()
 {
 	tst_resm TINFO "Running memcg_process $1 -s $2"
 	memcg_process $1 -s $2 &
-	sleep 1
+	TST_CHECKPOINT_WAIT 0
 
 	warmup $!
 	if [ $? -ne 0 ]; then
@@ -183,7 +184,7 @@ malloc_free_memory()
 {
 	tst_resm TINFO "Running memcg_process $1 -s $2"
 	memcg_process $1 -s $2 &
-	sleep 1
+	TST_CHECKPOINT_WAIT 0
 
 	echo $! > tasks
 	kill -s USR1 $! 2> /dev/null
@@ -226,7 +227,7 @@ test_proc_kill()
 
 	memcg_process $2 -s $3 &
 	pid=$!
-	sleep 1
+	TST_CHECKPOINT_WAIT 0
 	echo $pid > tasks
 
 	kill -s USR1 $pid 2> /dev/null
@@ -295,7 +296,7 @@ test_hugepage()
 	echo $1 > /proc/sys/vm/nr_hugepages
 
 	memcg_process $2 --hugepage -s $3 > $TMP_FILE 2>&1 &
-	sleep 1
+	TST_CHECKPOINT_WAIT 0
 
 	kill -s USR1 $! 2> /dev/null
 	sleep 1
@@ -343,7 +344,7 @@ test_subgroup()
 
 	tst_resm TINFO "Running memcg_process --mmap-anon -s $PAGESIZE"
 	memcg_process --mmap-anon -s $PAGESIZE &
-	sleep 1
+	TST_CHECKPOINT_WAIT 0
 
 	warmup $!
 	if [ $? -ne 0 ]; then
@@ -379,7 +380,7 @@ test_move_charge()
 
 	tst_resm TINFO "Running memcg_process $1 -s $2"
 	memcg_process $1 -s $2 &
-	sleep 1
+	TST_CHECKPOINT_WAIT 0
 	warmup $!
 	if [ $? -ne 0 ]; then
 		rmdir subgroup_a
testcases/kernel/controllers/memcg/functional/memcg_process.c +6 -0
index 4ad2d6f..fbb76e2 100644
@@ -34,6 +34,8 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#define TST_NO_DEFAULT_MAIN
+#include "tst_test.h"
 
 static int fd;
 
@@ -315,6 +317,10 @@ int main(int argc, char *argv[])
 
 	process_options(argc, argv);
 
+	tst_reinit();
+
+	TST_CHECKPOINT_WAKE(0);
+
 	while (!flag_exit)
 		sleep(1);
 
Signature · 1 line
1.7.1
#3 lore raw

PATCH v2 4/4 memcg/functional: check several times if the process is killed

On some systems it may take slightly more than one second to kill the memcg_process. So let's check several times if the process is alive.

---
No changes since V1.

 .../controllers/memcg/functional/memcg_lib.sh      |   15 ++++++++++++---
 1 files changed, 12 insertions(+), 3 deletions(-)
testcases/kernel/controllers/memcg/functional/memcg_lib.sh +12 -3
index 8822f48..1d6e495 100755
@@ -231,10 +231,19 @@ test_proc_kill()
 	echo $pid > tasks
 
 	kill -s USR1 $pid 2> /dev/null
-	sleep 1
 
-	ps -p $pid > /dev/null 2> /dev/null
-	if [ $? -ne 0 ]; then
+	tpk_pid_exists=1
+	for tpk_iter in $(seq 20); do
+		if [ ! -d "/proc/$pid" ] ||
+			grep -q 'Z (zombie)' "/proc/$pid/status"; then
+			tpk_pid_exists=0
+			break
+		fi
+
+		tst_sleep 250ms
+	done
+
+	if [ $tpk_pid_exists -eq 0 ]; then
 		wait $pid
 		ret=$?
 		if [ $ret -eq 1 ]; then
Signature · 1 line
1.7.1
#5 lore raw

PATCH v2 1/4 memcg/functional: rewrite

In reply to Stanislav Kholmanskikh

Hi!

testcases/kernel/controllers/memcg/functional/memcg_function_test.sh testcase_38() · line 283

Quoted 4 lines

shmmax=cat /proc/sys/kernel/shmmax
if [ $shmmax -lt $HUGEPAGESIZE ]; then

testcases/kernel/controllers/memcg/functional/memcg_function_test.sh +1 -1
-	echo $(($HUGEPAGESIZE)) > /proc/sys/kernel/shmmax
+	ROD "$HUGEPAGESIZE" \> /proc/sys/kernel/shmmax

^
Missing echo here?

The rest looks fine.

Signature · 2 lines
Cyril Hrubis
[email protected]
#6 lore raw

PATCH v2 1/4 memcg/functional: rewrite

Hi

Quoted 10 lines · Cyril Hrubis

Hi!

testcases/kernel/controllers/memcg/functional/memcg_function_test.sh testcase_38() · line 283

Quoted 4 lines

shmmax=cat /proc/sys/kernel/shmmax
if [ $shmmax -lt $HUGEPAGESIZE ]; then

testcases/kernel/controllers/memcg/functional/memcg_function_test.sh +1 -1
-	echo $(($HUGEPAGESIZE)) > /proc/sys/kernel/shmmax
+	ROD "$HUGEPAGESIZE" \> /proc/sys/kernel/shmmax

^
Missing echo here?

The rest looks fine.

Added the missing 'echo' and pushed the series.

Thank you for review.