x (Actually, its smaller than that heap Process 3 What - - PowerPoint PPT Presentation

x
SMART_READER_LITE
LIVE PREVIEW

x (Actually, its smaller than that heap Process 3 What - - PowerPoint PPT Presentation

11/20/15 Virtual Memory Physical Addressing Motivation: why not direct physical memory access? Main memory Address translation with pages 0: 1: Optimizing translation: translation


slide-1
SLIDE 1

11/20/15 1

Virtual ¡Memory

Motivation: ¡ why ¡not ¡direct ¡physical ¡memory ¡ access? Address ¡translation with ¡pages Optimizing ¡ translation: ¡ translation ¡lookaside buffer Extra ¡ benefits: ¡sharing ¡and ¡protection Memory ¡as ¡a ¡contiguous ¡array ¡ of ¡bytes ¡is ¡a ¡lie! ¡ ¡Why?

1

Physical ¡Addressing

2

Small ¡ embedded ¡systems ¡without ¡processes

Elevators, ¡microwaves, ¡radio-­‑powered ¡devices, ¡…

0: 1: M-­‑1:

Main ¡memory

CPU

2: 3: 4: 5: 6: 7:

Physical ¡address (PA)

Data

8:

...

4

Problem ¡1: ¡Memory ¡Management

3

Main ¡memory

What ¡goes ¡ where?

stack heap

.text .data

… Process ¡1 Process ¡2 Process ¡3 … Process ¡n

x

Also: Context ¡switches must ¡swap ¡out ¡entire ¡memory ¡contents. Isn't ¡that ¡expensive?

Problem ¡2: ¡Capacity

4

64-­‑bit ¡addresses ¡can ¡address several ¡ exabytes (18,446,744,073,709,551,616 ¡bytes) Physical ¡main ¡memory ¡offers a ¡few ¡gigabytes (e.g. ¡8,589,934,592 ¡bytes)

?

1 ¡virtual ¡address ¡space ¡per ¡process, ¡ with ¡many ¡processes…

(Actually, ¡ it’s ¡smaller ¡ than ¡that dot ¡compared ¡ to ¡virtual ¡ memory.)

slide-2
SLIDE 2

11/20/15 2

Problem ¡3: ¡Protection

5

Physical ¡main ¡memory Process ¡i Process ¡j

Problem ¡4: ¡Sharing

Physical ¡main ¡memory Process ¡i Process ¡j

Solution: ¡Virtual ¡Memory ¡(address ¡indirection)

6

Private ¡ virtual ¡ address ¡space ¡ per ¡process.

Physical ¡memory Virtual ¡memory Virtual ¡memory Process ¡1 Process ¡n

virtual-­‑to-­‑physical

mapping

virtual ¡ addresses physical ¡ addresses virtual ¡ addresses

Single ¡physical ¡ address ¡space ¡ managed ¡ by ¡OS/hardware.

Indirection

Direct ¡naming Indirect ¡ naming

7

"2" "x"

2

What ¡if ¡we ¡move ¡Thing?

Thing 7 1 2 3 6 5 4 What ¡X ¡ currently ¡ maps ¡to

Tangent: Indirection ¡everywhere

  • Pointers
  • Constants
  • Procedural ¡abstraction
  • Domain ¡Name ¡Service ¡ (DNS)
  • Dynamic ¡Host ¡Configuration ¡Protocol ¡(DHCP)
  • Phone ¡numbers
  • 911
  • Call ¡centers
  • Snail ¡mail ¡forwarding

“Any ¡problem ¡in ¡computer ¡science ¡can ¡be ¡solved ¡by ¡adding ¡another ¡level ¡of ¡indirection.”

–David ¡ Wheeler, ¡ inventor ¡ of ¡the ¡subroutine ¡(a.k.a. ¡ procedure), ¡or ¡Butler ¡ Lampson

Another ¡Wheeler ¡ quote? ¡"Compatibility ¡means ¡deliberately ¡repeating ¡other ¡people's ¡mistakes."

slide-3
SLIDE 3

11/20/15 3

Virtual ¡Addressing

9

Physical ¡addresses ¡are invisible to ¡programs.

0: 1: M-­‑1:

Main ¡memory MMU

2: 3: 4: 5: 6: 7:

Physical ¡address (PA)

Data

8:

...

CPU

Virtual ¡address (VA) CPU ¡Chip

4 4100

Memory ¡Management ¡ Unit

translates ¡virtual ¡address ¡to ¡physical ¡address

Page-­‑based ¡Mapping

Physical Address ¡Space

Physical ¡

Page

Physical ¡

Page 1

Physical ¡

Page 2p -­‑ 1

2m -­‑ 1 Virtual Address ¡Space

Virtual Page Virtual Page 1

Virtual Page 2v -­‑ 1

2n -­‑ 1

Virtual Page 2 Virtual Page 3

both ¡address ¡spaces divided ¡into ¡fixed-­‑size, ¡aligned ¡pages

page ¡size ¡= ¡power ¡of ¡two

Map ¡virtual ¡ pages ¡

  • nto ¡physical ¡pages.

Some ¡virtual ¡pages ¡do ¡not ¡fit! ¡ ¡Where ¡are ¡they ¡stored?

Physical ¡Memory Address ¡Space

Physical ¡

Page

Physical ¡

Page 1

Physical ¡

Page 2p -­‑ 1

2m -­‑ 1 Virtual ¡Memory Address ¡Space

Virtual Page Virtual Page 1

Virtual Page 2v -­‑ 1

2n -­‑ 1

Virtual Page 2 Virtual Page 3

  • 1. ¡On ¡disk (if ¡used)
  • 2. ¡Nowhere! (if ¡not ¡yet ¡used)

virtual ¡address ¡space usually ¡much ¡larger ¡than physical ¡address ¡space

Virtual ¡Memory: ¡cache ¡for ¡disk?

12

Disk

Main ¡ Memory

L2 ¡ unified ¡ cache L1 ¡ I-­‑cache L1 ¡ D-­‑cache

CPU Reg

2 ¡B/cycle 8 ¡B/cycle 16 ¡B/cycle 1 ¡B/30 ¡cycles Throughput: Latency: 100 ¡cycles 14 ¡cycles 3 ¡cycles millions ~4 ¡MB 32 ¡KB ~8 ¡GB ~500 ¡GB

Intel ¡Core ¡2 ¡Duo

c.a. ¡2006-­‑2011

Cache ¡miss ¡penalty (latency): ¡33x

Memory ¡ miss ¡penalty (latency): ¡ 10,000x

SRAM DRAM

solid-­‑state "flash" ¡ memory

  • r

spinning magnetic ¡platter .

Not ¡drawn ¡to ¡scale ¡

slide-4
SLIDE 4

11/20/15 4

Design ¡for ¡a ¡Slow ¡Disk: ¡Exploit ¡Locality

Physical ¡Memory Address ¡Space

Physical ¡

Page

Physical ¡

Page 1

Physical ¡

Page 2p -­‑ 1

2m -­‑ 1 Virtual ¡Memory Address ¡Space

Virtual Page Virtual Page 1

Virtual Page 2v -­‑ 1

2n -­‑ 1

Virtual Page 2 Virtual Page 3

  • n ¡disk

Fully ¡associative

  • Store ¡any ¡virtual ¡page ¡in ¡any ¡physical ¡pag

e

  • Large ¡mapping ¡function

Large ¡page ¡size

usually ¡4KB, ¡up ¡to ¡2-­‑4MB

Sophisticated replacement ¡policy

  • Not ¡just ¡hardware

Write-­‑back

Address ¡Translation

14

What ¡happens ¡in ¡here?

0: 1: M-­‑1:

Main ¡memory

MMU

2: 3: 4: 5: 6: 7:

Physical ¡address (PA)

Data

8:

...

CPU

Virtual ¡address (VA) CPU ¡Chip

4 4100

Page ¡Table

array ¡of ¡page ¡table ¡entries(PTEs) mapping ¡virtual ¡page ¡to ¡where ¡it ¡is ¡stored

15

Physical ¡pages (Physical ¡memory) Swap ¡space (Disk) VP ¡7 VP ¡4 PP ¡0 VP ¡2 VP ¡1 PP ¡3

How ¡many ¡page ¡tables ¡ are ¡in ¡the ¡system?

null null

page ¡table

1 1 1 1

Valid

Physical ¡Page ¡Number

  • r ¡disk ¡address

PTE ¡0 PTE ¡7

Memory ¡resident, managed ¡by ¡HW ¡(MMU), ¡OS

VP ¡3 VP ¡6

Address ¡Translation ¡with ¡a Page ¡Table

16 Virtual ¡ page ¡number (VPN) Virtual ¡ page ¡offset (VPO) Physical ¡ page ¡number (PPN) Physical ¡ page ¡offset (PPO)

Virtual ¡address (VA) Physical ¡address ¡(PA)

Valid Physical ¡page ¡number ¡(PPN)

Page ¡ table ¡ base ¡ register (PTBR)

Page ¡table ¡

Base ¡address

  • f ¡current ¡process's

page ¡table

Virtual ¡page ¡mapped to ¡physical ¡page?

slide-5
SLIDE 5

11/20/15 5

Page ¡Hit: virtual ¡page ¡in ¡memory

17

Physical ¡pages (Physical ¡memory) Swap ¡space (Disk) VP ¡7 VP ¡4 PP ¡0 VP ¡1 PP ¡3

null null

page ¡table

1 1 1 1

Valid

Physical ¡Page ¡Number

  • r ¡disk ¡address

PTE ¡0 PTE ¡7

Virtual ¡Page ¡Numb er VP ¡2 VP ¡3 VP ¡6

Process

Page ¡Fault: ¡ exceptional ¡control ¡flow

Process ¡accessed ¡virtual ¡address ¡in ¡a ¡page ¡that ¡is ¡not ¡in ¡physical ¡memory.

18

User ¡Code OS ¡exception ¡handler exception: ¡page ¡ fault Create ¡page ¡and ¡ load ¡into ¡memory return movl Returns ¡to ¡faulting ¡instruction: movl is ¡executed ¡again!

Page ¡Fault: ¡1. page ¡not ¡in ¡memory

19

Physical ¡pages (Physical ¡memory) Swap ¡space (Disk) VP ¡7 VP ¡4 PP ¡0 VP ¡1 PP ¡3

null null

page ¡table

1 1 1 1

Valid

Physical ¡Page ¡Number

  • r ¡disk ¡address

PTE ¡0 PTE ¡7

Virtual ¡Page ¡Numb er VP ¡2

What ¡now? OS ¡handles ¡ fault

VP ¡3 VP ¡6

null

Page ¡Fault: ¡2. OS ¡evicts ¡another ¡page.

20

Physical ¡pages (Physical ¡memory) Swap ¡space (Disk) VP ¡7 VP ¡4 PP ¡0 VP ¡1 PP ¡3 VP ¡3

null

page ¡table

1 1 1

Valid

Physical ¡Page ¡Number

  • r ¡disk ¡address

PTE ¡0 PTE ¡7

VP ¡6 Virtual ¡Page ¡Numb er VP ¡2

"Page ¡out"

VP ¡1

slide-6
SLIDE 6

11/20/15 6

1

Page ¡Fault: ¡2. OS ¡loads ¡needed ¡page.

21

Physical ¡pages (Physical ¡memory) Swap ¡space (Disk) VP ¡7 VP ¡4 PP ¡0 VP ¡2 PP ¡3

null null

page ¡table

1 1 1 1

Valid

Physical ¡Page ¡Number

  • r ¡disk ¡address

PTE ¡0 PTE ¡7

Virtual ¡Page ¡Numb er VP ¡3 VP ¡6 VP ¡1 VP ¡3

Finally: Reexecute faulting ¡instruction. Page ¡hit! "Page ¡in"

Terminology

context ¡switch

Switch ¡control ¡between ¡processes ¡on ¡the ¡same ¡CPU.

page ¡in

Move ¡pages ¡of ¡virtual ¡memory ¡from ¡disk ¡to ¡physical ¡memory.

page ¡out

Move ¡pages ¡of ¡virtual ¡memory ¡from ¡physical ¡memory ¡to ¡disk.

thrash

Total ¡working ¡set ¡size ¡of ¡processes ¡is ¡larger ¡than ¡physical ¡memory. Most ¡time ¡is ¡spent ¡paging ¡in ¡and ¡out ¡instead ¡of ¡doing ¡useful ¡computation.

(I ¡find ¡all ¡these ¡ terms ¡useful ¡ when ¡talking ¡to ¡other ¡ computer ¡scientists ¡ about ¡my ¡brain…) 22

swap

Address ¡Translation: ¡Page ¡Hit

23

1) ¡Processor ¡sends ¡virtual ¡address ¡to ¡MMU ¡(memory ¡management ¡unit) 2-­‑3) ¡MMU ¡fetches ¡PTE ¡from ¡page ¡table ¡in ¡cache/memory 4) ¡MMU ¡sends ¡physical ¡address ¡to ¡cache/memory 5) ¡Cache/memory ¡sends ¡data ¡word ¡to ¡processor MMU

