Virtual memory is a technique that provides larger memory to the user by creating virtual memory space. This scheme has main advantage that programs can be larger than physical memory size. We can have more processes executing in memory at a time. It increases degree of multiprogramming. Virtual memory allows memory protection, because virtual address is translated to physical address.
There are some benefits of the using virtual memory. These are higher degree of multiprogramming, higher CPU utilization and throughput, a user process can be larger than physical memory, etc.
There are three types of virtual memory techniques: overlays, paged virtual memory and segmented virtual memory.
What actually the demand paging is process of loading page or program into main memory whenever asked or demand is known as demand paging.
Observe clearly how the demand paging works:
- Suppose CPU needs a page that is not in the main memory, it may generate abort or interrupt.
- Moving execution further operating system will bring the demand page into the memory
- Demand page will have brought from logical address to physical address space, then the page will be replaced one of the existing page their we have use page replacement algorithms.
- After the getting information to CPU it will continue the program execution and the process will be back with ready state.
In this scenario, whenever the page fault occurs these are the necessary steps followed by operating systems to bring page into main memory.
There are some advantages of demand paging. It reduces context switching time and only executing processes are loaded in the memory. Disadvantages are programs have extra latency when they access a page for the first time and there is possible security risk. Thrashing may occur due to repeated page faults.