From 28673c9220debee363a21cc7ecbcb87e2eaa49da Mon Sep 17 00:00:00 2001 From: "Suren A. Chilingaryan" Date: Sun, 15 Apr 2012 16:32:49 +0200 Subject: fsbench --- .bzrignore | 1 + fsbench.sh | 161 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ fwbench.sh | 2 - seqreader.c | 64 ++++++++++++++++++++---- 4 files changed, 216 insertions(+), 12 deletions(-) create mode 100755 fsbench.sh diff --git a/.bzrignore b/.bzrignore index b3ab8b2..f0d8bc2 100644 --- a/.bzrignore +++ b/.bzrignore @@ -4,3 +4,4 @@ Makefile config.h cmake_install.cmake fwbench +seqreader diff --git a/fsbench.sh b/fsbench.sh new file mode 100755 index 0000000..a76126b --- /dev/null +++ b/fsbench.sh @@ -0,0 +1,161 @@ +#! /bin/bash + +DEVICE="/dev/md1" +WIDTH=32 +CHUNK=64 +FILE_SIZE=128 #1024 +FAST_SPEED=3650 +NUMA_CPU=4 +PYHST="/root/pyhst/pyhst.sh" +PYHST_DATA="/home/csa/data/bench" + +FS_LIST="ext4 xfs ext2 jfs reiserfs btrfs" + + + +END_START=`expr $WIDTH '*' 2 - 2` +END_END=`expr $WIDTH '*' 2` + +echo $DEVICE | grep "/dev/md" &> /dev/null +if [ $? -eq 0 ]; then SUFFIX="p"; else SUFFIX=""; fi + + +umount -l /mnt/slow &> /dev/null +umount -l /mnt/fast &> /dev/null + +function partition { + parted $DEVICE --script mklabel gpt + parted $DEVICE --script rm 3 &> /dev/null + parted $DEVICE --script rm 2 &> /dev/null + parted $DEVICE --script rm 1 &> /dev/null + parted $DEVICE --script mkpart primary 1GB 2TB + parted $DEVICE --script mkpart primary ${END_START}TB ${END_END}TB + parted $DEVICE --script mkpart primary 2TB 3TB +} + +function format_ext4 { + block=4 # in KB (4096) + stride=`expr $CHUNK / $block` + swidth=`expr $stride '*' $WIDTH` + mkfs.ext4 -b 4096 -E stride=${stride},stripe-width=${swidth} $1 > /dev/null + return 0 +} + +function format_ext2 { + block=4 # in KB (4096) + stride=`expr $CHUNK / $block` + swidth=`expr $stride '*' $WIDTH` + mkfs.ext2 -b 4096 -E stride=${stride},stripe-width=${swidth} $1 > /dev/null + return 0 +} + +function format_xfs { + mkfs.xfs -f -d su=${CHUNK}k,sw=${WIDTH} $1 > /dev/null + mount -o noatime,allocsize=1GiB,largeio,swalloc $1 $2 + return 1 +} + +function format_xfsrt { + mkfs.xfs -f -d su=${CHUNK}k,sw=${WIDTH} -r rtdev=$1,extsize=1g ${DEVICE}${SUFFIX}3 > /dev/null + mount -o noatime,allocsize=1GiB,largeio,swalloc,rtdev=$1 ${DEVICE}${SUFFIX}3 $2 + return 1 +} + +function format_btrfs { + sector=`expr $CHUNK '*' 1024` +# mkfs.btrfs -s $sector -l $sector -n $sector $1 > /dev/null + mkfs.btrfs $1 > /dev/null + return 0 +} + +function format_jfs { + mkfs.jfs -q $1 > /dev/null + return 0 +} + +function format_reiserfs { + mkfs.reiserfs -q $1 > /dev/null + return 0 +} + +function bench_path { + speed=$2 + res=`stdbuf -oL -eL ./fwbench.sh $1/testfile ${FILE_SIZE} $speed |tee /dev/stderr | tail -n 7 | sed -e ':a;N;$!ba;s/\n/@eol@/g'` + echo $res | sed -e 's/@eol@/\n/g' + res=`echo $res | sed -e 's/@eol@/\n/g' | tail -n 1 | cut -d ':' -f 2` + if [ $res -gt 0 ]; then + speed=$res + fi + stdbuf -oL -eL taskset -c $NUMA_CPU ./seqreader $1 | tee /dev/stderr | tail -n 5 +} + +function bench_device { + speed=$2 + res=`stdbuf -oL -eL ./fwbench.sh $1 ${FILE_SIZE} $speed |tee /dev/stderr | tail -n 7 | sed -e ':a;N;$!ba;s/\n/@eol@/g'` + echo $res | sed -e 's/@eol@/\n/g' + res=`echo $res | sed -e 's/@eol@/\n/g' | tail -n 1 | cut -d ':' -f 2` + if [ $res -gt 0 ]; then + speed=$res + fi + stdbuf -oL -eL taskset -c $NUMA_CPU ./seqreader $1 ${FILE_SIZE} | tee /dev/stderr | tail -n 5 +} + + +function bench_pyhst { + data=$1/pyhst + mkdir -p $data + cat $PYHST_DATA/*.par | sed -e "s|@PATH@|$data|g" > $data/bench.par + cp -r $PYHST_DATA/out_phase $data/ + echo 3 > /proc/sys/vm/drop_caches + eval stdbuf -oL -eL $PYHST $data/bench.par 2>&1 | tee /dev/stderr | grep "Input/Output" +} + +function test_fs { + speed=`expr $FAST_SPEED + 50` + formater="format_$1" + eval $formater ${DEVICE}${SUFFIX}1 /mnt/fast + if [ $? -eq 0 ]; then + mount -o noatime ${DEVICE}${SUFFIX}1 /mnt/fast + fi + echo "Testing $1 (fast partition)" + echo "==================================" + bench_path /mnt/fast $speed + + echo + echo "Testing $1 (PyHST)" + echo "==================================" + bench_pyhst /mnt/fast + + umount /mnt/fast + + echo + + eval $formater ${DEVICE}${SUFFIX}2 /mnt/slow + if [ $? -eq 0 ]; then + mount -o noatime ${DEVICE}${SUFFIX}2 /mnt/slow + fi + echo "Testing $1 (slow partition)" + echo "==================================" + bench_path /mnt/slow $speed + umount /mnt/slow + + echo + echo +} + +function test_partition { + speed=`expr $FAST_SPEED + 50` + echo "Testing partition: $1" + echo "==================================" + bench_device $1 $speed + echo +} + +partition +test_partition ${DEVICE} +test_partition ${DEVICE}${SUFFIX}2 + +for fs in $FS_LIST; do + test_fs $fs +done + diff --git a/fwbench.sh b/fwbench.sh index f653bb2..c5b4e49 100755 --- a/fwbench.sh +++ b/fwbench.sh @@ -40,5 +40,3 @@ while [ $res -ne 0 ]; do done echo "Maximal speed: $speed" -echo - diff --git a/seqreader.c b/seqreader.c index f2128e2..359f38e 100644 --- a/seqreader.c +++ b/seqreader.c @@ -13,8 +13,13 @@ #define FASTWRITER_SYNCIO_ALIGN 512 +#define SYNC_MODE #define BUFSIZE 2097152 -#define BLOCK_SIZE 2097152 +#ifdef SYNC_MODE +# define BLOCK_SIZE 2097152 +#else /* SYNC_MODE */ +# define BLOCK_SIZE 16384 +#endif /* SYNC_MODE */ #define WRITE_INTERVAL 1 @@ -31,18 +36,29 @@ int main(int argc, char *argv[]) { size_t skip; size_t run; ssize_t res; + size_t max_size = (size_t)-1; char *buffer;//[BUFSIZE]; long double mcoef = 1000000. / (1024 * 1024); + int flags = O_RDONLY|O_NOATIME|O_LARGEFILE; + +#ifdef SYNC_MODE + flags |= O_DIRECT; +#endif posix_memalign((void**)&buffer, FASTWRITER_SYNCIO_ALIGN, BUFSIZE); if (argc < 2) { - printf("Usage: %s [skip]\n", argv[0]); + printf("Usage: %s [skip|size]\n", argv[0]); exit(0); } if (strstr(argv[1], "/dev/")) { - int fd = open(argv[1], O_RDONLY|O_NOATIME|O_LARGEFILE|O_DIRECT, 0); + if (argc > 2) { + max_size = atol(argv[2]); + max_size *= 1024 * 1024 * 1024; + } + + int fd = open(argv[1], flags, 0); if (fd < 0) { printf("Unable to open device %s\n", argv[1]); exit(1); @@ -66,6 +82,12 @@ int main(int argc, char *argv[]) { last_write = us; printf("Reading: %s (%lu GB), Measured speed: %zu MB/s\n", argv[0], total_size / 1024 / 1024 / 1024, (size_t)(mcoef * total_size / us)); } + + if (total_size > max_size) { + printf("Reading: %s (%lu GB), Measured speed: %zu MB/s\n", argv[0], total_size / 1024 / 1024 / 1024, (size_t)(mcoef * total_size / us)); + break; + } + res = read(fd, buffer, size); } @@ -100,9 +122,14 @@ int main(int argc, char *argv[]) { if (stat(ent->d_name, &st)) continue; if (!S_ISREG(st.st_mode)) continue; - + +#ifdef F_MODE FILE *f = fopen(ent->d_name, "r"); if (!f) continue; +#else + int fd = open(ent->d_name, flags, 0); + if (fd < 0) continue; +#endif int size = st.st_blksize; @@ -110,16 +137,33 @@ int main(int argc, char *argv[]) { printf("Buffer too small\n"); exit(1); } - + + +#ifdef F_MODE while (!feof(f)) { err = fread(buffer, 1, size, f); - if (err < 0) { - printf("Read failed\n"); - exit(1); - } + if (err < 0) break; } - +#else +# ifdef SYNC_MODE + if (size < BLOCK_SIZE) size = BLOCK_SIZE; +# endif + err = read(fd, buffer, size); + while (err > 0) { + err = read(fd, buffer, size); + } +#endif + + if (err < 0) { + printf("Read failed\n"); + exit(1); + } + +#ifdef F_MODE fclose(f); +#else + close(fd); +#endif total_size += st.st_size; files++; -- cgit v1.2.3