UNIT IV · MEMORY MANAGEMENT · OS SYLLABUS

MEMORY//PARTITION

How operating systems carve physical memory into usable regions — and why fragmentation is the price we pay.

OS
P1 · 120KB
P2 · 90KB
▤
FREE
P3
0%Utilization
0KBFragmentation
3Algorithms
3Strategies

Why Memory Management?

Modern systems run dozens of processes concurrently. The OS must allocate, protect, and reclaim RAM — or everything collapses into chaos.

LOGICAL
0x1A00
MMU
→
PHYSICAL
0x3F00
RELOCATION

Logical addresses translate to physical ones transparently at runtime.

PROCESS
A
→
TRAP
PROCESS
B
PROTECTION

Hardware barriers prevent any process from touching another's memory.

PROC
P1
→
→
SHARED
libc.so
→
→
PROC
P2
SHARING

Multiple processes share one physical copy of common library code.

LOGICAL ORGANIZATION

Segmented logical view maps onto a flat physical address space.

// MEMORY HIERARCHY — SPEED vs CAPACITY
Registers
~0.3ns < 1KB
Cache (L1/L2/L3)
~1–10ns 256KB – 32MB
Main Memory (RAM)
~60–100ns 4GB – 128GB
Secondary Storage (SSD/HDD)
~100μs – 10ms 256GB – 8TB

Partitioning Strategies

Three fundamental approaches to dividing RAM — each with trade-offs between simplicity, efficiency, and fragmentation.

Fixed / Static Partitioning

Memory is divided into a fixed number of partitions at system boot time. Partitions may be equal-sized or of varying sizes. A process must fit into a single partition. partition table in OS max P = num partitions

  • Simple — no runtime allocation decisions needed
  • Internal fragmentation — wasted space inside a partitionWASTE
  • No external fragmentationGOOD
// Memory Layout — 512KB Total
OS Kernel128KB0x0000
P1 — 90KBin 128KB partition0x2000
⚠ Wasted — 38KBinternal frag
P2 — 70KBin 128KB partition0x4000
⚠ Wasted — 58KBinternal frag
FREE128KB0x6000

Dynamic / Variable Partitioning

Partitions are created at runtime, sized exactly to the process request. No internal fragmentation — but holes accumulate as processes exit. uses First/Best/Worst Fit holes block large requests

  • Partitions fit process exactly — no internal wasteGOOD
  • External fragmentation accumulates over timePROBLEM
  • Compaction can defrag — but it's expensive to run
// After several allocations & deallocations
OS64KB0x0000
P1 — active96KB0x1000
▣ Hole — 32KBext. frag
P2 — active80KB0x3000
▣ Hole — 24KBext. frag
P3 — active112KB0x5000
FREE104KB0x7000

Buddy System

Memory is always allocated in power-of-2 sized blocks. When a block is freed, it checks if its "buddy" is also free — if so, they merge back into a larger block. Elegant recursion. used by Linux kernel 256KB → 128KB + 128KB

  • Fast allocation — binary tree structureFAST
  • Internal fragmentation — process gets next power-of-2WASTE
  • Easy coalescing — buddies merge automatically
// Interactive — use Prev / Next to step through allocation & deallocation
Step 1 / 5

Placement Algorithms

When a new process arrives, which free hole does it go into? Three algorithms, same memory state, different choices.

// Scenario: Memory with 3 holes — Process P requests 40KB

OS
HOLE 1
100KB
P·60KB
HOLE 2
50KB
P·20KB
HOLE 3
200KB
H1 = 100KB
P1
H2 = 50KB
P2
H3 = 200KB
→ New process P needs 40KB. Which hole is chosen?
First Fit
Scans from start → picks first hole that fits
✕ NO FIT
H1 chosen — 100KB ✓
Stops at H1 (100KB ≥ 40KB). Fast — minimal scan. Leaves a 60KB remnant in H1.
Remnant: 60KB · Speed: Fast
Best Fit
Scans all holes → picks smallest hole that fits
✕ NO FIT
H2 chosen — 50KB ✓
H2 (50KB) is the tightest fit for 40KB. Leaves smallest remnant (10KB). Better utilization, slower search.
Remnant: 10KB · Speed: Slow
Worst Fit
Scans all holes → picks largest hole
✕ NO FIT
H3 chosen — 200KB ✓
H3 (200KB) is largest. Leaves 160KB — biggest remnant, possibly useful for future requests. Counterintuitive strategy.
Remnant: 160KB · Speed: Slow
// This module covers Unit IV — Memory Partitioning
←
Deadlock
→
Paging & Page Replacement
→
Segmentation
COMING SOON

// Simulator ready

Build. Allocate. Fragment. Compact.

Load a preset or define your own memory layout. Watch fragmentation accumulate in real-time. Switch algorithms. Run compaction.

LAUNCH MEMORY SIMULATOR ▶