Published by Patrick Mutisya · 14 days ago
An operating system must provide each running program with the illusion of a large, contiguous block of memory, even though the physical memory is limited and fragmented. This is achieved through virtual memory, which abstracts the actual hardware resources and allows the OS to:
Virtual memory extends the address space of a process by mapping virtual addresses to physical addresses. The mapping is performed by the Memory Management Unit (MMU) using structures such as page tables.
The relationship between a virtual address \$V\$, page number \$p\$, offset \$d\$, and page size \$S\$ can be expressed as:
\$V = p \times S + d\$
When a program accesses \$V\$, the MMU translates it to a physical address \$P\$ using the page table entry for \$p\$.
Paging divides both virtual and physical memory into fixed‑size blocks called pages (virtual) and frames (physical). Typical page sizes are 4 KB or 8 KB.
Segmentation divides a program’s address space into variable‑length logical units called segments (e.g., code, stack, heap). Each segment has a base address and a limit.
The translation from a logical address \$(s, o)\$, where \$s\$ is the segment number and \$o\$ the offset within the segment, to a linear address \$L\$ is:
\$L = \text{Base}s + o \quad \text{provided } o < \text{Limit}s\$
Segmentation provides a more natural view of program structure but can suffer from external fragmentation.
| Aspect | Paging | Segmentation |
|---|---|---|
| Unit size | Fixed (e.g., 4 KB) | Variable (defined by programmer) |
| Fragmentation type | Internal fragmentation only | External fragmentation possible |
| Address translation | Page number → frame number via page table | Segment number → base address via segment table |
| Protection | Same protection for whole page | Protection can differ per segment |
| Typical use | Core memory management in most modern OSes | Often combined with paging (paged segmentation) or used in systems emphasizing logical structure |
Many modern operating systems use a hybrid approach: a program is divided into segments, each of which is further divided into pages. This combines the logical organization of segmentation with the allocation efficiency of paging.