Discussion:
splice()/sendfile() with sockets
(too old to reply)
Vincent Bernat
2014-01-28 00:09:24 UTC
Permalink
Raw Message
Hi!

Currently, libevent is not using splice() syscall but it is mentioned at
several places. It could be used in place of sendfile(). This would be
convenient since it would allow to copy one socket to another through
event buffers without the data to be copied in user memory. Does the use
of splice() instead of sendfile() be difficult? Would this allow
evbuffer_add_file() to be used with sockets?
--
HARDFAIL("Not enough magic.");
2.4.0-test2 /usr/src/linux/drivers/block/nbd.c
***********************************************************************
To unsubscribe, send an e-mail to ***@freehaven.net with
unsubscribe libevent-users in the body.
Nick Mathewson
2014-01-29 20:47:30 UTC
Permalink
Raw Message
Post by Vincent Bernat
Hi!
Currently, libevent is not using splice() syscall but it is mentioned at
several places. It could be used in place of sendfile(). This would be
convenient since it would allow to copy one socket to another through
event buffers without the data to be copied in user memory. Does the use
of splice() instead of sendfile() be difficult?
--
I'd be happy to merge a patch for splice() support. Have a look at
the evbuffer_splice_sendfile() function to see what you'd need to
change.

Are there any cases where sendfile is necessary because splice won't
work? If so, we'll need to use the flags argument to
evbuffer_file_segment_new() for that.
Post by Vincent Bernat
Would this allow
evbuffer_add_file() to be used with sockets?
I don't know; it would be interesting to find out. The APIs might
also need a bit of tweaking to support that case.

yrs,
--
Nick
***********************************************************************
To unsubscribe, send an e-mail to ***@freehaven.net with
unsubscribe libevent-users in the body.
Vincent Bernat
2014-02-01 15:46:28 UTC
Permalink
Raw Message
Post by Nick Mathewson
Post by Vincent Bernat
Currently, libevent is not using splice() syscall but it is mentioned at
several places. It could be used in place of sendfile(). This would be
convenient since it would allow to copy one socket to another through
event buffers without the data to be copied in user memory. Does the use
of splice() instead of sendfile() be difficult?
--
I'd be happy to merge a patch for splice() support. Have a look at
the evbuffer_splice_sendfile() function to see what you'd need to
change.
Are there any cases where sendfile is necessary because splice won't
work? If so, we'll need to use the flags argument to
evbuffer_file_segment_new() for that.
Note that I opened the an issue to track a bit progress here.

sendfile() now uses splice(). However, splice() is more recent and buggy
until 2.6.28. Here is what we can find about it in HAProxy source code:

/* Versions of splice between 2.6.25 and 2.6.27.12 were bogus and would return EAGAIN
* on incoming shutdowns. On these versions, we have to call recv() after such a return
* in order to find whether splice is OK or not. Since 2.6.27.13 we don't need to do
* this anymore, and we can avoid this logic by defining ASSUME_SPLICE_WORKS.
*/

So, if we overload sendfile(), we need to be ready for splice() to be
accepted but buggy. HAProxy's code show how to detect that and
circumvent it without relying on version numbers.

As pointed in the issue I opened, this is only half of the problem. The
other half is to be able to do zero-copy between sockets.
--
Take care to branch the right way on equality.
- The Elements of Programming Style (Kernighan & Plauger)
***********************************************************************
To unsubscribe, send an e-mail to ***@freehaven.net with
unsubscribe libevent-users in the body.
Loading...