CoursifyCoursify

Memory Allocation with First-Fit and Best-Fit

Memory Allocation with First-Fit and Best-Fit

Verified Sources
May 27, 2026

In contiguous memory allocation systems, the operating system selects a free partition or hole for each incoming process according to a placement rule such as first-fit or best-fit.2 These strategies influence fragmentation and overall memory efficiency.2

We are given memory blocks, in order:

PartitionSize
1100 KB
2500 KB
3200 KB
4300 KB
5600 KB

Processes arrive in order:

ProcessSize
P1212 KB
P2417 KB
P3112 KB
P4426 KB

Under first-fit, the allocator scans memory from the beginning and places each process into the first sufficiently large free block. Under best-fit, it scans all available blocks and chooses the smallest one that can still hold the process, aiming to reduce immediate leftover space.2

Footnotes

  1. First-Fit Allocation in Operating Systems - Defines first-fit scanning behavior and discusses fragmentation effects. 2 3

  2. First Best and Worst Fit.pptx - Provides the exact worked example with these partition and process sizes. 2

  3. Memory Management in Operating System - Summarizes first-fit, best-fit, and fragmentation concepts in OS memory management. 2

First Fit, Best Fit, Next Fit, Worst Fit Memory Allocation

Key Interpretation

This problem is typically solved using variable-sized free blocks, where any leftover part of a block remains available for later allocation. That is why a 500500 KB block used for a 212212 KB process leaves a reusable 288288 KB hole.

Footnotes

  1. First Best and Worst Fit.pptx - Provides the exact worked example with these partition and process sizes.

First-Fit Allocation Walkthrough

  1. 1
    Step 1

    Scan from the first partition: 100100 is too small, 500500 is the first block large enough, so allocate P1 there. Remaining free space in that block becomes 500212=288500 - 212 = 288 KB.

    Footnotes

    1. First-Fit Allocation in Operating Systems - Defines first-fit scanning behavior and discusses fragmentation effects.

  2. 2
    Step 2

    Scan again from the beginning of memory among current free blocks: 100100, 288288, 200200, and 300300 are too small; 600600 is the first block large enough, so allocate P2 to the 600600 KB block. Remaining free space becomes 600417=183600 - 417 = 183 KB.

    Footnotes

    1. First-Fit Allocation in Operating Systems - Defines first-fit scanning behavior and discusses fragmentation effects.

  3. 3
    Step 3

    Scan from the beginning: 100100 is too small, then 288288 is large enough, so allocate P3 there. Remaining free space becomes 288112=176288 - 112 = 176 KB.

    Footnotes

    1. First-Fit Allocation in Operating Systems - Defines first-fit scanning behavior and discusses fragmentation effects.

  4. 4
    Step 4

    Scan current free blocks: 100100, 176176, 200200, 300300, and 183183 are all too small. Therefore P4 cannot be allocated and must wait.2

    Footnotes

    1. First-Fit Allocation in Operating Systems - Defines first-fit scanning behavior and discusses fragmentation effects.

    2. Memory Management in Operating System - Summarizes first-fit, best-fit, and fragmentation concepts in OS memory management.

The resulting first-fit state is:

ProcessAllocation
P1 = 212 KBplaced in 500 KB block, leaving 288 KB
P2 = 417 KBplaced in 600 KB block, leaving 183 KB
P3 = 112 KBplaced in leftover 288 KB block, leaving 176 KB
P4 = 426 KBnot allocated

Final free blocks after first-fit:

Free block sizes
100 KB, 176 KB, 200 KB, 300 KB, 183 KB

Notice the important effect of external fragmentation: although total remaining free memory is 100+176+200+300+183=959100 + 176 + 200 + 300 + 183 = 959 KB, no single block is at least 426426 KB, so P4 still cannot be placed.2

Largest free block after first-fit=300 KB<426 KB\text{Largest free block after first-fit} = 300 \text{ KB} < 426 \text{ KB}

Thus, first-fit leaves enough total memory but not enough contiguous memory for the last process.2

Footnotes

  1. Memory Management in Operating System - Summarizes first-fit, best-fit, and fragmentation concepts in OS memory management. 2

  2. OPERATING SYSTEMS - Real Memory Management PDF - Explains placement algorithms and external fragmentation in contiguous allocation. 2

