[LTP] [PATCH V3] memcg_stress_test.sh: Fix reserved mem calculate

Hao Ge gehao@kylinos.cn
Mon Mar 13 10:50:49 CET 2023


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>
---
 .../memcg/stress/memcg_stress_test.sh         | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/testcases/kernel/controllers/memcg/stress/memcg_stress_test.sh b/testcases/kernel/controllers/memcg/stress/memcg_stress_test.sh
index cb52840d7..2c0488170 100755
--- a/testcases/kernel/controllers/memcg/stress/memcg_stress_test.sh
+++ b/testcases/kernel/controllers/memcg/stress/memcg_stress_test.sh
@@ -34,13 +34,20 @@ 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=$(( $mem_free + $swap_free / 2 ))
+	mem_min=`cat /proc/sys/vm/min_free_kbytes`
+
+	#Apply a margin because we cannot get below "min" watermark
+	mem_min=$(( $mem_min + $mem_min/10 ))
+	#we need calculate RESERVED_MEN , if have enough swap ,RESERVED_MEM =0
+	#else RESERVED_MEN = mem_min + mem_min/10
+	[ $swap_free -gt $mem_min ] && RESERVED_MEM=0 || RESERVED_MEM=$mem_min
+	# Use the lower value of free and available to calculate MEM
+	[ $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 +100,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
-- 
2.25.1



More information about the ltp mailing list