From owner-freebsd-arch@FreeBSD.ORG Mon May 26 17:21:00 2003 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 433AC37B401 for ; Mon, 26 May 2003 17:21:00 -0700 (PDT) Received: from stork.mail.pas.earthlink.net (stork.mail.pas.earthlink.net [207.217.120.188]) by mx1.FreeBSD.org (Postfix) with ESMTP id A260B43F93 for ; Mon, 26 May 2003 17:20:59 -0700 (PDT) (envelope-from tlambert2@mindspring.com) Received: from dialup-67.30.96.194.dial1.sanjose1.level3.net ([67.30.96.194] helo=mindspring.com) by stork.mail.pas.earthlink.net with asmtp (SSLv3:RC4-MD5:128) (Exim 3.33 #1) id 19KSD1-0002oY-00; Mon, 26 May 2003 17:20:56 -0700 Message-ID: <3ED2AF18.F5EB4FA5@mindspring.com> Date: Mon, 26 May 2003 17:19:36 -0700 From: Terry Lambert X-Mailer: Mozilla 4.79 [en] (Win98; U) X-Accept-Language: en MIME-Version: 1.0 To: Igor Sysoev References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-ELNK-Trace: b1a02af9316fbb217a47c185c03b154d40683398e744b8a4f756173a69883f238a60c0f62127d40c387f7b89c61deb1d350badd9bab72f9c350badd9bab72f9c cc: arch@freebsd.org Subject: Re: sendfile(2) SF_NOPUSH flag proposal X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 27 May 2003 00:21:00 -0000 Igor Sysoev wrote: > sendfile(2) now has two drawbacks: Only two? ;^). > 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. OK, basically what is happening is that the data is being pushed out as it's made available, and it's being made available in seperate chunks. The small file case is not really the optimum case for using the sendfile interface at all. The problem here is that you have a send queue depth limit on the sockets, and it's expected that the file will end up exceeding this, so it's going to get buffered anyway, due to a buffer size limit stall on the send side of the socket. > 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. I don't see this as being terrifically useful; small files should probably just be mapped and written; the copy expense is still there for the headers and trailers, no matter what, and the file size itself is very small overhead, relatively speaking, for files small enough for this to be an issue. I also think your headers and trailers are very small, if they are fitting with the file contents in a single packet. I think this is atypical. On the other hand, if you want to add a flag for this, I say "knock yourself out" -- go ahead and add the flag; it's not really going to benefit you that much, but it's not going to really hurt any of the rest of us either, so there's really no reason to make you not do it. 8-). BTW: if you go ahead with this, you should verify that it also works for the trailers, etc., and you should probably skip it if you headers > transmit queue depth, or file size > transmit queue depth, or trailers > transmit queue depth. -- Terry