Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
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. – Tamás Szelei Jun 16 '11 at 18:59
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
@Nicholas, absolutely correct – Uri Herrera Jun 17 '11 at 6:52
@TheX: maybe in some years when people see your comment they will laugh :) – Benoit Jun 17 '11 at 8:57

19 Answers 19

up vote 112 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

share|improve this answer
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). – Tamás Szelei Jun 16 '11 at 22:24
@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
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
Space may be cheap on HDDs, but on SSDs it's hardly cheap; not as expensive as DAM, but still. – Mircea Chirea Jan 8 '12 at 15:36
If your systems use 31GB swap and you need the last GB, they will probably be very sloooow. IMHO if you constantly need more than 2GB swap you should install more RAM. – Martin Schröder Dec 13 '13 at 13:55

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 2012):

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            0.5 times the amount of RAM    1.5 times the amount of RAM
64GB of RAM or more           4GB of swap space              No extra space needed

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

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)

share|improve this answer
Upvote for the link to the FAQ, and for introducing some sanity amidst the opinions and anecdotal evidence. – Marty Fried Jun 24 '12 at 17:04
The point is there is no such large programs yet and your link saying just opposite of this. See this – Anwar Shah Oct 18 '12 at 16:48
To relieve memory from extra load, I'd prefer zRAM and swappiness=60 , rather than traditional HDD swap. – Barafu Albino Jun 30 '13 at 7:27

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.)

share|improve this answer
I have no swap at all and can hibernate/suspend my laptop just fine. – scribu Jun 17 '11 at 9:05
@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
It is quite possible to hibernate with 16gb of ram and 4gb of swap: you just need to be using less than 4gb when you go to hibernate. – psusi Jun 24 '12 at 3:48

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

share|improve this answer

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.

With that said, the rule of twice as much memory ram should not apply on Linux based systems, even more so if you have more memory. You should however have the same size of swap equal to your ram size of you arr planning to hibernate, since the process of hibernation grabs everything in ram and puts it on swap, which is why you need a minimum size equal to your ram size for swap.

The other detail is that some apps (not all) will still force to read from swap. So having a bit is good. Disabling it altogether is very bad in the case you get to the point of out of memory or OOM. At this point if you do not have swap, there is no way the kernel can swap in/out different ram app usages and will eventually start killing the less used ones.

If it helps with home desktop decision making, after updating this answer in more than 4 years, I have used a 16gb, 32gb and now a 64gb ram PC. Testing with only 128MB of swap revealed that I had no need for larger swap except if I wanted to hibernate. I have used cloud environments on them, lxc, virtualbox, wine, you name it. I have rendered videos with openshot, kazam, handbrake, audacity. I have used gimp, blender, Inkscape and even the full LibreOffice suite. I even played on steam and in none of those scenarios the swap wad used. It will eventually be used if you end up using the full ram amount but if you ate able to not get there, you have the option to not having such a huge swap.

Just my 2 cents.

share|improve this answer

In most cases, I'd say you don't need any at all. Perhaps if you edit very large image files, or some other app that needs lots of ram, you might need some.

I've never seen any used at all on my system, similar to yours. In fact, at one time, I had it disabled for a week or two accidentally, and never noticed any problem. But I still keep about 5GB for my swap drive, mainly because I have over 1TB available, and don't use all the space as it is.

share|improve this answer
I remember seeing it used once, when I used Wubi and I hibernated. – Vladashram May 13 '12 at 2:05
If you use hibernation, that may be a good reason to have enough swap space to save the machine's state. I'd guess you would never need more than the amount of available memory, unless perhaps you are using enough at the time to be using swap space already. – Marty Fried May 13 '12 at 2:16

If your ram is higher than 1GB, it is usually enough for ubuntu. The "Swap = RAM x2" rule is for old computers with 256 or 128mb of ram.

So 1 GB of swap is usually enough for 4GB of RAM. 8 GB would be too much.

share|improve this answer

If you use hibernation your swap should have at least the same amount as your physical ram.

share|improve this answer

If you use hibernate, it's safe to have as much swap as your amount of RAM.

For a general rule of thumb on how much swap to have, read here:

In your case I'd say 4 GB would be enough to match your RAM.

share|improve this answer

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

share|improve this answer
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

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.

share|improve this answer

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.

share|improve this answer

Keep this in mind -

You should typically size your swap space to approximately 2x main memory for systems with less than 2GB of RAM, or approximately 1x main memory if you have more

So If you have 4 Gb ram you should never ever need swap unless hibernating
Swap required would be around 3 - 3.5 Gb, not more than that.
So use your common sense and dont waste disk space

share|improve this answer
@AnwarShah -Srry i didnt read that. edited my answer – Ashu May 13 '12 at 7:05

If you're building very big files, say for instance if you're building machine translation systems on a laptop (yea ok why would you wanna do that? I for one can say that my professors are making me ;-)) the answer is a clear yes, actually at this moment I'm regretting not making it 32GB swap....

For casual use of Ubuntu for office work and internet no you're never going to use even 2 GB of swap but in reality there is no clear answer, it all depends on what you are going to do on your computer...

share|improve this answer

I have a laptop with 4GB of RAM and Ubuntu 16.04. After boot it consumes around 1GB of RAM and even then Inkscape (for example) won't run (System monitor shows more than 50% of free RAM). Inkscape freezes After I apply a swap file it runs as expected, even with no one single byte of swap being used).Inkscape running So I recommend a swap partition (or swap file). About the size of it, you can use david6 rule.

share|improve this answer

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.

share|improve this answer

If it is a laptop then keeping at least the swap equal to the amount of RAM, to fully allow hibernation. I would still keep an amount equal to the amount of RAM even if a desktop, but that is just me; it will get little use in a desktop.

share|improve this answer

Too much information, and variance in opinion.

My suggested Ubuntu desktop guidelines:

 amount of RAM      recommended swap    with hibernation
----------------    ----------------    ----------------
 less than 4GB        2x RAM size         3x RAM size
   up to 8GB              4GB             2x RAM size
   up to 16GB             4GB            1.5x RAM size
  16GB or more            4GB           No extra needed
share|improve this answer

protected by Braiam Feb 28 '14 at 1:18

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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