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
32 [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
39 sed '1,/^EOF/d' < $odir/$0 > $dir/shm2.c
40 mycc -o shm2 -Wall -Wextra -O0 -g shm2.c || exit 1
43 (cd $odir/../testcases/swap; ./swap -t 2m -i 20 -h -l 100) &
45 while pkill swap; do sleep 1; done
52 #include <sys/types.h>
53 #include <sys/resource.h>
55 #include <sys/sysctl.h>
59 #include <vm/vm_param.h>
67 #define INCARNATIONS 32
69 static unsigned long size, original;
70 static int runtime, utime;
77 size = size / INCARNATIONS;
80 errx(1, "Argument too small");
82 if (getrlimit(RLIMIT_DATA, &rlp) < 0)
84 rlp.rlim_cur -= 1024 * 1024;
86 if (size > (unsigned long)rlp.rlim_cur)
90 printf("setup: pid %d. Total %luMb\n",
91 getpid(), size / 1024 / 1024 * INCARNATIONS);
95 errx(1, "Argument too small");
109 shmkey = ftok("/tmp", getpid());
111 while (shmid == -1) {
112 if ((shmid = shmget(shmkey, size, IPC_CREAT | IPC_EXCL | 0640)) == -1) {
113 if (errno != ENOSPC && errno != EEXIST)
114 err(1, "shmget (%s:%d)", __FILE__, __LINE__);
119 if ((c = shmat(shmid, NULL, 0)) == (void *) -1)
121 if (size != original)
122 printf("shm size changed from %ld kb to %ld kb\n",
123 original / 1024, size / 1024);
124 page = getpagesize();
126 while ((time(NULL) - start) < runtime) {
131 if ((time(NULL) - start) >= runtime)
136 if (shmdt((void *)c) == -1) {
138 warn("shmdt(%p)", c);
140 if (shmctl(shmid, IPC_RMID, NULL) == -1)
141 warn("shmctl IPC_RMID");
149 pid_t pids[INCARNATIONS];
152 runtime = 120; /* 2 minutes */
153 utime = 1000; /* 0.001 sec */
155 size = 512 * 1024 * 1024;
158 for (i = 0; i < INCARNATIONS; i++)
159 if ((pids[i] = fork()) == 0)
162 for (i = 0; i < INCARNATIONS; i++)
163 if (waitpid(pids[i], NULL, 0) != pids[i])
164 err(1, "waitpid(%d)", pids[i]);