I have 16GB RAM. Do I need 32GB swap?
Here's a very good recommendation from RedHat: Recommended System Swap Space
An excerpt from the same link:
In years past, the recommended amount of swap space increased linearly with the amount of RAM in the system. But because the amount of memory in modern systems has increased into the hundreds of gigabytes, it is now recognized that the amount of swap space that a system needs is a function of the memory workload running on that system. However, given that swap space is usually designated at install time, and that it can be difficult to determine beforehand the memory workload of a system, we recommend determining system swap using the following table.
Current table (as of December 2017):
Amount of RAM in the system Recommended swap space Recommended swap space
if allowing for hibernation
--------------------------- ---------------------------- ---------------------------
2GB of RAM or less 2 times the amount of RAM 3 times the amount of RAM
2GB to 8GB of RAM Equal to the amount of RAM 2 times the amount of RAM
8GB to 64GB of RAM At least 4 GB 1.5 times the amount of RAM
64GB of RAM or more At least 4 GB Hibernation not recommended
Original table:
Amount of RAM in the System Recommended Amount of Swap Space
4GB of RAM or less a minimum of 2GB of swap space
4GB to 16GB of RAM a minimum of 4GB of swap space
16GB to 64GB of RAM a minimum of 8GB of swap space
64GB to 256GB of RAM a minimum of 16GB of swap space
256GB to 512GB of RAM a minimum of 32GB of swap space
It entirely depends on what you plan to do with the machine. For example if it were a Sap server then yes, I would add 32gb swap ( we have boxes at work with 128gb ram and 32gb swap ). If you were manipulating massive pictures and video then it makes sense to have a little swap. 32gb is probably overkill.
However I would not say zero swap.
In the unlikely event that you run out of RAM - perhaps opening a big file, perheps a long running tab in firefox, it doesn't matter, in that event your kernel OOM killer will kick in and start killing applications to get memory back. Under those circumstances it's entirely possible that you will lose data as applications get killed. However if you have a bit of swap then the system will carry on, grabbing swap and allowing the system to continue. System slows down as heavy swapping happens, you notice and investigate before all swap exhausted. Also disk is very cheap, so why not have swap?
Anyone who says "you don't need swap" without asking you what you're actually doing with your computer is making assumptions. Whilst you may well do very little with your computer that eats RAM, it's still best to ask the questions about what you're planning to do with it before making the rash judgement that you don't "need" swap. In my humble opinion
Argh. The answers on this post are so very wrong, and this comes up as one of the first results in a Google search for "How much swap?"
First, a good point of reference is the Ubuntu Swap FAQ
This FAQ makes an important point that no one here mentions, and that is (emphasis mine)
Sometimes, a large program (like OpenOffice, Neverwinter Nights, or a video editor) make the entire system need extra memory. A significant number of the pages used by these large programs during its startup may only be used for initialization and then never used again. The system can swap out those pages and free the memory for other programs or even for the disk cache. In these cases, swap will be used to help the system handle any extra load.
So, swap is not just for hibernation! This activity, swapping out unused pages, can be beneficial in some scenarios and detrimental in others. Beneficial because it can free up memory for the system to use elsewhere, but detrimental when that swap out is too aggressive, and swaps out pages you actually do want. This is especially true on a desktop system where applications can sit idle for long periods of time, but the user still expects immediate performance when bringing it back to life. The control for how aggressive this is, is referred to as swappiness
The Ubuntu Swap FAQ discusses this lightly under What is swappiness and how do I change it? The default value on an Ubuntu system is 60, while the FAQ recommends a value of 10 for a desktop machine.
So, I would say that it is generally very important to not have a system with absolutely no swap space, as some people were recommending on this question, unless you know for certain very specific usage scenarios for your system and are very aware of the consequences it could have. (Personally, there is no situation where I would run a system without swap) In an Out of Memory scenario with no swap, the system will start killing processes (generally the one that caused the OOM)