Virtual memory Segmentation fault
- OS places each of program heap stack in a different location in memory
- prevents unused space
- now, MMU has three base bound pairs
Segmentation is an archaic type of virtual memory management, where the virtual address space is divided into different segments (code, heap, stack) at different places in memory.
Each segment is a variable size, and can be dynamically resized. However, they can be large and costly to relocate. It leads to memory fragmentation (large gaps in memory) at the expense of unused space.
Each segment contains a base, limit, and permissions. The MMU checks that the offset is within the limit. If it is, it calculates the base and offset, and does permission checks. Otherwise, we get a segmentation fault.
The physical address is represented with: segment selector:offset
, i.e., 0x1:0xFF
translates to segment 0x1
, base 0x2000
, and limit 0x1FF
. Linux sets every base to 0 and limits to the maximum amount. Every x86 chip still has an MMU that functions like this.