Cache/ Memory

PA Data

CPU

VA

CPU ¡Chip

PTEA PTE 1 2 3 4 5

Address ¡Translation: ¡Page ¡Fault

24

1) ¡Processor ¡sends ¡virtual ¡address ¡to ¡MMU ¡ 2-­‑3) ¡MMU ¡fetches ¡PTE ¡from ¡page ¡table ¡in ¡cache/memory 4) ¡Valid ¡bit ¡is ¡zero, ¡so ¡MMU ¡triggers ¡page ¡fault ¡exception 5) ¡Handler ¡identifies ¡victim ¡(and, ¡if ¡dirty, ¡pages ¡it ¡out ¡to ¡disk) 6) ¡Handler ¡pages ¡in ¡new ¡page ¡and ¡updates ¡PTE ¡in ¡memory 7) ¡Handler ¡returns ¡to ¡original ¡process, ¡restarting ¡faulting ¡instruction MMU

Cache/ Memory

CPU

VA

CPU ¡Chip

PTEA PTE 1 2 3 4 5

Disk

Page ¡fault ¡handler

Victim ¡ page New ¡ page

Exception

6 7

slide-7
SLIDE 7

11/20/15 7

Translation ¡sounds ¡slow!

Each ¡access ¡= ¡2 ¡accesses: ¡load ¡PTE, ¡access ¡requested ¡ address

