 Hello friends, Myself Rohit Kumar R. Vardarikar, working as an assistant professor in Department of Computer Science and Engineering at Walsh Institute of Technology, Solapur. Learning outcomes. At the end of the session, student will be able to solve optimal page replacement problems. So in this session, we are going to solve the problem statement on optimal page replacement. So now, let us say we will have this one problem statement in which we will have some pages, those are mathematical page references and we will have the frame that will be the size of 3. So now here, we need to calculate the total number of page faults. So let us switch to our example. So guys, basically this type of examples are going to be asked in the get examinations for the two marks, it depends on the problem statement. So we focused and try to solve this problem statement. So now here, we will have the total number of pages, these are nothing but our pages. So now here, we will have one page frame. So now the page frame size is nothing but the 3. Page frame size is equals to 3, otherwise you can call it as a simply frame size, fine. So now here, let us draw one frame with the size 3, fine. Let us consider this is our frame, we will copy this one. So that we will use for the next instead of wasting our time, we will do that, fine. So here I have created the some frames, fine. So now here, these are nothing but our frames. So now these are our first frame and in this frame, we are going to place our pages. So now initially the frame is empty. So we need to place all these pages here, right, so that the CPU can directly use these pages from the frames. We have already seen this concept in our previous videos, fine. Then let us start here. So first what we will do, we will take the page number 1 and we will insert into the frame. Why we are going directly for the insertion? Because initially our frame is empty. So here what we will do, we will directly place this one and our frame. Initially what happens, if there is some pages in our frame, so here we need to first make the comparisons, whether that particular page is available in our frame. If that page is not available, then that is nothing but the page fault. If that page is available in our frame, then that is called the page hit. So here we need to calculate the total number of page fault and page hit. So initially let's see, we do not have any page in our frame, means what the first page is nothing but our page fault, fine. So now we will insert one in our frame. So we will go for the next, that is 3, 3rd page. Now here in the 3rd page what we will do, we will check whether this 3 is available in our frame. 3 is not available in our frame. So again that is nothing but the page fault. So now again page fault and we will insert the 3 in our frame. So next we will go for the 0. So now this 0 is again not available in our frame. So again what happens, page fault occurs and we will insert the 0 in our frame, fine. Now our frame is full. Now whenever we are going for the next frame, now let's say we are going for the next page that is 3 and we will check whether that 3 is available in our frame. So now here 3 is available in our frame, means what here we will call it as a page hit, fine. So that is nothing but the page hit. So now next we will take the page 5. So now here we need to check whether that 5 is available in our frame. So now here the page 5 is not available in our frame. So now here what happens, we need to perform the page replacement. Here comes the actual objective that is what, which page we are going to replace. Which means which page from our frame we are going to remove. That is depends on the type of algorithm we are going to use. Here we are going to use the optimal page replacement strategy. So now here 5 is becomes the page fault, right. So now the question is which page will replace, fine. So to perform this, to replace any page from the frame, we need to check the list into the forward direction. It means what we are looking for the future pages, right, we will discuss about that in the next, fine. So now 5 is not available, then 5, then here the page fault occurs. So now which page we are going to replace. So now we need to check the future pages. Now if I want to replace one, so whether this one is going to be used somewhere here, one we are going to use, right. So we will keep it in our frame as it is. So now 3, so now 3 is again needed, right, fine, we will keep it that one also. Now 0, so now 0 is required in the future here, 0 is again required. So which one we are going to replace then? So 0 and 1 are next we are going to use, right. The third is the last one which we are going to use in our future. So now what we will do? We will replace the third page by 5, fine. So now here 1 as it is and then 3 is going to be replaced by 5 and here we will keep it as it is, 0, fine. Have you got this concept because what we are going to do? We are looking for the future pages, fine. So now go for the next. Now here what we will do? I want to perform the insertion of the page in my frame. So now 6 is my next page. So whether the 6 is available in our frame, no. Again what happened? Here it is a page, fault occurs, right. Page is not available. So again the question is same, which one we are going to replace then, right. Again obviously we are going to see the list in the forward direction and here 0, the next needed, 1 is next needed, right, after that 5. But before this 5 we are required 0 and 1. So again we need to replace this 5 with the 6. So the content of my frames becomes 1 and then 6 and then 0, fine. So now next what we will do? Next is 0. So now check whether that 0 is available, yes. Now see here the page fault is not occurs, it's a page hit because 0 is available in our frame. So now that is nothing but our page fault, sorry page hit. Now next we are going to check for the 1. So 1 is again available in our frame, right. So here the 1 is again available, so page hit occurs, right. So next one is what? Next one is a 6. So now let's see here. So now again 6, 6 is available whether the 6 is available in our frame, yes the 6 is available that is again page hit, right. We got the 1 more page hit, right, fine because 6 is also available in our frame, fine. So now next one is what? Next is 5. So whether this 5 is available in our frame, no. We do not have 5 in our frame. So now here page fault occurs. Now here we need to perform the page replacement. Again here which page we are going to replace then? Obviously as per the logic we are looking in the forward direction in our page references here we have the 3 and 1. So we cannot replace the 1, why? Because 1 is needed in the future, right. So we can replace either any one out of these two pages, 0 and 6. So let's say here we are going to replace the 6 by 5, fine and then here it becomes the 0, fine. So now the next page will take that is nothing but the 3. So now whether 3 is available in our frame, no, 3 is not available then again it's a page fault occurs. So again the question is which one we are going to replace? One next is a 1 and that one is available, we cannot replace the 1. We can replace any one either of these two, 5 or 0. So now here what we will do? We will keep as it is in our frame and then next let's say we will keep the 5 as it is 0 as it is in our frame. So now we will replace the 0 by 3, fine. So now next is a 1. So now let's check the 1. 1 is available? Yes. 1 is available, fine. So now here we will see the page hit occurs. So if we will see into the page fault and page hit ratio in this algorithm we got more page hits means what here the processing is faster as compared to other algorithm. So this optimal page replacement strategy is based out of this page replacement algorithms. So now, so let's calculate the total number of page faults. So now here total number of page faults are we have marked page faults by the cross marks 1, 2, 3, 4, 5, 6 and 7. So here total 7 page faults occurs. So now next one is page hit we need to calculate, right? So now page hit is equals to what? We have marked the tick marks. So now here 1, 2, 3, 4 and 5. We got the 5. So in this example we got the more page number of page hits means this algorithm is best for the use, fine. So this optimal page replacement is possible to implement in operating system means what? This page replacement strategy is best but what we are required is we can use it in real time. So think and answer no because operating system cannot know the future request means what? Operating system cannot identify the future page references because which page is needed by the application we don't know operating system don't know that one. That's why this is a theoretical concept still this optimal page replacement is not yet implemented in our operating system concepts. So use of optimal the use of optimal page replacement is a setup a benchmark so that other page replacement can analyze and use it. Now the references are we got this concept from the operating system concepts by the Galbin. Thank you. Thank you. Bye. Bye. Bye. Bye. Bye.