Files.copy does userspace copies but FileChannel uses sendfile

Brian Burkhalter brian.burkhalter at oracle.com
Wed Oct 12 16:30:19 UTC 2016


It seems as if this is a good candidate for some JMH testing from the Java layer.

Brian

On Oct 12, 2016, at 9:22 AM, Martin Buchholz <martinrb at google.com> 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.
> 
> 
> On Tue, Oct 11, 2016 at 10:41 PM, Alan Bateman <Alan.Bateman at oracle.com> wrote:
> On 12/10/2016 00:30, Max Kanat-Alexander wrote:
>> :
>> 
>> Should these be merged? Or should the Java-side implementation of Files.copy be changed to use FileChannel underneath?
>> 
>> 
> It's been a copy while the performance was checked but the last time then sendfile was great for file <--> socket but we weren't see any benefit for file <--> file. Kernels improve and there are many different file systems so it probably should be remeasured. If there are benefits to the FileSystemProvider to use sendfile then it could do that.
> 
> -Alan
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/nio-dev/attachments/20161012/35c4fde8/attachment.html>


More information about the nio-dev mailing list