惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

A
About on SuperTechFans
C
Cybersecurity and Infrastructure Security Agency CISA
N
News and Events Feed by Topic
C
Cisco Blogs
Cisco Talos Blog
Cisco Talos Blog
A
Arctic Wolf
Scott Helme
Scott Helme
P
Palo Alto Networks Blog
S
Schneier on Security
D
Darknet – Hacking Tools, Hacker News & Cyber Security
T
Tor Project blog
量子位
G
Google Developers Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
B
Blog RSS Feed
NISL@THU
NISL@THU
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
AWS News Blog
AWS News Blog
爱范儿
爱范儿
Last Week in AI
Last Week in AI
Y
Y Combinator Blog
L
LINUX DO - 最新话题
Security Archives - TechRepublic
Security Archives - TechRepublic
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
S
Secure Thoughts
Cloudbric
Cloudbric
aimingoo的专栏
aimingoo的专栏
L
Lohrmann on Cybersecurity
TaoSecurity Blog
TaoSecurity Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Hacker News: Ask HN
Hacker News: Ask HN
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
The GitHub Blog
The GitHub Blog
有赞技术团队
有赞技术团队
S
Security @ Cisco Blogs
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Cyber Attacks, Cyber Crime and Cyber Security
G
GRAHAM CLULEY
P
Proofpoint News Feed
V
V2EX
Martin Fowler
Martin Fowler
C
CERT Recently Published Vulnerability Notes
Attack and Defense Labs
Attack and Defense Labs
C
CXSECURITY Database RSS Feed - CXSecurity.com
The Cloudflare Blog
SecWiki News
SecWiki News
罗磊的独立博客
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
小众软件
小众软件
The Last Watchdog
The Last Watchdog

The Register - Software: OSes

Fedora: Microsoft is all aboard, but Deepin is dumped Microsoft promises to do better, but it has a long way to go First big Microsoft update after vow to 'win back fans' Who needs ghost train scares when Windows is such a fright? Microsoft boss tells investors the company is working to 'win back fans' Microsoft boss says company is working to 'win back fans' Linux cryptographic code flaw offers fast route to root Fedora 44 is out – countless versions of it Microsoft sets its sights on the past with 86-DOS and PC-DOS Microsoft updates the Windows Update Experience Windows second-chance setup hurts IT, productivity Ubuntu Resolute Raccoon drops Xorg, keeps X11 apps alive More ancient Linux device support facing the ax WSL9x hacks Linux into ancient Windows 9x systems UK tribunal sends £2B claim accusing Microsoft of overcharging for licensing to trial Zorin OS 18.1 released - and the Lite edition reappears Task Manager's CPU%: an obituary for the recent past Linux 7.1 will have an optional new NTFS driver Microsoft releases Windows Server update to fix April update 20-year-old Enlightenment E16 bug finally gets patched 20-year-old Enlightenment E16 bug finally gets patched Raspberry Pi OS ends open-door policy for sudo Firefox Nightly adds Web Serial after years of saying no Windows Update: Torture chamber for seldom-used PCs Windows Update: Torture chamber for seldom-used PCs Notepad loses Copilot icon as Microsoft gives subtlety a try Notepad loses Copilot icon as Microsoft gives subtlety a try Microsoft attempts to untangle Windows Insider program Adobe finally patches PDF pest after months of abuse NHS pays £46K to prep next Microsoft licensing round Linux 7.0 debuts as Linus Torvalds ponders AI's impact Linux 7.0 debuts as Linus Torvalds ponders AI's impact Red Hat RHELocates its Chinese engineering team to India Showing the Windows 10 desktop was the yeast they could do Apple's chips are winners, but Windows fails help it most The end of Linux i486 support looks nigh The end of Linux i486 support looks nigh Windows asks a networking question on a Stratford billboard Some 'broken by update' PCs were already doomed SystemRescue 13 lands with Linux 6.18 and bcachefs support Memo: Red Hat Global Engineering plans to lean in to AI Microsoft plans another out-of-band Windows fix Ubuntu beta arrives with GNOME 50, sans Google Drive support Ubuntu beta arrives with GNOME 50, sans Google Drive support Microsoft pulls Windows update after installation problems Microsoft pulls Windows update after installation problems Microsoft cracks down on old Windows kernel drivers Microsoft cracks down on old Windows kernel drivers Linux kernel czar says AI bug reports aren't slop anymore How Windows 95 fought off badly behaved installers Open source isn't a tip jar – it's time to charge for access Age checks creep into Linux as systemd gets a DOB field Systemd-free antiX 26: Debian 13, in bonsai form Systemd-free antiX 26: Debian 13, in bonsai form Windows boss promises to heal the operating system's wounds Windows boss promises to heal the operating system's wounds Smart TVs and voice assistants are the next gatekeepers Microsoft releases emergency fix for account internet error Microsoft releases emergency fix for account internet error Microsoft: Removing some Copilots will improve Windows 11 WSL, WINE updates speed cross-OS app performance MS update kills Microsoft account sign-ins in Windows 11 GNOME 50 debuts with X11 axed, Wayland front and center Microsoft publishes a workaround for Samsung's C:\ drive woes Systemd 260 kills SysV, tells AI not to misbehave Out-of-band getting out of hand as Microsoft pushes hotpatch for Bluetooth Microsoft pushes out-of-band hotpatch for Bluetooth Big moves in Linux filesystems as new bcachefs lands and KDE adds support for Apple's APFS Age verification isn't sage verification when it's inside operating systems Age verification isn't sage verification inside OSes Microsoft points at Samsung after Galaxy app bug locks users out of C:\ Nanny state vs. Linux: show us your ID, kid Smart mirror shows dumb Windows in elevator Microsoft adding Xbox mode to Windows 11 – even the Professional edition DR-DOS rises again – rebuilt from scratch, not open source Hotpatching goes default in Windows Autopatch whether you like it or not Hotpatching goes default in Windows Autopatch Linux PC vendor System76 tries to talk Colorado down over OS age checks System76 tries to talk Colorado down over OS age checks US state laws push age checks into the operating system Microsoft finally gets around to fixing Windows 10 Recovery Environment after breaking it in October BunsenLabs Carbon keeps the CrunchBang flame alive with Debian 13 Bootleg Windows, Office scheme crashes, triggers 22-month lockup for Florida woman
RAM is getting expensive, so squeeze the most from it
2026-03-13 · via The Register - Software: OSes

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 zram tool has been in the news this week. Phoronix reports that the 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 got much more expensive and the price rises are expected to continue. Apple has even 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.

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 zswap.

Both work with Linux's existing 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.

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.

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 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. Perlod's guidelines seem reasonable:

Zram

Thinking about where swap is, and how much, is where zram comes in. As is often the case, the Arch wiki explains it well. Zram creates compressed dynamic RAM disks. "Dynamic" meaning they grow only as they fill up, and "compressed" means with 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 Latency Numbers Every Programmer Should Know on GitHub, and a humanized version that expresses the time differentials in terms more meaningful to 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 used memory compression since 10.9, and Windows 10 gained the feature in 2015 in 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.

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 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 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: the zswap compressed swap cache.

There's a short sharp 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 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 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 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 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 others find the same.

We know a lot of people also advocate encrypting your machines' drives, especially laptops. We feel that 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 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. ®