News: 1773406969

  ARM Give a man a fire and he's warm for a day, but set fire to him and he's warm for the rest of his life (Terry Pratchett, Jingo)

RAM is getting expensive, so squeeze the most from it

(2026/03/13)


Linux has two ways to do memory compression – zram and zswap – but you rarely hear about the second. The Register compares and contrasts them.

The Linux kernel's [1]zram tool has been in the news this week. [2]Phoronix reports that the [3]new patch could make some zram operations 50 percent faster.

Thanks to the increasingly desperate flailing by the hucksters selling automatic plagiarism machines, RAM has [4]got much more expensive and the price rises are [5]expected to continue . Apple has even [6]quietly dropped the 512 GB RAM model of its Mac Studio. This is not a good time to buy computers with lots of RAM, or to add more RAM to existing machines.

[7]

Better to try to make the most of what you've already got. So we thought this might be a good time to look at what zram is and does, and explore its less well-known companion [8]zswap .

[9]

[10]

Both work with Linux's existing [11]swapping mechanism . Swapping (called paging in Windows) is a way for the kernel to handle running low on available RAM. It chooses pages of memory that aren't in use right now and copies them to disk, then those blocks can be marked as free and reused for something else. This could be a whole process and its data, which gets paused and swapped out from RAM onto disk. The hope is that some other program will finish, which frees up its RAM, and the process can be swapped in again. Unfortunately, in real life, it's more likely that the poor stressed user switches to the inactive program, which means something else has to get swapped out to make room for it.

This matters because it means that to use either zram or zswap, you need some form of swap.

[12]

Swapping is a basic mechanism that comes along as part of the deal with any OS that has virtual memory. That broadly means any OS that can use a hardware memory-management unit. For the PC industry, this means anything since Linux (1991) and Windows NT (1993). From reading far too many posts in far too many techie message boards, we get the impression that a lot of people these days think "My computer has enough RAM. I don't need swap, so I turned it off."

This is wrong. Don't do it. Always configure some swap, just in case.

It is like concluding that you are happy with your body weight, and so put a wire waistband in all your trousers (underpants, skirts, whatever you prefer). Sure, on a normal day they will fit, but you might go to a really good dinner and eat too much, or you might get sick and not eat and lose a bit of weight, and suddenly they will all painfully cut into you, or they'll fall down. A little bit of elastic, even if only in your underwear, makes life much more comfortable.

[13]

Having some swap is an elastic waistband for your computer. In normal use, the machine might never need it, but if something goes a bit wrong one day, it's much better to have it than, metaphorically speaking, have your clothes split and fall off. One day you will be glad there was a little slack or a little give.

So, first, let's talk briefly about swap space.

What kind of swap?

By default, there are basically two options here: a swap file, or a swap partition. Ever since [14]version 17.04 , Ubuntu has used a swap file by default. When the Linux kernel was young, this was slower, but there's been next to no difference in a decade or more. The only real snag is that you need more room in the root partition.

From old habit, The Reg FOSS desk always sets up a dedicated swap partition. One advantage is that if you have more than one physical drive, you can put the swap partition on a different drive, which spreads the load on the disks a little. Back when SSDs were expensive and wore out, we kitted out machines with a small SSD and a big HDD, and put the OS on the SSD and the swap on spinning rust, but that isn't really necessary any more. Just bung an extra partition on the end of one of your SSDs, and during installation tell the installer that's for swap.

How much? That's contentious. [15]Perlod's guidelines seem reasonable:

Under 2 GB RAM: Set swap to 2× your RAM.

2 GB to 8 GB RAM: Set swap equal to your RAM.

Over 8 GB RAM: 4 GB is usually enough.

Exception: If you use Hibernation, your swap must be bigger than your total RAM.

Zram

Thinking about where swap is, and how much, is where zram comes in. As is often the case, the Arch wiki [16]explains it well . Zram creates compressed dynamic RAM disks. "Dynamic" meaning they grow only as they fill up, and "compressed" means with [17]LZ4 , which is fast. One use for those RAM disks is for swapping.

