Table of contents
1.
Introduction
2.
Types of partitioning in contiguous memory allocation
2.1.
Variable size partitioning
2.2.
Fixed-size partitioning
3.
Types of partitions allocation techniques
3.1.
First fit
3.1.1.
Advantages of the first fit
3.1.2.
Disadvantages of the first fit
3.2.
Best fit
3.2.1.
Advantages of best fit
3.2.2.
Disadvantages of best fit
3.3.
Worst fit
3.3.1.
Advantages of worst fit
3.3.2.
Disadvantages of worst fit
3.4.
Next fit
3.4.1.
Advantages of next fit
3.4.2.
Disadvantages of next fit
4.
Frequently Asked Questions
4.1.
What is internal fragmentation?
4.2.
What is external fragmentation?
4.3.
Which partition allocation technique can be considered the best?
5.
Conclusion
Last Updated: Mar 27, 2024

Partition Allocation Technique

Author Ankit Kumar
2 upvotes
Operating Systems

Introduction

Memory management comes under the responsibility of Operating systems, and in this blog, we will learn about it. There are two types of memory allocation that the operating system handles. The first is contiguous memory allocation, and the second is non-contiguous memory allocation.

In non-contiguous memory allocation, the operating system manages a page table that includes each block's base address, acquired by the memory process.

This article will primarily discuss contiguous memory allocation, involving all the partition allocation techniques.

Let us begin the article by learning about different types of partitioning in contiguous memory allocation.

“Must Recommended Topic, Internal and External Fragmentation, Multiprogramming vs Multitasking"

Types of partitioning in contiguous memory allocation

There are two types in which the operating system can create partitions in the memory space.

  1. Variable size partitioning
  2. Fixed-size partitioning

Also, see Introduction to Memory and its Units

Variable size partitioning

In this policy, the operating system treats the memory as a single chunk and accordingly allocates parts of the memory as per the requirement of a different process. If possible, the leftover memory can be reused.

This policy is not recommended as the memory is allocated randomly, and thus it is very much unorganized.

The following figure shows that the operating system treats the whole memory as one unit and allocates the same amount of memory to the process, as per its requirements. 

Illustration Image

You can also read about the Multilevel Feedback Queue Scheduling and Open Source Operating System.

Fixed-size partitioning

In this policy, the operating system divides the memory into fixed-size partitions (The size of different divisions may vary). It then allocates these partitions entirely using other partition allocation techniques. Once allocated to a process, these cannot reuse the partitions in any case, and hence This will waste the memory remaining unused in the partitions internally.

The following figure shows partitions of different sizes inside the memory.

Illustration Image

As we have discussed different types of partitions now, we will see how partition allocation techniques help the operating system allocate partitions to the process inside the memory.

Types of partitions allocation techniques

There are four types of partitions allocation techniques 

  1. First, fit policy
  2. Best fit policy
  3. Worst fit policy
  4. Next fit policy

Let us discuss all of these in brief.

First fit

As the name suggests in this policy, the operating system starts searching the memory from the base and allocates the first partition capable enough to hold the process.

Advantages of the first fit

It is easy to understand, easy to use, and straightforward.

Disadvantages of the first fit

It performs very poorly in terms of both space and time.

Best fit

In this policy, we traverse the memory and allocate the smallest partition capable enough to hold the process.

Advantages of best fit

It performs best in fixed-sized partitions as it saves space.

Disadvantages of best fit

It isn't elementary to implement and is a very time-consuming process.

Worst fit

In this policy, we traverse the memory and allocate the giant partition, holding the process.

Advantages of worst fit

It performs best in variable size partitioning as the space can be reused once allocated, thus leading to low internal fragmentation.

Disadvantages of worst fit

It is suicidal to use this in the fix size partitioning schema as the internal fragmentation will be high.

Next fit

This policy is just a modified version of the first fit. Once it finds a suitable partition, it allocates that and starts searching for the subsequent request from where it was left and not from the beginning.

Advantages of next fit

It is swift and straightforward.

Disadvantages of next fit

It leads to high internal fragmentation in fixed-size partitioning.

With this, you successfully covered the different partitioning algorithms, and let us now see some of the frequently asked questions related to this topic.


You can also read about the interleave memory.

Must Read Evolution of Operating System

Frequently Asked Questions

What is internal fragmentation?

When the partition size of the process is larger than the request, the remaining memory is called internal fragmentation. It occurs only in fixed-size partitioning. In this case, once a partition is allocated, the operating system cannot reuse it.

What is external fragmentation?

When the space requested by the process is available in the memory but not in contiguous form and thus cannot be allocated, this wastage is called external fragmentation. It only occurs in contiguous memory allocation.

Which partition allocation technique can be considered the best?

There is no such best partition allocation technique, as every method has its advantages and disadvantages, and thus, We should use it according to the requirement of the process.

Let us now summarize what we have discussed in this article.

Conclusion

In this article, we first learned that memory allocation techniques could be of two types. The first would be contiguous, and the other would be non-contiguous memory allocation.

Then we focused on the contiguous part and learned about different types of partitioning. It was followed by other partition allocation techniques, which the operating system uses as per the requirement of the process. And at last, we saw some of the frequently asked questions related to it.

Recommended Reading:

Do check out The Interview guide for Product Based Companies as well as some of the Popular Interview Problems from Top companies like Amazon, Adobe, Google, Uber, Microsoft, etc. on Coding Ninjas Studio.

Also check out - Buddy System In OS

Also check out some of the Guided Paths on topics such as Data Structure and Algorithms, Competitive Programming, Operating Systems, Computer Networks, DBMS, System Design, etc. as well as some Contests, Test Series, Interview Bundles, and some Interview Experiences curated by top Industry Experts only on Coding Ninjas Studio.

Cheers!

Live masterclass