diff mbox series

[v4] memcg_stress_test.sh: Fix reserved mem calculate

Message ID 20230315080041.128271-1-gehao@kylinos.cn
State Accepted
Headers show
Series [v4] memcg_stress_test.sh: Fix reserved mem calculate | expand

Commit Message

Hao Ge March 15, 2023, 8 a.m. UTC
When running this test case on a machine with large memory,
and without swap or swap is too small,existing reserved
memory is too small for a machine with large memory,and
will cause forking a subprocess to run a command will fail
due to memory is exhausted,so optimize reserved memory
calculate .

Signed-off-by: Hao Ge <gehao@kylinos.cn>
---
 .../controllers/memcg/stress/memcg_stress_test.sh   | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

Comments

Li Wang March 15, 2023, 12:47 p.m. UTC | #1
Hi Hao,

I adjust some syntax and expressions then pushed. Thanks!
diff mbox series

Patch

diff --git a/testcases/kernel/controllers/memcg/stress/memcg_stress_test.sh b/testcases/kernel/controllers/memcg/stress/memcg_stress_test.sh
index cb52840d7..ed35eaace 100755
--- a/testcases/kernel/controllers/memcg/stress/memcg_stress_test.sh
+++ b/testcases/kernel/controllers/memcg/stress/memcg_stress_test.sh
@@ -34,13 +34,16 @@  setup()
 	echo 3 > /proc/sys/vm/drop_caches
 	sleep 2
 	local mem_free=`cat /proc/meminfo | grep MemFree | awk '{ print $2 }'`
+	local mem_available=`cat /proc/meminfo | grep MemAvailable | awk '{ print $2 }'`
 	local swap_free=`cat /proc/meminfo | grep SwapFree | awk '{ print $2 }'`
-	local pgsize=`tst_getconf PAGESIZE`
+	mem_min=`cat /proc/sys/vm/min_free_kbytes`
 
-	MEM=$(( $mem_free + $swap_free / 2 ))
+	mem_min=$(( $mem_min + $mem_min / 10 ))
+	[ $swap_free -gt $mem_min ] && RESERVED_MEM=0 || RESERVED_MEM=$mem_min
+	[ $mem_free -lt $mem_available ] && MEM=$mem_free || MEM=$mem_available
+	MEM=$(( $MEM - $RESERVED_MEM ))
 	MEM=$(( $MEM / 1024 ))
 	RUN_TIME=$(( 15 * 60 ))
-	[ "$pgsize" = "4096" ] && THREAD_SPARE_MB=1 || THREAD_SPARE_MB=8
 
 	tst_res TINFO "Calculated available memory $MEM MB"
 }
@@ -93,12 +96,12 @@  run_stress()
 
 test1()
 {
-	run_stress 150 $(( ($MEM - 150 * $THREAD_SPARE_MB) / 150 )) 5 $RUN_TIME
+	run_stress 150 $(( $MEM  / 150 )) 5 $RUN_TIME
 }
 
 test2()
 {
-	run_stress 1 $(( $MEM - $THREAD_SPARE_MB)) 5 $RUN_TIME
+	run_stress 1 $MEM 5 $RUN_TIME
 }
 
 . cgroup_lib.sh