Reminder: enable ZRAM on your Linux system to optimize RAM usage (and potentially save money)

ZRAM zstd compression ram sticks

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:


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:


Once done, I installed zram-tools:


and edited the /etc/default/zramswap file as follows:


To be on the safe side, you may want to check zstd if supported by your kernel:


I then restarted the service with the new parameters:


Finally, let’s check if everything is enabled as expected:


It looks good. The swapfile on my NVMe SSD is not used anymore, but I’ll try to use my system that way, and only re-enable it in case the system runs out of memory.

Ubuntu zram laptop

Finally, I wanted to make sure it was enabled on my Raspberry Pi 5 with 2GB of RAM, and I forgot that it’s indeed enabled by default on Raspberry Pi OS:


Raspberry Pi ZRAM

Note the config for rpi-swap is in a different location: /etc/rpi/swap.conf, and follows a different format:


More details about this specific implementation can be found on GitHub. If you are using a different operating system on any SBC, you may want to check ZRAM (or  zswap) is enabled.

Share this:

Support CNX Software! Donate via cryptocurrencies, become a Patron on Patreon, or purchase goods on Amazon or Aliexpress. We also use affiliate links in articles to earn commissions if you make a purchase after clicking on those links.

Radxa Orion O6 Armv9 mini-ITX motherboard
Subscribe
Notify of
guest
The comment form collects your name, email and content to allow us keep track of the comments placed on the website. Please read and accept our website Terms and Privacy Policy to post a comment.
49 Comments
oldest
newest
Boardcon MINI1126B-P AI vision system-on-module wit Rockchip RV1126B-P SoC