mmap'd file vs. swap

Poul-Henning Kamp phk at
Mon May 5 21:44:23 CEST 2008

In message <CA82C829555343D1B279CA6BBD4B0752 at T60>, "Brian Smith" writes:

>My understanding is that Varnish uses a mmap'd file, but it doesn't re-use 
>the file's contents when it is restarted.


> Why does Varnish use a mmap'd file 
>instead of just using regular virtual memory (swap) directly? 

For many small reasons, none of which are particularly good.

You can use regular VM by enabling the "malloc" storage method
and various people report good success with that.

>I would think 
>that the operating system would be more eager to write the data to the 
>mmap'd file than it would be to write to swap; on a system where the hot 
>cache entries can be stored on disk, it would seem that the swap-based 
>method would be superior.

Well, it's slightly more complex than that, we mmap with the
MAP_NOSYNC flag so it should be about a wash.

Poul-Henning Kamp       | UNIX since Zilog Zeus 3.20
phk at FreeBSD.ORG         | TCP/IP since RFC 956
FreeBSD committer       | BSD since 4.3-tahoe    
Never attribute to malice what can adequately be explained by incompetence.

More information about the varnish-dev mailing list