PTEs ¡may be ¡cached, ¡but ¡may ¡be ¡evicted. L1 ¡cache ¡hit ¡still ¡requires ¡1-­‑3 ¡cycles

What ¡can ¡we ¡do ¡to ¡make ¡this ¡faster?

25

Translation ¡LookasideBuffer ¡(TLB)

Small ¡ hardware ¡ cache ¡in ¡MMU ¡just ¡for ¡page ¡table ¡entries

Modern ¡Intel ¡processors: ¡128 ¡or ¡256 ¡entries ¡in ¡TLB

Much ¡faster ¡than ¡a ¡page ¡table ¡lookup ¡in ¡cache/memory In ¡the ¡running ¡for ¡"classiest ¡name ¡of ¡a ¡thing ¡in ¡CS"

26

TLB ¡Hit

27

MMU

Cache/ Memory

PA Data

CPU

VA

CPU ¡Chip

PTE 1 2 4 5

A ¡TLB ¡hit ¡eliminates ¡ a ¡memory ¡access

TLB

VPN 3

TLB ¡Miss

28

MMU

Cache/ Memory

PA Data

CPU

VA

CPU ¡Chip

PTE 1 2 5 6

TLB

VPN 4 PTEA 3

A ¡TLB ¡miss ¡incurs ¡an ¡additional ¡ memory ¡access ¡(the ¡PTE)