This sounds insane: swapping from memory to memory? What's the point? But it is not mad, it works. The gist is that your computer swaps stuff out when it's short of space. Normally, that means to disk. For instance, a 500 MB program gets turfed out of RAM and stuck in half a gigabyte of disk space, freeing up half a gig of RAM for other stuff.

The problem is, swap is very slow, because disks are very slow compared to RAM. To understand how many thousands of times slower, there's a handy table of [18]Latency Numbers Every Programmer Should Know on GitHub, and a [19]humanized version that expresses the time differentials in terms more meaningful to [20]us meatsacks .

The idea of zram is: rather than take the time to write it out to disk, why not compress it and keep it in memory? With a fast CPU, it won't take long, and it will take about half as much space. When you need it back, swapping it in just means decompressing it from RAM to RAM, which is relatively quick.

It works surprisingly well and some distros enable it by default these days, such as Fedora and derivatives.

Memory compression is mainstream tech now: macOS has [21]used memory compression since 10.9 , and Windows 10 gained [22]the feature in 2015 in [23]Build 10525 .

There are two main use cases for swapping to zram. One is if your machine has enough RAM that you rarely run low. In this scenario, it takes a little of the free memory that the kernel would use for your disk cache anyway, and hey presto, you can have more programs in memory at once.

[24]DR-DOS rises again – rebuilt from scratch, not open source

[25]Linux PC vendor System76 tries to talk Colorado down over OS age checks

[26]RSS dulls the pain of the modern web

[27]Gram: Zed, but with AI and chat features removed

The other situation is that you might not have much spare memory, but your system drive is slow, or small, or limited in how many writes it can handle. This applies to computers which boot from microSD cards, or similar onboard storage such as an eMMC drive. This particularly applies to the Raspberry Pi, and to many low-end single-board computers and cheap tablets.

Here, zram lets you avoid wearing out the card, and helps prevent you from running out of memory. It lets you over-commit your RAM: load more stuff into memory than you have available memory, because the stuff that isn't running right now has effectively been zipped so it takes less space.

This only works so far – it can't compress everything in your memory: the kernel needs some workspace, and room for whatever task is currently running. The good news is that the kernel natively understands the idea of multiple separate areas of swap space, and can prioritize them. So you can have some zram as well as a swap file, and it will move the least recently used stuff from zram into disk swap as needed.

In our [28]testing of Pop!_OS 24.04 so far, we found it configures two-level swap like this: first zram, then an encrypted swap file in the root partition.

To summarize, zram can take the place of swap on disk. Or, if you have the room to spare, you can use it as well as plain old swapping to disk, in which case it acts as a sort of compressed cache for your swap, speeding swap performance slightly. That's why, earlier in its development, it was called compcache .

Zswap

The main alternative to zram is [29]zswap , which works rather differently.

Zswap isn't an alternative to, or complement for, having swap on disk. It requires swap on disk, but does its best to reduce how much your OS uses that swap by compressing stuff before it gets to the swap space. For the technical nitty-gritty, its developer described how it works for LWN in 2013: [30]the zswap compressed swap cache .

There's a short sharp [31]description in the Debian wiki. The good thing about zswap is that using it is basically as simple as turning it on or off. You can even do it on the fly, although we usually enable it on all our machines, right from the bootloader. If your distro boots using GRUB, it's as simple [32]editing one line in one config file. For distros that use systemd-boot , it's a bit more complicated – that is systemd all over – but it's only a [33]couple more steps .

Pop!_OS is one example – but for that distro, compressed swap needs more work. Two things need to be turned off for this to provide any performance benefit. Firstly, Pop!_OS enables zram by default, so you need to [34]disable zram . Then reboot and check it's gone. (Hint: sudo swapon -s lists all active swap volumes.)

Secondly, Pop defaults to encrypting its swap file. The encryption and decryption reduces performance, and zswap is a performance optimization. So you should [35]disable cryptswap too. Afterwards, for (much) faster boots, remove the /etc/crypttab file too. (We just renamed it to crypttab.old from old paranoid habit.)

