0
8.9kviews
Short note on Demand Paging

Subject: Operating System

Topic: Memory Management

Difficulty: Hard

1 Answer
0
248views

The basic idea behind demand paging is that when a process is swapped in, its pages are not swapped in all at once. Rather they are swapped in only when the process needs them (On demand). This is termed as lazy swapper, although a pager is a more accurate term.

Initially only those pages are loaded which will be required the process immediately.

The pages that are not moved into the memory, are marked as invalid in the page table. For an invalid entry the rest of the table is empty. In case of pages that are loaded in the memory, they are marked as valid along with the information about where to find the swapped out page.

enter image description here

When the process requires any of the page that is not loaded into the memory, a page fault trap is triggered and following steps are followed,

  1. The memory address which is requested by the process is first checked, to verify the request made by the process.

  2. If it’s found to be invalid, the process is terminated.

  3. In case the request by the process is valid, a free frame is located, possibly from a free-frame list, where the required page will be moved.

  4. A new operation is scheduled to move the necessary page from disk to the specified memory location. (This will usually block the process on an I/O wait, allowing some other process to use the CPU in the meantime.)

  5. When the I/O operation is complete, the process's page table is updated with the new frame number, and the invalid bit is changed to valid.

  6. The instruction that caused the page fault must now be restarted from the beginning.

There are cases when no pages are loaded into the memory initially, pages are only loaded when demanded by the process by generating page faults. This is called Pure Demand Paging.

The only major issue with Demand Paging is, after a new page is loaded, the process starts execution from the beginning. It is not a big issue for small programs, but for larger programs it affects performance drastically.

Please log in to add an answer.