Enable zRAM for improved memory handling and less swapping Print

  • 3

zRAM, formerly called compcache, is a Linux kernel module for creating a compressed block device in RAM, i.e. a RAM disk, but with on-the-fly "disk" compression. The block device created with zRAM can then be used for swap space, that is much higher performance than relying on a physical block device and therefore improves performance substantially.

In a typical scenario, zRAM allows the operating system to hold more data in memory, and especially for web servers, helps improve the performance of moderate to heavily loaded servers.

Ubuntu has a very simple method of implementing and automatically assigning zRAM:

sudo apt-get install zram-config

By default, zram-config will activate a zRAM swap partition on boot that is exactly 50% of your server's physical RAM. This is optimal for most web servers, however larger servers may wish to reduce this size.

nano /usr/bin/init-zram-swapping
mem=$(((totalmem / 2 / ${NRDEVICES}) * 1024))

This line can be edited as required to reduce the size of zRAM, then rebooting the server will apply the new setting safely.


Was this answer helpful?

« Back