Implementation of Demand Paging in OS

Demand paging

Implementation of Demand Paging in Operating System

A demand paging system is quite similar to a paging system with swapping where processes reside in secondary memory and pages are loaded only on demand, not in advance. When a context switch occurs, the operating system does not copy any of the old program’s pages out to the disk or any of the new program’s pages into the main memory Instead, it just begins executing the new program after loading the first page and fetches that program’s pages as they are referenced.

The main steps involved in demand paging that is in between the page is requested and it is loaded into main memory are as follows:-

  1. CPU refers to the page it needs.
  2.  The referred page is checked in page table whether that is present in main memory or not.If not an interrupt page fault is generated.
  3. OS puts the interrupts  process in blocking state and  starts the process of fetching the page from memory so that process can be executed.
  4. OS will search for it in logical address space.
  5. Required page will be brought from logical address space to physical address space. The page replacement algorithms are used for the decision making of replacing the page in physical address space.
  6. Page table will be updated.
  7. Interrupted process will be restarted.

 

Steps in handling a page fault

These are  steps when a page required is missing from the memory.

 

Performance of Demand Paging

Demand paging can significantly affect the performance of a computer system.
To see why, let’s compute the effective access time for a demand-paged
memory. the memory-access time, denoted ma,ranges from 10 to 200 nanoseconds.

effective access time = (1 − p) × ma + p × page fault time.

where p is probability of page fault.

Three major activities
– Service the interrupt – careful coding means just several hundred instructions needed
– Read the page – lots of time
– Restart the process – again just a small amount of time