Swap memory is an area on a hard disk used as the virtual memory extension of a computer’s RAM (Random Access Memory).
Every operating system has a dedicated amount of RAM available through which the processing of a program is done. But, amount of this RAM is limited and that is why RAM cannot hold a bulk of data in it.
Therefore, there need a backup option which can support RAM whenever it runs out of memory. This concept holds true for the Windows operating system as well as for Linux.
Thus, whenever RAM has an insufficient amount of memory to hold a process, it borrows some amount of memory from the secondary storage.
The files in the RAM which are not used in more frequent is moved to this space until it is needed later. When needed again will be moved back to the RAM.
In many Operating Systems, the files that are moved are called pages and the moving process is called paging.
Swap Memory is also used when the machine is set to hibernate.
Creation of Swap Area:
Most of the Operating systems create the swap area by there own without input from users.
While in Linux (eg.: UBUNTU) if you select to do a custom installation you have to create your swap area manually (It is a mandatory step).
The size of the Swap is preferred to be more than the RAM (I usually take RAM memory size x 2)
Advantage of Swap Memory:
- Space availability other than that of just RAM
- Faster memory access as the processor doesn’t have to go back for reading Hard Disk again and again.
- As the processor doesn’t have to wait for frequently used pages the processing time is thus less.
Thus we understand the Swapping of memory is very useful.