Tuesday, 13 June 2017

Dynamic partitioning in operating system

 

In my previous post, I discussed fixed partitioning. You might want to check out that because this post is just the continuation of that.
If you remember the major drawback of fixed partitioning was that it could not allocate memory to processes even if we had memory. This was all because of the fixed partitions that were already created. To overcome this problem people came up with another solution which was called dynamic partitioning.

In this method, the memory was not divided until or unless a process asks for it. Whenever a new process used to come, the operating system uses to find out the size of the process and allocate that much space to the process. To illustrate this let's look at the following scenario.

We had 20 MB of memory available whenever the process P1 arrived we assigned it 1 MB of memory. Similarly, when process P2 arrived we assigned it 2 MB of memory and so on. So in this approach, we didn't waste any memory. This means there was no internal fragmentation.

But even this method had some flaws. Can you think of something? The limitations were that once the process completes its execution and empties the memory slot, we are left with a hole. The problem arises when the processes at different places in the memory finish the execution and create holes. The following scenario explains the drawback of dynamic programming.

Assume now after the execution processes P1, P3 and P5 left. Now we have holes of sizes 1 MB, 3MB and 5 MB. Now another process say P6 comes in and asks for 6 MB of space. Now you can see we have more than 6 MB of space but still we are not able to allocate any space to the process. This is called as external fragmentation.
One solution which was proposed to overcome this problem was compaction. In this technique, the free spaces or the holes were brought together to form a bigger hole. But this process was very tedious and consumed a lot of time. So dynamic allocation was also not a big hit though it was much better than the fixed partitioning.
So altogether dynamic partitioning had following advantages and disadvantages:

Advantages:


  • The degree of multiprogramming is dynamic as compared to static partitioning.
  • The size of the process is not limited by the size of the partition.
  • It doesn't suffer from internal fragmentation.

Disadvantage:

  • Allocation and deallocation of memory is tedious. 
  • It suffers from external fragmentation if compaction is not applied.

This was all about this topic. As always if you like the post, share it. If you have any queries, or you want to suggest something you can always ping me on Facebook or mention in the comments section below. I will be happy to help. You can follow me on Facebook or google+. Don't forget to follow the blog post.

Thank you!