important thing you should know is for execution of a process that process has to be in main memory that is for sure if one process is there suppose this is a process p1 and if CP wants to execute this process so this process this is now a secondary memory so for execution this process has to be loaded into your main memory that is the simple rule otherwise this process cannot be executed and second thing is as we know the size of main memory see main memory is also known as physical memory the size of main memory is what finite and may be sometimes it happens the size of this process is larger than this main memory size then we cannot load this complete process into main memory okay or maybe sometimes it possible see rather than rather than loading the complete process into main memory is it possible that we can we can load only some part of the process see because when CPU is working CPU is executing this process it is not like that CPU is executing the complete process baby CPU is executing only this part of the process may be CPU is executing only this part of the process so it is better to if it is better to load only this part or this part to main memory rather than loading the entire process into the main memory if you can implement this funda for memory management then what what is the benefit of this thing because as the size of this memory is finite so if you implement this funda only the required portion of that that process is to be loaded into the main memory then what will happen many many processes can reside in the main memory at same time because if you load the complete process then it will take larger space in the main memory and maybe maybe two processors can be there in main memory three processes can be there in main memory and if you look like this one dozen maybe at the same time 5 10 15 processes can reside in main memory ok now how does funda is to be implemented simple break is if we divide this process into these portions equal sized portions and this this is known as pages so process is divided into equal sized pages this is supposed page 0 1 2 3 4 we are we are taking page number at some time CPU is executing this process and CPU needs only the page number 3 so only this page is to be loaded into main memory these pages will not be loaded into main map so these pages will will be in secondary memory like that suppose this is our secondary memory what you can say hard disk ok somewhere in secondary memory all the pages of this process is there in secondary memory and when the CPU needs a particular page then that pages to be loaded into main memory this kind of fund is also known as demand paging and when you apply this funded and many processes can be there in main memory so it seems that that main size of main memory is very large but actually that's not true and that thing is known as what virtual memory because that is virtually it seems that the size of main memory is very large because many processes can be there in main memory why so because we are not loading the complete process into the main memory we are just loading the required pages into the main memory okay so that that thing is known as virtual memory actually virtual memory is say this this some portion of hard disk is known as virtual memory now see if at some point of time CPU needs this page number 2 of this process p1 now if this requested page is available in the main memory then normal execution we'll be there if some if suppose this page number two is not load not there in the main memory then that thing is known as page four if the needed page is not available in the main memory then that thing is known as page fault now if page fault occurs then what will happen if operating system finds that that particular page is not in main memory then what operating system will do first of all operating system will contact with hard disk where the process reside in highness it will find okay and it will find that page of that process the needed page of that process and it will load that page into main memory now if the situation is something like that the main memory is full see the process is divided into equal sized pages and the main memories is divided into frames like this equal sized frames if the memory if this main memory is full all the frames are having some pages so if this main memory is full then you cannot put the requested page the page number two in this main memory then what operating system will do obviously some page has to be swapped out in to secondary memory so that the new requested page can be swapped into main memory you see page guapo yamazaki minimum this a secondary memory made a la bodega that is known as swap out okay and when you put a page from secondary memory to main memory that is known as swapping now the question is which pages to be replaced the operating system will choose which page to swap out that thing is decided by page replacement algorithm so there are many algorithms to decide which to decide this thing that which pages to if main memory is full all the frames are full then which pages to be replaced with this new page for deciding this thing we have many types of algorithm so in this video we'll discuss first-in-first-out algorithm now one more thing is how operating system knows which page of which process is in main memory and which page of that process is in secondary memory obviously the operating system has to keep this information also that which paces in suppose the page of P this process p2 this two or three pages are in main memory and this zero one four are in secondary memory okay so operating system keeps this information also and for keeping this information one page table is there so this page table is also reside in this main memory okay somewhere so maybe here here this is base table many many information are stored in the space table I am just telling about valid and invalid bits if the space number 2 and page number 3 is in main memory then we said this bit to valid and if the particular page is not there in this memory than that that bit is corresponding to that page is set to I invalid bit now suppose main mode is completely full and you have to swap out some page from here to here and operating system using some page replacement algorithm operating system chose this 3 page number 3 to swap out in secondary memory now the operating system will also update this page table it have it has to update the space table ok so the bit corresponding to the space number 3 is said to invalid now why invalid because this page is not available in main memory right now because this face has been swept out to secondary memory so this is the processor when a page fault occurs an operating system will do operating system will first of all contact with the hardware to locate where that process is where the pages second thing is then operating system will choose the victim page which page is to be replaced or you can see which pages to be swapped out of secondary memory then that page would be swapped out and second that secondary memory and the requested page would be swapped into the main memory plus operating system will also update the space table the corresponding bit to that page which has been swapped out is set to invalid okay and the corresponding bit to the page which has been swapped in is set to valid so this is the processor so before going to that algorithm I just want to tell you one more thing one example of that page fold see when you open some movie in VLC player suppose this is your VLC player with this one is your screen so here you have some that bar and the cursor is now at this place at time zero zero and movies you have stuck at the movie now suddenly if you forward this cursor here to here maybe suppose at five minute then I guess you have noticed that that VLC player will not play this movie instantly okay it takes some time it takes maybe one second two second or three seconds why so because that is page fault you can say you can take something like this this complete is known as a process so this complete entire process will not be loaded into main memory when you start the movie okay all the pages of that process will not be loaded into main memory when when the operating system is using paging technique for memory management in that case only so maybe it's starting the operating system will load only some pages like this maybe from here to here okay and you suddenly put the cursor to here so this page is not there in the main memory so that is why it takes some time to load the space may be time for swap in and swap out that is why it takes VLC player takes some time to play the movie from here so see so for peas replacement there are many algorithms now which algorithm means to be choose there are many factors on which you will choose which page replacement algorithm is good when is this this also page fault should be less that algorithm should reduce page four that is one criteria now we'll discuss that first-in first-out algorithm now the question is something like this the reference string is given that this one pages reference string four pages it means CPU CPU request pages in this order it will request first of all the page number three then page number two then one three like this okay and you are given only three frames three frames has been allocated to this process okay f1 f2 and f3 now how you will apply the space replacement algorithm FIFO page replacement algorithm C and will also calculate the hit ratio and as well as the page number of page faults okay now see the first first requirement of CPU is what a page number 3 okay now check frame frame means this is our main memory now three frames are there allocated to this process allocated to this process having these these page numbers now you chip you check whether you have this page into this main memory no this one is empty this one is important this one is empty we don't have this page number okay so we'll swap in this page will load this page here in frame 1 and this is known as page fold because this page was not available in our main memory okay so this is no you can say a miss or you can say page is not available page is not available in the main memory okay second page now second is page number two check we have only one page having number three we don't have to so now the operating system will load this page here we have three in second frame we will put to say no need to swap out any page wise so because we still have two frames left two frames are still empty so we can put new page into frame two so this is also known as page phone because two was not available in our main memory so you can say page was not available or you can say it is a mess okay next is one see we have only page number 3 n 2 1 is not available now 3 2 still we have one frame empty so we will put one here and this is also a Miss or you can say page for now now our main memory is full now what to do see next page requirement is three the operating system first of all check whether if the spin is available in the main memory yes this is available see this one three so no there is no page fault so page is available so here three two and one no need to swap out and swap in okay next there's page number four is this page number available three two one no this is not available not available so this is a page fault you can say a miss now our memory is full now we have to swap out one page operating system has to swap out one page from main memory to secondary memory to put this needed pages into the frames because we have only three frames now which page is to be swapped out which pages to be selected as a width M page in first in first in first out algorithm so the page the oldest page obviously the names are just first in first out so the oldest page will be selected as victim the page which has come first very first and for this thing for this thing operating system will maintain a queue okay because the the in queue queue operates in which manner 3/4 manner so operating system will will maintain a queue like this and it will put the pages something like this and when when it has to select a page for swap out then it will select the page from the from front of the queue ok because we we insert data from the rear now which pain is to be selected out of three two and one which pages in the which page is the oldest page which has come first this three page this this page having number three so the operating system will swap out this page so here we will put four two and one will be same fine now see for one this pain is all already available so this is a hit for two and one pages available so it is a hit now next is six this page is not available now which page is to be swapped out out of these three pages which one is the oldest one see this 4 has come here this too has come ad from here and one has come here so see the sampled record I use to apply this trick basically I just see here only see 4 is here starting off to his hair and starting off one is here so obviously this one is the oldest Erna so you will choose this page 2 4 6 n 1 and this is a mess because this this page was not available now - if the space available no so this is a miss now which page is to be replaced for has come here 6 has come here only one has come here only so see after after looking at this table after looking at this scenario 6 was here initial point of 4 is here initial point of 1 is here so obviously this one is the oldest one ok so we will select 1 4 6 and 2 so this is the simple trick I used to apply next is for this page is available for so this is a hit for 6 - no need to do any swap out swapping now next is 3 4 6 2 this page is not available now which pin is to be selected see the initial point of 4 is here initial point of success here initial point of 2 is here so obviously this 4 is the oldest one so we will choose this 4 so 4 will be replaced with 3 3 6 2 and here is a Miss now next is 4 4 is not available now which page is to be tuesd initial point of 3 is here only 6 initial point of success here only initial point of this 2 is here only so 6 1 6 is the oldest one so we'll choose 6 3 and 2 here is also a miss because this page was not available next is to this page is available so here it is a hit three four and two next is one this is not a variable this is a Miss which pages to be selected three the initial point of three is here initial point of this one is here initial point of two is here so this is the oldest one so we will put one here four and three next is 4 4 is available this is a hit three four and one next is five this is not available so this is a Miss which pages will be selected see initial point of three is here initial point of four is here initial point of one is here so we will select three because this is the oldest one so here five four and one okay next is two next do is not aware available so this is a Miss which pins to be selected five initial point of five is here initial point of 4s here an initial point of this one is here so this is the oldest one so we'll put two here - what next is one one is available so this is a hit five two and one so next is three say this page is not available so this is a Miss which is to be selected or isn't over this five is initial point is here initial point of two is here initial point of one is here so this one is the oldest one okay so we'll choose this one - 105 4 4 is not available you will choose which one I guess 5 has here 2 is here and 3 is here so so sorry 5's here - 0 & 3 0 he needs to choose this one for 2 & 3 so number of page folds how many page holes you just count this cross one two three four five six seven eight nine ten eleven twelve thirteen and hit ratio hit ratio is what number of hits divided by total how many number of hits are there one two three four five and six six divided by total is how many is 19 total is 19 so this is what's the hit ratio you can also find out to miss a ratio that is 13 by 19 total number of Miss total number of a faceful divided by total so this is how the pay is replaced algorithm will work so in next video I'll discuss with you both that LRU technique and optimal page replacement technique will compare all the three techniques in that video so till then bye bye take it