4 # Copyright (c) 2016 EMC Corp.
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
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.
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
29 # Parallel write test.
31 # fsync: giving up on dirty
32 # 0xc9172168: tag devfs, type VCHR
33 # usecount 1, writecount 0, refcount 31 mountedhere 0xc96bd300
35 # v_object 0xc96e55a0 ref 0 pages 983 cleanbuf 27 dirtybuf 2
36 # lock type devfs: EXCL by thread 0xcbedf340 (pid 58752, write, tid 100254)
37 # #0 0xc0c23f33 at __lockmgr_args+0xae3
38 # #1 0xc0cff943 at vop_stdlock+0x53
39 # #2 0xc12027c8 at VOP_LOCK1_APV+0x118
40 # #3 0xc0d2400a at _vn_lock+0xba
41 # #4 0xc0f3288b at ffs_sync+0x34b
42 # #5 0xc0f16cc5 at softdep_ast_cleanup_proc+0x205
43 # #6 0xc0ca3ac7 at userret+0x37
44 # #7 0xc11d021e at syscall+0x50e
45 # #8 0xc11bae3f at Xint0x80_syscall+0x2f
49 # https://people.freebsd.org/~pho/stress/log/write.txt
56 sed '1,/^EOF/d' < $odir/$0 > $dir/write.c
57 mycc -o write -Wall -Wextra -O2 -g write.c || exit 1
62 [ `df -k $(dirname $diskimage) | tail -1 | awk '{print int($4 / 1024)}'` \
64 printf "Need %d MB on %s.\n" $need `dirname $diskimage` && exit 0
65 wd=`dirname $diskimage`
77 #include <sys/param.h>
82 #include <machine/atomic.h>
93 #define MAXBLK (2 * 1024 * 1024)
95 #define MAXSIZ (9LL * 1024 * 1024 *1024)
96 #define RUNTIME (15 * 60)
99 volatile u_int *share;
113 return (arc4random() % (ma - mi + 1) + mi);
117 test(int indx, int num)
124 atomic_add_int(&share[SYNC], 1);
125 while (share[SYNC] != (unsigned int)parallel)
128 if ((buf = malloc(t[indx].blocksize)) == NULL)
130 snprintf(file, sizeof(file), "file.%06d.%06d", indx, num);
133 while (share[DONE] != (unsigned int)parallel) {
134 setproctitle("test(%d) num %d, n %d", indx, num, n);
135 if ((fd = open(file, O_RDWR | O_CREAT | O_TRUNC, DEFFILEMODE))
137 err(1, "open(%s)", file);
139 for (i = 0; i < t[indx].blocks; i++) {
140 if (t[indx].sequential == 0)
141 if (lseek(fd, 2LL << (arc4random() % 18),
144 if ((r = write(fd, buf, t[indx].blocksize)) !=
146 warn("write returned %zd\n", r);
149 usleep(rnd(t[indx].mindelay, t[indx].maxdelay));
154 atomic_add_int(&share[DONE], 1);
155 if (time(NULL) - start >= RUNTIME / 4) {
157 fprintf(stderr, "test(%d), %d Timed out\n", indx, num);
164 atomic_add_int(&share[DONE], 1);
174 parallel = arc4random() % MAXPROC + 1;
175 for (i = 0; i < parallel; i++) {
176 if (arc4random() % 100 < 10)
177 t[i].blocksize = (arc4random() + 1) % MAXBLK;
179 t[i].blocksize = 2 << (arc4random() % 20);
180 t[i].sequential = arc4random() % 2;
181 t[i].mindelay = arc4random() % 50;
182 t[i].maxdelay = t[i].mindelay + arc4random() % 100;
183 t[i].blocks = 2LL << (arc4random() % 18);
184 if (t[i].blocks * t[i].blocksize > MAXSIZ)
185 t[i].blocks = MAXSIZ / t[i].blocksize;
187 fprintf(stderr, "%3d: blocksize %7lld, sequential %d, "
188 "mindelay %3d, maxdelay %3d, blocks %6lld, size %4lld MB\n",
189 i, (long long)t[i].blocksize, t[i].sequential, t[i].mindelay,
190 t[i].maxdelay, (long long)t[i].blocks,
191 (long long)t[i].blocksize * t[i].blocks / 1024 / 1024);
201 int e, i, n, *pids, status;
205 if ((share = mmap(NULL, len, PROT_READ | PROT_WRITE,
206 MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED)
211 while ((time(NULL) - start) < RUNTIME && e == 0) {
214 pids = malloc(sizeof(pid_t) * parallel);
215 share[SYNC] = share[DONE] = 0;
216 for (i = 0; i < parallel; i++) {
217 if ((pids[i] = fork()) == 0)
220 for (i = 0; i < parallel; i++) {
221 if (waitpid(pids[i], &status, 0) != pids[i])
222 err(1, "waitpid %d", pids[i]);
223 e += status == 0 ? 0 : 1;