First Fit Allocation

First Fit - Simulation

First Fit

In First-fit, scan the memory from the beginning and allocate the first available block that is large enough. It is one of the fastest algorithms as it would search only as little as possible. But, the remaining unused memory areas left after allocations become waste if it is too smaller. Thus request for large memory requirement cannot be accomplished. We will prove that the following problem, which algorithm makes the most efficient use of memory.


How does it work?

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

  • Accommodate the process
  • Nearest from starting/top of main memory

Example:

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


Implementation of First-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 check if it can be assigned to current block.
  4. If size-of-process <= size-of-block if yes then assign and check for next process.
  5. If not then keep checking the further blocks.

Advantages of First fit Allocation
  1. It takes lesser time compare to the other algorithms.
  2. It produces bigger holes that can be used to load other processes later on.
  3. It is easiest to implement.

Disadvantages of First fit Allocation
  1. It wastes a lot of memory. The processor ignores if the size of partition allocated to the job is very large as compared to the size of job or not. It just allocates the memory. As a result, a lot of memory is wasted and many jobs may not get space in the memory, and would have to wait for another job to complete.

Simulations

Card image cap
MVT-First fit Simulation

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

Go to simulator
Card image cap
MFT-First fit Simulation

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

Go to simulator