Sie sind auf Seite 1von 16

1

Page Replacement
A. Manoj Wednesday,
November 15,
2017
2

A. Manoj Wednesday,
November 15,
2017

Optimal Algorithm
Replace page that will not be used for longest
period of time
3

A. Manoj Wednesday,
November 15,
2017

Least Recently Used (LRU) Algorithm


We replace the page that has not been used for the
longest period of time, LRU algorithm.
For this there are 2 types of implementation:
Counters
Stacks
Counters:
Every page has counters
Every time page is referenced through this entry, copy
the clock into the counter.
When a page needs to be changed, look at the counters
to determine which are to change
4

A. Manoj Wednesday,
November 15,
2017

Least Recently Used (LRU) Algorithm


5

A. Manoj Wednesday,
November 15,
2017

Least Recently Used (LRU) Algorithm


Stack implementation:
Keep a stack of page numbers in a double link
form.
When a page is referenced
That page is removed from the stack.
And move it to the top of the stack.
Like that most recently used page is always at the
top of the stack.
And least recently used page is always at the bottom.
6

A. Manoj Wednesday,
November 15,
2017

Least Recently Used (LRU) Algorithm


7

A. Manoj Wednesday,
November 15,
2017

LRU Approximation Algorithms


Many systems provide the help in the form of a
reference bit.
The reference bit for a page is set by the
hardware whenever the page is referenced.
Reference bit:
With each page associate a bit, initially = 0
When page is referenced bit set to 1
Replace the one which is 0 (if one exists).
8

A. Manoj Wednesday,
November 15,
2017

LRU Approximation Algorithms


Second chance:
The basic of this algorithm is FIFO replacement
algorithm.
When a page is selected, it inspects its reference
bit.
If value is 0, we replace this page
If the bit is 1, we give a page second chance.
When a page get a 2nd chance, its reference bit is
cleared and its arrival time is reset to current time.
Thus if the page is often used, then that page will
never replaced.
9

A. Manoj Wednesday,
November 15,
2017

LRU Approximation Algorithms


10

A. Manoj Wednesday,
November 15,
2017

Counting Algorithms
Keep a counter of the number of references that
have been made to each page

LFU (Least Frequently Used) Algorithm:


Replaces page with smallest count.

MFU (Most frequently used) Algorithm: Based


on the argument that the page with the smallest
count was probably just brought in and has yet
to be used.
11

A. Manoj Wednesday,
November 15,
2017

Thrashing
If a process does not have enough pages, the page-
fault rate is very high.
Since all its pages are in active use, there exists some
need that it must replace the pages.
Then it quickly faults again, and again.
This high paging activity is called Trashing.
A process is trashing if it is spending more time
paging than in executing.

Thrashing : a process is busy swapping pages in


and out.
12

A. Manoj Wednesday,
November 15,
2017

Thrashing
13

A. Manoj Wednesday,
November 15,
2017

Working-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
Locality: It is a set of pages that are actively used
together.
if too large will encompass several localities
if = will encompass entire program
14

A. Manoj Wednesday,
November 15,
2017

Working-Set Model
= WSSi = total demand frames
if > m => Thrashing Policy
if > m, then suspend one of the processes
15

A. Manoj Wednesday,
November 15,
2017

Page-Fault Frequency Scheme

1. If the actual page fault exceeds the upper bound then we allocate the process
to another frame
2. If the actual page fault falls below the lower limit, we remove a frame from the
process.

Thus we can directly measure and control the page-fault rate to prevent
trashing.
16

A. Manoj Wednesday,
November 15,
2017

Das könnte Ihnen auch gefallen