Transcript for:
Least Recently Used (LRU) Page Replacement Algorithm

hi students coming to the next page replacement algorithm that is the LRU least recently used algorithm so in the previous video I explained about the free for first-in first-out replacement algorithm that is a page replacement algorithm now let us see the second technique that is the least recently used page replacement algorithm so here I am taking the reference string as this so this is a different string means this is a pages that the CPU is demanding there's a page demanding so let's see how this algorithm will work so the starting the main memory that is the RAM is having the three frames so everything is free free so now I want to the CPUs demanding for the reference page so the first is the CP is demanding that is the users this is the user reference stream so the user is remanding for this page seven so but the seven is not present in the main memory that is in the RAM the seven is not present so if the page that is requesting is not present in the main memory in the RAM then you call it as a page fault so whenever the page fault is occurred the CPU transfers the control that operating system to the operating system or operating system fetch the free frame from the disk and place in the main memory so that is a concept so first the page that is referenced by the user is the seven so seven is not placed in the main memory so we have to body abroad it from the disk and placed in the main memory so then the page fault will occur so there's a page fault because the requested page is not present in the main memory then you call it as a page fault so next I had to place zero so already the two frames are free so just place zero so this is also page fault because zero is not present in the RAM next I had to place one seven zero one so this is also page fault because one is not present in the Braham so now I have to place two means the CPU is demanding the user is demanding but for the page two but tui is not present in the wrap so it has to bring from the disk and we have to bring that page from the disk and place in the main memory but the main memory frames are already full so then we have to replace the page there is a page replacement technique so I have to use the least recently used page replacement technique so what does this least recently used least recently used means so I had to place two on the frame so which page I have to be replaced now I have to check which is the least recently used one is the most recently used so this is the most and the last one becomes the least so one is most recently so I don't want one next is 0 next 7 so 7 is the least recently used so in place of 7 I have to so just remove the 7 so in place of 7 I have to write to 0 1 so this is also page fault because 2 is not present in the frame so I had to I brought that page from the this now I have to place 0 so 0 is already the demanded page by the CP or the user is already present in the RAM so just write as it is so this you call it as a hit it means if already demanded page is present in the main memory in the RAM so then you call it as a hit if the page is not present that you call it as a page fault if already it is present then it is hit now I have to place 3 so 3 is not present in the RAM so if it is not present in the means it is a page fault so I had to bring from the disk so I brought the page 3 from the disk that is the reference ring 3 from the list then where I had to place so follow the least recently used algorithm page replacement algorithm so what is a recently used from this to zero to one so you had to check here so which is the least recently used zero zero is most recently next to two next to 1 so 1 is the least recently used so remove one ok so just remove one so in place of 1 you have to place 3 so this is same 2 0 3 so this is also page fault next I had to play a 0 but 0 is already present here so this is hit now I had to the CP is demanding the user is demanding for the page 4 so page 4 is not present here so this is a page fault so okay I brought from the disk so where I have to place so which page I have to be replaced so check the least recently used so from this you have to check the place recently use from here 0 3 0 2 ok so this 2 0 3 so 0 3 is 0 2 so which is this is the most 0s most recently used so next is 3 is most recently used next 2 is least recently used so just replace 2 in place of 2 I'm just writing for 0 3 so this is a page fault now I have to write 2 so to check which is the place recently used for or 0 or 3 from this which is the least 4 is most recently used so least recently used is 3 so in place of 3 I have to write to 0 4 so this is the page fault now I have to place 3 so now again check which is the least recently used from here 2 from 2 is the most recently next to for next to 0 so 0 is the least recently used so in place of 0 I have to replace with 3 4 - so this is also a page fault now right for the zero so which page I had to be replaced so check for release recently used so from three these three three four - so here are only three numbers so you had to check these three numbers only so three is most recently - is next for is least recently used so in place of four I have to write 0 3 2 so this is also page fault because 0 is not present now I had two three demanding the page 3 3 is already present in the RAM so right as this so this is hit next to one so one is not present in the frame main memory so on how to be replace the page because there is no space here so which page I had to be replaced check this which is the most recently used 3 is the most 0 3 & 2 so to Iza least recently used so in place of 2 I had to replace with 1 3 0 so this is also page fault so next I had 2 CPUs demanding for the page reference number 2 so 2 is not present here okay I had to bring from the disk so then where I had to place in the main memory so this is already full so which Peter had to be replaced now check for least recently used so one is most recently 3 is next and 0 0 is the least recently used so just replace the 0 with 2 3 1 so this is also page fault now 0 now again check which is the least recently used to is most recently one is next so 3 is the least recently used so in place of 3 I have to replace with 0 to 1 so this is also page fault so this is how the least recently used all that page replacement algorithm will be able so we have to replace the page which is really least recently used so then if the before number that is you call it as a most recently and the last number that it is at least recently so here how many hits are there it sees three and the Falls page hit page fault the page faults are 1 2 3 4 5 6 7 8 9 10 11 12 sutram so it this complete the page hits and page faults is completely based on the reference string so whatever the reference string you are given so based on that reference ring only the hit ratio and the fault ratio will be calculated so this heat and fall will be different for different reference strings so this is completely based on reference string that the user is selecting thank you