Has it ever happened with you that you are playing some game on your computer and suddenly screen get stuck? Or you are watching a high definition movie and video is not played properly? Or you are trying to run so many applications together and your computer starts taking time in responding? You somehow restart you computer and try to find solution of your issue on internet. You come to know that your computer don’t have adequate RAM for those applications. Now go and buy some more RAM but suddenly you see some magical advice, some geek(!) on some forum advised you to increase the Virtual Memory
. You don’t know what the heck this Virtual Memory is but you simply follow the steps and yippee, it works for you. Be happy that it worked for you but you can be happier by understanding what exactly is Virtual Memory and how it works.Before going in details of Virtual Memory
, lets understand about execution of any process in computer. Main memory or RAM is the place where everything happens
. (Keep your imagination of everything limited to domain of computer processes only.) A process needs to be in memory for execution and most of the times end user is not concerned how this memory is organized. So application developers and OS architects create an illusion of infinite memory
for end users and this illusion is based on the concept of Virtual Memory.
Virtual memory is a techinque that allows the execution of processes that may not be completely in memory. It means programs can be larger than physical memory. This technique frees users and programmers from the concerns of memory storage limitation. Virtual memory combines the computer RAM with temporary space on the hard disk. That temporary space is called a paging file or swap file. The default and recommended size of this file is 1.5 times the amount of physical memory. Virtual memory is the sum of physical memory and the page file.
So Virtual Memory works as a layer above RAM and swap area.
Executing programs can not differentiate between RAM and swap area. Virtual Memory is which they could understand. This concept allows an extremely large pool of memory to be provided for programmers when only a smaller physical memory is available. If RAM size of a computer is very small and it is slowing the system then in that case we can increase the swap area to compensate it. But we should keep in mind while increasing the swap area that reading from hard disk is slower than reading from RAM. There are settings on all PCs for changing the size of virtual memory.I tried to tell you about Virtual Memory in very simple terms but if you go and read some more articles on the same, you will see so many jargon being used at other places. So here are few jargon which will help you understanding the concept of virtual memory more.
Paging is a memory management scheme which divides logical memory into fixed size blocks called pages and physical memory into frames. when a process is to be executed, its pages are loaded into available memory frames.
Page table is the hardware support for paging which is used to map logical address (pages) to physical address( frames). The main advantage of paging is that it allows the physical address space of a process to be non contiguous.
Swapping is a simple memory management technique used by the operating system to increase the utilization of the processor by moving some blocked process from the main memory to the secondary memory(backing-store);thus forming a queue of temporarily suspended process and the execution continues with the newly arrived process. For example, assume a multi-programming environment with a round-robin CPU-scheduling algorithm. When a quantum expires, the memory manager will start to swap out the process that just finished, and to swap in another process to the memory space that has been freed.