aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Lu <aaron.lu@intel.com>2016-10-11 16:30:56 +0800
committerFengguang Wu <fengguang.wu@intel.com>2016-10-12 10:52:55 +0800
commitdddafc918d897c2acfabaddb1dabc67e4284e2d0 (patch)
tree9fc7d7ef6af5d2538ba02994131a6220a3bce120
parentf2a5432692f922b4ff170892b2ce324064f9b9a0 (diff)
downloadvm-scalability-dddafc918d897c2acfabaddb1dabc67e4284e2d0.tar.gz
case-swapin: add swapin test case
Signed-off-by: Aaron Lu <aaron.lu@intel.com> Signed-off-by: Fengguang Wu <fengguang.wu@intel.com>
-rwxr-xr-xcase-swapin51
1 files changed, 51 insertions, 0 deletions
diff --git a/case-swapin b/case-swapin
new file mode 100755
index 0000000..aa7300a
--- /dev/null
+++ b/case-swapin
@@ -0,0 +1,51 @@
+#!/bin/sh
+
+. ./hw_vars
+
+if [ "$SwapTotal" -eq 0 ]; then
+ echo "No swap space. Please setup swap before running $0" >&2
+ exit 1
+fi
+
+[ -n "$unit_size" ] || unit_size=$((MemAvailable << 10))
+
+TMP=/tmp
+
+# start N detached processes and do write first to consume all memory
+# then wait for SIGUSR1 to resume to do read
+./usemem -n $nr_task -W -d -p $TMP/pidfile $((unit_size / nr_task))
+
+# Now that the N detached processes are done, start another process
+# to consume memory to push pages allocated by the first N processes
+# to swap.
+# Also, redirect its output to /dev/null so that it won't output any
+# statistics related information
+swapfree=$(grep SwapFree /proc/meminfo |awk '{print $2}')
+swapfree=$((swapfree << 10))
+pushsize=$(($swapfree < $unit_size ? $swapfree : $unit_size))
+./usemem $pushsize >/dev/null
+# do it again to push more memory to swap
+./usemem $pushsize >/dev/null
+
+# wake those detached processes up to do read
+kill -USR1 `cat $TMP/pidfile`
+
+any_pid_alive()
+{
+ local pidfile=$1
+ for pid in $(cat $pidfile)
+ do
+ test -d /proc/$pid && return
+ done
+ return 1
+}
+
+# wait till those detached processes exit
+while true
+do
+ sleep 5
+ any_pid_alive $TMP/pidfile && continue
+ break
+done
+
+rm $TMP/pidfile