Hacker News new | past | comments | ask | show | jobs | submit

Do not buy RAM, compress

https://curiousbits.nl/blog/do-not-buy-ram-compress/
As others have said, macOS does this by default and it's quite impressive. I have a long running daemon with a memory leak. By its nature, the leaking memory is very repetitive and easily compressed. Right now this daemon has tried to claim 2.5GB of memory, but it's been compressed to a mere 450MB of actual memory! And because it's a memory leak, it never accesses this old stuff, so it never gets decompressed. Only 20MB of RAM is held that isn't compressed.

Of course, it would be far better to just not have the memory leak...but in the mean time, macOS memory compression is making the leak nearly a none issue.

loading story #50564797
RAM compression sounds very useful but the thing I really need extra RAM for is local inference.

Since the models are effectively highly compressed data already my assumption is that RAM compression won't help improve that much (I'm assuming unified memory here as per the Framework Desktop). A bit like trying to compress a JPEG in a zip file.

Could anyone comment on that?

loading story #50561996
loading story #50561750
loading story #50559382
I haven't tried it in RAM, but your reasoning matches what I saw when I looked at compressing weights for archiving them. The weights don't compress nicely with standard, especially fast, algorithms. Some more background in this repo [1] including example compression ratios. I would also worry about decompression speed, that gives you a hard bound on the throughput. If the numbers in this repo are accurate, you likely hit the throughput limit of decompression way before you hit the memory limit, even considering the space savings and thus higher effective throughput.

[1] https://github.com/zipnn/zipnn#results

loading story #50561617
I don't know at all. But I've been playing with oMlx and Splash. Using Pi there are compression extensions like the billion-context. I suspect your right.

But all seem to have massive issue boards. What I did see was oMlx release clustering so you can string 3 macs and have 3 times the memory or use one for prefilling accelerating.

Which I thought was neat and what I'll likely poke at instead of getting more ran.

perhaps i'm not pilled enough for this conversation, but aren't you conflating two disparate concepts — model-weights and context-window?
loading story #50561671
loading story #50562483
> Memory compression is not new. If you have a Windows or Mac device you are already using it.

Yes, macOS has had it enabled by default since OS X Mavericks 10.9, released in October 2013. I’m surprised some desktop Linux distributions still require manual configuration to enable it.

For browser tabs, though, I think a better solution is automatic tab closing, using something like the Tab Wrangler extension for Chrome. Collecting tabs comes naturally; we’re much worse at closing them.

"For browser tabs, though, I think a better solution is automatic tab closing" ... the better solution is to actually offload tabs. The issue with Chrome/Edge/... is not your tabs itself but the huge amount of memory loaded for GPU operations.

Do Shift+Esc and watch how large the GPU memory usage is. Often 2/3 to 50% of your actual tab usage.

Ironically, its not the closing of tabs that bothers me, but the fact that tab order changes, what slows my productivity/muscle memory down. And its the same reason for a lot of people why they keep tabs open.

I never understood why we do not have a basic snapshot / sleep that offloads a tabs memory on disk (and dumps the GPU memory), aka a ghost tab. And fast loads when you view the tab. Sure, there may be a small delay but it can save so much memory, while people can keep their tabs open/organized.

Some extensions try to mimic that but its often a crude solution because they do not have deeper access to the webview2 engine.

Chrome has had a built-in tab-sleeping Memory Saver feature for 4 years: https://blog.google/products-and-platforms/products/chrome/n...
loading story #50558977
loading story #50559005
>I’m surprised some desktop Linux distributions still require manual configuration to enable it.

Its a user choice and should be a user-facing knob because there are times it is inappropriate for use, such as in safety-critical circumstances, certain realtime realities, and so on. It should probably be on by default for desktop Linux, but off by default for every other application a distribution may be targeting ...

loading story #50563398
Don't use Zram, use Zswap. Especially if you want to swap to disk.

https://chrisdown.name/2026/03/24/zswap-vs-zram-when-to-use-...

loading story #50561505
I just discovered zram thanks to claude after installing fedora on a new computer and man I was blown away by both zram and fedora. Fedora amongst the linux distributions for some reasons has really got everything that an end user needs and the whole experience is just way smoother than anything I have used in 25 years on linux.

