The basic memory management approach is to divide memory into several fixed size of partitions where each partition accommodate only one program for execution. The program residing in memory will be bound by the number of partitions. When a program terminates that partitions is free for another program waiting in queue.
For example, refer the figure. the memory is divided in 6 regions the first region is reserved for the operating system. The remaining five regions are for user program area. The above figure there partitions are occupied by the program P1,P2,P3 only the first and last one are free for allocation. Once partitions are defined operating system keeps track of status of memory partitions.
The two most common strategies to allocate free partitions to ready processes are:
- First Fit: The approach followed in first fit is to allocate first free partitions large through to accommodate the process.
- Best Fit: The approach followed is the best fit is to allocate smallest free partition that meets the requirement of the process.
Both these strategies require a partition description table to find out the free partitions. However, the first fit terminates after finding the first such partitions whereas the best fit continues searching for the near exact size. As result, the first fit executes faster whereas the best fit achieves higher utilization of memory by searching the smallest free partition.
To explain these two strategies, let us take one example. A new process P4 with size 80K is ready to be allocated into memory whose partition layout is given in the figure using first fit strategy, P4 will get the first partition having 120K of unused memory space. This is internal fragmentation, Since the 120K of memory space is wasted. No other process requires this much of memory space will be allocated to the next partition but can not utilize this free space left in the above partition. Therefore, to reduce the internal fragmentation best fit will continue. Searching for the best posible partition and allocate the last partition to the process having fast 20k bytes of unused memory. Here also we have internal fragmentation but only 20k of memory space is wested.