2009-04-22 23:06:30

by Mark Hills

[permalink] [raw]
Subject: splice() on unix sockets

I found that splice() can operate from a pipe to a unix socket, but from a
unix socket to a pipe fails with EINVAL.

On investigation, splicing from a pipe to a unix socket (af_unix.c) gets
routed through a regular unix_stream_sendmsg (via sock_no_sendpage). If my
understanding is correct this means it will copy memory and not
references, so it's not actually a splice.

If so, splice() behaves inconsistently; sometimes it fails on unsupported
file descriptors, sometimes it falls back to a copy. The man page favours
the former, but the latter could also be useful -- to call splice() with
any pair of fds and have the kernel do the best it can.

Splicing between unix sockets and pipes would give a useful performance
benefit. Is there any work in progress on this? Are there any caveats to
implementing it?

Thanks,

--
Mark