I am hoping to switch my dad from ubuntu to fedora in a month or so because he has 16 GB ram and this seems like something most people dont know.

loading story #50562105
Wow, very cool. Is this like the old "RAM doubler" for Mac OS (or like Johnny Mnemonic's "Pemex MemDoubler")? :)
It's funny, I switch from Fedora back to Ubuntu last year.

I really like Fedora in that it seems very up to date package wise but I found it requires a reboot every time I update using the UI updater.

It's better using the dnf command but it still felt a bit lumpy compared to apt.

loading story #50558742
Could this be one of the tricks the M-series cpus are pulling behind the scenes to make them look faster?
loading story #50561875
loading story #50561216
I like Fedora too but I'm pretty sure Ubuntu also has zram. You just need to enable it.
What a fun loop through time. I remember downloading programs to free up ram in the early 2000's, then as RAM became more ubiqutous and programs were still small you could run them directly on RAMDisk. (I did this with Path of Exile about 10 years ago to avoid lag.) Now we are working back to getting the most out of our ram.
MacOS does this by default for inactive pages. On my current system with 18GB of RAM I show 4.80GB for Apps, 3.16GB Wired and 5.06GB Compressed.
I have to wonder if the better solution would be for browsers (and apps that are effectively broswers) to compress their data proactively.

I find that the ratio of browserish memory use to that of other programs is enough to render the latter insignificant most of the time.

For a programmer, on many cases, it pays to compress the data, to improve RAM IO, because the alu may already be doing nothing meanwhile waiting for the data from ram, so you can use that time to decompress, process, compress, and store the result. A lot of code today is bottlenecked by IO. You spend a lot of effort optimizing with SIMD, processing the data super fast, and then the speed it's wssted because there is not enough bandwidth to even send the result to ram. Modern cpu should include more hardware support for memory compression
I switched to Fedora some time ago and only recently learned about zram. I was hitting full system memory(16GB) during normal use, and after increasing my zram to 16GB, I was blown away. I had initially planned to buy additional ram.
MacOS has been doing this for quite a while now. I was a bit surprised this wasn’t the default for most Linux distros, although I think Pop!_OS (what a name!) has had zram enabled for a few years already. I turned it on on one of my servers (1GB RAM) and it works fine.
loading story #50558416
So, if it is used as swap, that means to use the data, it first needs to go to the CPU, then back to regular RAM, then back to the CPU.

Isn't that wasteful? The CPU's caches may help a bit, but I would guess first a huge block is going through the decompression, so only the last bits are still in the cache, when the actual usage starts.

It's funny that MS didn't integrate memory compression until 2015. From ye olden days, we used "RAM doublers" in MSDOS, which were a bit of a different beast and took a performance hit due to simpler implementation, so some of us aren't "excited" by the cost of packing things in with compression. It is a bandaid for processes that lie somewhere between being needed and not (otherwise it would goto swap right?)

If it avoids hitting the disk I get it, but to some of us, that just means it's time to buy more RAM

I've used zswap on most of my systems and generally find it beneficial especially as (de)compression can be very fast these days.

What's interesting to note is that I've occasionally wondered why isn't the swap partition compressed.

If you have it on an NVMe drive it probably is as is all data! The controller usually transparently does it as it writes to/from NAND.

So the kernel sees uncompressed fixed block pages and the speed boosts happen with data arriving faster when read or written to flash.

loading story #50562128
loading story #50561351
loading story #50563253
I wonder what the theoretical limits are of semantic compression for LLM input/output (eg. "Can you please send me the final report by Friday?" -> "Send final report by Friday." -> sr(FINAL, DEADLINE=FRIDAY)) that can still be recovered back to English
loading story #50562146
loading story #50563234
loading story #50562410
loading story #50563115
Having viewed that page, I cannot fathom how Firefox is using 27GB of RAM in his screenshot?!
loading story #50561731
loading story #50561778
Since I am using Claude with parallel sessions in different workspaces I started to run out of RAM.

Instead of buying more RAM, which meant that I should replace my device, I decided to implement zram. This compresses memory. Now I can do more with the same hardware.

In many cloud environments compression is not enabled. I am curious to see if the same gains can be made in such environment.

loading story #50558390
> Compressing memory does not come with downsides. It takes a little bit more from your CPU and adds latency to some processes

It sounds like those are downsides

loading story #50559073
loading story #50558693
They are downsides in cases where an application has to escalate a critical fault as quickly as possible - indeed where every nanosecond counts - and a process waiting for page restoration is going to be delayed even an intolerable amount.

It should be a user switch and probably will become one in most Linux desktop distributations, I would wager. However, I would not enable it - I run Ubuntu Studio for every last little bit of latency it gives me in a realtime audio-capture application, and on those systems were it to become default-on by way of distro update, I'd be kinda miffed.

loading story #50558683
loading story #50558980
loading story #50558614
loading story #50558670
Hilarious ending to the article. You expect some implementation details with a Getting Started section, instead you get a "check the arch wiki" link.
nice try Ram Altman
"Compressing memory does not come with downsides. It takes a little bit more from your CPU and adds latency to some processes"

Which one is it?

Compression is fine as long as the CPU doesn't become the bottleneck.
You’d hope with these amazing GPUs today, that some cycles can be used to compress RAM very efficiently. So many parallel cores, surely we can get even better compression from this latent hardware?
loading story #50561816
Do not buy RAM, download more RAM
Things I did: - Zswap instead of zram. - Unload browser tabs (my own private extension. - Force idle cli AI agents to go to disk swap earlier.
Windows doesn't do memory compression if the page file is not enabled. I never particularly saw the point of the page file because I don't enjoy swapping, but it appears that the memory management system disproportionately depends on it to the point where it simply refuses to work properly with it off. So make sure that's turned on if you want memory compression. (Do not let it auto-size or it will happily fill up your whole drive, set it to something reasonable)
Vectors do not compress.
loading story #50562815
So why is zswap (basically zram+swap) not enabled by default everywhere?
Because it is a user choice, and there are applications where it is inappropriate. For desktop Linux it should probably be on, as long as its clear to the user - but yeah, for many other Linux use cases its inappropriate.
loading story #50561240
Maybe it should generally be on and and only switched off when it is inappropriate.
loading story #50561300
loading story #50562461
{"deleted":true,"id":50559012,"parent":50557661,"time":1795089791,"type":"comment"}
Do not eat, drink water.

As usual, working class is being told to tighten the belts whilst the rich get insanely richer.

Fuck that.

loading story #50564430
> If you have a Windows or Mac device you are already using it

Technically yes, practically on Windows memory compression is not used.

I have Windows 11, 128 GB RAM, and my memory stats show: 42 GB in use, 380 MB compressed.

You have plenty of RAM free. Compressing at that point is increasing latency for no good reason. Unused RAM is wasted RAM

I'm a Linux user myself, but I think it would start compressing it when there would be less than 25% free

In many systems, adding compression makes not just storage better but increases the io you get from a system too. Here's Valkey 9.2 compression figures showing that: https://www.phoronix.com/news/Valkey-9.2

That's for RDB persistence. https://valkey.io/topics/persistence/

I wonder if there's any similar wins with ram? That some workloads would see net wins from compression. Some cost of cpu, but increasing net throughput significantly.

Okay, Johnny Mnemonic.
I have built my PC with core i7 14700K, RTX 3090,128 GB DDR3, 2TB SSD, 8TB HDD about 3 years ago.

Still perfectly usable and I won't upgrade until prices come down. Even used prices are terrible now.

loading story #50558714
loading story #50558674
Zram vs Zswap: https://chrisdown.name/2026/03/24/zswap-vs-zram-when-to-use-...

> If in doubt, prefer to use zswap. Only use zram if you have a highly specific reason to.

> In terms of architecture:

> zswap sits in front of your disk swap, compresses pages in RAM, and automatically tiers cold data to disk. It integrates directly with the kernel's memory management and distributes pressure gracefully.

> zram is a compressed RAM block device with a hard capacity limit. When you put swap on it and it fills up, there is no automatic eviction, and the kernel has very little leverage to do anything about the situation. The system either OOMs or falls back to lower-priority swap, causing LRU inversion (see below). It only really makes sense for extremely memory-constrained embedded systems, diskless setups, or cases with specific security requirements around keeping private data off persistent storage. Swap on zram is also increasingly unsupported upstream.

loading story #50559018
loading story #50558821