Date: Wed, 18 Feb 2015 13:07:27 +0000 (UTC) From: Peter Holm <pho@FreeBSD.org> To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r278955 - user/pho/stress2/misc Message-ID: <201502181307.t1ID7R4l065368@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: pho Date: Wed Feb 18 13:07:26 2015 New Revision: 278955 URL: https://svnweb.freebsd.org/changeset/base/278955 Log: Added more mmap(2)/mlock(2) test scenarios. Sponsored by: EMC / Isilon storage division Added: user/pho/stress2/misc/mmap14.sh (contents, props changed) user/pho/stress2/misc/mmap15.sh (contents, props changed) user/pho/stress2/misc/mmap16.sh (contents, props changed) user/pho/stress2/misc/mmap17.sh (contents, props changed) user/pho/stress2/misc/mmap18.sh (contents, props changed) user/pho/stress2/misc/mmap20.sh (contents, props changed) user/pho/stress2/misc/mmap21.sh (contents, props changed) user/pho/stress2/misc/mmap22.sh (contents, props changed) Added: user/pho/stress2/misc/mmap14.sh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/pho/stress2/misc/mmap14.sh Wed Feb 18 13:07:26 2015 (r278955) @@ -0,0 +1,222 @@ +#!/bin/sh + +# +# Copyright (c) 2014 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$ +# + +# Simplified version of mmap10.sh with focus on core dumps +# Deadlock seen: +# http://people.freebsd.org/~pho/stress/log/kostik673.txt +# No issues seen with r272060. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > mmap14.c +mycc -o mmap14 -Wall -Wextra -O2 -g mmap14.c -lpthread || exit 1 +rm -f mmap14.c + +daemon sh -c "(cd $here/../testcases/swap; ./swap -t 2m -i 20 -k -h)" +rnd=`od -An -N1 -t u1 /dev/random | sed 's/ //g'` +sleep $((rnd % 10)) +for i in `jot 2`; do + /tmp/mmap14 +done +killall -q swap + +rm -f /tmp/mmap14 /tmp/mmap14.core +exit 0 +EOF +#include <sys/types.h> +#include <sys/mman.h> +#include <sys/stat.h> +#include <sys/time.h> +#include <sys/wait.h> + +#include <err.h> +#include <errno.h> +#include <fcntl.h> +#include <pthread.h> +#include <pthread_np.h> +#include <sched.h> +#include <signal.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <time.h> +#include <unistd.h> + +#define LOOPS 2 +#define N (128 * 1024 / (int)sizeof(u_int32_t)) +#define PARALLEL 50 + +void *p; +u_int32_t r[N]; + +unsigned long +makearg(void) +{ + unsigned long val; + unsigned int i; + + val = arc4random(); + i = arc4random() % 100; + if (i < 20) + val = val & 0xff; + if (i >= 20 && i < 40) + val = val & 0xffff; + if (i >= 40 && i < 60) + val = (unsigned long)(r) | (val & 0xffff); +#if defined(__LP64__) + if (i >= 60) { + val = (val << 32) | arc4random(); + if (i > 80) + val = val & 0x00007fffffffffffUL; + } +#endif + + return(val); +} + +void * +makeptr(void) +{ + unsigned long val; + + if (p != MAP_FAILED && p != NULL) + val = (unsigned long)p + arc4random(); + else + val = makearg(); + val = trunc_page(val); + + return ((void *)val); +} + +void * +tmmap(void *arg __unused) +{ + size_t len; + int i, fd; + + pthread_set_name_np(pthread_self(), __func__); + len = 1LL * 1024 * 1024 * 1024; + + for (i = 0; i < 100; i++) { + if ((fd = open("/dev/zero", O_RDWR)) == -1) + err(1,"open()"); + + if ((p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, + 0)) != MAP_FAILED) { + usleep(100); + munmap(p, len); + } + + if ((p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_ANON, -1, 0)) != + MAP_FAILED) { + usleep(100); + munmap(p, len); + } + close(fd); + } + + return (NULL); +} + +void * +tmlock(void *arg __unused) +{ + size_t len; + int i, n; + + pthread_set_name_np(pthread_self(), __func__); + n = 0; + for (i = 0; i < 200; i++) { + len = trunc_page(makearg()); + if (mlock(makeptr(), len) == 0) + n++; + len = trunc_page(makearg()); + if (arc4random() % 100 < 50) + if (munlock(makeptr(), len) == 0) + n++; + } + if (n < 10) + fprintf(stderr, "Note: tmlock() only succeeded %d times.\n", + n); + + return (NULL); +} + +void +test(void) +{ + pthread_t tid[4]; + int i, rc; + + if ((rc = pthread_create(&tid[0], NULL, tmmap, NULL)) != 0) + errc(1, rc, "tmmap()"); + if ((rc = pthread_create(&tid[1], NULL, tmlock, NULL)) != 0) + errc(1, rc, "tmlock()"); + + for (i = 0; i < 100; i++) { + if (fork() == 0) { + usleep(10000); + _exit(0); + } + wait(NULL); + } + + raise(SIGSEGV); + + for (i = 0; i < 2; i++) + if ((rc = pthread_join(tid[i], NULL)) != 0) + errc(1, rc, "pthread_join(%d)", i); + _exit(0); +} + +int +main(void) +{ + int i, j; + + for (i = 0; i < N; i++) + r[i] = arc4random(); + + for (i = 0; i < LOOPS; i++) { + for (j = 0; j < PARALLEL; j++) { + if (fork() == 0) + test(); + } + + for (j = 0; j < PARALLEL; j++) + wait(NULL); + } + + return (0); +} Added: user/pho/stress2/misc/mmap15.sh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/pho/stress2/misc/mmap15.sh Wed Feb 18 13:07:26 2015 (r278955) @@ -0,0 +1,213 @@ +#!/bin/sh + +# +# Copyright (c) 2014 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$ +# + +# Missing wakeup in the bufobj_wwait(). + +# Snapshot of WiP work. +# http://people.freebsd.org/~pho/stress/log/mmap15.txt +# Not fixed + +# panic: invalid size +# http://people.freebsd.org/~pho/stress/log/kostik738.txt +# Fixed in r274878 + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > mmap15.c +mycc -o mmap15 -Wall -Wextra -O2 -g mmap15.c -lpthread || exit 1 +rm -f mmap15.c + +for i in `jot 2`; do + su $testuser -c /tmp/mmap15 +done + +rm -f /tmp/mmap15 /tmp/mmap15.core +exit 0 +EOF +#include <sys/types.h> +#include <sys/mman.h> +#include <sys/stat.h> +#include <sys/time.h> +#include <sys/wait.h> + +#include <err.h> +#include <errno.h> +#include <fcntl.h> +#include <pthread.h> +#include <pthread_np.h> +#include <signal.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <time.h> +#include <unistd.h> + +#define LOOPS 2 +#define N (128 * 1024 / (int)sizeof(u_int32_t)) +#define PARALLEL 50 + +void *p; +u_int32_t r[N]; + +unsigned long +makearg(void) +{ + unsigned long val; + unsigned int i; + + val = arc4random(); + i = arc4random() % 100; + if (i < 20) + val = val & 0xff; + if (i >= 20 && i < 40) + val = val & 0xffff; + if (i >= 40 && i < 60) + val = (unsigned long)(r) | (val & 0xffff); +#if defined(__LP64__) + if (i >= 60) { + val = (val << 32) | arc4random(); + if (i > 80) + val = val & 0x00007fffffffffffUL; + } +#endif + + return(val); +} + +void * +makeptr(void) +{ + unsigned long val; + + if (p != MAP_FAILED && p != NULL) + val = (unsigned long)p + arc4random(); + else + val = makearg(); + val = trunc_page(val); + + return ((void *)val); +} + +void * +tmmap(void *arg __unused) +{ + size_t len; + int i, fd; + + pthread_set_name_np(pthread_self(), __func__); + len = 1LL * 128 * 1024 * 1024; + + if ((fd = open("/dev/zero", O_RDWR)) == -1) + err(1,"open()"); + for (i = 0; i < 100; i++) { + p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0); + p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_ANON, -1, 0); + } + close(fd); + + return (NULL); +} + +void * +tmlock(void *arg __unused) +{ + size_t len; + int i, n; + + pthread_set_name_np(pthread_self(), __func__); + n = 0; + for (i = 0; i < 200; i++) { + len = trunc_page(makearg()); + if (mlock(makeptr(), len) == 0) + n++; + len = trunc_page(makearg()); + if (arc4random() % 100 < 50) + if (munlock(makeptr(), len) == 0) + n++; + } + if (n < 10) + fprintf(stderr, "Note: tmlock() only succeeded %d times.\n", + n); + + return (NULL); +} + +void +test(void) +{ + pthread_t tid[2]; + int i, rc; + + if ((rc = pthread_create(&tid[0], NULL, tmmap, NULL)) != 0) + errc(1, rc, "tmmap()"); + if ((rc = pthread_create(&tid[1], NULL, tmlock, NULL)) != 0) + errc(1, rc, "tmlock()"); + + for (i = 0; i < 100; i++) { + if (fork() == 0) { + usleep(10000); + _exit(0); + } + wait(NULL); + } + + raise(SIGSEGV); + + for (i = 0; i < 2; i++) + if ((rc = pthread_join(tid[i], NULL)) != 0) + errc(1, rc, "pthread_join(%d)", i); + _exit(0); +} + +int +main(void) +{ + int i, j; + + alarm(120); + for (i = 0; i < N; i++) + r[i] = arc4random(); + + for (i = 0; i < LOOPS; i++) { + for (j = 0; j < PARALLEL; j++) { + if (fork() == 0) + test(); + } + + for (j = 0; j < PARALLEL; j++) + wait(NULL); + } + + return (0); +} Added: user/pho/stress2/misc/mmap16.sh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/pho/stress2/misc/mmap16.sh Wed Feb 18 13:07:26 2015 (r278955) @@ -0,0 +1,147 @@ +#!/bin/sh + +# +# Copyright (c) 2014 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$ +# + +exit 0 # Experimental test scenario + +# Test scenario by kib@ + +[ `uname -m` = "i386" ] || exit 0 + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > mmap16.c +mycc -o mmap16 -Wall -Wextra -O2 -g mmap16.c -lpthread || exit 1 +rm -f mmap16.c /tmp/mmap16.core +rm -f /tmp/mmap16.core + +/tmp/mmap16 > /dev/null + +rm -f /tmp/mmap16 /tmp/mmap16.core +exit 0 +EOF +/* $Id: map_hole.c,v 1.6 2014/06/16 05:52:03 kostik Exp kostik $ */ + +#include <sys/types.h> +#include <sys/mman.h> +#include <sys/resource.h> +#include <err.h> +#include <signal.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <ucontext.h> +#include <unistd.h> + +#ifndef MAP_HOLE +#define MAP_HOLE 0x00002000 /* no backing pages */ +#endif + +static void +sighandler(int signo, siginfo_t *info, void *uap1) +{ + static char scratch; + ucontext_t *uap; + + uap = uap1; + printf("SIG%s(%d) at %p (%%eax %p)\n", + signo < sys_nsig ? sys_signame[signo] : "SOME", signo, + info->si_addr, (void *)(uintptr_t)uap->uc_mcontext.mc_eax); + uap->uc_mcontext.mc_eax = (uintptr_t)&scratch; +} + +static void +access_addr(char *addr) +{ + char r; + + r = '1'; + printf("accessing %p\n", addr); + __asm __volatile("movb %0,(%%eax)" : : "i"(r), "a"(addr) : "memory"); + printf("done\n"); +} + +static int pagesz; + +static void +test_access(char *addr) +{ + struct rusage ru; + long majflt, minflt; + + if (getrusage(RUSAGE_THREAD, &ru) == -1) + err(1, "getrusage"); + majflt = ru.ru_majflt; + minflt = ru.ru_minflt; + access_addr(addr); + if (mprotect(addr, pagesz, PROT_READ | PROT_WRITE) == -1) + warn("mprotect"); + access_addr(addr); + if (getrusage(RUSAGE_THREAD, &ru) == -1) + err(1, "getrusage"); + majflt = ru.ru_majflt - majflt; + minflt = ru.ru_minflt - minflt; + printf("majflt %ld minflt %ld\n", majflt, minflt); +} + +int +main(void) +{ + struct sigaction sa; + char *addr; + char cmd[128]; + + bzero(&sa, sizeof(sa)); + sa.sa_sigaction = sighandler; + sa.sa_flags = SA_SIGINFO; + if (sigaction(SIGSEGV, &sa, NULL) == -1) + err(1, "sigaction"); + pagesz = getpagesize(); + + printf("MAP_HOLE\n"); + addr = mmap(NULL, pagesz, PROT_NONE, MAP_HOLE, -1, 0); + if (addr == (char *)MAP_FAILED) + err(1, "FAIL: mmap(MAP_HOLE)"); + test_access(addr); + + printf("PROT_NONE wire\n"); + addr = mmap(NULL, pagesz, PROT_NONE, MAP_ANON, -1, 0); + if (addr == (char *)MAP_FAILED) + err(1, "mmap(PROT_NONE)"); + if (mlock(addr, pagesz) == -1) + err(1, "mlock"); + test_access(addr); + + snprintf(cmd, sizeof(cmd), "procstat -v %d", getpid()); + system(cmd); + + return (0); +} Added: user/pho/stress2/misc/mmap17.sh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/pho/stress2/misc/mmap17.sh Wed Feb 18 13:07:26 2015 (r278955) @@ -0,0 +1,88 @@ +#!/bin/sh + +# +# Copyright (c) 2014 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$ +# + +# Test scenario by kib@ + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > mmap17.c +mycc -o mmap17 -Wall -Wextra -O2 -g mmap17.c -lpthread || exit 1 +rm -f mmap17.c /tmp/mmap17.core +rm -f /tmp/mmap17.core + +{ /tmp/mmap17 > /dev/null; } 2>&1 | grep -v worked + +rm -f /tmp/mmap17 /tmp/mmap17.core +exit 0 +EOF +/* $Id: map_excl.c,v 1.2 2014/06/16 06:02:52 kostik Exp kostik $ */ + +#include <sys/mman.h> +#include <err.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + +#ifndef MAP_EXCL +#define MAP_EXCL 0x00004000 /* for MAP_FIXED, fail if address is used */ +#endif + +int +main(void) +{ + char *addr, *addr1; + int pagesz; + char cmd[128]; + + pagesz = getpagesize(); + addr = mmap(NULL, pagesz, PROT_READ | PROT_WRITE, MAP_ANON, -1, 0); + if (addr == (char *)MAP_FAILED) + err(1, "mmap 1"); + printf("addr %p\n", addr); + + addr -= pagesz; + addr1 = mmap(addr, 3 * pagesz, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_FIXED | MAP_EXCL, -1, 0); + if (addr1 == MAP_FAILED) + warn("EXCL worked"); + else + fprintf(stderr, "EXCL failed\n"); + + addr1 = mmap(addr, 3 * pagesz, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_FIXED, -1, 0); + printf("addr1 %p\n", addr); + + snprintf(cmd, sizeof(cmd), "procstat -v %d", getpid()); + system(cmd); + + return (0); +} Added: user/pho/stress2/misc/mmap18.sh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/pho/stress2/misc/mmap18.sh Wed Feb 18 13:07:26 2015 (r278955) @@ -0,0 +1,275 @@ +#!/bin/sh + +# +# Copyright (c) 2014 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$ +# + +# Copy of mmap10.sh with core dump disabled. +# http://people.freebsd.org/~pho/stress/log/kostik711.txt +# http://people.freebsd.org/~pho/stress/log/mmap18.txt + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > mmap18.c +mycc -o mmap18 -Wall -Wextra -O2 mmap18.c -lpthread || exit 1 +rm -f mmap18.c + +daemon sh -c "(cd $here/../testcases/swap; ./swap -t 2m -i 20 -k)" +rnd=`od -An -N1 -t u1 /dev/random | sed 's/ //g'` +sleep $((rnd % 10)) +for i in `jot 2`; do + /tmp/mmap18 +done +killall -q swap + +rm -f /tmp/mmap18 /tmp/mmap18.core +exit 0 +EOF +#include <sys/types.h> +#include <sys/mman.h> +#include <sys/resource.h> +#include <sys/stat.h> +#include <sys/time.h> +#include <sys/wait.h> + +#include <err.h> +#include <errno.h> +#include <fcntl.h> +#include <pthread.h> +#include <pthread_np.h> +#include <sched.h> +#include <signal.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <time.h> +#include <unistd.h> + +#define LOOPS 50 +#define N (128 * 1024 / (int)sizeof(u_int32_t)) +#define PARALLEL 50 + +u_int32_t r[N]; +void *p; + +unsigned long +makearg(void) +{ + unsigned long val; + unsigned int i; + + val = arc4random(); + i = arc4random() % 100; + if (i < 20) + val = val & 0xff; + if (i >= 20 && i < 40) + val = val & 0xffff; + if (i >= 40 && i < 60) + val = (unsigned long)(r) | (val & 0xffff); +#if defined(__LP64__) + if (i >= 60) { + val = (val << 32) | arc4random(); + if (i > 80) + val = val & 0x00007fffffffffffUL; + } +#endif + + return(val); +} + +void * +makeptr(void) +{ + unsigned long val; + + if (p != MAP_FAILED && p != NULL) + val = (unsigned long)p + arc4random(); + else + val = makearg(); + val = trunc_page(val); + + return ((void *)val); +} + +void * +tmmap(void *arg __unused) +{ + size_t len; + int i, fd; + + pthread_set_name_np(pthread_self(), __func__); + len = 1LL * 1024 * 1024 * 1024; + + for (i = 0; i < 100; i++) { + if ((fd = open("/dev/zero", O_RDWR)) == -1) + err(1,"open()"); + + if ((p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_PRIVATE, + fd, 0)) != MAP_FAILED) { + usleep(100); + munmap(p, len); + } + + if ((p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_ANON, -1, + 0)) != MAP_FAILED) { + usleep(100); + munmap(p, len); + } + close(fd); + } + + return (NULL); +} + +void * +tmlock(void *arg __unused) +{ + int i, n; + size_t len; + + pthread_set_name_np(pthread_self(), __func__); + n = 0; + for (i = 0; i < 200; i++) { + len = trunc_page(makearg()); + if (mlock(makeptr(), len) == 0) + n++; + len = trunc_page(makearg()); + if (arc4random() % 100 < 50) + if (munlock(makeptr(), len) == 0) + n++; + } + if (n < 10) + fprintf(stderr, "Note: tmlock() only succeeded %d times.\n", + n); + + return (NULL); +} + +void * +tmprotect(void *arg __unused) +{ + const void *addr; + size_t len; + int i, n, prot; + + pthread_set_name_np(pthread_self(), __func__); + n = 0; + for (i = 0; i < 200; i++) { + addr = makeptr(); + len = trunc_page(makearg()); + prot = makearg(); + if (mprotect(addr, len, prot) == 0) + n++; + usleep(1000); + } + if (n < 10) + fprintf(stderr, "Note: tmprotect() only succeeded %d times.\n", + n); + + return (NULL); +} + +void * +tmlockall(void *arg __unused) +{ + int flags, i, n; + + pthread_set_name_np(pthread_self(), __func__); + n = 0; + for (i = 0; i < 200; i++) { + flags = makearg(); + if (mlockall(flags) == 0) + n++; + usleep(100); + munlockall(); + usleep(1000); + } + if (n < 10) + fprintf(stderr, "Note: tmlockall() only succeeded %d times.\n", + n); + + return (NULL); +} + +void +test(void) +{ + pthread_t tid[4]; + int i, rc; + + if ((rc = pthread_create(&tid[0], NULL, tmmap, NULL)) != 0) + errc(1, rc, "tmmap()"); + if ((rc = pthread_create(&tid[1], NULL, tmlock, NULL)) != 0) + errc(1, rc, "tmlock()"); + if ((rc = pthread_create(&tid[2], NULL, tmprotect, NULL)) != 0) + errc(1, rc, "tmprotect()"); + if ((rc = pthread_create(&tid[3], NULL, tmlockall, NULL)) != 0) + errc(1, rc, "tmlockall()"); + + for (i = 0; i < 100; i++) { + if (fork() == 0) { + usleep(10000); + _exit(0); + } + wait(NULL); + } + + for (i = 0; i < 4; i++) + if ((rc = pthread_join(tid[i], NULL)) != 0) + errc(1, rc, "pthread_join(%d)", i); + _exit(0); +} + +int +main(void) +{ + struct rlimit rl; + int i, j; + + rl.rlim_max = rl.rlim_cur = 0; + if (setrlimit(RLIMIT_CORE, &rl) == -1) + warn("setrlimit"); + + for (i = 0; i < N; i++) + r[i] = arc4random(); + + for (i = 0; i < LOOPS; i++) { + for (j = 0; j < PARALLEL; j++) { + if (fork() == 0) + test(); + } + + for (j = 0; j < PARALLEL; j++) + wait(NULL); + } + + return (0); +} Added: user/pho/stress2/misc/mmap20.sh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/pho/stress2/misc/mmap20.sh Wed Feb 18 13:07:26 2015 (r278955) @@ -0,0 +1,84 @@ +#!/bin/sh + +# +# Copyright (c) 2014 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$ +# + +# "panic: pmap_unwire: pte 0x672d405 is missing PG_W" seen. +# http://people.freebsd.org/~pho/stress/log/mmap20.txt + +# Test scenario by: Mark Johnston markj@ + +# Fixed by r272036 + *** DIFF OUTPUT TRUNCATED AT 1000 LINES ***
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201502181307.t1ID7R4l065368>