summaryrefslogtreecommitdiff
path: root/src/wc.c
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2010-07-20 18:51:01 +0100
committerPádraig Brady <P@draigBrady.com>2010-07-22 01:04:47 +0100
commit47076e3c7c22fc7557f388ad3d47228b922da71e (patch)
tree94f785d628a11e6c786f5aa85daa88d2a672b2fe /src/wc.c
parent63b5e8164847285f5d3c1dbc9f7c41ad8c17ccc6 (diff)
downloadcoreutils-47076e3c7c22fc7557f388ad3d47228b922da71e.tar.xz
provide POSIX_FADV_SEQUENTIAL hint to appropriate utils
Following on from commit dae35bac, 01-03-2010, "sort: inform the system about our input access pattern" apply the same hint to all appropriate utils. This currently gives around a 5% speedup for reading large files from fast flash devices on GNU/Linux. * src/base64.c: Call fadvise (..., FADVISE_SEQUENTIAL); * src/cat.c: Likewise. * src/cksum.c: Likewise. * src/comm.c: Likewise. * src/cut.c: Likewise. * src/expand.c: Likewise. * src/fmt.c: Likewise. * src/fold.c: Likewise. * src/join.c: Likewise. * src/md5sum.c: Likewise. * src/nl.c: Likewise. * src/paste.c: Likewise. * src/pr.c: Likewise. * src/ptx.c: Likewise. * src/shuf.c: Likewise. * src/sum.c: Likewise. * src/tee.c: Likewise. * src/tr.c: Likewise. * src/tsort.c: Likewise. * src/unexpand.c: Likewise. * src/uniq.c: Likewise. * src/wc.c: Likewise, unless we don't actually read().
Diffstat (limited to 'src/wc.c')
-rw-r--r--src/wc.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/wc.c b/src/wc.c
index 6df7feddf..a1922baf9 100644
--- a/src/wc.c
+++ b/src/wc.c
@@ -29,6 +29,7 @@
#include "system.h"
#include "argv-iter.h"
#include "error.h"
+#include "fadvise.h"
#include "mbchar.h"
#include "physmem.h"
#include "quote.h"
@@ -211,6 +212,10 @@ wc (int fd, char const *file_x, struct fstatus *fstatus)
}
count_complicated = print_words || print_linelength;
+ /* Advise the kernel of our access pattern only if we will read(). */
+ if (!count_bytes || count_chars || print_lines || count_complicated)
+ fdadvise (fd, 0, 0, FADVISE_SEQUENTIAL);
+
/* When counting only bytes, save some line- and word-counting
overhead. If FD is a `regular' Unix file, using lseek is enough
to get its `size' in bytes. Otherwise, read blocks of BUFFER_SIZE
@@ -238,6 +243,7 @@ wc (int fd, char const *file_x, struct fstatus *fstatus)
}
else
{
+ fdadvise (fd, 0, 0, FADVISE_SEQUENTIAL);
while ((bytes_read = safe_read (fd, buf, BUFFER_SIZE)) > 0)
{
if (bytes_read == SAFE_READ_ERROR)