mmap() sendfile()
Mike Silbersack
silby at silby.com
Mon Dec 12 06:38:35 PST 2005
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.
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.
So, if there was a reason to not use sendfile under 4.x, it's probably not
true anymore.
Someone sent me a patch to thttpd which made it more efficient on FreeBSD
a looooooong time ago, I don't recall what changes he had made.
Mike "Silby" Silbersack
More information about the freebsd-hackers
mailing list