Date: Wed, 17 Jul 2013 07:17:08 +0000 (UTC) From: Peter Holm <pho@FreeBSD.org> To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r253412 - user/pho/stress2/misc Message-ID: <201307170717.r6H7H8mI081711@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: pho Date: Wed Jul 17 07:17:07 2013 New Revision: 253412 URL: http://svnweb.freebsd.org/changeset/base/253412 Log: Swap test scenario added. Sponsored by: EMC / Isilon storage division Added: user/pho/stress2/misc/swap.sh (contents, props changed) Added: user/pho/stress2/misc/swap.sh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/pho/stress2/misc/swap.sh Wed Jul 17 07:17:07 2013 (r253412) @@ -0,0 +1,152 @@ +#!/bin/sh + +# +# Copyright (c) 2013 EMC Corp. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# + +# Swap test. Variation of testcases/swap. + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/swap.c +cc -o swap -Wall -Wextra -O2 swap.c || exit 1 +rm -f swap.c + +usermem=`sysctl hw.usermem | sed 's/.* //'` +swap=`sysctl vm.swap_total | sed 's/.* //'` + +if [ $swap -gt 0 ]; then + size=$((usermem/10*11)) +else + size=$((usermem/10*9)) +fi + +/tmp/swap $((size / 4096)) + +rm -f /tmp/swap +exit +EOF +#include <sys/types.h> +#include <err.h> +#include <stdio.h> +#include <stdlib.h> +#include <sys/resource.h> +#include <sys/sysctl.h> +#include <sys/time.h> +#include <sys/wait.h> +#include <unistd.h> + +#define RUNTIME (5 * 60) +#define INCARNATIONS 32 + +static unsigned long size, original; + +void +setup(void) +{ + struct rlimit rlp; + + size = size / INCARNATIONS; + original = size; + if (size == 0) + errx(1, "Argument too small"); + + if (getrlimit(RLIMIT_DATA, &rlp) < 0) + err(1,"getrlimit"); + rlp.rlim_cur -= 1024 * 1024; + + if (size > (unsigned long)rlp.rlim_cur) + size = rlp.rlim_cur; + +#if 0 + printf("setup: pid %d. Total %luMb\n", + getpid(), size / 1024 / 1024 * INCARNATIONS); +#endif + + if (size == 0) + errx(1, "Argument too small"); + + return; +} + +int +test(void) +{ + char *c; + int page; + unsigned long i, j; + time_t start; + + c = malloc(size); + while (c == NULL) { + size -= 1024 * 1024; + c = malloc(size); + } + if (size != original) + printf("Malloc size changed from %ld Mb to %ld Mb\n", + original / 1024 / 1024, size / 1024 / 1024); + page = getpagesize(); + start = time(NULL); + while ((time(NULL) - start) < RUNTIME) { + i = j = 0; + while (i < size) { + c[i] = 0; + i += page; + if (++j % 1024 == 0) { + if ((time(NULL) - start) >= RUNTIME) + break; + if (arc4random() % 100 < 5) + usleep(1000); + } + } + } + free(c); + + _exit(0); +} + +int +main(int argc, char **argv) +{ + int i; + + if (argc != 2) + errx(1, "Usage: %s bytes", argv[0]); + + size = atol(argv[1]) * 4096; + setup(); + + for (i = 0; i < INCARNATIONS; i++) + if (fork() == 0) + test(); + + for (i = 0; i < INCARNATIONS; i++) + wait(NULL); + + return (0); +}
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201307170717.r6H7H8mI081711>