sendfile(2) SF_NOPUSH flag proposal
From: Igor Sysoev (is_at_rambler-co.ru)
Date: Mon, 26 May 2003 21:41:50 +0400 (MSD) To: email@example.com
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 126.96.36.199.
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);
tp->t_flags |= TF_NOPUSH;
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
firstname.lastname@example.org mailing list
To unsubscribe, send any mail to "email@example.com"