It is most common used now days. Virtual Memory is a technique which provides an illusion to user that a very large size of main memory. It is done by using some part of secondary memory as the main memory.
In this technique, those processes which having the larger size than RAM can also be loaded. For this purpose, OS does not load the entire process in main memory. But it loads some parts of each process in main memory.
In this way more and more process are accommodated in main memory and the main target of degree of multi-programming is achieved.
Working of Virtual Memory
Suppose, if some pages needs to be loaded in RAM for the execution and RAM is already full. Then the question is how these pages will enter into RAM? The answer is, OS use some Page Replacement algorithms (i.e. LRU) to load these pages in RAM. According to these algorithms some of the RAM pages are Swap OUT as the entering of new pages. The SWAP OUT pages are shifted to secondary memory.
All this, provides an illusion of unlimited RAM to user because all processes (even bigger than RAM) are executing successfully.
As we see in virtual memory, instead of loading the entire process in main memory, OS loads the some pages of a process in main memory.
The question is that which part of process is loaded in RAM? Because we cannot decide in advance that which part should be kept in main memory and which should be in secondary memory?
For this purpose OS use Demand Paging Concept. Demand paging uses the Page replacement algorithms. All of this is explained in the later lectures in detail.
Explain Through Example
Suppose 2 processes, P1 and P2, each process contains 8 pages. The size of each page is 1 KB. The main memory contains 16 frames of 1 KB each. The OS resides in the first partitions. First page of P1 is stored in the fifth partition and the other partitions are also filled with the different pages of processes in RAM.
The page tables of both the processes is also shown in the diagram
CPU registers contains the base address of each frame. So in the diagram base address of Page table 1 in the main memory is 5 and base address of Page table 2 is 6. The base address of any page table is added to the page number of the Logical address. In this way OS finds actual corresponding entry.
Advantages of Virtual Memory
- Degree of Multi-programming is achieved.
- Processes having even bigger the size of RAM are executed successfully.
- Cost effective because System can work through with smaller RAM size.
Disadvantages of Virtual Memory
- System becomes slower because of swapping, switching, and compaction etc.
- As virtual memory consumes some space of hard disk.