Complete Computer Knowledge Portal

Friday, May 3, 2013

Demand Paging

Whenever a program is executed it is required to be loaded into main memory. This loading can be done by two methods:

1) By loading the entire program into main memory. But Problem with this technique is that if user wants to select limited options, whole program will be loaded regardless of user selection.

2) Another Approach is to load only those pages which are currently needed. “The Technique of loading in which only those pages are loaded into main memory which is currently needed is called Demand Paging”. The pages which are not required are not loaded into main memory.

This technique has the advantage that less memory is consumed and more processes can be loaded at the same time which utilizes more resources. Demand paging is very similar to swapping. The whole program resides in secondary storage and when process execution is required, it is swapped into main memory and in spite of loading whole program only currently required pages ware swapped.

To perform this task swapper is used which is called pager. It does not swap any program until it is required in the main memory. Additional hardware is also required to check that which pages are in memory and which pages are on disk.



Page table is used for the marking of valid and invalid bits. Bit is set to valid if page is legal (means it is in logical memory space) and is in main memory. This bit is set to invalid if page is not in logical address space or currently is in disk. If a page is marked as invalid process will never attempt to access this page.
If the reference is valid process is terminated and if the reference is valid and page is not brought into memory it is required to bring in and a trap is generated. to do so following procedure is followed:
i)                    Free frame is taken from free frame list.
ii)                   Disk read operation is done to bring desired page in to allocated frame.
iii)                 On Completion of Disk read operation page table is updated to indicate that desired page is in memory now.
iv)                 Instruction is restarted that was interrupted by trap and process can now access the desired page.

No comments:

Post a Comment