diff options
author | Darrick J. Wong <djwong@kernel.org> | 2023-01-17 16:44:02 -0800 |
---|---|---|
committer | Zorro Lang <zlang@kernel.org> | 2023-01-22 20:32:19 +0800 |
commit | 3ea9a3274403ad1cc07fde4d08bde9688b2875f1 (patch) | |
tree | c4011a5ebe241c434ffcafb5c42613c5f0aabde4 /src | |
parent | 116804dc92d234838d3ad06dc2e4f1769c0f4687 (diff) |
populate: remove file creation loops that take forever
Replace the file creation loops with a perl script that does everything
we want from a single process. This reduces the runtime of
_scratch_xfs_populate substantially by avoiding thousands of execve
overhead. On my system, this reduces the runtime of xfs/349 (with scrub
enabled) from ~140s to ~45s.
[zlang: add popdir.pl into src/Makefile install list]
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Zorro Lang <zlang@redhat.com>
Signed-off-by: Zorro Lang <zlang@kernel.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile | 2 | ||||
-rwxr-xr-x | src/popdir.pl | 72 |
2 files changed, 73 insertions, 1 deletions
diff --git a/src/Makefile b/src/Makefile index afdf6b30..fb7298f8 100644 --- a/src/Makefile +++ b/src/Makefile @@ -36,7 +36,7 @@ LINUX_TARGETS = xfsctl bstat t_mtab getdevicesize preallo_rw_pattern_reader \ uuid_ioctl EXTRA_EXECS = dmerror fill2attr fill2fs fill2fs_check scaleread.sh \ - btrfs_crc32c_forged_name.py + btrfs_crc32c_forged_name.py popdir.pl SUBDIRS = log-writes perf diff --git a/src/popdir.pl b/src/popdir.pl new file mode 100755 index 00000000..dc0c046b --- /dev/null +++ b/src/popdir.pl @@ -0,0 +1,72 @@ +#!/usr/bin/perl -w + +# Copyright (c) 2023 Oracle. All rights reserved. +# SPDX-License-Identifier: GPL-2.0 +# +# Create a bunch of files and subdirs in a directory. + +use Getopt::Long; +use File::Basename; + +$progname=$0; +GetOptions("start=i" => \$start, + "end=i" => \$end, + "file-mult=i" => \$file_mult, + "incr=i" => \$incr, + "format=s" => \$format, + "dir=s" => \$dir, + "remove!" => \$remove, + "help!" => \$help, + "verbose!" => \$verbose); + + +# check/remove output directory, get filesystem info +if (defined $help) { + # newline at end of die message suppresses line number + print STDERR <<"EOF"; +Usage: $progname [options] +Options: + --dir chdir here before starting + --start=num create names starting with this number (0) + --incr=num increment file number by this much (1) + --end=num stop at this file number (100) + --file-mult create a regular file when file number is a multiple + of this quantity (20) + --remove remove instead of creating + --format=str printf formatting string for file name ("%08d") + --verbose verbose output + --help this help screen +EOF + exit(1) unless defined $help; + # otherwise... + exit(0); +} + +if (defined $dir) { + chdir($dir) or die("chdir $dir"); +} +$start = 0 if (!defined $start); +$end = 100 if (!defined $end); +$file_mult = 20 if (!defined $file_mult); +$format = "%08d" if (!defined $format); +$incr = 1 if (!defined $incr); + +for ($i = $start; $i <= $end; $i += $incr) { + $fname = sprintf($format, $i); + + if ($remove) { + $verbose && print "rm $fname\n"; + unlink($fname) or rmdir($fname) or die("unlink $fname"); + } elsif ($file_mult == 0 or ($i % $file_mult) == 0) { + # create a file + $verbose && print "touch $fname\n"; + open(DONTCARE, ">$fname") or die("touch $fname"); + close(DONTCARE); + } else { + # create a subdir + $verbose && print "mkdir $fname\n"; + mkdir($fname, 0755) or die("mkdir $fname"); + } +} + +exit(0); |