Virtual Memory Hakim Weatherspoon CS 3410 Computer Science - - PowerPoint PPT Presentation

virtual memory
SMART_READER_LITE
LIVE PREVIEW

Virtual Memory Hakim Weatherspoon CS 3410 Computer Science - - PowerPoint PPT Presentation

Virtual Memory Hakim Weatherspoon CS 3410 Computer Science Cornell University [Weatherspoon, Bala, Bracy, McKee, and Sirer] Where are we now and where are we going? How many programs do you run at once? a) 1 b) 2 c) 3-5


slide-1
SLIDE 1

Virtual Memory

Hakim Weatherspoon CS 3410 Computer Science Cornell University

[Weatherspoon, Bala, Bracy, McKee, and Sirer]

slide-2
SLIDE 2

2

  • How many programs do you run at once?
  • a) 1
  • b) 2
  • c) 3-5
  • d) 6-10
  • e) 11+

Where are we now and where are we going?

slide-3
SLIDE 3

3

Big Picture: Multiple Processes

How to run multiple processes?

  • Time-multiplex a single CPU core (multi-

tasking)

  • Web browser, skype, office, … all must co-exist
  • Many cores per processor (multi-core)
  • r many processors (multi-processor)
  • Multiple programs run simultaneously
slide-4
SLIDE 4

4

Processor & Memory

  • CPU address/data bus...
  • … routed through caches
  • … to main memory
  • Simple, fast, but…

CPU

Text Data Stack Heap

Memory

0x000…0 0x7ff…f 0xfff…f

$$

slide-5
SLIDE 5

5

Multiple Processes

  • Q: What happens when another program

is executed concurrently on another processor?

CPU

Text Data Stack Heap

Memory CPU

Text Data Stack Heap

0x000…0 0x7ff…f 0xfff…f

$$ $$

slide-6
SLIDE 6

6

Multiple Processes

CPU

Text Data Stack Heap

Memory CPU

Text Data Stack Heap

0x000…0 0x7ff…f 0xfff…f

$$ $$

  • Q: Can we relocate second program?
slide-7
SLIDE 7

7

Big Picture: (Virtual) Memory

Process 1

A B C D

3 2 1

Process 2

E F G H

3 2 1

Give each process an illusion that it has exclusive access to entire main memory

slide-8
SLIDE 8

8

But In Reality…

Process 1 Process 2

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

slide-9
SLIDE 9

9

How do we create the illusion?

Process 1

A B C D

3 2 1

Process 2

E F G H

3 2 1

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

slide-10
SLIDE 10

10

How do we create the illusion?

Process 1

A B C D

3 2 1

Process 2

E F G H

3 2 1

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

slide-11
SLIDE 11

11

How do we create the illusion?

Process 1

A B C D

3 2 1

Process 2

E F G H

3 2 1

C B A D E F G H Physical Memory Virtual Memory (just a concept; does not exist physically) Virtual address Memory management unit (MMU) takes care

  • f the mapping

Map virtual address to physical address 1 2 3 4 5 6 7 8 9 10 11 12 13 14 Physical address

slide-12
SLIDE 12

12

How do we create the illusion?

Process 1

A B C D

3 2 1

Process 2

E F G H

3 2 1

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

slide-13
SLIDE 13

13

How do we create the illusion?

Process 1

A B C D

3 2 1

Process 2

E F G H

3 2 1

C B D E G H Physical Memory Virtual Memory A F Disk Memory management unit (MMU) takes care

  • f the mapping

Map virtual address to physical address 1 2 3 4 5 6 7 8 9 10 11 12 13 14

slide-14
SLIDE 14

14

Big Picture: (Virtual) Memory

  • From a process’s perspective –
  • Process only sees the virtual memory

Contiguous memory

Process 1

A B C D

3 2 1

Virtual Memory C Physical Memory Hidden from Process

slide-15
SLIDE 15

15

Big Picture: (Virtual) Memory

Process 1

A B C D

3 2 1

Virtual Memory C Physical Memory Hidden from Process

  • From a process’s perspective –
  • Process only sees the virtual memory

 Contiguous memory  No need to recompile - only mappings need to be updated

slide-16
SLIDE 16

16

Big Picture: (Virtual) Memory

  • From a process’s perspective –
  • Process only sees the virtual memory

Contiguous memory No need to recompile - only mappings need to be updated

Process 1

A B C D

3 2 1

Virtual Memory C Physical Memory Hidden from Process

slide-17
SLIDE 17

17

Big Picture: (Virtual) Memory

  • From a process’s perspective –
  • Process only sees the virtual memory

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

Process 1

A B C D

3 2 1

Virtual Memory C Physical Memory Disk Hidden from Process

slide-18
SLIDE 18

18

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?

slide-19
SLIDE 19

19

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?

slide-20
SLIDE 20

20

Virtual Memory Agenda

What is Virtual Memory? How does Virtual memory Work?

  • Address Translation
  • Overhead
  • Paging
  • Performance