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

The challenges of demand paging in memory management, focusing on the importance of frame-allocation and page-replacement algorithms. It covers the concept of page replacement, the need for it, and introduces various page replacement algorithms such as fifo, optimal, and lru. The document also explains belady's anomaly and the importance of evaluating algorithms based on their page fault rates.

Typology: Study notes

2010/2011

Uploaded on 09/01/2011

visir66
visir66 🇮🇳

4.4

(74)

97 documents

1 / 38

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
MEMORY MANAGEMENT
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26

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.