SLIDE 1
1
CSE 421/521 - Operating Systems Fall 2011
Tevfik Koşar
University at Buffalo
October 27th, 2011
Lecture - XVI
Virtual Memory - II
Roadmap
- Virtual Memory
– Page Replacement Algorithms – Optimal Algorithm – Least Recently Used (LRU) – LRU Approximations – Counting Algorithms – Allocation Policies – Thrashing – Working Set Model
3
FIFO
- FIFO is obvious, and simple to implement
– when you page in something, put it on the tail of a list – evict page at the head of the list
- Why might this be good?
– maybe the one brought in longest ago is not being used
- Why might this be bad?
– then again, maybe it is being used – have absolutely no information either way
- In fact, FIFO’s performance is typically lousy
- In addition, FIFO suffers from Belady’s Anomaly
– there are reference strings for which the fault rate increases when the process is given more physical memory
Optimal Algorithm
- Replace page that will not be used for the longest time in future
- 4 frames example
1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5
Optimal Algorithm
- Replace page that will not be used for longest period of time
- 4 frames example
1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5
- How would you know this in advance?
1 2 3 4 6 page faults 4 5
6
Optimal (Belady’s) Algorithm
- Provably optimal: lowest fault rate (remember SJF?)
– evict the page that won’t be used for the longest time in future – problem: impossible to predict the future
- Why is Belady’s Optimal algorithm useful?
– as a yardstick to compare other algorithms to optimal
- if Belady’s isn’t much better than yours, yours is pretty good
– how could you do this comparison?
- Is there a best practical algorithm?
– no; depends on workload
- Is there a worst algorithm?
– no, but random replacement does pretty badly
- there are some other situations where OS’s use near-random