xref: /freebsd/tools/test/stress2/misc/swapoff6.sh (revision 7937bfbc0ca53fe7cdd0d54414f9296e273a518e)
1#!/bin/sh
2
3#
4# Copyright (c) 2024 Peter Holm <pho@FreeBSD.org>
5#
6# SPDX-License-Identifier: BSD-2-Clause
7#
8
9# A swap test scenario, using swapoff(8) and sort(1) for VM pressure
10
11# Out of free pages seen:://people.freebsd.org/~pho/stress/log/log0540.txt
12
13. ../default.cfg
14[ `id -u` -ne 0 ] && echo "Must be root!" && exit 1
15
16[ `swapinfo | wc -l` -eq 1 ] && exit 0
17set -u
18nmax=`sysctl -n hw.ncpu`
19[ $nmax -gt 4 ] && nmax=4
20
21for i in `jot $nmax`; do
22	timeout -k 2m 1m sort /dev/zero &
23	sleep .`jot -r 1 1 9`
24done
25while [ `swapinfo | tail -1 | awk '{sub("%","");print $NF}'` -lt 2 ]; do sleep 1; done
26
27start=`date +%s`
28while [ $((`date +%s` - start)) -lt 300 ]; do
29	while ! swapoff -a > /dev/null 2>&1; do sleep .1; done
30	swapon -a > /dev/null
31	ncur=`pgrep sort | wc -l`
32	if [ $ncur -lt $nmax ]; then
33		echo "Starting $((nmax - ncur)) sort"
34		for i in `jot $((nmax - ncur))`; do
35			timeout -k 2m 1m sort /dev/zero &
36			sleep .`jot -r 1 1 9`
37		done
38	fi
39done
40pkill -9 sort
41wait
42exit 0
43