Use zram to Compress RAM on Linux Workstations
A Hacker News author recommends Linux memory compression with zram as an alternative to expanding expensive or non-upgradable workstation RAM. The author reports a personal Firefox test that compressed 5.7 GB of data into 1.7 GB of RAM, a 1:3.35 ratio, while noting extra CPU work and process latency. The report also says Fedora and Pop!_OS enable RAM compression by default, whereas Ubuntu and most other distributions do not.
For workstations running memory-intensive parallel AI workloads, zram may provide additional usable capacity without immediately purchasing more physical memory.
AI has changed a lot. We do more work in parallel. This increases the memory demand on our workstations. Also, memory is expensive and often not extendable. So buying more RAM is not an easy option. Recently I was running out of memory, I found my solution in zram, a solution to compress memory.
Memory compression is not new. If you have a Windows or Mac device you are already using it. Also, many Android smartphones utilize the technique of using compression to put more data into the RAM. Unfortunately not all Linux environments have RAM compression enabled by default. Fedora, Pop!_OS do, but Ubuntu doesn’t. Amazon Linux only enables zram on smaller virtual machines. Most other distributions do not have it enabled.
Compressing memory does come with small, but not really noticeable, downsides. It takes a little bit more from your CPU and adds latency to some processes. What you gain is gigantic amounts of extra capacity. It is not uncommon to see compression ratios up to 1:4.
I remember that in the early days of writing SaaS software we would often need double the size of the machines when we added more features to our monolithic app. Often the CPUs were under little stress, so we could have avoided upgrading if we had enabled RAM compression. This could have cut our Cloud spend in half!