On 05/01/2012 05:59 PM, Pádraig Brady wrote:
> Now many coreutils already provide such a hint to the kernel:
> http://git.sv.gnu.org/gitweb/?p=coreutils.git;a=commit;h=47076e3c
> But copy.c does not currently. I'm not sure why I didn't
> do it for copy.c now, but I look into adding it.

The attached seems to give another 5% speedup!

$ dd bs=1MB count=200 if=/dev/zero of=file.in

$ dd of=file.in oflag=nocache conv=notrunc,fdatasync count=0
$ time ./cp-before file.in /dev/shm/; rm /dev/shm/file.in
real    0m0.843s
user    0m0.005s
sys     0m0.417s
$ dd of=file.in oflag=nocache conv=notrunc,fdatasync count=0
$ time ./cp-before file.in /dev/shm/; rm /dev/shm/file.in
real    0m0.856s
user    0m0.002s
sys     0m0.422s

$ dd of=file.in oflag=nocache conv=notrunc,fdatasync count=0
$ time ./cp-after file.in /dev/shm/; rm /dev/shm/file.in
real    0m0.809s
user    0m0.006s
sys     0m0.373s
$ dd of=file.in oflag=nocache conv=notrunc,fdatasync count=0
$ time ./cp-after file.in /dev/shm/; rm /dev/shm/file.in
real    0m0.804s
user    0m0.007s
sys     0m0.405s

cheers,
Pádraig.
>From 24e6311c53f40e874854e1574ee1c8f2de161ab2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <[email protected]>
Date: Tue, 1 May 2012 21:50:49 +0100
Subject: [PATCH] cp,mv,install: provide POSIX_FADV_SEQUENTIAL hint to input

This was inadvertently omitted from v8.5-104-g47076e3,
and gives the same 5% speedup when copying from an SSD.

* src/copy.c (copy_internal): Apply the FADVISE_SEQUENTIAL hint.
---
 src/copy.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/src/copy.c b/src/copy.c
index 414fbe0..00d1c34 100644
--- a/src/copy.c
+++ b/src/copy.c
@@ -39,6 +39,7 @@
 #include "cp-hash.h"
 #include "extent-scan.h"
 #include "error.h"
+#include "fadvise.h"
 #include "fcntl--.h"
 #include "fiemap.h"
 #include "file-set.h"
@@ -980,6 +981,8 @@ copy_reg (char const *src_name, char const *dst_name,
       size_t buf_alignment_slop = sizeof (word) + buf_alignment - 1;
       size_t buf_size = io_blksize (sb);
 
+      fdadvise (source_desc, 0, 0, FADVISE_SEQUENTIAL);
+
       /* Deal with sparse files.  */
       bool make_holes = false;
       bool sparse_src = false;
-- 
1.7.6.4

Reply via email to