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.

(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:

We check an internal table for this process, to determine whether the reference was a valid or invalid memory access.

If the reference was invalid, we terminate the process. If it was valid, but we have not yet brought in that page into memory.

We find a free frame (by taking one from the free-frame list).

We schedule a disk operation to read the desired page into the newly allocated frame.

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.

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.

(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 theeffective access time is