What is Virtual memory, paging and swap space ?

Swapping

A process normally runs on physical memory where the memory is divided into sets of pages. A page is a 4kb area of memory and is the basic unit of memory with which both kernel and CPU deal.

There might be a situation when all the pages in physical memory goes full. In such cases all the inactive pages inside physical memory is shifted to the secondary storage or the swap space using the paging technique. By doing this physical memory gets free pages which can again be utilized by new processes. This entire process is termed as swapping.

NOTE: Swapping is a good idea as it gives you an additional space to store data files and programs when your physical memory is out of space but accessing a hard disk is hundred times slower than accessing memory.

Virtual memory is a memory management technique that is implemented using both hardware and software which gives an application program the impression that it has contiguous working memory (an address space).

In simple terms Virtual memory is a logical combination of RAM memory and swap space which is used by running process

NOTE: It is NOT just an additional space used in hard disk to make it act as physical memory

Paging

This is one of the memory management technique schemes by which a computer can store and retrieve data from secondary storage for use in main memory.

Swap space

This is a space on the hard disk which is used by the operating system to store data pages that are currently not needed. This swap sapce can be a partition as well as swap file.

Amount of RAM in the system recommended amount of swap space
4GB of RAM or less a minimum of 2GB of swap space
4GB to 16GB of RAM a minimum of 4GB of swap space
16GB to 64GB of RAM a minimum of 8GB of swap space
64GB to 256GB of RAM a minimum of 16GB of swap space
256GB to 512GB of RAM a minimum of 32GB of swap space