4 # Copyright (c) 2014 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 # panic: pmap active 0xfffff801d22cdae8" seen.
30 # Variation of mmap18.sh.
31 # http://people.freebsd.org/~pho/stress/log/kostik712.txt
34 [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
40 sed '1,/^EOF/d' < $here/$0 > mmap19.c
41 mycc -o mmap19 -Wall -Wextra -O2 mmap19.c -lpthread || exit 1
44 daemon sh -c "(cd $here/../testcases/swap; ./swap -t 2m -i 20 -k)"
45 rnd=`od -An -N1 -t u1 /dev/random | sed 's/ //g'`
51 while pgrep -q swap; do
55 rm -f /tmp/mmap19 /tmp/mmap19.core
58 #include <sys/types.h>
60 #include <sys/resource.h>
69 #include <pthread_np.h>
79 #define N (128 * 1024 / (int)sizeof(u_int32_t))
92 i = arc4random() % 100;
95 if (i >= 20 && i < 40)
97 if (i >= 40 && i < 60)
98 val = (unsigned long)(r) | (val & 0xffff);
101 val = (val << 32) | arc4random();
103 val = val & 0x00007fffffffffffUL;
115 if (p != MAP_FAILED && p != NULL)
116 val = (unsigned long)p + arc4random();
119 val = trunc_page(val);
121 return ((void *)val);
125 tmmap(void *arg __unused)
130 pthread_set_name_np(pthread_self(), __func__);
131 len = 1LL * 1024 * 1024 * 1024;
133 for (i = 0; i < 100; i++) {
134 if ((fd = open("/dev/zero", O_RDWR)) == -1)
137 if ((p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_PRIVATE,
138 fd, 0)) != MAP_FAILED) {
143 if ((p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_ANON, -1,
155 tmprotect(void *arg __unused)
161 pthread_set_name_np(pthread_self(), __func__);
163 for (i = 0; i < 200; i++) {
165 len = trunc_page(makearg());
167 if (mprotect(addr, len, prot) == 0)
172 fprintf(stderr, "Note: tmprotect() only succeeded %d times.\n",
184 if ((rc = pthread_create(&tid[0], NULL, tmmap, NULL)) != 0)
185 errc(1, rc, "tmmap()");
186 if ((rc = pthread_create(&tid[1], NULL, tmprotect, NULL)) != 0)
187 errc(1, rc, "tmprotect()");
189 for (i = 0; i < 100; i++) {
198 for (i = 0; i < 2; i++)
199 if ((rc = pthread_join(tid[i], NULL)) != 0)
200 errc(1, rc, "pthread_join(%d)", i);
208 pid_t pids[PARALLEL];
213 rl.rlim_max = rl.rlim_cur = 0;
214 if (setrlimit(RLIMIT_CORE, &rl) == -1)
217 for (i = 0; i < N; i++)
222 for (i = 0; i < LOOPS && e == 0; i++) {
223 for (j = 0; j < PARALLEL; j++) {
224 if ((pids[j] = fork()) == 0)
228 for (j = 0; j < PARALLEL; j++) {
229 if (waitpid(pids[j], &status, 0) != pids[j])
230 err(1, "waitpid(%d)", pids[j]);
231 if (status != 0 && e == 0 && status != SIGSEGV && status != EFAULT)
234 if (time(NULL) - start > 1200) {
235 fprintf(stderr, "Timed out.");