0% found this document useful (0 votes)
175 views

Lab 15 - Optimal Page Replacement Algo

The optimal page replacement algorithm replaces the page that will not be used for the longest period of time in the future. It aims to minimize page faults. It is not possible in practice since the operating system cannot know future page requests. The document provides an example of applying the optimal page replacement algorithm and calculates the number of page faults. It also lists advantages of having low complexity and disadvantages of not being practical and having difficult error handling. Finally, it provides instructions for a lab assignment to implement the optimal page replacement algorithm.

Uploaded by

hamza
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
175 views

Lab 15 - Optimal Page Replacement Algo

The optimal page replacement algorithm replaces the page that will not be used for the longest period of time in the future. It aims to minimize page faults. It is not possible in practice since the operating system cannot know future page requests. The document provides an example of applying the optimal page replacement algorithm and calculates the number of page faults. It also lists advantages of having low complexity and disadvantages of not being practical and having difficult error handling. Finally, it provides instructions for a lab assignment to implement the optimal page replacement algorithm.

Uploaded by

hamza
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Lab 15- Virtual Memory

Optimal Page Replacement Algorithm


In an operating system that uses paging for memory management, a page replacement
algorithm is needed to decide which page needs to be replaced when new page comes
in the main memory
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.
In case of page fault, Operating System might have to replace one of the existing
pages with the newly needed page. Different page replacement algorithms suggest
different ways to decide which page to replace. The target for all algorithms is to reduce
the number of page faults.
Page Replacement Algorithm:
Optimal Page replacement –
In this algorithm, pages are replaced which would not be used for the longest duration
of time in the future.
Example
Consider the page references 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 3 with 4-page frame.
Find number of page fault.
Initially all slots are empty, so when 7 0 1 2 are allocated to the empty slots —> 4 Page
faults
0 is already there so —> 0 Page fault.
when 3 came it will take the place of 7 because it is not used for the longest duration of
time in the future.—>1 Page fault.
0 is already there so —> 0 Page fault..
4 will takes place of 1 —> 1 Page Fault.

Now for the further page reference string —> 0 Page fault because they are already
available in the memory.
Optimal page replacement is perfect, but not possible in practice as the operating
system cannot know future requests. The use of Optimal Page replacement is to set up
a benchmark so that other replacement algorithms can be analyzed against it.
Advantages
1. Complexity is less and easy to implement.
2. Assistance needed is low i.e Data Structure used are easy and light.
Disadvantages
1. OPR is perfect, but not possible in practice as the operating system
cannot know future requests.
2. Error handling is tough

Lab Assignment:
Implement the Optimal Page replacement algorithm. Input should be number of free
frames and a reference string. The output should be number of page faults (miss) and
Hits. Also, show the status of frames allocation to pages after each page is referred.

You might also like