Fortunately, ¡TLB ¡misses ¡are ¡rare. ¡ ¡Does ¡a ¡TLB ¡miss ¡require ¡disk ¡access?

slide-8
SLIDE 8

11/20/15 8

Simple ¡Memory ¡System ¡Example ¡(small)

Addressing

14-­‑bit ¡virtual ¡addresses 12-­‑bit ¡physical ¡address Page ¡size ¡= ¡64 ¡bytes

29

13 12 11 10 9 8 7 6 5 4 3 2 1 11 10 9 8 7 6 5 4 3 2 1

VPO PPO PPN VPN Virtual ¡Page ¡Number Virtual ¡Page ¡Offset Physical ¡Page ¡Number Physical ¡Page ¡Offset

Simple ¡Memory ¡System ¡Page ¡Table

Only ¡showing ¡first ¡16 ¡entries ¡(out ¡of ¡256 ¡= ¡28) What ¡about ¡a ¡real ¡address ¡space? ¡ ¡Read ¡more ¡in ¡the ¡book…

30 1 0D 0F 1 11 0E 1 2D 0D – 0C – 0B 1 09 0A 1 17 09 1 13 08 Valid PPN VPN – 07 – 06 1 16 05 – 04 1 02 03 1 33 02 – 01 1 28 00 Valid PPN VPN

