virtual memory - cornell university...virtual memory c physical memory disk hidden from process 18...

20
Virtual Memory Hakim Weatherspoon CS 3410 Computer Science Cornell University [Weatherspoon, Bala, Bracy, McKee, and Sirer]

Upload: others

Post on 15-Oct-2020

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Virtual Memory - Cornell University...Virtual Memory C Physical Memory Disk Hidden from Process 18 Next Goal •How does Virtual Memory work? •i.e. How do we create the “map”

Virtual Memory

Hakim WeatherspoonCS 3410

Computer ScienceCornell University

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

Page 2: Virtual Memory - Cornell University...Virtual Memory C Physical Memory Disk Hidden from Process 18 Next Goal •How does Virtual Memory work? •i.e. How do we create the “map”

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?

Page 3: Virtual Memory - Cornell University...Virtual Memory C Physical Memory Disk Hidden from Process 18 Next Goal •How does Virtual Memory work? •i.e. How do we create the “map”

3

Big Picture: Multiple ProcessesHow 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)or many processors (multi-processor)

• Multiple programs run simultaneously

Page 4: Virtual Memory - Cornell University...Virtual Memory C Physical Memory Disk Hidden from Process 18 Next Goal •How does Virtual Memory work? •i.e. How do we create the “map”

4

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

Text

Data

Stack

Heap

Memory0x000…0

0x7ff…f

0xfff…f

$$

Page 5: Virtual Memory - Cornell University...Virtual Memory C Physical Memory Disk Hidden from Process 18 Next Goal •How does Virtual Memory work? •i.e. How do we create the “map”

5

Multiple Processes • Q: What happens when another program

is executed concurrently on anotherprocessor? CPU

Text

Data

Stack

Heap

Memory

CPU

Text

Data

Stack

Heap

0x000…0

0x7ff…f

0xfff…f

$$$$

Page 6: Virtual Memory - Cornell University...Virtual Memory C Physical Memory Disk Hidden from Process 18 Next Goal •How does Virtual Memory work? •i.e. How do we create the “map”

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?

Page 7: Virtual Memory - Cornell University...Virtual Memory C Physical Memory Disk Hidden from Process 18 Next Goal •How does Virtual Memory work? •i.e. How do we create the “map”

7

Big Picture: (Virtual) Memory

Process 1 ABCD

3210

Process 2 EFGH

3210

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

Page 8: Virtual Memory - Cornell University...Virtual Memory C Physical Memory Disk Hidden from Process 18 Next Goal •How does Virtual Memory work? •i.e. How do we create the “map”

8

But In Reality…

Process 1

Process 2

C

B

A

D

E

F

GH

Physical Memory

01

2

34

5678910

11

121314

Page 9: Virtual Memory - Cornell University...Virtual Memory C Physical Memory Disk Hidden from Process 18 Next Goal •How does Virtual Memory work? •i.e. How do we create the “map”

9

How do we create the illusion?

Process 1 ABCD

3210

Process 2 EFGH

3210

C

B

A

D

E

F

GH

Physical Memory

01

2

34

5678910

11

121314

Page 10: Virtual Memory - Cornell University...Virtual Memory C Physical Memory Disk Hidden from Process 18 Next Goal •How does Virtual Memory work? •i.e. How do we create the “map”

10

How do we create the illusion?

Process 1 ABCD

3210

Process 2 EFGH

3210

C

B

A

D

E

F

GH

Physical Memory

01

2

34

5678910

11

121314

All problems in computer science can be solved by another level of indirection.

– David Wheeler

Page 11: Virtual Memory - Cornell University...Virtual Memory C Physical Memory Disk Hidden from Process 18 Next Goal •How does Virtual Memory work? •i.e. How do we create the “map”

11

How do we create the illusion?

Process 1 ABCD

3210

Process 2 EFGH

3210

C

B

A

D

E

F

GH

Physical Memory

Virtual Memory(just a concept; does not exist physically)

Virtual addressMemory 

management unit (MMU) takes care of the mapping

Map virtual address to 

