Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The situation is:
Im building PHP application, and need http caching.
Varnish is great, and lots of people tell me that Varnish store the cached data in RAM. But I want it cached in hard disk.

Is there any way to store the Varnish cached data in hard disk?


share|improve this question
You want varnish to only cache to disk? Are you aware of the limitations (random i/o performance) that this will give you? – pauska Apr 7 '10 at 19:42

There are 2 main ways Varnish caches your data:

  1. to memory (with the malloc storage config)
  2. to disk (with the file storage config)

You are asking for #2. In this method Varnish will always write the cache to disk and rely on the OS virtual memory subsystem to keep the most used disk pages in RAM.

If you are using Red Hat/CentOS, edit your /etc/sysconfig/varnish


# DAEMON_OPTS is used by the init script.  If you add or remove options, make
# sure you update this section, too.
#             -h classic,500009 \
             -t ${VARNISH_TTL} \
             -u varnish -g varnish \
             -s ${VARNISH_STORAGE} \
             -p thread_pool_min=200 \
             -p thread_pool_max=2000 \
             -p thread_pools=8 \
             -p listen_depth=4096 \
             -p session_linger=50/100/150 \
             -p lru_interval=60"

If not, you want something like this:

 varnishd -s file,/var/lib/varnish/varnish_storage.bin,50%

50% will use half the available disk. You can also use 10G etc. When using the file storage it is recommended to mount /var/lib/varnish to a non-journaled file system (eg ext2) and to use noatime and nodiratime when mounting the FS.

share|improve this answer

Varnish stores data on disk and then pulls it into RAM to accelerate requests. Short of modifying the source code, I doubt what you're asking for is possible.

share|improve this answer

Take a look at the Architect Notes. A quick read and you should understand the basics quite clearly. The most important bit to note is that Varnish doesn't differentiate between disk and memory, that's the kernel's job.

share|improve this answer

Why you mount point varnish cache file to RAM? Default in system, path /dev/shm is mounted into RAM

share|improve this answer

Your Answer


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