Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation...
Transcript of Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation...
![Page 1: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/1.jpg)
L05-1MIT 6.823 Spring 2020
Mengjia YanComputer Science and Artificial Intelligence Laboratory
M.I.T.
Based on slides from Daniel Sanchez
Modern Virtual Memory Systems
![Page 2: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/2.jpg)
MIT 6.823 Spring 2020
Recap: Virtual Memory SystemsIllusion of a large, private, uniform store
February 20, 2020
Protection & Privacy• several users, each with their private
address space and one or more shared address spaces• page table º name space
Demand Paging• Provides the ability to run programs
larger than the primary memory• Hides differences in machine
configurations
The price is address translation on each memory reference
OS
useri
PrimaryMemory
SwappingStore
VA PAmappingTLB
![Page 3: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/3.jpg)
MIT 6.823 Spring 2020
Recap: Hierarchical Page Table
February 20, 2020
Level 1 Page Table
Level 2Page Tables
Data Pages
page in primary memory page in secondary memory
Root of the CurrentPage Table
p1
offset
p2
Virtual Address
(ProcessorRegister)
PTE of a nonexistent page
p1 p2 offset01112212231
10-bitL1 index
10-bit L2 index
![Page 4: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/4.jpg)
MIT 6.823 Spring 2020
Recap: Translation Lookaside Buffers
February 20, 2020
Address translation is very expensive!• In a two-level page table, each reference becomes
several memory accesses
Solution: Cache translations in TLBTLB hit Þ Single-cycle TranslationTLB miss Þ Page Table Walk to refill
VPN offset
V R W D tag PPN
physical address PPN offset
virtual address
hit?
(VPN = virtual page number)
(PPN = physical page number)
![Page 5: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/5.jpg)
MIT 6.823 Spring 2020
Recap: Translation Lookaside Buffers
February 20, 2020
Address translation is very expensive!• In a two-level page table, each reference becomes
several memory accesses
Solution: Cache translations in TLBTLB hit Þ Single-cycle TranslationTLB miss Þ Page Table Walk to refill
VPN offset
V R W D tag PPN
physical address PPN offset
virtual address
hit?
(VPN = virtual page number)
(PPN = physical page number)
<tag, index>
![Page 6: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/6.jpg)
MIT 6.823 Spring 2020
Recap: TLB Designs
• Typically 32-128 entries, usually fully associative– Each entry maps a large page, hence less spatial locality across
pages è more likely that two entries conflict– Sometimes larger TLBs (256-512 entries) are 4-16 way set-
associative
• Random or FIFO replacement policy• No process information in TLB?• TLB Reach: Size of largest virtual address space
that can be simultaneously mapped by TLB
Example: 64 TLB entries, 4KB pages, one page per entry
TLB Reach = _____________________________________?
February 20, 2020
64 entries * 4 KB = 256 KB (if contiguous)
![Page 7: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/7.jpg)
MIT 6.823 Spring 2020
Variable-Sized Page Support
February 20, 2020
Level 1 Page Table
Level 2Page Tables
Data Pages
page in primary memorylarge page in primary memory page in secondary memoryPTE of a nonexistent page
Root of the CurrentPage Table
p1
offset
p2
Virtual Address
(ProcessorRegister)
p1 p2 offset01112212231
10-bitL1 index
10-bit L2 index
L05-7
![Page 8: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/8.jpg)
MIT 6.823 Spring 2020
Variable-Sized Page Support
February 20, 2020
Level 1 Page Table
Level 2Page Tables
Data Pages
page in primary memorylarge page in primary memory page in secondary memoryPTE of a nonexistent page
Root of the CurrentPage Table
p1
offset
p2
Virtual Address
(ProcessorRegister)
p1 p2 offset01112212231
10-bitL1 index
10-bit L2 index
L05-8
![Page 9: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/9.jpg)
MIT 6.823 Spring 2020
Variable-Size Page TLB
February 20, 2020
• Chicken-and-egg problem
virtual address
V RWD Tag PPN L
L05-9
47 21 12 0
xxxxxxxx……xxxxxxx 000000110 110010111000
![Page 10: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/10.jpg)
MIT 6.823 Spring 2020
Variable-Size Page TLB
February 20, 2020
• Chicken-and-egg problem
virtual address
V RWD Tag PPN L
L05-10
47 21 12 0
xxxxxxxx……xxxxxxx 000000110 1100101110004KB page VPN 4KB page offset
![Page 11: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/11.jpg)
MIT 6.823 Spring 2020
Variable-Size Page TLB
February 20, 2020
• Chicken-and-egg problem
virtual address
V RWD Tag PPN L
L05-11
47 21 12 0
xxxxxxxx……xxxxxxx 000000110 1100101110002MB page VPN
4KB page VPN
2MB page offset
4KB page offset
![Page 12: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/12.jpg)
MIT 6.823 Spring 2020
Variable-Size Page TLB
February 20, 2020
• Chicken-and-egg problem
virtual address
hit?
V RWD Tag PPN L
L05-12
47 21 12 0
xxxxxxxx……xxxxxxx 000000110 1100101110002MB page VPN
4KB page VPN
2MB page offset
4KB page offset
![Page 13: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/13.jpg)
MIT 6.823 Spring 2020
Variable-Size Page TLB
February 20, 2020
• Chicken-and-egg problem
virtual address
hit?
V RWD Tag PPN L
L05-13
47 21 12 0
xxxxxxxx……xxxxxxx 000000110 1100101110002MB page VPN
4KB page VPN
2MB page offset
4KB page offset
xxxxxxxx……xxxxxxx xxxxxxxxx 110010111000physical address
![Page 14: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/14.jpg)
MIT 6.823 Spring 2020
Variable-Size Page TLB
February 20, 2020
• Chicken-and-egg problem• Q: how about set-associative TLBs?
virtual address
hit?
V RWD Tag PPN L
L05-14
47 21 12 0
xxxxxxxx……xxxxxxx 000000110 1100101110002MB page VPN
4KB page VPN
2MB page offset
4KB page offset
xxxxxxxx……xxxxxxx xxxxxxxxx 110010111000physical address
![Page 15: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/15.jpg)
MIT 6.823 Spring 2020
Variable-Size Page TLB
February 20, 2020
• Chicken-and-egg problem• Q: how about set-associative TLBs?• Some systems use separate TLBs for different page sizes.
virtual address
hit?
V RWD Tag PPN L
L05-15
47 21 12 0
xxxxxxxx……xxxxxxx 000000110 1100101110002MB page VPN
4KB page VPN
2MB page offset
4KB page offset
xxxxxxxx……xxxxxxx xxxxxxxxx 110010111000physical address
![Page 16: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/16.jpg)
MIT 6.823 Spring 2020
Handling a TLB Miss
February 20, 2020
• Software (MIPS, Alpha)
• Hardware (SPARC v8, x86, PowerPC)
L05-16
![Page 17: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/17.jpg)
MIT 6.823 Spring 2020
Handling a TLB Miss
February 20, 2020
• Software (MIPS, Alpha)• TLB miss causes an exception and the operating system
walks the page tables and reloads TLB.• A privileged “untranslated” addressing mode used for walk
• Hardware (SPARC v8, x86, PowerPC)
L05-17
![Page 18: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/18.jpg)
MIT 6.823 Spring 2020
Handling a TLB Miss
February 20, 2020
• Software (MIPS, Alpha)• TLB miss causes an exception and the operating system
walks the page tables and reloads TLB.• A privileged “untranslated” addressing mode used for walk
• Hardware (SPARC v8, x86, PowerPC)• A memory management unit (MMU) walks the page tables
and reloads the TLB• If a missing (data or PT) page is encountered during the
TLB reloading, MMU gives up and signals a Page-Fault exception for the original instruction
L05-18
![Page 19: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/19.jpg)
MIT 6.823 Spring 2020
Handling a TLB Miss
February 20, 2020
• Software (MIPS, Alpha)• TLB miss causes an exception and the operating system
walks the page tables and reloads TLB.• A privileged “untranslated” addressing mode used for walk
• Hardware (SPARC v8, x86, PowerPC)• A memory management unit (MMU) walks the page tables
and reloads the TLB• If a missing (data or PT) page is encountered during the
TLB reloading, MMU gives up and signals a Page-Fault exception for the original instruction
L05-19
Q: Pros and cons of software and hardware approaches?
![Page 20: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/20.jpg)
MIT 6.823 Spring 2020
Hierarchical Page Table Walk: SPARC v8
February 20, 2020
31 11 0
Virtual Address Index 1 Index 2 Index 3 Offset31 23 17 11 0
ContextTableRegister
ContextRegister
root ptr
PTPPTP
PTE
Context Table
L1 Table
L2 TableL3 Table
Physical Address PPN Offset
MMU does this table walk in hardware on a TLB missL05-20
![Page 21: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/21.jpg)
MIT 6.823 Spring 2020
Address Translation:putting it all together
February 20, 2020
Virtual Address
TLBLookup
hardwarehardware or softwaresoftware
L05-21
![Page 22: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/22.jpg)
MIT 6.823 Spring 2020
Address Translation:putting it all together
February 20, 2020
Virtual Address
TLBLookup
ProtectionCheck
hit
hardwarehardware or softwaresoftware
L05-22
![Page 23: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/23.jpg)
MIT 6.823 Spring 2020
Address Translation:putting it all together
February 20, 2020
Virtual Address
TLBLookup
ProtectionCheck
hit
hardwarehardware or softwaresoftware
PhysicalAddress(to cache)
permitted
L05-23
![Page 24: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/24.jpg)
MIT 6.823 Spring 2020
Address Translation:putting it all together
February 20, 2020
Virtual Address
TLBLookup
ProtectionCheck
hit
hardwarehardware or softwaresoftware
PhysicalAddress(to cache)
permitteddenied
ProtectionFault
SEGFAULT
L05-24
![Page 25: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/25.jpg)
MIT 6.823 Spring 2020
Address Translation:putting it all together
February 20, 2020
Virtual Address
TLBLookup
Page TableWalk
miss
ProtectionCheck
hit
hardwarehardware or softwaresoftware
PhysicalAddress(to cache)
permitteddenied
ProtectionFault
SEGFAULT
L05-25
![Page 26: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/26.jpg)
MIT 6.823 Spring 2020
Address Translation:putting it all together
February 20, 2020
Virtual Address
TLBLookup
Page TableWalk
miss
ProtectionCheck
hit
Update TLB
the page is Îmemory
hardwarehardware or softwaresoftware
PhysicalAddress(to cache)
permitteddenied
ProtectionFault
SEGFAULT
L05-26
![Page 27: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/27.jpg)
MIT 6.823 Spring 2020
Address Translation:putting it all together
February 20, 2020
Virtual Address
TLBLookup
Page TableWalk
miss
ProtectionCheck
hit
Update TLB
the page is Îmemory
hardwarehardware or softwaresoftware
PhysicalAddress(to cache)
permitteddenied
ProtectionFault
SEGFAULT
L05-27
Page Fault(OS loads page)
Ïmemory
![Page 28: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/28.jpg)
MIT 6.823 Spring 2020
Address Translation:putting it all together
February 20, 2020
Virtual Address
TLBLookup
Page TableWalk
miss
ProtectionCheck
hit
Update TLB
the page is Îmemory
hardwarehardware or softwaresoftware
PhysicalAddress(to cache)
permitteddenied
ProtectionFault
SEGFAULTWhere?L05-28
Page Fault(OS loads page)
Ïmemory
![Page 29: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/29.jpg)
MIT 6.823 Spring 2020
Topics
February 20, 2020
• Interrupts• Speeding up the common case:
– TLB & Cache organization• Speeding up page table walks• Modern Usage
L05-29
Virtual Address
TLBLookup
Page TableWalk
miss
ProtectionCheck
hit
Update TLB
the page is Îmemory
hardwarehardware or softwaresoftware
PhysicalAddress(to cache)
permitteddenied
ProtectionFault
SEGFAULTWhere?
Page Fault(OS loads page)
Ïmemory
![Page 30: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/30.jpg)
MIT 6.823 Spring 2020
Interrupts: altering the normal flow of control
February 20, 2020
Ii-1
Ii
Ii+1
program
An external or internal event that needs to be processed by another (system) program. The event is usually unexpected or rare from program’s point of view.
L05-30
![Page 31: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/31.jpg)
MIT 6.823 Spring 2020
Interrupts: altering the normal flow of control
February 20, 2020
Ii-1
Ii
Ii+1
program
An external or internal event that needs to be processed by another (system) program. The event is usually unexpected or rare from program’s point of view.
L05-31
HI1
HI2
HIn
interrupt handler
![Page 32: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/32.jpg)
MIT 6.823 Spring 2020
Causes of Interrupts
• Asynchronous: an external event – input/output device service-request– timer expiration– power disruptions, hardware failure
• Synchronous: an internal event (a.k.a exception)– undefined opcode, privileged instruction– arithmetic overflow, FPU exception– misaligned memory access – virtual memory exceptions:
• page faults, TLB misses, protection violations– traps: system calls, e.g., jumps into kernel
February 20, 2020
Interrupt: an event that requests the attention of the processor
L05-32
![Page 33: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/33.jpg)
MIT 6.823 Spring 2020
Asynchronous Interrupts:invoking the interrupt handler
• An I/O device requests attention by asserting one of the prioritized interrupt request lines
• Tricky: interrupted thread cannot anticipate/prepare for this control transfer
• When the processor decides to process the interrupt
February 20, 2020 L05-33
![Page 34: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/34.jpg)
MIT 6.823 Spring 2020
Asynchronous Interrupts:invoking the interrupt handler
• An I/O device requests attention by asserting one of the prioritized interrupt request lines
• Tricky: interrupted thread cannot anticipate/prepare for this control transfer
• When the processor decides to process the interrupt – Precise interrupt: It stops the current program at instruction Ii,
completing all the instructions up to Ii-1
– It saves the PC of instruction Ii in a special register (EPC) – It disables interrupts and transfers control to a designated
interrupt handler running in the kernel mode
February 20, 2020 L05-34
Ii-1
Ii
Ii+1
HI1
HI2
HIn
User->kernel
Kernel->user
![Page 35: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/35.jpg)
MIT 6.823 Spring 2020
Interrupt Handler• Needs to read a status register that indicates the
cause of the interrupt• Uses a special indirect jump instruction RFE
(return-from-exception) that– enables interrupts– restores the processor to the user mode– restores hardware status and control state
• Nested interrupts
February 20, 2020 L05-35
![Page 36: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/36.jpg)
MIT 6.823 Spring 2020
Interrupt Handler• Needs to read a status register that indicates the
cause of the interrupt• Uses a special indirect jump instruction RFE
(return-from-exception) that– enables interrupts– restores the processor to the user mode– restores hardware status and control state
• Nested interrupts– Saves EPC before enabling interrupts– need an instruction to move EPC into GPRs – need a way to mask further interrupts at least until EPC can be
saved
February 20, 2020 L05-36
![Page 37: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/37.jpg)
MIT 6.823 Spring 2020
Synchronous Interrupts
• A synchronous interrupt (exception) is caused by a particular instruction
• In general, the instruction cannot be completed and needs to be restarted after the exception has been handled– With pipelining, requires undoing the effect of one or more
partially executed instructions
• In case of a trap (system call), the instruction is considered to have been completed – A special jump instruction involving a change to privileged
kernel mode
February 20, 2020 L05-37
![Page 38: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/38.jpg)
MIT 6.823 Spring 2020
Topics
• Interrupts
• Speeding up the common case:– TLB & Cache organization
• Speeding up page table walks
• Modern Usage
February 20, 2020 L05-38
![Page 39: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/39.jpg)
MIT 6.823 Spring 2020
Address Translation in CPU
February 20, 2020
PCInst.
CacheData Cache+RegFile
L05-39
![Page 40: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/40.jpg)
MIT 6.823 Spring 2020
Address Translation in CPU
February 20, 2020
PCInst.
CacheData Cache+
Inst TLB
Data TLBRegFile
L05-40
![Page 41: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/41.jpg)
MIT 6.823 Spring 2020
Address Translation in CPU
February 20, 2020
PCInst.
CacheData Cache+
Inst TLB
Data TLB
TLB miss? Page Fault?Protection violation?
TLB miss? Page Fault?Protection violation?
RegFile
L05-41
![Page 42: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/42.jpg)
MIT 6.823 Spring 2020
Address Translation in CPU
• TLB miss: a hardware or software mechanism• Page fault or protection violation: software handler
February 20, 2020
PCInst.
CacheData Cache+
Inst TLB
Data TLB
TLB miss? Page Fault?Protection violation?
TLB miss? Page Fault?Protection violation?
RegFile
L05-42
![Page 43: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/43.jpg)
MIT 6.823 Spring 2020
Address Translation in CPU
• TLB miss: a hardware or software mechanism• Page fault or protection violation: software handler• The common case: TLB lookup before every cache access
February 20, 2020
PCInst.
CacheData Cache+
Inst TLB
Data TLB
TLB miss? Page Fault?Protection violation?
TLB miss? Page Fault?Protection violation?
RegFile
L05-43
![Page 44: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/44.jpg)
MIT 6.823 Spring 2020
Address Translation in CPU
• TLB miss: a hardware or software mechanism• Page fault or protection violation: software handler• The common case: TLB lookup before every cache access
• Need mechanisms to cope with the additional latency of TLB:
February 20, 2020
PCInst.
CacheData Cache+
Inst TLB
Data TLB
TLB miss? Page Fault?Protection violation?
TLB miss? Page Fault?Protection violation?
RegFile
L05-44
![Page 45: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/45.jpg)
MIT 6.823 Spring 2020
Address Translation in CPU
• TLB miss: a hardware or software mechanism• Page fault or protection violation: software handler• The common case: TLB lookup before every cache access
• Need mechanisms to cope with the additional latency of TLB:– slow down the clock– pipeline the TLB and cache access– virtual-address caches– parallel TLB/cache access
February 20, 2020
PCInst.
CacheData Cache+
Inst TLB
Data TLB
TLB miss? Page Fault?Protection violation?
TLB miss? Page Fault?Protection violation?
RegFile
L05-45
![Page 46: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/46.jpg)
MIT 6.823 Spring 2020
Virtual-Address Caches
February 20, 2020
Pros and cons:
CPU PhysicalCacheTLB Primary
MemoryVA
PA
L05-46
![Page 47: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/47.jpg)
MIT 6.823 Spring 2020
Virtual-Address Caches
February 20, 2020
Pros and cons:
CPU PhysicalCacheTLB Primary
MemoryVA
PA
Alternative: place the cache before the TLB
CPU
VA
VirtualCache
PATLB
PrimaryMemory
L05-47
![Page 48: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/48.jpg)
MIT 6.823 Spring 2020
Virtual-Address Caches
February 20, 2020
Pros and cons:• one-step process in case of a hit (+)
CPU PhysicalCacheTLB Primary
MemoryVA
PA
Alternative: place the cache before the TLB
CPU
VA
VirtualCache
PATLB
PrimaryMemory
L05-48
![Page 49: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/49.jpg)
MIT 6.823 Spring 2020
Virtual-Address Caches
February 20, 2020
Pros and cons:• one-step process in case of a hit (+)• cache needs to be flushed on a context switch unless
address space identifiers (ASIDs) included in tags (-)
CPU PhysicalCacheTLB Primary
MemoryVA
PA
Alternative: place the cache before the TLB
CPU
VA
VirtualCache
PATLB
PrimaryMemory
L05-49
![Page 50: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/50.jpg)
MIT 6.823 Spring 2020
Virtual-Address Caches
February 20, 2020
Pros and cons:• one-step process in case of a hit (+)• cache needs to be flushed on a context switch unless
address space identifiers (ASIDs) included in tags (-)• aliasing problems due to the sharing of pages (-)
CPU PhysicalCacheTLB Primary
MemoryVA
PA
Alternative: place the cache before the TLB
CPU
VA
VirtualCache
PATLB
PrimaryMemory
L05-50
![Page 51: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/51.jpg)
MIT 6.823 Spring 2020
Aliasing in Virtual-Address Caches
February 20, 2020
VA1
VA2
Page Table
Data Pages
PA
Two virtual pages share one physical page
L05-51
![Page 52: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/52.jpg)
MIT 6.823 Spring 2020
Aliasing in Virtual-Address Caches
February 20, 2020
VA1
VA2
Page Table
Data Pages
PA
Two virtual pages share one physical page
General Solution: Disallow aliases to coexist in cache
L05-52
![Page 53: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/53.jpg)
MIT 6.823 Spring 2020
Aliasing in Virtual-Address Caches
February 20, 2020
VA1
VA2
Page Table
Data Pages
PA
VA1
VA2
1st Copy of Data at PA
2nd Copy of Data at PA
Tag Data
Two virtual pages share one physical page
General Solution: Disallow aliases to coexist in cache
L05-53
![Page 54: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/54.jpg)
MIT 6.823 Spring 2020
Aliasing in Virtual-Address Caches
February 20, 2020
VA1
VA2
Page Table
Data Pages
PA
VA1
VA2
1st Copy of Data at PA
2nd Copy of Data at PA
Tag Data
Two virtual pages share one physical page
Virtual cache can have two copies of same physical data. Writes to one copy not visible
to reads of other!
General Solution: Disallow aliases to coexist in cache
L05-54
![Page 55: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/55.jpg)
MIT 6.823 Spring 2020
Aliasing in Virtual-Address Caches
February 20, 2020
VA1
VA2
Page Table
Data Pages
PA
VA1
VA2
1st Copy of Data at PA
2nd Copy of Data at PA
Tag Data
Two virtual pages share one physical page
Virtual cache can have two copies of same physical data. Writes to one copy not visible
to reads of other!
General Solution: Disallow aliases to coexist in cacheSoftware (i.e., OS) solution for direct-mapped cache
VAs of shared pages must agree in cache index bits; this ensures all VAs accessing same PA will conflict in direct-mapped cache (early SPARCs)
L05-55
![Page 56: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/56.jpg)
MIT 6.823 Spring 2020
Concurrent Access to TLB & Cache
February 20, 2020
VPN
TLBDirect-map Cache
2L blocks2b-byte block
PPN
Data
VA
PA
k
L05-56
PageOffset
![Page 57: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/57.jpg)
MIT 6.823 Spring 2020
Concurrent Access to TLB & Cache
February 20, 2020
VPN
TLBDirect-map Cache
2L blocks2b-byte block
PPN
Data
VA
PA
k
L05-57
VirtualIndexL b
PageOffset
![Page 58: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/58.jpg)
MIT 6.823 Spring 2020
Concurrent Access to TLB & Cache
February 20, 2020
Index L is available without consulting the TLBÞ cache and TLB accesses can begin simultaneously
VPN
TLBDirect-map Cache
2L blocks2b-byte block
PPN
Data
VA
PA
k
L05-58
VirtualIndexL b
PageOffset
![Page 59: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/59.jpg)
MIT 6.823 Spring 2020
Concurrent Access to TLB & Cache
February 20, 2020
Index L is available without consulting the TLBÞ cache and TLB accesses can begin simultaneously
VPN
TLBDirect-map Cache
2L blocks2b-byte block
PPN
Data=
hit?Physical Tag
Tag
VA
PA
k
L05-59
VirtualIndexL b
PageOffset
![Page 60: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/60.jpg)
MIT 6.823 Spring 2020
Concurrent Access to TLB & Cache
February 20, 2020
Index L is available without consulting the TLBÞ cache and TLB accesses can begin simultaneously
Tag comparison is made after both accesses are completed
VPN
TLBDirect-map Cache
2L blocks2b-byte block
PPN
Data=
hit?Physical Tag
Tag
VA
PA
k
L05-60
VirtualIndexL b
PageOffset
![Page 61: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/61.jpg)
MIT 6.823 Spring 2020
Concurrent Access to TLB & Cache
February 20, 2020
Index L is available without consulting the TLBÞ cache and TLB accesses can begin simultaneously
Tag comparison is made after both accesses are completed
VPN
TLBDirect-map Cache
2L blocks2b-byte block
PPN
Data=
hit?Physical Tag
Tag
VA
PA
k
L05-61
VirtualIndexL b
PageOffset
VPN2 VA2 L b
![Page 62: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/62.jpg)
MIT 6.823 Spring 2020
Concurrent Access to TLB & Cache
February 20, 2020
Index L is available without consulting the TLBÞ cache and TLB accesses can begin simultaneously
Tag comparison is made after both accesses are completed
When does this work? L + b < k __ L + b = k __ L + b > k __
VPN
TLBDirect-map Cache
2L blocks2b-byte block
PPN
Data=
hit?Physical Tag
Tag
VA
PA
k
L05-62
VirtualIndexL b
PageOffset
VPN2 VA2 L b
![Page 63: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/63.jpg)
MIT 6.823 Spring 2020
Concurrent Access to TLB & Cache
February 20, 2020
Index L is available without consulting the TLBÞ cache and TLB accesses can begin simultaneously
Tag comparison is made after both accesses are completed
When does this work? L + b < k __ L + b = k __ L + b > k __
VPN
TLBDirect-map Cache
2L blocks2b-byte block
PPN
Data=
hit?Physical Tag
Tag
VA
PA
k
üL05-63
VirtualIndexL b
PageOffset
VPN2 VA2 L b
![Page 64: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/64.jpg)
MIT 6.823 Spring 2020
Concurrent Access to TLB & Cache
February 20, 2020
Index L is available without consulting the TLBÞ cache and TLB accesses can begin simultaneously
Tag comparison is made after both accesses are completed
When does this work? L + b < k __ L + b = k __ L + b > k __
VPN
TLBDirect-map Cache
2L blocks2b-byte block
PPN
Data=
hit?Physical Tag
Tag
VA
PA
k
ü üL05-64
VirtualIndexL b
PageOffset
VPN2 VA2 L b
![Page 65: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/65.jpg)
MIT 6.823 Spring 2020
Concurrent Access to TLB & Cache
February 20, 2020
Index L is available without consulting the TLBÞ cache and TLB accesses can begin simultaneously
Tag comparison is made after both accesses are completed
When does this work? L + b < k __ L + b = k __ L + b > k __
VPN
TLBDirect-map Cache
2L blocks2b-byte block
PPN
Data=
hit?Physical Tag
Tag
VA
PA
k
ü ü ûL05-65
VirtualIndexL b
PageOffset
VPN2 VA2 L b
![Page 66: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/66.jpg)
MIT 6.823 Spring 2020
Concurrent Access to TLB & Large L1The problem with L1 > Page size
February 20, 2020
TLB
PPN b
Tag
VA
PA
L1 cacheVIPTDirect-map
= hit?
L05-66
kPageOffset
VPN b
![Page 67: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/67.jpg)
MIT 6.823 Spring 2020
Concurrent Access to TLB & Large L1The problem with L1 > Page size
February 20, 2020
TLB
PPN b
Tag
VA
PA
L1 cacheVIPTDirect-map
= hit?
L05-67
kPageOffset
VPN b
Virtual Index
![Page 68: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/68.jpg)
MIT 6.823 Spring 2020
Concurrent Access to TLB & Large L1The problem with L1 > Page size
February 20, 2020
TLB
PPN b
Tag
VA
PA
L1 cacheVIPTDirect-map
= hit?
L05-68
kPageOffset
VPN b
Virtual Index
a
![Page 69: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/69.jpg)
MIT 6.823 Spring 2020
Concurrent Access to TLB & Large L1The problem with L1 > Page size
February 20, 2020
Can VA1 and VA2 both map to PA?
TLB
PPN b
Tag
VA
PA
L1 cacheVIPTDirect-map
= hit?
L05-69
kPageOffset
VPN b
Virtual Index
a
![Page 70: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/70.jpg)
MIT 6.823 Spring 2020
Concurrent Access to TLB & Large L1The problem with L1 > Page size
February 20, 2020
Can VA1 and VA2 both map to PA?
TLB
PPN b
Tag
VA
PA
L1 cacheVIPTDirect-map
= hit?
PPNa Data
PPNa Data
VA1
VA2
Yes
L05-70
kPageOffset
VPN b
Virtual Index
a
![Page 71: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/71.jpg)
MIT 6.823 Spring 2020
Virtual-Index Physical-Tag Caches: Associative Organization
February 20, 2020
Is this scheme realistic?
VPN L = k-b b
TLB Direct-map2L blocks
PPN
=hit?
Data
Phy.Tag
Tag
VA
PA
VirtualIndex
kDirect-map2L blocks
2a
=2a
After the PPN is known, 2a physical tags are compared
L05-71
PageOffset
a
![Page 72: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/72.jpg)
MIT 6.823 Spring 2020
A solution via Second-Level Cache
February 20, 2020
Usually a common L2 cache backs up both Instruction and Data L1 caches
L2 is “inclusive” of both Instruction and Data caches
CPU
L1 Data Cache
L1 Instruction
Cache Unified L2 Cache
RF Memory
Memory
Memory
Memory
L05-72
![Page 73: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/73.jpg)
MIT 6.823 Spring 2020
Anti-Aliasing Using L2: MIPS R10000
February 20, 2020
VPN Page Offset b
TLB
PPN Page Offset b
Tag
VA
PA
Virtual Index
= hit?
PPNa DataVA1
VA2
PPN
• Suppose VA1 and VA2 both map to PA and VA1 is already in L1, L2 (VA1 ¹ VA2)
L05-73
L1 cacheVIPTDirect-map
a into L2 tag
![Page 74: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/74.jpg)
MIT 6.823 Spring 2020
L2 cache
PA a1 Data
(PIPT)
Anti-Aliasing Using L2: MIPS R10000
February 20, 2020
VPN Page Offset b
TLB
PPN Page Offset b
Tag
VA
PA
Virtual Index
= hit?
PPNa DataVA1
VA2
PPN
• Suppose VA1 and VA2 both map to PA and VA1 is already in L1, L2 (VA1 ¹ VA2)
L05-74
L1 cacheVIPTDirect-map
a into L2 tag
![Page 75: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/75.jpg)
MIT 6.823 Spring 2020
L2 cache
PA a1 Data
(PIPT)
Anti-Aliasing Using L2: MIPS R10000
February 20, 2020
VPN Page Offset b
TLB
PPN Page Offset b
Tag
VA
PA
Virtual Index
= hit?
PPNa DataVA1
VA2
PPN
• Suppose VA1 and VA2 both map to PA and VA1 is already in L1, L2 (VA1 ¹ VA2)
• After VA2 is resolved to PA, collision is detected in L2. Collision à
L05-75
L1 cacheVIPTDirect-map
a into L2 tag
![Page 76: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/76.jpg)
MIT 6.823 Spring 2020
L2 cache
PA a1 Data
(PIPT)
Anti-Aliasing Using L2: MIPS R10000
February 20, 2020
VPN Page Offset b
TLB
PPN Page Offset b
Tag
VA
PA
Virtual Index
= hit?
PPNa DataVA1
VA2
PPN
• Suppose VA1 and VA2 both map to PA and VA1 is already in L1, L2 (VA1 ¹ VA2)
• After VA2 is resolved to PA, collision is detected in L2. Collision à Field a is different.
L05-76
L1 cacheVIPTDirect-map
a into L2 tag
![Page 77: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/77.jpg)
MIT 6.823 Spring 2020
L2 cache
PA a1 Data
(PIPT)
Anti-Aliasing Using L2: MIPS R10000
February 20, 2020
VPN Page Offset b
TLB
PPN Page Offset b
Tag
VA
PA
Virtual Index
= hit?
PPNa DataVA1
VA2
PPN
• Suppose VA1 and VA2 both map to PA and VA1 is already in L1, L2 (VA1 ¹ VA2)
• After VA2 is resolved to PA, collision is detected in L2. Collision à
• VA1 will be purged from L1, and VA2 will be loaded Þ no aliasing!
Field a is different.
L05-77
L1 cacheVIPTDirect-map
a into L2 tag
![Page 78: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/78.jpg)
MIT 6.823 Spring 2020
L2 cache
PA a1 Data
(PIPT)
Anti-Aliasing Using L2: MIPS R10000
February 20, 2020
VPN Page Offset b
TLB
PPN Page Offset b
Tag
VA
PA
Virtual Index
= hit?
PPNa DataVA1
VA2
PPN
• Suppose VA1 and VA2 both map to PA and VA1 is already in L1, L2 (VA1 ¹ VA2)
• After VA2 is resolved to PA, collision is detected in L2. Collision à
• VA1 will be purged from L1, and VA2 will be loaded Þ no aliasing!
Field a is different.
L05-78
L1 cacheVIPTDirect-map
a into L2 tag
![Page 79: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/79.jpg)
MIT 6.823 Spring 2020
L2 cache
PA a1 Data
(PIPT)
Anti-Aliasing Using L2: MIPS R10000
February 20, 2020
VPN Page Offset b
TLB
PPN Page Offset b
Tag
VA
PA
Virtual Index
= hit?
PPNa DataVA1
VA2
PPN
• Suppose VA1 and VA2 both map to PA and VA1 is already in L1, L2 (VA1 ¹ VA2)
• After VA2 is resolved to PA, collision is detected in L2. Collision à
• VA1 will be purged from L1, and VA2 will be loaded Þ no aliasing!
Field a is different.a2
L05-79
L1 cacheVIPTDirect-map
a into L2 tag
![Page 80: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/80.jpg)
MIT 6.823 Spring 2020
L2 cache
PA a1 Data
(PIPT)
Anti-Aliasing Using L2: MIPS R10000
February 20, 2020
VPN Page Offset b
TLB
PPN Page Offset b
Tag
VA
PA
Virtual Index
= hit?
PPNa Data
PPNa Data
VA1
VA2
PPN
• Suppose VA1 and VA2 both map to PA and VA1 is already in L1, L2 (VA1 ¹ VA2)
• After VA2 is resolved to PA, collision is detected in L2. Collision à
• VA1 will be purged from L1, and VA2 will be loaded Þ no aliasing!
Field a is different.a2
L05-80
L1 cacheVIPTDirect-map
a into L2 tag
![Page 81: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/81.jpg)
MIT 6.823 Spring 2020
Virtually Addressed L1:Anti-Aliasing using L2
February 20, 2020
VPN Page Offset b
TLB
PPN Page Offset b
Tag
VA
PA
VirtualIndex & Tag
PhysicalIndex & Tag
L1 VA Cache
L2 PA Cache L2 “contains” L1
PA VA1 Data
VA1 Data
VA2 Data
“VirtualTag”
Physically addressed L2 can also be used to avoid aliases in virtually addressed L1
L05-81
![Page 82: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/82.jpg)
MIT 6.823 Spring 2020
Topics
• Interrupts
• Speeding up the common case:– TLB & Cache organization
• Speeding up page table walks
• Modern Usage
February 20, 2020 L05-82
![Page 83: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/83.jpg)
MIT 6.823 Spring 2020
Page Fault Handler
• When the referenced page is not in DRAM:– The missing page is located (or created)– It is brought in from disk, and page table is updated
Another job may be run on the CPU while the first job waits for the requested page to be read from disk
– If no free pages are left, a page is swapped outPseudo-LRU replacement policy
February 20, 2020 L05-83
![Page 84: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/84.jpg)
MIT 6.823 Spring 2020
Page Fault Handler
• When the referenced page is not in DRAM:– The missing page is located (or created)– It is brought in from disk, and page table is updated
Another job may be run on the CPU while the first job waits for the requested page to be read from disk
– If no free pages are left, a page is swapped outPseudo-LRU replacement policy
• Since it takes a long time to transfer a page (msecs), page faults are handled completely in software by the OS– Untranslated addressing mode is essential to allow kernel
to access page tables
February 20, 2020 L05-84
![Page 85: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/85.jpg)
MIT 6.823 Spring 2020
Translation for Page Tables• Can references to page tables cause TLB misses?• Can this go on forever?
February 20, 2020
User Page Table(in virtual space)
Data Pages
User PTE Base
System Page Table(in physical space)
System PTE Base
L05-85
![Page 86: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/86.jpg)
MIT 6.823 Spring 2020
Translation for Page Tables• Can references to page tables cause TLB misses?• Can this go on forever?
February 20, 2020
User Page Table(in virtual space)
Data Pages
User PTE Base
System Page Table(in physical space)
System PTE Base
A program that traverses the page table needs a “no translation” addressing mode.
L05-86
![Page 87: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/87.jpg)
MIT 6.823 Spring 2020
A PTE in primary memory contains primary or secondary memory addresses
A PTE in secondary memory contains only secondary memory addresses
Þ a page of a PT can be swapped out onlyif none of its PTE’s point to pages in the primary memory
Why?__________________________________
Swapping a Page of a Page Table
February 20, 2020 L05-87
page in primary memory page in secondary memory
![Page 88: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/88.jpg)
MIT 6.823 Spring 2020
A PTE in primary memory contains primary or secondary memory addresses
A PTE in secondary memory contains only secondary memory addresses
Þ a page of a PT can be swapped out onlyif none of its PTE’s point to pages in the primary memory
Why?__________________________________
Swapping a Page of a Page Table
February 20, 2020
Pointed-to pages become inaccessible(page fault due to swapped-out PT page)
May cause deadlock!
L05-88
page in primary memory page in secondary memory
![Page 89: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/89.jpg)
MIT 6.823 Spring 2020
Atlas Revisited
• One PAR for each physical page
• PAR’s contain the VPN’s of the pages resident in primary memory
• Advantage:
• Disadvantage?
February 20, 2020
VPN
PARs
PPN
L05-89
![Page 90: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/90.jpg)
MIT 6.823 Spring 2020
Atlas Revisited
• One PAR for each physical page
• PAR’s contain the VPN’s of the pages resident in primary memory
• Advantage: – The size is proportional to the size of the
primary memory
• Disadvantage?
February 20, 2020
VPN
PARs
PPN
L05-90
![Page 91: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/91.jpg)
MIT 6.823 Spring 2020
Atlas Revisited
• One PAR for each physical page
• PAR’s contain the VPN’s of the pages resident in primary memory
• Advantage: – The size is proportional to the size of the
primary memory
• Disadvantage?
February 20, 2020
VPN
PARs
PPN
Must check all PARs!
L05-91
![Page 92: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/92.jpg)
MIT 6.823 Spring 2020
Hashed Page Table:Approximating Associative Addressing
February 20, 2020
hashOffset
Base of Table
+ PA of PTE
PrimaryMemory
VPN PID PPN
Page TableVPN Virtual Address
VPN PID DPN
VPN PID
PID
L05-92
![Page 93: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/93.jpg)
MIT 6.823 Spring 2020
Hashed Page Table:Approximating Associative Addressing
• Hashed Page Table is typically 2 to 3 times larger than the number of PPNs to reduce collision probability
February 20, 2020
hashOffset
Base of Table
+ PA of PTE
PrimaryMemory
VPN PID PPN
Page TableVPN Virtual Address
VPN PID DPN
VPN PID
PID
L05-93
![Page 94: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/94.jpg)
MIT 6.823 Spring 2020
Hashed Page Table:Approximating Associative Addressing
• Hashed Page Table is typically 2 to 3 times larger than the number of PPNs to reduce collision probability
• It can also contain DPNs for some non-resident pages (not common)
• If a translation cannot be resolved in this table then the software consults a data structure that has an entry for every existing page
February 20, 2020
hashOffset
Base of Table
+ PA of PTE
PrimaryMemory
VPN PID PPN
Page TableVPN Virtual Address
VPN PID DPN
VPN PID
PID
L05-94
![Page 95: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/95.jpg)
MIT 6.823 Spring 2020
Virtual Memory Use Today - 1• Desktop/server/cellphone processors have full
demand-paged virtual memory– Portability between machines with different memory sizes– Protection between multiple users or multiple tasks– Share small physical memory among active tasks– Simplifies implementation of some OS features
• Vector supercomputers and GPUs have translation and protection but not demand paging (Older Crays: base&bound, Japanese & Cray X1: pages)– Don’t waste expensive processor time thrashing to disk (make
jobs fit in memory)– Mostly run in batch mode (run set of jobs that fits in memory)– Difficult to implement restartable vector instructions
February 20, 2020 L05-95
![Page 96: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/96.jpg)
MIT 6.823 Spring 2020
Virtual Memory Use Today - 2
• Most embedded processors and DSPs provide physical addressing only– Can’t afford area/speed/power budget for virtual memory support– Often there is no secondary storage to swap to!– Programs custom-written for particular memory configuration in
product– Difficult to implement restartable instructions for exposed
architectures
February 20, 2020 L05-96
![Page 97: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/97.jpg)
L05-97MIT 6.823 Spring 2020
Next lecture: Pipelining!
![Page 98: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/98.jpg)
MIT 6.823 Spring 2020
Global System Address Space
• Level A maps users’ address spaces into the global space providing privacy, protection, sharing etc.
• Level B provides demand paging for the large global system address space
• Level A and Level B translations may be kept in separate TLB’s
February 20, 2020
GlobalSystem Address Space
PhysicalMemory
User
User
map
map
mapLevel A
Level B
L05-98
![Page 99: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/99.jpg)
MIT 6.823 Spring 2020
Hashed Page Table Walk: PowerPC Two-level, Segmented Addressing
February 20, 2020
Seg ID Page Offset0 35 51 63
Hashed Segment Table
80-bit System VA Global Seg ID Page Offset0 51 67 79
Hashed Page Table
PPN Offset0 27 39
hashP
PA of Page Table +
hashS
PA of Seg Table +
40-bit PA
64-bit user VA
per process
system-wide
PA
PA
[ IBM numbers bits with MSB=0 ]
L05-99
![Page 100: Modern Virtual Memory Systemscsg.csail.mit.edu/6.823/Lectures/L05split.pdf · Recap: Translation Lookaside Buffers February 20, 2020 Address translation is very expensive! • In](https://reader034.fdocuments.in/reader034/viewer/2022050208/5f5ae007d8679915543546bd/html5/thumbnails/100.jpg)
MIT 6.823 Spring 2020
Base of Table
Power PC: Hashed Page Table
• Each hash table slot has 8 PTEs <VPN,PPN> that are searched sequentially
• If the first hash slot fails, an alternate hash function is used to look in another slot
All these steps are done in hardware!• Hashed Table is typically 2 to 3 times
larger than the number of physical pages• The full backup Page Table is a software
data structureFebruary 20, 2020
hashOffset + PA of Slot
PrimaryMemory
VPN PPN
Page TableVPN d 80-bit VA
VPN
L05-100