 assistant professor, department of electronics, W. D. Solapur. In this video lecture, we are going to focus on the optimal page replacement algorithm. Students, at the end of this video, we are going to describe the need of the page replacement. Then we can describe the working of the optimal page replacement policy. We also are going to measure the performance of the optimal page replacement policy. Friends, before we go for this actual concept here, let us try to understand some basic concepts here. The page. Page is a segment in the secondary memory. That is, we are going to segment the secondary memory in equal size partitions and each partition is normally called as a page. Now, a paging. Paging is a memory management scheme by which a computer stores or retrieves data from the secondary memory. That is, whenever we want some data from secondary memory to be accessed here, this unit which is called the memory management unit is normally coming in the picture and that is going to help us to bring the required data at required position. Then this one more phrase is coming here is called the need of paging. Now, when we require paging. Now, we know when a process is under execution, he access data from the main memory. Suppose data is available, it is very fine. So, instruction under execution will access data from the main memory and we are going to execute that instruction properly. But suppose the required data is not available in the main memory, then we are going for the paging. Now, in the paging we also encounter some terms here. That is the first is called as the page hit and second is called the page fault here. Now when the process find the required data in the main memory, it is normally called as a page hit case and whenever the process won't find data in the main memory, it is a case of page fault. Now to measure its performance, we are going to define two more terms. One is called as the page hit ratio and second is called the page fault ratio. Now page hit ratio is nothing but the number of page hits upon the total page faults and the page hits sum and whereas the page fault ratio will be the ratio of the total number of page faults upon the sum of the total page number of page faults and the page hits ratio. Now friends, this is the algorithm we are going to focus today. That is the optimal page replacement algorithm. As I said earlier, the instruction under execution is going to access data from the main memory. Support data required by this instruction is available in the main memory. So this access data and these activities mark as the page hit. Now suppose the instruction won't find the required data in the main memory. Then first we record this event as the page fault. Then we are going to halt the current instruction execution because he don't find required data from the main memory and so that we have to make some provision to bring the useful data from the secondary memory back in the main memory. So before that we have to make some empty space in the main memory. So for this we are going to use some swap out policy and this policy will be defined as the page replacement policy. So currently we are talking about this optimal page replacement. So we are going to delete that page from the main memory which will not be required in the next future. That is I will delete that page or the frame from the main memory which will not be required in the future for longer time. This is a working principle of this optimal page replacement algorithm. So first we are going to make the empty space here and we are going to bring out the required page from the secondary memory back in the main memory and so that we can execute the halted instruction back again. So in this case it is an example that describes the operation of this optimal page replacement. So let us try to understand how this thing works here. So in the top I am writing here the page references here. So the yellow colored boxes showing you the page numbers you require to execute for current instruction execution here and whereas I got four frames are allocated for the current process execution. At the bottom we are going to record the activity as either page fault or the page hit. In the beginning the entire frames allocated for the current process executions are empty. So whenever I start the execution of the instruction here. So obviously I will record the page fault here because I get nothing in the frames for the process. So first I record this fault page fault here and I will bring out now the 0th page from the main memory back into the secondary memory back into the main memory here. Similarly in the second case I require again the page number two. So again I record a page fault here because in the main memory I do not find the page number two. So I have to bring out the page from the main memory secondary memory back into the main memory. Friends currently we have got three empty locations are there basically in the main memory. So I can take data from the secondary memory for page number two and I can store that into the empty space. Again for the third case again we record a page fault here because I require page number one. It is again not in the main memory. Now again I will take data from the secondary memory and store it in the third slot as a page number one. Again we record a page fault here because I do not find page number six in the main memory and again I got empty spaces available in the main memory. So I can bring out the page number six from secondary memory into the main memory here. Now friends here in the next requirement here I require page number four and currently the main memory does not contain page number four. So I had to execute the instruction that requires a page number four. So here I will record this as a page fault here and now if you see here these no empty spaces are available in the main memory. So I had to make some empty space here. Now here the optical page replacement algorithm says that you can swipe out that page which will not be required in the next future for longer time. If you suppose see so in this case we do not look on the history but we are looking for the future here. So we know here we require in the future the page zero then the page one, page three and so on here. So I will choose the page number six to get replacement here because I do not require this page number six for longer time in the future. So I will swap out the page number six and I will bring out the page number four from the secondary memory at that place in the main memory and I will keep all remaining things as it is here. Then friends we require page number zero. So page zero is available in the main memory here. So I record this as a page hit. So I am going to keep all these frames as it is in the main memory. Then we require page number one again we record this as the page hit again we distribute the main memory as in the previous case here again we require zero page again I got page hit here again the secondary memory has got nothing to transfer in the main memory here. So main memory is going to keep this distribution as it is so I am going to get this as the given distribution here. Now friends in the next execution I require page number three and which is not in the main memory. So which page to be replaced here. Now here if you see in the future here I require page one, page two and page number one again in the future here. So I will not replace page two and page one in the main memory here. So I got two choices either page zero or page number four. So in this case the system choose that page which was there for longer time in the second in the main memory. So in this case I will choose page number zero. So I will first record the page part here and I will bring out the page number three at the place of page number zero in the main memory and I will keep all remaining things as same one. Next I record a page hit again the things are remaining very much same. Again for remaining two cases we are going to record only page hits there. So friends this is the way by which we use this optical page replacement policy and in this distribution in this working we are going to count number of page hits and we are going to record the number of page faults here. You see that the number of page faults are equal to six and number of page faults are equal to again six. So as we know here we are going to have two parameters that measures the performance of algorithm one is called as a page hit ratio. That is a ratio of total number of page hits upon sum of total page hits and total page faults here. So the value comes to be 0.5. Similarly we also get one parameter which is called the page fault ratio that again comes to be 0.5. Friends this is the advantage of the page replacement policy which is called to be optimal page replacement. It is observed this policy is showing us a better result compared with the FIFO and LRU. That is in these cases we are going to find out the less number of page faults compared with the FIFO and LRU policy. Friends there is also some issues in this optimal page replacement policy because in this policy we have to predict the future that is we have to understand which pages are required by the system for the future execution which is rather difficult and so that this algorithm is only limited for some study purpose and we use this policy to compare the performance of invented policy for the page replacement by the researchers there. Friends these are my references. I hope you understand the optimal page replacement policy its working algorithm or working principle. You also understand how to describe the performance of this policy. I hope this video is useful to you. Thank you friends. Thank you for watching my video. Thanks very much.