DEMAND PAGING


  • As there is much less physical memory than virtual memory the operating system must be careful that it does not use the physical memory inefficiently.
  • One way to save physical memory is to only load virtual pages that are currently being used by the executing program. 
  • For example, a database program may be run to query a database. 
  • In this case not all of the database needs to be loaded into memory, just those data records that are being examined. 
  • Also, if the database query is a search query then the it does not make sense to load the code from the database program that deals with adding new records. 
  • This technique of only loading virtual pages into memory as they are accessed is known as demand paging.

BASIC CONCEPTS

  • A demand paging system is quite similar to a paging system with swapping. 
  • When we want to execute a process, we swap it into memory.
  •  Rather than swapping the entire process into memory, however, we use a lazy swapper called pager.
  • 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 in anyway, decreasing the swap time and the amount of physical memory needed.
  • Hardware support is required to distinguish between those pages that are in memory and those pages that are on the disk using the valid-invalid bit scheme.
  •  Where valid and invalid pages can be checked by checking the bit.
  •  Marking a page will have no effect if the process never attempts to access the page.
  •  While the process executes and accesses pages that are memory resident, execution proceeds normally.
  • Access to a page marked invalid causes a page-fault trap. 
  • This trap is the result of the operating system's failure to bring the desired page into memory.
  •  But page fault can be handled as following steps:

Step 1:Check an internal table for this process, to determine whether the reference was a valid or it was an invalid memory access.
Step 2:If the reference was invalid, terminate the process. If it was valid, but page have not yet brought in, page in the latter.
Step 3:Find a free frame.
Step 4:Schedule a disk operation to read the desired page into the newly allocated frame.
Step 5:When the disk read is complete, modify the internal table kept with the process and the page table to indicate that the page is now in memory.
Step 6: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.

  •  Therefore, the operating system reads the desired page into memory and restarts the process as though the page had always been in memory.

Advantages

  • Large virtual memory.
  • More efficient use of memory.
  • Unconstrained multiprogramming. There is no limit on degree of multiprogramming.

Disadvantages

  • Number of tables and amount of processor overhead for handling page interrupts are greater than in the case of the simple paged management techniques.
  • Due to the lack of an explicit constraints on a jobs address space size.

PERFORMANCE OF DEMAND PAGING

  • Demand paging have a significant effect on the performance of a computer system.
  • Page Fault Rate (p) 0 < p < 1.0   (no page faults to every ref is a fault)
  • Page Fault Overhead = write page in + update + restart
  • Effective Access Time= (1-p) (memory access) + p (page fault overhead)

No comments:

Post a Comment