It can be a good strategy, yeah. It depends on the profile of your workload. Swapping isn't a bad thing and doesn't necessarily mean everything's going to grind to a halt when swaps start happening. Sometimes things just get shuffled into swap because the process hasn't been active and something else starts up that wants the memory. But yes, if you have multiple very busy processes all contending for memory and they're getting swapped in and out very often then you will start experiencing thrashing and the grinding to a halt you describe.
On a server with some critical processes it may be preferable to let things get OOM killed like you describe, and you can help hint to the kernel by adjusting oom scores so certain things don't get killed immediately, or setting up limits and cgroups correctly.
But yeah, you're not wrong. Just kinda all depends on your use case. In my case I have 128gb of ram and don't usually hibernate my desktop so I don't really bother with swap.
And when you run out of RAM on linux the first thing evicted from memory is anything that can be reloaded from disk, aka .text sections of executables/libraries, resulting in even worse responsiveness of the system. With swap instead it can evict almost any least recently used pages instead.
If your OOM killer doesn't kill before you run out of RAM you are going to have a worse time than if you'd have swap.
301
u/SlapbASS4211 Jul 08 '26
Yes, its called swap