Professional Documents
Culture Documents
1
Memory Management
• From early absolute addressing schemes, to
modern virtual memory systems with support for
virtual machine monitors
3
Bare Machine
Physical Physical
Address Inst. Address Data
PC D Decode E + M W
Cache Cache
4
Dynamic Address Translation
Location-independent programs
Programming and storage management ease
need for a base register prog1
Protection
Physical Memory
Independent programs should not affect
each other inadvertently
need for a bound register
Multiprogramming drives requirement for
resident supervisor to manage context prog2
switches between multiple programs
OS
5
Simple Base and Bound Translation
Segment Length
Bound Bounds
Register Violation?
Physical Memory
Physical current
Load X Effective Address segment
Address +
Base
Register
Base Physical Address
Program
Address
Space
Main Memory
Data Base Physical
Register + Address
Inst. Data
PC + D Decode E + M + Cache W
Cache
Physical Physical
Address Address
Program Base Data Base
Register Register
Physical Physical
Address Address
Memory Controller
Physical Address
Main Memory (DRAM)
10
Private Address Space per User
OS
User 1 VA1 pages
Page Table
User 2
Physical Memory
VA1
Page Table
User 3 VA1
12
Page Tables in Physical Memory
PT
User
1
VA1
PT
Physical Memory
User
User 1 Virtual 2
Address Space
VA1
User 2 Virtual
Address Space
13
Linear Page Table
• Page Table Entry (PTE) Data Pages
Page Table
contains: PPN
– A bit to indicate if a page PPN
exists DPN
PPN
– PPN (physical page number) Data word
for a memory-resident page
Offset
– DPN (disk page number) for
a page on the disk
– Status bits for protection DPN
and usage PPN
• OS sets the Page Table Base PPN
DPN
Register whenever active DPN
user process changes VPN
DPN
PPN
PPN
PT Base Register VPN Offset
Virtual address
14
Size of Linear Page Table
With 32-bit addresses, 4-KB pages & 4-byte PTEs:
220 PTEs, i.e, 4 MB page table per user per process
4 GB of swap needed to back up full virtual address
space
Larger pages?
• Internal fragmentation (Not all memory in page is used)
• Larger page fault penalty (more time to read from disk)
10-bit 10-bit
L1 index L2 index offset
Physical Memory
Root of the Current
Page Table p2
p1
(Processor Level 1
Register) Page Table
Level 2
page in Memory Page Tables
page on Disk
User2/VA1
VA1 User1/VA1
User 2
Level 2 PT
User 2
17
Address Translation & Protection
Virtual Address Virtual Page No. (VPN) offset
Kernel/User Mode
Read/Write
Protection Address
Check Translation
Exception?
Physical Address Physical Page No. (PPN) offset
19
TLB Designs
• Typically 16-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-8 way set-
associative
– Larger systems sometimes have multi-level (L1 and L2) TLBs
• Random (Clock Algorithm) or FIFO replacement policy
• No process information in TLB
– Flush TLB on Process Context Switch
• 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
20
TLB Designs
• Typically 16-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-8 way set-
associative
– Larger systems sometimes have multi-level (L1 and L2) TLBs
• Random (Clock Algorithm) or FIFO replacement policy
• No process information in TLB
– Flush TLB on Process Context Switch
• 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
21
TLB Extensions
• Address Space Identifier (ASID)
– Allow TLB Entries from multiple processes to be in
TLB at same time. ID of address space (Process) is
matched on.
– Global Bit (G) can match on all ASIDs
• Variable Page Size (PS)
– Can increase reach on a per page basis
VRWD tag PPN PS G ASID
22
Handling a TLB Miss
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
23
Hierarchical Page Table Walk:
SPARC v8
Virtual Address Index 1 Index 2 Index 3 Offset
31 23 17 11 0
Context Context Table
Table
Register L1 Table
root ptr
Context
Register L2 Table
PTP L3 Table
PTP
PTE
31 11
Physical Address 0 PPN Offset
Miss? Miss?
Page-Table Base
Register Hardware Page
Table Walker
Physical Physical
Memory Controller Address
Address
Physical Address
Main Memory (DRAM)
• Assumes page tables held in untranslated physical memory
25
Address Translation:
putting it all together
Virtual Address
hardware
Restart instruction hardware or software
TLB
software
Lookup
miss hit
Page Fault
Update TLB Protection Physical
(OS loads page) Address
Fault
(to cache)
SEGFAULT
26
Modern Virtual Memory Systems
Illusion of a large, private, uniform store
Protection & Privacy OS
several users, each with their private
address space and one or more
shared address spaces useri
page table name space
Swapping
Demand Paging Store
Provides the ability to run programs Primary
larger than the primary memory Memory
29
Virtually Addressed Cache
(Virtual Index/Virtual Tag)
Virtual Virtual
Address Address
Inst. Data
PC D Decode E + M W
Cache Cache
Miss? Miss?
Inst.
Page-Table Base Data
TLB Register Hardware Page
TLB
Physical Table Walker
Address Physical
Instruction Memory Controller Address
data
Physical Address
Main Memory (DRAM)
Translate on miss
30
Aliasing in Virtual-Address Caches
Page Table Tag Data
VA1
Data Pages VA1 1st Copy of Data at PA
31
Cache-TLB Interactions
• Physically Indexed/Physically Tagged
• Virtually Indexed/Virtually Tagged
• Virtually Indexed/Physically Tagged
– Concurrent cache access with TLB Translation
• Both Indexed/Physically Tagged
– Small enough cache or highly associative cache
will have fewer indexes than page size
– Concurrent cache access with TLB Translation
• Physically Indexed/Virtually Tagged
32
Acknowledgements
• These slides contain material developed and copyright by:
– Arvind (MIT)
– Krste Asanovic (MIT/UCB)
– Joel Emer (Intel/MIT)
– James Hoe (CMU)
– John Kubiatowicz (UCB)
– David Patterson (UCB)
– Christopher Batten (Cornell)
33
Copyright © 2013 David Wentzlaff
34