--- /dev/null
+/* 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));
+}
/* 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
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) \