Memory Allocation Algorithms
Memory allocation is how the OS assigns portions of RAM to processes and reclaims them when processes finish. It must decide where each process goes and how much space it gets. Explore contiguous allocation in action: fixed vs dynamic partitioning and the classic First Fit, Best Fit and Worst Fit strategies, with an animated scan of every block.
Memory allocation is the method the OS uses to assign RAM to processes and reclaim it when they finish. The key question is whether a process must occupy one consecutive region or may be split across separate free regions.
Contiguous allocation
One continuous region
A process receives one continuous run of adjacent memory addresses. It is simple and fast to access, but finding a large enough run can cause external fragmentation.
Non-contiguous allocation
Scattered memory pieces
A process is divided into smaller pieces that can occupy separate memory locations. This uses scattered free space efficiently, but needs mapping tables and address translation.
What to notice: P1 uses 8–11 and P2 uses 16–18. Each process stays together, so each needs one hole large enough for its entire size.Use the buttons to remove either process and watch its units return to the free pool.
Fixed partitioning — live example
Press Place Job A to see how a 120 KB job is allocated under fixed partitioning and where fragmentation appears.
Real-world analogy: Parking a car in a row of bays
First Fit: Scan from the top and take the first block big enough.
B1
50 KB
50K free
B2
300 KB
300K free
B3
75 KB
75K free
B4
700 KB
700K free
B5
100 KB
100K free
Step 1 · What is happening?
The OS takes the next job from the queue and scans the free block list using First Fit.
Step 2 · Why this decision?
Scan from the top and take the first block big enough.
Step 3 · What changes in memory?
The chosen partition is marked busy; the leftover space inside it is internal fragmentation and cannot be reused.
Step 4 · Resulting state
Free sizes update, totals for used memory and fragmentation are recalculated, and the next job is considered.
First Fit
- J1 (20) → block 1 (50 KB)
- J2 (200) → block 2 (300 KB)
- J3 (50) → block 3 (75 KB)
- J4 (150) → block 4 (700 KB)
Internal fragmentation: 705 KB
External fragmentation: 100 KB
Unallocated jobs: 0
Best Fit
- J1 (20) → block 1 (50 KB)
- J2 (200) → block 2 (300 KB)
- J3 (50) → block 3 (75 KB)
- J4 (150) → block 4 (700 KB)
Internal fragmentation: 705 KB
External fragmentation: 100 KB
Unallocated jobs: 0
Worst Fit
- J1 (20) → block 4 (700 KB)
- J2 (200) → block 2 (300 KB)
- J3 (50) → block 5 (100 KB)
- J4 (150) → not allocated
Internal fragmentation: 830 KB
External fragmentation: 125 KB
Unallocated jobs: 1
Same blocks, same jobs — only the choice rule changes. Notice how Worst Fit destroys the biggest block early, while Best Fit leaves many tiny unusable holes.
Memory partitions: 50 KB, 300 KB, 75 KB, 700 KB, 100 KB. Jobs: J1 = 20 KB, J2 = 200 KB, J3 = 50 KB, J4 = 150 KB. Show the First Fit allocation.
1. Which algorithm always scans the whole free list before deciding?
2. Internal fragmentation happens mainly in…
3. Total free memory is 300 KB but the largest hole is 90 KB. A 120 KB job arrives. What happens?