Office of International Affairs 2014.10 Introduction to National Chung Hsing University (NCHU)
NCHU System & Network Lab Lab 12 Page Replacement Algorithm.
-
date post
20-Dec-2015 -
Category
Documents
-
view
228 -
download
2
Transcript of NCHU System & Network Lab Lab 12 Page Replacement Algorithm.
NCHU System & Network LabNCHU System & Network Lab
Lab 12Lab 12Page Replacement AlgorithmPage Replacement Algorithm
NCHU System & Network LabNCHU System & Network Lab
IntroductionIntroduction
• Why do we need page replacement algorithm ?– When page fault occur and there are no free
memory frame, we need an algorithm to choose a victim frame.
• What is page fault ?– Process wants to access the page but the page isn’t
placed in main memory.
NCHU System & Network LabNCHU System & Network Lab
Page FaultPage Fault
a
b
c
d
e
f
3 vi
8 vii
6 v
f
c
a
a b c d
e f
012345
0
1
2
3
4
5
0
3
6
8logicalmemory
page table
physical memory
secondary memory
frame
valid-invalid bit
NCHU System & Network LabNCHU System & Network Lab
Page Replacement AlgorithmPage Replacement Algorithm
• First In, First Out (FIFO)– Simplest– Associates with each page the time when it was
brought into memory.– victim page = oldest page– Just use a FIFO queue
NCHU System & Network LabNCHU System & Network Lab
FIFOFIFO
Reference string
a b c d a c a a b c
a
b
a
c
b
a
c
b
d
first in first out
c
a
d
c
a
d
c
a
d
c
a
d
b
a
d
b
a
c
page frames
NCHU System & Network LabNCHU System & Network Lab
ExampleExample
• A program that show FIFO replacement algorithm process
• Input – A file that has a reference string.
• Output– Page replacement process.– Number of page fault times.
NCHU System & Network LabNCHU System & Network Lab
Page Replacement AlgorithmPage Replacement Algorithm
• Least Recently Used (LRU)– Associates with each page the time of that page’s
last use– Victim page = the page that has not been used for
the longest period of time– Use counters or stack
NCHU System & Network LabNCHU System & Network Lab
LRU (stack)LRU (stack)
Reference string
a b c d a c a a b c
a
b
a
c
b
a
d
c
b
least-recently used
a
d
c
c
d
a
a
c
d
a
c
d
b
a
c
c
b
a
page frames
NCHU System & Network LabNCHU System & Network Lab
LRU (counter)LRU (counter)
Reference string
0 1 2 3 4 5 6 7 8 9
a b c d a c a a b ca 0 a 0
b 1
a 0
b 1
c 2
d 3
b 1
c 2
d 3
a 4
c 2
d 3
a 4
c 5
d 3
a 6
c 5
d 3
a 7
c 5
b 8
a 7
c 5
b 8
a 7
c 9
page frames
least-recently used
NCHU System & Network LabNCHU System & Network Lab
LabLab
• A program that show LRU replacement algorithm process
• Input – A file that has a reference string.
• Output– Page replacement process.– Number of page fault times.
NCHU System & Network LabNCHU System & Network Lab
ReferenceReference•Advanced Programming in the UNIX Environment 2nd
Author : Richard Stevens, Stephen A.Rago, Publisher : Addison-Wesley
•Beginning Linux ProgrammingAuthor : Richard Stones, Neil Matthew Publisher : Wrox
•Operating System Concepts 6th edition Author : Abraham Silberschatz, Peter Baer Galvin, Greg Gagne Publisher : John Wiley & Sons, inc.