section7

advertisement
CSE Four Fiddy One
Section 7
Kurtis Heimerl (kheimerl@)
Aaron Kimball (ak@)
What you’ve luckily skipped:
• Project 3 - Your job: Replacement Algorithms
–
–
Given:
• random
You need to write:
• FIFO
• LRU Clock
• One of your choice
– A few possibilities:
»
»
»
»
–
True LRU (e.g. via storing full timestamp)
Variations on LRU Clock (enhanced second-chance, etc)
LFU/MFU
Your own!
You can write more than 3 if your experiment focuses on replacement algorithms.
So we’ll go over some aspects
of this you may have missed.
Paging Algorithms
(Thanks wikipedia!)
•
FIFO (First in/first out)
– Replace the oldest page with the one being paged in
•
Second-Chance (Modified FIFO)
– FIFO, but skip referenced pages
•
Random
– Duh
•
NFU (Not Frequently Used)
– Replace the page used the least number of times
•
NRU (Not Recently Used)
– Replace a page not used since last clock cycle
•
LRU (Least Recently Used)
– Replace the least recently used page
•
LRU Clock (Modified LRU)
– Replace the least recently used page, with a hard limit on the max time since
used
•
Clairvoyant
– Replace the page that’s going to be needed farthest in the future.
FIFO
• First in/First out
• Advantages?
• Problems?
FIFO
• First in/First out
• Advantages?
– Little Bookkeeping
• Problems?
– Efficiency
• Why?
FIFO
• First in/First out
• Advantages?
– Little Bookkeeping
• Problems?
– Efficiency
• Why?
– Belady's anomaly
• What is it?
Belady's anomaly
Belady's anomaly states that it is possible
to have more page faults when increasing
the number of page frames while using
FIFO method of frame management.
Laszlo Belady demonstrated this in 1970.
Previously, it was believed that an
increase in the number of page frames
would always provide the same number or
fewer page faults.
Example
Page Requests
321032432104
Example (Page Faults in Red)
Page Requests – 3
frames
Frame 1
Frame 2
Frame 3
321032432104
333000444444
22233333111
1112222200
Example (Page Faults in Red)
• Page Requests – 4
frames
• Frame 1
3 2 1 0 3 2 4 3 2 1 0 4
3 3 3 3 3 3 4 4 4 4 0 0
• Frame 2
2 2 2 2 2 2 3 3 3 3 4
• Frame 3
1 1 1 1 1 1 2 2 2 2
• Frame 4
0 0 0 0 0 0 1 1 1
Second-Chance FIFO
• Simply add a referenced bit to FIFO
pages.
• Advantages?
• Disadvantages?
Second-Chance FIFO
• Simply add a referenced bit to FIFO
pages.
• Advantages?
– Obvious improvement over FIFO
– Allows commonly used pages to stay in
queue
• Disadvantages?
– Still suffers from Belady's anomaly
Random
• Randomly Select a page to be replaced
• Advantages?
• Disadvantages?
Random
• Randomly Select a page to be replaced
• Advantages?
– Usually better than FIFO
– Better than LRU in some degenerate cases
(looping)
– Easy to implement
• Disadvantages?
– Less than efficient in most common cases
NFU (Not Frequently Used)
• Remove the page used the least number
of total times
• Advantages?
• Disadvantages?
NFU (Not Frequently Used)
• Remove the page used the least number
of total times
• Advantages?
– Frequently used pages stay longer than FIFO
• Disadvantages?
– Older pages are less likely to be removed,
even if they are no longer frequently used
– Newer pages are more likely to be replaced
even if they are frequently used
NRU (Not Recently Used)
• Remove the page used the least often
since the last clock cycle
• Advantages?
• Disadvantages?
NRU (Not Recently Used)
• Remove the page used the least often
since the last clock cycle
• Advantages?
– Much better behavior than FIFO or NFU
– Frequently used pages are much more likely
to stay
• Disadvantages?
– Behavior sucks near clock cycles
LRU (Least Recently Used)
• Remove the page not used for the longest
period of time
• Advantages?
• Disadvantages?
LRU (Least Recently Used)
• Remove the page not used for the longest
period of time
• Advantages?
– Great efficiency behavior
• Disadvantages?
– Implementation difficult. How do you keep
track of the time each page was last used?
LRU Clock (Modified LRU)
• Remove the page with the longest time
since it’s use, with a hard cap on that time.
• Advantages?
• Disadvantages?
LRU Clock (Modified LRU)
• Remove the page with the longest time
since it’s use, with a hard cap on that time.
• Advantages?
– Very close approximation of LRU
– Cap on hardware resources needed
• Disadvantages?
– Still not optimal
Clairvoyant
• Remove the page that will be needed
farthest in the future
• Advantages?
• Disadvantages?
Clairvoyant
• Remove the page that will be needed
farthest in the future
• Advantages?
– Optimal
• Disadvantages?
– Impossible to implement
Download