Docsity

Understanding Page Replacement Algorithms & Challenges in Demand Paging, Study notes of Operating Systems

Partial preview of the text

Download Understanding Page Replacement Algorithms & Challenges in Demand Paging and more Study notes Operating Systems in PDF only on Docsity!

MEMORY MANAGEMENT

Challenges of Demand Paging

  • (^) It is important to develop a frame-allocation algorithm and a page-replacement algorithm.
  • (^) If we have multiple processes in memory, we must decide how many frames to allocate to each process.
  • (^) Further, when page replacement is required, we must select the frames that are to be replaced.

Need For Page

Replacement

Basic Page Replacement

  1. Find the location of the desired page on disk
  2. 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
    • (^) Write the victim frame to the disk change the frame and page tables accordingly.
  3. Read the desired page into the (newly) free frame. Update the page and frame tables.
  4. Restart the process

Page Replacement

  • (^) There are many different page-replacement algorithms.
  • (^) Every operating system probably has its own replacement scheme.
  • (^) How do we select a particular replacement algorithm?
  • (^) In general, we want the one with the lowest page- fault rate.

Page Replacement

  • (^) We evaluate an algorithm by running it on a particular string of memory references and computing the number of page faults.
  • (^) The string of memory references is called a reference string.
  • (^) To determine the number of page faults for a particular reference string and page-replacement algorithm, we also need to know the number of page frames available.

Page Replacement Algorithms

  • (^) FIFO Page Replacement Algorithm
  • (^) Optimal Page Replacement Algorithm
  • (^) Least Recently Used (LRU) Algorithm

First-In-First-Out (FIFO)

Algorithm

  • (^) This policy simply removes pages in the order they arrived in the main memory.
  • (^) When a page must be replaced, the oldest page is chosen.

First-In-First-Out (FIFO)

Algorithm

  • (^) The FIFO page-replacement algorithm is easy to understand and program.
  • (^) However, its performance is not always good.
  • (^) On the one hand, the page replaced may be an initialization module that was used a long time ago and is no longer needed.

First-In-First-Out (FIFO)

Algorithm

  • (^) Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5
  • (^) 3 frames (3 pages can be in memory at a time per process)
  • (^) 4 frames
  • FIFO Replacement – Belady’s Anomaly
    • (^) more frames  more page faults 1 2 3 1 2 3 4 1 2 5 3 4 9 page faults 1 2 3 1 2 3 5 1 2 4 (^5) 10 page faults 4 4 3

Optimal Page Replacement

  • (^) It has the lowest page fault rate.
  • (^) It will never suffers from Belady’s anomaly.
  • (^) “Replace the page that will not be used for the longest period of time”.

Optimal Page Replacement

  • (^) No. of page fault = 9

Optimal Page Replacement

  • (^) Unfortunately, the optimal page-replacement algorithm is difficult to implement, because it requires future knowledge of the reference string.
  • (^) We encountered a similar situation with the SJF CPU-scheduling algorithm.

Least Recently Used (LRU)

Algorithm

  • (^) This policy suggests that we remove a page whose last usage is farthest from current time.
  • (^) LRU replacement associates with each page the time of that page's last use.
  • (^) When a page must be replaced, LRU chooses the page that has not been used for the longest period of time.
  • (^) We can think of this strategy as the optimal page- replacement algorithm looking backward in time rather than forward.