virtual memory - ee.iitb.ac.in
TRANSCRIPT
![Page 1: Virtual Memory - ee.iitb.ac.in](https://reader031.vdocument.in/reader031/viewer/2022013005/61cd4d35088ac62550326d1e/html5/thumbnails/1.jpg)
CADSL
Virtual Memory
Virendra Singh
Associate Professor Computer Architecture and Dependable Systems Lab
Department of Electrical Engineering Indian Institute of Technology Bombay
http://www.ee.iitb.ac.in/~viren/ E-mail: [email protected]
CP-226: Computer Architecture Lecture 21 (12 April 2013)
![Page 2: Virtual Memory - ee.iitb.ac.in](https://reader031.vdocument.in/reader031/viewer/2022013005/61cd4d35088ac62550326d1e/html5/thumbnails/2.jpg)
CADSL Computer Architecture@MNIT 2
Memory Hierarchy
CPU
I & D L1 Cache
Shared L2 Cache
Main Memory
Disk
Temporal Locality • Keep recently referenced items at higher levels • Future references saEsfied quickly
SpaEal Locality • Bring neighbors of recently referenced to higher levels • Future references saEsfied quickly
17 Apr 2013
![Page 3: Virtual Memory - ee.iitb.ac.in](https://reader031.vdocument.in/reader031/viewer/2022013005/61cd4d35088ac62550326d1e/html5/thumbnails/3.jpg)
CADSL Computer Architecture@MNIT 3
Virtual Memory Implementation • Caches have fixed policies, hardware FSM for control, pipeline stall
• VM has very different miss penalEes – Remember disks are 10+ ms!
• Hence engineered differently
17 Apr 2013
![Page 4: Virtual Memory - ee.iitb.ac.in](https://reader031.vdocument.in/reader031/viewer/2022013005/61cd4d35088ac62550326d1e/html5/thumbnails/4.jpg)
CADSL Computer Architecture@MNIT 4
Page Faults • A virtual memory miss is a page fault
– Physical memory locaEon does not exist – ExcepEon is raised, save PC – Invoke OS page fault handler
• Find a physical page (possibly evict) • IniEate fetch from disk
– Switch to other task that is ready to run – Interrupt when disk access complete – Restart original instrucEon
17 Apr 2013
![Page 5: Virtual Memory - ee.iitb.ac.in](https://reader031.vdocument.in/reader031/viewer/2022013005/61cd4d35088ac62550326d1e/html5/thumbnails/5.jpg)
CADSL Computer Architecture@MNIT 5
Address Translation
• O/S and hardware communicate via PTE • How do we find a PTE?
– &PTE = PTBR + page number * sizeof(PTE) – PTBR is private for each program
• Context switch replaces PTBR contents
VA PA Dirty Ref ProtecEon 0x20004000 0x2000 Y/N Y/N Read/Write/
Execute
17 Apr 2013
![Page 6: Virtual Memory - ee.iitb.ac.in](https://reader031.vdocument.in/reader031/viewer/2022013005/61cd4d35088ac62550326d1e/html5/thumbnails/6.jpg)
CADSL Computer Architecture@MNIT 6
Address Translation
PA VA D PTBR
Virtual Page Number Offset
+
17 Apr 2013
![Page 7: Virtual Memory - ee.iitb.ac.in](https://reader031.vdocument.in/reader031/viewer/2022013005/61cd4d35088ac62550326d1e/html5/thumbnails/7.jpg)
CADSL Computer Architecture@MNIT 7
Page Table Size
• How big is page table? – 232 / 4K * 4B = 4M per program (!) – Much worse for 64-‐bit machines
• To make it smaller – Use limit register(s)
• If VA exceeds limit, invoke O/S to grow region
– Use a mulE-‐level page table – Make the page table pageable (use VM)
17 Apr 2013
![Page 8: Virtual Memory - ee.iitb.ac.in](https://reader031.vdocument.in/reader031/viewer/2022013005/61cd4d35088ac62550326d1e/html5/thumbnails/8.jpg)
CADSL Computer Architecture@MNIT 8
Multilevel Page Table
PTBR +
Offset
+
+
17 Apr 2013
![Page 9: Virtual Memory - ee.iitb.ac.in](https://reader031.vdocument.in/reader031/viewer/2022013005/61cd4d35088ac62550326d1e/html5/thumbnails/9.jpg)
CADSL Computer Architecture@MNIT 9
Hashed Page Table • Use a hash table or inverted page table
– PT contains an entry for each real address • Instead of entry for every virtual address
– Entry is found by hashing VA – Oversize PT to reduce collisions:
#PTE = 4 x (#phys. pages)
17 Apr 2013
![Page 10: Virtual Memory - ee.iitb.ac.in](https://reader031.vdocument.in/reader031/viewer/2022013005/61cd4d35088ac62550326d1e/html5/thumbnails/10.jpg)
CADSL Computer Architecture@MNIT 10
Hashed Page Table
PTBR
Virtual Page Number Offset
Hash PTE2 PTE1 PTE0 PTE3
17 Apr 2013
![Page 11: Virtual Memory - ee.iitb.ac.in](https://reader031.vdocument.in/reader031/viewer/2022013005/61cd4d35088ac62550326d1e/html5/thumbnails/11.jpg)
CADSL Computer Architecture@MNIT 11
High-Performance VM • VA translaEon
– AddiEonal memory reference to PTE – Each instrucEon fetch/load/store now 2 memory references • Or more, with mulElevel table or hash collisions
– Even if PTE are cached, sEll slow • Hence, use special-‐purpose cache for PTEs
– Called TLB (translaEon lookaside buffer) – Caches PTE entries – Exploits temporal and spaEal locality (just a cache)
17 Apr 2013
![Page 12: Virtual Memory - ee.iitb.ac.in](https://reader031.vdocument.in/reader031/viewer/2022013005/61cd4d35088ac62550326d1e/html5/thumbnails/12.jpg)
CADSL Computer Architecture@MNIT 12
TLB
17 Apr 2013
![Page 13: Virtual Memory - ee.iitb.ac.in](https://reader031.vdocument.in/reader031/viewer/2022013005/61cd4d35088ac62550326d1e/html5/thumbnails/13.jpg)
CADSL Computer Architecture@MNIT 13
Virtual Memory Protection • Each process/program has private virtual address space – AutomaEcally protected from rogue programs
• Sharing is possible, necessary, desirable – Avoid copying, staleness issues, etc.
• Sharing in a controlled manner – Grant specific permissions
• Read • Write • Execute • Any combinaEon
– Store permissions in PTE and TLB
17 Apr 2013
![Page 14: Virtual Memory - ee.iitb.ac.in](https://reader031.vdocument.in/reader031/viewer/2022013005/61cd4d35088ac62550326d1e/html5/thumbnails/14.jpg)
CADSL Computer Architecture@MNIT 14
Summary • Memory hierarchy: Register file
– Under compiler/programmer control – Complex register allocaEon algorithms to opEmize uElizaEon
• Memory hierarchy: Virtual Memory – Placement: fully flexible – IdenEficaEon: through page table – Replacement: approximate LRU or LFU – Write policy: write-‐through
17 Apr 2013
![Page 15: Virtual Memory - ee.iitb.ac.in](https://reader031.vdocument.in/reader031/viewer/2022013005/61cd4d35088ac62550326d1e/html5/thumbnails/15.jpg)
CADSL Computer Architecture@MNIT 15
Summary • Page tables
– Forward page table • &PTE = PTBR + VPN * sizeof(PTE)
– MulElevel page table • Tree structure enables more compact storage for sparsely populated address space
– Inverted or hashed page table • Stores PTE for each real page instead of each virtual page • HPT size scales up with physical memory
– Also used for protecEon, sharing at page level
17 Apr 2013
![Page 16: Virtual Memory - ee.iitb.ac.in](https://reader031.vdocument.in/reader031/viewer/2022013005/61cd4d35088ac62550326d1e/html5/thumbnails/16.jpg)
CADSL Computer Architecture@MNIT 16
Summary • TLB
– Special-‐purpose cache for PTEs – Olen accessed in parallel with L1 cache
• Main memory design – Commodity DRAM chips – Wide design space for
• Minimizing cost, latency • Maximizing bandwidth, storage
17 Apr 2013
![Page 17: Virtual Memory - ee.iitb.ac.in](https://reader031.vdocument.in/reader031/viewer/2022013005/61cd4d35088ac62550326d1e/html5/thumbnails/17.jpg)
CADSL
Thank You
17 Apr 2013 Computer Architecture@MNIT 17