diff options
author | James Youngman <jay@gnu.org> | 2011-06-11 16:28:34 +0100 |
---|---|---|
committer | Jim Meyering <meyering@redhat.com> | 2011-06-13 12:39:22 +0200 |
commit | 5a3879ad03ff926e504b48694d8e589089154369 (patch) | |
tree | cda0d0b41e35264578a58d04cb01cd9d44c73a8b /src | |
parent | e4feb5c03bb4122344050efe75325d432db5791c (diff) | |
download | coreutils-5a3879ad03ff926e504b48694d8e589089154369.tar.xz |
maint: use stat-size module from gnulib
* gnulib: Update to latest.
* src/system.h: Definitions of ST_* macros have moved into the
gnulib module stat-size (specifically, the header file
stat-size.h), so remove them from here.
* src/truncate.c: Include stat-size.h.
* src/stat.c: Likewise.
* src/shred.c: Likewise.
* src/ls.c: Likewise.
* src/du.c: Likewise.
* src/ioblksize.h: New file. Move definition of io_blksize out of
system.h so that system.h does not have to include stat-size.h.
* src/cat.c: Include ioblksize.h.
* src/split.c: Likewise.
* src/copy.c: Include both stat-size.h and ioblksize.h.
* src/Makefile.am (noinst_HEADERS): Add ioblksize.h.
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/cat.c | 1 | ||||
-rw-r--r-- | src/copy.c | 2 | ||||
-rw-r--r-- | src/du.c | 1 | ||||
-rw-r--r-- | src/ioblksize.h | 66 | ||||
-rw-r--r-- | src/ls.c | 1 | ||||
-rw-r--r-- | src/shred.c | 1 | ||||
-rw-r--r-- | src/split.c | 1 | ||||
-rw-r--r-- | src/stat.c | 1 | ||||
-rw-r--r-- | src/system.h | 116 | ||||
-rw-r--r-- | src/truncate.c | 1 |
11 files changed, 76 insertions, 116 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 908cd332d..516e1e59e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -149,6 +149,7 @@ noinst_HEADERS = \ find-mount-point.h \ fs.h \ group-list.h \ + ioblksize.h \ ls.h \ operand2sig.h \ prog-fprintf.h \ @@ -33,6 +33,7 @@ #include <sys/ioctl.h> #include "system.h" +#include "ioblksize.h" #include "error.h" #include "fadvise.h" #include "full-write.h" diff --git a/src/copy.c b/src/copy.c index 801a47433..1025fe139 100644 --- a/src/copy.c +++ b/src/copy.c @@ -47,9 +47,11 @@ #include "hash.h" #include "hash-triple.h" #include "ignore-value.h" +#include "ioblksize.h" #include "quote.h" #include "same.h" #include "savedir.h" +#include "stat-size.h" #include "stat-time.h" #include "utimecmp.h" #include "utimens.h" @@ -37,6 +37,7 @@ #include "human.h" #include "quote.h" #include "quotearg.h" +#include "stat-size.h" #include "stat-time.h" #include "stdio--.h" #include "xfts.h" diff --git a/src/ioblksize.h b/src/ioblksize.h new file mode 100644 index 000000000..eaeced30b --- /dev/null +++ b/src/ioblksize.h @@ -0,0 +1,66 @@ +/* I/O block size definitions for coreutils + Copyright (C) 1989, 1991-2011 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +/* Include this file _after_ system headers if possible. */ + +/* sys/stat.h will already have been included by system.h. */ +#include "stat-size.h" + + +/* As of Mar 2009, 32KiB is determined to be the minimium + blksize to best minimize system call overhead. + This can be tested with this script with the results + shown for a 1.7GHz pentium-m with 2GB of 400MHz DDR2 RAM: + + for i in $(seq 0 10); do + size=$((8*1024**3)) #ensure this is big enough + bs=$((1024*2**$i)) + printf "%7s=" $bs + dd bs=$bs if=/dev/zero of=/dev/null count=$(($size/$bs)) 2>&1 | + sed -n 's/.* \([0-9.]* [GM]B\/s\)/\1/p' + done + + 1024=734 MB/s + 2048=1.3 GB/s + 4096=2.4 GB/s + 8192=3.5 GB/s + 16384=3.9 GB/s + 32768=5.2 GB/s + 65536=5.3 GB/s + 131072=5.5 GB/s + 262144=5.7 GB/s + 524288=5.7 GB/s + 1048576=5.8 GB/s + + Note that this is to minimize system call overhead. + Other values may be appropriate to minimize file system + or disk overhead. For example on my current GNU/Linux system + the readahead setting is 128KiB which was read using: + + file="." + device=$(df -P --local "$file" | tail -n1 | cut -d' ' -f1) + echo $(( $(blockdev --getra $device) * 512 )) + + However there isn't a portable way to get the above. + In the future we could use the above method if available + and default to io_blksize() if not. + */ +enum { IO_BUFSIZE = 32*1024 }; +static inline size_t +io_blksize (struct stat sb) +{ + return MAX (IO_BUFSIZE, ST_BLKSIZE (sb)); +} @@ -94,6 +94,7 @@ #include "obstack.h" #include "quote.h" #include "quotearg.h" +#include "stat-size.h" #include "stat-time.h" #include "strftime.h" #include "xstrtol.h" diff --git a/src/shred.c b/src/shred.c index ecb27b851..a2365b0fb 100644 --- a/src/shred.c +++ b/src/shred.c @@ -100,6 +100,7 @@ #include "quotearg.h" /* For quotearg_colon */ #include "randint.h" #include "randread.h" +#include "stat-size.h" /* Default number of times to overwrite. */ enum { DEFAULT_PASSES = 3 }; diff --git a/src/split.c b/src/split.c index 95a2cccac..2962b6891 100644 --- a/src/split.c +++ b/src/split.c @@ -35,6 +35,7 @@ #include "fcntl--.h" #include "full-read.h" #include "full-write.h" +#include "ioblksize.h" #include "quote.h" #include "safe-read.h" #include "sig2str.h" diff --git a/src/stat.c b/src/stat.c index 4e6e1c355..c479726da 100644 --- a/src/stat.c +++ b/src/stat.c @@ -67,6 +67,7 @@ #include "mountlist.h" #include "quote.h" #include "quotearg.h" +#include "stat-size.h" #include "stat-time.h" #include "strftime.h" #include "find-mount-point.h" diff --git a/src/system.h b/src/system.h index 47aad0222..95ef2c3b3 100644 --- a/src/system.h +++ b/src/system.h @@ -133,77 +133,6 @@ enum /* include here for SIZE_MAX. */ #include <inttypes.h> -/* Get or fake the disk device blocksize. - Usually defined by sys/param.h (if at all). */ -#if !defined DEV_BSIZE && defined BSIZE -# define DEV_BSIZE BSIZE -#endif -#if !defined DEV_BSIZE && defined BBSIZE /* SGI */ -# define DEV_BSIZE BBSIZE -#endif -#ifndef DEV_BSIZE -# define DEV_BSIZE 4096 -#endif - -/* Extract or fake data from a `struct stat'. - ST_BLKSIZE: Preferred I/O blocksize for the file, in bytes. - ST_NBLOCKS: Number of blocks in the file, including indirect blocks. - ST_NBLOCKSIZE: Size of blocks used when calculating ST_NBLOCKS. */ -#ifndef HAVE_STRUCT_STAT_ST_BLOCKS -# define ST_BLKSIZE(statbuf) DEV_BSIZE -# if defined _POSIX_SOURCE || !defined BSIZE /* fileblocks.c uses BSIZE. */ -# define ST_NBLOCKS(statbuf) \ - ((statbuf).st_size / ST_NBLOCKSIZE + ((statbuf).st_size % ST_NBLOCKSIZE != 0)) -# else /* !_POSIX_SOURCE && BSIZE */ -# define ST_NBLOCKS(statbuf) \ - (S_ISREG ((statbuf).st_mode) \ - || S_ISDIR ((statbuf).st_mode) \ - ? st_blocks ((statbuf).st_size) : 0) -# endif /* !_POSIX_SOURCE && BSIZE */ -#else /* HAVE_STRUCT_STAT_ST_BLOCKS */ -/* Some systems, like Sequents, return st_blksize of 0 on pipes. - Also, when running `rsh hpux11-system cat any-file', cat would - determine that the output stream had an st_blksize of 2147421096. - Conversely st_blksize can be 2 GiB (or maybe even larger) with XFS - on 64-bit hosts. Somewhat arbitrarily, limit the `optimal' block - size to SIZE_MAX / 8 + 1. (Dividing SIZE_MAX by only 4 wouldn't - suffice, since "cat" sometimes multiplies the result by 4.) If - anyone knows of a system for which this limit is too small, please - report it as a bug in this code. */ -# define ST_BLKSIZE(statbuf) ((0 < (statbuf).st_blksize \ - && (statbuf).st_blksize <= SIZE_MAX / 8 + 1) \ - ? (statbuf).st_blksize : DEV_BSIZE) -# if defined hpux || defined __hpux__ || defined __hpux -/* HP-UX counts st_blocks in 1024-byte units. - This loses when mixing HP-UX and BSD file systems with NFS. */ -# define ST_NBLOCKSIZE 1024 -# else /* !hpux */ -# if defined _AIX && defined _I386 -/* AIX PS/2 counts st_blocks in 4K units. */ -# define ST_NBLOCKSIZE (4 * 1024) -# else /* not AIX PS/2 */ -# if defined _CRAY -# define ST_NBLOCKS(statbuf) \ - (S_ISREG ((statbuf).st_mode) \ - || S_ISDIR ((statbuf).st_mode) \ - ? (statbuf).st_blocks * ST_BLKSIZE (statbuf) / ST_NBLOCKSIZE : 0) -# endif /* _CRAY */ -# endif /* not AIX PS/2 */ -# endif /* !hpux */ -#endif /* HAVE_STRUCT_STAT_ST_BLOCKS */ - -#ifndef ST_NBLOCKS -# define ST_NBLOCKS(statbuf) ((statbuf).st_blocks) -#endif - -#ifndef ST_NBLOCKSIZE -# ifdef S_BLKSIZE -# define ST_NBLOCKSIZE S_BLKSIZE -# else -# define ST_NBLOCKSIZE 512 -# endif -#endif - /* Redirection and wildcarding when done by the utility itself. Generally a noop, but used in particular for native VMS. */ #ifndef initialize_main @@ -629,51 +558,6 @@ bad_cast (char const *s) return (char *) s; } -/* As of Mar 2009, 32KiB is determined to be the minimium - blksize to best minimize system call overhead. - This can be tested with this script with the results - shown for a 1.7GHz pentium-m with 2GB of 400MHz DDR2 RAM: - - for i in $(seq 0 10); do - size=$((8*1024**3)) #ensure this is big enough - bs=$((1024*2**$i)) - printf "%7s=" $bs - dd bs=$bs if=/dev/zero of=/dev/null count=$(($size/$bs)) 2>&1 | - sed -n 's/.* \([0-9.]* [GM]B\/s\)/\1/p' - done - - 1024=734 MB/s - 2048=1.3 GB/s - 4096=2.4 GB/s - 8192=3.5 GB/s - 16384=3.9 GB/s - 32768=5.2 GB/s - 65536=5.3 GB/s - 131072=5.5 GB/s - 262144=5.7 GB/s - 524288=5.7 GB/s - 1048576=5.8 GB/s - - Note that this is to minimize system call overhead. - Other values may be appropriate to minimize file system - or disk overhead. For example on my current GNU/Linux system - the readahead setting is 128KiB which was read using: - - file="." - device=$(df -P --local "$file" | tail -n1 | cut -d' ' -f1) - echo $(( $(blockdev --getra $device) * 512 )) - - However there isn't a portable way to get the above. - In the future we could use the above method if available - and default to io_blksize() if not. - */ -enum { IO_BUFSIZE = 32*1024 }; -static inline size_t -io_blksize (struct stat sb) -{ - return MAX (IO_BUFSIZE, ST_BLKSIZE (sb)); -} - void usage (int status) ATTRIBUTE_NORETURN; #define emit_cycle_warning(file_name) \ diff --git a/src/truncate.c b/src/truncate.c index b6c776273..eaa1b74f0 100644 --- a/src/truncate.c +++ b/src/truncate.c @@ -28,6 +28,7 @@ #include "system.h" #include "error.h" #include "quote.h" +#include "stat-size.h" #include "xstrtol.h" /* The official name of this program (e.g., no `g' prefix). */ |