Implement file access pattern hints for sequential or random file access using posix_fadvise if available. On Linux this will influence the kernel's readahead behaviour.
Signed-off-by: Luke Deller luke@deller.id.au --- v6: Use a configure check rather than _POSIX_C_SOURCE macro check to see if posix_fadvise is available --- configure | 1 + configure.ac | 1 + server/fd.c | 10 ++++++++++ 3 files changed, 12 insertions(+)
diff --git a/configure b/configure index cc4f64347f1..3197f07f02b 100755 --- a/configure +++ b/configure @@ -18010,6 +18010,7 @@ for ac_func in \ pipe2 \ poll \ port_create \ + posix_fadvise \ prctl \ pread \ proc_pidinfo \ diff --git a/configure.ac b/configure.ac index cb8fa573c37..361da0428cf 100644 --- a/configure.ac +++ b/configure.ac @@ -2186,6 +2186,7 @@ AC_CHECK_FUNCS(\ pipe2 \ poll \ port_create \ + posix_fadvise \ prctl \ pread \ proc_pidinfo \ diff --git a/server/fd.c b/server/fd.c index de7c5d7e36d..7c101fde2e0 100644 --- a/server/fd.c +++ b/server/fd.c @@ -1882,6 +1882,7 @@ struct fd *open_fd( struct fd *root, const char *name, struct unicode_str nt_nam int root_fd = -1; int rw_mode; char *path; + unsigned int cache_hint;
if (((options & FILE_DELETE_ON_CLOSE) && !(access & DELETE)) || ((options & FILE_DIRECTORY_FILE) && (flags & O_TRUNC))) @@ -2026,6 +2027,15 @@ struct fd *open_fd( struct fd *root, const char *name, struct unicode_str nt_nam free( closed_fd ); fd->cacheable = 1; } + +#ifdef HAVE_POSIX_FADVISE + cache_hint = options & (FILE_SEQUENTIAL_ONLY | FILE_RANDOM_ACCESS); + if (cache_hint == FILE_SEQUENTIAL_ONLY) + posix_fadvise( fd->unix_fd, 0, 0, POSIX_FADV_SEQUENTIAL ); + else if (cache_hint == FILE_RANDOM_ACCESS) + posix_fadvise( fd->unix_fd, 0, 0, POSIX_FADV_RANDOM ); +#endif + if (root_fd != -1) fchdir( server_dir_fd ); /* go back to the server dir */ return fd;