Title: Lecture 16: Page Replacement Algorithms Tanenbaum Ch' 4'4
1Lecture 16Page Replacement Algorithms
(Tanenbaum Ch. 4.4)
2First-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) -
- Beladys Anomaly more frames ? more page faults
3FIFO Page Replacement
Problem heavily-used old page will be evicted
from memory.
4Clock Page Replacement Algorithm
Algorithmically identical with another algorithm
called 2nd chance. Only the implementation is
different.
5Clock Algorithm Example
Pictures from Stallings Operating Systems, 6th
edition.
6The 2nd Chance Algorithm
- Holds a FIFO list of pages, each page has a bit
R1 if referenced. - Evict the oldest page not referenced in last
tick. - Repeat while oldest has R1
- Move to end of list (as if just paged in)
- Set R0
- At worst, all pages have R1, so degenerates to
regular FIFO. - Page list if fault occurs at time 20, A has R bit
set (numbers above pages are loading times)
7Not Recently Used
- The clock algorithm on 2 bits referenced R and
modified M - Hardware sets corresponding R on every memory
reference - At process start, M and R set to 0
- Each circular pass, R bits set to 0.
- Pages are classified
- not referenced, not modified
- not referenced, modified
- referenced, not modified
- referenced, modified
- NRU removes page from lowest-numbered non-empty
class
Picture from Stallings Operating Systems, 6th
edition.
8System Behavior Principle of Locality
9Least Recently Used (LRU) Algorithm
- Principle of locality pages used recently will
be used again soon - throw out the page that has been unused for
longest time - Must keep a linked list of pages
- most recently used at front, least at rear
- update this list every memory reference !!
- Alternatively keep time of last reference in each
page table entry - choose page with lowest timestamp
- Reference string 1, 2, 3, 4, 1, 2, 5, 1, 2, 3,
4, 5
10LRU Page Replacement
11Comparison of 4 Page Replacement Algorithms
- Study published by Baer in 1980.
- 0.25 million memory references in a FORTRAN
program - Page size 256 words
From Stallings Operating Systems, 6th edition.
12Working-Set Model
- ? ? working-set window ? a fixed number of page
references Example 10,000 instruction - WSSi (working set of Process Pi) total number
of pages referenced in the most recent ? (varies
in time) - if ? too small will not encompass entire locality
- if ? too large will encompass several localities
- if ? ? ? will encompass entire program
- D ? WSSi ? total demand frames
- If D gt m ? Thrashing
- Policy if D gt m, then suspend one process
13Keeping Track of the Working Set
- Approximate with interval timer a reference bit
- Example ? 10,000
- Timer interrupts after every 5000 time units
- Keep in memory 2 bits for each page
- Whenever a timer interrupts copy and sets the
values of all reference bits to 0 - If one of the bits in memory 1 ? page in
working set - Make sure working set in memory before process
runs
14Working Set as Defined by Window Size
From Stallings Operating Systems, 6th edition.
15Typical Working Set Size
From Stallings Operating Systems, 6th edition.
16Thrashing
- 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
- Thrashing ? a process is busy swapping pages in
and out
17Thrashing (Cont.)
18Page-Fault Frequency Scheme
- Establish acceptable page-fault rate
- If actual rate too low, process loses frame
- If actual rate too high, process gains frame
19Animation for Page Replacement Algorithms
- http//gaia.ecs.csus.edu/zhangd/oscal/PagingApple
t.html