I wanted to just confirm how much the size of Swap partition should be. Lots of places tell that the swap size should be twice the size of RAM. Somebody also told me that it shouldn't be more than 8 GB.If twice the size of RAM is more than 8 GB how big should the Swap partition be?

  • 5
    I'm voting to re-open this question because none of the existing answers explain any of the why and are outdated if we look at 1GB or RAM and up, while this one does. – David Foerster Feb 28 '16 at 15:01
  • 1
    @Fabby I'm removing that antiquated banner - when this gets closed again, it will get a new proper dupe notice. – muru Jan 1 '17 at 11:52

The text below was obtained from the nixCraft page Linux: Should You Use Twice the Amount of Ram as Swap Space?. (Please follow the link and read the source for more information)

Note that nixCraft page cites text purportedly coming from the OpenBSD FAQ, but there is no matching text in the current document; this may however be something that used to be in there in 2006 (so the 2 x RAM rule was already obsolete more than 10 years ago):

Nonsense rule: Twice the size of your main system RAM for Servers

According to OpenBSD FAQ:

Many people follow an old rule of thumb that your swap partition should be twice the size of your main system RAM. This rule is nonsense. On a modern system, that's a LOT of swap, most people prefer that their systems never swap. You don't want your system to ever run out of RAM+swap, but you usually would rather have enough RAM in the system so it doesn't need to swap.

More from the nixCraft page:

Red hat recommends setting as follows for RHEL 5:

The reality is the amount of swap space a system needs is not really a function of the amount of RAM it has but rather the memory workload that is running on that system. A Red Hat Enterprise Linux 5 system will run just fine with no swap space at all as long as the sum of anonymous memory [memory mapping without file or device backing it: memory obtained from the OS stack and heap] and system V shared memory is less than about 3/4 the amount of RAM. In this case the system will simply lock the anonymous and system V shared memory into RAM and use the remaining RAM for caching file system data so when memory is exhausted the kernel only reclaims pagecache memory.

Considering that: 1. At installation time when configuring the swap space there is no easy way to predetermine the memory a workload will require, and 2. The more RAM a system has the less swap space it typically needs, a better swap space [might be along this recommendation for CentOS Linux 7.x and RHEL 7]:

Recommendation for Swap Space in RHEL/CentOS 7

And so the nixCraft page concludes:


If Linux kernel is going to use more than 2GiB swap space at a time, all users will feel the heat. Either, you get more RAM (recommend) and move to faster storage to improve disk I/O. There are no rules, each setup and configuration is unique. Adjust values as per your requirements. Select amount of swap that is right for you.

Furthermore, this Red Hat article: Do we really need swap on modern systems? (2017) says:

Our size recommendation for most modern systems is ‘a part of the physical RAM’, for example, 20%. With this, the painfully slow phase of operation in our example will not last as long, and the OOM kicks in earlier.

Of course, there are scenarios when different behaviour is desired. When aware of the behaviour, such swap configurations are ok, as well as running the system without any swap. Such a system is supported by us as well - but the customer should know the behaviour in the above situations.

  • Please describe the link. – N.N. Sep 19 '11 at 9:18
  • I just added excerpts from the source link that the answerer provided. @A T: Next time, please add atleast an excerpt from the source your are referring to or describe it. – Nitin Venkatesh Sep 19 '11 at 9:42
  • you know, there is no such paragraph in the linked OpenBSD FAQ... – pqnet Aug 6 '14 at 14:38
  • 1
    @pqnet Yes indeed. Updating... – David Tonhofer Jan 31 '19 at 16:50
  • If you are working on an Azure VM (or even at home), put the swap on an SSD. See What are Resource Disks in Microsoft Azure? – David Tonhofer Jan 31 '19 at 17:23

The only hard rule for swap space I know of is 1x RAM to Hibernate. The System Monitor or CLI free command will tell you how much swap space you're using with your particular hardware configuration and usage patterns. With 2GB of RAM my system rarely uses any swap space at all and never more than .4GB that I've seen.


Swap isn't something you want to use. It's something you want to have as a last resort because swap isn't fast, it's dead-slow. And if you are using like 1 GB of swap then your system will be really slow to respond.

The whole point of SWAP memory is to not have a system crash when you run out of available RAM. It's not something you can use as extra memory or something you really want to use, unless you really really have to.

So for size, I would say 5 GB but if you are really doing heavy stuff that uses a lot of RAM then you could go up to 8 GB. But really if you start using more than 1 GB of swap, start killing process's. so you DON'T have a crash.


Normally you don't want (and shouldn't) use the swap that much, so yea, more than 8 gb seems like a lot. I have 8 gb of RAM on my desktop and a 8 gb swap, I don't think I ever used more than 1 gb of swap. The 2x rules makes sense for low amount of RAM but it gets a little crazy with ~6+ gb of RAM.

Of course it depends on what you're doing with your computer...

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