sendfile(2) SF_NOPUSH flag proposal

From: Igor Sysoev (is_at_rambler-co.ru)
Date: 05/26/03

  • Next message: Peter Jeremy: "Re: sendfile(2) SF_NOPUSH flag proposal"
    Date: Mon, 26 May 2003 21:41:50 +0400 (MSD)
    To: arch@freebsd.org
    
    

    sendfile(2) now has two drawbacks:

    1) it always sends the header, the file and the trailer in the separate
       packets even their sizes allow to place all them in one packet.
       For example the typical HTTP response header is less then an ethernet
       packet and sendfile() sends it in first small packet.

    2) often enough it sends 4K page in three packets: 1460, 1460 and 1176 bytes.

    When I turn TCP_NOPUSH on just before sendfile() then it sends the header
    and the first part of the file in one 1460 bytes packet.
    Besides it sends file pages in the full ethernet 1460 bytes packets.
    When sendfile() completed or returned EAGAIN (I use non-blocking sockets)
    I turn TCP_NOPUSH off and the remaining file part is flushed to client.
    Without turing off the remaining file part is delayed for 5 seconds.

    Surprisingly that the turning TCP_NOPUSH off flushes the file part (I did not
    try the trailer) on FreeBSD 4.2 and 4.3 without src/sys/netinet/tcp_usrreq.c
    fixes 1.53 and 1.51.2.11.

    I looked in src/sys/netinet/tcp_usrreq.c to learn how
    to turn TCP_NOPUSH on/off. It's seems it's as simple as:

            struct inpcb *inp;
            struct tcpcb *tp;

            inp = sotoinpcb(so);
            tp = intotcpcb(inp);

    turn on:
            tp->t_flags |= TF_NOPUSH;

    turn off:
            tp->t_flags &= ~TF_NOPUSH;
            error = tcp_output(tp);

    So here is a proposal. We can introduce a sendfile(2) flag, i.e. SF_NOPUSH
    that will turn TF_NOPUSH on before the sending and turn it off just
    before return. It allows to save two syscalls on each sendfile() call
    and it's especially useful with non-blocking sockets - they can cause many
    sendfile() calls.

    Igor Sysoev
    http://sysoev.ru/en/

    _______________________________________________
    freebsd-arch@freebsd.org mailing list
    http://lists.freebsd.org/mailman/listinfo/freebsd-arch
    To unsubscribe, send any mail to "freebsd-arch-unsubscribe@freebsd.org"


  • Next message: Peter Jeremy: "Re: sendfile(2) SF_NOPUSH flag proposal"

    Relevant Pages

    • Re: sendfile(2) SF_NOPUSH flag proposal
      ... > file in the process address space to mbufs, to the card. ... > packet, you are probably going to spend more on the headers ... I mean that if you have 230 bytes header then sendfile() will send it ...
      (freebsd-arch)
    • Re: set up gateway for PPP to Ethernet?
      ... It looks like the PDA tries to go directly to the Barricade which isn't ... Remember that the source and destination address in the IP header isn't ... The Linux box will take the IP packet and send it on unchanged (unless it ... of packet type) and 4 byte trailer. ...
      (comp.os.linux.networking)
    • Re: sendfile(2) SF_NOPUSH flag proposal
      ... > packets even their sizes allow to place all them in one packet. ... > packet and sendfile() sends it in first small packet. ... is still there for the headers and trailers, no matter what, ...
      (freebsd-arch)
    • RFC: Sendfile patch
      ... The attached patch: ... modifies sendfile to ensure that the header is sent in the same packet as ... it if someone could verify that I have the old sendfile compatibility part ...
      (freebsd-arch)
    • RE: Transfer a sending packet to upper TCP/IP protocol layer in IM
      ... If the IPv6 address can be resolved, ... IPv4 header will be larger than the MTU. ... After prepending IPv4 header and UDP header to the original IPv6 packet, ...
      (microsoft.public.development.device.drivers)