70 likes | 185 Views
Chapter 16 Segmentation. Chien -Chung Shen CIS, UD cshen@cis.udel.edu. Support Large Address Space. With base and bounds registers, MMU could relocate the entire address space to different parts of physical memory Any thing you don’t like? F ree ( unused) space between heap and stack
E N D
Chapter 16Segmentation Chien-Chung Shen CIS, UD cshen@cis.udel.edu
Support Large Address Space • With base and bounds registers, MMU could relocate the entire address space to different parts of physical memory • Any thing you don’t like? • Free (unused) space between heap and stack • Solution: segmentation[base-bounds pair for each logical segment (e.g., code, heap, stack) of the address space allow them to be places in different parts of physical memory]
Segmentation • Only used memory is allocated space in physical memory • A set of base and bounds registers • Segment Base Size • Code 32K 2K • Heap 34K 2K • Stack 28K 2K • Notion of offset • Virtual address 100 ? • 32K = 32768 • within code: 32868 • Virtual address 4200 ? • 34K = 34816 • within heap: 34920 • Segmentation fault: refer to illegal address
Mechanism • Explicit approach • 3 segments: 2 bits • e.g., 4200 • offset < bound (OK) • Implicit approach: based on how address is formed • from CPU (program counter) -> code • based on stack pointer -> stack • else -> heap
Stack – Grow Backward • Segment Base Size Grows Positive Code 32K 2K 1 Heap 34K 2K 1 Stack 28K 2K 0 • VA 15KB -> 27KB 11 1100 0000 0000
Sharing • Sharecertain memory segments between address spaces: codesegment • Protection bits per segment indicating R, W, X • Segment Base Size Grows Positive Protection Code 32K 2K 1 R-X Heap 34K 2K 1 R-W Stack 28K 2K 0 R-W
OS Support • Context switching • segment registers must be saved/restored • Managing free space in physical memory • external fragmentation (holes of free space) • compaction