f2fs_io: measure readdir/stat performance
PATCH 1/1 f2fs_io: measure readdir/stat performance
- mkdir dir
- f2fs_io test_lookup_perf -i /mnt/f2fs/dir 50000
- sync
- echo 3 > /proc/sys/vm/drop_caches
- f2fs_io test_lookup_perf /mnt/f2fs/dir
Output:
Measure readdir performance
Measure stat performance
Operation: total_files, total_time_s, throughput_files_per_sec
readdir: 50000, 1.7781, 28120.08
stat: 50000, 2.1665, 23079.19
- f2fs_io test_lookup_perf -v /mnt/f2fs/dir 50000
Output:
inode file type d_reclen d_off d_name 6176 directory 24 1 . 3 directory 24 2 .. 6276 regular 32 4 test_file_0 6285 regular 32 6 test_file_1 6291 regular 32 8 test_file_2 6295 regular 32 10 test_file_3
....
Signed-off-by Chao Yu <[email protected]>
--- tools/f2fs_io/f2fs_io.c | 163 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 163 insertions(+)
tools/f2fs_io/f2fs_io.c +163 -0
@@ -36,6 +36,8 @@#include <time.h> #include <unistd.h> #include <sys/xattr.h> +#define _GNU_SOURCE +#include <dirent.h> #ifdef HAVE_CONFIG_H #include <config.h>
@@ -2237,6 +2239,166 @@ static void do_test_create_perf(int argc, char **argv, const struct cmd_desc *cmexit (0 ); } +#define test_lookup_perf_desc "measure readdir/stat speed" +#define test_lookup_perf_help \ +"f2fs_io test_lookup_perf [-s] [-S] <dir> <num_files>\n\n" \ +"Measures readdir/stat performance.\n" \ +" <dir> The target directory in where it will test on.\n" \ +" <num_files> The total number of files the test will initialize or test.\n"\ +" [-i] Initialized to create files only.\n"\ +" [-v] Verbose mode.\n" + +static void do_test_lookup_perf (int argc,char **argv,const struct cmd_desc *cmd) +{ +struct timespec readdir_start, readdir_end; +struct timespec stat_start, stat_end; +int opt; +char *dir; +int num_files; +bool need_initialize = false; +bool verb = false; +int i; +int fd; + +while ((opt =getopt (argc, argv,"iv" )) !=-1 ) { +switch (opt) { +case 'i' : + need_initialize = true; +break ; +case 'v' : + verb = true; +break ; +default : +fputs (cmd->cmd_help, stderr); +exit (1 ); + } + } + + argc -= optind; + argv += optind; + +if (argc !=2 ) { +fputs ("Excess arguments\n\n" , stderr); +fputs (cmd->cmd_help, stderr); +exit (1 ); + } + + dir = argv[0 ]; + num_files =atoi (argv[1 ]); + +if (num_files <=0 ) { +fprintf (stderr,"Error: Number of files must be positive.\n" ); +exit (1 ); + } + +if (need_initialize) { +// Initialization Phase +printf ("Starting test: Creating %d files in %s\n" , num_files, dir); + +for (i =0 ; i < num_files; i++) { +char path[1024 ]; + +snprintf (path,sizeof (path),"%s/test_file_%d" , dir, i); + + fd =xopen (path,O_WRONLY |O_CREAT ,0644 ); +if (fd <0 ) +exit (1 ); +close (fd); + } + +exit (0 ); + } + +// Measure readdir performance +printf ("Measure readdir performance\n" ); +clock_gettime (CLOCK_MONOTONIC , &readdir_start); + + fd =xopen (dir,O_DIRECTORY |O_RDONLY ,0644 ); +if (fd <0 ) +exit (1 ); + +if (verb) +printf ("inode file type d_reclen d_off d_name\n" ); + +while (1 ) { +char buf[1024 ]; +long nr, pos; + + nr =getdents64 (fd, buf,1024 ); +if (nr <0 ) { +printf ("getdents failed, errno:%d\n" , errno); +break ; + } +if (!nr) +break ; + +for (pos =0 ; pos < nr;) { +struct dirent *d; + + d = (struct dirent *)(buf + pos); + pos += d->d_reclen; + +if (!verb) +continue ; + +printf ("%-8lu %-10s %-9d %-8jd %s\n" , + d->d_ino, + (d->d_type ==DT_REG ) ?"regular" : + (d->d_type ==DT_DIR ) ?"directory" : + (d->d_type ==DT_FIFO ) ?"FIFO" : + (d->d_type ==DT_SOCK ) ?"socket" : + (d->d_type ==DT_LNK ) ?"symlink" : + (d->d_type ==DT_BLK ) ?"block dev" : + (d->d_type ==DT_CHR ) ?"char dev" :"unknown" , + d->d_reclen, d->d_off, d->d_name); + } + } + +close (fd); + +clock_gettime (CLOCK_MONOTONIC , &readdir_end); + +// Measure stat performance +printf ("Measure stat performance\n" ); + +clock_gettime (CLOCK_MONOTONIC , &stat_start); + +for (i =0 ; i < num_files; i++) { +char path[1024 ]; +struct stat st; + +snprintf (path,sizeof (path),"%s/test_file_%d" , dir, i); +if (stat (path, &st) !=0 ) +die_errno ("stat failed" ); + } + +clock_gettime (CLOCK_MONOTONIC , &stat_end); + +long readdir_seconds = readdir_end.tv_sec - readdir_start.tv_sec; +long readdir_ns = readdir_end.tv_nsec - readdir_start.tv_nsec; +double readdir_time_s = (double )readdir_seconds + (double )readdir_ns /1000000000.0 ; +double readdir_throughput = (readdir_time_s >0 ) ? (num_files / readdir_time_s) :0 ; + +long stat_seconds = stat_end.tv_sec - stat_start.tv_sec; +long stat_ns = stat_end.tv_nsec - stat_start.tv_nsec; +double stat_time_s = (double )stat_seconds + (double )stat_ns /1000000000.0 ; +double stat_throughput = (stat_time_s >0 ) ? (num_files / stat_time_s) :0 ; + +printf ("Operation: total_files, total_time_s, throughput_files_per_sec\n" ); + +printf ("readdir: %d, %.4f, %.2f\n" , + num_files, + readdir_time_s, + readdir_throughput); + +printf ("stat: %d, %.4f, %.2f\n" , + num_files, + stat_time_s, + stat_throughput); + +exit (0 ); +} +#define CMD_HIDDEN 0x0001#define CMD (name) { #name, do_##name, name##_desc, name##_help, 0 }#define _CMD (name) { #name, do_##name, NULL, NULL, CMD_HIDDEN }
@@ -2286,6 +2448,7 @@ const struct cmd_desc cmd_list[] = {CMD (ioprio),CMD (ftruncate),CMD (test_create_perf), +CMD (test_lookup_perf), { NULL, NULL, NULL, NULL, 0 } };
Signature · 8 lines
2.49.0 _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel