4 # SPDX-License-Identifier: BSD-2-Clause-FreeBSD
6 # Copyright (c) 2019 Dell EMC Isilon
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
11 # 1. Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
13 # 2. Redistributions in binary form must reproduce the above copyright
14 # notice, this list of conditions and the following disclaimer in the
15 # documentation and/or other materials provided with the distribution.
17 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 # "panic: Lock (rw) vm object not locked @ vm/vm_page.c:1013" seen:
31 # https://people.freebsd.org/~pho/stress/log/mlockall6-2.txt
35 [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
36 [ `swapinfo | wc -l` -eq 1 ] && exit 0
41 sed '1,/^EOF/d' < $odir/$0 > $dir/mlockall6.c
42 mycc -o mlockall6 -Wall -Wextra -O0 -g mlockall6.c || exit 1
46 mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint
47 mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart
48 mdconfig -a -t swap -s 512m -u $mdstart || exit 1
49 bsdlabel -w md$mdstart auto
50 newfs $newfs_flags -n md${mdstart}$part > /dev/null
51 mount /dev/md${mdstart}$part $mntpoint || exit 1
53 daemon sh -c "(cd $odir/../testcases/swap; ./swap -t 20m -i 20 -l 100)" \
57 (cd $mntpoint; /tmp/mlockall6 || echo FAIL)
59 while pgrep -q swap; do
64 while mount | grep "on $mntpoint " | grep -q /dev/md; do
65 umount $mntpoint || sleep 1
67 [ $n -gt 10 ] && { echo FAIL; exit 1; }
69 mdconfig -d -u $mdstart
74 #include <sys/param.h>
79 #include <machine/atomic.h>
94 #define RUNTIME (10 * 60)
96 static volatile u_int *share;
98 static char c[32 * 1024 * 1024];
105 for (i = 0; i < (int)sizeof(c); i += ps)
113 volatile u_int *share2;
118 if ((share2 = mmap(NULL, len, PROT_READ | PROT_WRITE,
119 MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED)
122 usleep(arc4random() % 100000);
124 if ((pid = fork()) == 0) {
126 while (share2[R1] == 0) /* Wait for parent */
128 atomic_add_int(&share2[R1], 1);
129 if (arc4random() % 100 < 50)
130 usleep(arc4random() % 1000);
131 if (mlockall(MCL_CURRENT | MCL_FUTURE) == -1)
134 atomic_add_int(&share2[R2], 1);
137 atomic_add_int(&share2[R1], 1);
138 while (share2[R1] != 2) /* Wait for child */
141 for (i = 0; i < 100000 && share2[R2] == 0; i++)
142 touch(); /* while child is running */
144 if (waitpid(pid, &status, 0) == -1)
148 fprintf(stderr, "Got signal %d\n", WTERMSIG(status));
149 _exit(WTERMSIG(status));
158 while (share[R0] == 0)
161 for (i = 0; i < LOOPS; i++) {
162 if ((pid = fork()) == 0)
164 waitpid(pid, &status, 0);
165 s = (s == 0) ? status : s;
180 if ((share = mmap(NULL, len, PROT_READ | PROT_WRITE,
181 MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED)
185 while (s == 0 && (time(NULL) - start) < RUNTIME) {
186 for (i = 0; i < PARALLEL; i++) {
187 if ((pid = fork()) == 0)
190 atomic_add_int(&share[R0], 1); /* Start test() runs */
191 for (i = 0; i < PARALLEL; i++) {
192 waitpid(pid, &status, 0);
194 fprintf(stderr, "FAIL: status = %d\n",
197 s = (s == 0) ? status : s;
199 atomic_add_int(&share[R0], -1);