Optimal Page Replacement

Definition

The process in an operating system occupies some dedicated memory. This memory is further divided into chunks called pages. These pages are brought from secondary memory to the primary memory as the CPU demands them. This method is known as page swapping and is done through an algorithm.
To fulfill the demand of the most frequently used pages, the operating systems keep these pages in the primary memory. Pages that not have been used since a long time are replaced with the most frequently used pages under the method called as Optimal Page Replacement technique.
The approach can be best explained by the below reference string and the frame size.

Reference String: 4 6 7 8 5 6 7

The diagrammatic representation above states the order in which the stack will be filled as per the demands in the primary memory. In the case of a page fault, the least recently used page is replaced with the pager which in immediate demand.

Algorithm for Optimal Page Replacement

Step 1: Push the first page in the stack as per the memory demand.

Step 2:
Push the second page as per the memory demand.

Step 3:
Push the third page until the memory is full.

Step 4:
As the queue is full, the page which is least recently used is popped.

Step 5:
repeat step 4 until the page demand continues and until the processing is over.

Step 6:
Terminate the program.

Please Login/Signup to comment