Demand Paging | Operating System | Basic IT Topic

Demand Paging

Demand Paging

A demand-paging system is similar to a paging system with swapping. Generally, Processes reside on secondary memory (which is usually a disk). When we want to execute a process, we swap it into memory. Rather than swapping the entire process into memory, it swaps the required page.  This can be done by a lazy swapper.

A lazy swapper never swaps a page into memory unless that page will be needed. A swapper manipulates entire processes, whereas a pager is concerned with the individual pages of a process.

Page transfer Method: When a process is to be swapped in, the pager guesses which pages will be used before the process is swapped out again. Instead of swapping in a whole process, the pager brings only those necessary pages into memory. Thus, it avoids reading into memory pages that will not be used anyway, decreasing the swap time and the amount of physical memory needed.

Demand Paging

(Page table when some pages are not in main memory)

When a page references an invalid page, then it is called Page Fault. It means that page is not in main memory. The procedure for handling page fault is as follows:

  1. We check an internal table for this process, to determine whether the reference was a valid or invalid memory access.
  2. If the reference was invalid, we terminate the process. If it was valid, but we have not yet brought in that page into memory.
  3. We find a free frame (by taking one from the free-frame list).
  4. We schedule a disk operation to read the desired page into the newly allocated frame.
  5. When the disk read is complete, we modify the internal table kept with the process and the page table to indicate that the page is now in memory.
  6. We restart the instruction that was interrupted by the illegal address trap. The process can now access the page as though it had always been in memory.

Demand Paging

(Diagram of Steps in handling a page fault)

Note: The pages are copied into memory, only when they are required. This mechanism is called Pure Demand Paging.

Performance of Demand Paging:

Let p be the probability of a page fault (0< p < 1). Then the effective access time is

Effective access time = (1 p) x memory access time + p x page fault time

In any case, we are faced with three major components of the page-fault service time:

  1. Service the page-fault interrupt.
  2. Read on the page.
  3. Restart the process.

 

basicittopic

basicittopic

A Computer Science Study for IT students and people of IT community