Do both, and don't forget to reboot each time. When you're sure both zram and cryptsetup are gone, then try enabling zswap.

One or the other, not both

Zram can work alongside a normal swap file, but not alongside zswap. Both are trying to do the same thing, and any performance improvement either could give will be eliminated by them duplicating one another's work and wasting the very resource you're trying to use more efficiently. Use zram, or zswap, but don't even try both at once.

We've tried both, and we do use zram on things like our Raspberry Pis and on custom bootable Linux keys. However, for general desktop and laptop use, we find zswap works better – and [36]others find the same .

We know a lot of people also advocate encrypting your machines' drives, especially laptops. We feel that [37]XKCD 538 applies here. Turn it off, especially swap. If possible, configure a dedicated partition – then enable zswap, and leave it well alone.

Bootnote

There is a third alternative as well, called [38]Zcache . This is a bolder and more general effort than either zram or zswap, but despite decades of work, it is still quite experimental and it's not just a feature that you can turn on or off. For that reason, we decided to leave it out in favor of the two things you can have right now, off the metaphorical shelf. ®

Get our [39]Tech Resources



[1] https://docs.kernel.org/admin-guide/blockdev/zram.html

[2] https://www.phoronix.com/news/Linux-ZRAM-50p-Compress-Boost

[3] https://lore.kernel.org/lkml/ae51966c3cb445e9983230243bb6a5b2@honor.com/

[4] https://www.theregister.com/2025/11/19/commodity_memory_price_rise/

[5] https://www.theregister.com/2026/02/02/dram_prices_expected_to_double/

[6] https://www.macrumors.com/2026/03/05/mac-studio-no-512gb-ram-upgrade/

[7] https://pubads.g.doubleclick.net/gampad/jump?co=1&iu=/6978/reg_onprem/storage&sz=300x50%7C300x100%7C300x250%7C300x251%7C300x252%7C300x600%7C300x601&tile=2&c=2abRCssxmqC_2LNqTBpz_TAAAAFY&t=ct%3Dns%26unitnum%3D2%26raptor%3Dcondor%26pos%3Dtop%26test%3D0

[8] https://docs.kernel.org/admin-guide/mm/zswap.html

[9] https://pubads.g.doubleclick.net/gampad/jump?co=1&iu=/6978/reg_onprem/storage&sz=300x50%7C300x100%7C300x250%7C300x251%7C300x252%7C300x600%7C300x601&tile=4&c=44abRCssxmqC_2LNqTBpz_TAAAAFY&t=ct%3Dns%26unitnum%3D4%26raptor%3Dfalcon%26pos%3Dmid%26test%3D0

[10] https://pubads.g.doubleclick.net/gampad/jump?co=1&iu=/6978/reg_onprem/storage&sz=300x50%7C300x100%7C300x250%7C300x251%7C300x252%7C300x600%7C300x601&tile=3&c=33abRCssxmqC_2LNqTBpz_TAAAAFY&t=ct%3Dns%26unitnum%3D3%26raptor%3Deagle%26pos%3Dmid%26test%3D0

[11] https://wiki.archlinux.org/title/Swap

[12] https://pubads.g.doubleclick.net/gampad/jump?co=1&iu=/6978/reg_onprem/storage&sz=300x50%7C300x100%7C300x250%7C300x251%7C300x252%7C300x600%7C300x601&tile=4&c=44abRCssxmqC_2LNqTBpz_TAAAAFY&t=ct%3Dns%26unitnum%3D4%26raptor%3Dfalcon%26pos%3Dmid%26test%3D0

[13] https://pubads.g.doubleclick.net/gampad/jump?co=1&iu=/6978/reg_onprem/storage&sz=300x50%7C300x100%7C300x250%7C300x251%7C300x252%7C300x600%7C300x601&tile=3&c=33abRCssxmqC_2LNqTBpz_TAAAAFY&t=ct%3Dns%26unitnum%3D3%26raptor%3Deagle%26pos%3Dmid%26test%3D0

[14] https://www.theregister.com/2017/04/03/ubuntu_17_04_review/

