Page Fault

Stuff iThink
that will be on the Quiz/Midterm.
by Andrew Yee
What is Page Replacement?
Virtual Memory
Memory Management
Why Page Replacement?
• Cache is limited
• Need ways to manage
virtual memory in Cache
How to Page Replace?
• 3 Ways to manage Virtual Memory in Cache
1. Optimal – Best possible outcome
2. LRU - Least Recently Used
3. FIFO - First In First Out
Think “Stacks”
How to Represent Pages in Time?
1
2
3
Time increases
CPU issues the page
reference string.
Frame set that can 3
page reference
string.
Frame cell that can
hold a page
reference string.
Think Animated “Stacks”
How to Represent
Page Hit and Page Fault (miss)?
1
2
3
4
Time increases
Page Hit – Don’t box
the frame set
Page Fault (miss) –
box the frame set
Think Animated “Stacks”
Optimal Method
• What you need?
Requires Future Knowledge.
Example of Optimal Method
1
2
3
4
4
1
2
1
4
5
4
5
1
4
1
2
3
4
4
4
4
4
4
4
4
4
4
4
1
2
2
2
2
2
2
2
5
5
5
5
5
1
1
1
1
1
1
1
1
1
1
1
1
5 –Page Fault (Missed)
Each of the rectangle is a frame, and each number is a page.
Page fault (miss) is when you cant find the page in cache.
A hit is when you do find it.
You want to minimize the # of miss.
Each cell contains a Page.
FIFO – First in First Out Method
• How?
First Page In
First Page Out
Example of FIFO Method
1
2
3
4
4
1
2
1
4
5
4
5
1
4
1
2
3
4
4
1
2
2
2
5
4
4
1
1
1
2
3
3
4
1
1
1
2
5
5
4
4
1
2
2
3
4
4
4
1
2
2
5
5
9 –Page Fault (Missed)
Each of the rectangle is a frame, and each number is a page.
Page fault (miss) is when you cant find the page in cache.
A hit is when you do find it.
You want to minimize the # of miss.
Each cell contains a Page.
LRU – Least Recently Used
• Key to this method is:
Past experience may indicate
future behavior
Example of LRU Method
1
2
3
4
4
1
2
1
4
5
4
5
1
4
1
2
3
4
4
1
2
1
4
5
4
5
1
4
1
2
3
3
4
1
2
1
4
5
4
5
1
1
2
2
3
4
4
2
1
1
1
4
5
7 –Page Fault (Missed)
Each of the rectangle is a frame, and each number is a page.
Page fault (miss) is when you cant find the page in cache.
A hit is when you do find it.
You want to minimize the # of miss.
Each cell contains a Page.
Page Fault Comparison
Methods
# of Page Fault
Optimal
5
FIFO – First In First Out
9
LRU – Least Recently Used
7
Practical Method Comparison
Methods
# of Page Fault
What we Need?
Optimal
5
Future
Knowledge
FIFO – First In
First Out
9
LRU – Least
Recently Used
7
1st page
Past
Experience
Hit Ratio
• Hit Ratio =
(Total # of Frame Set - # of Page Fault)
---------------------------------------------------- * 100
Total # of Frame Set
Hit Ratio
Methods
# of Page Fault
Optimal
5
FIFO – First
In First Out
9
LRU – Least
Recently
Used
7
Total # of Frame Set
Hit Ratio
14
(14-5)/14* 100 =
9/14 *100 =
64.29%
14
35.71%
14
50%
Practice Example
• Compute the hit ratio of each method:
– Optimal, FIFO, LRU
1
3
3
6
4
Practice Example
• Compute the hit ratio of each method:
–Optimal
Number of Page Fault = 4
Hit ratio = (5 - 4) / 5 * 100
= 20%
1
3
3
6
4
1
3
3
6
4
1
1
3
6
1
3
Practice Example
• Compute the hit ratio of each method:
–FIFO
Number of Page Fault = 4
Hit ratio = (5 - 4) / 5 * 100
= 20%
1
3
3
6
4
1
3
3
6
4
1
1
3
6
1
3
Practice Example
• Compute the hit ratio of each method:
–LRU
Number of Page Fault = 4
Hit ratio = (5 - 4) / 5 * 100
= 20%
1
3
3
6
4
1
3
3
6
4
1
1
3
6
1
3