Reminder: enable ZRAM on your Linux system to optimize RAM usage (and potentially save money)
With the price of RAM getting out of control, it might be a good idea to remind Linux users to enable ZRAM so they can get better performance without upgrading memory, or save money on their next single board computer by selecting a board with the right amount of memory.
I had already written about the subject when I enabled ZRAM on a ODROID-XU4Q in 2018 using zram-config, and did the same on my Ubuntu laptop at the time. In recent days, I found Firefox crashing often due to running out of memory on my system with 16GB of RAM, and the Linux 7.0 release reminded me about ZRAM, since there were some related changes. So I decided to check the current swap configuration on my Ubuntu 24.04 laptop:
jaufranc@CNX-LAPTOP-5:~$ zramctl NAME ALGORITHM DISKSIZE DATA COMPR TOTAL STREAMS MOUNTPOINT /dev/zram0 lzo-rle 7.6G 6.6G 2.1G 2.1G [SWAP] jaufranc@CNX-LAPTOP-5:~$ swapon NAME TYPE SIZE USED PRIO /swapfile file 8G 5.6G -2 /dev/zram0 partition 7.6G 7.3G 5 jaufranc@CNX-LAPTOP-5:~$ free -mh total used free shared buff/cache available Mem: 15Gi 9.6Gi 4.3Gi 2.4Gi 3.4Gi 5.7Gi Swap: 15Gi 12Gi 2.7Gi 1 2 3 4 5 6 7 8 9 10 11 jaufranc @ CNX - LAPTOP - 5 : ~ $ zramctl NAME ALGORITHM DISKSIZE DATA COMPR TOTAL STREAMS MOUNTPOINT / dev / zram0 lzo - rle 7.6G 6.6G 2.1G 2.1G [ SWAP ] jaufranc @ CNX - LAPTOP - 5 : ~ $ swapon NAME TYPE SIZE USED PRIO / swapfile file 8G 5.6G - 2 / dev / zram0 partition 7.6G 7.3G 5 jaufranc @ CNX - LAPTOP - 5 : ~ $ free - mh total used free shared buff / cache available Mem : 15Gi 9.6Gi 4.3Gi 2.4Gi 3.4Gi 5.7Gi Swap : 15Gi 12Gi 2.7Gi
lzo doesn’t look like a recent compression algorithm, and I think I’ve seen Zstandard compression used on other systems before. However, the zram-config utility appears to be an older solution, and it’s now been replaced with zram-tools. So I decided to replace it. If you haven’t already enabled ZRAM with zram-config, you don’t need to do that, but in my case, I had to disable swap and purge the package:
sudo swapoff -a sudo swapoff /dev/zram0 2>/dev/null || true echo 1 | sudo tee /sys/block/zram0/reset 2>/dev/null || true sudo modprobe -r zram sudo apt purge --autoremove zram-config 1 2 3 4 5 sudo swapoff - a sudo swapoff / dev / zram0 2 > / dev / null || true echo 1 | sudo tee / sys / block / zram0 / reset 2 > / dev / null || true sudo modprobe - r zram sudo apt purge -- autoremove zram - config
... continue reading