Activating ZRam on Linux distributions

Hey guys!
This tutorial's for those of us on GNU/Linux, are low on physical RAM, and have flash storage (especially for SBCs like the Raspberry Pi). ZRam is a kernel module that compresses RAM content to save space for more RAM intensive processes. It acts much like a swap file/partition, where RAM pages are "swap"ped in and out to free up RAM.

The overall process is pretty simple, involving just a few commands and no extra packages.
  1. Load the zram kernel module
    $ sudo modprobe zram
  2. Use zramctl to get an available zram device
    $ sudo zramctl --find --size <size in megabytes>M
    Example: $
    sudo zramctl --find --size 1024M # For 1GB
  3. Create swap on the created zram device
    $ sudo mkswap <device name printed by zramctl>
  4. Enable swap
    $ sudo swapon <device name printed by zramctl>
  5. Profit!
For a comparison on its effectiveness,  I tried doing a (memory intensive) compile directly on my Raspberry Pi. Memory was completely used up and everything went to a standstill. Enabling zram allowed memory to be used up completely and still leave the SSH session interactive.

Cheers!
Technohacker

Comments

Popular Posts