What is the difference between paging and segmentation?
MediumConceptMemory Management
Answer
Paging divides a process's logical memory into fixed-size blocks called pages and physical memory into frames of the same size; any page can be placed in any free frame. Segmentation divides a program into variable-size logical parts, such as code, data, heap and stack, each called a segment with its own base address and limit (length).
- Paging is a physical, fixed-size division that the programmer never sees; segmentation follows the program's logical structure, which makes per-segment protection and sharing natural, such as read-only code.
- Paging has no external fragmentation but has internal fragmentation in the last page; segmentation has the opposite problem.
- A paged address is (page number, offset) and goes through the page table; a segmented address is (segment number, offset), and the offset is checked against the segment's limit.
- Some systems page each segment; modern 64-bit operating systems rely almost entirely on paging.
Example: the segment table says segment 2 (the stack) has base 4300 and limit 400. Logical address (2, 53) is valid because 53 < 400, so the physical address is 4300 + 53 = 4353. Address (2, 500) exceeds the limit, so the hardware traps and the OS reports a segmentation fault. With 1 KB paging, the same program would simply be cut into 1 KB pieces regardless of their contents.