From 64c8db3cdead7d0e9a28168c80a3c53e13459221 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 1 Nov 2021 10:46:32 +0100 Subject: [PATCH] hardlink: rename --buffer-size to --io-size Addresses: https://github.com/karelzak/util-linux/pull/1467 Signed-off-by: Karel Zak --- misc-utils/hardlink.1.adoc | 13 +++++++------ misc-utils/hardlink.c | 31 +++++++++++++++++-------------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/misc-utils/hardlink.1.adoc b/misc-utils/hardlink.1.adoc index cf7ce72bd5..bdd83d0978 100644 --- a/misc-utils/hardlink.1.adoc +++ b/misc-utils/hardlink.1.adoc @@ -78,12 +78,13 @@ A regular expression to include files. If the option *--exclude* has been given, *-s*, *--minimum-size* _size_:: The minimum size to consider. By default this is 1, so empty files will not be linked. The _size_ argument may be followed by the multiplicative suffixes KiB (=1024), MiB (=1024*1024), and so on for GiB, TiB, PiB, EiB, ZiB and YiB (the "iB" is optional, e.g., "K" has the same meaning as "KiB"). -*-S*, *--buffer-size* _size_:: -The size of read buffer used when comparing file contents (default: 8KiB). This -costs some additional memory but potentially reduces the amount of seek -operations and therefore improve performance, especially with mechanic disk -drives. Optional factor suffixes are supported, like with the *-s* option. This is mostly efficient with other filters (i.e. with *-f* or *-X*) and can be less efficient with *-top* options. - +*-b*, *--io-size* _size_:: +The size of read or sendfile buffer used when comparing file contents. The +_size_ argument may be followed by the multiplicative suffixes KiB, MiB, etc. +The "iB" is optional, e.g., "K" has the same meaning as "KiB". The default is +8KiB for memcmp method and 1MiB for the other methods. The only memcmp method +uses process memory for the buffer, other methods use zero-copy way and I/O +operation is done in kernel. == ARGUMENTS diff --git a/misc-utils/hardlink.c b/misc-utils/hardlink.c index d00d1db7ce..035e3f43ec 100644 --- a/misc-utils/hardlink.c +++ b/misc-utils/hardlink.c @@ -96,10 +96,6 @@ enum log_level { JLOG_VERBOSE2 }; -#ifndef DEF_SCAN_BUFSIZ -# define DEF_SCAN_BUFSIZ 8192 -#endif - /** * struct statistic - Statistics about the file * @started: Whether we are post command-line processing @@ -159,7 +155,7 @@ static struct options { unsigned int keep_oldest:1; unsigned int dry_run:1; uintmax_t min_size; - size_t bufsiz; + size_t io_size; } opts = { /* default setting */ .method = "sha256", @@ -168,8 +164,7 @@ static struct options { .respect_time = TRUE, .respect_xattrs = FALSE, .keep_oldest = FALSE, - .min_size = 1, - .bufsiz = DEF_SCAN_BUFSIZ + .min_size = 1 }; /* @@ -830,8 +825,8 @@ static void visitor(const void *nodep, const VISIT which, const int depth) if (!nnodes) continue; memsiz = (10*1024*1024)/nnodes; - /* filesiz, readsiz, memsiz */ - ul_fileeq_set_size(&fileeq, master->st.st_size, 1024*1024, memsiz); + /* filesiz, readsiz, memsiz */ + ul_fileeq_set_size(&fileeq, master->st.st_size, opts.io_size, memsiz); for (other = master->next; other != NULL; other = other->next) { int eq; @@ -916,7 +911,7 @@ static void __attribute__((__noreturn__)) usage(void) fputs(_(" -x, --exclude regular expression to exclude files\n"), out); fputs(_(" -i, --include regular expression to include files/dirs\n"), out); fputs(_(" -s, --minimum-size minimum size for files.\n"), out); - fputs(_(" -S, --buffer-size buffer size for file reading (speedup, using more RAM)\n"), out); + fputs(_(" -b, --io-size I/O buffer size for file reading (speedup, using more RAM)\n"), out); fputs(_(" -c, --content compare only file contents, same as -pot\n"), out); fputs(USAGE_SEPARATOR, out); @@ -933,7 +928,7 @@ static void __attribute__((__noreturn__)) usage(void) */ static int parse_options(int argc, char *argv[]) { - static const char optstr[] = "VhvnfpotXcmMOx:y:i:s:S:q"; + static const char optstr[] = "VhvnfpotXcmMOx:y:i:s:b:q"; static const struct option long_options[] = { {"version", no_argument, NULL, 'V'}, {"help", no_argument, NULL, 'h'}, @@ -951,7 +946,7 @@ static int parse_options(int argc, char *argv[]) {"include", required_argument, NULL, 'i'}, {"method", required_argument, NULL, 'y' }, {"minimum-size", required_argument, NULL, 's'}, - {"buffer-size", required_argument, NULL, 'S'}, + {"io-size", required_argument, NULL, 'b'}, {"content", no_argument, NULL, 'c'}, {"quiet", no_argument, NULL, 'q'}, {NULL, 0, NULL, 0} @@ -1020,8 +1015,8 @@ static int parse_options(int argc, char *argv[]) case 's': opts.min_size = strtosize_or_err(optarg, _("failed to parse size")); break; - case 'S': - opts.bufsiz = strtosize_or_err(optarg, _("failed to parse size")); + case 'b': + opts.io_size = strtosize_or_err(optarg, _("failed to parse I/O size")); break; case 'h': usage(); @@ -1090,6 +1085,14 @@ int main(int argc, char *argv[]) if (rc < 0) err(EXIT_FAILURE, _("failed to initialize files comparior")); + /* defautl I/O size */ + if (!opts.io_size) { + if (strcmp(opts.method, "memcmp") == 0) + opts.io_size = 8*1024; + else + opts.io_size = 1024*1024; + } + stats.started = TRUE; jlog(JLOG_VERBOSE2, _("Scanning [device/inode/links]:")); -- 2.47.3