Skip to main content
Loading Explore guides…
Memory Management in OS · Acedra
Home
Explore
Computer Science
Memory Management in OS
Sign in to save
Chat
If YouTube asks you to sign in, open the video on YouTube.
Watch on YouTube
Reload player
Transcript
60 segments
Copy
Hide video
0:00
Memory Management in Operating System. Memory Management in Operating System is what? It is a kind of method or it is a kind of functionality to manage the various kind of memories. Means in our laptop, in our system, there are lot of different types of memories available like we are having RAM, like we are having Hard Disk, like we are having registers, so how we can manage all the memory resources in a more and more efficient manner?
0:28
This is the functionality of the Operating System. So I have written a single line that method of managing the primary memory. Why I have written the primary memory? Because out of all the types of memories, the majority of the memory is what? The RAM. Means we have to concentrate more on the RAM, means our system, how it actually works. Let's see with a simple diagram.
0:57
CPU. The purpose of CPU is what? To execute the instruction, to execute the program. So program is what? A collection of instruction. So one by one instructions are to be executed, who does this? CPU. So CPU, it is generally directly connected with the registers,
1:15
registers as well as cache memory.
1:22
CPU is directly connected with the registers and cache. And it is also connected with the RAM,
1:34
which also known as Primary Memory.
1:43
And RAM is generally connected with the secondary memory. So we will see the hierarchy in the future videos on how the system is actually, how the memories are connected with each other, this I will tell you later. But the concept is what? The CPU executes instructions one by one and CPU is generally connected with what? With Register, cache and RAM. There is a direct connection. But secondary memory is not connected directly with the CPU. The reason is what? Speed.
2:20
Because secondary memory is very slow, CPU is very fast so that's why we generally cannot directly connect them. So that's why in between we put faster memories that is Register, cache and RAM. Now there is a funda of science that here we have some size of register, some size of cache, some size of RAM. But like we are having an important part that is the RAM. Here if I increase size of RAM,
2:50
then it will directly affect the cost of the system. Means RAM, cache and register if the size of any of these three, means if I put more registers in the system, put more cache or increase the RAM, then cost of the system will also get high. So if cost is very high then it is possible that it goes out of budget of normal user. So that's why generally the laptops or computers we purchase from the market, they have limited, like 4GB RAM is there, now 8GB RAM upto 16GB RAM is now available,
3:23
but primarily the value was less. The funda is what? Why are we discussing about RAM here? Because in secondary memory almost all programs, whatever number of processes or generally we call programs, all the programs are available in the secondary memory. All the programs are available in the secondary memory which are to be executed now. CPU will execute them, but how will CPU execute these processes?
3:55
For that I will have to bring the processes here, for CPU I will have to bring processes from secondary memory in the RAM so that CPU can directly interact with the processes and it can execute. This is a very important part. All the programs, like we make programs in C, in C++ all the normal programs we make, the programs are sitting idle in the secondary memory. because size of secondary memory is very big so there accommodate as many programs as you can.
4:30
Now when you have to execute these programs then to execute CPU is required. And how will CPU execute? CPU is not connected to secondary memory. So means we have to pick the programs and bring them where? In the RAM, so that CPU can directly interact with the RAM. And why does it have to come in RAM only? Because you can also use cache and register, size of register and cache is very less than RAM.
4:59
The registers generally in our laptops, they are in the KBs, Kilobytes. So that is very small size. Although they are very fast, but the size is very less. Just for the simplification what I am trying to say, let's remove this hierarchy.
5:16
We are not talking about the register and cache at this point of time. So means we are now talking directly about this. So means as many processes, as many programs or processes
5:29
are present in secondary memory, we need to swap in all these processes, means those processes we will have to bring in the RAM, when the process enters the RAM now CPU can directly interact with the process and it can execute them one by one. And this is called the Degree of Multiprogramming. What Multiprogramming concept says,
5:56
Multiprogramming means
6:00
whenever we are keeping the programs in the secondary memory and when we are bringing that program in the RAM then don't bring one program in the RAM try to bring more than one processes in the RAM. That is called the Multiprogramming. We can know from the name multiple programs, why multiple programs? why there is a need? That maximum, what is the line here? That bring maximum number of programs or processes from secondary memory in the RAM, in the main memory so that CPU can execute them.
6:37
Now what is the advantage of bringing maximum number of programs? The advantage is that higher the Degree of Multiprogramming higher the utilization of CPU. If we take simple example, let's say that if I bring P1 process in the RAM. I bring only one process in the RAM. CPU starts executing that process, it is executing, as we already know each process
7:08
can have 2 types of things, one is the CPU, one is the I/O. Means a process will get executed how will it execute? Either CPU will execute it and it is possible that that process makes a request for Input/Output in between. Means it wants to use printer or scanner or wants to read a particular file from secondary memory, then it is possible that it makes an I/O request. So when a process makes an I/O request,
7:39
then CPU at that time makes it free, means okay, get blocked and go there and start using I/O. So let's say that P1 was being executed, CPU is executing P1,
7:53
CPU is executing this P1, and in between P1 says that I want to do some I/O operation. If I want to do some I/O operations, if P1 is saying that then what will CPU say? Okay, you can do the I/O operation. Now that process exits CPU so at that time what is the CPU executing? CPU is free at that time because P1 process exits from here, exits from RAM, and it is doing I/O work, when it is doing I/O work then CPU at that time is not executing P1. So means we can say CPU will sit idle.
8:37
And this is what we should not do. If CPU is idle means obviously efficiency of the system will be down. Performance will be down. And we don't have to let it be down. So what is the Degree of Multiprogramming?
8:53
Degree of Multiprogramming is keep more and more number of processes in the RAM. Means bring as many number of processes as you can and try keep in the RAM so that efficiency of the system is very high, means when utilization of CPU is very high then performance of system will automatically increase. For more detail let's solve one numerical. We'll solve this with a numerical you will get more clarity from that.
9:22
Let's say
9:25
I'm having
9:28
RAM of size 4MB.
9:37
Let's say I'm having RAM of size 4MB and there is one process, process size is also 4MB.
9:45
RAM size is 4MB, process size is 4MB. Now how many processes can be there in the RAM? Simple, one. Because what is the RAM size? 4MB and what is the process size? 4MB. So it will be 1. So how many number of processes can come in the RAM? There is only 1 process that can come. So let's say that process P1 comes in the RAM.
10:10
Now there is a probability that process will go for the I/O operation. Let's say there is a probability K,
10:32
K is a probability or we can say K is time, amount of time that a process will do I/O operation. K is time for I/O operation.
10:47
A process will take K amount of time to do the I/O operation. So if out of total time, it is doing I/O operation for K time then for how much time is it executed in CPU? For CPU it will execute for (1-K) time. As we already know that one process does only 2 jobs, either it will be executed by CPU or it will perform I/O operation. So one process is going on, it is being executed by CPU, in between it says that I want to do some I/O operation.
11:21
Then okay, it will go for the I/O operation, so at that time CPU cannot execute it. So that's what we have taken here. Let's say that for K amount of time any process, take this P1 process, that P1 process for K amount of time is performing I/O operation. So if it is performing I/O operation for K amount of time, then how much will be CPU utilization here? CPU utilization is 1-K. Because subtracted K from total so 1-K. Now let's say this K amount of time is let's say 70%.
12:01
Means out of total time 70% of the time it does I/O operation so remaining 1-K that is 30% it does what? Performing in CPU. Means 70% it does I/O, so means 1-70%, 1 is 100%, so 100%-70% it will be 30%. So 30% what it is performing? CPU utilization. Means using the CPU. So check, what is the utilization here? How much is CPU utilization? Only 30%.
12:37
Why? The reason, because there was only one process. Now what we are doing,
12:44
let's increase the size of the RAM. Let's say that now RAM size let's take as 8MB.
12:53
Process size is same, process is still 4MB.
13:00
So size of one process is 4MB, size of RAM is 8MB, number of processes
13:06
number of processes that can come in the RAM, that can accommodate in the RAM it will be 2. 8MB divided by 4MB it will be 2. So now we can say 2 number of processes can come in the RAM. Now that same thing that if one process for K amount of time,
13:30
single, one process for K amount of time what is it doing? Performing I/O operation. If one process for K amount of time is performing I/O operation then here how many I have? 2 K. So means total time becomes how much? K square. So what is the total time? Upto K square time the processes are performing what? I/O operation. Then what will be the CPU utilization? CPU utilization will be 1-K^2.
14:07
First here it was only single because there was only 1 process, that's why what we did, what is I/O operation? For K amount of time. Here what is I/O? K^2 because here there are 2 processes both are using K amount of time so K*K will be K^2 will be the total time used for the I/O operation. So if K^2 is for I/O then how much for CPU utilization? 1-K^2. And value of K we have taken let's say 70% what is it doing? I/O operation. So CPU utilization here will be how much? 1-let's say (0.7)^2
14:47
which is equal to near about 76%. Approximately 76%. So see the difference, when there was only 1 process, the utilization was only 30%. Now I just increased the size of the RAM, CPU utilization is increased by a huge amount of time that is 76%. Let's say again increase, again we increase the size,
15:15
Now let's say the RAM is 16MB and the process is still 4MB.
15:25
Process still 4MB, RAM is 16MB, now how many number of processes? Number of processes will be 4.
15:36
How many number of processes can I accommodate in the RAM? Will be 4. So now 4 processes can be accommodated in the RAM. So same we are doing, if K is the amount of time that one process is doing the I/O operation.
15:54
One process is performing I/O operation for K amount of time so here if we say that let's say all 4 are doing the I/O operation at same time, what is the probability that all 4 are doing the I/O operation at same time? The total will be K to the power 4. Then what will be the CPU utilization? CPU utilization will be 1-K^4. And K value we have already taken as 70% that out of total time, 70% of the time it does I/O, so means if all 4 perform I/O operation at the same time
16:44
then the time will be K^4. So what is the CPU utilization? 1-K^4. So if you simply substitute the value K that is 70% so here I will have an answer Near about 93%. Approximately it will come 93 or maybe around 94% the result will come. You can simply substitute the value and you can find out it will be 93 or approximately 94 we can say. 93 point something so let's say approximately it is 94%, it is also approximate 76, so let's say approximate it is 94.
17:23
See what is the point? Point is that whenever we increase the size of RAM, the CPU utilization is increased. So means if I make number of processes very high or you can say, how will number of prcocesses be high? Here what was the number of processes? 1. Number of processes here? 2. Number of processes here? 4. But how did they become 4? We can only accommodate 4 when the size of RAM is big. So there are 2 points here, first we have to increase the number of processes.
18:00
To increase the number of processes means to increase the Degree of Multiprogramming, I will have to increase size of RAM. And if we increase size of RAM then obviously more and more processes will be accommodated, and when more and more processes are accommodated then CPU utilization will be high. So this is the concept. So here if I take number of processes upto 'n', means let's say if I take it upto 1-K^n, then value will come near about 100%. Means my CPU utilization will be 100%.
18:37
Because already it is increasing upto 94%, now if you want you can do 32MB,
18:44
increase size of RAM to 32MB and then, size of process is fixed that is 4MB, so automatically you can see the utilization is increasing. So what is my point here? Generally we say, in all the theory, we generally say that Degree of Multiprogramming means more and more number of processes in the RAM. This is the only definition. But how we can bring more and more number of processes? For that I will have to increase size of the RAM and when I increase size of the RAM
19:17
then definitely more and more number of processes will be accommodated there. And then CPU utilization will automatically increase. A real life example of this, a numerical we solved here so you can easily judge this from here also. So here my memory management technique, memory management technique says what? Although we have to manage all memories, Operating System manages all memories, but here for which memory this management is most important? RAM. Reason is that
19:49
whatever number of processes which are present in the secondary memory,
19:58
and this is my RAM, and this is the CPU. so whatever number of processes which are present where? In the secondary memory. So from the secondary memory, to bring more and more number of processes in the RAM, this is also responsibility of what? Operating System. So this is a part of the memory management. Second, we said that bring more and more processes in the RAM, so due to this functionality of Operating System increased, what is the functionality?
20:27
Allocation, deallocation. It will have to concentrate more on allocation and deallocation. When more and more number of processes come in the RAM then more and more allocation will happen and when the processes will go back then deallocation will be there. And here funda of security will also be used. Why? Because the more processes we bring in the RAM, it is possible that one or two processes may interfere with each other,
20:53
means their instructions may interfere with each other. So Operating System takes care of this also that no, this type of problem should not happen. The size or memory allocated to some process, it will use only that much space, more than that its instruction cannot come out. So funda of security, allocation deallocation, that is done by the Operating System in the memory management. So that's why this is the important part
21:22
that why we relate Degree of Multiprogramming to memory management and here the entire memory management, the majority of memory management is that bring more and more processes in the memory, in which memory? In RAM. But that is a challenge in itself. Challenge is in one more sense that it may happen that I bring a process entirely, one full process I bring in the RAM, and second can also be that I divide the process into fractions, and some of its part,
21:56
the part that is required I bring only that, that will be seen in Paging and Segmentation further. But yes, we can also bring the entire process in the RAM. But let's say that a process of 4MB we bring in the RAM, then it is possible that only 1 or 2 instructions we to be executed in it, so 1 or 2 instructions are in bytes, means CPU only wanted data of 1 or 2 bytes, but I bring 4MB data in the RAM to execute, then obviously here also efficiency of system can be affected because this much data
22:29
through buses, through the data bus you have to travel, so instead of travelling more data what we do? We generally divide the process in fractions, in multiple blocks and we bring blocks of some processes like we bring one block of P1, second block of P2, some other block of P3, some other block of P4 process, some other block of P5, some other of P6, means we try to bring their blocks in the RAM. But how we divide these blocks and all,
22:59
that will be seen in the further videos of Paging and Segmentation. So this is all about how we relate Degree of Multiprogramming and Memory Management with each other and why the Degree of Multiprogramming is very important, and how to achieve it? Concept is simple, increase the size of RAM and when you increase the size of RAM, more and more processes will be accommodated. And how will CPU utilization increase? You can easily check through this example.
23:29
So this is all about Memory Management and Degree of Multiprogramming. So if you like the video then please like it, share it and please subscribe my channel, thank you.
Here to help you learn
Sign in to keep a private conversation with your course tutor.
Ask me anything about the material…
Sign in to chat