Virtual Memory Hakim Weatherspoon CS 3410 Computer Science

  • Slides: 20
Download presentation
Virtual Memory Hakim Weatherspoon CS 3410 Computer Science Cornell University [Weatherspoon, Bala, Bracy, Mc.

Virtual Memory Hakim Weatherspoon CS 3410 Computer Science Cornell University [Weatherspoon, Bala, Bracy, Mc. Kee, and Sirer]

Where are we now and where are we going? • How many programs do

Where are we now and where are we going? • How many programs do you run at once? • • • a) 1 b) 2 c) 3 -5 d) 6 -10 e) 11+ 2

Big Picture: Multiple Processes How to run multiple processes? • Time-multiplex a single CPU

Big Picture: Multiple Processes How to run multiple processes? • Time-multiplex a single CPU core (multitasking) • Web browser, skype, office, … all must co-exist • Many cores per processor (multi-core) or many processors (multi-processor) • Multiple programs run simultaneously 3

Processor & Memory • CPU address/data bus. . . • … routed through caches

Processor & Memory • CPU address/data bus. . . • … routed through caches • … to main memory § Simple, fast, but… CPU 0 xfff…f 0 x 7 ff…f $$ Stack Heap Data Text 0 x 000… 0 Memory 4

Multiple Processes • Q: What happens when another program is executed concurrently on another

Multiple Processes • Q: What happens when another program is executed concurrently on another 0 xfff…f processor? CPU 0 x 7 ff…f $$ $$ Stack Heap CPU Data Text 0 x 000… 0 Memory 5

Multiple Processes • Q: Can we relocate second program? CPU 0 xfff…f 0 x

Multiple Processes • Q: Can we relocate second program? CPU 0 xfff…f 0 x 7 ff…f $$ $$ Stack Heap CPU Data Text 0 x 000… 0 Memory 6

Big Picture: (Virtual) Memory Process 1 Process 2 3 2 1 0 A B

Big Picture: (Virtual) Memory Process 1 Process 2 3 2 1 0 A B C D 3 2 1 0 E F G H Give each process an illusion that it has exclusive access to entire main memory 7

But In Reality… Process 1 D 14 13 12 E 11 C B G

But In Reality… Process 1 D 14 13 12 E 11 C B G H Process 2 10 9 8 7 6 5 4 A 3 2 F 1 0 Physical Memory 8

How do we create the illusion? Process 1 3 2 1 0 A B

How do we create the illusion? Process 1 3 2 1 0 A B C D D 14 13 12 E 11 C B G H Process 2 3 2 1 0 E F G H 10 9 8 7 6 5 4 A 3 2 F 1 0 Physical Memory 9

How do we create the illusion? D 14 13 12 3 2 1 0

How do we create the illusion? D 14 13 12 3 2 1 0 A E 11 B 10 C 9 C D 8 All problems in computer science can be solved by another level of indirection. 7 B Wheeler – David 6 G H 5 E 3 4 Process 2 F 2 3 A G 1 2 H 0 F 1 0 Process 1 Physical Memory 10

Process 1 3 2 1 0 A B C D Virtual address Process 2

Process 1 3 2 1 0 A B C D Virtual address Process 2 3 2 1 0 E F G H Map virtual address to physical address Memory management unit (MMU) takes care of the mapping Virtual Memory (just a concept; does not exist physically) D 14 13 12 E 11 C B G H 10 9 8 7 6 5 Physical address How do we create the illusion? 4 A 3 2 F 1 0 Physical Memory 11

Process 1 Virtual address Process 2 Process 1 wants to access data C Process

Process 1 Virtual address Process 2 Process 1 wants to access data C Process 1 thinks it A 3 is stored at addr 1 B 2 So CPU generates C 1 addr 1 D 0 This addr is intercepted by MMU knows this is a virtual addr E 3 MMU looks at the F mapping 2 Virtual addr 1 -> G 1 Physical addr 9 H 0 Data at Physical addr 9 is sent to Virtual Memory CPUphysically) (just a concept; does not exist And that data is indeed C!!! D 14 13 12 E 11 C B G H 10 9 8 7 6 5 Physical address How do we create the illusion? 4 A 3 2 F 1 0 Physical Memory 12

How do we create the illusion? Process 1 Process 2 3 2 1 0

How do we create the illusion? Process 1 Process 2 3 2 1 0 A B C D Map virtual address to physical address Memory management unit (MMU) takes care of the mapping E F G H D 14 13 12 E 11 C B G H 10 9 8 7 6 5 4 3 2 1 0 Virtual Memory A Disk F Physical Memory 13

Big Picture: (Virtual) Memory Process 1 3 2 1 0 A B C D

Big Picture: (Virtual) Memory Process 1 3 2 1 0 A B C D Virtual Memory § Hidden from Process • From a process’s perspective – C Physical Memory Process only sees the virtual memory üContiguous memory 14

Big Picture: (Virtual) Memory Process 1 3 2 1 0 A B C D

Big Picture: (Virtual) Memory Process 1 3 2 1 0 A B C D Virtual Memory Hidden from Process • From a process’s perspective – C Physical Memory • Process only sees the virtual memory ü Contiguous memory ü No need to recompile - only mappings need to be updated 15

Big Picture: (Virtual) Memory Process 1 3 2 1 0 A B C D

Big Picture: (Virtual) Memory Process 1 3 2 1 0 A B C D Virtual Memory § Hidden from Process • From a process’s perspective – C Physical Memory Process only sees the virtual memory üContiguous memory üNo need to recompile - only mappings need to be updated 16

Big Picture: (Virtual) Memory Process 1 3 2 1 0 A B C D

Big Picture: (Virtual) Memory Process 1 3 2 1 0 A B C D Virtual Memory § Hidden from Process • From a process’s perspective – Physical Memory Process only sees the virtual memory C Disk üContiguous memory üNo need to recompile - only mappings need to be updated üWhen run out of memory, MMU maps data on disk in a transparent manner 17

Next Goal • How does Virtual Memory work? • i. e. How do we

Next Goal • How does Virtual Memory work? • i. e. How do we create the “map” that maps a virtual address generated by the CPU to a physical address used by main memory? 18

Next Goal (after spring break!) • How does Virtual Memory work? • i. e.

Next Goal (after spring break!) • How does Virtual Memory work? • i. e. How do we create the “map” that maps a virtual address generated by the CPU to a physical address used by main memory? 19

Virtual Memory Agenda What is Virtual Memory? How does Virtual memory Work? • •

Virtual Memory Agenda What is Virtual Memory? How does Virtual memory Work? • • Address Translation Overhead Paging Performance 20