Simple ¡Memory ¡System ¡TLB

16 ¡entries 4-­‑way ¡associative

31

13 12 11 10 9 8 7 6 5 4 3 2 1

virtual ¡page ¡offset virtual ¡page ¡number

TLB ¡index TLB ¡tag

– 02 1 34 0A 1 0D 03 – 07 3 – 03 – 06 – 08 – 02 2 – 0A – 04 – 02 1 2D 03 1 1 02 07 – 00 1 0D 09 – 03 Valid PPN Tag Valid PPN Tag Valid PPN Tag Valid PPN Tag Set

TLB ¡ignores ¡ page ¡offset. Why?

Simple ¡Memory ¡System ¡Cache

16 ¡lines, ¡4-­‑byte ¡block ¡size Physically ¡ addressed Direct ¡mapped

32

11 10 9 8 7 6 5 4 3 2 1

physical ¡page ¡offset physical ¡page ¡number

cache ¡offset cache ¡index cache ¡tag

03 DF C2 11 1 16 7 – – – – 31 6 1D F0 72 36 1 0D 5 09 8F 6D 43 1 32 4 – – – – 36 3 08 04 02 00 1 1B 2 – – – – 15 1 11 23 11 99 1 19 B3 B2 B1 B0 Valid Tag Idx – – – – 14 F D3 1B 77 83 1 13 E 15 34 96 04 1 16 D – – – – 12 C – – – – 0B B 3B DA 15 93 1 2D A – – – – 2D 9 89 51 00 3A 1 24 8 B3 B2 B1 B0 Valid Tag Idx

slide-9
SLIDE 9

11/20/15 9

Address ¡Translation ¡Example ¡#1

Virtual ¡ Address: ¡0x03D4

virtual ¡ page ¡#___ ¡ ¡ ¡ ¡TLB ¡index___ ¡ ¡ ¡ ¡TLB ¡tag ¡____ ¡ ¡ ¡ ¡TLB ¡Hit? ¡__ ¡ ¡Page ¡Fault? ¡__ ¡physical ¡page ¡#: ¡____

13 12 11 10 9 8 7 6 5 4 3 2 1

page ¡offset virtual ¡page ¡number

TLB ¡index TLB ¡tag – 02 1 34 0A 1 0D 03 – 07 3 – 03 – 06 – 08 – 02 2 – 0A – 04 – 02 1 2D 03 1 1 02 07 – 00 1 0D 09 – 03 Valid PPN T ag Valid PPN T ag Valid PPN T ag Valid PPN T ag Set

TLB

Address ¡Translation ¡Example ¡#1

Physical ¡Address: ¡0x354

cache ¡offset___ cache ¡index___ cache ¡tag____ Hit? ¡__ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡Byte: ¡____ 34

11 10 9 8 7 6 5 4 3 2 1

physical ¡page ¡offset physical ¡page ¡number

cache ¡offset

cache ¡index cache ¡tag

03 DF C2 11 1 16 7 – – – – 31 6 1D F0 72 36 1 0D 5 09 8F 6D 43 1 32 4 – – – – 36 3 08 04 02 00 1 1B 2 – – – – 15 1 11 23 11 99 1 19 B3 B2 B1 B0 Valid Tag Idx – – – – 14 F D3 1B 77 83 1 13 E 15 34 96 04 1 16 D – – – – 12 C – – – – 0B B 3B DA 15 93 1 2D A – – – – 2D 9 89 51 00 3A 1 24 8 B3 B2 B1 B0 Valid Tag Idx

Cache

virtual ¡ page ¡#___ ¡ ¡ ¡ ¡TLB ¡index___ ¡ ¡ ¡ ¡TLB ¡tag ¡____ ¡ ¡ ¡ ¡TLB ¡Hit? ¡__ ¡ ¡Page ¡Fault? ¡__ ¡physical ¡page ¡#: ¡____

Address ¡Translation ¡Example ¡#2

Virtual ¡ Address: ¡0x0B8F

35

13 12 11 10 9 8 7 6 5 4 3 2 1

page ¡offset virtual ¡page ¡number

