Mailing List Archive

mmap'd file vs. swap
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? 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.

(I ask because I am trying to decide which method to use for a back-end
system, not to be critical of Varnish's design.)

Thank you,
Brian
mmap'd file vs. swap [ In reply to ]
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? 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.

(I ask because I am trying to decide which method to use for a back-end
system, not to be critical of Varnish's design.)

Thank you,
Brian
mmap'd file vs. swap [ In reply to ]
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.

Correct.

> 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.
mmap'd file vs. swap [ In reply to ]
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.

Correct.

> 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.
mmap'd file vs. swap [ In reply to ]
Poul-Henning Kamp wrote:
> You can use regular VM by enabling the "malloc" storage method
> and various people report good success with that.
...
> Well, it's slightly more complex than that, we mmap with the
> MAP_NOSYNC flag so it should be about a wash.

Thanks. I wasn't familiar with MAP_NOSYNC since I am using Linux, which
doesn't have it.

In the mmap-based implementation, it looks like you have to implement
malloc-like logic yourself, including thread-safety and defragmentation.
Does the mmap-based storage have some advantage to normal malloc()
implementations (e.g. glibc, jemalloc, TCMalloc) due to its domain-specific
knowledge?

Thanks,
Brian
mmap'd file vs. swap [ In reply to ]
Poul-Henning Kamp wrote:
> You can use regular VM by enabling the "malloc" storage method
> and various people report good success with that.
...
> Well, it's slightly more complex than that, we mmap with the
> MAP_NOSYNC flag so it should be about a wash.

Thanks. I wasn't familiar with MAP_NOSYNC since I am using Linux, which
doesn't have it.

In the mmap-based implementation, it looks like you have to implement
malloc-like logic yourself, including thread-safety and defragmentation.
Does the mmap-based storage have some advantage to normal malloc()
implementations (e.g. glibc, jemalloc, TCMalloc) due to its domain-specific
knowledge?

Thanks,
Brian