5 Virtual Memory Architecture: Assignments
5 Virtual Memory Architecture: Assignments
5 Virtual Memory Architecture: Assignments
9/9/98
Reading:
Supplemental Reading: http://www.cne.gmu.edu/modules/vm/submap.html Jacob & Mudge: Virtual Memory: Issues of Implementation Hennessy & Patterson: 5.7, 5.8
Assignments
u
Supplemental Reading :
Hennessy & Patterson: 5.3, 5.4
9/9/98
First look at how cache memories work -- hardware managed fast memory
u
Evolution of Virtual Memory Address mapping with page tables Why virtual memory is useful How you make it fast
Translation Lookaside Buffer (TLB) Inverted page table
9/9/98
9/9/98
Address Mapping
u
TASK 1
VIRTUAL ADDRESS ADDRESS TRANSLATION TASK 1 PHYSICAL ADDRESS PHYSICAL ADDRESS TASK 2 TASK 1 TASK 2 TASK 1 TASK 1
VIRTUAL ADDRESS
ADDRESS TRANSLATION
MAIN MEMORY
TASK 1 TASK 2 DISK ADDRESS
TASK 2
REGIST ERS VIRTUAL MEMORY ADDRESS CACHE PHYSICAL ADDRESS PHYSICAL MEMORY DISK ADDRESS DISK IP ADDRESS TLB
FILE SYST EM
NETW ORK
NETW ORK
9/9/98
9/9/98
Example: Job 5 must wait until 30 KB contiguous memory is available, not 30 KB fragmented while Job 2 is running
Example: Memory is compacted to make room for Job 5 while Job 2 is still running
9/9/98
Time is consumed copying memory blocks Programs may be bigger than physical memory
Can be solved with overlays
Programmer defines many small programs that are loaded into memory as needed Programmer-visible form of virtual memory Painful to write -- programmer must do all partitioning manually
Memory space is treated as a set of pages that may be arbitrarily distributed among main memory and swap space
Fixed size pages eliminate memory fragmentation No need for compacting and cost of copying memory blocks Base+Bound registers replaced with mapping tables (page tables) For example, implemented on IBM S/370 (1970) UNUSED 1-A 1-C 1-B 1-B 1-C UNUSED 1-D 2-J UNUSED UNUSED 1-A 2-J 2-K 2-K 2-L 2-L 1-D
9/9/98
9/9/98
Control bits
Valid/Present bit
If set, page being pointed to is resident in memory
Modified/dirty bit
Set if at least one word in page has been modified
Referenced bit
Set if page has been referenced (with either read or write) Used to support software replacement policies
Protection bits
Used to restrict access For example, read-only access, or system-only access
9/9/98
But, can keep only portions of the page table in physical memory
VAX 11/780 can page portions of page table Need not allocate entire page table (can allocate only first portion if desired) Gets complicated... is there a better way?
10
9/9/98
Only page directory & active page tables need to be in main memory
Page tables can be created on demand Page tables can be one page in size -- uniform paging mechanism for both virtual memory management and actual memory contents!
Can scale up with 3-level scheme and keep page directory size small
Example -- Alpha: say an 8 KB page holds 1K directory entries
1 level: 1K page table = 8 MB 2 levels: 1K page directory * 1K page tables = 8 GB 3 levels: 1K page directory * 1K intermediate directories * 1K page tables = 8 TB = 243
Alpha 21164 is specified to have a 43-bit virtual address space with 8KB pages...
11
9/9/98
12
9/9/98
Protection
u
Page fault mechanism provides hardware-assisted address range checks almost for free
Can set permissions on per-page basis for selective sharing Can detect some programming errors (such as dereferencing a null pointer) But, granularity can be too large to be completely useful (4KB or 8KB chunks)
13
9/9/98
14
9/9/98
15
9/9/98
TLB Operation
u
Page Name stores virtual address of page for that translation entry
May also contain process ID to avoid having to flush TLB on process switch
u u
Page Frame Address stores physical memory location of that page Example control bits (MIPS R2000):
Read-only Non-cacheable Valid Global (globally accessible; unprotected access)
S BIT
20 HI GH
BIT S
TLB
16
9/9/98
Complicates things because of aliasing (two virtual addresses can point to same physical address)
Easier to implement for I-cache than D-cache because no need to update multiple copies of data on a write operation Well look at this again in the multiprocessing/coherence lecture
u
A Hierarchy of Misses
u
Cache miss: page table entry wasnt found in the cache when reloading TLB
Example Penalty: 6 clocks for L1 miss; 48 clocks for L2 miss
Note: multiple instances of any of these misses can occur for any single instruction execution
TLB miss may require fetching page table which isnt in memory, and then cause a page fault when fetching the target page which isnt in memory Some pages are locked into main memory to prevent page faults (analogous to software management of cache contents)
17
9/9/98
Hierarchical page tables dont change fact that lots of page table entries are needed
Can lazily create page tables
18
9/9/98
The significant difference is that there are thousands of entries in an Inverted Page Table, as opposed to tens of entries in a TLB
2% space
Can still use TLB to cache recently used inverted page table entries
u
19
9/9/98
REVIEW
20
9/9/98
Review
u
VIRTUAL MEMORY
Main Memory DRAM Demand Paging Swap Device (disk) Page (4KB - 8KB) Page Tables
21
9/9/98
Key Concepts
u
Latency
Virtual memory is used to cache potential disk contents in main memory Main memory is used to cache page table entries TLB is used to cache page table entries Inverted page tables are used to cache page table entries too Disks are really slow, so its worth some effort to get page fault rate low
Bandwidth
Page sizes of 4KB or 8KB exploit bandwidth capabilities of system with block data transfers
Concurrency
Accessing Cache & TLB in parallel takes address translation off critical path
Balance
Need to balance amount of page table information in memory with amount of actual data
Inverted page tables avoid problems with degenerate cases
22