Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I'm interested in maximizing cache hits and efficiency for a slow-changing site. The virtual host doesn't have a huge amount of RAM, but I'd like to use what's available for varnish, but to fall back to disk cache if there isn't enough memory.

Is it possible to do this with a single instance of varnish? The docs describe "file" and "malloc" storage as distinct options.

share|improve this question

2 Answers 2

up vote 6 down vote accepted

Use the malloc method. It will try to put everything in RAM and the kernel will swap it out if needed. This way you are using memory and disk together.

At the same time file performs much better than malloc when you start hitting disk. For more info, see:

share|improve this answer
Thanks, this works. I think I'll just use malloc method with available RAM, and rely on the server to do disc caching (e.g. apache mod_disk_cache). –  user67641 Feb 1 '11 at 20:29
Is there a way to plug Varnish into other memory based backends? –  CMCDragonkai May 20 '14 at 0:50

You need to name storage respectively as follows and in vcl you specify which backend storage you want to use with beresp.storage = storage_name. .

Varnish 3.* process options

DAEMON_OPTS="-a :80 \
             -T localhost:6082 \
             -f /etc/varnish/default.vcl \
             -S /etc/varnish/secret \
             -s foo=malloc,512m \
             -s bar=file,/var/lib/varnish/varnish_storage.bin,512m"

vcl v3

sub vcl_fetch {
    if (req.url ~ "html") {
       set beresp.storage = "foo";
       set beresp.http.x-storage = "foo";
    } else {
       set beresp.storage = "bar";
       set beresp.http.x-storage = "bar";
    return (deliver);

For Varnish v4, you can follow the official blog post's instruction https://www.varnish-software.com/blog/partitioning-your-varnish-cache

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.