segmentation - computer science and...

15
Segmentation 1 CSE 2431: Introduction to Operating Systems Instructor: Adam C. Champion, Ph.D. Reading: §10.7, [OSC]; Chap. 16 (Operating Systems: Three Easy Pieces, http ://www.ostep.org/)

Upload: others

Post on 01-Oct-2020

15 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Segmentation - Computer Science and Engineeringweb.cse.ohio-state.edu/~champion.17/2431/13-Segmentation.pdf · Paging vs. Segmentation Consideration Paging Segmentation Must programmer

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/)

Page 2: Segmentation - Computer Science and Engineeringweb.cse.ohio-state.edu/~champion.17/2431/13-Segmentation.pdf · Paging vs. Segmentation Consideration Paging Segmentation Must programmer

Contents

• Page Replacement (Review)–Working Set–WSClock

• Segmentation• Segmentation + Paging

2

Page 3: Segmentation - Computer Science and Engineeringweb.cse.ohio-state.edu/~champion.17/2431/13-Segmentation.pdf · Paging vs. Segmentation Consideration Paging Segmentation Must programmer

Miss Ratio Curve

3

Page 4: Segmentation - Computer Science and Engineeringweb.cse.ohio-state.edu/~champion.17/2431/13-Segmentation.pdf · Paging vs. Segmentation Consideration Paging Segmentation Must programmer

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

Page 5: Segmentation - Computer Science and Engineeringweb.cse.ohio-state.edu/~champion.17/2431/13-Segmentation.pdf · Paging vs. Segmentation Consideration Paging Segmentation Must programmer

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

Page 6: Segmentation - Computer Science and Engineeringweb.cse.ohio-state.edu/~champion.17/2431/13-Segmentation.pdf · Paging vs. Segmentation Consideration Paging Segmentation Must programmer

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

Page 7: Segmentation - Computer Science and Engineeringweb.cse.ohio-state.edu/~champion.17/2431/13-Segmentation.pdf · Paging vs. Segmentation Consideration Paging Segmentation Must programmer

User’s View of Program

7

Page 8: Segmentation - Computer Science and Engineeringweb.cse.ohio-state.edu/~champion.17/2431/13-Segmentation.pdf · Paging vs. Segmentation Consideration Paging Segmentation Must programmer

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

Page 9: Segmentation - Computer Science and Engineeringweb.cse.ohio-state.edu/~champion.17/2431/13-Segmentation.pdf · Paging vs. Segmentation Consideration Paging Segmentation Must programmer

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

Page 10: Segmentation - Computer Science and Engineeringweb.cse.ohio-state.edu/~champion.17/2431/13-Segmentation.pdf · Paging vs. Segmentation Consideration Paging Segmentation Must programmer

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

Page 11: Segmentation - Computer Science and Engineeringweb.cse.ohio-state.edu/~champion.17/2431/13-Segmentation.pdf · Paging vs. Segmentation Consideration Paging Segmentation Must programmer

Example: Segmentation

11

Page 12: Segmentation - Computer Science and Engineeringweb.cse.ohio-state.edu/~champion.17/2431/13-Segmentation.pdf · Paging vs. Segmentation Consideration Paging Segmentation Must programmer

Segmentation Address Mapping

12

Page 13: Segmentation - Computer Science and Engineeringweb.cse.ohio-state.edu/~champion.17/2431/13-Segmentation.pdf · Paging vs. Segmentation Consideration Paging Segmentation Must programmer

Sharing of Segments

13

Page 14: Segmentation - Computer Science and Engineeringweb.cse.ohio-state.edu/~champion.17/2431/13-Segmentation.pdf · Paging vs. Segmentation Consideration Paging Segmentation Must programmer

Intel IA-32 Address Translation

14

Page 15: Segmentation - Computer Science and Engineeringweb.cse.ohio-state.edu/~champion.17/2431/13-Segmentation.pdf · Paging vs. Segmentation Consideration Paging Segmentation Must programmer

Summary

• WSClock Page Replacment• Segmentation• Segmentation + Paging

15