As we know if we have to increase our degree of multiprogramming, we will over-allocate memory. For this we use demand paging technique.But if CPU demands a page which is not present in memory then page fault occurs. In this situation the command of CPU is taken by O/S and O/S replace the page with the demanded page. Then return command to the CPU then CPU will perform its execution on that demanded page.
Therefore, we can say page replacement occur when CPU demands any page which is not in memory and the memory is full, then one page is to replace from memory by demanded page. And page fault happens when a running program accesses a memory page that is mapped into the virtual address space, but not loaded in physical memory.
Page replacement takes the following approach. If no frame is free, we find one that is not currently being used and freee it. We can free a frame by writing its contents to swap space and changing the page table to indicate that the page is no longer in memory. We modify the page-fault service routine to include page replacement by following method :-
1. Find the location of the desired page on the disk.
2. Find a free frame :-
a. If there is a free frame, use a page-replacement algorithm to select a victim frame.
b. If there is no free frame, use a page-replacement algorithm to select a victim frame.
c. Write the victim frame to the disk, change the page and frame tables accordingly.
3. Read the desired page into the newly freed frame, change the page and frame tables.
4. Continue the user process from where the page fault occured.
If no frames are free, two page transfers are required, one for out and one for in. This situatioon effectively doubles the page-fault service time and increase the affective access time accordingly. We must solve two major problems to implement demend paging :-
We must develop a frame-allocation algorithm and a page-replacement algorithm. That is, if we have multiple processes in memory, we must decide how frames to allocate to each process, and when page replacement is required, we must select the flames that are to be replaced. Designing appropriate algorithms to solve these problems is an important task, because disk I/O is so expensive.
Comments
Post a Comment
Please comment.