cmsc421: principles of operating systems

21
1 CMSC421: Principles of Operating Systems Nilanjan Banerjee Principles of Operating Systems Acknowledgments: Some of the slides are adapted from Prof. Mark Corner and Prof. Emery Berger’s OS course at Umass Amherst Assistant Professor, University of Maryland Baltimore County [email protected] http://www.csee.umbc.edu/~nilanb/teaching/ 421/

Upload: fox

Post on 16-Jan-2016

29 views

Category:

Documents


0 download

DESCRIPTION

CMSC421: Principles of Operating Systems. Nilanjan Banerjee. Assistant Professor, University of Maryland Baltimore County [email protected] http://www.csee.umbc.edu/~nilanb/teaching/421/. Principles of Operating Systems - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: CMSC421: Principles of Operating Systems

1

CMSC421: Principles of Operating Systems

Nilanjan Banerjee

Principles of Operating SystemsAcknowledgments: Some of the slides are adapted from Prof. Mark Corner

and Prof. Emery Berger’s OS course at Umass Amherst

Assistant Professor, University of MarylandBaltimore [email protected]

http://www.csee.umbc.edu/~nilanb/teaching/421/

Page 2: CMSC421: Principles of Operating Systems

2

Announcements

• Midterm (29th of October in class)• Project 2 design document is due 26th October• We will do a review at the end of the class

Page 3: CMSC421: Principles of Operating Systems

How does all of this work?

• A process asks for memory to read/write/copy– Does not really care where the data came from– Registers, L1, L2, L3, Main memory, Network

memory or the disk• Key question: How do we make this

transparent from the process

Page 4: CMSC421: Principles of Operating Systems

4

Virtual vs. Physical Memory

• Processes don’t access physical memory– Well, not directly

• Apps use virtual memory– Addresses start at 0– One level of indirection– Address you see is not “real” address

Page 5: CMSC421: Principles of Operating Systems

Memory Pages

• Programs use memory as individual bytes• OS manages groups of bytes: pages

– typically 4kB, 8kB– Applies this to virtual and physical memory

• Physical pages usually called frames

A

Page 6: CMSC421: Principles of Operating Systems

Mapping Virtual to Physical

Page 7: CMSC421: Principles of Operating Systems

7

Why Virtual Memory?

• Why?– Simpler

• Everyone gets illusion of whole address space

– Isolation• Every process

protected from every other

– Optimization • Reduces space

requirements

Page 8: CMSC421: Principles of Operating Systems

Memory Management Unit

• Programs issue loads and stores• What kind of addresses are these?• MMU Translates virtual to physical

addresses– Maintains page table (big hash table):– Almost always in HW… Why?

MMU Physical Address

Virtual AddressProgram Memory

Page Table

Page 9: CMSC421: Principles of Operating Systems

Page Tables

• Table of translations – virtual pages -> physical pages

• One page table per process• One page table entry per virtual page• How?

– Programs issue virtual address– Find virtual page (how?)– Lookup physical page, add offset

Page 10: CMSC421: Principles of Operating Systems

Page Table Entries

• Do all virtual pages -> physical page?– Valid and Invalid bits

• PTEs have lots of other information– For instance some pages can only be read

Page 11: CMSC421: Principles of Operating Systems

11

Address Translation

• Powers of 2:– Virtual address space: size 2^m– Page size 2^n

• Page#: High m-n bits of virtual address• Lower n bits select offset in page

Lets take an example

Page 12: CMSC421: Principles of Operating Systems

12

Paging Hardware

Page 13: CMSC421: Principles of Operating Systems

Quick Activity

• How much mem does a page table need?– 4kB pages, 32 bit address space– page table entry (PTE) uses 4 bytes

• 2^32/2^12*4=2^22 bytes=4MB– Is this a problem?– Isn’t this per process?– What about a 64 bit address space?

• Any ideas how to fix this?

Page 14: CMSC421: Principles of Operating Systems

14

A

B

AB

Locality

• Most programs obey 90/10 “rule”– 90% of time spent

accessing 10% of memory

• Exploit this rule:– Only keep “live”

parts of process in memory

Page 15: CMSC421: Principles of Operating Systems

Multi-Level Page Tables

• Use a multi-level page table

A A

A

Level 0 Table

Level 1 Table

Level 1 Table

Page 16: CMSC421: Principles of Operating Systems

Quick Activity

• How much mem does a page table need?– 4kB pages, 32 bit address space– Two level page table– 20bits = 10 bits each level– page table entry (PTE) uses 4 bytes– Only first page of program is valid

• 2^10*4+2^10*4=2^13 bytes=8kB

• Isn’t this slow?

Page 17: CMSC421: Principles of Operating Systems

17

Translation Lookaside Buffer (TLB)

• TLB: fast, fully associative memory– Caches page table entries– Stores page numbers (key) and frame (value) in

which they are stored• Assumption: locality of reference

– Locality in memory accesses =locality in address translation

• TLB sizes: 8 to 2048 entries– Powers of 2 simplifies translation

of virtual to physical addresses

Page 18: CMSC421: Principles of Operating Systems

Linear Address in Linux

Uses a three-level paging strategy that works well for 32-bit and 64-bit systems

Linear address broken into four parts:

Page 19: CMSC421: Principles of Operating Systems

Three-level Paging in Linux

Page 20: CMSC421: Principles of Operating Systems

20

Paging

Page 21: CMSC421: Principles of Operating Systems

21

Midterm review