18a272653SPeter Holm#!/bin/sh 28a272653SPeter Holm 38a272653SPeter Holm# 48a272653SPeter Holm# Copyright (c) 2013 EMC Corp. 58a272653SPeter Holm# All rights reserved. 68a272653SPeter Holm# 78a272653SPeter Holm# Redistribution and use in source and binary forms, with or without 88a272653SPeter Holm# modification, are permitted provided that the following conditions 98a272653SPeter Holm# are met: 108a272653SPeter Holm# 1. Redistributions of source code must retain the above copyright 118a272653SPeter Holm# notice, this list of conditions and the following disclaimer. 128a272653SPeter Holm# 2. Redistributions in binary form must reproduce the above copyright 138a272653SPeter Holm# notice, this list of conditions and the following disclaimer in the 148a272653SPeter Holm# documentation and/or other materials provided with the distribution. 158a272653SPeter Holm# 168a272653SPeter Holm# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 178a272653SPeter Holm# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 188a272653SPeter Holm# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 198a272653SPeter Holm# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 208a272653SPeter Holm# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 218a272653SPeter Holm# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 228a272653SPeter Holm# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 238a272653SPeter Holm# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 248a272653SPeter Holm# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 258a272653SPeter Holm# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 268a272653SPeter Holm# SUCH DAMAGE. 278a272653SPeter Holm# 288a272653SPeter Holm 298a272653SPeter Holm# Swap test. Variation of swap.sh 308a272653SPeter Holm# panic: vm_radix_remove: impossible to locate the key 318a272653SPeter Holm# panic: vm_page_alloc: cache page 0xff... is missing from the free queue 328a272653SPeter Holm# panic: vm_radix_node_put: rnode 0xfffffe00099035a0 has a child 338a272653SPeter Holm# panic: vm_radix_remove: impossible to locate the key 348a272653SPeter Holm 358a272653SPeter Holm[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 368a272653SPeter Holm 378a272653SPeter Holm. ../default.cfg 388a272653SPeter Holm 398a272653SPeter Holmmount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint 408a272653SPeter Holmmdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart 418a272653SPeter Holmmdconfig -a -t swap -s 2g -u $mdstart 42*608c97bfSPeter Holmnewfs $newfs_flags md$mdstart > /dev/null 43*608c97bfSPeter Holmmount /dev/md$mdstart $mntpoint 448a272653SPeter Holmchmod 777 $mntpoint 458a272653SPeter Holm 468a272653SPeter Holmexport RUNDIR=$mntpoint/stressX 478a272653SPeter Holmrm -rf /tmp/stressX.control 488a272653SPeter Holmdir=/tmp 498a272653SPeter Holmodir=`pwd` 508a272653SPeter Holmcd $dir 518a272653SPeter Holmsed '1,/^EOF/d' < $odir/$0 > $dir/swap2.c 528a272653SPeter Holmmycc -o swap2 -Wall -Wextra -O2 swap2.c || exit 1 538a272653SPeter Holmrm -f swap2.c 548a272653SPeter Holmcd $odir 558a272653SPeter Holm 568a272653SPeter Holmusermem=`sysctl -n hw.usermem` 578a272653SPeter Holmswap=`sysctl -n vm.swap_total` 588a272653SPeter Holm 598a272653SPeter Holmif [ $swap -gt 0 ]; then 608a272653SPeter Holm size=$((usermem/10*11)) 618a272653SPeter Holmelse 628a272653SPeter Holm size=$((usermem/10*8)) 638a272653SPeter Holmfi 648a272653SPeter Holm 658a272653SPeter Holm/tmp/swap2 $((size / 4096)) & 668a272653SPeter Holmsleep 30 678a272653SPeter Holmsu $testuser -c "(cd ../testcases/rw; ./rw -t 3m -i 40 -l 100 -v -h -h)" & 688a272653SPeter Holmwait 698a272653SPeter Holm 708a272653SPeter Holmwhile mount | grep $mntpoint | grep -q /dev/md; do 718a272653SPeter Holm umount $mntpoint || sleep 1 728a272653SPeter Holmdone 738a272653SPeter Holmmdconfig -d -u $mdstart 748a272653SPeter Holmrm -f /tmp/swap2 758a272653SPeter Holmexit 768a272653SPeter HolmEOF 778a272653SPeter Holm#include <sys/types.h> 788a272653SPeter Holm#include <err.h> 798a272653SPeter Holm#include <stdio.h> 808a272653SPeter Holm#include <stdlib.h> 818a272653SPeter Holm#include <sys/resource.h> 828a272653SPeter Holm#include <sys/sysctl.h> 838a272653SPeter Holm#include <sys/time.h> 848a272653SPeter Holm#include <sys/wait.h> 858a272653SPeter Holm#include <unistd.h> 868a272653SPeter Holm 878a272653SPeter Holm#define RUNTIME (5 * 60) 888a272653SPeter Holm#define INCARNATIONS 32 898a272653SPeter Holm 908a272653SPeter Holmstatic unsigned long size, original; 918a272653SPeter Holm 928a272653SPeter Holmvoid 938a272653SPeter Holmsetup(void) 948a272653SPeter Holm{ 958a272653SPeter Holm struct rlimit rlp; 968a272653SPeter Holm 978a272653SPeter Holm size = size / INCARNATIONS; 988a272653SPeter Holm original = size; 998a272653SPeter Holm if (size == 0) 1008a272653SPeter Holm errx(1, "Argument too small"); 1018a272653SPeter Holm 1028a272653SPeter Holm if (getrlimit(RLIMIT_DATA, &rlp) < 0) 1038a272653SPeter Holm err(1,"getrlimit"); 1048a272653SPeter Holm rlp.rlim_cur -= 1024 * 1024; 1058a272653SPeter Holm 1068a272653SPeter Holm if (size > (unsigned long)rlp.rlim_cur) 1078a272653SPeter Holm size = rlp.rlim_cur; 1088a272653SPeter Holm 1098a272653SPeter Holm#if 0 1108a272653SPeter Holm printf("setup: pid %d. Total %luMb\n", 1118a272653SPeter Holm getpid(), size / 1024 / 1024 * INCARNATIONS); 1128a272653SPeter Holm#endif 1138a272653SPeter Holm 1148a272653SPeter Holm if (size == 0) 1158a272653SPeter Holm errx(1, "Argument too small"); 1168a272653SPeter Holm 1178a272653SPeter Holm return; 1188a272653SPeter Holm} 1198a272653SPeter Holm 1208a272653SPeter Holmint 1218a272653SPeter Holmtest(void) 1228a272653SPeter Holm{ 1238a272653SPeter Holm volatile char *c; 1248a272653SPeter Holm int page; 1258a272653SPeter Holm unsigned long i, j; 1268a272653SPeter Holm time_t start; 1278a272653SPeter Holm 1288a272653SPeter Holm c = malloc(size); 1298a272653SPeter Holm while (c == NULL) { 1308a272653SPeter Holm size -= 1024 * 1024; 1318a272653SPeter Holm c = malloc(size); 1328a272653SPeter Holm } 1338a272653SPeter Holm if (size != original) 1348a272653SPeter Holm printf("Malloc size changed from %ld Mb to %ld Mb\n", 1358a272653SPeter Holm original / 1024 / 1024, size / 1024 / 1024); 1368a272653SPeter Holm page = getpagesize(); 1378a272653SPeter Holm start = time(NULL); 1388a272653SPeter Holm while ((time(NULL) - start) < RUNTIME) { 1398a272653SPeter Holm i = j = 0; 1408a272653SPeter Holm while (i < size) { 1418a272653SPeter Holm c[i] = 0; 1428a272653SPeter Holm i += page; 1438a272653SPeter Holm if (++j % 1024 == 0) { 1448a272653SPeter Holm if ((time(NULL) - start) >= RUNTIME) 1458a272653SPeter Holm break; 1468a272653SPeter Holm if (arc4random() % 100 < 5) 1478a272653SPeter Holm usleep(1000); 1488a272653SPeter Holm } 1498a272653SPeter Holm } 1508a272653SPeter Holm } 1518a272653SPeter Holm free((void *)c); 1528a272653SPeter Holm 1538a272653SPeter Holm _exit(0); 1548a272653SPeter Holm} 1558a272653SPeter Holm 1568a272653SPeter Holmint 1578a272653SPeter Holmmain(int argc, char **argv) 1588a272653SPeter Holm{ 1598a272653SPeter Holm int i; 1608a272653SPeter Holm 1618a272653SPeter Holm if (argc != 2) 1628a272653SPeter Holm errx(1, "Usage: %s bytes", argv[0]); 1638a272653SPeter Holm 1648a272653SPeter Holm size = atol(argv[1]) * 4096; 1658a272653SPeter Holm setup(); 1668a272653SPeter Holm 1678a272653SPeter Holm for (i = 0; i < INCARNATIONS; i++) 1688a272653SPeter Holm if (fork() == 0) 1698a272653SPeter Holm test(); 1708a272653SPeter Holm 1718a272653SPeter Holm for (i = 0; i < INCARNATIONS; i++) 1728a272653SPeter Holm wait(NULL); 1738a272653SPeter Holm 1748a272653SPeter Holm return (0); 1758a272653SPeter Holm} 176