5 ms·
Actually no - this is the situation that swap kills your system. That rarely used code path will now take 50 seconds because it got called when it was swapped
by lazide 4y ago
Actually no - this is the situation that swap kills your system.
That rarely used code path will now take 50 seconds because it got called when it was swapped out (and the system is under memory pressure), instead of either OOM’ing awhile ago or completing in a couple microseconds like it usually does.
And ‘infrequently called’ here could be every couple minutes.
- Dylan16807 4y agoIf the system is under such strong memory pressure despite swap then you already screwed up. And trying to run that much without swap would be even worse.
- morelisp 4y ago> And trying to run that much without swap would be even worse. No, swap makes it worse. In virtually all cases I’d rather die than stall or flap.
- Dylan16807 4y agoHaving no swap won't prevent stalling out. Systems can do that just fine by evicting necessary executable code over and over.
- lazide 4y agoOnly in a very, very tiny window. I’ve never seen a system sustain it for more than a trivial amount of time before it OOM kills something and then voila, enough memory. I’m sure someone here will chime in with their example though.
- Dylan16807 4y agoI mean, it happened to me twice in the last couple months on a laptop where I did a lazy install and didn't set up swap. Firefox and 2-3 smaller programs ate up so much memory that it stopped responding for multiple minutes and then went completely dead. I rarely need or set up much swap on a server, but I've managed to have the same kind of problem with the OOM killer not kicking in very quickly on a server. And on my desktops swap is able to soak up many gigabytes and improve my performance a lot with thrashing basically never happening.
- lazide 4y agoIt almost always happens at some point. Someone fat fingers a memory allocation. Memory leak from a long running process finally grows too big, someone installs an update and it doubles memory usage on something, etc. I had it happen recently that the backup/sync software for a NAS had a constant factor memory consumption based on the number of files it was syncing. Transferred in a bunch of data, and blam. Commercial NAS, and they used swap (shitty, never buy QNAP). Wedged so hard it took a hard power cycle to even get console, AND caused data corruption in the ZFS pools. It’s what happens next that decides the stability of the system. If it can grow into swap and keep going, things start crawling, load builds up, buffers expand, and the system eventually grinds to a halt. On Linux, often in a really wedged and irritating/impossible to fix way. Or, if no swap, OOM killer shoots something in the head (hopefully the offender), and we’re back to normal (minus the thing it killed, which is usually the thing you didn’t want it to - but at least the system works and you know something is wrong). In either case, caches have dropped to near zero awhile ago so performance is already getting bad. It’s if we enter a death spiral, or get death early enough the whole system doesn’t spiral.
- Dylan16807 4y ago> In either case, caches have dropped to near zero awhile ago so performance is already getting bad. Right. You can get pretty deep into a death spiral even without swap. I feel like the better-performing solution is to make OOM trigger earlier, and to then go ahead and have swap be on. Somewhat tangentially, I'd really like a setting for minimum disk cache, and that would do so much to help prevent thrashing.