Memory management is the OS function that handles allocation and deallocation of memory to processes. It tracks which parts of memory are in use, allocates memory to new processes, and frees memory when processes terminate.
Contiguous vs Non-Contiguous Allocation
| Scheme | Description | Fragmentation |
|---|---|---|
| Contiguous | Each process occupies a single contiguous block of memory | External fragmentation |
| Paging | Process divided into fixed-size pages, loaded into arbitrary frames | Internal fragmentation (page boundary waste) |
| Segmentation | Process divided into variable-size segments (code, data, stack) | External fragmentation |
Fragmentation
- Internal fragmentation: allocated memory block is larger than requested — the rest is wasted inside the block. Common with fixed-size partitions and paging (last page is rarely full).
- External fragmentation: total free memory is sufficient, but it’s scattered in small holes — no contiguous block large enough for a request. Solved by paging.
Paging
Physical memory is divided into fixed-size frames. Logical memory is divided into pages of the same size. A page table maps page → frame.
Logical address: [page number | offset]
↓
Page table lookup
↓
Physical address: [frame number | offset]
TLB (Translation Lookaside Buffer): A fast hardware cache that stores recent page→frame translations. Without a TLB, every memory access requires two physical accesses (one for the page table, one for the actual data). The TLB reduces this to one in the common case.
Segmentation
Segments are variable-sized logical units: code segment, data segment, stack segment. Each segment has a base address and a limit. Segmentation matches the programmer’s view of memory — different segments for different purposes.
Q: What’s the difference between internal and external fragmentation?
A: Internal fragmentation is wasted space inside an allocated block (e.g., a 14KB process in a 16KB partition — 2KB wasted). External fragmentation is free space scattered in small holes — total free memory is sufficient but no single block is large enough.
Q: Compare paging and segmentation.
A: Paging divides memory into fixed-size frames — no external fragmentation, but internal fragmentation. Segmentation divides memory into variable-sized logical units — matches the programmer’s view, but causes external fragmentation. Paging is transparent to the programmer; segmentation is visible.
Q: What is a page table?
A: A per-process data structure that maps virtual page numbers to physical frame numbers. Each process has its own page table. The CPU’s MMU uses it to translate every memory address.
Q: Why do we need a TLB?
A: Without a TLB, every memory access requires two RAM accesses (page table lookup + data access) — doubling memory latency. The TLB caches recent translations in fast CPU memory (usually fully associative), making the common case a single access.
Premium Content
Unlock Memory Allocation & Paging and all premium lessons with a subscription.
From ₹199.99/year — See plans