Basics of Memory Management


The functionality of a computer depends on 2 things - CPU and Memory. Till now, we have focused on CPU but from now on we will be focusing on memory. Today we will begin with Basics of Memory Management.

Basics of Memory Management


Criterias of  Memory

Size : It is always desirable to have a larger memory so that we can solve large problems as well.
Access Time : It is always desirable to have less access time and one shall access memory in least time.
Per unit cost : It is the cost of memory. So, one always wants the cost to be minimal.

But these 3 criterias cannot be archived together because they are contradictory to each other. If one is having size larger than the access time will be larger too. That's why we do not have a single memory but hierarchy of memory.

Hierarchy of Memory


Basics of Memory Management

We have a hierarchy of memory because we want to archive every criteria of memory which I mentioned above. Exactly, all those criteria are not archived but with a level of memories we try to have size maximum, access time minimum and cost per unit maximum.

Locality of reference

We know that a program executes sequentially. Now is it possible that sometimes this sequence of execution might break ?
Yes, sometimes this linear sequence of execution is broken if our program contain conditions like if-else, goto, continue etc. But still most of the time the program executes sequentially.
Now if suppose we have a program of 1000 lines and currently we are executing line 200 then it is expected that the next line to be executed is 201 only. This process is locality of reference.
Look at the picture above, we have a secondary memory which has a very large size as compared to main memory so access time in secondary memory is very high than main memory. Thus, whenever we try to access some line of program, the next few lines or blocks of code which are expected to be executed are moved from secondary memory to main memory to decrease the access time.

Hit Ratio

Hit ratio means the percentage of times a data is found in main memory.
In the above paragraph, we discussed that data is moved from secondary memory to main memory for fast access. Now, is it possible that everytime the data we are looking for is present in the main memory ?
No, in all cases 90 % of the data is present in main memory and the remaining 10 % of the data is fetched from secondary memory.
So, this 90 % is the hit ratio of main memory.

Now, you can observe that secondary memory is kind of backup memory because all the main data is present at main memory and if some data is missing then we can request that data from secondary memory. We have used main memory in order to reduce access time and we are using secondary memory to have larger memory size. So, we have archived 2 criterias of memory management.

Now, look at the picture above you will find that we can have another level of memory known as cache memory. But cache memory comes under the topic of computer system architecture so for now we can ignore cache memory.

Q.  If access time from secondary memory is 100ms and access time from main memory is 10ms and hit ratio is 0.9. Then find the average access time.

Ans. Hit ratio is given 0.9 which means in 90 % of the cases data is found in main memory but in 10 % of the cases we will have to access secondary memory.
Avg access time = 0.9(access time from main memory) + 0.1(access time from main memory + access time from secondary memory)
Avg access time= 0.9(10) + 0.1(10+100)
Avg access time= 9 + 11
Avg access time =20ms

Next we have to study 2 important concepts which are how data is moved from secondary memory to main memory( contiguous or non-contiguous allocation) and how the address is translated from logical to physical address.

Post a Comment (0)
Previous Post Next Post