Zram swap on Debian and Linux Mint

Last edited on 2022-09-20 Tagged under  #debian   #mint   #lmde   #linux 

Instead of creating a separate swap partition or using a swapfile, its possible to create a high-speed swap device in RAM itself with the Linux kernel module zram. Even though its been around for years, I've only learned about it recently and its pretty cool!

Let's go!

Zram swap - not to be confused with zswap - creates a compressed block device in memory, and the RAM assigned to it is only used for swapping as-needed (until then, the RAM is still available for use by applications).

Swap data stored is compressed thereby allowing more data to be stored in RAM. Performing read/write operations in memory is both a speed boost and reduces wear on SSD drives, at the cost of more CPU-intensive activity.

My setup

  • OS is Linux Mint Debian Edition (LMDE)
  • Enabled on my Thinkpad T480s with 8GB RAM
  • Assign 25% of memory to the zram0 device for swap
  • No other swap devices are in use

1. Install

Disable any active swaps ...

$ sudo swapoff --all

Install ...

$ sudo apt install zram-tools

2. Configure

Stop zram ...

$ sudo zramswap stop

Settings are modified in /etc/default/zramswap.

Uncomment PERCENT and set amount of RAM used by zram as a percentage of the total memory available ...


Uncomment PRIORITY and set the priority of the swap device ...


3. Fstab

Check if any swap devices exist in fstab (example: I had swapfile vgmint-swap_1) ...

$ grep swap /etc/fstab
/dev/mapper/vgmint-swap_1 none            swap    sw              0       0

If so, comment out the swap entries to disable.

4. Start

$ sudo zramswap start
$ sudo zramctl

5. Helpful

Thanks for reading! Read other posts?

» Next: Getting started with Git and GitLab

« Previous: DoH and custom DNS servers with OpenWrt