[PATCH] Use sendfile to copy data between file descriptors

Bartosz Gołaszewski bartekgola at gmail.com
Mon Oct 20 13:03:59 UTC 2014


2014-10-20 14:45 GMT+02:00 Baruch Siach <baruch at tkos.co.il>:
> Hi Laurent,
>
> On Mon, Oct 20, 2014 at 02:34:02PM +0200, Laurent Bercot wrote:
>> Le 20/10/2014 13:36, Bartosz Golaszewski a écrit :
>> >Busybox already uses sendfile in httpd. This patch proposes to use it
>> >globally to copy data between file descriptors.
>>
>>  I haven't been keeping up-to-date with sendfile() in the last couple of
>> years, but AFAICR sendfile() was limited in the type of file it's writing
>> from/to, and the way to perform zero-copy data transmission across generic
>> fds is splice().
>
> This has changed in kernel version 2.6.33. Since that version sendfile()
> out_fd can be any file. The in_fd parameter must support mmap, though. See the
> sendfile(2) man page.
>
> baruch

There's even a comment in the kernel code in fs/splice.c:

/**
1289  * do_splice_direct - splices data directly between two files
(...)
1297  * Description:
1298  *    For use by do_sendfile(). splice can easily emulate sendfile, but
1299  *    doing it in the application would incur an extra system call
1300  *    (splice in + splice out, as compared to just sendfile()).
So this helper
1301  *    can splice directly through a process-private pipe.
1302  *
1303  */

So apparently sendfile() is ok in this case.

Best regards,
Bartosz Gołaszewski


More information about the busybox mailing list