mmap() sendfile()

Cedric Tabary ced at grumly.eu.org
Mon Dec 12 00:42:25 PST 2005


I was looking at the freebsd port of thttpd and i saw this patch :
/usr/ports/www/thttpd/files/patch-mmc.c

This is some sort of file cache, it works by mmap()ing some files and
keeping the mmap address in a hashtable. I suppose this is used to keep
the file in memory until munmap() is called.

The patch is just removing the mmap() and keeping file descriptors open
for use by sendfile(). But I don't know if replacing the mmap() by
sendfile() has the same cache effect ?!
Keeping the file descriptor open after using sendfile() will keep the
file in memory ??

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


More information about the freebsd-hackers mailing list