Files.copy does userspace copies but FileChannel uses sendfile

Alan Bateman Alan.Bateman at oracle.com
Wed Oct 12 16:31:39 UTC 2016


On 12/10/2016 17:22, Martin Buchholz wrote:

> sendfile(2) says
>
>        sendfile() copies data between one file descriptor and another.
>        Because this copying is done within the kernel, sendfile() is more
>        efficient than the combination of read(2) and write(2), which would
>        require transferring data to and from user space.
>
> The advantage of read/write is portability, but we've already paid the 
> price and are already using sendfile.  The savings with a particular 
> pair of fds may not be great, but in principle we should always be 
> using sendfile when we can.
>
I don't disagree, it' just that historically sendfile was for file <-> 
socket and there wasn't support for file <-> file on all platforms. In 
this case, it shouldn't be hard to try out using sendfile for the 
regular file copy and then get some data on performance for a number of 
different platforms and file systems.

-Alan


More information about the nio-dev mailing list