3 ms·
You can absolutely turn it off. I've been running with swap turned off on all of my desktop systems (Linux, Unix and Windows), and some servers, for over 20 ye
by blihp 7y ago
You can absolutely turn it off. I've been running with swap turned off on all of my desktop systems (Linux, Unix and Windows), and some servers, for over 20 years.
The theoretical worst case scenario is that the system hits an OOM situation and you end up with data/filesystem corruption... I have not had this occur due to swap being turned off this century.[1] The typical worst case scenario is that either due to a runaway process or accidentally overloading the system for a indefinite period of time, the system goes completely unresponsive so you have to perform a hard reboot. This happens to me 1-2 times a year but I have yet to loose any data (and if it ever does, that's one of the many reasons to have backups) The more common scenario is that a runaway process will OOM briefly, when it can't allocate the memory it needs crash, and everything is back to normal within a couple of seconds.[2]
FWIW, mobile (Android and iOS) devices typically run without swap just fine. IMO, this 'always enable swap' is bad advice and dates from a time when very bad things could and did happen if you OOM'd a system. The marginal performance improvement from freeing up on the order of megabytes (or even tens of megabytes) of RAM on a system with double digit GB's of RAM makes absolutely no sense to me. It makes even less sense on SSD systems where you would be unlikely to notice a chronic swapping situation until you had severely shortened the life of your SSD.
[1] This would be a good reason to not turn off swap on a production database server where it is more likely to be an issue, for example.
[2] One of the dubious advantages to 'modern' programs not handling errors like OOM is that, since they don't check for it, they can't handle when it happens and just crash. This was actually more of a problem in the 90's and earlier when it was more common for applications to handle OOM situations which could actually make the problem worse since they would often hang around waiting for any memory to be freed and use it which resulted in a persistent OOM situation.