Best-Fit Allocation Walkthrough

  1. 1
    Step 1

    Among all free blocks large enough for 212212 KB, the candidates are 500500, 300300, and 600600. The smallest adequate block is 300300, so allocate P1 there.2 Remaining free space becomes 300212=88300 - 212 = 88 KB.

    Footnotes

    1. First Best and Worst Fit.pptx - Provides the exact worked example with these partition and process sizes.

    2. Memory Management in Operating System - Summarizes first-fit, best-fit, and fragmentation concepts in OS memory management.

  2. 2
    Step 2

    Current adequate blocks are 500500 and 600600. The smallest adequate block is 500500, so allocate P2 there. Remaining free space becomes 500417=83500 - 417 = 83 KB.

    Footnotes

    1. First Best and Worst Fit.pptx - Provides the exact worked example with these partition and process sizes.

  3. 3
    Step 3

    Current free blocks are 100100, 8383, 200200, 8888, and 600600. The adequate blocks are 200200 and 600600, so choose 200200 as the smallest adequate block.2 Remaining free space becomes 200112=88200 - 112 = 88 KB.

    Footnotes

    1. First Best and Worst Fit.pptx - Provides the exact worked example with these partition and process sizes.

    2. Memory Management in Operating System - Summarizes first-fit, best-fit, and fragmentation concepts in OS memory management.

  4. 4
    Step 4

    Current free blocks are 100100, 8383, 8888, 8888, and 600600. Only 600600 is large enough, so allocate P4 there. Remaining free space becomes 600426=174600 - 426 = 174 KB.

    Footnotes

    1. First Best and Worst Fit.pptx - Provides the exact worked example with these partition and process sizes.

The resulting best-fit state is:

ProcessAllocation
P1 = 212 KBplaced in 300 KB block, leaving 88 KB
P2 = 417 KBplaced in 500 KB block, leaving 83 KB
P3 = 112 KBplaced in 200 KB block, leaving 88 KB
P4 = 426 KBplaced in 600 KB block, leaving 174 KB

Final free blocks after best-fit:

Free block sizes
100 KB, 83 KB, 88 KB, 88 KB, 174 KB

All four processes are allocated successfully. This aligns with standard best-fit behavior: choosing the smallest adequate free block tends to preserve larger blocks for later large requests.2

Footnotes

  1. First Best and Worst Fit.pptx - Provides the exact worked example with these partition and process sizes.

  2. Memory Management in Operating System - Summarizes first-fit, best-fit, and fragmentation concepts in OS memory management.

Processes Successfully Allocated

Comparison of how many processes each algorithm places

A direct efficiency comparison can be made in two ways:

  1. Number of processes allocated: best-fit allocates all 44 processes, while first-fit allocates only 33.2
  2. Memory utilization for this sequence: total requested memory is
212+417+112+426=1167 KB212 + 417 + 112 + 426 = 1167 \text{ KB}

Under first-fit, allocated memory is

212+417+112=741 KB212 + 417 + 112 = 741 \text{ KB}

Under best-fit, allocated memory is

1167 KB1167 \text{ KB}

So best-fit uses more of the available memory to satisfy actual process demand in this particular case.2

MetricFirst-FitBest-Fit
Processes allocated34
Requested memory satisfied741 KB1167 KB
Largest remaining free block300 KB174 KB
P4 allocated?NoYes

This example is a classic case where best-fit is more efficient because it avoids consuming large blocks too early.2

Footnotes

  1. First Best and Worst Fit.pptx - Provides the exact worked example with these partition and process sizes. 2 3

  2. OPERATING SYSTEMS - Real Memory Management PDF - Explains placement algorithms and external fragmentation in contiguous allocation. 2

  3. Memory Management in Operating System - Summarizes first-fit, best-fit, and fragmentation concepts in OS memory management.

Exam Strategy

For first-fit, always scan from the beginning and stop at the first usable block. For best-fit, compare all usable blocks before choosing. This prevents mistakes in allocation order.2

Footnotes

  1. First-Fit Allocation in Operating Systems - Defines first-fit scanning behavior and discusses fragmentation effects.

  2. First Best and Worst Fit.pptx - Provides the exact worked example with these partition and process sizes.

Common Mistake

Do not conclude that first-fit is better just because it may search less. In this problem, search speed is not the question; allocation efficiency is. Best-fit is more efficient here because it places all four processes.3

Footnotes

  1. First-Fit Allocation in Operating Systems - Defines first-fit scanning behavior and discusses fragmentation effects.

  2. First Best and Worst Fit.pptx - Provides the exact worked example with these partition and process sizes.

  3. Memory Management in Operating System - Summarizes first-fit, best-fit, and fragmentation concepts in OS memory management.

ProcessPlacement
212212 KB500500 KB block
417417 KB600600 KB block
112112 KBleftover 288288 KB block from the 500500 KB allocation
426426 KBnot allocated

Remaining free blocks: 100100, 176176, 200200, 300300, 183183 KB.

Concept Checks and Clarifications

Allocation Sequence Across the Two Algorithms

P1 = 212 KB

Step 1

First-fit selects 500500 KB; best-fit selects 300300 KB.2"

