1#!/bin/sh 2 3# 4# SPDX-License-Identifier: BSD-2-Clause 5# 6# Copyright (c) 2021 Peter Holm <pho@FreeBSD.org> 7# 8# Redistribution and use in source and binary forms, with or without 9# modification, are permitted provided that the following conditions 10# are met: 11# 1. Redistributions of source code must retain the above copyright 12# notice, this list of conditions and the following disclaimer. 13# 2. Redistributions in binary form must reproduce the above copyright 14# notice, this list of conditions and the following disclaimer in the 15# documentation and/or other materials provided with the distribution. 16# 17# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27# SUCH DAMAGE. 28# 29 30# O_CREAT / unlink() timing test with different FFS options. 31 32[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 33[ `uname -m` = "i386" ] && exit 0 # very long runtime 34 35. ../default.cfg 36[ $# -eq 0 ] && half=1 # SU and SUJ workaround 37first=1 38export LANG=en_US.ISO8859-1 39odir=`pwd` 40dir=$mntpoint 41 42cd /tmp 43sed '1,/^EOF/d' < $odir/$0 > perf.c 44mycc -o perf -Wall -Wextra perf.c || exit 1 45rm -f perf.c 46cd $odir 47 48mount | grep -q "on $mntpoint " && umount $mntpoint 49mdconfig -l | grep md$mdstart > /dev/null && mdconfig -d -u $mdstart 50 51mdconfig -a -t swap -s 2g -u $mdstart 52 53tst() { 54 local i j k s 55 56 s=0 57 cd $dir 58 inodes=`df -ik $mntpoint | tail -1 | \ 59 awk '{printf "%d\n", $7}'` 60# SU and SUJ tests fail with ENOSPC 61 [ $half ] && 62 i=$((inodes / 4)) || 63 i=$(((inodes - 500) / 2)) 64 [ $first -eq 1 ] && 65 printf "Using %'\''d inodes out of a total of %'\''d.\n" \ 66 $((i * 2)) $inodes 67 first=0 68 69 for k in `jot 3`; do 70 pids="" 71 for j in `jot 2`; do 72 /tmp/perf $i & 73 pids="$pids $!" 74 done 75 for pid in $pids; do 76 wait $pid; r=$? 77 [ $r -ne 0 ] && s=$r 78 done 79 done 80 cd $odir 81 return $s 82} 83 84s=0 85for i in "" "-U" "-j"; do 86 newfs $i /dev/md$mdstart > /dev/null 2>&1 87 [ "$i" = "" ] && tunefs -n disable md$mdstart 88 mount /dev/md$mdstart $mntpoint 89 90 t1=`date +%s` 91 tst; r=$? 92 t2=$((`date +%s` - t1)) 93 94 umount -f $mntpoint 95 t2=$((`date +%s` - t1)) 96 [ $t2 -eq 0 ] && t2=1 97 [ -z "$base" ] && base=$t2 98 pct=$(((t2 - base) * 100 / base)) 99 printf '%3d seconds elapsed for newfs option "%2s" (%+4d%%)\n' \ 100 $t2 "$i" $pct 101 [ $pct -gt 10 ] && s=111 102 [ $s -eq 0 -a $r -ne 0 ] && s=$r 103done 104rm -f /tmp/perf 105mdconfig -d -u $mdstart 106exit $s 107EOF 108#include <sys/types.h> 109#include <sys/stat.h> 110#include <err.h> 111#include <errno.h> 112#include <fcntl.h> 113#include <stdio.h> 114#include <stdlib.h> 115#include <unistd.h> 116 117int 118main(int argc __unused, char **argv) 119{ 120 pid_t pid; 121 int64_t size; 122 int e, fd, i, j; 123 char file[128]; 124 125 size = atol(argv[1]); 126 127 e = 0; 128 pid = getpid(); 129 for (j = 0; j < size; j++) { 130 sprintf(file,"p%05d.%05d", pid, j); 131 if ((fd = open(file, O_RDWR | O_CREAT | O_TRUNC, 132 DEFFILEMODE)) == -1) { 133 e = errno; 134 if (errno != EINTR) { 135 warn("open(%s)", file); 136 printf("break out at %d, errno %d\n", j, 137 errno); 138 break; 139 } 140 } 141 close(fd); 142 } 143 144 for (i = --j; i >= 0; i--) { 145 sprintf(file,"p%05d.%05d", pid, i); 146 if (unlink(file) == -1) 147 err(3, "unlink(%s)", file); 148 149 } 150 151 return (e); 152} 153