x
play

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


  1. 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 ¡lookaside buffer Physical ¡address 2: 3: Extra ¡ benefits: ¡ sharing ¡and ¡protection (PA) CPU 4: 4 5: 6: 7: 8: Memory ¡as ¡a ¡contiguous ¡array ¡ of ¡bytes ¡is ¡a ¡lie! ¡ ¡Why? ... M-­‑1: Data Small ¡ embedded ¡systems ¡without ¡processes Elevators, ¡microwaves, ¡radio-­‑powered ¡devices, ¡… 1 2 Problem ¡1: ¡Memory ¡Management Problem ¡2: ¡Capacity 64-­‑bit ¡addresses ¡can ¡address Physical ¡main ¡memory ¡offers Main ¡memory several ¡ exabytes a ¡few ¡gigabytes (18,446,744,073,709,551,616 ¡bytes) (e.g. ¡8,589,934,592 ¡bytes) Process ¡1 stack Process ¡2 x (Actually, ¡ it’s ¡smaller ¡ than ¡that heap Process ¡3 What ¡goes ¡ ? dot ¡compared ¡ to ¡virtual ¡ memory.) .text … where? .data Process ¡n … Also: Context ¡switches must ¡swap ¡out ¡entire ¡memory ¡contents. 1 ¡virtual ¡address ¡space ¡per ¡process, ¡ Isn't ¡that ¡ expensive ? with ¡many ¡processes… 3 4 1

  2. 11/20/15 Problem ¡3: ¡Protection Solution: ¡Virtual ¡Memory ¡ (address ¡ indirection ) Virtual ¡memory Physical ¡main ¡memory Process ¡i Process ¡1 virtual ¡ Physical ¡memory addresses Process ¡j virtual-­‑to-­‑physical mapping physical ¡ Virtual ¡memory addresses Problem ¡4: ¡Sharing Physical ¡main ¡memory Process ¡n virtual ¡ Process ¡i addresses Private ¡ virtual ¡ address ¡space ¡ Single ¡physical ¡ address ¡space ¡ Process ¡j per ¡process. managed ¡ by ¡OS/hardware. 5 6 Indirection Tangent: Indirection ¡everywhere 0 Pointers • Direct ¡naming 1 "2" Constants • Thing 2 Procedural ¡abstraction • 3 What ¡X ¡ Domain ¡Name ¡Service ¡ (DNS) • 4 currently ¡ Dynamic ¡Host ¡Configuration ¡Protocol ¡(DHCP) maps ¡to 5 • Indirect ¡ naming 2 Phone ¡numbers "x" 6 • 7 911 • Call ¡centers • Snail ¡mail ¡forwarding What ¡if ¡we ¡move ¡ Thing ? • … • “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." 7 2

  3. 11/20/15 Virtual ¡Addressing Page-­‑based ¡Mapping both ¡address ¡spaces divided ¡into ¡fixed-­‑size, ¡aligned ¡ pages Virtual Memory ¡Management ¡ Unit Address ¡Space page ¡size ¡= ¡power ¡of ¡two translates ¡virtual ¡address ¡to ¡physical ¡address 0 Main ¡memory Virtual Physical Page Address ¡Space 0: 0 0 CPU ¡Chip 1: Physical ¡ Virtual Page Virtual ¡address Physical ¡address 2: Page 3: 0 (VA) (PA) 1 CPU MMU 4: Physical ¡ 4 Virtual 4100 5: Page Page 6: 1 2 7: … Virtual 8: Page Map ¡virtual ¡ pages ¡ ... … 3 onto ¡physical ¡pages. Physical ¡ M-­‑1: Page 2 p -­‑ 1 2 m -­‑ 1 Virtual Data Page 2 v -­‑ 1 2 n -­‑ 1 Physical ¡addresses ¡are invisible to ¡programs. 9 Not ¡drawn ¡to ¡scale ¡ Virtual ¡Memory: ¡cache ¡for ¡disk? Some ¡virtual ¡pages ¡do ¡not ¡fit! ¡ ¡Where ¡are ¡they ¡stored? Virtual ¡Memory virtual ¡address ¡space Address ¡Space usually ¡much ¡larger ¡than SRAM DRAM 0 physical ¡address ¡space Virtual Physical ¡Memory ~4 ¡MB ~8 ¡GB ~500 ¡GB Page Address ¡Space 0 0 L1 ¡ Physical ¡ Virtual I-­‑cache Page Page L2 ¡ Main ¡ Disk 0 1 unified ¡ 32 ¡KB Memory Physical ¡ Virtual cache Page Page L1 ¡ CPU Reg 1 D-­‑cache 2 … Virtual Throughput: 16 ¡B/cycle 8 ¡B/cycle 2 ¡B/cycle 1 ¡B/30 ¡cycles Page solid-­‑state … Latency: 3 ¡cycles 14 ¡cycles 100 ¡cycles millions 3 1. ¡On ¡disk (if ¡used) "flash" ¡ memory Physical ¡ or Page 2 p -­‑ 1 spinning 2 m -­‑ 1 Virtual magnetic ¡platter . Cache ¡miss ¡penalty Page (latency): ¡33x 2. ¡Nowhere! (if ¡not ¡yet ¡used) 2 v -­‑ 1 2 n -­‑ 1 Memory ¡ miss ¡penalty Intel ¡Core ¡2 ¡Duo (latency): ¡ 10,000x c.a. ¡2006-­‑2011 12 3

  4. 11/20/15 Design ¡for ¡a ¡Slow ¡Disk: ¡Exploit ¡Locality Address ¡Translation Virtual ¡Memory Large ¡page ¡size Main ¡memory Address ¡Space usually ¡4KB, ¡up ¡to ¡2-­‑4MB 0 0: Virtual Physical ¡Memory CPU ¡Chip 1: Page Address ¡Space Virtual ¡address Physical ¡address 2: 0 0 3: Physical ¡ (VA) (PA) Virtual CPU MMU Page 4: 4 Page Fully ¡associative 4100 5: 0 1 6: Store ¡any ¡virtual ¡page ¡in ¡any ¡physical ¡pag e Physical ¡ • Virtual 7: Page Large ¡mapping ¡function Page • 8: 1 2 ... … What ¡happens ¡in ¡here? Virtual Page M-­‑1: … 3 on ¡disk Physical ¡ Data Page 2 p -­‑ 1 2 m -­‑ 1 Virtual Sophisticated Page 2 v -­‑ 1 replacement ¡policy 2 n -­‑ 1 Write-­‑back • Not ¡just ¡hardware 14 Page ¡Table Address ¡Translation ¡ with ¡a Page ¡Table Physical ¡pages array ¡of ¡ page ¡table ¡entries (PTEs) (Physical ¡memory) mapping ¡virtual ¡page ¡to ¡where ¡it ¡is ¡stored PP ¡0 VP ¡1 Virtual ¡address (VA) Physical ¡Page ¡Number Page ¡ table ¡ base ¡ register or ¡disk ¡address Valid Virtual ¡ page ¡number (VPN) Virtual ¡ page ¡offset (VPO) VP ¡2 (PTBR) PTE ¡0 null 0 Base ¡address VP ¡7 Page ¡table ¡ 1 of ¡current ¡process's 1 page ¡table Valid Physical ¡page ¡number ¡(PPN) VP ¡4 PP ¡3 0 1 null 0 0 PTE ¡7 1 Swap ¡space Virtual ¡page ¡mapped page ¡table (Disk) to ¡physical ¡page? VP ¡3 Physical ¡ page ¡number (PPN) Physical ¡ page ¡offset (PPO) Memory ¡resident, VP ¡6 managed ¡by ¡HW ¡(MMU), ¡OS Physical ¡addres s ¡(PA) How ¡many ¡page ¡tables ¡ are ¡in ¡the ¡system? 15 16 4

  5. 11/20/15 Page ¡ Fault: ¡ exceptional ¡control ¡flow Page ¡ Hit: virtual ¡page ¡in ¡memory Physical ¡pages (Physical ¡memory) Virtual ¡Page ¡Numb er Process ¡accessed ¡virtual ¡address ¡in ¡a ¡page ¡that ¡is ¡not ¡in ¡physical ¡memory. PP ¡0 VP ¡1 Physical ¡Page ¡Number or ¡disk ¡address Valid VP ¡2 Process PTE ¡0 null 0 VP ¡7 User ¡Code OS ¡exception ¡handler 1 1 VP ¡4 PP ¡3 0 exception: ¡page ¡ fault 1 movl null 0 Create ¡page ¡and ¡ 0 load ¡into ¡memory PTE ¡7 1 return Swap ¡space page ¡table (Disk) VP ¡3 VP ¡6 Returns ¡to ¡faulting ¡instruction: is ¡executed ¡ again ! movl 17 18 "Page ¡out" Page ¡ Fault: ¡1. page ¡ not ¡ in ¡memory Page ¡ Fault: ¡2. OS ¡evicts ¡another ¡page. Physical ¡pages Physical ¡pages (Physical ¡memory) (Physical ¡memory) Virtual ¡Page ¡Numb er Virtual ¡Page ¡Numb er PP ¡0 PP ¡0 VP ¡1 VP ¡1 Physical ¡Page ¡Number Physical ¡Page ¡Number or ¡disk ¡address or ¡disk ¡address Valid Valid VP ¡2 VP ¡2 PTE ¡0 null PTE ¡0 null 0 0 VP ¡7 VP ¡7 1 0 1 1 VP ¡4 VP ¡4 PP ¡3 PP ¡3 0 0 1 1 null null 0 0 0 0 PTE ¡7 1 PTE ¡7 1 Swap ¡space Swap ¡space page ¡table (Disk) page ¡table (Disk) VP ¡3 VP ¡3 What ¡now? VP ¡6 VP ¡6 OS ¡handles ¡ fault VP ¡1 19 20 5

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend