xref: /freebsd/tools/test/stress2/misc/swapoff4.sh (revision ba3c1f5972d7b90feb6e6da47905ff2757e0fe57)
1#!/bin/sh
2
3#
4# SPDX-License-Identifier: BSD-2-Clause
5#
6# Copyright (c) 2020 Peter Holm
7#
8# Redistribution and use in source and binary forms, with or without
9# modification, are permitted provided that the following conditions
10# are met:
11# 1. Redistributions of source code must retain the above copyright
12#    notice, this list of conditions and the following disclaimer.
13# 2. Redistributions in binary form must reproduce the above copyright
14#    notice, this list of conditions and the following disclaimer in the
15#    documentation and/or other materials provided with the distribution.
16#
17# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27# SUCH DAMAGE.
28#
29
30# A variation of Mark's swapoff3.sh
31
32# "panic: Last close with active requests" seen:
33# https://people.freebsd.org/~pho/stress/log/mark134.txt
34# Fixed by r358024-6
35
36. ../default.cfg
37[ `id -u` -ne 0 ] && echo "Must be root!" && exit 1
38dir=`dirname $diskimage`
39[ `df -k $dir | tail -1 | awk '{print $4}'` -lt \
40    $((20 * 1024 * 1024)) ] &&
41    { echo "Need 20GB on $dir"; exit 0; }
42
43set -e
44md1=$mdstart
45md2=$((md1 + 1))
46[ `sysctl -n vm.swap_total` -gt 0 ] && { swapoff -a > /dev/null; off=1; }
47truncate -s 10G $dir/swap1
48mdconfig -a -t vnode -f $dir/swap1 -u $md1
49swapon /dev/md$md1
50truncate -s 10G $dir/swap2
51mdconfig -a -t vnode -f $dir/swap2 -u $md2
52swapon /dev/md$md2
53set +e
54
55export swapINCARNATIONS=25
56(cd ../testcases/swap; ./swap -t 4m -i 20 -l 100) &
57for i in `jot 90`; do
58	used=`swapinfo | tail -1 | awk '{print $3}'`
59	[ $used -gt 0 ] && break
60	sleep 2
61done
62
63n=0
64while pgrep -q swap; do
65	for dev in /dev/md$md1 /dev/md$md2; do
66		for i in `jot 3`; do
67			swapoff $dev && break
68		done
69		swapon $dev
70		n=$((n + 1))
71	done
72done
73[ $n -lt 100 ] && { echo "Only performed $n swapoffs"; s=1; } || s=0
74wait
75for dev in /dev/md$md1 /dev/md$md2; do
76	swapoff $dev
77done
78mdconfig -d -u $md1
79mdconfig -d -u $md2
80rm -f $dir/swap1 $dir/swap2
81[ $off ] && swapon -a > /dev/null
82exit 0
83