In defense of swap: common misconceptions (2018)
(The article is from 2018.)<p>I think the article is strongly from the point of view of what to do &quot;in production&quot;. If you have a bunch of servers with known specialized workloads, I can believe that enabling swap is good for efficiency. You can run more tasks and get closer to the memory limit while remaining safe. Coming from a Facebook employee, this makes sense.<p>However, for individual development machines, the pragmatic situation is completely different. The truth is that in practice running out of memory stems from two types of human errors:<p>1. You wrote some code that leaks lots of memory quickly.<p>2. You used Google Chrome.<p>In either situation, still in 2022, Linux reacts in the following way:<p>A. With swap, your system becomes completely unresponsive for longer than you have patience for, so you power-cycle it.<p>B. Without swap, the culprit is immediately identified and killed. Your system is perfectly usable, aside from a killed process.<p>Note that depending on your distro, the good case B. may have become a bit harder to achieve recently: systemd-oomd now tries to eagerly detect OOM situations before the kernel, and when it does, it kills the offending process&#x27; whole cgroup! If you have gnome or kde, you&#x27;re good, but otherwise, this may terminate your session. This can be fixed with &quot;systemctl mask systemd-oomd.service&quot;