 Hello, welcome to the session on first out block replacement policies. This is Dhanan Patil, working as assistant professor in computer science and engineering department, Valchand Institute of Technology, Solop. At the end of this session, we will be able to explain before block replacement policy and solve problems on the same method and calculate the hit ratio. When a main memory block needs to be brought into main memory, while all the cache memory blocks are occupied, one of them has to be replaced. In the previous video lectures, we have discussed while executing the application the required main memory blocks to bring from main memory to the cache memory. So, while transferring the blocks from main memory to cache memory, we need to replace based upon the different mapping techniques, those we have discussed in the previous video lectures, direct mapping technique, associative mapping technique. So, in that in direct mapping technique, there is no need to worry about that which block to be replaced because it is already defined, we must replace in a round robin manner only, that we have discussed in the previous lecture. So, there will be no block replacement policy to be applied. And in the set associative and fully associative methods, so block replacement policy is required because there we can map any block of main memory to the any line of the cache. That is why we need to decide that which block to be replaced. So, to take a decision which block to be replaced in a cache memory, the block replacement policy is used. So, that replacement policies are used for associative and set associative mapping techniques. So, as we have discussed, it is not applicable for the direct mapping technique. The main goal of replacement policy is to maximize the hit ratio. So, even in using that memory mapping techniques also, the objective was that maximizing the hit ratio. Here the replacement policies also used to maximize the hit ratio. There are three commonly used methods that first in, first out, least recently used and optimal replacement policies. The first in, first out. So, this method, select for the replacement the block least recently loaded into the cache memory. So, based upon the block transferred from the main memory to the cache memory, the block which is least recently loaded means the block which is first loaded to the cache memory is first out while replacing any of the cache lines. So, the loading sequence number is associated with each block in the occupied list. If any block is transferred from main memory to the cache memory, that loading sequence number is associated with each block and those blocks are updated every time when a block is transferred to cache memory. Example, we will see the example. Consider a programming system in which M1 has capacity of three pages and execution of application needs five distinct pages that 1, 2, 3, 4, 5. The page address stream formed by executing application. So, here that M1 has a capacity of three pages means here the cache, M1 refers to the cache memory which is having three cache lines and that executing application needs to access the five distinct pages from the main memory that is 1, 2, 3, 4, 5. These blocks are accessed from the main memory and that executing that application needs to access these pages with a stream of this sequence. So, this is the sequence in which these blocks are accessed from the main memory. So, this is the solution for this example. So, here we can see the same stream we have taken here that 2, 3. So, that stream that is address trace, the order in which the different blocks are accessed. So, according to that first in first out method. So, first 2 is replaced in a cache memory and this is marked with a star. This indicating that the block 2 is replaced first into the cache memory. Initially, all the lines of the cache memory will be free. So, this is the first stage at the beginning all these stage will be empty. First that 2 is loaded to the cache memory and next 3 that it will search for the empty blocks. There are two empty blocks. So, the next block that 3 is replaced here are loaded into the cache memory. Next is to the page. First it will search again from the cache that 2 is already existed in the cache memory. So, if that 2 is already existed in the cache then no need to access that or no need to read that block from main memory. So, that time we will say that the cache hit occurs. So, here we can see at the last line this edge indicating that at this stage that cache hit occurs. Because the block 2 is already available in the cache memory. So, the hit occurs and no need to access this block from the main memory. That time again the 2 is loaded first into the cache memory. That same it will remain that 2 is marked with a star and the next 3 is already loaded. And in the next step or the for the next access that block 1 need to read from the main memory. So, here that it will find that empty block in the cache memory. So, it is going to load the block 1 from the main memory to the cache. Now the cache memory is full. So, while whenever that application need to access the next blocks to continue the execution. So, the next sequence is that fifth block need to be accessed. Here we can see. So, first it will find whether that 5 is present in this cache memory. Now this is the status of the cache memory at this stage. So, first it will find here whether that block number 5 is present no. So, if it is no then it will find that there is no empty blocks also. So, if there is no empty block and there is no existence of that block number 5 in the cache memory. So, it is going to overwrite the existing one of the cache line. That is based upon the PFO method that is first in first out. Which is least recently loaded into the cache. That 2 is loaded very earlier compared to all these blocks. So, 2 is overwritten. Here the 5 is replaced in place of the block number 2 in the cache memory. Now the 5 is loaded into the cache and the which one is the first in in this cache memory. So, third one is the first in into the cache compared to that 5 and 1. So, the 3 is marked with the star, star mark. Now if the next while continuing the execution the block 2 need to be replaced. So, again it will search in the cache memory 2 is existed no and there is no empty block in the cache memory. So, now the 2 is replaced at the block number 3 where it was loaded into the cache. So, now that cache that block number 2 is replaced at 3. And after replacing the 2 the 1 is oldest block in the cache memory which is loaded first compared to the existing block. So, 1 is marked with the star. Similarly, it will continue for the next sequence of the blocks also. Here the 4 is there is no 4 is not existed and there is no empty block. 4 is replaced by 1 and 5 is marked as the first in block. Next 5 1 so, while replacing the 5th one it will check that 5th one is already existed. So, there is no need to access from the main memory. So, again the cache hit occurs it will remain the oldest block. And again next third one the third one there is no third block in a cache memory and there is no empty blocks. The third one is replaced with 5 and 2 is marked with a star indicating that the first in. Similarly, it will continue so on. The second one is here the 2 is already existed. Again the cache hit occurs again the 5th one is replaced with 2. 4 is marked as star and 2 is replaced at the fourth block and 3 is marked as old one. So, here that execution of the current application ends. So, now after replacement strategy we can calculate the hit ratio. That is the number of hit is 3 number of hit occurs and divided by the number of access. The number of access is total 12 access are there in that the 3 are the cache hit. So, 3 divided by 12 equal to 0.25 is the hit ratio for this example. Here we can see. So, time to reflect now read the question and pause the video and write the answer. The question is consider a paging system in which M1 has a capacity of 4 pages. And execution of application needs the pages 1, 2, 3, 4, 5 and this is the stream in which these pages are accessed. So, here the cache memory is having a capacity of 4 pages. So, there will be 4 lines in a cache. So, at a time 4 blocks of main memory can be accessed. So, the answer is this is the answer. Here we can see there are 4 cache lines and this is the stream. So, we are applying the same method for this stream also. The hit ratio is there is number of hit is 2 and the total number access is 12. The hit ratio for this example is 0.16. This is the reference I have referred. Thank you.