TLB ¡index TLB ¡tag – 02 1 34 0A 1 0D 03 – 07 3 – 03 – 06 – 08 – 02 2 – 0A – 04 – 02 1 2D 03 1 1 02 07 – 00 1 0D 09 – 03 Valid PPN T ag Valid PPN T ag Valid PPN T ag Valid PPN T ag Set

TLB

virtual ¡ page ¡#___ ¡ ¡ ¡ ¡TLB ¡index___ ¡ ¡ ¡ ¡TLB ¡tag ¡____ ¡ ¡ ¡ ¡TLB ¡Hit? ¡__ ¡ ¡Page ¡Fault? ¡__ ¡physical ¡page ¡#: ¡____

Address ¡Translation ¡Example ¡#3

Virtual ¡ Address: ¡0x0020

36

13 12 11 10 9 8 7 6 5 4 3 2 1

page ¡offset virtual ¡page ¡number

TLB ¡index TLB ¡tag – 02 1 34 0A 1 0D 03 – 07 3 – 03 – 06 – 08 – 02 2 – 0A – 04 – 02 1 2D 03 1 1 02 07 – 00 1 0D 09 – 03 Valid PPN T ag Valid PPN T ag Valid PPN T ag Valid PPN T ag Set

TLB

slide-10
SLIDE 10

11/20/15 10

virtual ¡ page ¡#___ ¡ ¡ ¡ ¡TLB ¡index___ ¡ ¡ ¡ ¡TLB ¡tag ¡____ ¡ ¡ ¡ ¡TLB ¡Hit? ¡__ ¡ ¡Page ¡Fault? ¡__ ¡physical ¡page ¡#: ¡____

Address ¡Translation ¡Example ¡#3

Virtual ¡ Address: ¡0x0020

37

13 12 11 10 9 8 7 6 5 4 3 2 1

page ¡offset virtual ¡page ¡number

TLB ¡index TLB ¡tag 1 0D 0F 1 11 0E 1 2D 0D – 0C – 0B 1 09 0A 1 17 09 1 13 08 Valid PPN VPN – 07 – 06 1 16 05 – 04 1 02 03 1 33 02 – 01 1 28 00 Valid PPN VPN

Page ¡table

Address ¡Translation ¡Example ¡#3

Physical ¡Address: ¡0xA20

cache ¡offset___ cache ¡index___ cache ¡tag____ Hit? ¡__ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡Byte: ¡____ 38

11 10 9 8 7 6 5 4 3 2 1

physical ¡page ¡offset physical ¡page ¡number

cache ¡offset

cache ¡index cache ¡tag

03 DF C2 11 1 16 7 – – – – 31 6 1D F0 72 36 1 0D 5 09 8F 6D 43 1 32 4 – – – – 36 3 08 04 02 00 1 1B 2 – – – – 15 1 11 23 11 99 1 19 B3 B2 B1 B0 Valid Tag Idx – – – – 14 F D3 1B 77 83 1 13 E 15 34 96 04 1 16 D – – – – 12 C – – – – 0B B 3B DA 15 93 1 2D A – – – – 2D 9 89 51 00 3A 1 24 8 B3 B2 B1 B0 Valid Tag Idx

Cache

Easy ¡address ¡space ¡allocation

Process ¡needs ¡private ¡ contiguous address ¡space.

Fully ¡associative: ¡Virtual ¡pages ¡can ¡live ¡anywhere ¡in ¡physical ¡memory.

39

Virtual ¡ Address ¡ Space ¡for ¡ Process ¡1: Physical ¡ Address ¡ Space ¡ (DRAM)

N-­‑1

Virtual ¡ Address ¡ Space ¡for ¡ Process ¡2:

VP ¡1 VP ¡2

...

N-­‑1

VP ¡1 VP ¡2

...

PP ¡2 PP ¡6 PP ¡8

...

M-­‑1

PP ¡9

Easy ¡cached ¡access ¡to ¡storage ¡> ¡memory

Good ¡temporal ¡ locality ¡ + ¡small ¡working ¡ set ¡= ¡mostly ¡page ¡hits

Great ¡if ¡working ¡sets ¡< ¡physical ¡memory, even ¡if ¡total ¡data ¡> ¡physical ¡memory

If ¡combined ¡working ¡ sets ¡of ¡all ¡processes) ¡> ¡physical ¡memory:

Thrashing: Performance ¡meltdown. ¡CPU ¡always ¡waiting ¡or ¡paging.

