unstick r358161

Revision 358161

Date:
2020/02/20 08:58:09
Author:
pho
Revision Log:
Added a submitted test scenario.
Files:

Legend:

 
Added
 
Removed
 
Modified
  • user/pho/stress2/misc/collapse.sh

     
    1 #!/bin/sh
    2
    3 #
    4 # Copyright (c) 2020 Jeffrey Roberson <jeff@FreeBSD.org>
    5 # All rights reserved.
    6 #
    7 # Redistribution and use in source and binary forms, with or without
    8 # modification, are permitted provided that the following conditions
    9 # are met:
    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.
    15 #
    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
    26 # SUCH DAMAGE.
    27 #
    28 # $FreeBSD$
    29 #
    30
    31 . ../default.cfg
    32
    33 # "panic: freeing mapped page 0xfffffe000aa73910" seen:
    34 # https://people.freebsd.org/~pho/stress/log/collapse.txt
    35
    36 odir=`pwd`
    37 cd /tmp
    38 sed '1,/^EOF/d' < $odir/$0 > collapse.c
    39 mycc -o collapse -Wall -Wextra -g -O0 collapse.c || exit 1
    40 rm -f collapse.c
    41 cd $odir
    42
    43 daemon sh -c '(cd ../testcases/swap; ./swap -t 20m -i 16 -l 85)' > \
    44 /dev/null 2>&1
    45 sleep 2
    46 /tmp/collapse
    47 while pgrep -q swap; do
    48 pkill -9 swap
    49 done
    50 rm -f /tmp/collapse
    51 exit 0
    52
    53 EOF
    54 #include <sys/param.h>
    55 #include <sys/mman.h>
    56 #include <sys/wait.h>
    57
    58 #include <err.h>
    59 #include <errno.h>
    60 #include <fcntl.h>
    61 #include <stdio.h>
    62 #include <stdlib.h>
    63 #include <string.h>
    64 #include <time.h>
    65 #include <unistd.h>
    66
    67 #define ADRSPACE (256 * 1024)
    68 #define DEPTH 6
    69 #define WIDTH 3
    70 #define PARALLEL 4
    71 #define RUNTIME 1200
    72 #define CHILDTIME 5
    73 #define STARTTIME 5
    74 #define TOUCH 16
    75
    76 char *p;
    77
    78 static void
    79 child(int depth, time_t start)
    80 {
    81 time_t run, delay;
    82 int i, shared, off;
    83 int len;
    84
    85 /* Pick a random bit of address space to change inherit on. */
    86 for (i = 0; i < ADRSPACE; i += len) {
    87 shared = arc4random() & 0x1;
    88 len = roundup2(arc4random() % ((ADRSPACE - i) / 4),
    89 PAGE_SIZE);
    90 if (minherit(p + i, len, shared ? INHERIT_SHARE :
    91 INHERIT_COPY) != 0)
    92 err(1, "minherit");
    93 }
    94
    95 for (i = 0; depth != 0 && i < WIDTH; i++)
    96 if (fork() == 0)
    97 child(depth - 1, start);
    98
    99 /*
    100 * Touch all of the memory and exit at a random time to collapse
    101 * some portion of the chain.
    102 */
    103 delay = arc4random() % (CHILDTIME - 1);
    104 run = arc4random() % (CHILDTIME - delay);
    105 for (;;) {
    106 if (time(NULL) >= start + delay)
    107 break;
    108 usleep(100);
    109 }
    110 while (time(NULL) - start < run) {
    111 off = rounddown2(arc4random() % ADRSPACE, PAGE_SIZE);
    112 bzero(p + off, PAGE_SIZE);
    113 usleep((run * 1000) / TOUCH);
    114 }
    115
    116 _exit(0);
    117 }
    118
    119 static void
    120 work(int depth)
    121 {
    122
    123 if ((p = mmap(NULL, ADRSPACE, PROT_READ | PROT_WRITE,
    124 MAP_SHARED | MAP_ANON, -1, 0)) == MAP_FAILED) {
    125 if (errno == ENOMEM)
    126 return;
    127 err(1, "mmap()");
    128 }
    129 child(depth, time(NULL) + STARTTIME);
    130 }
    131
    132 int
    133 main(void)
    134 {
    135 pid_t pids[PARALLEL];
    136 time_t start;
    137 int i, n;
    138
    139 start = time(NULL);
    140 while (time(NULL) - start < RUNTIME) {
    141 n = arc4random() % PARALLEL + 1;
    142 for (i = 0; i < n; i++) {
    143 if ((pids[i] = fork()) == 0)
    144 work(DEPTH);
    145 }
    146
    147 sleep(CHILDTIME + STARTTIME + 1);
    148
    149 for (i = 0; i < n; i++)
    150 if (waitpid(pids[i], NULL, 0) != pids[i])
    151 err(1, "waitpid(%d)", pids[i]);
    152 }
    153
    154 return (0);
    155 }