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 # vm.stats.vm.v_laundry_count test. WiP. No problems seen.
32 [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
37 sed '1,/^EOF/d' < $odir/$0 > $dir/laundry.c
38 mycc -o laundry -Wall -Wextra -O0 -g laundry.c || exit 1
42 size=`sysctl -n hw.usermem`
43 swaptotal=`sysctl -n vm.swap_total`
44 [ $swaptotal -eq 0 ] && exit 0
45 [ $size -gt $swaptotal ] && size=$swaptotal
46 size=$((size / 10 * 8))
48 mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint
49 [ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart
50 mdconfig -a -t swap -s 1g -u $mdstart
51 bsdlabel -w md$mdstart auto
52 newfs $newfs_flags md${mdstart}$part > /dev/null
53 mount /dev/md${mdstart}$part $mntpoint
59 [ -f laundry.core -a $s -eq 0 ] &&
60 { ls -l laundry.core; s=1; }
64 mount | grep -q "on $mntpoint " || break
65 umount $mntpoint && break || sleep 10
67 [ $i -eq 6 ] && exit 1
68 mdconfig -d -u $mdstart
73 #include <sys/param.h>
78 #include <machine/atomic.h>
88 static volatile u_int *share;
92 #define RUNTIME (5 * 60)
103 atomic_add_int(&share[SYNC], 1);
104 while (share[SYNC] != PARALLEL)
108 if ((cp = mmap(0, sz, PROT_READ|PROT_WRITE, MAP_ANON, -1, 0)) ==
110 err(1, "mmap size %zd", sz);
114 while ((time(NULL) - start) < RUNTIME) {
117 for (i = 0; i < sz; i += PAGE_SIZE)
127 main(int argc __unused, char *argv[])
129 pid_t pids[PARALLEL];
135 sscanf(argv[1], "%zd", &size);
139 if ((share = mmap(NULL, len, PROT_READ | PROT_WRITE,
140 MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED)
144 while ((time(NULL) - start) < RUNTIME && e == 0) {
146 for (i = 0; i < PARALLEL; i++) {
147 if ((pids[i] = fork()) == 0)
152 for (i = 0; i < PARALLEL; i++) {
153 if (waitpid(pids[i], &status, 0) == -1)
154 err(1, "waitpid(%d)", pids[i]);
156 if (WIFEXITED(status)) {
157 printf("exited, status=%d\n",
158 WEXITSTATUS(status));
159 } else if (WIFSIGNALED(status)) {
160 printf("killed by signal %d\n",
162 } else if (WIFSTOPPED(status)) {
163 printf("stopped by signal %d\n",
165 } else if (WIFCONTINUED(status)) {
166 printf("continued\n");
168 fprintf(stderr, "pid %d exit code %d\n",
171 e += status == 0 ? 0 : 1;