From: Akihiro Sagawa Subject: [PATCH 1/4] server: Implement access pattern hints for file data. Message-Id: <20191212223839.105D.375B48EC@gmail.com> Date: Thu, 12 Dec 2019 22:39:35 +0900 Signed-off-by: Akihiro Sagawa --- configure | 1 + configure.ac | 1 + dlls/ntdll/tests/file.c | 2 ++ include/config.h.in | 3 +++ server/fd.c | 19 +++++++++++++++++++ 5 files changed, 26 insertions(+) diff --git a/configure b/configure index a5c504b..cb34665 100755 --- a/configure +++ b/configure @@ -17710,6 +17710,7 @@ for ac_func in \ pipe2 \ poll \ port_create \ + posix_fadvise \ prctl \ pread \ proc_pidinfo \ diff --git a/configure.ac b/configure.ac index 13f9718..47c1dc0 100644 --- a/configure.ac +++ b/configure.ac @@ -2161,6 +2161,7 @@ AC_CHECK_FUNCS(\ pipe2 \ poll \ port_create \ + posix_fadvise \ prctl \ pread \ proc_pidinfo \ diff --git a/dlls/ntdll/tests/file.c b/dlls/ntdll/tests/file.c index 539ce44..1d42058 100644 --- a/dlls/ntdll/tests/file.c +++ b/dlls/ntdll/tests/file.c @@ -3744,6 +3744,8 @@ static void test_file_mode(void) { &file_name, FILE_SYNCHRONOUS_IO_ALERT, FILE_SYNCHRONOUS_IO_ALERT }, { &file_name, FILE_NO_INTERMEDIATE_BUFFERING, FILE_NO_INTERMEDIATE_BUFFERING }, { &file_name, FILE_SYNCHRONOUS_IO_NONALERT | FILE_NON_DIRECTORY_FILE, FILE_SYNCHRONOUS_IO_NONALERT }, + { &file_name, FILE_RANDOM_ACCESS | FILE_SEQUENTIAL_ONLY, FILE_SEQUENTIAL_ONLY }, + { &file_name, FILE_SEQUENTIAL_ONLY, FILE_SEQUENTIAL_ONLY }, { &file_name, FILE_DELETE_ON_CLOSE, 0 }, { &file_name, FILE_RANDOM_ACCESS | FILE_NO_COMPRESSION, 0 }, { &pipe_dev_name, 0, 0 }, diff --git a/include/config.h.in b/include/config.h.in index 63396e9..3550b52 100644 --- a/include/config.h.in +++ b/include/config.h.in @@ -707,6 +707,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_PORT_H +/* Define to 1 if you have the `posix_fadvise' function. */ +#undef HAVE_POSIX_FADVISE + /* Define to 1 if you have the `powl' function. */ #undef HAVE_POWL diff --git a/server/fd.c b/server/fd.c index 5d80e21..dd0e662 100644 --- a/server/fd.c +++ b/server/fd.c @@ -1756,6 +1756,9 @@ struct fd *open_fd( struct fd *root, const char *name, int flags, mode_t *mode, struct fd *fd; int root_fd = -1; int rw_mode; +#ifdef HAVE_POSIX_FADVISE + int advice = POSIX_FADV_NORMAL; +#endif if (((options & FILE_DELETE_ON_CLOSE) && !(access & DELETE)) || ((options & FILE_DIRECTORY_FILE) && (flags & O_TRUNC))) @@ -1894,6 +1897,22 @@ struct fd *open_fd( struct fd *root, const char *name, int flags, mode_t *mode, free( closed_fd ); fd->cacheable = 1; } + +#ifdef HAVE_POSIX_FADVISE + /* hint file access patterns */ + switch (options & (FILE_SEQUENTIAL_ONLY | FILE_RANDOM_ACCESS)) + { + case FILE_SEQUENTIAL_ONLY: + advice = POSIX_FADV_SEQUENTIAL; + break; + case FILE_RANDOM_ACCESS: + advice = POSIX_FADV_RANDOM; + break; + } + if (advice != POSIX_FADV_NORMAL) + posix_fadvise(fd->unix_fd, 0, 0, advice); +#endif + if (root_fd != -1) fchdir( server_dir_fd ); /* go back to the server dir */ return fd;