1#!/bin/sh 2 3# Test scenario for Bug 261707. 4# Based on Kostik's shm_super.sh 5# "panic: vm_page_free_prep: freeing mapped page ..." seen. 6 7# Test scenario suggestion by kib@ 8 9. ../default.cfg 10 11cat > /tmp/shm3.c <<EOF 12#include <sys/param.h> 13#include <sys/mman.h> 14 15#include <err.h> 16#include <fcntl.h> 17#include <stdio.h> 18#include <stdlib.h> 19#include <string.h> 20#include <unistd.h> 21 22#define M(x) ((x) * 1024 * 1024) 23#define SZ M(256) 24 25int 26main(void) 27{ 28 off_t cnt; 29 void *ptr; 30 int error, shmfd; 31 char buf[128]; 32 33 shmfd = shm_open(SHM_ANON, O_CREAT | O_RDWR, 0600); 34 if (shmfd == -1) 35 err(1, "shm_open"); 36 error = ftruncate(shmfd, SZ); 37 if (error == -1) 38 err(1, "truncate"); 39 memset(buf, 0, sizeof(buf)); 40 for (cnt = 0; cnt < SZ; cnt += sizeof(buf)) { 41 error = write(shmfd, buf, sizeof(buf)); 42 if (error == -1) 43 err(1, "write"); 44 else if (error != sizeof(buf)) 45 errx(1, "short write %d", (int)error); 46 } 47 ptr = mmap(NULL, SZ, PROT_READ | PROT_WRITE, MAP_SHARED, 48 shmfd, 0); 49 if (ptr == MAP_FAILED) 50 err(1, "mmap"); 51 for (cnt = 0; cnt < SZ; cnt += PAGE_SIZE) 52 *((char *)ptr + cnt) = 0; 53 close(shmfd); 54 sleep(30); 55} 56EOF 57mycc -o /tmp/shm3 -Wall -Wextra -O0 -g /tmp/shm3.c || exit 1 58rm /tmp/shm3.c 59 60../testcases/swap/swap -t 3m -i 50 > /dev/null & 61sleep 30 62for i in `jot 50`; do 63 /tmp/shm3 & 64done 65while pgrep -q shm3; do 66 sleep 5 67done 68while pkill swap; do 69 sleep .2 70done 71wait 72 73rm -f /tmp/shm3 74exit $s 75