xref: /freebsd/tools/test/stress2/misc/altbufferflushes.sh (revision 19261079b74319502c6ffa1249920079f0f69a72)
1#!/bin/sh
2
3#
4# Copyright (c) 2008 Peter Holm <pho@FreeBSD.org>
5# All rights reserved.
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions
9# are met:
10# 1. Redistributions of source code must retain the above copyright
11#    notice, this list of conditions and the following disclaimer.
12# 2. Redistributions in binary form must reproduce the above copyright
13#    notice, this list of conditions and the following disclaimer in the
14#    documentation and/or other materials provided with the distribution.
15#
16# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26# SUCH DAMAGE.
27#
28
29# Regression test. This script caused this panic:
30
31# panic: lockmgr: locking against myself
32# cpuid = 2
33# KDB: enter: panic
34# [thread pid 2526 tid 100070 ]
35# Stopped at      kdb_enter+0x2b: nop
36# db> bt
37# Tracing pid 2526 tid 100070 td 0xc46f8360
38# kdb_enter(c094247f) at kdb_enter+0x2b
39# panic(c09402b6,c46f8360,0,12,c06af5d9,...) at panic+0x14b
40# _lockmgr(d864a748,202122,c479f788,c46f8360,c094b01c,12d) at _lockmgr+0x41a
41# getblk(c479f6b8,5d51940,0,4000,0,...) at getblk+0x13c
42# breadn(c479f6b8,5d51940,0,4000,0,...) at breadn+0x2f
43# bread(c479f6b8,5d51940,0,4000,0,e6d13544,c4743eac,0,c095a185,56d) at bread+0x20
44# ffs_alloccg(c47408c4,104,1754628,0,4000,c4743eac,1,c095a185,4d8) at ffs_alloccg+0x11d
45# ffs_hashalloc(c47408c4,104,1754628,0,4000,...) at ffs_hashalloc+0x45
46# ffs_alloc(c47408c4,3f2cd,0,1754628,0,4000,c42fd400,e6d13674) at ffs_alloc+0x1a5
47# ffs_balloc_ufs2(c4735d70,fcb34000,0,4000,c42fd400,...) at ffs_balloc_ufs2+0x1619
48# ffs_copyonwrite(c479f6b8,d84e3d08) at ffs_copyonwrite+0x3d3
49# ffs_geom_strategy(c479f7c0,d84e3d08) at ffs_geom_strategy+0xbd
50# bufwrite(d84e3d08,4000,d84e3d08,e6d137e4,c070b7a9,...) at bufwrite+0x17a
51# ffs_bufwrite(d84e3d08) at ffs_bufwrite+0x282
52# vfs_bio_awrite(d84e3d08) at vfs_bio_awrite+0x235
53# bdwrite(d864a6e8,c4743eac,0,c095a185,57c,...) at bdwrite+0x237
54# ffs_alloccg(c4b54a50,104,1754628,0,4000,c4743eac,1,c095a185,4d8) at ffs_alloccg+0x1f6
55# ffs_hashalloc(c4b54a50,104,1754628,0,4000,...) at ffs_hashalloc+0x45
56# ffs_alloc(c4b54a50,1b00c,0,1754628,0,4000,c4b22a80,e6d139ac) at ffs_alloc+0x1a5
57# ffs_balloc_ufs2(c4e72158,6c030000,0,4000,c4b22a80,...) at ffs_balloc_ufs2+0x1619
58# ffs_write(e6d13b98) at ffs_write+0x2ac
59# VOP_WRITE_APV(c0a00e80,e6d13b98) at VOP_WRITE_APV+0x132
60# vn_write(c46c65a0,e6d13c60,c4b22a80,0,c46f8360) at vn_write+0x1f6
61# dofilewrite(c46f8360,4,c46c65a0,e6d13c60,ffffffff,...) at dofilewrite+0x77
62# kern_writev(c46f8360,4,e6d13c60,8430000,d0000,...) at kern_writev+0x36
63# write(c46f8360,e6d13d00) at write+0x45
64# syscall(e6d13d38) at syscall+0x256
65
66[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
67
68persist () {
69	false
70	while [ $? -ne 0 ]; do
71		$1 > /dev/null 2>&1
72		sleep 1
73	done
74}
75
76diskfree=`df -k /var/tmp | tail -1 | awk '{print $4}'`
77[ $((diskfree / 1024 / 1024)) -lt 5 ] && echo "Not enough disk space" && exit 1
78
79rm -f /var/.snap/stress2 /var/tmp/big.?
80trap "rm -f /var/.snap/stress2 /var/tmp/big.?" EXIT INT
81persist 'mksnap_ffs /var /var/.snap/stress2'
82tresh=`sysctl  vfs.dirtybufthresh | awk '{print $NF}'`
83sysctl vfs.dirtybufthresh=10
84
85cd /var/tmp
86for j in `jot 5`; do
87	old=`sysctl  vfs.altbufferflushes | awk '{print $NF}'`
88	for i in `jot 4`; do
89		echo "`date '+%T'` Create big.$i"
90		dd if=/dev/zero of=big.$i bs=1m count=4k status=none
91	done
92	sleep 1
93	rm -rf /var/tmp/big.?
94	new=`sysctl  vfs.altbufferflushes | awk '{print $NF}'`
95	[ $new -ne $old ] && echo "vfs.altbufferflushes changed from $old to $new."
96done
97sysctl vfs.dirtybufthresh=$tresh
98rm -f /var/.snap/stress2
99