UNIT IV - Compatibility Mode
UNIT IV - Compatibility Mode
(UNIT IV)
OS OS OS OS
process 8 process 10
Thus, a page has to be replaced to create a room for the required page.
As the name suggests, this algorithm works on the principle of “First in First
out“.
It replaces the oldest page that has been present in the main memory for the
longest time.
It replaces the newest page that arrived at last in the main memory.
•Only frame is used for page replacement during entire procedure after all the
frames get occupied.
LRU Page Replacement Algorithm-
It replaces the page that has not been referred by the CPU for the longest
time.
Random Page Replacement Algorithm-
As the name suggests, this algorithm randomly replaces any page. So, this
algorithm may behave like any other algorithm like FIFO, LIFO, LRU,
Optimal etc.
Optimal Page Replacement Algorithm-
•This algorithm replaces the page that will not be referred by the CPU in
future for the longest time.
•It is practically impossible to implement this algorithm.
•This is because the pages that will not be used in future for the longest
time can not be predicted.
•However, it is the best known algorithm and gives the least number of
page faults.
•Hence, it is used as a performance measure criterion for other algorithms.
A system uses 3-page frames for storing process pages in main memory. It uses
the First in First out (FIFO) page replacement policy. Assume that all the page
frames are initially empty. What is the total number of page faults that will occur
while processing the page reference string given below-
4, 7, 6, 1, 7, 6, 1, 2, 7, 2
12 10 10
4
1
3 2
4
0
0
page table
• During address translation, if valid–invalid bit in page table entry
is 0 page fault.
Page Fault
• If there is ever a reference to a page, first reference will trap to
OS page fault
• OS looks at another table to decide:
– Invalid reference abort.
– Just not in memory.
• Get empty frame.
• Swap page into frame.
• Reset tables, validation bit = 1.
• Restart instruction: Least Recently Used
– block move
1 1 4 5
2 2 1 3 9 page faults
• 4 frames 3 3 2 4
1 1 5 4
2 2 1 5 10 page faults
3 3 2
4 4 3
1 4
2 6 page faults
3
4 5
• How do you know this?
• Used for measuring how well your algorithm performs.
Least Recently Used (LRU)
Algorithm
• Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5
1 5
2
3 5 4
4 3
• Counter implementation
– Every page entry has a counter; 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.
LRU Algorithm (Cont.)
• Stack implementation – keep a stack of page numbers in
a double link form:
– Page referenced:
• move it to the top
• requires 6 pointers to be changed
– No search for replacement
LRU Approximation Algorithms
• 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). We do
not know the order, however.
• Second chance
– Need reference bit.
– Clock replacement.
– If page to be replaced (in clock order) has
reference bit = 1. then:
• set reference bit 0.
• leave page in memory.
• replace next page (in clock order), subject to
same rules.
Counting Algorithms
• Keep a counter of the number of references that have been
made to each page.
• LFU Algorithm: replaces page with smallest count.
• MFU Algorithm: based on the argument that the page with the
smallest count was probably just brought in and has yet to be
used.
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.
• Thrashing a process is busy swapping pages in and
out.
Thrashing Diagram