This document discusses different page replacement algorithms used in operating systems. It covers page faults, which occur when a program accesses a memory page not loaded in physical memory. When a page fault happens, an existing page may need to be replaced. The document describes three algorithms: optimal page replacement, which is difficult to implement but would result in the fewest faults; first-in first-out (FIFO), which replaces the oldest page; and least recently used (LRU), which replaces the least recently accessed page. Examples are provided to illustrate how each algorithm determines which page to replace.
2. Points to be covered
Page Fault
Optimal Page Replacement Algorithm
First In First Out (FIFO) Algorithm
Least Recently Used Algorithm
02-04-2020
3. PAGE FAULT
A page fault happens when a running program accesses a memory
page that is mapped into the virtual address space, but not loaded in
physical memory.
Since actual physical memory is much smaller than virtual memory,
page faults happen.
02-04-2020
4. Contd.
In case of page fault, Operating System might have to replace one of
the existing pages with newly needed page.
Different page replacement algorithms suggest different ways to
decide which page to replace. The target for all algorithms is to reduce
number of page faults.
02-04-2020
5. OPTIMAL PAGE REPLACEMENT ALGORITHM
In this algorithm, pages are replaced which would not be used for the
longest duration of time in the future.
It is also known as Belady’s optimal page replacement policy.
Despite this limitation, algorithms exist that can offer near-optimal
performance — the operating system keeps track of all pages
referenced by the program.
02-04-2020
6. Contd.
Hence Operating System uses those data to decide which pages to
swap in and out on subsequent runs.
Optimal Page Replacement is difficult to implement, because it is
depend on future pages.
As it is difficult to implement, but it will gives the Best Best result.
Let’s see the Example,
02-04-2020
7. FIRST IN FIRST OUT(FIFO)
This is the simplest page replacement algorithm.
In this algorithm, operating system keeps track of all pages in the
memory in a queue, oldest page is in the front of the queue.
When a page needs to be replaced page in the front of the queue is
selected for removal.
02-04-2020
8. Contd.
For example-1, consider page reference string 1, 3, 0, 3, 5, 6 and 3
page slots.
Initially all slots are empty, so when 1, 3, 0 came they are allocated to
the empty slots —> 3 Page Faults.
when 3 comes, it is already in memory so —> 0 Page Faults.
Then 5 comes, it is not available in memory so it replaces the oldest
page slot i.e. 1. —>1 Page Fault.
Finally 6 comes, it is also not available in memory so it replaces the
oldest page slot i.e. 3 —>1 Page Fault.
Let’s see the another example,
02-04-2020
9. LEAST RECENTLY USED(LRU)
Here Recent word is connected to the TIME.
Least word is connected to the FREQUENCY.
LRU algorithm works on the concept that the pages that are heavily
used in previous instructions are likely to be used heavily in next
instructions.
02-04-2020
10. Contd.
The page that are used very less are likely to be used less in future.
Whenever a page fault occurs, the page that is least recently used is
removed from the memory frames.
Page fault occurs when a referenced page in not found in the memory
frames.
Let’s see the Example,
02-04-2020