90 likes | 121 Views
Segmentation. Hoyoon Jun (hoyoonjun@davinci.snu.ac.kr) School of Computer Science and Engineering Seoul National University. Motivation. Base : 32KB +. 0KB. 0KB. Operating system. Program Code. 2KB. Heap. 4KB. 16KB. (free). (not in use). 10 KB free space
E N D
Segmentation Hoyoon Jun (hoyoonjun@davinci.snu.ac.kr) School of Computer Science and Engineering Seoul National University
Motivation Base : 32KB + 0KB 0KB Operating system Program Code 2KB Heap 4KB 16KB (free) (not in use) 10 KB free space (Allocated but not in use!) 32KB 48KB (not in use) 14KB Stack Bound : 16KB 64KB • The simple approach of using a base and bounds register pair to virtualize memory is wasteful
Concept of Segmentation 0KB 0KB Operating system Operating system 16KB 16KB (not in use) (not in use) Segmentation Stack (not in use) Program code Program code 32KB 32KB Heap Heap (not in use) Stack 48KB 48KB (not in use) • Define logical segment, a smaller chunk of logically related memory allocation unit • With base and bounds pair per segment, we can place segment independently in physical memory • We have three basic segments in an address space structure • Program code, heap, and stack 64KB 64KB
Hardware Implementation Segment registers 26KB Stack 28KB (not in use) Offset mask Segment mask < bound 32KB Program Code 34KB Heap Heap Segment Offset Virtual address 36KB Address translator should know about the segment id and offset of the given virtual address
Segment Growth Flag for Stack Stack (not in use) Segment registers Program Code Heap • Stack has one critical difference with regard to other segments • Stack grows backwards • Segment growth direction should be saved in segment register hardware
Sharing Support 0KB Operating system Segment registers 16KB (not in use) Stack (not in use) Program code Heap 32KB (not in use) Stack Heap 48KB • If several processes share same program code, there is no need to store same piece of code repeatedly • With hardware support of protection bits, we can share a segment across multiple processes without harming isolation 64KB
Fine-grained Segmentation 0KB Operating system Logical address space 16KB Segment table (not in use) 0 : main 1 : subroutine 32KB 2 : globals (not in use) 48KB 3 : symbols (not in use) (not in use) 4 : stack 64KB • With further hardware support, some systems provide fine-grained segmentation • Store segment table in memory • Enable a system to use segments in more flexible ways
Further Issues and OS Supports 0KB 0KB Operating system Operating system 16KB 16KB allocated (not in use) allocated 32KB 32KB Compact rearrange (not in use) (not in use) 48KB 48KB allocated (not in use) allocated 64KB 64KB • Segmentation raises a number of new issues • Segment registers must be saved and restored when a process is context-switched • Unlike address space, each segment might be a different size • Physical memory become full of little hoes (external fragmentation) • Many free-list management algorithms proposed (best-fit, worst-fit, buddy…)
Summaries • Segmentation helps us build a more effective virtualization of memory • Segmentation can better support sparse address spaces, by avoiding huge potential waste of memory between logical segments • Hardware implementation is also fast and straightforward • More benefits, like code-sharing, are available with appropriate hardware support • However, allocating variable-sized segments in memory leads to some problems • Free memory gets chopped up to odd-sized pieces, and makes further memory allocation more difficult • Still not flexible enough to support fully generalized, sparse address space • Large, but sparsely-used heap still consumes many memory • Need new solutions!