4 # Copyright (c) 2013 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 # Out of VM seen due to missing close of kqueue handle.
34 [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
35 ulimit -k 5000 || { echo FAIL; exit 1; }
40 sed '1,/^EOF/d' < $odir/$0 > kevent8.c
41 mycc -o kevent8 -Wall -Wextra -O2 -g kevent8.c -lpthread || exit 1
45 mount | grep "on $mntpoint " | grep -q md$mdstart && umount -f $mntpoint
46 mdconfig -l | grep -q $mdstart && mdconfig -d -u $mdstart
48 mdconfig -a -t swap -s 2g -u $mdstart
49 bsdlabel -w md$mdstart auto
50 newfs $newfs_flags md${mdstart}$part > /dev/null
51 mount /dev/md${mdstart}$part $mntpoint
54 su $testuser -c "(cd $mntpoint; /tmp/kevent8)" &
57 kill -0 $! 2>/dev/null || break
63 while mount | grep -q $mntpoint; do
64 umount $mntpoint || sleep 1
66 mdconfig -d -u $mdstart
71 #include <sys/types.h>
72 #include <sys/event.h>
93 spin(void *arg __unused)
99 snprintf(path, sizeof(path), "file.%06d.%d", getpid(), i);
100 if ((fd = open(path, O_CREAT | O_TRUNC | O_RDWR, 0622)) ==
111 test(void *arg __unused)
118 for (i = 0; i < 500000; i++) {
119 if ((kq = kqueue()) < 0)
124 memset(&ev, 0, sizeof(ev));
125 EV_SET(&ev, fd, EVFILT_VNODE, EV_ADD | EV_ENABLE | EV_CLEAR,
126 NOTE_DELETE|NOTE_RENAME|NOTE_EXTEND, 0, 0);
129 if (kevent(kq, &ev, n, NULL, 0, NULL) < 0)
130 continue; /* Note: missing close(kq)! */
132 memset(&ev, 0, sizeof(ev));
134 ts.tv_nsec = 1000000;
135 if ((n = kevent(kq, NULL, 0, &ev, 1, &ts)) == -1)
146 pthread_t cp[PARALLEL], sp;
149 if ((e = pthread_create(&sp, NULL, spin, NULL)) != 0)
150 errc(1, e, "pthread_create");
152 for (i = 0; i < PARALLEL; i++) {
153 if ((e = pthread_create(&cp[i], NULL, test, NULL)) != 0)
154 errc(1, e, "pthread_create");
157 for (i = 0; i < PARALLEL; i++)
158 pthread_join(cp[i], NULL);