From owner-freebsd-hackers@FreeBSD.ORG Wed Jan 4 14:25:21 2006 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 085BE16A41F for ; Wed, 4 Jan 2006 14:25:21 +0000 (GMT) (envelope-from is@rambler-co.ru) Received: from yam.park.rambler.ru (yam.park.rambler.ru [81.19.64.116]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5CBA643D48 for ; Wed, 4 Jan 2006 14:25:20 +0000 (GMT) (envelope-from is@rambler-co.ru) Received: from is.park.rambler.ru (is.park.rambler.ru [81.19.64.102]) by yam.park.rambler.ru (8.13.3/8.13.3) with ESMTP id k04EPI7j078267; Wed, 4 Jan 2006 17:25:18 +0300 (MSK) (envelope-from is@rambler-co.ru) Date: Wed, 4 Jan 2006 17:25:17 +0300 (MSK) From: Igor Sysoev X-X-Sender: is@is.park.rambler.ru To: Mike Silbersack In-Reply-To: <20051212083537.T78724@odysseus.silby.com> Message-ID: <20060104171645.J2352@is.park.rambler.ru> References: <20051212083930.GC91837@efrei.fr> <20051212083537.T78724@odysseus.silby.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: Cedric Tabary , freebsd-hackers@freebsd.org Subject: Re: mmap() sendfile() X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 04 Jan 2006 14:25:21 -0000 On Mon, 12 Dec 2005, Mike Silbersack wrote: > On Mon, 12 Dec 2005, Cedric Tabary wrote: > >> If it is true, doing a sendfile() on some very big files (even if not >> keeping the descriptor open after) will kill the cache ? >> >> Please help me to understand why this patch ? and the difference between >> sendfile() and mmap() at the memory or cache level.. >> >> C?dric > > My memory escapes me on all the details, but there were two potential reasons > not to use sendfile with 4.x that no longer apply in 5.x and above: > > 1. Sendfile used to send small files inefficiently, sending the http headers > in one packet and the data in another. I fixed this in 5.x. There is workaround, it's used in my server nginx: setting the TCP_NOPUSH socket option. By the way, I've backported the patch to 4.x: http://sysoev.ru/freebsd/patch.uio.txt http://sysoev.ru/freebsd/patch.sendfile_header.txt > 2. Alan Cox improved the memory efficiency of sendfile greatly, it now uses > a single kernel buffer for all copies of the same block of the same file, > whereas the old implementation made an in-kernel copy of each block, making > it no more memory efficient than using mbufs. sendfile() in 4.x is more memory efficient than mbufs because sfbufs use KVA only while mbuf clusters use both KVA and physical memory. Igor Sysoev http://sysoev.ru/en/