Pages

Do You Really Need A Swap Partition, If So How Much in Capacity

When an operating system gets installed on your HDD + when you start programs, they are loaded into you RAM so you can run them faster (a simple illustration only). So why do you need a separate SWAP partition in Linux, which acts similar to the Microsoft "page file" in Windows?.

The short answer is - To make the process more faster. But unless you have a basic understanding of how the process works this won't make any sense. So I'll explain using as short text as possible :).

I think everyone knows that, even though we see single files, but in reality they consist of thousands of little pieces in your HDD. So keeping that in mind...

when you install a program on your PC the OS tries to "copy" the parts of that program as close to each other as possible on your Hard Drive from where they'll be loaded into the RAM for faster access on later. But if your OS tries to do this properly by considering each bits and bytes of your program, it will take a long time to install it. So sometimes as result of "neglecting" the optimization, parts of that program gets scattered across your HDD. 

But the more programs you have running the more their pieces get scattered across the HDD thus it takes a lot of time for the OS to locate them (since it has to search the HDD to find those parts) when trying to load them to the RAM.

As a fix to this, the OS uses a dedicated temporary space called "virtual memory" (known as page file or swap space... which are names given by the developers but basically it means the same thing). In which let's say you have 3 running programs, then the OS would locate their "pieces" and copy then into that dedicated space which makes it easy for the OS to find and located them rather than looking all over your HDD. That's is the basic idea of a virtual memory.

So back to the question. How much virtual space do I need?.

As a general rule, you should have a "dedicated virtual memory" or swap in this case, space which at least has 1.5x times the capacity of your RAM.

According to Ubuntu developers, if you have a RAM of 3GB or higher, the Ubuntu will automatically disable the Swap space since a RAM of that amount is more than enough for the OS. So if you already have a non-changeable partition for swap space on Linux, then after some time, let's say that you upgraded your RAM size. Then unless it is over 3GB, you should increase the Swap partition size as well.

*. Note - After some limit, no matter how much you expand your virtual memory or even the physical RAM, if won't make things any faster either. 

No comments:

Post a Comment