One of our blog reader asked below question..

Q. Why we give swap partition in double the size of the RAM?

It has a meaning and for that we should know memory hierarchy. We have different levels of memory which is useful for processing your data. They are as follows.
Processor/CPU registers(Bit’s in size)
L1 Cache(kbs in size)
L2 Cache(MBs in size)
L3 cache(100s of MBs in size)
RAM(GB's in size)
suppose take one application which is in running state. The application data is moved to RAM for faster accessing and some of it’s data is moved to L3 cache for processing frequently used data and we move more frequently used app data to L2 and then L1. And we move data which is right now processed by your processor/CPU to registers which is present in processor. If you observe the memory size will gradually decrease when you go up in the ladder more frequently used data is kept at higher levels and made it self available for processing. So if suppose you want to load a bigger program which can consume all the ram/L3/L2/L1 cache it’s better to move already running process to some location which we can access later to process it once again. But moving this data to HDD is not preferred as it is bit slow and other solution is to increase the RAM size which bit cost. So people came with a solution called SWAP partition which can solve both these limitations.
We create swap partition to cache all the data in registers, L1, L2, L3 caches and RAM.
Then why we create two times the RAM?
The reason behind it is that if you club all the above memory locations, the total size will be between 1.5 times to 2 times the RAM. This is the reason behind the thumb rule to create swap size 2 times the RAM

Some FAQ related SWAP:

If I create swap size more than two times the RAM, What will happen?
As we said earlier swap is used to move data from different memories and their total size is always 1.5 times to 2 times maximum so it's of no use if you create swap size more than 2 times the RAM. In other words, all the space more than 2 times the RAM in swap is no use.

I have RAM size of 128GB and my RAM usage never fills up, do I have to create swap partition?

No, not at all required. As mention earlier swap is a temporary space to store all your memories data for future processing, if your RAM is free then there is no use of swap partition.

I have no free partitions left to create swap partition but want to create some swap space is it possible?

Yes, it’s possible use virtual file system to do it. To know more about this have a look at our other article.
How can I see swap details in Linux/Unix?
Use free command to view it. To know more about free command output click here.
Hope this helps to understand swap thumb rule.
The following two tabs change content below.
Mr Surendra Anne is from Vijayawada, Andhra Pradesh, India. He is a Linux/Open source supporter who believes in Hard work, A down to earth person, Likes to share knowledge with others, Loves dogs, Likes photography. He works as Devops Engineer with Taggle systems, an IOT automatic water metering company, Sydney . You can contact him at surendra (@) linuxnix dot com.