You are on page 1of 14

LRU PAGEREPLACEMENT ALGORITHM

GROUP MEMBERS:

10E621 10E622 10E623 -

M. MOHAMMED KISHORE
B.MUTHUKANNAN P. MUTHUKUMARAN

10E624 10E625 11E910 -

B. NAVEENKUMAR
M. NEELABHARATHY S. SABARI

PAGE REPLACEMENT
When a page fault occurs, the OS has to choose a page to

remove from memory to make room for the page that


has to be brought in. Goal: Want lowest page-fault rate. Evaluate algorithm by running it on a particular string of memory references (reference string) and computing the number of page faults on that string.

BASIC PAGE REPLACEMENT


Find the location of the desired page on disk. Find a free frame
If there is a free frame, use it. If there is no free frame, use a page replacement algorithm to select a victim frame.

Bring the desired page into the (newly) free


frame; update the page and frame tables.

Restart the process.

LRU LEAST RECENTLY USED


LRU is a good approximation to the optimal
algorithm.

It is based on the observation that pages heavily


used in the last few instructions will probably be heavily used again. Conversely, pages that have not been used for ages will probably remain unused for a long time.

LRU LEAST RECENTLY USED


When a page fault occurs, throw out the page that has been unused for the longest time. This strategy is called LRU (Least Recently Used) paging. LRU is the optimal page-replacement algorithm looking backward in time, rather than forward.

EXAMPLE

Reference string Reference string is the sequence of pages being referenced. If user has the following sequence of addresses 123, 215, 600, 1234, 76, 96.

If the page size is 100, then the reference string is - 1, 2, 6,


12, 0, 0.

PROBLEMS
Implementation is difficult Requires substantial hardware assistance - to determine an order for the frames defined by the time of last use.

IMPLEMENTATION
USING COUNTERS:

Each page-table entry is associated with a time-ofuse field and add to the CPU a logical clock or counter. The clock is incremented for every memory reference.

We always have the "time" of the last reference to


each page. We replace the page with the smallest time value.

IMPLEMENTATION
DISADVANTAGES Requires a search of the page table to find the LRU page and a write to memory for each

memory access.
The times must also be maintained when page

tables are changed (due to CPU scheduling).


Overflow of the clock must be considered.

USING STACK

IMPLEMENTATION

Whenever a page is referenced, it is removed from the stack and put on the top. the most recently used page is always at the top of the stack and the least recently used page is always at the bottom Because entries must be removed from the middle of the stack, it is best to implement using doubly linked list with a head pointer and a tail pointer. Removing a page and putting it on the top of the stack then requires changing six pointers at worst. Each update is a little more expensive There is no search for a replacement; the tail pointer points to the bottom of the stack, which is the LRU page.

EXAMPLE

IMPLEMENTATION
USING MATRIX For a machine with n page frames, the LRU hardware can maintain a matrix of n x n bits, initially all zero.

Whenever page frame k is referenced, the hardware


first sets all the bits of row k to 1, then sets all the bits of column k to 0. At any instant, the row whose binary value is lowest is the least recently used.

IMPLEMENTATION
EXAMPLE
Reference string: 0,1,2,3,2,1,0,3,2,3

THANK YOU

You might also like