Week10 Virtual Memory
Week10 Virtual Memory
Week10 Virtual Memory
Demand Paging
Page Replacement Algorithms
Thrashing
References:
1. Silberschatz, Abraham, Peter B. Galvin, and Greg Gagne. Operating
system concepts with Java. Wiley Publishing, 2009.
2. Stallings, William. Operating Systems 5th Edition. Pearson Education
India, 2006.
3. Tannenbaum, Andrew S. "Modern Operating Systems, 2009."
Objectives
Virtual-address Space
• So for example, if pages were of size 100 bytes, then the sequence of
address requests ( 0100, 0432, 0101, 0612, 0634, 0688, 0132, 0038,
0420 ) would reduce to page requests ( 1, 4, 1, 6, 1, 0, 4 )
Graph of Page Faults Versus The Number of Frames
First-In-First-Out (FIFO) Algorithm
• Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5
• 3 frames (3 pages can be in memory at a time per process)
1 1 4 5
2 2 1 3 9 page faults
3 3 2 4
• 4 frames
1 1 5 4
2 2 1 5 10 page faults
3 3 2
4 4 3
FIFO Page Replacement
• 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
1 4
6 page
2
faults
3
4 5
• Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5
1 1 1 1 5
2 2 2 2 2
3 5 5 4 4
4 4 3 3 3
• If all reference bits in the table are set, then second chance
degrades to FIFO, but also requires a complete search of the
table for every page-replacement.
• This algorithm is also known as the clock algorithm, from the
hands of the clock moving around the circular queue.
Second-Chance (clock) Page-Replacement Algorithm
LRU Approximation : Enhanced Second-Chance
Algorithm
• The enhanced second chance algorithm looks at the reference bit
and the modify bit ( dirty bit ), and classifies pages into one of four
classes:
• This algorithm searches for the first page it can find in the lowest
numbered category. I.e. it first makes a pass looking for a ( 0, 0 ), and
then if it can't find one, it makes another pass looking for a ( 0, 1 ),
etc.
Counting Algorithms
• There are several algorithms based on counting the number of
references that have been made to a given page, such as:
– Least Frequently Used, LFU: Replace the page with the lowest
reference count.
– Most Frequently Used, MFU: Replace the page with the highest
reference count.
Allocation of Frames
• Each process needs minimum number of pages
• Two major allocation schemes
– fixed allocation
– priority allocation
Fixed Allocation
• Equal allocation – For example, if there are 100 frames and 5
processes, give each process 20 frames.
• Proportional allocation – Allocate according to the size of process
si size of process pi
S si
m total number of frames
si
ai allocation for pi m
S
m 64
si 10
s2 127
10
a1 64 5
137
127
a2 64 59
137
Priority Allocation
• Use a proportional allocation scheme using priorities
rather than size
• Local replacement – each process selects from only its own set
of allocated frames
Thrashing
• If a process does not have “enough” pages, the page-fault rate is
very high. This leads to:
– low CPU utilization
– operating system thinks that it needs to increase the degree of
multiprogramming
– another process added to the system