4 # Copyright (c) 2017 Dell EMC Isilon
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 # Variation of kevent5.sh
30 # OOM seen: https://people.freebsd.org/~pho/stress/log/mark018.txt
33 [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
38 sed '1,/^EOF/d' < $odir/$0 > $dir/kevent11.c
39 mycc -o kevent11 -Wall -Wextra -O0 -g kevent11.c || exit 1
44 mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint
45 [ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart
46 mdconfig -a -t swap -s 2g -u $mdstart
47 bsdlabel -w md$mdstart auto
48 newfs $newfs_flags md${mdstart}$part > /dev/null
49 mount /dev/md${mdstart}$part $mntpoint
52 (cd $odir/../testcases/swap; ./swap -t 5m -i 20 -h -l 100 > /dev/null) &
56 [ -f kevent11.core -a $s -eq 0 ] &&
57 { ls -l kevent11.core; mv kevent11.core /tmp; s=1; }
59 while pkill -9 swap; do :; done
63 mount | grep -q "on $mntpoint " || break
64 umount $mntpoint && break || sleep 10
66 [ $i -eq 6 ] && exit 1
67 mdconfig -d -u $mdstart
72 #include <sys/param.h>
73 #include <sys/event.h>
78 #include <machine/atomic.h>
89 static volatile u_int *share;
90 static char *file = "file";
93 #define RUNTIME (3 * 60)
103 if ((fd = open(file, O_RDONLY, 0)) == -1)
104 err(1, "open(%s). %s:%d", file, __func__, __LINE__);
106 if ((kq = kqueue()) < 0)
110 EV_SET(&ev[n], fd, EVFILT_VNODE, EV_ADD | EV_ENABLE | EV_CLEAR,
114 if (kevent(kq, ev, n, NULL, 0, NULL) < 0)
117 setproctitle("presync");
118 atomic_add_int(&share[SYNC], 1);
119 while (share[SYNC] != PARALLEL)
121 setproctitle("postsync");
123 memset(&ev, 0, sizeof(ev));
124 n = kevent(kq, NULL, 0, ev, 1, &ts);
134 pid_t pids[PARALLEL];
137 int e, fd, i, status;
141 if ((share = mmap(NULL, len, PROT_READ | PROT_WRITE,
142 MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED)
146 while ((time(NULL) - start) < RUNTIME && e == 0) {
147 if ((fd = open(file, O_CREAT | O_TRUNC | O_RDWR, 0660)) ==
149 err(1, "open(%s)", file);
152 for (i = 0; i < PARALLEL; i++) {
154 if ((pids[i] = fork()) == 0)
159 while (share[SYNC] != PARALLEL)
161 if (unlink(file) == -1)
162 err(1, "unlink(%s). %s:%d\n", file,
164 for (i = 0; i < PARALLEL; i++) {
165 if (waitpid(pids[i], &status, 0) == -1)
166 err(1, "waitpid(%d)", pids[i]);
168 if (WIFSIGNALED(status))
170 "pid %d exit signal %d\n",
171 pids[i], WTERMSIG(status));
173 e += status == 0 ? 0 : 1;