zRam is a virtual memory compression using block devices named /dev/zram using a fast compression algorithm that compress the least recently used (LRU) or inactive space in the memory allows the GNU/Linux kernel to free up more memory with less performance hit.

zRam is greatly increasing the available amount of memory without swap disks/partition. It is recommended for user to use zRam instead of not using swap or swap on slow disks.

Create a zRam block devices

Load the zRam modules to the kernel using modprobe:

Set the zRam extremely fast compression algorithm using lz4:
Set 2 Gigabyte available zRam disk space for swap:
Create a swap on zRam block devices:
Enable the zRam block devices for swapping with high priority:

Automatically activate zRam swap at startup

Create a systemd service (zram.service) using a text editor such as nano:

Add following to the zram.service:
Enable the zram.service to automatically run at startup:

Disable zRam block devices

Disable the zRam block devices swapping:

Remove the zRam module from the kernel:
Disable the zram.service from automatically run at startup:

See also

  1. Zram or zswap section (Maximizing Performance) – ArchWiki
  2. zram: Compressed RAM based block devices – Linux Kernel Documentation
  3. Image by TobiasDCC0 Public Domain