Re: Re[2]: sendfile to nonblocking socket

From: Eric Dumazet
Date: Tue Apr 24 2007 - 08:48:51 EST


On Tue, 24 Apr 2007 14:33:48 +0400
Alex Vorona <voron@xxxxxxxxxx> wrote:

> Hello David,
>
> Tuesday, April 24, 2007, 1:19:49 PM, you wrote:
>
> >> sendfile function is not just a more efficient version of a read
> >> followed by a write. It reads from one fd and write to another at tha
> >> same time. Please try to read 2G, and then write 2G - and how much
> >> memory you will be need and how much time you will loose while reading
> >> 2G from disk, but not writing them to socket.
>
> DS> You are correct. What I meant to say was that it's just a
> DS> more efficient version of 'mmap'ing a file and then 'write'ing
> DS> from the 'mmap'. The 'write' to a non-blocking socket can still
> DS> 'block' on disk I/O.
>
> How can I avoid that blocking? Or maybe another question - how can I
> deliver data from disk to network with minimal copy operations, etc.
>

I believe the modern way would be to use splice() system call :

loop
splice(from disk , to pipe) with SPLICE_F_NONBLOCK
wait_event_from_epoll (pipe ready for reading)
splice(from pipe, to socket)
wait_event_from_epoll (socket ready for writing)

But :

1) I am not sure epoll can get an event when page(s) is/are ready in pipe (ie disk delivered the page(s) to cache)
2) I am not sure splice() to socket is actually implemented with 0-copy
3) I am not sure pipe capacity (16 pages) would be enough to get a good readahead.

Eric



-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/