Surviving The RAM Price Squeeze With Linux In-Kernel Memory Compression

Swissbit 2GB PC2-5300U-555

You’ve probably heard — we’re currently experiencing very high RAM prices due mostly to increased demand from AI data centers.

RAM prices gone up four times

If you’ve been priced out of new RAM you are going to want to get as much value out of the RAM you already have as possible, and that’s where today’s hack comes in: if you’re on a Debian system read about ZRam for how to install and configure zram-tools to enable and manage the Linux kernel facilities that enable compressed RAM by integrating with the swap-enabled virtual memory system. We’ve seen it done with the Raspberry Pi, and the concept is the same.

Ubuntu users should check out systemd-zram-generator instead, and be aware that zram might already be installed and configured by default on your Ubuntu Desktop system.

If you’re interested in the history of in-kernel memory compression LWN.net has an old article covering the technology as it was gestating back in 2013: In-kernel Memory Compression. For those trying to get a grip on what has happened with RAM prices in recent history, a good place to track memory prices is memory.net and if you swing by you can see that a lot of RAM has gone up as much as four times in the last three or four months.

If you have any tips or hacks for memory compression on other platforms we would love to hear from you in the comments section!

27 thoughts on “Surviving The RAM Price Squeeze With Linux In-Kernel Memory Compression

  1. Is not better to remove the sh*t from the kernel? is not normale that the kernel use all this space… Then you can optimize it with memory compression, but what the point to have a lot of unused stuff in the kernel?

    1. for real!

      This article reminds me of a similar hack i used back in like 1996. Used an ‘after-market’ patch to Linux 1.2.13. I “needed” the compression because i had 4MB of RAM and it simply wasn’t enough. A year later, a summer internship paid for 32MB of RAM and i never worried about RAM ever again.

      Anecdote about the kernel hack…back then, the kernel stack was one 4kB page and the compression code would sometimes blow that, eating the 0xdeadbeef magic bytes at the end of the stack and causing an Oops. That really amused me, but it was an easy fix to just use two pages for the stack. I was sure glad to get rid of the hack though.

        1. Well wit the kinda of money ai got to inflate dram

          Just use sram, nobody going to complain about sram prices, if anything they go down

          Can’t get faster than sram that can run at CPU clock

    1. Heh, I seem to remember practically everyone complaining about how fat and inefficient programs were. Now is the time to put that complaint into some action and put programs on a diet.

  2. It’s called swap. It’s a good thing. Swap to SSD works very well, since the latency is often 1000 times lower than for HDs.

    Sure, thrashing is bad, but zram doesn’t help that at all – even makes it worse, since compression and decompression is more expensive cycle and joules-wise.

Leave a Reply to mark hahnCancel reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.