Skip to contentSkip to conversation

memcg_function_test: do a warmup before actual test

PATCH In review Jan Stancek 2 participants 2 messages Nov 3, 2011 – Nov 11, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 memcg_function_test: do a warmup before actual test

This test relies on getting correct rss number out of memory.stat. Very rarely it fails and finds bigger number than expected, for example:
memcg_function_test 6 TFAIL : rss=8192/4096

My assumption is that extra page is faulted in as result of need for another stack page.

Documentation describes it as:
"rss - # of bytes of anonymous and swap cache memory."

This includes also stack pages. I intentionally modified memcg_process' sigusr handler to grab few extra stack pages, to confirm, that these indeed contribute to this number.

This patch adds a 'warmup' before actual test. The point is to exercise the whole code path, so that any page fault, which is unrelated to actual test occurs before process is moved to target cgroup.

What happens now is:
spawn process
[NEW] signal it with SIGUSR1 (alloc)
[NEW] signal it with SIGUSR1 (free)
move it to cgroup
signal it with SIGUSR1 (alloc)
check rss in memory.stat
signal it with SIGUSR1 (free)
optionally check rss in memory.stat

---
 .../memcg/functional/memcg_function_test.sh        |   43 
++++++++++++++++++++
 1 files changed, 43 insertions(+), 0 deletions(-)
testcases/kernel/controllers/memcg/functional/memcg_function_test.sh +43 -0
index 73c1fa1..f281256 100755
@@ -93,6 +93,34 @@ check_mem_stat()
 	result $pass "rss=$rss/$1"
 }
 
+warmup()
+{
+	pid=$1
+
+	case $cur_id in
+	"11"|"12"|"13")
+		#no warmp here, these are expected to fail
+		;;
+	*)
+		echo "Warming up for test: $cur_id, pid: $pid"
+		/bin/kill -s SIGUSR1 $pid 2> /dev/null
+		sleep 1
+		/bin/kill -s SIGUSR1 $pid 2> /dev/null
+		sleep 1
+
+		kill -0 $pid
+		if [ $? -ne 0 ]; then
+			result $FAIL "cur_id=$cur_id"
+			return 1
+		else
+			echo "Process is still here after warm up: $pid"
+		fi
+		;;
+	esac
+	return 0
+}
+
+
 # Run test cases which checks memory.stat after make
 # some memory allocation
 #
@@ -102,8 +130,15 @@ check_mem_stat()
 # $4 - check after free ?
 test_mem_stat()
 {
+	echo "Running $TEST_PATH/memcg_process $1 -s $2"
 	$TEST_PATH/memcg_process $1 -s $2 &
 	sleep 1
+
+	warmup $!
+	if [ $? -ne 0 ]; then
+		return
+	fi
+
 	echo $! > tasks
 	/bin/kill -s SIGUSR1 $! 2> /dev/null
 	sleep 1
@@ -235,8 +270,15 @@ test_subgroup()
 	echo $1 > memory.limit_in_bytes
 	echo $2 > subgroup/memory.limit_in_bytes
 
+	echo "Running $TEST_PATH/memcg_process --mmap-anon -s $PAGESIZE"
 	$TEST_PATH/memcg_process --mmap-anon -s $PAGESIZE &
 	sleep 1
+
+	warmup $!
+	if [ $? -ne 0 ]; then
+		return
+	fi
+
 	echo $! > tasks
 	/bin/kill -s SIGUSR1 $! 2> /dev/null
 	sleep 1
@@ -520,6 +562,7 @@ fi
 
 cleanup()
 {
+	killall -9 memcg_process 2>/dev/null
 	if [ -e /dev/memcg ]; then
 		umount /dev/memcg 2>/dev/null
 		rmdir /dev/memcg 2>/dev/null

------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1

_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#1 lore raw

Hi!
Commited thanks.

Quoted 4 lines

What happens now is:
spawn process
[NEW] signal it with SIGUSR1 (alloc)
[NEW] signal it with SIGUSR1 (free)

Doing malloc() and/or free() from signal handler is simply wrong and will lead to memory corruptions or deadlocks someday. Here it may work most of the time as you aren't doing anything in the main program loop, but still correct way of doing this is to create pipe and sleep on the file decriptor.

Signature · 12 lines
Cyril Hrubis
[email protected]

------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list