UnixServerAdmin

Server Administration & Management

Why swap is double the size of the RAM in Linux

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(Bits 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 its 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 its 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

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.

Advertisements

July 20, 2014 - Posted by | Tips & Tricks, Unix/Linux | , , ,

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: