summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2010-07-14 09:49:16 +0100
committerPádraig Brady <P@draigBrady.com>2010-07-22 01:03:48 +0100
commit63b5e8164847285f5d3c1dbc9f7c41ad8c17ccc6 (patch)
treead36d7838aa11ba9a3090cf88890de923d61a6ce /src
parentc88cfffb6cb424c2f2ee8317dd8f546bd8594443 (diff)
downloadcoreutils-63b5e8164847285f5d3c1dbc9f7c41ad8c17ccc6.tar.xz
fadvise: new module providing a simpler interface to posix_fadvise
* bootstrap.conf: Include the new module * gl/lib/fadvise.c: Provide a simpler interface to posix_fadvise. (fadvise): Provide hint to the whole file associated with a stream. (fdadvise): Provide hint to the specific portion of a file associated with a file descriptor. * gl/lib/fadvise.h: Redefine POSIX_FADV_* to FADVISE_* enums. * gl/modules/fadvise: New file. * m4/jm-macros.m4: Remove the no longer needed posix_fadvise check. * .x-sc_program_name: Exclude test-fadvise.c from this check. * gl/tests/test-fadvise (main): New test program. * gl/modules/fadvise-testss: A new index to reference the tests. * src/sort.c (stream_open): Use the new interface. * src/dd.c (iwrite): Likewise.
Diffstat (limited to 'src')
-rw-r--r--src/dd.c7
-rw-r--r--src/sort.c30
2 files changed, 10 insertions, 27 deletions
diff --git a/src/dd.c b/src/dd.c
index ab8b84c22..b6643e2e1 100644
--- a/src/dd.c
+++ b/src/dd.c
@@ -27,10 +27,10 @@
#include "system.h"
#include "close-stream.h"
#include "error.h"
+#include "fadvise.h"
#include "fd-reopen.h"
#include "gethrxtime.h"
#include "human.h"
-#include "ignore-value.h"
#include "long-options.h"
#include "quote.h"
#include "quotearg.h"
@@ -849,12 +849,9 @@ iwrite (int fd, char const *buf, size_t size)
posix_fadvise to tell the system not to pollute the buffer
cache with this data. Don't bother to diagnose lseek or
posix_fadvise failure. */
-#ifdef POSIX_FADV_DONTNEED
off_t off = lseek (STDOUT_FILENO, 0, SEEK_CUR);
if (0 <= off)
- ignore_value (posix_fadvise (STDOUT_FILENO,
- off, 0, POSIX_FADV_DONTNEED));
-#endif
+ fdadvise (STDOUT_FILENO, off, 0, FADVISE_DONTNEED);
/* Attempt to ensure that that final block is committed
to disk as quickly as possible. */
diff --git a/src/sort.c b/src/sort.c
index afa45a8b3..fa59e6ac3 100644
--- a/src/sort.c
+++ b/src/sort.c
@@ -30,11 +30,11 @@
#include "system.h"
#include "argmatch.h"
#include "error.h"
+#include "fadvise.h"
#include "filevercmp.h"
#include "hard-locale.h"
#include "hash.h"
#include "heap.h"
-#include "ignore-value.h"
#include "md5.h"
#include "mbswidth.h"
#include "nproc.h"
@@ -856,9 +856,13 @@ create_temp_file (int *pfd, bool survive_fd_exhaustion)
return node;
}
-/* Predeclare an access pattern for input files.
- Ignore any errors -- this is only advisory.
+/* Return a stream for FILE, opened with mode HOW. A null FILE means
+ standard output; HOW should be "w". When opening for input, "-"
+ means standard input. To avoid confusion, do not return file
+ descriptors STDIN_FILENO, STDOUT_FILENO, or STDERR_FILENO when
+ opening an ordinary FILE. Return NULL if unsuccessful.
+ fadvise() is used to specify an access pattern for input files.
There are a few hints we could possibly provide,
and after careful testing it was decided that
specifying POSIX_FADV_SEQUENTIAL was not detrimental
@@ -899,24 +903,6 @@ create_temp_file (int *pfd, bool survive_fd_exhaustion)
cache immediately after processing. This is done implicitly
however when the files are unlinked. */
-static void
-fadvise_input (FILE *fp)
-{
-#if HAVE_POSIX_FADVISE
- if (fp)
- {
- int fd = fileno (fp);
- ignore_value (posix_fadvise (fd, 0, 0, POSIX_FADV_SEQUENTIAL));
- }
-#endif
-}
-
-/* Return a stream for FILE, opened with mode HOW. A null FILE means
- standard output; HOW should be "w". When opening for input, "-"
- means standard input. To avoid confusion, do not return file
- descriptors STDIN_FILENO, STDOUT_FILENO, or STDERR_FILENO when
- opening an ordinary FILE. Return NULL if unsuccessful. */
-
static FILE *
stream_open (const char *file, const char *how)
{
@@ -932,7 +918,7 @@ stream_open (const char *file, const char *how)
}
else
fp = fopen (file, how);
- fadvise_input (fp);
+ fadvise (fp, FADVISE_SEQUENTIAL);
return fp;
}
return fopen (file, how);