- OS - Home
- OS - Needs
- OS - Overview
- OS - History
- OS - Components
- OS - Structure
- OS - Architecture
- OS - Services
- OS - Properties
- Process Management
- OS - Processes
- OS - Process Control Block
- OS - Operations on Processes
- OS - Inter Process Communication
- OS - Context Switching
- OS - Multi-threading
- Scheduling Algorithms
- OS - Process Scheduling
- Preemptive and Non-Preemptive Scheduling
- Scheduling Algorithms Overview
- FCFS Scheduling Algorithm
- SJF Scheduling Algorithm
- Round Robin Scheduling Algorithm
- HRRN Scheduling Algorithm
- Priority Scheduling Algorithm
- Multilevel Queue Scheduling
- Lottery Scheduling Algorithm
- OS - TAT & WAT
- Predicting Burst Time in SJF Scheduling
- Process Synchronization
- OS - Process Synchronization
- OS - Critical Section Problem
- OS - Critical Section Synchronization
- OS - Mutual Exclusion Synchronization
- OS - Semaphores
- OS - Counting Semaphores
- OS - Mutex
- OS - Turn Variable
- OS - Bounded Buffer Problem
- OS - Reader Writer Locks
- OS - Test and Set Lock
- OS - Peterson's Solution
- OS - Monitors
- OS - Sleep and Wake
- OS - Race Condition
- OS Deadlock
- Introduction to Deadlock in Operating System
- Conditions for Deadlock in Operating System
- Memory Management
- OS - Memory Management
- OS - Contiguous Memory Allocation
- OS - Non-Contiguous Memory Allocation
- OS - First Fit Algorithm
- OS - Next Fit Algorithm
- OS - Best Fit Algorithm
- OS - Worst Fit Algorithm
- OS - Fragmentation
- OS - Virtual Memory
- OS - Segmentation
- OS - Buddy System
- OS - Allocating Kernel Memory
- OS - Overlays
- Paging and Page Replacement
- OS - Paging
- OS - Demand Paging
- OS - Page Table
- OS - Page Replacement Algorithms
- OS - Optimal Page Replacement Algorithm
- OS - Belady's Anomaly
- OS - Thrashing
- Storage and File Management
- OS - File Systems
- OS - File Attributes
- OS - Structures of Directory
- OS - Linked Index Allocation
- OS - Indexed Allocation
- I/O Systems
- OS - I/O Hardware
- OS - I/O Software
- OS Types
- OS - Types
- OS - Batch Processing
- OS - Multiprocessing
- OS - Hybrid
- OS - Monolithic
- OS - Zephyr
- OS - Nix
- OS - Linux
- OS - Blackberry
- OS - Garuda
- OS - Tails
- OS - Clustered
- OS - Haiku
- OS - AIX
- OS - Solus
- OS - Tizen
- OS - Bharat
- OS - Fire
- OS - Bliss
- OS - VxWorks
- OS - Embedded
- OS - Single User
- Miscellaneous Topics
- OS - Security
- OS Questions Answers
- OS - Questions Answers
- OS Useful Resources
- OS - Quick Guide
- OS - Useful Resources
- OS - Discussion
Operating System - Optimal Page Replacement Algorithm
In virtual memory systems, page replacement algorithms are used to decide which pages to remove from memory during a page fault. An Optimal Page Replacement Algorithm is considered as the best page replacement algorithm. In this chapter, we will explain how this algorithm works with the help of an example. Following topics will be covered in this chapter −
- What is Optimal Page Replacement Algorithm?
- Example of Optimal Page Replacement Algorithm
- Pros and Cons of Optimal Page Replacement Algorithm
What is Optimal Page Replacement Algorithm?
An Optimal Page Replacement Algorithm is a page replacement algorithm that replaces the page that will not be used for the longest period of time in the future. This involve predicting the future page references, which is not always possible. So this algorithm is just a theoretical concept and cannot be implemented in real systems. This is often used to evaluate the performance of other page replacement algorithms.
The idea behind this algorithm is to minimize the number of page faults as less as possible. This is ensured by replacing the page that will not be used for the longest period of time in the future. This will help to keep the pages that are likely to be used in memory, which will reduce the number of page faults.
Example of Optimal Page Replacement Algorithm
Let's solve an example that involves the optimal page replacement algorithm to understand how it works.
Consider the following page reference string and frames −
Page Reference String: 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 3 Frames: 4
Here, the first four pages 7, 0, 1, 2 are loaded directly into the first four empty frames. When the next page 0 is referenced, it is already in memory, so no page fault occurs. Next, page 3 is referenced, which causes a page fault. So the optimal algorithm will remove page 1 since it will not be used for the longest period of time in the future (it is not used again in the reference string). The same process continues for the rest of the page references.
The table below shows all the steps of the process −
| Page Reference | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 7 | 0 | 1 | 2 | 0 | 3 | 0 | 4 | 2 | 3 | 0 | 3 | 2 | 3 | |
| Frames | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | ||||
| 1 | 1 | 1 | 1 | 1 | 4 | 4 | 4 | 4 | 4 | 4 | 4 | |||
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
| 7 | 7 | 7 | 7 | 7 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | |
| Page Fault | Yes | Yes | Yes | Yes | No | Yes | No | Yes | No | No | No | No | No | No |
- Total Page References: 14
- Total Page Faults: 6
- Total Page Hits: 8
- Page Fault Rate: 6/14 = 0.4286 (approximately 42.86%)
- Page Hit Rate: 8/14 = 0.5714 (approximately 57.14%)
These results clearly show that the page fault rate significantly reduced by using the optimal page replacement algorithm. After a certain number of page references, the page fault will not occur frequently. This happens because the pages that are likely to be used in the future are available in memory.
We are able to implement this algorithm as we already know the entire page reference string in advance. But that will not be the case in real-world scenarios. You never know what pages will be referenced in the future. That's why we told earlier that this algorithm is just a theoretical model.
Pros and Cons of Optimal Page Replacement Algorithm
The advantages of the optimal page replacement algorithm are −
- This algorithm have lowest page fault rate compared to other page replacement algorithms.
- This algorithm is theoretically optimal because it uses future knowledge to make decisions.
- This algorithm is easy to understand and implement.
The optimal page replacement algorithm also comes with some disadvantages −
- This algorithm is not practical in real world systems. Because it require the knowledge of future page references, i.e., OS should know the entire page reference string in advance.
- This algorithm may not be suitable for systems with large number of processes and large address spaces. Because the page table can become very large and consume a lot of memory.
Conclusion
An optimal page replacement algorithm is a theoretical concept used to evaluate the performance of other page replacement algorithms. It is considered as the best page replacement algorithm. But to implement this algorithm, you need to have the knowledge of future page references. Hence, it is not used in real-world systems. It is important to understand this algorithm is used just to improve the performance other page replacement algorithms.