Memory 4
Memory 4
Page Fault: 12
Least Recently Used (LRU) Algorithm
Counter implementation
Each page has a counter.
Copy clock into counter when page is referenced.
During Page Replacement
Search for counter having smallest value
Search through table needed
Write to memory in counter during each page access.
Clock Overflow must be considered.
Least Recently Used (LRU) Algorithm
Stack implementation
keep a stack of page numbers in a double link form
Page referenced:
move it to the top
Top of the stack is always the most recently used page
Update is expensive.
No search for replacement
Reference String
4707101212712
Least Recently Used (LRU) Algorithm
LRU (Approximation) Algorithm
Clock Algorithm (Second-Chance)
Arrange physical pages in circle with single clock hand
Approximate LRU
Details:
Hardware “use” bit per physical page:
Hardware sets use bit on each reference
If use bit isn’t set, means not referenced in a long time
On page fault:
Advance clock hand
Check use bit: 1used recently; clear and leave alone
0selected candidate for replacement
Will always find a page or loop forever?
Even if all use bits set, will eventually loop around FIFO
This is Second-Chance, can go for n chances as well.
Enhanced Second chance Algorithm
Improve algorithm by using reference bit and modify bit
Take ordered pair (reference, modify)
(0,0) neither recently use nor modified -> best page to replace
(0,1) not recently used but modified -> not quite good, because the
page must be written to memory
(1,0) recently used and clean -> it probably will be used again
(1,1) recently used and modified -> it probably will be used again and
need to write back.
Free List
Keep list of free pages ready for use for demand paging
Free-list filled in background by Clock algorithm or other technique
Dirty pages start copying back to disk when they enter this list.
Advantage: Faster for page fault
Can always use page (or pages) immediately on fault
Clock Hand
D
Set of all pages
in Memory
D
Free Pages
For Processes