4 # Copyright (c) 2013 Peter Holm <pho@FreeBSD.org>
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 # mlockall(2) test scenario.
30 # "panic: vm_page_unwire: page xxx's wire count is zero" seen.
31 # http://people.freebsd.org/~pho/stress/log/mlockall.txt
33 [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
40 sed '1,/^EOF/d' < $odir/$0 > $dir/mlockall3.c
41 mycc -o mlockall3 -Wall -Wextra mlockall3.c -lpthread || exit 1
47 killall mlockall3 > /dev/null 2>&1
52 #include <sys/types.h>
64 #include <sys/param.h>
66 #include <sys/syscall.h>
70 #define N (128 * 1024 / (int)sizeof(u_int32_t))
74 hand(int i __unused) { /* handler */
85 i = arc4random() % 100;
88 if (i >= 20 && i < 40)
90 if (i >= 40 && i < 60)
91 val = (unsigned long)(r) | (val & 0xffff);
94 val = (val << 32) | arc4random();
96 val = val & 0x00007fffffffffffUL;
104 calls(void *arg __unused)
107 unsigned long arg1, arg2, arg3;
110 for (i = 0; i < 500; i++) {
116 syscall(SYS_mlockall, arg1, arg2, arg3);
130 if ((pw = getpwnam("nobody")) == NULL)
131 err(1, "no such user: nobody");
133 if (setgroups(1, &pw->pw_gid) ||
134 setegid(pw->pw_gid) || setgid(pw->pw_gid) ||
135 seteuid(pw->pw_uid) || setuid(pw->pw_uid))
136 err(1, "Can't drop privileges to \"nobody\"");
139 signal(SIGALRM, hand);
140 signal(SIGILL, hand);
141 signal(SIGFPE, hand);
142 signal(SIGSEGV, hand);
143 signal(SIGBUS, hand);
144 signal(SIGURG, hand);
145 signal(SIGSYS, hand);
146 signal(SIGTRAP, hand);
149 for (i = 0; i < 8000; i++) {
150 if ((pid = fork()) == 0) {
151 for (j = 0; j < N; j++)
153 for (j = 0; j < 50; j++)
154 if ((e = pthread_create(&cp[j], NULL, calls, NULL)) != 0)
155 errc(1, e, "pthread_create");
157 for (j = 0; j < 50; j++)
158 pthread_join(cp[j], NULL);