Demand Paging


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.

For example:

Observe clearly,

  1. virtual address:

  2. Address translation:

  3. Physical Address:

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.

Contributor's Info


1. Paging is a Memory Management Technique.
2. In Paging the memory is divided into fixed size pages.
3. Operating system retrieves data from secondary storage in same-size blocks called pages.
4. Paging is an important part of virtual memory implementations in modern operating systems.
5. It allows the physical address space of the process to be non-contiguous. 6. The concept of paging is used to remove the problem of fragmentation
7. Paging is used for faster access to data.

Image result for paging in OS

Effect of page size on performance:-

1. The number of frames is equal to the size of memory divided by the page-size.
2. Increase in page size means a decrease in the number of available frames.
3. Due to lower freedom in replacement choice, having a fewer frames will increase the number of page faults.
4. Large pages would also waste space by Internal Fragmentation.
5. On the other hand, a larger page-size would draw in more memory per fault.
6. So the number of fault may decrease, if there is limited contention.
7. Larger pages also reduce the number of TLB misses.
8. Small Page size increases number of pages as well as size of page table.
9. Hence large page size is preferable.
10. Generally this problem as no best answer some factors favors smaller page while other favors larger page size.


Contributor's Info

Demand Paging

Demand Paging:
1. For loading a program in memory, the traditional method usually loads the entire program in memory.
2. However, it may lead to programs or lines of codes with at the end go untouched.
3. To overcome this drawback, we use the concept of demand paging.
4. In Demand Paging, only the pages needed currently for execution are brought in to memory as and when needed.
5. The virtual memory system is commonly implemented using the concept of demand paging.
6. Demand Paging uses a lazy swapper to swap the pages from memory.
7. An important feature of a lazy swapper is that it never swaps until that page is needed.
8. In Demand Paging instead of word swapper the term pager is used.
9. When a process is to be swapped in, the pager guesses which pages will be used before the process is swapped out again.
10. The pager then brings only those pages into memory.
11. The valid-invalid bit scheme is used to determine if the page is on the disk.
a. When bit set to “valid”: The page is legal and in memory.
b. When bit set to “invalid”: The page is not in its address specified or it is currently on the disk.
12. A page-table entry is made based in this for every pages.
13. Access to a page marked invalid in the page-table entry causes a Page Fault.
14. It results in a trap to the operating system.
15. After this the OS swaps page into frame via scheduled disk operation and replacement algorithms.

Contributor's Info