4 # Copyright (c) 2015 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 # Copy of holdcnt0.sh, but without the memory disk usage.
31 # Test scenario suggestion by alc@
33 [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
34 [ `swapinfo | wc -l` -eq 1 ] && exit 0
35 [ `sysctl -n hw.physmem` -lt $((32 * 1024 * 1024 * 1024)) ] && exit 0
41 sed '1,/^EOF/d' < $here/$0 > holdcnt02.c
42 mycc -o holdcnt02 -Wall -Wextra -g holdcnt02.c || exit 1
46 trap "rm -f /tmp/holdcnt02 `dirname $diskimage`/f000???" EXIT INT
47 (cd `dirname $diskimage`; /tmp/holdcnt02) &
50 while kill -0 $! 2> /dev/null; do
51 (cd ../testcases/swap; ./swap -t 1m -i 1) > /dev/null 2>&1
57 A test that causes the page daemon to generate cached pages
58 within a bunch of files and has some consumer that is trying to
59 allocate new pages to the same files.
62 #include <sys/types.h>
77 #define BUFSIZE (1024 * 1024)
86 static volatile char val;
89 hand(int i __unused) { /* handler */
99 for (i = 0; i < FILES; i++) {
100 snprintf(file, sizeof(file), "f%06d", i);
111 for (i = 0; i < FILES; i++) {
112 snprintf(file, sizeof(file), "f%06d", i);
113 if ((fd = open(file, O_RDWR | O_CREAT | O_TRUNC, 0644)) ==
115 err(1, "open(%s)", file);
116 if (write(fd, buf, BUFSIZE) != BUFSIZE)
131 setproctitle("writer");
133 while (time(NULL) - start < 600) {
134 for (i = 0; i < FILES; i++) {
135 snprintf(file, sizeof(file), "f%06d", i);
136 if ((fd = open(file, O_RDWR | O_APPEND)) == -1) {
138 err(1, "open(%s) append", file);
141 if (fstat(fd, &statbuf) < 0)
142 err(1, "fstat error");
143 if (statbuf.st_size < maxsize) {
144 if (write(fd, buf, ps) != ps) {
167 setproctitle("reader");
168 signal(SIGSEGV, hand);
169 signal(SIGBUS, hand);
173 for (i = 0; i < FILES; i++) {
174 snprintf(file, sizeof(file), "f%06d", i);
177 if ((fd = open(file, O_RDWR)) == -1) {
179 warn("reader(%s)", file);
182 if (fstat(fd, &statbuf) < 0)
183 err(1, "fstat error");
184 if (statbuf.st_size >= maxsize) {
185 if (ftruncate(fd, ps) == -1)
189 len = statbuf.st_size;
190 if ((p = mmap(p, len, PROT_READ, MAP_SHARED, fd, 0))
194 n = statbuf.st_size / ps;
195 for (j = 0; j < n; j++) {
200 if (munmap(p, len) == -1)
210 pid_t rpid[RPARALLEL], wpid[WPARALLEL];
213 maxsize = 2LL * 1024 * 1024 * 1024 / FILES;
214 buf = malloc(BUFSIZE);
219 for (i = 0; i < WPARALLEL; i++) {
220 if ((wpid[i] = fork()) == 0)
223 for (i = 0; i < RPARALLEL; i++) {
224 if ((rpid[i] = fork()) == 0)
228 for (i = 0; i < WPARALLEL; i++)
229 waitpid(wpid[i], &s, 0);
231 for (i = 0; i < RPARALLEL; i++)
232 waitpid(rpid[i], &s, 0);