Enable zRAM for improved memory handling and less swapping

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.

  • 3 Users Found This Useful
Was this answer helpful?

Related Articles

Setting and syncing time on Ubuntu with ntp / ntpdate

These commands will help you change your server's local timezone configuration to London, and...

Installing the latest mainline kernel on Ubuntu

This is an example article and may well be out of date by the time you are reading, so please...

Using Unbound to speed up DNS queries

Using a local DNS resolver cache can significantly boost the speed of a server, particularly one...