# Partition Allocation Methods in Operating System

In this tutorial, we will be covering the concepts of Partition Allocation methods in the Operating system.

As available memory blocks comprised of a set of holes of various sizes that scattered throughout the memory. Whenever a process arrives and needs memory, the system searches the set for a hole that is large enough for the arrived process.

In case if the hole is too large then it splits the hole into two parts. One part is allocated to the arrived process and the other part is returned to the set of holes.

Whenever the process terminates, it releases the block of the memory and the released block is then placed back into the set of holes. If the new hole is adjacent to other holes, these adjacent holes are then merged together to form a large single hole.

Now at this point system may need to check whether there are processes that are waiting for memory and whether this newly freed and merged memory can satisfy the demands of any process that is in the waiting queue.

The above-given procedure is a particular instance of the **general dynamic storage allocation problem**, which is concerned with how to satisfy a request that is of size **n** from the list of free holes.

As there are many solutions to this problem.

## Partition Allocation (Memory Allocation) Strategies

In the figure given below, there are strategies that are used to select a hole from the set of available holes.

Let us discuss these strategies one by one: memory management

## 1. First Fit Allocation

According to this strategy, allocate the **first hole or first free partition** to the process that is big enough. This searching can start either from the beginning of the set of holes or from the location where the previous first-fit search ended.

Searching can be stopped as soon as we find a free hole that is large enough.

Let us take a look at the example given below:

Process P1 of size 10KB has arrived and then the first hole that is enough to meet the requirements of size 20KB is chosen and allocated to the process.

## 2. Best Fit Allocation

With this strategy, the smallest free partition/ hole that is big enough and meets the requirements of the process is allocated to the process. This strategy searches the entire list of free partitions/holes in order to find a hole whose size is either greater than or equal to the size of the process.

Let us take a look at the example given below:

Process P1 of size 10KB is arrived and then the smallest hole to meet the requirements of size 10 KB is chosen and allocated to the process.

## 3. Worst Fit Allocation

With this strategy, the Largest free partition/ hole that meets the requirements of the process is allocated to the process. It is done so that the portion that is left is big enough to be useful. This strategy is just the opposite of Worst Fit.

This strategy searches the entire list of holes in order to find the largest hole and then allocate the largest hole to process.

Let us take a look at the example given below:

Process P1 of size 10KB has arrived and then the largest hole of size 80 KB is chosen and allocated to the process.

## 4. Next Fit Allocation

This strategy is the modified version of the First fit because in Next Fit and in this memory is searched for empty spaces similar to the first fit memory allocation scheme. But it differs from the first fit as when called Next time it starts from where it let off and not from the beginning.