Discussion
Chris Down
nephanth: I used to put swap on zram when my laptop had one of those early ssds, that people would tell you not to put swap on for fear of wearing them outSetup was tedious
jitl: thank goodness Kubernetes got support for swap; zswap has been a great boon for one of my workloads
patrakov: User here, who also acts as a Level 2 support for storage.The article contains some solid logic plus an assumption that I disagree with.Solid logic: you should prefer zswap if you have a device that can be used for swap.Solid logic: zram + other swap = bad due to LRU inversion (zram becomes a dead weight in memory).Advice that matches my observations: zram works best when paired with a user-space OOM killer.Bold assumption: everybody who has an SSD has a device that can be used for swap.The assumption is simply false, and not due to the "SSD wear" argument. Many consumer SSDs, especially DRAMless ones (e.g., Apacer AS350 1TB, but also seen on Crucial SSDs), under synchronous writes, will regularly produce latency spikes of 10 seconds or more, due to the way they need to manage their cells. This is much worse than any HDD. If a DRAMless consumer SSD is all that you have, better use zram.
cdown: Thank you for reading and your critique! What you're describing is definitely a real problem, but I'd challenge slightly and suggest the outcome is usually the inverse of what you might expect.One of the counterintuitive things here is that _having_ disk swap can actually _decrease_ disk I/O. In fact this is so important to us on some storage tiers that it is essential to how we operate. Now, that sounds like patent nonsense, but hear me out :-)With a zram-only setup, once zram is full, there is nowhere for anonymous pages to go. The kernel can't evict them to disk because there is no disk swap, so when it needs to free memory it has no choice but to reclaim file cache instead. If you don't allow the kernel to choose which page is colder across both anonymous and file-backed memory, and instead force it to only reclaim file caches, it is inevitable that you will eventually reclaim file caches that you actually needed to be resident to avoid disk activity, and those reads and writes hit the same slow DRAMless SSD you were trying to protect.In the article I mentioned that in some cases enabling zswap reduced disk writes by up to 25% compared to having no swap at all. Of course, the exact numbers will vary across workloads, but the direction holds across most workloads that accumulate cold anonymous pages over time, and we've seen it hold on constrained environments like BMCs, servers, desktop, VR headsets, etc.So, counter-intuitively, for your case, it may well be the case that zswap reduces disk I/O rather than increasing it with an appropriately sized swap device. If that's not the case that's exactly the kind of real-world data that helps us improve things on the mm side, and we'd love to hear about it :-)
adgjlsfhk1: can you make a follow-up here for the best way to setup swap to support full disk encryption+hybernation?