xref: /dflybsd-src/test/stress/stress2/misc/altbufferflushes.sh (revision 86d7f5d305c6adaa56ff4582ece9859d73106103)
186d7f5d3SJohn Marino#!/bin/sh
286d7f5d3SJohn Marino
386d7f5d3SJohn Marino#
486d7f5d3SJohn Marino# Copyright (c) 2008 Peter Holm <pho@FreeBSD.org>
586d7f5d3SJohn Marino# All rights reserved.
686d7f5d3SJohn Marino#
786d7f5d3SJohn Marino# Redistribution and use in source and binary forms, with or without
886d7f5d3SJohn Marino# modification, are permitted provided that the following conditions
986d7f5d3SJohn Marino# are met:
1086d7f5d3SJohn Marino# 1. Redistributions of source code must retain the above copyright
1186d7f5d3SJohn Marino#    notice, this list of conditions and the following disclaimer.
1286d7f5d3SJohn Marino# 2. Redistributions in binary form must reproduce the above copyright
1386d7f5d3SJohn Marino#    notice, this list of conditions and the following disclaimer in the
1486d7f5d3SJohn Marino#    documentation and/or other materials provided with the distribution.
1586d7f5d3SJohn Marino#
1686d7f5d3SJohn Marino# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1786d7f5d3SJohn Marino# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1886d7f5d3SJohn Marino# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1986d7f5d3SJohn Marino# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2086d7f5d3SJohn Marino# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2186d7f5d3SJohn Marino# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2286d7f5d3SJohn Marino# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2386d7f5d3SJohn Marino# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2486d7f5d3SJohn Marino# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2586d7f5d3SJohn Marino# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2686d7f5d3SJohn Marino# SUCH DAMAGE.
2786d7f5d3SJohn Marino#
2886d7f5d3SJohn Marino# $FreeBSD$
2986d7f5d3SJohn Marino#
3086d7f5d3SJohn Marino
3186d7f5d3SJohn Marino# Regression test. This script caused this panic:
3286d7f5d3SJohn Marino
3386d7f5d3SJohn Marino# panic: lockmgr: locking against myself
3486d7f5d3SJohn Marino# cpuid = 2
3586d7f5d3SJohn Marino# KDB: enter: panic
3686d7f5d3SJohn Marino# [thread pid 2526 tid 100070 ]
3786d7f5d3SJohn Marino# Stopped at      kdb_enter+0x2b: nop
3886d7f5d3SJohn Marino# db> bt
3986d7f5d3SJohn Marino# Tracing pid 2526 tid 100070 td 0xc46f8360
4086d7f5d3SJohn Marino# kdb_enter(c094247f) at kdb_enter+0x2b
4186d7f5d3SJohn Marino# panic(c09402b6,c46f8360,0,12,c06af5d9,...) at panic+0x14b
4286d7f5d3SJohn Marino# _lockmgr(d864a748,202122,c479f788,c46f8360,c094b01c,12d) at _lockmgr+0x41a
4386d7f5d3SJohn Marino# getblk(c479f6b8,5d51940,0,4000,0,...) at getblk+0x13c
4486d7f5d3SJohn Marino# breadn(c479f6b8,5d51940,0,4000,0,...) at breadn+0x2f
4586d7f5d3SJohn Marino# bread(c479f6b8,5d51940,0,4000,0,e6d13544,c4743eac,0,c095a185,56d) at bread+0x20
4686d7f5d3SJohn Marino# ffs_alloccg(c47408c4,104,1754628,0,4000,c4743eac,1,c095a185,4d8) at ffs_alloccg+0x11d
4786d7f5d3SJohn Marino# ffs_hashalloc(c47408c4,104,1754628,0,4000,...) at ffs_hashalloc+0x45
4886d7f5d3SJohn Marino# ffs_alloc(c47408c4,3f2cd,0,1754628,0,4000,c42fd400,e6d13674) at ffs_alloc+0x1a5
4986d7f5d3SJohn Marino# ffs_balloc_ufs2(c4735d70,fcb34000,0,4000,c42fd400,...) at ffs_balloc_ufs2+0x1619
5086d7f5d3SJohn Marino# ffs_copyonwrite(c479f6b8,d84e3d08) at ffs_copyonwrite+0x3d3
5186d7f5d3SJohn Marino# ffs_geom_strategy(c479f7c0,d84e3d08) at ffs_geom_strategy+0xbd
5286d7f5d3SJohn Marino# bufwrite(d84e3d08,4000,d84e3d08,e6d137e4,c070b7a9,...) at bufwrite+0x17a
5386d7f5d3SJohn Marino# ffs_bufwrite(d84e3d08) at ffs_bufwrite+0x282
5486d7f5d3SJohn Marino# vfs_bio_awrite(d84e3d08) at vfs_bio_awrite+0x235
5586d7f5d3SJohn Marino# bdwrite(d864a6e8,c4743eac,0,c095a185,57c,...) at bdwrite+0x237
5686d7f5d3SJohn Marino# ffs_alloccg(c4b54a50,104,1754628,0,4000,c4743eac,1,c095a185,4d8) at ffs_alloccg+0x1f6
5786d7f5d3SJohn Marino# ffs_hashalloc(c4b54a50,104,1754628,0,4000,...) at ffs_hashalloc+0x45
5886d7f5d3SJohn Marino# ffs_alloc(c4b54a50,1b00c,0,1754628,0,4000,c4b22a80,e6d139ac) at ffs_alloc+0x1a5
5986d7f5d3SJohn Marino# ffs_balloc_ufs2(c4e72158,6c030000,0,4000,c4b22a80,...) at ffs_balloc_ufs2+0x1619
6086d7f5d3SJohn Marino# ffs_write(e6d13b98) at ffs_write+0x2ac
6186d7f5d3SJohn Marino# VOP_WRITE_APV(c0a00e80,e6d13b98) at VOP_WRITE_APV+0x132
6286d7f5d3SJohn Marino# vn_write(c46c65a0,e6d13c60,c4b22a80,0,c46f8360) at vn_write+0x1f6
6386d7f5d3SJohn Marino# dofilewrite(c46f8360,4,c46c65a0,e6d13c60,ffffffff,...) at dofilewrite+0x77
6486d7f5d3SJohn Marino# kern_writev(c46f8360,4,e6d13c60,8430000,d0000,...) at kern_writev+0x36
6586d7f5d3SJohn Marino# write(c46f8360,e6d13d00) at write+0x45
6686d7f5d3SJohn Marino# syscall(e6d13d38) at syscall+0x256
6786d7f5d3SJohn Marino
6886d7f5d3SJohn Marino
6986d7f5d3SJohn Marino[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
7086d7f5d3SJohn Marino
7186d7f5d3SJohn Marinopersist () {
7286d7f5d3SJohn Marino	false
7386d7f5d3SJohn Marino	while [ $? -ne 0 ]; do
7486d7f5d3SJohn Marino		$1 > /dev/null 2>&1
7586d7f5d3SJohn Marino		sleep 1
7686d7f5d3SJohn Marino	done
7786d7f5d3SJohn Marino}
7886d7f5d3SJohn Marino
7986d7f5d3SJohn Marinodiskfree=`df -k /var/tmp | tail -1 | awk '{print $4}'`
8086d7f5d3SJohn Marino[ $((diskfree / 1024 / 1024)) -lt 5 ] && echo "Not enough disk space" && exit 1
8186d7f5d3SJohn Marino
8286d7f5d3SJohn Marinorm -f /var/.snap/pho /var/tmp/big.?
8386d7f5d3SJohn Marinotrap "rm -f /var/.snap/pho /var/tmp/big.?" 0
8486d7f5d3SJohn Marinopersist 'mksnap_ffs /var /var/.snap/pho'
8586d7f5d3SJohn Marinosysctl vfs.dirtybufthresh=10 > /dev/null 2>&1
8686d7f5d3SJohn Marino
8786d7f5d3SJohn Marinocd /var/tmp
8886d7f5d3SJohn Marinofor j in `jot 10`; do
8986d7f5d3SJohn Marino	old=`sysctl  vfs.altbufferflushes | awk '{print $NF}'`
9086d7f5d3SJohn Marino	for i in `jot 4`; do
9186d7f5d3SJohn Marino		echo "`date '+%T'` Create big.$i"
9286d7f5d3SJohn Marino		dd if=/dev/zero of=big.$i bs=1m count=4k 2>&1 | egrep -v "records|transferred"
9386d7f5d3SJohn Marino	done
9486d7f5d3SJohn Marino	sleep 1
9586d7f5d3SJohn Marino	rm -rf /var/tmp/big.?
9686d7f5d3SJohn Marino	new=`sysctl  vfs.altbufferflushes | awk '{print $NF}'`
9786d7f5d3SJohn Marino	[ $new -ne $old ] && echo "vfs.altbufferflushes changed from $old to $new."
9886d7f5d3SJohn Marinodone
9986d7f5d3SJohn Marinorm -f /var/.snap/pho
100