[15] https://perlod.com/tutorials/swap-usage-on-linux-servers/#faq-question-1769163254784

[16] https://wiki.archlinux.org/title/Zram

[17] https://lz4.org/

[18] https://gist.github.com/jboner/2841832

[19] https://gist.github.com/hellerbarde/2843375#file-latency_humanized-markdown

[20] https://www.mit.edu/people/dpolicar/writing/prose/text/thinkingMeat.html

[21] https://blog.greggant.com/posts/2024/07/03/macos-memory-management.html

[22] https://www.makeuseof.com/windows-memory-compression-guide/

[23] https://blogs.windows.com/windows-insider/2015/08/18/announcing-windows-10-insider-preview-build-10525/

[24] https://www.theregister.com/2026/03/11/drdos_9/

[25] https://www.theregister.com/2026/03/10/foss_age_verification_2/

[26] https://www.theregister.com/2026/03/09/rss_in_2026/

[27] https://www.theregister.com/2026/03/04/gram_cut_down_zed/

[28] https://www.theregister.com/2025/12/22/popos_2404_cosmic_epoch_1/

[29] https://wiki.archlinux.org/title/Zswap

[30] https://lwn.net/Articles/537422/

[31] https://wiki.debian.org/Zswap

[32] https://www.reddit.com/r/debian/comments/q2ux4c/comment/hfnt9zu/

[33] https://www.reddit.com/r/pop_os/comments/ier8d0/comment/g2kc3jp/

[34] https://www.baeldung.com/linux/zram-boot-disable

[35] https://unix.stackexchange.com/questions/793563/ubuntu-fully-disabling-cryptswap

[36] https://linuxblog.io/zswap-better-than-zram/

[37] https://xkcd.com/538/

[38] https://github.com/arp242/zcache

[39] https://whitepapers.theregister.com/



williamyf

With my P1 90Mhz 16MB RAM and WfW 3.1 I "discovered" that, I if I made a 4 or 8 MB RAMdisk, compressed it with doublespace and pointed /tmp, /temp and the windows pagefile to it, the machine was greatly accelerated (especialy compile jobs) AND coyld fit bigger software than woulkd be possible otherwise.

Sadly, win95 put an end to it, as the swap bypased the doublespace via APIs and stored everything uncomprerssed.

One of the reasons I delayed the upgrade as much as feasible.

Everything old is new again!

lordminty

Coming from an IBM mainframe background you used dedicated Page disks (real huge spinning rust) normally, and dedicated Swap disks only when you were right in the sh**.

I was told stories of a British electrical/electronics retailer (which still exists) that was so tight they used to create Page and Swap datasets (files) all over data disks. With entirely predictable results. There were tales of their entire online system stopping when the OS swapped, leaving store terminals hung until it sorted itself out.

When I got a home PC one of the first things I did was fit a second hard drive, a cheap secondhand one, as a Page disk. The difference in performance was noticeable. Since then I've carried on doing it on my Linux PCs, until SSDs started arriving. I even used USB sticks for page/swap.

Looks like its time to start doing it again!

Re: Everything old is new again!

Anonymous Coward

Sounds hard...do old people still leave their doors unlocked?

We could just work out who has two sticks of RAM, sneak in during the night and take one stick. Leave one in.

It's a victimless crime...probably.

anthonyhegedus

Perhaps with the price of RAM being what it is, programs could start getting more efficient. Why does Teams, which I only use for messaging most of the time, take up 2GB? Why does a simple website use 1.1GB?

Word has one file open - 750MB.

Pascal Monett

Because, historically speaking, programmers don't give a flying fuck about the amount of RAM their code uses.

This trend started when Windows 95 came out and RAM was a dime a megabyte.

The only way Redmond programmers are going to pay attention to their RAM usage is if their office gets as small as their RAM usage gets large.

VoiceOfTruth

>> programmers don't give a flying fuck about the amount of RAM their code uses.

I am not sure that is correct. It didn't use to be that way. It also doesn't explain why Linux has to copy that methodology.

