6 ms·
This comes up every time swap is mentioned. Even if you have plenty of ram, having swap can help with performance. Why? Because the OS can page rarely used or
by anyfoo 5d ago
This comes up every time swap is mentioned.
Even if you have plenty of ram, having swap can help with performance.
Why? Because the OS can page rarely used or seemingly downright unused dirty pages to swap, freeing up precious RAM for caches.
I'd hazard a guess that especially if you run a ton of containers this can help, as there's probably a lot of memory getting dirtied on initialization of containers and their processes, which ends up never read afterwards.
I always set up swap, because sacrificing some disk space in potential exchange of free RAM, which is orders of magnitudes more expensive, is a nice prospect.
- lokar 5d agoWe looked at this a lot (it was a lot of money at our scale). A cgroup itself is just a few small data structures. And a reasonable process inside will only ever have a small amount of dirty memory it won’t ever use. Even then you can’t be sure of it packing neatly into whole pages. So, the typical saving is tiny, and the cost in unpredictable performance is quite bad. If you really do have an issue with “lost” dirty memory, your time is best spent addressing that directly.
- quectophoton 5d agoSomething I've never understood is why, say, 60GB RAM + 4GB swap is supposed to be faster than 64GB RAM + no swap. Or why 64GB RAM + 4GB swap is supposed to be faster than 68GB RAM. I get the hibernation argument, but not the arguments implying swap is always better. Actively using 60GB RAM and moving 4GB of unused pages to swap (60+4), is somehow faster than actively using 60GB RAM and keeping unused pages in the remaining 4GB RAM (64+0)? EDIT: If you prefer more round numbers, feel free to replace them with "32GB RAM + 32GB swap" and "64GB RAM + no swap" respectively.
- mitxela 4d agoThe actual choice is 32GB RAM + 32GB swap or 32GB RAM + no swap. This is because people already bought their RAM and disks by the time they make the decision, and aren't using the whole disk.
- quectophoton 4d agoI mentioned this in a response[1] to a sibling comment, but my question is more about learning what are the advantages of swap itself, other than just cheaper slow RAM. What does the OS do differently with swap vs RAM? What can I do with swap that I cannot do with RAM? Things like that. [1]: https://news.ycombinator.com/item?id=49670574 https://news.ycombinator.com/item?id=49670574
- mitxela 4d agoNothing besides having more of it. Apparently also hibernation, but that's more of an artificial limitation - there's no good reason a system couldn't create a hibernation file on demand.
- anyfoo 5d agoI’m not sure I understand. In your equations, why is swap taking away from RAM? It’s purely additive. Say you have 64GB of RAM, of which 4GB are dirty pages that are never, or at least very rarely, accessed. With 64GB RAM + 4GB swap, you filled up your swap with them and have 64GB RAM left to use actively. With 64GB RAM + 0GB swap, you only have 60GB RAM left to use actively.
- quectophoton 4d agoIn my examples nothing is taking away from nothing, I'm just asking if, if two situations have the same total amount of GB, what's the actual difference between RAM+swap vs entirely RAM. Use the 32+32 numbers if you're more comfortable with those round numbers. If I have a system running comfortably with 32GB RAM + 32GB swap (no OOM, no swap thrashing), and I upgrade to 64GB RAM + 0 swap, what actual negative effects would I be getting for the lack of swap? That's my question, to know if swap has any benefits other than being additional slow RAM.