190 likes | 477 Views
Page Replacement. Overview. Why we need page replacement? Basic page replacement technique. Different type of page replacement algorithm and their examples. Why????. Limited physical memory --> limited number of frame --> limited number of frame allocated to a process.
E N D
Overview • Why we need page replacement? • Basic page replacement technique. • Different type of page replacement algorithm and their examples.
Why???? • Limited physical memory --> limited number of frame --> limited number of frame allocated to a process.
Basic Page Replacement • Find the location of the desired page on the disk. • Find a free frame • If there is a free frame use it. • No free frame – use page replacement algorithm to select a victim frame. • Write the victim frame to disk, change the frame and page tables accordingly.
Replacement Policy • Which page to be replaced? • Page removed should be the page least likely to be referenced in the near future. • Most policies predict the future behavior on the basis of past behavior.
Replacement Algorithm • FIFO page replacement • Optimal page replacement • LRU page replacement • LRU-Approximation page replacement • Counting-Based page replacement
example String Reference 7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1 0 0 3 2 0 2 7 7 7 7 0 2 1 0 2 7 0 3 7 4 0 3 1 0 3 2 1 1 3 1 7 3 4 3 7 7 1 0 1 Young page Frames initially empty 2 2 2 3 7 2 0 7 2 2 0 0 1 0 4 7 2 0 Old Page * * * * * * * * * * * * Page faults
FIFO Page Replacement • FIFO is similar to First In First Out CPU scheduling algorithm wherein the requested page is loaded first and subsequent fetches are also serviced in order of request arrival. • A page which is being accessed quite often may also get replaced because it arrived earlier than those present • Ignores locality of reference. A page which was referenced last may also get replaced, although there is high probability that the same page may be needed again.
FIFO pf/n pf = page faults N = number of reference made 12/20 = 60% 7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1 2 2 1 4 0 3 0 2 7 7 7 7 7 3 0 7 0 0 2 0 7 4 3 1 3 1 1 3 7 2 0 3 0 1 7 1 0 3 1 7 0 7 2 1 4 2 2 2 0 3 2 2 0 0 2 0 7 * * * * * * * * * * * *
Optimal Page Replacement (OPT) • The main idea of OPT is to replace the pages found n the frames that re not going to be used/ referenced soon. • An optimal page-replacement algorithm has the lowest page-fault rate of all algorithms (called OPT or MIN). It is simply this: Replace the page that will not be used for the longest period of time. - At the moment of page fault: • Label each page in memory is labeled with the number of instructions that will be executed before that page is first referenced • Replace the page with the highest number: i.e. postpone as much as possible the next page fault
OPT pf/n pf = page faults N = number of reference made 6/20 = 30% 7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1 4 0 4 7 0 0 0 0 0 0 7 2 0 0 0 7 0 0 4 2 1 2 1 0 0 1 2 1 1 2 2 2 2 1 0 2 3 1 1 7 1 3 2 3 7 3 3 1 3 7 2 0 3 0 2 2 3 * * * * * *
Least Recently Used Page Replacement Algorithm • This algorithm reposes on the opposite of the concept of temporal locality, wherein if a page has not been referenced for quite some time then it is not going to be referenced in the future.
Least Recently Used Page Replacement Algorithm • Pf/N 9 / 20 = 45% 7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1 2 2 4 3 2 1 0 0 7 7 1 7 2 3 2 7 2 1 3 0 3 0 2 2 3 1 7 4 7 0 3 3 0 2 0 0 0 1 2 0 0 2 1 3 4 0 1 1 2 2 1 2 0 1 0 3 0 * * * * * * * * *