Title: Virtual Memory
1Virtual Memory
2Outline
- Virtual Space
- Address translation
- Accelerating translation
- with a TLB
- Multilevel page tables
- Different points of view
- Suggested reading 10.110.6
3Physical Addressing
- Attributes of the main memory
- Organized as an array of M contiguous byte-sized
cells - Each byte has a unique physical address (PA)
started from 0 - physical addressing
- A CPU use physical addresses to access memory
- Examples
- Early PCs, DSP, embedded microcontrollers, and
Cray supercomputers
4Physical Addressing
5Virtual Addressing
- Virtual addressing
- the CPU accesses main memory by a virtual address
(VA) - The virtual address is converted to the
appropriate physical address
6Virtual Addressing
- Address translation
- Converting a virtual address to a physical one
- requires close cooperation between the CPU
hardware and the operating system - the memory management unit (MMU)
- Dedicated hardware on the CPU chip to translate
virtual addresses on the fly - A look-up table
- Stored in main memory
- Contents are managed by the operating system
7(No Transcript)
8Address Space
- Address Space
- An ordered set of nonnegative integer addresses
- Linear Space
- The integers in the address space are consecutive
- N-bit address space
9Address Space
- K210(Kilo), M220(Mega), G230(Giga),
T240(Tera), P250(Peta), E260(Exa)
256
255
16
64K-1
4G
4G-1
48
256T-1
16E
16E-1
10Address Space
- Data objects and their attributes
- Bytes vs. addresses
- Each data object can have multiple independent
addresses
11Using Main Memory as a Cache
12Using Main Memory as a Cache
- DRAM vs. disk is more extreme than SRAM vs. DRAM
- Access latencies
- DRAM 10X slower than SRAM
- Disk 100,000X slower than DRAM
- Bottom line
- Design decisions made for DRAM caches driven by
enormous cost of misses
13Design Considerations
- Line size?
- Large, since disk better at transferring large
blocks - Associativity?
- High, to minimize miss rate
- Write through or write back?
- Write back, since cant afford to perform small
writes to disk
14Page
- Virtual memory
- Organized as an array of contiguous byte-sized
cells stored on disk conceptually. - Each byte has a unique virtual address that
serves as an index into the array - The contents of the array on disk are cached in
main memory
15Page
- The data on disk is partitioned into blocks
- Serve as the transfer units between the disk and
the main memory - virtual pages (VPs)
- physical pages (PPs)
- Also referred to as page frames
16Page Attributes
- Unallocated
- Pages that have not yet been allocated (or
created) by the VM system - Do not have any data associated with them
- Do not occupy any space on disk.
17Page Attributes
- Cached
- Allocated pages that are currently cached in
physical memory. - Uncached
- Allocated pages that are not cached in physical
memory.
18Page
19Page Table
- Each allocate page of virtual memory has entry in
page table - Mapping from virtual pages to physical pages
- From uncached form to cached form
- Page table entry even if page not in memory
- Specifies disk address
- OS retrieves information
20Page Table
21Page Table
22Page Hits
23Page Faults
- Page table entry indicates virtual address not in
memory - OS exception handler invoked to move data from
disk into memory - current process suspends, others can resume
- OS has full control over placement, etc.
24Page Faults
- Swapping or paging
- Swapped out or paged out
- Demand paging
25Servicing a Page Fault
(1) Initiate Block Read
- Processor Signals Controller
- Read block of length P starting at disk address X
and store starting at memory address Y
Processor
Reg
Cache
Memory-I/O bus
I/O controller
Memory
disk
Disk
26Servicing a Page Fault
Processor
- Read Occurs
- Direct Memory Access (DMA)
- Under control of I/O controller
Reg
Cache
Memory-I/O bus
(2) DMA Transfer
I/O controller
Memory
disk
Disk
27Servicing a Page Fault
- I / O Controller Signals Completion
- Interrupt processor
- OS resumes suspended process
Processor
Reg
(3) Read Done
Cache
Memory-I/O bus
I/O controller
Memory
disk
Disk
28Address Translation
- V 0, 1, . . . , N1 virtual address space
- P 0, 1, . . . , M1 physical address space
- N gt M
- MAP V ? P U ? address mapping function
- MAP(a) a' if data at virtual address a is
- present at physical address a' in P
- ? if data at virtual address a is not
- present in P
29Address Translation
30Address Translation
- Parameters
- P 2p page size (bytes).
- N 2n Virtual address limit
- M 2m Physical address limit
31Address Translation
32Address Translation via Page Table
33Simple Memory System Example
- Addressing
- 14-bit virtual addresses
- 12-bit physical address
- Page size 64 bits
34Simple Memory System Page Table
- Only show first 16 entries
35Address Translation Example
Virtual Address 0x03D4
VPN 0x0f Page Fault? No
PPN 0x0D VPO 0x14 PA 0x354
36Page Hits
37Page Faults
38Integrating Caches and VM
39Integrating Caches and VM
- Most Caches Physically Addressed
- Accessed by physical addresses
- Allows multiple processes to have blocks in cache
at same time - Allows multiple processes to share pages
- Cache doesnt need to be concerned with
protection issues - Access rights checked as part of address
translation
40Integrating Caches and VM
- Perform Address Translation Before Cache Lookup
- But this could involve a memory access itself (of
the PTE) - Of course, page table entries can also become
cached
41(No Transcript)
42Speeding up Translation with a TLB
- Translation Lookaside Buffer (TLB)
- Small hardware cache in MMU
- Maps virtual page numbers to physical page
numbers
43(No Transcript)
44Speeding up Translation with a TLB
45Speeding up Translation with a TLB
n1
0
p1
p
virtual address
virtual page number
page offset
valid
physical page number
tag
.
.
.
TLB
TLB hit
physical address
tag
byte offset
index
valid
tag
data
Cache
data
cache hit
46Simple Memory System TLB
- TLB
- 16 entries
- 4-way associative
47Address Translation Example
Virtual Address 0x03D4
VPN 0x0f TLBI 0x03 TLBT 0x03 TLB Hit? yes
Page Fault? No
PPN 0x0D VPO 0x14 PA 0x354
48Simple Memory System Cache
- Cache
- 16 lines
- 4-byte line size
- Direct mapped
49Simple Memory System Cache
50Address Translation Example
PA 0x354
Offset 0x0 CI 0x05 CT 0x0D Hit? Yes
Byte 0x36
51Multi-Level Page Tables
- Given
- 4KB (212) page size
- 32-bit address space
- 4-byte PTE
- Problem
- Would need a 4 MB page table!
- 220 4 bytes
52Multi-Level Page Tables
- Common solution
- multi-level page tables
- e.g., 2-level table (P6)
- Level 1 table 1024 entries, each of which points
to a Level 2 page table. - Level 2 table 1024 entries, each of which
points to a page
53Representation of Virtual Address Space
Page 15
PT 3
Page 14
Page 13
Page Directory
Page 12
Page 11
PT 2
Page 10
Page 9
Page 8
PT 0
Page 7
Page 6
Page 5
Mem Addr
- Simplified Example
- 16 page virtual address space
- Flags
- P Is entry in physical memory?
- M Has this part of VA space been mapped?
Page 4
Page 3
Disk Addr
Page 2
In Mem
Page 1
On Disk
Page 0
Unmapped
54Multi-Level Page Tables
55Multi-Level Page Tables
56A Tool for Memory Management
- Separate virtual address space
- Each process has its own virtual address space
- Simplify linking, sharing, loading, and memory
allocation
57A Tool for Memory Management
58A Tool for Memory Management
59A Tool for Memory Protection
- Page table entry contains access rights
information - hardware enforces this protection (trap into OS
if violation occurs)
60A Tool for Memory Protection
61A Tool for Memory Protection