Virtual Memory : Page Replacement

When a user process executes and page fault occurs and there are no free frames in memory, then one choice for OS is to terminate the process, another choice is to swap out one process, one frame is freed that is not currently being used, these whole process is called Page Replacement. Page Replacement completes separation between logical memory and physical memory - large virtual memory can be provided on a smaller physical memory.


For example consider a situation where a process of 20 pages actually uses only 10 pages of them, then demand paging saves the I/O necessary to load the 10 pages that are never used. We can use these remaining space (frames) to run twice as many processes. Thus, if we had 80 frames, we could run 8 processes, rather than the four that could run if each required 20 frames.

To increase degree of multiprogramming we can over allocate the memory. If we run 6 processes, each of which has total 20 pages, but actually uses only 10 pages, we have higher CPU utilization and throughput, with 20 frames to spare. It may happen that each of these processes demand all 20 pages at any time, resulting in a need for 120 frames, through only 80 are available. This situation requires page replacement.

Page replacement is done as given below :

If no frame is free, find one that is not currently being used and free it. To free a frame OS writes its contents to swap space, and changing the page table (and all other tables) to indicate that the page is no longer in memory. The freed frame is now available to hold the page for which the process faulted.

Since it is not necessary that we had changed the contents of the frame, we can reduce the overhead of writing the contents of the frame back into swap space we can use a modify bit. Each page or frame has a modify bit associated with it in the Hardware. The modify bit for a page is set by the hardware whenever any change or modification is done in the page. When we select a page for replacement we check this bit, if it is set then we write the page into the disk before replacing. If it is not set we directly replace the page.

Demand paging with the replacement capability can provide a very large virtual memory for programmers on a smaller physical memory.



Next Topic :

No comments:

Post a Comment