4 ms·
If you care about performance you shouldn't be running from swap period. Swap is just a safety net.
by Rohansi 5d ago
If you care about performance you shouldn't be running from swap period. Swap is just a safety net.
- ssl-3 5d agoIt's OK to care about the performance of the safety net, too.
- fpoling 5d agoSwap is required for hibernation. And with fast ssd or properly tuned zram/zswap one can run task that use 10%-20% more memory than installed RAM. Surely there is a slowdown, but it is not that big especially when SSD can read write more than 5GB/s.
- MrDrMcCoy 5d agoSwap is so much more than a safety net and can increase performance if used correctly. See Chris Down's "In defense of swap" and follow-up that breaks down zram vs zswap.
- marginalia_nu 5d agoSwap actually helps with performance for the most part. Here's a good summary of what it actually does. https://chrisdown.name/2018/01/02/in-defence-of-swap.html https://chrisdown.name/2018/01/02/in-defence-of-swap.html TL;DR that swap shouldn't be seen as "spare RAM", but a mechanism for paging out anonymous pages, which is desirable in many circumstances in avoiding OOM situations and making memory management work better. It paradoxically typically reduces I/O thrashing.
- Rohansi 5d agoIt helps with performance by allowing your system to have more free physical RAM. And by free I mean for caches. It does this by moving data from inactive pages out of physical RAM. You shouldn't care about the peak bandwidth of zram vs. ordinary swap because latency matters more.
- CJefferson 5d agoI mean, are you saying ‘but more RAM?’ because obviously yes that’s true but not a solution if you already own a laptop, and have you seen ram prices? Also swapping to a fast SSD isn’t like it used to be on spinning discs. I’ve been amazed how responsive Mac neo laptops are and they are swapping all the time.
- Rohansi 5d agoI'm not saying to avoid swap. It is great at what it was designed to do. I only take issue with optimizing swap for bandwidth when it will never be able to keep up with RAM bandwidth. The MacBook Neo for example has 60 GB/s of RAM bandwidth but only 1.5 GB/s SSD bandwidth.
- ssl-3 5d agoObviously, running out of memory and resorting to swap (or other safety nets) is less than ideal. But why reject taking apparently-free steps to soften the blow? Is there some advantage in making sure that when the wall is hit, it is hit as hard as it possibly can be?
- Rohansi 4d agoBecause it wouldn't soften the blow. Swap benefits the most from improved latency not bandwidth. Data is moved from swap back to physical RAM when swapped out pages are accessed by software (which stalls the thread). The kernel has less insight into the memory access pattern to prefetch the next page so the stalls likely continue for each page it needs to restore. The latency of zram (compressed in memory) is still lower than the fastest SSDs which reduces those stalls.