Footnotes

  1. First-Fit Allocation in Operating Systems - Defines first-fit scanning behavior and discusses fragmentation effects.

  2. First Best and Worst Fit.pptx - Provides the exact worked example with these partition and process sizes.

P2 = 417 KB

Step 2

First-fit selects 600600 KB; best-fit selects 500500 KB.2"

Footnotes

  1. First-Fit Allocation in Operating Systems - Defines first-fit scanning behavior and discusses fragmentation effects.

  2. First Best and Worst Fit.pptx - Provides the exact worked example with these partition and process sizes.

P3 = 112 KB

Step 3

First-fit uses leftover 288288 KB; best-fit uses 200200 KB.2"

Footnotes

  1. First-Fit Allocation in Operating Systems - Defines first-fit scanning behavior and discusses fragmentation effects.

  2. First Best and Worst Fit.pptx - Provides the exact worked example with these partition and process sizes.

P4 = 426 KB

Step 4

First-fit fails because no contiguous free block is large enough; best-fit still has 600600 KB available and succeeds.2"

Footnotes

  1. First Best and Worst Fit.pptx - Provides the exact worked example with these partition and process sizes.

  2. OPERATING SYSTEMS - Real Memory Management PDF - Explains placement algorithms and external fragmentation in contiguous allocation.

Final Conclusion

For the partitions 100100, 500500, 200200, 300300, and 600600 KB and the processes 212212, 417417, 112112, and 426426 KB, the placements are:

  • First-fit:
    212500212 \rightarrow 500,
    417600417 \rightarrow 600,
    112288112 \rightarrow 288 leftover,
    426426 \rightarrow not allocated.2

  • Best-fit:
    212300212 \rightarrow 300,
    417500417 \rightarrow 500,
    112200112 \rightarrow 200,
    426600426 \rightarrow 600.2

Therefore, best-fit makes the most efficient use of memory in this case because it allocates all four processes, whereas first-fit allocates only three.2

Footnotes

  1. First-Fit Allocation in Operating Systems - Defines first-fit scanning behavior and discusses fragmentation effects.

  2. OPERATING SYSTEMS - Real Memory Management PDF - Explains placement algorithms and external fragmentation in contiguous allocation. 2 3

  3. First Best and Worst Fit.pptx - Provides the exact worked example with these partition and process sizes. 2

Knowledge Check

Question 1 of 4
Q1Single choice

In first-fit, where is the 212212 KB process placed?

Explore Related Topics

1

Compare Between Compile-Time, Load-Time, and Execution-Time Address Binding

Address binding maps a program’s symbolic or relocatable addresses to actual physical memory, and it can be performed at compile‑time, load‑time, or execution‑time.

  • Compile‑time binding: the compiler produces absolute code; final addresses are fixed before loading and require recompilation if the start location changes.
  • Load‑time binding: the loader relocates code using a base register (e.g., Physical=Base+LogicalPhysical = Base + Logical); addresses are fixed after loading but no recompilation is needed.
  • Execution‑time binding: the CPU generates logical addresses that the MMU translates on each reference, allowing the process to move while running and supporting paging, segmentation, and virtual memory.
2

SSTF Disk Scheduling Worked Example: Total Head Movement for the Given Request Queue

The example applies the Shortest Seek Time First (SSTF) disk‑scheduling algorithm to a pending request queue, starting from head position 143, and computes the total cylinder movement.

  • Service order by minimum distance: 1431308691394810221470150917501774143 \rightarrow 130 \rightarrow 86 \rightarrow 913 \rightarrow 948 \rightarrow 1022 \rightarrow 1470 \rightarrow 1509 \rightarrow 1750 \rightarrow 1774
  • Stepwise moves: 13,44,827,35,74,448,39,241,2413, 44, 827, 35, 74, 448, 39, 241, 24 cylinders, giving total movement 17451745 cylinders
  • The previous request at 125125 only hints at recent direction; SSTF selects the nearest pending request regardless of it
  • SSTF typically lowers seek time versus FIFO but can starve distant requests, and a straightforward simulation runs in O(n2)O(n^2) time.
3

Which Component Is the Brain of a Microcomputer System?

The microprocessor is the brain of a microcomputer because it executes instructions, controls operations, and incorporates the ALU, control unit, and registers.

  • It combines all CPU functions on one chip, unlike RAM (volatile workspace) or ROM (permanent storage).
  • The ALU only performs arithmetic/logic and cannot direct the whole system.
  • Formula: Microcomputer Brain=Instruction Control+Execution+Coordination\text{Microcomputer Brain} = \text{Instruction Control} + \text{Execution} + \text{Coordination}
  • Exam strategy: discard memory components and sub‑units, leaving the microprocessor as the correct choice.
Chat with Kiro