Full ¡indirection ¡quote:

“Every ¡problem ¡in ¡computer ¡science ¡can ¡be ¡solved ¡by ¡adding ¡another ¡level ¡

  • f ¡indirection, ¡but ¡that ¡usually ¡will ¡create ¡another ¡problem.”

40

slide-11
SLIDE 11

11/20/15 11

Easy ¡protection ¡and sharing

Protection:

All ¡user ¡accesses ¡go ¡through ¡translation. Impossible ¡to ¡access ¡physical ¡memory ¡not ¡mapped ¡in ¡virtual ¡address ¡spac

  • e. ¡

Sharing:

Map ¡virtual ¡pages ¡in ¡separate ¡address ¡spaces ¡to ¡same ¡physical ¡page(PP ¡6).

41

Virtual ¡ Address ¡ Space ¡for ¡ Process ¡1: Physical ¡ Address ¡ Space ¡ (DRAM)

N-­‑1 (e.g., ¡ read-­‑only ¡ library ¡ code)

Virtual ¡ Address ¡ Space ¡for ¡ Process ¡2:

VP ¡1 VP ¡2

...

N-­‑1

VP ¡1 VP ¡2

...

PP ¡2 PP ¡6 PP ¡8

...

M-­‑1

Easy ¡protection

All ¡user ¡accesses ¡go ¡through ¡translation.

Extend ¡page ¡table ¡entries ¡with ¡permission ¡bits. MMU ¡checks ¡permission bits ¡on ¡every ¡memory ¡access If ¡not ¡allowed, ¡raise ¡exception.

42

Process ¡1:

Physical ¡Page ¡Num WRITE EXEC PP ¡6 No No PP ¡4 No Yes PP ¡2 Yes

Process ¡2:

No READ Yes No Yes WRITE EXEC PP ¡9 Yes No PP ¡6 No No PP ¡11 Yes No READ No Yes No VP ¡0: VP ¡1: VP ¡2: VP ¡0: VP ¡1: VP ¡2:

Physical ¡ Address ¡Space

PP ¡2 PP ¡4 PP ¡6 PP ¡8 PP ¡9 PP ¡11 Yes Yes Yes Yes Yes Yes Valid Valid Physical ¡Page ¡Num

Summary

Programmer’s ¡ view ¡of ¡virtual ¡ memory

Each ¡process ¡has ¡its ¡own ¡private ¡linear ¡address ¡space Cannot ¡be ¡corrupted ¡by ¡other ¡processes

System ¡view ¡of ¡virtual ¡ memory

Uses ¡memory ¡efficiently ¡by ¡caching ¡virtual ¡memory ¡pages Efficient ¡only ¡because ¡of ¡locality Simplifies ¡memory ¡management ¡and ¡sharing Simplifies ¡protection ¡-­‑-­‑ easy ¡to ¡interpose ¡and ¡check ¡permissions

43

Memory ¡System ¡Summary

L1/L2/L3 ¡Cache

Purely ¡a ¡speed-­‑up ¡technique "Invisible" ¡to ¡application ¡programmer ¡and ¡OS Implemented ¡totally ¡in ¡hardware

Virtual ¡ Memory

Supports ¡processes, ¡memory ¡management Operating ¡System ¡(software) Allocates ¡physical ¡memory Maintains ¡page ¡tables ¡and ¡memory ¡metadata Handles ¡exceptions, ¡fills ¡tables ¡used ¡by ¡hardware Hardware Translates ¡virtual ¡addresses ¡via ¡mapping ¡tables, ¡enforces ¡permissions Accelerates ¡mapping ¡via ¡translation ¡cache ¡(TLB)

44

slide-12
SLIDE 12

11/20/15 12

Memory ¡System ¡Summary

L1/L2/L3 ¡Cache

Controlled ¡by ¡hardware Programmer ¡cannot ¡control ¡it Programmer ¡can write ¡code ¡in ¡a ¡way ¡that ¡takes ¡advantage ¡of ¡it

Virtual ¡ Memory

Controlled ¡by ¡OS ¡and ¡hardware Programmer ¡cannot ¡control ¡mapping ¡to ¡physical ¡memory Programmer ¡can ¡control ¡sharing ¡and ¡some ¡protection via ¡OS ¡system ¡calls

45