Day 111 - Demand Paging In Virtual Memory

We are learning about what VM or virtual memory is and how it is used and operated in the operating system and now we will be looking at a technique that is used to implement VM. It is called Demand Paging.

What Is Demand Paging?

Demand Paging is a technique that is used to implement Virtual Memory in OS. In this technique a Page is brought into memory only when it is actually needed by the CPU for execution.

Following is a life cycle of a program in execution.

  1. On porcess initiation, atlease on Page must be loaded into the main memory. This Page is containing the execution of the porcess.
  2. Execiton of the process commences and proceeds through subsequent instructions beyond the starting point.
  3. The execution of the process continues until the references generated by this page are also in the same page and if not, a page fault happens that will cause an interrupt for the refereced page to be loaded into the memory. This loaded page is called demanding page.
  4. The OS will try to load the referenced page and if it is loaded into some free part of the memory, the execution will continue.
  5. Finally when the process termintaes, the pages belonging to the process are removed from the memory.

Page Faults / Segment Faults

Page Faults / Segment Faults occur when a page whose address is referenced in the current page but that page is not in the main memory. If there are no free frames in the memory, some frame of some other process is removed from the memory.

It is necessary for the OS to choose a good Page Replacement policy. It could happen that the page removed from the memroy is the one that will be used next and if so it will cause another interrupt to solve it. To avoid these a good page replacement policy must be used and that is what we will be learning in the next post.


zainscizainsci