Skip to contentSkip to conversation

cpuset/cpuset_memory_pressure_test: Check whether the swap partition is configured

PATCH New Zou Wei 2 participants 3 messages Apr 6, 2021 – Sep 14, 2021

lore
Share & tools
lore

Zou Wei

author
#0 lore raw

PATCH 1/1 cpuset/cpuset_memory_pressure_test: Check whether the swap partition is configured

--------------------------

1. Fixed a bug where a null value is obtained because swap is not in the fourth line of the free result
free -m
total used free shared buff/cache available

Mem:   128135        3857      120633         158        3644      123219
Swap:    8191          82        8109

free -m
total used free shared buffers cached
Mem: 419694 9464 410230 234 435 6005
-/+ buffers/cache: 3022 416671
Swap: 2053 0 2053

2. If no swap partition is configured in the test environment, the testcase will be failed:

cpuset_memory_pressure 7 TFAIL: sub group's memory_pressure didn't have memory pressure rate. cpuset_memory_pressure 9 TFAIL: root group's memory_pressure didn't have memory pressure rate. cpuset_memory_pressure 11 TFAIL: root group's memory_pressure didn't have memory pressure rate.

---
 .../cpuset_memory_pressure_testset.sh                        | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
testcases/kernel/controllers/cpuset/cpuset_memory_pressure_test/cpuset_memory_pressure_testset.sh +10 -2
index eddd7f6..2a2d2a1 100755
@@ -35,8 +35,16 @@ exit_status=0
 # usable physical memory
 py_mem=$(free -m | awk '{if(NR==2) print $4 + $6 + $7}')
 
-# free swap space
-sw_mem=$(free -m | awk '{if(NR==4) print $4}')
+# total swap space
+sw_mem=$(free -m | awk '{if(NR==4) print $2}')
+if [ -z $sw_mem ]; then
+	sw_mem=$(free -m | awk '{if(NR==3) print $2}')
+fi
+
+if [ $sw_mem -eq 0 ]; then
+	tst_resm TCONF "The size of the swap partition is zero."
+	exit 32
+fi
 
 # the memory which is going to be used
 usemem=$((py_mem - 20))
Signature · 1 line
2.6.2
author
#1 lore raw

PATCH 1/1 cpuset/cpuset_memory_pressure_test: Check whether the swap partition is configured

ping, and has anybody met the same issue?

Quoted 54 lines · Zou Wei

--------------------------

1. Fixed a bug where a null value is obtained because swap is not in the fourth line of the free result
free -m
total used free shared buff/cache available

Mem:   128135        3857      120633         158        3644      123219
Swap:    8191          82        8109

free -m
total used free shared buffers cached
Mem: 419694 9464 410230 234 435 6005
-/+ buffers/cache: 3022 416671
Swap: 2053 0 2053

2. If no swap partition is configured in the test environment, the testcase will be failed:

cpuset_memory_pressure 7 TFAIL: sub group's memory_pressure didn't have memory pressure rate. cpuset_memory_pressure 9 TFAIL: root group's memory_pressure didn't have memory pressure rate. cpuset_memory_pressure 11 TFAIL: root group's memory_pressure didn't have memory pressure rate.

---
  .../cpuset_memory_pressure_testset.sh                        | 12 ++++++++++--
  1 file changed, 10 insertions(+), 2 deletions(-)
testcases/kernel/controllers/cpuset/cpuset_memory_pressure_test/cpuset_memory_pressure_testset.sh +10 -2
index eddd7f6..2a2d2a1 100755
@@ -35,8 +35,16 @@ exit_status=0
  # usable physical memory
  py_mem=$(free -m | awk '{if(NR==2) print $4 + $6 + $7}')
 
-# free swap space
-sw_mem=$(free -m | awk '{if(NR==4) print $4}')
+# total swap space
+sw_mem=$(free -m | awk '{if(NR==4) print $2}')
+if [ -z $sw_mem ]; then
+	sw_mem=$(free -m | awk '{if(NR==3) print $2}')
+fi
+
+if [ $sw_mem -eq 0 ]; then
+	tst_resm TCONF "The size of the swap partition is zero."
+	exit 32
+fi
 
  # the memory which is going to be used
  usemem=$((py_mem - 20))
#2 lore raw

PATCH 1/1 cpuset/cpuset_memory_pressure_test: Check whether the swap partition is configured

In reply to Zou Wei

Hello,

Quoted 35 lines · Zou Wei

--------------------------

1. Fixed a bug where a null value is obtained because swap is not in the fourth line of the free result
free -m
total used free shared buff/cache available

Mem:   128135        3857      120633         158        3644      123219
Swap:    8191          82        8109

free -m
total used free shared buffers cached
Mem: 419694 9464 410230 234 435 6005
-/+ buffers/cache: 3022 416671
Swap: 2053 0 2053

2. If no swap partition is configured in the test environment, the testcase will be failed:

cpuset_memory_pressure 7 TFAIL: sub group's memory_pressure didn't have memory pressure rate. cpuset_memory_pressure 9 TFAIL: root group's memory_pressure didn't have memory pressure rate. cpuset_memory_pressure 11 TFAIL: root group's memory_pressure didn't have memory pressure rate.

---
 .../cpuset_memory_pressure_testset.sh                        | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
testcases/kernel/controllers/cpuset/cpuset_memory_pressure_test/cpuset_memory_pressure_testset.sh +0 -0
index eddd7f6..2a2d2a1 100755

testcases/kernel/controllers/cpuset/cpuset_memory_pressure_test/cpuset_memory_pressure_testset.sh exit_status=0 · line 42

Quoted 10 lines
testcases/kernel/controllers/cpuset/cpuset_memory_pressure_test/cpuset_memory_pressure_testset.sh +5 -2
@@ -35,8 +35,16 @@ exit_status=0
 # usable physical memory
 py_mem=$(free -m | awk '{if(NR==2) print $4 + $6 + $7}')
 
-# free swap space
-sw_mem=$(free -m | awk '{if(NR==4) print $4}')
+# total swap space
+sw_mem=$(free -m | awk '{if(NR==4) print $2}')
+if [ -z $sw_mem ]; then
+	sw_mem=$(free -m | awk '{if(NR==3) print $2}')
+fi

The original use of awk and free looks error prone. Perhaps it would be better to do?

sw_mem=$(cat /proc/meminfo | awk '/SwapTotal/ { print $2 }')

Quoted 10 lines
testcases/kernel/controllers/cpuset/cpuset_memory_pressure_test/cpuset_memory_pressure_testset.sh +5 -0
+
+if [ $sw_mem -eq 0 ]; then
+	tst_resm TCONF "The size of the swap partition is zero."
+	exit 32
+fi
 
 # the memory which is going to be used
 usemem=$((py_mem - 20))
Signature · 1 line
2.6.2
Signature · 2 lines
Thank you,
Richard.