Worst Fit Allocation

Worst Fit - Simulation

Worst Fit

In Worst-fit, the entire list of blocks must be searched the largest block and allocate this block. Reduce the rate of production of small gaps. In contrast, this strategy produces the largest leftover block, which may be big enough to hold another process. But, if a process requiring larger memory arrives at a later stage then it cannot be accommodated as the largest hole is already split and occupied.


How does it work?

In Worst fit memory allocation scheme, the operating system searches that can –

  • Accommodate the process
  • Also, leaves the maximum memory wastage

Example:

Given 5 partiton of size 3KB, 5KB, 2KB, 4KB and 1 KB respectivly, if a new process A of 1KB arrives to main memory it is alloted to partition 2 of size 5KB which leaves memory wastage of 4KB.


Implementation of Worst-fit

  1. Input memory blocks with size and processes with size
  2. Initialize all memory blocks as free.
  3. Start by picking each process and find the maximum block size that can be assigned to current process i.e., find max (Partition 1, Partition 2,......, Partition n > processSize [current] if found then assign it to the current process.
  4. If size-of-process <= size-of-block if yes then assign and check for next process.
  5. If not then leave that process and keep checking the further processes.

Advantages of Worst fit Allocation
  1. Since this process chooses the largest hole/partition, therefore there will be large internal fragmentation. Now, this internal fragmentation will be quite big so that other small processes can also be placed in that leftover partition.

Disadvantages of Worst fit Allocation
  1. It requires O(n) time to search the entire list and find the Largest one.
  2. If the upcoming processes sizes are large than the holes created by worst-fit allocation then they are left unused until enough space is left free.

Simulations

Card image cap
MVT-Worst fit Simulation

Try out worst fit allocation in variable task with visualising the process allocation in main memory

Go to simulator
Card image cap
MFT-Worst fit Simulation

Try out worst fit allocation in fixed task with visualising the process allocation in main memory

Go to simulator