Segmentation
1
CSE 2431: Introduction to Operating SystemsInstructor: Adam C. Champion, Ph.D.Reading: §10.7, [OSC]; Chap. 16 (Operating Systems: Three Easy Pieces, http://www.ostep.org/)
Contents
• Page Replacement (Review)–Working Set–WSClock
• Segmentation• Segmentation + Paging
2
Miss Ratio Curve
3
WSClock Page Replacement Algorithm
• Carr and Hennessey, 1981; used very widely (Linux)• Circular list as in the clock algorithm:
– Initially, list is empty; pages added to list as they’re loaded into memory– Each entry contains Time of last use plus reference, dirty bits.
• Algorithm: – At each page fault, the page pointed to by the clock hand is examined. – Repeat the following:
• If reference bit is 1, then page has been referenced during the current tick, so it’s in working set and bad candidate to remove. Clear reference bit, update time of last use.
• If reference bit is 0, then check if it’s in working set window (i.e., if Current Time – Time of last use is less than the working set window size time).
• If page is not in the working set and the page is clean, then replace it. • If the page is not in working set and page is dirty, request write to disk, and
move on to the next page in the circular list.4
Virtual Memory So Far• One-dimensional address
space
• An example: the compiling process
• Need a way to free programmers from managing expansion, contraction
5
Symbol Table
Source Text
Constant Table
Parse Tree
Call Stack
Segmentation
• Segment is a logical unit: programmer is aware of it, uses as such (e.g., code, heap, stack)
• Advantages:– Easy to handle dynamically expanded/shrunk data
structures– Linking is simplified if each procedure occupies a separate
segment– Facilitating sharing procedures/data– Different protection for different segments
6
User’s View of Program
7
Logical View of Segmentation
• Similar to variable partitioning• First fit, best fit, or worst fit• External fragmentation
8
1
3
2
4
User space
14
2
3
Physical memory space
Paging vs. SegmentationConsideration Paging Segmentation
Must programmer know that technique is being used?
No Yes
How many linear address spaces? 1 Many
Can total address space exceed size of physical memory?
Yes Yes
Can we distinguish procedures, data and protect each separately?
No Yes
Can tables whose sizes change be accommodated easily?
No Yes
Can we share procedures among users?
No Yes
Why was technique invented? To get large linear address space without having to buy more physical memory
To let programs, data be partitioned into logically independent address spaces; aids sharing, protection
9
Segmentation Architecture• Logical address: <segment-number, offset>• Each process has one segment table with each entry
for one segment• Each table entry has– Base: contains starting physical address where segment
resides in memory– Limit: specifies the length of the segment
• Segment-table base register (STBR): Points to the segment table’s location in memory
• Segment-table length register (STLR): Indicates number of segments used by a program
• Segment number s is valid if s < STLR 10
Example: Segmentation
11
Segmentation Address Mapping
12
Sharing of Segments
13
Intel IA-32 Address Translation
14
Summary
• WSClock Page Replacment• Segmentation• Segmentation + Paging
15