1 / 13

Chapter 16 Segmentation

Chapter 16 Segmentation. Jake M. Choi (kidcoder@snu.ac.kr) School of Computer Science and Engineering Seoul National University. Too Much Wasted Space. 0KB 1KB 2KB . . 4KB 5KB 6KB . . . . . . 14KB 15KB 16KB. Wasted Space. Address Space

donnabishop
Download Presentation

Chapter 16 Segmentation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 16Segmentation Jake M. Choi (kidcoder@snu.ac.kr) School of Computer Science and Engineering Seoul National University

  2. Too Much Wasted Space 0KB 1KB 2KB . . 4KB 5KB 6KB . . . . . . 14KB 15KB 16KB Wasted Space • Address Space • Using only one pair of base and bounds registers is wasteful • Too much free space between the stack and heap • 32-bit address space • The entire address space will not fit in memory • 4 GB in size • Typical program uses MB of memory

  3. Segmentation 0KB 16KB 32KB 48KB 64KB MMU 3 • Base and bounds pair • For each logical segment • Operating system’s role • Separate code, stack, and heap • Different parts of physical memory • Avoids having unused virtual address space

  4. Example Translation 0KB 2KB 4KB 6KB 14KB 16KB • Virtual Address 100 • 0KB < 100 < 2KB = Code Segment (0KB – 2KB) • Is 100 < 2K Size? • Physical Address = 100 + 46KB = 47204 • Virtual Address 4200 • 4096 < 4200 < 6144 = Heap Segment (4KB – 6KB) • 4200 – 4096 = 104 • Is 104 < 2K Size? • Physical Address = 104 + 49152= 49256

  5. Example Translation 0KB 2KB 4KB 6KB 14KB 16KB • Virtual Address 7KB (7168) • 6KB < 7168 • 7168 – 4096 = 3072 • Is 3072 < 2K Size? • Results in Segmentation Fault

  6. Which Segment Though? • 12 11 10 9 8 7 6 5 4 3 2 1 0 Offset Segment • How does the hardware know which segment an address refers to? • Explicit Approach

  7. Which Segment Though? • How does the hardware know which segment an address refers to? • Implicit Approach • Hardware notices how the address was formed • Generated from PC = Code Segment • Address is based off stack or base pointer = Stack Segment • Anything else = Heap Segment

  8. The Stack • However, the stack grows backwards • Extra hardware support is needed • Extra bit • Set to 1 when segment grows in positive direction • Set to 0 when segment grows in negative direction • Example Translation • Access Virtual Address 15KB = 11 1100 0000 0000 (hex 0x3C00) • Top two bits 11 = stack segment • Offset is 3KB, 2KB – 3KB = -1KB • Absolute value of (-1KB) = 1KB < 2KB? • Simply add to base register (28K) to become 27K

  9. Sharing Memory Segments • Sometimes memory segments are shared • Code sharing is common even today • Protection bits • Read-only code segment • Additional hardware checks • If user process tries to write to read-only page or execute the non-executable • Exception should be raised by hardware

  10. Fine-grained vs. Coarse-grained Segmentation • Our examples had only a few segments (code, heap, stack) • Coarse-grained segmentation • Early systems had more flexibility • Fine-grained segmentation • Segment table • Stored in memory • Supports creation of large number of segments • Burroughs B5000 • OS/Hardware managed thousands of segments • Fine-grained segments = Better main memory utilization?

  11. OS Support 0KB 64KB • Segment registers • Must be saved and restored on context switch • Managing free space in physical memory • Each address space used to be same size • Now different sizes for each segment • External Fragmentation • 20KB Request comes in • 24KB free in separate chunks • OS cannot satisfy

  12. OS Support 0KB 64KB • Compacted memory • OS stops processes • Copies data to one contiguous region of memory • Changes registers to point to new location • Expensive • Memory-intensive • Uses too much processor time • Needs a simpler approach • Best-fit, worst-fit, first-fit algorithms • Buddy algorithm • Yet, external fragmentation is unavoidable

  13. Summary • Segmentation saves memory • Is fast • Has fringe benefits like code-sharing • However, has two problems • External fragmentation • Still not flexible enough • Large but sparsely-used heap • Entire heap must still reside in memory

More Related