Memory Allocation with First-Fit and Best-Fit
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:
| Partition | Size |
|---|---|
| 1 | 100 KB |
| 2 | 500 KB |
| 3 | 200 KB |
| 4 | 300 KB |
| 5 | 600 KB |
Processes arrive in order:
| Process | Size |
|---|---|
| P1 | 212 KB |
| P2 | 417 KB |
| P3 | 112 KB |
| P4 | 426 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
-
First-Fit Allocation in Operating Systems - Defines first-fit scanning behavior and discusses fragmentation effects. ↩ ↩2 ↩3
-
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
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 KB block used for a KB process leaves a reusable KB hole.
Footnotes
-
First Best and Worst Fit.pptx - Provides the exact worked example with these partition and process sizes. ↩
First-Fit Allocation Walkthrough
- 1Step 1
Scan from the first partition: is too small, is the first block large enough, so allocate P1 there. Remaining free space in that block becomes KB.
Footnotes
-
First-Fit Allocation in Operating Systems - Defines first-fit scanning behavior and discusses fragmentation effects. ↩
-
- 2Step 2
Scan again from the beginning of memory among current free blocks: , , , and are too small; is the first block large enough, so allocate P2 to the KB block. Remaining free space becomes KB.
Footnotes
-
First-Fit Allocation in Operating Systems - Defines first-fit scanning behavior and discusses fragmentation effects. ↩
-
- 3Step 3
Scan from the beginning: is too small, then is large enough, so allocate P3 there. Remaining free space becomes KB.
Footnotes
-
First-Fit Allocation in Operating Systems - Defines first-fit scanning behavior and discusses fragmentation effects. ↩
-
- 4Step 4
Scan current free blocks: , , , , and are all too small. Therefore P4 cannot be allocated and must wait.2
Footnotes
-
First-Fit Allocation in Operating Systems - Defines first-fit scanning behavior and discusses fragmentation effects. ↩
-
Memory Management in Operating System - Summarizes first-fit, best-fit, and fragmentation concepts in OS memory management. ↩
-
The resulting first-fit state is:
| Process | Allocation |
|---|---|
| P1 = 212 KB | placed in 500 KB block, leaving 288 KB |
| P2 = 417 KB | placed in 600 KB block, leaving 183 KB |
| P3 = 112 KB | placed in leftover 288 KB block, leaving 176 KB |
| P4 = 426 KB | not 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 KB, no single block is at least KB, so P4 still cannot be placed.2
Thus, first-fit leaves enough total memory but not enough contiguous memory for the last process.2
Footnotes
-
Memory Management in Operating System - Summarizes first-fit, best-fit, and fragmentation concepts in OS memory management. ↩ ↩2
-
OPERATING SYSTEMS - Real Memory Management PDF - Explains placement algorithms and external fragmentation in contiguous allocation. ↩ ↩2
Best-Fit Allocation Walkthrough
- 1Step 1
Among all free blocks large enough for KB, the candidates are , , and . The smallest adequate block is , so allocate P1 there.2 Remaining free space becomes KB.
Footnotes
-
First Best and Worst Fit.pptx - Provides the exact worked example with these partition and process sizes. ↩
-
Memory Management in Operating System - Summarizes first-fit, best-fit, and fragmentation concepts in OS memory management. ↩
-
- 2Step 2
Current adequate blocks are and . The smallest adequate block is , so allocate P2 there. Remaining free space becomes KB.
Footnotes
-
First Best and Worst Fit.pptx - Provides the exact worked example with these partition and process sizes. ↩
-
- 3Step 3
Current free blocks are , , , , and . The adequate blocks are and , so choose as the smallest adequate block.2 Remaining free space becomes KB.
Footnotes
-
First Best and Worst Fit.pptx - Provides the exact worked example with these partition and process sizes. ↩
-
Memory Management in Operating System - Summarizes first-fit, best-fit, and fragmentation concepts in OS memory management. ↩
-
- 4Step 4
Current free blocks are , , , , and . Only is large enough, so allocate P4 there. Remaining free space becomes KB.
Footnotes
-
First Best and Worst Fit.pptx - Provides the exact worked example with these partition and process sizes. ↩
-
The resulting best-fit state is:
| Process | Allocation |
|---|---|
| P1 = 212 KB | placed in 300 KB block, leaving 88 KB |
| P2 = 417 KB | placed in 500 KB block, leaving 83 KB |
| P3 = 112 KB | placed in 200 KB block, leaving 88 KB |
| P4 = 426 KB | placed 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
-
First Best and Worst Fit.pptx - Provides the exact worked example with these partition and process sizes. ↩
-
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:
- Number of processes allocated: best-fit allocates all processes, while first-fit allocates only .2
- Memory utilization for this sequence: total requested memory is
Under first-fit, allocated memory is
Under best-fit, allocated memory is
So best-fit uses more of the available memory to satisfy actual process demand in this particular case.2
| Metric | First-Fit | Best-Fit |
|---|---|---|
| Processes allocated | 3 | 4 |
| Requested memory satisfied | 741 KB | 1167 KB |
| Largest remaining free block | 300 KB | 174 KB |
| P4 allocated? | No | Yes |
This example is a classic case where best-fit is more efficient because it avoids consuming large blocks too early.2
Footnotes
-
First Best and Worst Fit.pptx - Provides the exact worked example with these partition and process sizes. ↩ ↩2 ↩3
-
OPERATING SYSTEMS - Real Memory Management PDF - Explains placement algorithms and external fragmentation in contiguous allocation. ↩ ↩2
-
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
-
First-Fit Allocation in Operating Systems - Defines first-fit scanning behavior and discusses fragmentation effects. ↩
-
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
-
First-Fit Allocation in Operating Systems - Defines first-fit scanning behavior and discusses fragmentation effects. ↩
-
First Best and Worst Fit.pptx - Provides the exact worked example with these partition and process sizes. ↩
-
Memory Management in Operating System - Summarizes first-fit, best-fit, and fragmentation concepts in OS memory management. ↩
| Process | Placement |
|---|---|
| KB | KB block |
| KB | KB block |
| KB | leftover KB block from the KB allocation |
| KB | not allocated |
Remaining free blocks: , , , , KB.
Concept Checks and Clarifications
Allocation Sequence Across the Two Algorithms
P1 = 212 KB
Step 1First-fit selects KB; best-fit selects KB.2"
Footnotes
-
First-Fit Allocation in Operating Systems - Defines first-fit scanning behavior and discusses fragmentation effects. ↩
-
First Best and Worst Fit.pptx - Provides the exact worked example with these partition and process sizes. ↩
P2 = 417 KB
Step 2First-fit selects KB; best-fit selects KB.2"
Footnotes
-
First-Fit Allocation in Operating Systems - Defines first-fit scanning behavior and discusses fragmentation effects. ↩
-
First Best and Worst Fit.pptx - Provides the exact worked example with these partition and process sizes. ↩
P3 = 112 KB
Step 3First-fit uses leftover KB; best-fit uses KB.2"
Footnotes
-
First-Fit Allocation in Operating Systems - Defines first-fit scanning behavior and discusses fragmentation effects. ↩
-
First Best and Worst Fit.pptx - Provides the exact worked example with these partition and process sizes. ↩
P4 = 426 KB
Step 4First-fit fails because no contiguous free block is large enough; best-fit still has KB available and succeeds.2"
Footnotes
-
First Best and Worst Fit.pptx - Provides the exact worked example with these partition and process sizes. ↩
-
OPERATING SYSTEMS - Real Memory Management PDF - Explains placement algorithms and external fragmentation in contiguous allocation. ↩
Final Conclusion
For the partitions , , , , and KB and the processes , , , and KB, the placements are:
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
-
First-Fit Allocation in Operating Systems - Defines first-fit scanning behavior and discusses fragmentation effects. ↩
-
OPERATING SYSTEMS - Real Memory Management PDF - Explains placement algorithms and external fragmentation in contiguous allocation. ↩ ↩2 ↩3
-
First Best and Worst Fit.pptx - Provides the exact worked example with these partition and process sizes. ↩ ↩2
Knowledge Check
In first-fit, where is the KB process placed?
Explore Related Topics
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., ); 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.
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:
- Stepwise moves: cylinders, giving total movement cylinders
- The previous request at 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 time.
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:
- Exam strategy: discard memory components and sub‑units, leaving the microprocessor as the correct choice.
