2. Current Mechanism..
❖ The operating system uses the method of paging for memory
management.
❖ Memory Frames.
❖ Processes are loaded as frames.
❖ Page Table.
3.
4. PROBLEM STATEMENT
❖ The demand occurs when the
operating system needs a page for
processing, and it is not present in
the main memory.
❖ Such situation is called Page
Fault.
5. Types of Page Replacement Algorithms
❖ First in First Out (FIFO) algorithm
❖ Optimal Page Replacement algorithm
❖ Least Recently Used (LRU) page replacement
algorithm
7. First in First Out
❖ This is the simplest page replacement method in which the operating
system maintains all the pages in a queue.
❖ On a page fault, these pages from the front are removed first, and the
pages in demand are added.
11. Advantages and Disadvantages
❖ Simple and easy to implement.
❖ Low overhead.
❏ Poor performance.
❏ Doesn’t consider the frequency of use or
last used time, simply replaces the oldest
page.
❏ Suffers from Belady’s Anomaly.
13. Least Recently Used Algorithm
❖ In this algorithm , pages are replaced which are not used for the
longest period of time.
❖ This algorithm can be seen as optimal page-replacement algorithm
looking backward in time, rather than forward.
❖ Counters and Stack are two primary ways in which this algorithm can
be implemented.
14. Least Recently Used Algorithm
❏ Counters
❖ Add the "time stamps" field to the page table entries.
❖ Add counter register to CPU. Counter is incremented every time a page
is referenced.
❖ When a page is referenced, the counter is copied to the "time stamps”
field.
❖ The victim page has the smallest "time stamps" value.
17. Least Recently Used Algorithm
❏ Stack
❖ The LRU replacement algorithm can also be accomplished by keeping
a stack of page numbers.
❖ When a page is referenced, it is removed from the stack and placed at
the top.
❖ Therefore, the most recently used page is always at the top of the stack
and the least recently used page is always at the bottom.
19. Algorithm
1.Start traversing the page
i) If set holds less page than capacity.
A. Insert page into the set one by one until the size
of set reaches capacity or all page requests are
processed.
B. Simultaneously maintain the recent occurred index
of each page in a map called indexes.
C. Increment page fault.
20. Algorithm
ii) Else
If Current page is present in set, do nothing else.
Else
A. Find the page in the set that was least recently used. We find
it using index array. We basically need to replace the page
with minimum index.
B. Replace the found page with current page.
C. Increment page faults.
D. Update index of current page.
2) Return page faults.
21. LRU Advantage
❏ Almost as good as OPT.
❏ No Belady’s Anomaly.
❏ Widely used for caches as well
LRU Disadvantage
❏ More complicated and expensive to implement than FIFO
algorithms:
❏ Determining an ordering based upon “time of last use”
❏ May require substantial hardware assistance
23. Optimal page replacement
❖ In this algorithm , pages are replaced which are not used for the
longest duration of time in the future.
❖ This algorithms replaces the page which will not be referred for so
long in future.
❖ This algorithm will never suffer from Belady’s anomaly.
24. Algorithm
1. Push the first page in the stack as per the memory demand.
2. Push the second page as per the memory demand
3. Push the third page until the memory if full.
4. As the stack is full,the page which is least recently used is popped.
5. Repeat step 4, until the page demand continues and until the
processing is over.
6. Terminate the program.
28. Implementation
❖ Since future cannot be predicted in general,the algorithm
cannot really be implemented
❖ Sometimes,if a program is used repeatedly, its behaviour may
be known
❖ OPT can be approximated
❖ OPT is set a benchmark.
29. Advantages
❖ It is less complex and easy to understand.
❖ A page is replaced with minimum fuss.
❖ Simple data structure are used for this purpose
30. Disadvantages
❖ Not all operating system can implement this
algorithm
❖ Error detection is harder
32. Conclusion
In the above methods or algorithms .we have found that optimal page replacement algorithm results
in the best algorithm because the average page faults in all three cases with page frame size 2,3 and
4 is less as compared to FIFO and LRU.
Considering above example: Page faults for respective algorithms were
➢ FIFO: 9 page faults.
➢ LRU: 8 page faults.
➢ OPTIMAL: 6 page faults.
Though optimal page replacement algorithm is best and efficient as compared to other two but it
cannot be implemented because we can't predict the future. So it is best for theory but LRU page
replacement algorithm is used in most of the cases.