Optimising network stack with sendfile(2) - BSD

This is a discussion on Optimising network stack with sendfile(2) - BSD ; Hi, This is just a quick question, does freebsd (6/6.2) using sendfile(2) system call to eliminate the double-copies (normally the file content is read into the application then write out to the socket) between application and socket? Thanks S...

+ Reply to Thread
Results 1 to 2 of 2

Thread: Optimising network stack with sendfile(2)

  1. Optimising network stack with sendfile(2)

    Hi,

    This is just a quick question, does freebsd (6/6.2) using sendfile(2)
    system call to eliminate the double-copies (normally the file content is
    read into the application then write out to the socket) between
    application and socket?

    Thanks
    S

  2. Re: Optimising network stack with sendfile(2)

    Pet Farrari wrote:
    > Hi,
    >
    > This is just a quick question, does freebsd (6/6.2) using sendfile(2)
    > system call to eliminate the double-copies (normally the file content is
    > read into the application then write out to the socket) between
    > application and socket?
    >


    $ man 2 sendfile

    ....

    IMPLEMENTATION NOTES
    The FreeBSD implementation of sendfile() is "zero-copy", meaning
    that it has been optimized so that copying of the file data is
    avoided.
    ....

    and take a look at /usr/src/sys/uipc_syscalls.c round about line 1797...
    in particular...


    /*
    * Loop through the pages in the file, starting with the requested
    * offset. Get a file page (do I/O if necessary), map the file page
    * into an sf_buf, attach an mbuf header to the sf_buf, and queue
    * it on the socket.
    */

    It's not the cleanest implementation imaginable but the source is very clear about what's going on!


    pete
    --
    pete@fenelon.com "he just stuck to buying beer and pointing at other stuff"

+ Reply to Thread