scribe for 7 th april 2014 page replacement algorithms payal priyadarshini 11cs30023

15
Scribe for 7 th April 2014 Page Replacement Algorithms Payal Priyadarshini 11CS30023

Upload: heriberto-norcross

Post on 31-Mar-2015

222 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Scribe for 7 th April 2014 Page Replacement Algorithms Payal Priyadarshini 11CS30023

Scribe for7th April 2014Page Replacement Algorithms

Payal Priyadarshini11CS30023

Page 2: Scribe for 7 th April 2014 Page Replacement Algorithms Payal Priyadarshini 11CS30023

Page replacement• In case of page fault, if all the frames are full then we have to

replace/swap out the pages of same process as victim. We should not make pages of another process as victim as it will lead to thrashing.

EAT = (1-p) * memory access + p (page fault overhead + swap page out+ swap page in + restart)

Page 3: Scribe for 7 th April 2014 Page Replacement Algorithms Payal Priyadarshini 11CS30023

Page Replacement

Page 4: Scribe for 7 th April 2014 Page Replacement Algorithms Payal Priyadarshini 11CS30023

Steps to follow in Page Replacement

• Choose the victim page from main memory(frame f) of same process. Swap that page out in the swap space. Write back into disk, if the dirty bit is 1. Otherwise don’t need to write back.

• Change the page table entry corresponding to particular page from valid(v) to invalid(i).

• Swap in the required/demanded page into the main memory.• Update the page table entry corresponding to swapped in

page to frame f and set valid/invalid bit to v.

Page 5: Scribe for 7 th April 2014 Page Replacement Algorithms Payal Priyadarshini 11CS30023

Page Replacement

Page 6: Scribe for 7 th April 2014 Page Replacement Algorithms Payal Priyadarshini 11CS30023

Improving the swap in/out• If we have modified that page which we have choose as victim

frame. Check dirty bit ( modification leads to 1 ) if it is 1 then, write into the disk otherwise not.

Page 7: Scribe for 7 th April 2014 Page Replacement Algorithms Payal Priyadarshini 11CS30023

Evaluation :• Evaluate algorithm by running it on a particular string of

memory references (reference string) and computing the number of page faults on that string• String is just page numbers, not full addressesRepeated access to the same page does not cause a page fault• Trace memory references of a process.

Sniffer: It will store all the physical addresses generated by CPU.

Page Replacement Algorithms

• How to evaluate Victim page ?

Page 8: Scribe for 7 th April 2014 Page Replacement Algorithms Payal Priyadarshini 11CS30023

Evaluation (cont’d) :• Reference string of memory accesses :

0100, 0432, 0101, 0612, 0102, 0104, 0101, 0611, 0102 three consecutive access of

same page which will lead to only 1 page faults

Page size : 100BReference string 1, 4, 1, 6, 1, 6

Page 9: Scribe for 7 th April 2014 Page Replacement Algorithms Payal Priyadarshini 11CS30023

Graph of Page Faults Versus The Number of Frames

This graph show as we increase the number of frames page fault rate will decrease, which is not always the case with some page replacement algorithms.

Page 10: Scribe for 7 th April 2014 Page Replacement Algorithms Payal Priyadarshini 11CS30023

First-In-First-Out (FIFO) Algorithm

• When any frames arrives in the main memory along with that store the corresponding Time-Stamp. Now, select the victim page with the least value of time-stamp.

• Methods to find out oldest page:- Associates a time with each frame when the page was brought into memory

We can maintain a FIFO queue instead of maintaining actual Time-stamp.

Page 11: Scribe for 7 th April 2014 Page Replacement Algorithms Payal Priyadarshini 11CS30023

FIFO Page Replacement

15 page faults.

3 frames in main memory.

How to track ages of pages?• Use a FIFO queue to maintain pages in main memory.• Replace the page at the head.• Inset at tail.

Page 12: Scribe for 7 th April 2014 Page Replacement Algorithms Payal Priyadarshini 11CS30023

Optimal Page Replacement• Replace the pages which we don’t require recently.• Replace the page that will not be required for longest period

of time.

09 page faults. Although we can not predict future, But this algorithm can be the page mark for other algorithm.

Page 13: Scribe for 7 th April 2014 Page Replacement Algorithms Payal Priyadarshini 11CS30023

Least Recently Used (LRU) Algorithm• Use past knowledge rather than future.• Past is the proxy for future.• Replace the pages that has not been been used in most of the

time.• Associate time of last use with each page.

12 page faults.

Page 14: Scribe for 7 th April 2014 Page Replacement Algorithms Payal Priyadarshini 11CS30023

LRU - Implementation• Counter implementation• CPU maintains a clock• Every page entry has a Time of use; • every time page is referenced, copy the clock into the time of

use• When a page needs to be replaced, look at the “Time of use” to

find smallest value• Search through table needed

Page 15: Scribe for 7 th April 2014 Page Replacement Algorithms Payal Priyadarshini 11CS30023

Stack Implementation• Stack implementation

• Keep a stack of page numbers in a double linked list form:• Page referenced:

• move it to the top

• When page needed to be replaced(victim), remove page from bottom.