I read many places that the rule of thumb for swap space is to double the amount of physical RAM. However, 32 GB does seem a LOT. Do I need that much? Do I need it at all with this high amount of physical RAM?

link|improve this question

57% accept rate
33  
to be completely honest here... you don't even need SWAP, you already have 16GB of RAM unless you seriously think you will ever run out of RAM, you don't need it. – Uri Herrera Jun 16 '11 at 18:55
Thanks Uri, I think you can add this as an answer, so I can accept it unless someone comes by and proves otherwise :). This is what I thought, I just wanted to be sure. – fish Jun 16 '11 at 18:59
14  
Lol I am envious of your large amount of RAM. – TheX Jun 17 '11 at 2:54
19  
That "rule of thumb" originated at a time when most PCs had RAM in single-digit megabytes. It hasn't been meaningful for 10+ years, but it just...won't...die! – Nicholas Knight Jun 17 '11 at 6:21
12  
@TheX: maybe in some years when people see your comment they will laugh :) – Benoit Jun 17 '11 at 8:57
show 2 more comments
feedback

10 Answers

up vote 35 down vote accepted

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

link|improve this answer
2  
Can you elaborate why said no to zero swap? Others seem to agree that there's no need for it unless I want to hibernate (which I don't). – fish Jun 16 '11 at 22:24
I agree it depends on the application, but if that application would require 8Gb of SWAP in an 8Gb RAM system, it requires no SWAP in an 16 RAM system, I would say. – Jochem Jun 17 '11 at 13:26
@popey - So what then if the system runs out of swap? Back to square one, there. – Michael Kjörling Jun 17 '11 at 14:11
@popey. thanks for the info. But what do you mean by "you will lose data"? – db42 Jun 17 '11 at 14:48
2  
Having a system with 8 GB of RAM, I can say this: any time I have had a program run away and dip into swap, my system will become mostly unresponsive. It's better to let the OOM killer run than to have to force an unclean reboot anyway; if you have that much RAM, unless you're doing very very heavy work that requires gigabytes of RAM, you'll be fine. Even when you do have heavy lifting, there's usually a way to process it that doesn't require swap space (which is less efficient than sane large-dataset handling in the application itself). – Michael Trausch Jun 20 '11 at 3:59
show 2 more comments
feedback

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.

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 
link|improve this answer
23  
The square root of the RAM in GB, rounded up to a power of two. – starblue Jun 17 '11 at 7:57
feedback

to be completely honest here... you don't even need SWAP, you already have 16GB of RAM unless you seriously think you will ever run out of RAM, you don't need it

link|improve this answer
12  
... Unless you want to hibernate/suspend to disk :). – crazy2be Jun 17 '11 at 3:39
7  
which he doesn't want to... – Uri Herrera Jun 17 '11 at 5:05
5  
how do you know that? He doesn't exclude that anywhere. – Christoph Jun 17 '11 at 7:24
3  
I'd avoid having no swap at all, at least to have some time to identify an issue and kill a process before the OOM killer of the kernel take automatic actions... but that could just be useless. – sylvainulg Jun 17 '11 at 10:32
3  
@Christoph -- ... need for it unless I want to hibernate (which I don't). – Tamás Szelei – Uri Herrera Jun 17 '11 at 17:39
show 1 more comment
feedback

Probably not. If you plan to hibernate your computer (suspend-to-disk) then you'll need at least 16 GB. If you won't hibernate, it is enough to let a few gigabytes for swap (4-8 max.)

link|improve this answer
1  
I have no swap at all and can hibernate/suspend my laptop just fine. – scribu Jun 17 '11 at 9:05
4  
@scribu this sounds interesting. I suspect that there is maybe a swap file somewhere because for completely powering off your laptop (i.e. unplug and remove battery) the contents of the RAM must be saved – bandi Jun 17 '11 at 20:34
feedback

No, you don't need 32 GB as long as you don't use features like suspend to disk.

link|improve this answer
feedback

You only need swap if you want to use hibernate for the rest it is a wast of space on your harddrive.

link|improve this answer
3  
Hibernate need swap space but not as bi as the RAM size, only as big as RAM usage at the moment of hibernate. Sleep do not need any swap, because the RAM is still active and hold the data. – Donny Kurnia Jun 17 '11 at 4:11
@Donny Kurnia thank you I didn't know that. But my laptop likes to use swap when it goes to sleep. I look if I can edit it. – Rens Jun 17 '11 at 6:14
you can do experiment by disabling the swap sudo swapoff -a then sleep your laptop. – Donny Kurnia Jun 20 '11 at 7:56
@Donny Kurnia I've did it and sleep does still work. – Rens Jun 20 '11 at 15:11
feedback

I think you got it the other way round. SWAP Recommendation, you would need ~16GB. So SWAP should be 1/2 of the actual RAM size. But still thats a LOT of space. Depends what you need it for. I'd say, if you don't use "hibernate", keep around ~4GB to ~8GB if you can afford the disk space. Since you have 16GB, I assume you may be using a computer which needs powerful resources... so maybe it might be beneficial to have 16GB to 32GB SWAP as well.

I have 2GB RAM and 1GB SWAP. I do pretty much fine with it, but that's just my opinion. Look at the other comments/suggestions and see what they say.

link|improve this answer
feedback

I could not find references to quote here, but if you are going to use an application where you need to swap out entire data in RAM, you would atleast need 'RAM size+128 MB' or '1.25 times of RAM Size' (i forgot which one was correct) assuming you have RAM more than 2 GB. If RAM is 2GB or less, it is recommended to have twice RAM size as swap.I followed this recommendation in my previous organisation for IBM AIX based on a document from IBM. I believe this holds true for most of *nix since the use of swap is move data from RAM safely in case RAM is not enough to handle the data to be loaded in memory. 'free' command can be used to evaluate how much swap is used in reality.

link|improve this answer
feedback

From experience I can say this:

For what I have seen using 4GB of ram for 3 years, Ubuntu has had a swap usage of around 60MB but only when doing some very intensive tasks. A couple of weeks ago I started using a PC that had 16GB of ram and the swap usage has stayed in 0% for ever. I have done multiple compiles, video rendering and other intensive tasks. There has never been a change in swap. Not even a 1KB change.

Basically, in Ubuntu, the more memory RAM you have, the less likely you will use or need swap for any task. 16GB of ram, or even 8GB of ram is more than enough. I have done with the 16GB PC 8 Virtualbox PCs (each between 1GB to 2GB of ram). I have compiled and rendered a 720p video and not even in those conditions has the swap changed.

link|improve this answer
feedback

I have a Mac laptop, which I leave on for months. Although much better than Windows, memory does creep in, particularly with your browser, if you keep it up. So eventually, memory fills up. Now if you have swap, as other people have noted, you can survive, notice and kill something. But more to the point, if you have swap, some pages get swapped out and you can keep going.

So if you're planning on leaving the machine up for a long time, swap is a handy way to free up memory from zombie junk. Granted it will take you longer to fill up 16g than me with 3gb, but it's still nice. For this purpose, 4Gb will do.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.