cmsc421: principles of operating systems
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 PresentationTRANSCRIPT
![Page 1: CMSC421: Principles of Operating Systems](https://reader034.vdocument.in/reader034/viewer/2022051401/56814a96550346895db7a395/html5/thumbnails/1.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051401/56814a96550346895db7a395/html5/thumbnails/2.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051401/56814a96550346895db7a395/html5/thumbnails/3.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051401/56814a96550346895db7a395/html5/thumbnails/4.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051401/56814a96550346895db7a395/html5/thumbnails/5.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051401/56814a96550346895db7a395/html5/thumbnails/6.jpg)
Mapping Virtual to Physical
![Page 7: CMSC421: Principles of Operating Systems](https://reader034.vdocument.in/reader034/viewer/2022051401/56814a96550346895db7a395/html5/thumbnails/7.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051401/56814a96550346895db7a395/html5/thumbnails/8.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051401/56814a96550346895db7a395/html5/thumbnails/9.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051401/56814a96550346895db7a395/html5/thumbnails/10.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051401/56814a96550346895db7a395/html5/thumbnails/11.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051401/56814a96550346895db7a395/html5/thumbnails/12.jpg)
12
Paging Hardware
![Page 13: CMSC421: Principles of Operating Systems](https://reader034.vdocument.in/reader034/viewer/2022051401/56814a96550346895db7a395/html5/thumbnails/13.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051401/56814a96550346895db7a395/html5/thumbnails/14.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051401/56814a96550346895db7a395/html5/thumbnails/15.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051401/56814a96550346895db7a395/html5/thumbnails/16.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051401/56814a96550346895db7a395/html5/thumbnails/17.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051401/56814a96550346895db7a395/html5/thumbnails/18.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051401/56814a96550346895db7a395/html5/thumbnails/19.jpg)
Three-level Paging in Linux
![Page 20: CMSC421: Principles of Operating Systems](https://reader034.vdocument.in/reader034/viewer/2022051401/56814a96550346895db7a395/html5/thumbnails/20.jpg)
20
Paging
![Page 21: CMSC421: Principles of Operating Systems](https://reader034.vdocument.in/reader034/viewer/2022051401/56814a96550346895db7a395/html5/thumbnails/21.jpg)
21
Midterm review