Page Replacement Algorithms
By,
Nikhil Katte
NKOCET, Solapur
02-04-2020
Points to be covered
 Page Fault
 Optimal Page Replacement Algorithm
 First In First Out (FIFO) Algorithm
 Least Recently Used Algorithm
02-04-2020
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
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
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
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
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
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
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
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
THANK YOU…!
02-04-2020

Page replacement algorithm

  • 1.
    Page Replacement Algorithms By, NikhilKatte NKOCET, Solapur 02-04-2020
  • 2.
    Points to becovered  Page Fault  Optimal Page Replacement Algorithm  First In First Out (FIFO) Algorithm  Least Recently Used Algorithm 02-04-2020
  • 3.
    PAGE FAULT  Apage 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 caseof 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 REPLACEMENTALGORITHM  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 OperatingSystem 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 FIRSTOUT(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 pagethat 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
  • 11.