Upload
brian-joseph
View
213
Download
0
Embed Size (px)
Citation preview
Virtual Memory main memory can act as a cache for
secondary storage motivation:
Allow programs to use more memory that there is available
transparent to programmer c.f. overlays
Allow multiple programs concurrently non-active part of of programs reside in secondary storage active portions of many programs reside in memory active portion of current program in cache
Virtual Memory With multiple programs sharing memory have
to deal with: program relocation protection
Give each program (process) it own (virtual) address space
When program accesses memory translate virtual address to physical address
Virtual MemoryP h y s ic a l a d d re s s e s
D is k a d d re s s e s
V ir t u a l a d d re s s e s
A d d re s s t ra n s la t io n
Definitions main concepts similar to caches
however different terminology used virtual memory block => page virtual memory miss => page fault
Address Translation
3 2 1 011 10 9 815 14 13 1231 30 29 28 27
Page offsetVirtual page number
Virtual address
3 2 1 011 10 9 815 14 13 1229 28 27
Page offsetPhysical page number
Physical address
Translation
Design Choices Page faults : when a page not in memory
then have to fetch from disk can take millions of cycles
Minimise miss penalty: make pages fairly large (4KB to 64KB) reduce page fault rate:
Use LRU replacement High levels of associatively
make caches write-back
Placing/Finding a page Want Full associatively
impractical to search all pages in memory Use a page table to map virtual addresses to
physical addresses Each program has its own page table Page tables reside in memory
reads/writes to main mem require twoo accesses: one to get page table entry one to perform data transfer
Page Tables
Physical memory
Disk storage
Valid
1
1
1
1
0
1
1
0
1
1
0
1
Page table
Virtual pagenumber
Physical page ordisk address
Page Tables
Base address of current page table held in the page table register
A programs state defined by its
PC Registers Page table
Page offsetVirtual page number
Virtual address
Page offsetPhysical page number
Physical address
Physical page numberValid
If 0 then page is notpresent in memory
Page table register
Page table
20 12
18
31 30 29 28 27 15 14 13 12 11 10 9 8 3 2 1 0
29 28 27 15 14 13 12 11 10 9 8 3 2 1 0
TLBs Translation-lookaside Buffer cache of page table mappings Typical values for a TLB might be:
TLB size 32 – 4096 entries Block Size: 1 – 2 page table entries Hit time: 0.5 – 1 clock cycles Miss penalty: 10 – 30 clock cycles Miss rate: 0.01 – 1%
TLBs
Valid
1
1
1
1
0
1
1
0
1
1
0
1
Page table
Physical pageaddressValid
TLB
1
1
1
1
0
1
TagVirtual page
number
Physical pageor disk address
Physical memory
Disk storage
TLBs and caches
Yes
Deliver datato the CPU
Write?
Try to read datafrom cache
Write data into cache,update the tag, and put
the data and the addressinto the write buffer
Cache hit?Cache miss stall
TLB hit?
TLB access
Virtual address
TLB missexception
No
YesNo
YesNo
Write accessbit on?
YesNo
Write protectionexception
Physical address
Virtual Memory Protection If a physical page is not pointed to from the
page table then it can not be accessed Need to prevent a process from changing its
own page table user and supervisor modes write protect bit to stop writes to the page table Mechanism to allow swaps between user and
supervisor mode and vice versa
Modern Systems
Very complicated memory systems:Characteristic Intel Pentium Pro PowerPC 604
Virtual address 32 bits 52 bitsPhysical address 32 bits 32 bitsPage size 4 KB, 4 MB 4 KB, selectable, and 256 MBTLB organization A TLB for instructions and a TLB for data A TLB for instructions and a TLB for data
Both four-way set associative Both two-way set associativePseudo-LRU replacement LRU replacementInstruction TLB: 32 entries Instruction TLB: 128 entriesData TLB: 64 entries Data TLB: 128 entriesTLB misses handled in hardware TLB misses handled in hardware
Characteristic Intel Pentium Pro PowerPC 604Cache organization Split instruction and data caches Split intruction and data cachesCache size 8 KB each for instructions/data 16 KB each for instructions/dataCache associativity Four-way set associative Four-way set associativeReplacement Approximated LRU replacement LRU replacementBlock size 32 bytes 32 bytesWrite policy Write-back Write-back or write-through