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.
Advantages of virtual memory:
- Firstly, the main advantage of virtual memory is the size of program can be more than the size of main memory.
- We can use memory efficiently because only partial program will have loaded into main memory
- And, it allows us to perform multiprogramming.
Disadvantages of virtual memory:
- Crucial thing is page size.
- Paging interrupts.
- And the hardware cost is also main disadvantage.
Mainly the virtual memory is used to translate virtual addresses to physical addresses when the system has some parameters.
Now you can clearly understand how virtual address is translated into physical address, virtual address is more than physical address then the virtual memory is more useful.
To understand more clearly 25MB program can be run in 5MB space by keeping 5MB to keep in memory each instance.
Finally, the virtual memory is nothing but the separation of user logical memory from physical memory. In this method we keep only part of program in the memory and the other remaining part on the disk that is secondary storage. Every user feels the execution smooth because of virtual memory they may think that program is running in a large space, but actual scenario is it is running on limited amount of space.