I remember running a Linux desktop on 32MB of RAM. It didn't have the bells and whistles which seem necessary these days. My productivity on the command line has not increased with the amount of RAM I have installed.

Sudosu

AI?

Liam Proven

> Word has one file open - 750MB.

I can only tell you that Word 97 still works, you can activate it with the magic number 1111-1111111, and its file format remained constant for the next decade so everything can open it. I think I reviewed it when it came out and mocked its size, but now, it can run inside any vaguely recent processor's L2 cache.

Runs a treat in WINE, including installing all the Service Releases, and is blazingly fast on an old low-end Core i5.

fortunately my system has plenty

Nate Amsden

My primary "desktop" is a Lenovo P15 workstation laptop from 2022 with a 8 core Xeon and 128G of ECC ram. No swap, usually 100G of ram available. Didn't really need more than 32 to 48GG, just wanted to max it out at the time wasn't too expensive in early 2023. I expect this to last me till 2030.

Laptop before that was a Lenovo P50 which I got in 2016. I specifically recall the kernel being terrible with swap at the time because it came with 16G of ram, and it would grind to a halt for a minute or more doing basic stuff because of swap. I ran the same workload (just newer OS/kernel) as my previous Toshiba Tecra A11 from 2011 which maxed out at 8G. The 16G laptop had plenty of ram but still swapped at times like crazy, so much the mouse cursor would stall and the system would freeze for many seconds at a time. "Swapiness" settings did nothing. A co worker said he had seen similar issues with Linux for years. I had not till that point.

16G ran worse than 8G just with a newer kernel/software. So crazy. I quickly had to upgrade to 32G which fixed it. Later upgraded again to 48G for no reason.(Max is 64G for that P15)

All 3 laptops are on my desk still with their lids closed stacked neatly on shelves with dedicated laptop coolers below each one.

later ran into linux slab memory leaks(resulting in swapping) at work on Ubuntu 20 which I spent about a year in investigating, that was super annoying, onky fix is to reboot. Newer kernels helped a bit and it seems maybe totally resolved in Ubuntu 24.

Re: fortunately my system has plenty

Sudosu

Not exactly related to the compression discussion, but is for the RAM savings one :)

I've got an ancient HP Z800 circa 2011, with an SSD, an NVMe (I always call these "ENVY ME!" drives, is that right?) plugged into the PCIe slot on a card, 100GB of blazing 1333MHz DDR3 and dual X5675 CPU's.

It cost me 90 dollars 5 years ago, which translates into less than 8GB of DDR4/5 RAM today I think.

I originally bought it to run Proxmox, but will run just about anything I toss at it.

It can even run modest LLM's (under Ollama) on just the CPU's, though somewhat slowly...saving up for an RTX3060 for it to help with that.

The power supplies are the greatest weakness, once it dies you toss the computer generally, so mine sips, or maybe gulps, filtered power.

Re: fortunately my system has plenty

Anonymous Coward

>The power supplies are the greatest weakness, once it dies you toss the computer generally, so mine sips, or maybe gulps, filtered power

Won't help. The PSUs in the z800 had an abnormal high failure rate, and filtered power doesn't change that. However, for someone versed in electronics the PSUs are easily repairable (and if they use higher spec parts they will also last much longer than a new one would have).

The successor z820 uses a revised version which sadly is incompatible with the z800. These PSUs are robust so HP used the same ones in the z840 as well.

Re: fortunately my system has plenty

Anonymous Coward

Same here. Sitting on a z8 G4 with 384GB RAM which should be enough for a while, and on the other desk there's a Dell 7820 with the same amount of memory.

Considered moving to a newer system but the current memory prices just make this completely unrealistic, especially with DDR5 now reaching price parity with brand new Chelsea tractors.

is zram backing compressed?

brainwrong

"So you can have some zram as well as a swap file, and it will move the least recently used stuff from zram into disk swap as needed."

