Should I completely turn off swap for linux webserver?

I would say it depends on your use case and the rest of the answers have covered this pretty well. 4G of swap are after all a cheap way to buy some safety. And I feel that this cheapness is what is making people not want to turn it off.

But let me answer with a rhetorical question. If money is not an issue, and you have a choice between two systems - one with 12G of RAM and 4G of swap, and another with 16G of RAM and no swap - which one would you choose? Unfortunately most people would still answer that they'd choose 16G of RAM and still add 4G of swap, which is missing my point.

And on another note, I personally find a swappy system worse than a crashed system. A crashed system would trigger a standby backup server to take over much sooner. And in an active-active (or load balanced setup) a crashed system would be taken out of rotation much sooner. A win for the no-swap system again.


It is NOT recommended to turn off swap even if you have enough memory. If your server needs more memory and it did not get it, it will crash. However, this can be prevented (to some extent) when you have a swap area.

Yes, your server performance will degrade when using swap, but at least it will be operational and accessible. Then, you can plan for adding more memory when needed if your server starts using swap.

I found this page talking about swap. Have a look at 3rd section.

Instead of turning off swap, you can control the swapiness.