On Linux this doubles the readahead. Even though we are not strictly
speaking going to read or write the file sequentially (only mostly
sequentially) it may provide some minor benefit.
---
configure.ac | 3 +++
copy/file-ops.c | 7 +++++++
2 files changed, 10 insertions(+)
diff --git a/configure.ac b/configure.ac
index fea43c8..6cf563a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -98,6 +98,9 @@ AC_CHECK_HEADERS([\
AC_CHECK_HEADERS([linux/vm_sockets.h], [], [], [#include <sys/socket.h>])
+dnl posix_fadvise helps to optimise linear reads and writes (optional).
+AC_CHECK_FUNCS([posix_fadvise])
+
dnl Check for strerrordesc_np (optional, glibc only).
dnl Prefer this over sys_errlist.
dnl
https://lists.fedoraproject.org/archives/list/glibc@lists.fedoraproject.o...
diff --git a/copy/file-ops.c b/copy/file-ops.c
index 1d7e6a6..73cbdcb 100644
--- a/copy/file-ops.c
+++ b/copy/file-ops.c
@@ -116,6 +116,13 @@ file_create (const char *name, int fd, off_t st_size, bool is_block)
rwf->can_fallocate = true;
}
+ /* Set the POSIX_FADV_SEQUENTIAL flag on the file descriptor, but
+ * don't fail.
+ */
+#if defined (HAVE_POSIX_FADVISE) && defined (POSIX_FADV_SEQUENTIAL)
+ posix_fadvise (fd, 0, 0, POSIX_FADV_SEQUENTIAL);
+#endif
+
return &rwf->rw;
}
--
2.29.0.rc2