ZRAM Boosts Raspberry Pi Performance

ZRAM Boosts Raspberry Pi Performance

Linux is a two-edged sword. On the one hand, there’s so much you can configure. On the other hand, there’s so much you can configure. It is sometimes hard to know just what you should do to get the best performance, especially on a small platform like the Raspberry Pi. [Hayden James] has a suggestion: enable ZRAM and tweak the kernel to match.


Although the post focuses on the Raspberry Pi 4, it applies to any Linux system that has limited memory including older Pi boards. The idea is to use a portion of main memory as a swap file. At first, that might seem like a waste since you could use that memory to, you know, actually run programs. However, the swap devices are compressed, so you get more swap space and transfers from these compressed swap devices and main memory are lightning-fast compared to a hard drive or solid state disk drive.

In addition to turning on the RAM-based swap, it is important to tune the kernel to make more use of swap now that it is relatively fast. The suggested settings change the following system parameters:


vm.vfs_cache_pressure – Increase the frequency of clearing file caches to free more memory.
vm.swappiness – Make the kernel more likely to use swap. Note that the ZRAM swap will have a higher priority than slower swap files.
vm.dirty_background_ratio – Allow a specified amount of memory pages to be dirty before writing to swap.
vm.dirty_ratio – Absolute limit on dirty pages before I/O starts blocking until the dirty pages are written out.

Of course, these parameters may or may not do the best thing for your setup, so you might want t ..

Support the originator by clicking the read the rest link below.