I was looking at these recently, and have been unable to find out if data remains compressed when zram moves data to the disk swap. I feel that if it did, then this would be a feature worth telling people about. My understanding of the architecture of the swap system is that if the zram swap device fills up, then the existing data will remain there, and new data swapped out of memory will go (uncompressed) to the disk swap. If data were to be moved out of zram swap to disk swap, it would be de-compressed as it leaves zram.

Zswap does write compressed data to the backing swap disk, so reducing the amount of writes, which is good for ssd's.

It appears to me that zram is only good if you have no disk swap, and zswap is the better option if you do.

I always encrypt swap partition, because raw memory contents may be sat there in the open.

Re: is zram backing compressed?

Liam Proven

> have been unable to find out if data remains compressed when zram moves data to the disk swap.

I thought it did, but during my research for this article it looks like no, it doesn't. I _think_ it's expanded again so that the existing unmodified read/write mechanisms still work.

For a previous recent piece, I found that the RAM image dumpted into the swap volume for hibernation _is_ compressed. So there is a different code path that can read/write compressed data.

Some unification work here is needed, I reckon.

"Perlod's guidelines seem reasonable"

sured

You mean to surf the web right?

This 8GB advice has never been so poor and ironically it is extremely poor for anyone who pays attention to swap. For over 20 years software for CAD, 3D, 2D, NLE, profiling, etc. hasn't worked dependably with 8GB swap and anyone who uses these knows this every time the GUI freezes/seizes. Now that's just typical GUI based userland software but it's the same with software services. Anyone running a modest DB laughs at 8GB swap. Any VPS user knows that a modest GIT repo wants at least 16GB. A modest mail daemon minus the DB will eat 8GB swap with queue.

For the audience of this article, again the people who pay attention to swap, there is simply near 0 use cases where 8GB swap will be acceptable.

Re: "Perlod's guidelines seem reasonable"

Liam Proven

> software for CAD, 3D, 2D, NLE, profiling, etc.

Nothing like which I ever use, myself. This may be why I can still get productive work done with my T420 and W520, which are now 15 year old laptops. They run VMs with aplomb, while I have 2 browsers, a multi-protocol chat program, a music player, and my horrifically bloated distraction-free writing tool of choice all open. And a music player, typically. They can handle 2 full-size modern 64-bit OSes in VMs concurrently at a push. I have successfully bootstrapped an entire working K8s cluster on a single 8GB PC before now.

So, no, not just to surf the web, no.

But those are cautious conservative low-end numbers. If you have the room and don't mind, then sure, you could allocate a tonne of swap. What do you in fact recommend? Since you don't specify.

2x RAM like of old?

It's Time To End The Confusion

dlc.usa

Why can't the industry standardize on paging for (typically) 4096-byte virtual memory pages moving in and out of real RAM (main storage in mainframes) while swapping is for process spaces to be rendered non-dispatchable with no in-flight I/O to be swapped out? The article would have been so much easier to read if the usage had been defined up front. Maybe we need new terms for swapping and paging to arise that adhere to these distinctions and end the confusion.

Re: It's Time To End The Confusion

lordminty

"main storage in mainframes"

You're showing your age there!

Shall we tell them that mainframes used 4k pages back in 1967...? ;-)

Re: It's Time To End The Confusion

dlc.usa

Mainframes' age--they're still pulling their considerable weight.

Re: It's Time To End The Confusion

sured

Do you mean standardize the terminology or in respect to the 'Z'? Moving from/to permanent storage or from/to RAM is the difference regardless of what the bytes represent. As for the 'Z' in ZRAM, it's basically for OEMs trying to lower costs by including less RAM. Now if you could also dedupe in RAM that might change things, but that would be a noticeable performance hit without new CPU instructions being added and possibly a tweaked PCIe (which the article doesn't mention).

After re-reading your comment, I think you're using 2 examples that use different context :-/. Of course it depends on your context of "swapping", but I feel like the article is using the context of 'swapon /swapfile'

Swap partitions ?

JimmyPage

Also making sure your swap partition lives on a different disk to your boot partition .

I am examining you on your fool ideas that no intelligent Christian
on earth believes.
-- Clarence Darrow, to William Jennings Bryan