 I am Ajit Mundale from Department of Electronics. Today I am going to present a lecture on memory management in operating systems. Now these are learning objectives. At the end of this video we can able to describe what is the memory management and we are going to describe the different methods of memory allocation. Now in a computer we say that it performs better when we execute the process at a very high speed. Now to execute a process at a high speed we always require a processor which execute program very fast means we require faster CPU. Now in the computer the CPU also require data and data is stored in the memory. So in the computer to make a faster execution both CPU and memory should be faster. And we know here data is faced from the memory so that what memory we use it should give me less access time. It is also seen that when a CPU deals with bigger programs so to execute bigger programs it also requires some larger data and that is stored also in the memory so that we always require a very huge memory from which data can be acquired for the processing. So we summarize that in a computer we require a memory it should be having a larger size it should give me a smaller access time so that I will say it is faster in access rate and this also be cheaper that is it should be quite economical and has less cost. Again as I said earlier the conditions memory size access time and the cost are not matching. So it is always recommended that or we recommend here is that we can use the different types of memories in the computers and it is also found that when you execute some program that is we execute instructions that is found that we execute all the instructions sequence in a sequence here. So that during execution we always can predict what is the next instruction to be executed that is the way how we can organize the memory here. So the first is a secondary memory is a R disk it is a large in the size but requires more time to access because the space is larger and it gives me a less cost here. So this kind of memory is always be there in the computers to store a huge data required for the process. Then we use a main memory so it is having little less size for than the secondary memory but it is having a faster access rate and also the cost is more compared with the secondary memory. Now again this one more type of memory is coming here in the practice is called the cache. Cache is normally integrated with the CPU also can be called as the onboard memory here in the CPU which is much more faster also than the RAM but the cost is very high it is a solid state memory on the chip and then the instruction is now provided to the CPU for the execution. So last figure shows me here we can have this kind of organization first comes the secondary memory then comes the main memory then the cache and the CPU. So with this combination we can enjoy the benefit of the cheaper memory the faster memory and we can reduce the time of execution. And again we can say that how data is transferred here into the RAM means data is always stored in the secondary memory. So actually the CPU always finding data for execution from the faster memories that is the main memory. So that we have to bring a program or data from the secondary memory back into the main memory. Now actually this kind of process is called as the prefetch. And it is also seen that when we write program for execution it is always kept in the secondary memory and during the execution it is brought into the main memory. Let us see in this diagram here there are two dark spaces here that is one kb and two kb respectively they are already filled by some previous processes. So there are two spaces remaining as two kb and a three kb here. Now my secondary memory is holding number of programs here one two three and four they require different sizes here or they are having different sizes program one is having two kb size program four is having three kb size. So we are trying to transfer this program here into the empty space. So program one can be transferred in the space having a size of two kb so that fits in that space perfectly whereas the program four having three kb size is transferred in the bottom side here which is having a size of three kb. So it is the process normally called as a prefetching so that CPU rather reading data from secondary memory he read data from the main memory which is much more faster. Now this can if you suppose analyze the access time here as we say here normally during execution of the program CPU is always finding data from the main memory which is much more faster and quite rarely it is finding a data in the secondary memory because it is possible that program may use some jump statements here. So in that case the sequential prediction will be failing here so that at some time the CPU will not find data from the main memory. So in that case the CPU has to go back to the secondary memory and he will get required data for execution. For example suppose if I use two memories in my computer example is a secondary memory and the main memory. Now suppose secondary memory is a hard disk type here and suppose that requires thousand microsecond time to scan all the memory locations in the secondary memory whereas I got one more memory called as main memory that is RAM so that requires 10 microsecond time to access the complete RAM section. Now suppose I am having one task is transfer to the CPU for execution so obviously at the most time CPU finds the data or the program which is inside the main memory here. So normally the access time will be only of 10 microsecond but suppose in some cases the CPU do not find data in the main memory then he will go back to the secondary memory and suppose by fortune the required data is at the end of the secondary memory location there. So what CPU does here? First if you try to find data required for the execution in the main memory that requires 10 microsecond time to scan all the main memory when that does not find that data in the main memory the control goes back in the secondary memory and we know here at very end the required data is found here so again the CPU takes thousand microsecond time to access all the secondary memory here so in all I require thousand 10 microsecond time to access the data from the memory here. So this shows me here how data is accessed from the memory here so it is obvious that we have to keep this data inside the secondary memory but for execution we have to bring it in advance in the main memory here. Now there are two types of allocations of memory are possible one is called contiguous memory allocation and second is called as non-contiguous memory allocation. Now in the contiguous memory allocation as you see in the diagram here again there are two memories here one is secondary memory and second is the RAM here that is the main memory. Now I made partitions in the RAM of 2MB equal here and suppose program in the secondary memory is having length of 3MB, 2MB and 2MB here and the arrow shows that I can easily fit all this program in this empty spaces here. Now in the given diagram here this dark portion that is of 2MB size in which already some process is residing so I will not use that space is already occupied here so I can fit my processes or program here in the empty spaces. So program 3 will go in the initial space of 2MB, program 2 will go in the second empty slot here and the program 1B is going to stored here in the given memory location in the RAM as shown here the 2MB and I occupy one more 1MB space in the RAM in the RAM here as you see here in the RAM of 8 or 10MB size here we got 8MB space is empty here in which the 4MB are in continuous position here whereas the program number 1 in the secondary memory requires 5MB space here and we find that the 5MB space is not at all available in continuous position in the RAM here so program 1 is not able to fit in the given RAM. So the program 1 gate is get delayed here by the CPU for execution. Now this program is found normally in the contagious memory allocation and this program is normally called as external fragmentation. Now how to overcome this difficulty here? So this one more type of memory allocation is possible here is called as non-contagious memory allocation. Now in this case when we do not find the required space of required length in the RAM the program can be split in different parts here and this small parts are kept inside the empty spaces in the given RAM means at all the occasions the program is finding the required space in the RAM and we are going to overcome the problem of this external fragmentation there but in this case this one more drawback is coming here as we know here program is stored in different locations in the RAM so CPU requires more time to access all these program parts here. So it is somewhat time consuming but this one big advantage is that in this case we are avoiding the problems like external fragmentation and so that process is never get delayed for execution. Now these are my references and thank you friends, thank you for watching this video.