Categories
SysOps

How to use virtual memory filesystem to store Varnish Shared memory Log

Varnish Shared memory Log can put a major strain on the disk (I/O write operations). The solution is to store it on the virtual memory filesystem.

Define tmpfs virtual memory filesystem on /var/lib/varnish directory.

$ echo "tmpfs /var/lib/varnish tmpfs rw,size=1G 0 0" | sudo tee -a /etc/fstab

Stop varnish service.

$ sudo systemctl stop varnish

Mount tmpfs virtual memory filesystem.

$ sudo mount /var/lib/varnish

Start varnish service.

$ sudo systemctl start varnish

The tmpfs virtual memory filesystem will get populated as expected.

$ df -h /var/lib/varnish/
Filesystem      Size  Used Avail Use% Mounted on
tmpfs           1.0G   81M  944M   8% /var/lib/varnish

Additional notes

The Varnish Book – Tuning