Operating Systems Presentation
Operating Systems Presentation
PAGE REPLACEMENT
R.K.SUSHMITA LAKSHME
LRU Page
Replacement
Whenever page fault occurs, least recently used
page will be replaced with a new page.
Page that is not utilized for longest time in
memory gets replaced.
PAGE FAULT: when a running program tries to
access a piece of memory that is not already
present in RAM.
PAGE HIT: Page is already present in memory .
LRU algorithm is used when a page fault occurs.
01 Table of Content
Meaning of LRU
Example
Algorithm
Example
Consider a reference string 1,2,1,0,3,0,4,2,4
2 0
1. All slots are empty so, pages 1,2 will be allocated to empty memory slots -> 2 page faults
will occur
121030424
2 1
2. Page 1 is referenced -> page hit -> NO page fault
3 1
121030424
2 1
3. Page 0 is referenced -> Allocated to third memory space -> page fault occurs
121030424
0 2 1
4. Page 3 is referenced -> no empty slot->page fault-> LRU -> replaces page 2 by page 3
121030424
0 3 1 4 2
121030424
0 3 1
6. Page 4 is referenced -> not in memory->page fault-> LRU -> replace page 1 by page 4
121030424
0 3 4 6 2
7. Page 2 is referenced-> not in memory-> page fault ->LRU -> replace page 3 by page 2
121030424
0 2 4
8. Page 4 is referenced-> page hit
121030424
0 2 4 6 3
Algorithm
s = main memory capacity
STEP 1
Iterate through the referenced pages.
If the current page is already present in the pages:
1. Remove the current page from pages.
2. Append current page to end of pages.
3. Increment page hits.
Else:
1. Increment page faults.
2. If page contains less pages than capacity s:
# Append current page to pages.
Else:
# Remove first page from pages
# Append current page to end of pages
STEP 2
Return number of page hits and page faults
Advantages
The page that has not been used for a
long time gets replaced
Gives less page faults
Capable of complete analysis
Disadvantages
Execution is complicated
Algorithm may need significant
assistance from hardware.
Thank You