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().
#include "system.h"
#include "error.h"
+#include "fadvise.h"
#include "xstrtol.h"
#include "quote.h"
#include "quotearg.h"
error (EXIT_FAILURE, errno, "%s", infile);
}
+ fadvise (input_fh, FADVISE_SEQUENTIAL);
+
if (decode)
do_decode (input_fh, stdout, ignore_garbage);
else
#include "system.h"
#include "error.h"
+#include "fadvise.h"
#include "full-write.h"
#include "quote.h"
#include "safe-read.h"
}
insize = io_blksize (stat_buf);
+ fdadvise (input_desc, 0, 0, FADVISE_SEQUENTIAL);
+
/* Compare the device and i-node numbers of this input file with
the corresponding values of the (output file associated with)
stdout, and skip this input file if they coincide. Input
#include <sys/types.h>
#include <stdint.h>
#include "system.h"
+#include "fadvise.h"
#include "xfreopen.h"
#ifdef CRCTAB
}
}
+ fadvise (fp, FADVISE_SEQUENTIAL);
+
while ((bytes_read = fread (buf, 1, BUFLEN, fp)) > 0)
{
unsigned char *cp = buf;
#include "system.h"
#include "linebuffer.h"
#include "error.h"
+#include "fadvise.h"
#include "hard-locale.h"
#include "quote.h"
#include "stdio--.h"
if (!streams[i])
error (EXIT_FAILURE, errno, "%s", infiles[i]);
+ fadvise (streams[i], FADVISE_SEQUENTIAL);
+
thisline[i] = readlinebuffer (all_line[i][alt[i][0]], streams[i]);
if (ferror (streams[i]))
error (EXIT_FAILURE, errno, "%s", infiles[i]);
#include "system.h"
#include "error.h"
+#include "fadvise.h"
#include "getndelim2.h"
#include "hash.h"
#include "quote.h"
}
}
+ fadvise (stream, FADVISE_SEQUENTIAL);
+
cut_stream (stream);
if (ferror (stream))
#include <sys/types.h>
#include "system.h"
#include "error.h"
+#include "fadvise.h"
#include "quote.h"
#include "xstrndup.h"
if (STREQ (file, "-"))
{
have_read_stdin = true;
- prev_file = file;
- return stdin;
+ fp = stdin;
}
- fp = fopen (file, "r");
+ else
+ fp = fopen (file, "r");
if (fp)
{
prev_file = file;
+ fadvise (fp, FADVISE_SEQUENTIAL);
return fp;
}
error (0, errno, "%s", file);
#include "system.h"
#include "error.h"
+#include "fadvise.h"
#include "quote.h"
#include "xstrtol.h"
static void
fmt (FILE *f)
{
+ fadvise (f, FADVISE_SEQUENTIAL);
tabs = false;
other_indent = 0;
next_char = get_prefix (f);
#include "system.h"
#include "error.h"
+#include "fadvise.h"
#include "quote.h"
#include "xstrtol.h"
return false;
}
+ fadvise (stdin, FADVISE_SEQUENTIAL);
+
while ((c = getc (istream)) != EOF)
{
if (offset_out + 1 >= allocated_out)
#include "system.h"
#include "error.h"
+#include "fadvise.h"
#include "hard-locale.h"
#include "linebuffer.h"
#include "memcasecmp.h"
int diff;
bool eof1, eof2;
+ fadvise (fp1, FADVISE_SEQUENTIAL);
+ fadvise (fp2, FADVISE_SEQUENTIAL);
+
/* Read the first line of each file. */
initseq (&seq1);
getseq (fp1, &seq1, 1);
# include "sha512.h"
#endif
#include "error.h"
+#include "fadvise.h"
#include "stdio--.h"
#include "xfreopen.h"
}
}
+ fadvise (fp, FADVISE_SEQUENTIAL);
+
err = DIGEST_STREAM (fp, bin_result);
if (err)
{
#include <regex.h>
#include "error.h"
+#include "fadvise.h"
#include "linebuffer.h"
#include "quote.h"
#include "xstrtol.h"
}
}
+ fadvise (stream, FADVISE_SEQUENTIAL);
+
process_file (stream);
if (ferror (stream))
#include <sys/types.h>
#include "system.h"
#include "error.h"
+#include "fadvise.h"
#include "quotearg.h"
/* The official name of this program (e.g., no `g' prefix). */
error (EXIT_FAILURE, errno, "%s", fnamptr[files_open]);
else if (fileno (fileptr[files_open]) == STDIN_FILENO)
opened_stdin = true;
+ fadvise (fileptr[files_open], FADVISE_SEQUENTIAL);
}
}
ok = false;
continue;
}
+ fadvise (fileptr, FADVISE_SEQUENTIAL);
}
delimptr = delims; /* Set up for delimiter string. */
#include <sys/types.h>
#include "system.h"
#include "error.h"
+#include "fadvise.h"
#include "hard-locale.h"
#include "mbswidth.h"
#include "quote.h"
error (0, errno, "%s", name);
return false;
}
+ fadvise (p->fp, FADVISE_SEQUENTIAL);
p->status = OPEN;
p->full_page_printed = false;
++total_files;
#include "argmatch.h"
#include "diacrit.h"
#include "error.h"
+#include "fadvise.h"
#include "quote.h"
#include "quotearg.h"
#include "regex.h"
{
size_t in_memory_size;
+ fdadvise (file_handle, 0, 0, FADVISE_SEQUENTIAL);
+
block->start = xmalloc ((size_t) stat_block.st_size);
if ((in_memory_size = read (file_handle,
#include "system.h"
#include "error.h"
+#include "fadvise.h"
#include "getopt.h"
#include "quote.h"
#include "quotearg.h"
usage (EXIT_FAILURE);
}
+ fadvise (stdin, FADVISE_SEQUENTIAL);
+
n_lines = read_input (stdin, eolbyte, &input_lines);
line = input_lines;
}
#include <getopt.h>
#include "system.h"
#include "error.h"
+#include "fadvise.h"
#include "human.h"
#include "safe-read.h"
#include "xfreopen.h"
}
}
+ fadvise (fp, FADVISE_SEQUENTIAL);
+
while ((ch = getc (fp)) != EOF)
{
total_bytes++;
#include "system.h"
#include "error.h"
+#include "fadvise.h"
#include "stdio--.h"
#include "xfreopen.h"
if (O_BINARY && ! isatty (STDOUT_FILENO))
xfreopen (NULL, "wb", stdout);
+ fadvise (stdin, FADVISE_SEQUENTIAL);
+
/* In the array of NFILES + 1 descriptors, make
the first one correspond to standard output. */
descriptors[0] = stdout;
#include "system.h"
#include "error.h"
+#include "fadvise.h"
#include "quote.h"
#include "safe-read.h"
#include "xfreopen.h"
if (O_BINARY && ! isatty (STDOUT_FILENO))
xfreopen (NULL, "wb", stdout);
+ fadvise (stdin, FADVISE_SEQUENTIAL);
+
if (squeeze_repeats && non_option_args == 1)
{
set_initialize (s1, complement, in_squeeze_set);
#include "system.h"
#include "long-options.h"
#include "error.h"
+#include "fadvise.h"
#include "quote.h"
#include "readtokens.h"
#include "stdio--.h"
if (!is_stdin && ! freopen (file, "r", stdin))
error (EXIT_FAILURE, errno, "%s", file);
+ fadvise (stdin, FADVISE_SEQUENTIAL);
+
init_tokenbuffer (&tokenbuffer);
while (1)
#include <sys/types.h>
#include "system.h"
#include "error.h"
+#include "fadvise.h"
#include "quote.h"
#include "xstrndup.h"
if (STREQ (file, "-"))
{
have_read_stdin = true;
- prev_file = file;
- return stdin;
+ fp = stdin;
}
- fp = fopen (file, "r");
+ else
+ fp = fopen (file, "r");
if (fp)
{
prev_file = file;
+ fadvise (fp, FADVISE_SEQUENTIAL);
return fp;
}
error (0, errno, "%s", file);
#include "argmatch.h"
#include "linebuffer.h"
#include "error.h"
+#include "fadvise.h"
#include "hard-locale.h"
#include "posixver.h"
#include "quote.h"
if (! (STREQ (outfile, "-") || freopen (outfile, "w", stdout)))
error (EXIT_FAILURE, errno, "%s", outfile);
+ fadvise (stdin, FADVISE_SEQUENTIAL);
+
thisline = &lb1;
prevline = &lb2;
#include "system.h"
#include "argv-iter.h"
#include "error.h"
+#include "fadvise.h"
#include "mbchar.h"
#include "physmem.h"
#include "quote.h"
}
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
}
else
{
+ fdadvise (fd, 0, 0, FADVISE_SEQUENTIAL);
while ((bytes_read = safe_read (fd, buf, BUFFER_SIZE)) > 0)
{
if (bytes_read == SAFE_READ_ERROR)