Debunking zswap and zram myths
38 points by javierhonduco
38 points by javierhonduco
There is no link but this seems to be the article referred in the quote. https://chrisdown.name/2018/01/02/in-defence-of-swap.html
What a surprise to find out cdown has a blog. I accidentally paged Chris as an intern at Meta in 2019, there was a wiki article telling you to run the IRC command !chirp cdown test (Chris was on webfoundation at the time) to test out sending a page. It was 9pm his time, and he was kind enough to get online, explain what I had done, and update the wiki page to show the current employee's username instead of his.
I ran both zram and zswap for some time without issues, but after some updates it frequently locked up in OOM situations. I disabled zram for now and set
echo 1000 > /sys/kernel/mm/lru_gen/min_ttl_ms
This seems to make the OOM trigger fine again.
In current year I'm obviously not using a disk swap at all, yet it sort of sounds like zswap would be architecturally preferable? Could I use zswap in front of a small ramdisk? Or should I stick with zram
In current year I'm obviously not using a disk swap at all
I wouldn’t say it’s obvious at all (especially if Chris Down is enough of an authority for you to consider his advice that you just read). The same author wrote In defence of swap, after all.
I have basically two kinds of systems:
Ones with 16GB RAM or more. So the RAM is never full, swap is always empty, and having swap set up just wastes disk space. Obviously also no need for zram here.
Ones with less RAM, and only an SSD, so if swap got used it would kill the drive.
So yeah I'm sure there's some use case for disk swap out there, but I haven't had one in at least a decade.
Something like an SD-card or a flash drive would indeed wear out pretty quickly, so this is a real concern for raspberry PIs, but for proper SSD storage swap is fine, especially with trim.
Check the stat sheet of your drive. They're usually rated something like 3-5 years of having something between 0.5-10x of drive's total capacity written to them every single day (DWPD).
FWIW, here's the most worn drive I have in prod. It has seen 2.5 years of sustained around the clock I/O. Wear isn't linear, so I doubt it has 20 more years into it, but probably at least 4-5 good years I'd estimate.
Percentage Used: 9%
Data Units Written: 3,669,708,888 [1.87 PB]
Power On Hours: 21,752
You have to have some legendary page thrashing before your get anywhere near this sort of I/O.
Ones with 16GB RAM or more. So the RAM is never full, swap is always empty, and having swap set up just wastes disk space
Or you can put it on a discard'ed partition and consider it a form of so-called "overprovisioning" (aka giving your SSD's FTL some guaranteed breathing room), if what you said is true about RAM being never full (what, not even by page cache?).
But I doubt the validity of the premise.
Ones with less RAM, and only an SSD, so if swap got used it would kill the drive.
I'm afraid that's an actively harmful misconception. After all, what would you put a swap on, if not an SSD?
...Besides, there's still a broken reasoning chain between here and "therefore, I can't use zswap". If your only reason for not using disk swap is that you're concerned about SSD's longevity (let's just assume it's a valid concern, even though it isn't), then you should set up disk swap anyway and enable zswap — it'll intercept 80+% of swapouts and your disk will be perfectly safe from an imaginary threat.
Either way — nothing "obvious" about not using a disk swap, regardless of the current year. I grant there are some narrow use-cases for such a setup, but more often that not it simply indicates a misinformed decision.
what would you put a swap on, if not an SSD?
Spinning disk, where infinite churning writes are safe.
Whether or not swap is useful on a given system is very workload dependent.
Although I have always had some swap enabled on my desktops/laptops over the decades, it is very rare for any swap to actually be used.
However, almost every server I have ever been in charge of has benefitted from having swap. Lots of software is not very efficient with physical memory usage (looking at you, every Java web service) and tends to have plenty of pages that are very rarely touched which can be safely swapped out to disk in order to free up valuable physical RAM for other applications. (Or more importantly, buffers and cache!) In these cases, having swap is a significant performance enhancement on systems where you would otherwise have to double the amount of physical RAM in the system to get the same performance.