What is Paging and Segmentation?
Paging and segmentation, told as a story about whether to cut the parts-warehouse shelf into equal slots or by what each part is for.
Every shelf slot is the same size, but work items come in every size.The puzzle: what size to cut memory (the shelf) into.
With same-size slots only, small items leave empty room and big ones get cut across slots.Same-size slots are easy to manage, but they don't fit the shape of the items.
Paging cuts memory into equal slots; segmentation cuts it by use.Both turn a virtual address into a real memory location.
Paging leaves scraps inside slots; segmentation leaves gaps between chunks.A hybrid also exists: segments cut again into same-size pages.
For location, a page table needs only a frame number; a segment table needs start and length.The address lookup and page faults are on the virtual-memory page.
Paging cuts memory into same-size slots, while segmentation cuts it by use (code, data, stack, and so on) — two ways of turning a virtual address into a real memory location.
Paging divides both virtual and physical memory into fixed-size chunks (pages/frames) matched through a page table — simple to implement, with no external fragmentation, though a partly filled last page wastes space (internal fragmentation). Segmentation divides a program into meaningful units (code, data, stack) and records each one's start and length in a segment table. Units that match meaning make protection and sharing easier, but their varied sizes can leave gaps between segments (external fragmentation). Systems such as Multics and 32-bit x86 combined segments with paging; modern 64-bit operating systems rely mostly on paging.
When grown-ups say it
- Paging
- Cutting memory into same-size slots. Splits by size alone, whatever's inside.
- Segmentation
- Cutting memory by use. The code, data, and stack zones are covered here. → the rule for dividing the workspace into zones
- Internal Fragmentation
- Leftover space wasted inside a fixed-size slot. Occurs in paging.
- External Fragmentation
- Unusable gaps left between chunks. Common in segmentation.
- Page Table
- The table matching virtual pages to real frames. The core structure of paging. → the fake map that makes the whole warehouse mine
- Segment Table
- The table recording each segment's start and length. Blocking addresses past the length also gives protection.
- Segmented Paging
- A hybrid that cuts each segment again into pages. Segments handle protection and sharing; pages avoid external fragmentation.
- Virtual Memory
- A fake map that shows each process memory as its own private space. Paging and segmentation are two ways to build this map. → the fake map that makes the whole warehouse mine