physical address

01

2

34

5678910

11

121314

Physical add

ress

Page 12: Virtual Memory - Cornell University...Virtual Memory C Physical Memory Disk Hidden from Process 18 Next Goal •How does Virtual Memory work? •i.e. How do we create the “map”

12

How do we create the illusion?

Process 1 ABCD

3210

Process 2 EFGH

3210

C

B

A

D

E

F

GH

Physical Memory

Virtual Memory(just a concept; does not exist physically)

Virtual address

Process 1 wants to Process 1 wants to access data C

01

2

34

5678910

11

121314

Physical add

ress

Process 1 thinks it is stored at addr 1So CPU generates 

addr 1This addr is 

intercepted by MMU

MMU knows this is a virtual addr

pp gMMU looks at the 

mapping

yVirtual addr 1 ‐> Physical addr 9Data at Physical addr 9 is sent to 

CPUAnd that data is indeed C!!!

Page 13: Virtual Memory - Cornell University...Virtual Memory C Physical Memory Disk Hidden from Process 18 Next Goal •How does Virtual Memory work? •i.e. How do we create the “map”

13

How do we create the illusion?

Process 1 ABCD

3210

Process 2 EFGH

3210

C

B

D

E

GH

Physical Memory

Virtual Memory

A FDisk

Memory management unit (MMU) takes care of the mapping

Map virtual address to 

physical address

01

2

34

5678910

11

121314

Page 14: Virtual Memory - Cornell University...Virtual Memory C Physical Memory Disk Hidden from Process 18 Next Goal •How does Virtual Memory work? •i.e. How do we create the “map”

14

Big Picture: (Virtual) Memory• From a process’s perspective –

Process only sees the virtual memoryContiguous memory

Process 1 ABCD

3210Virtual Memory

C

Physical MemoryHidd

en from

 Process

Page 15: Virtual Memory - Cornell University...Virtual Memory C Physical Memory Disk Hidden from Process 18 Next Goal •How does Virtual Memory work? •i.e. How do we create the “map”

15

Big Picture: (Virtual) Memory

Process 1 ABCD

3210Virtual Memory

C

Physical MemoryHidd

en from

 Process

• From a process’s perspective –

• Process only sees the virtual memoryContiguous memoryNo need to recompile - only mappings need to be

updated

Page 16: Virtual Memory - Cornell University...Virtual Memory C Physical Memory Disk Hidden from Process 18 Next Goal •How does Virtual Memory work? •i.e. How do we create the “map”

16

Big Picture: (Virtual) Memory• From a process’s perspective –

Process only sees the virtual memoryContiguous memoryNo need to recompile - only mappings need to be

updated

Process 1 ABCD

3210Virtual Memory

C

Physical MemoryHidd

en from

 Process

Page 17: Virtual Memory - Cornell University...Virtual Memory C Physical Memory Disk Hidden from Process 18 Next Goal •How does Virtual Memory work? •i.e. How do we create the “map”

17

Big Picture: (Virtual) Memory• From a process’s perspective –

Process only sees the virtual memoryContiguous memoryNo need to recompile - only mappings need to be

updatedWhen run out of memory, MMU maps data on disk

in a transparent manner

Process 1 ABCD

3210Virtual Memory

C

Physical Memory

Disk

Hidd

en from

 Process

Page 18: Virtual Memory - Cornell University...Virtual Memory C Physical Memory Disk Hidden from Process 18 Next Goal •How does Virtual Memory work? •i.e. How do we create the “map”

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?

Page 19: Virtual Memory - Cornell University...Virtual Memory C Physical Memory Disk Hidden from Process 18 Next Goal •How does Virtual Memory work? •i.e. How do we create the “map”

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?

Page 20: Virtual Memory - Cornell University...Virtual Memory C Physical Memory Disk Hidden from Process 18 Next Goal •How does Virtual Memory work? •i.e. How do we create the “map”

20

Virtual Memory AgendaWhat is Virtual Memory?How does Virtual memory Work?• Address Translation• Overhead• Paging• Performance