Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 4 Jan 2006 17:25:17 +0300 (MSK)
From:      Igor Sysoev <is@rambler-co.ru>
To:        Mike Silbersack <silby@silby.com>
Cc:        Cedric Tabary <ced@grumly.eu.org>, freebsd-hackers@freebsd.org
Subject:   Re: mmap() sendfile()
Message-ID:  <20060104171645.J2352@is.park.rambler.ru>
In-Reply-To: <20051212083537.T78724@odysseus.silby.com>
References:  <20051212083930.GC91837@efrei.fr> <20051212083537.T78724@odysseus.silby.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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/



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20060104171645.J2352>