Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chien-Chung Shen CIS/UD

Similar presentations


Presentation on theme: "Chien-Chung Shen CIS/UD"— Presentation transcript:

1 Chien-Chung Shen CIS/UD cshen@udel.edu
Chapter 16 Segmentation Chien-Chung Shen CIS/UD

2 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 How to support large address space? (32-bit address space leads to 4GB in size) Solution: segmentation [base-bounds pair for each logical segment (e.g., code, heap, stack) of the address space]  allow segments to be places independently in different parts of physical memory

3 Segmentation Only used memory is allocated space in physical memory
Segment: a contiguous portion of address space that may be placed independently in memory A set of base and bounds registers: one for each segment Key: offset within each segment Virtual address 100 ? inside code 32K = 32768 (100 – 0) = 32868 Virtual address 4200 ? inside heap 34K = 34816 (4200 – 4096) = 34920 Segmentation fault: refer to illegal address

4 Which Segment Are We Referring To?
16 KB address space – how many bits as address? 14 bits How many segments do we have? 3 (code, heap, stack) How many bits do we need to represent 3 segments? 2 bits How large could each segment be? 212 = 4KB Use segment registers for address translation

5 Which Segment Are We Referring To?
Explicit approach 3 segments: 2 bits e.g., VA 4200 offset = ( ) < bound (so it’s OK) Hardware algorithm base and bounds registers are arrays SEG_MASK = 0x3000 SEG_SHIFT = 12 OFFSET_MASK = 0xFFF

6 Which Segment Are We Referring To?
Implicit approach: based on how address is formed from CPU (program counter) -> code segment based on stack pointer -> stack segment any others -> heap segment

7 Stack Anything different for stack?
grow backward Values of segment registers (one extra bit for direction of growth) VA 15KB -> ??? 3KB Given a segment of size 4KB, we get negative offset of -1KB (3KB – 4KB), i.e., the “base” is at 4KB, not 0KB. Add -1KB to base (28KB) to get 27KB

8 Sharing Share certain memory segments between address spaces (processes): code segment Protection bit per segment indicating R, W, X

9 OS Support Context switching Managing free space in physical memory
segment registers must be saved/restored Managing free space in physical memory external fragmentation (holes of variable-sized free space) – what happens when a 20KB segment comes? compaction

10 Summary Problems solved Issues still exist dynamic relocation
support sparse address spaces code sharing efficient segmentation via hardware registers Issues still exist variable-sized segments – external fragmentation still isn’t flexible enough to support a fully generalized, sparse address space


Download ppt "Chien-Chung Shen CIS/UD"

Similar presentations


Ads by Google