Why is it recommended that the swap partition size be double that of the RAM size?

Specifically, why would I need to store data stored in the RAM twice??


Swap partition having double the memory size is just a general guideline, not a hard and fast rule. You'll need minimum 1 X your memory size if you suspend-to-disk (hibernation), and add enough spare for usage of 'swapped' memory which goes beyond your physical one. Hence the recommended 1.5 to 2 times.

I would think it also depends on the nature of your application usage and size of your physical memory etc. If you have anything beyond 2GB RAM and using non-memory intensive applications most of the time, you might not need swap partition at all, not big one anyway.

Having a big swap file and slow harddisk can be really punishing for your system too.

Here are a few useful reads:

Ubuntu SwapFAQ
SUperuser - Swap partition size for 4GB RAM
Do I Need a Swap Partition and If So, How Big?

  • 2
    Slow or not, it's always better to have a swap just in case, even if you don't need it, than risking running out of RAM with no swap available.
    – Don
    Feb 21 '10 at 10:52
  • @Don, yea I agree it is safer to have swap partition. :)
    – o.k.w
    Feb 21 '10 at 11:49

That's an old rule of thumb that I don't think makes sense anymore, because nowadays, that may equate to an absurd amount of swap in relation to the speed of the storage.

The minimum amount of swap you should have is your typical steady state usage. (That's the amount reached after long uptime, when most of your available memory consists of page cache. The defence of swap is a good read.)

But I'm here to tell you there's a maximum too … if responsiveness is a concern at all.

Desktop scenario: Typically, what happens when you run out of memory (such as when accidentally setting off a fork bomb like make -j) is this: First, you notice a bit laggy user interface, which means, you have roughly a minute to kill the offending process, before the mouse pointer becomes unresponsive. But that's only the start! You see, then, the computer is going to sit there with its SSD LED constantly lit, churning through the rest of its swap space, for tens of minutes to hours, while you can do nothing (except maybe pulling the plug). At this point, you are going to swear you wanted the OOM killer to kick in a bit sooner, instead of wasting your day.

So having a ridiculous amount of swap space that you don't normally use is actually bad from an availability standpoint — it just delays the inevitable in the event of a catastrophic memory leak (such that OOM is inevitable), during which time your computer is, for all practical purposes, unavailable.

I usually go for ½-2 GiB swap regardless of how much RAM the computer has.


Specifically, why would I need to store data stored in the RAM twice??

The swop is simply for freeing up system memory. If you begin to run low on memory the system will free up memory by moving the least used data from memory onto the hard disk swap file. This of course has a speed penalty but it frees up memory for other applications.

With memory being so cheap you are always better off to have as much as you can afford. This way the swap gets very little access and your system stays nice and fast.


With a larger swap space, programs can use more RAM than is present on the computer. This is possible because even if the data takes up more space than fits in the physical memory at once, it cannot all be accessed at once - the swap is pulled into physical memory as it is needed. The alternative is to have programs randomly killed when memory runs out. This is particularly useful if you want to edit high resolution images or videos, or do 3d modeling or rendering, or run numerical analysis on large amounts of data, there are many kinds of programs that end up wanting insane amounts of RAM, where it is better to be able to have it run very slow than to have it unable to run at all without crashing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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