DDCArv Ch8
DDCArv Ch8
Computer Architecture
Sarah Harris & David Harris
Chapter 8:
Memory Systems
Chapter 8 :: Topics
• Introduction
• Memory System Performance
Analysis
• Caches
• Virtual Memory
CLK CLK
MemWrite WE
Address ReadData
Processor Memory
WriteData
Main
Hard
CPU Cache Memory
Disk
DRAM $3 10 - 50 30
Speed
Main Memory
Memory Performance
Memory Performance
• Hit: data found in that level of memory hierarchy
• Miss: data not found (must go to next level)
Hit Rate = # hits / # memory accesses
= 1 – Miss Rate
Caches
Cache
• Highest level in memory hierarchy
• Fast (typically ~ 1 cycle access time)
• Ideally supplies most data to processor
• Usually holds most recently accessed data
Main
Hard
CPU Cache Memory
Disk
Direct-Mapped Caches
Direct Mapped Cache
Address
11...11111100 mem[0xFF...FC]
11...11111000 mem[0xFF...F8]
11...11110100 mem[0xFF...F4]
11...11110000 mem[0xFF...F0]
11...11101100 mem[0xFF...EC]
11...11101000 mem[0xFF...E8]
11...11100100 mem[0xFF...E4]
11...11100000 mem[0xFF...E0]
00...00100100 mem[0x00...24]
00...00100000 mem[0x00..20] Set Number
00...00011100 mem[0x00..1C] 7 (111)
00...00011000 mem[0x00...18] 6 (110)
00...00010100 mem[0x00...14] 5 (101)
00...00010000 mem[0x00...10] 4 (100)
00...00001100 mem[0x00...0C] 3 (011)
00...00001000 mem[0x00...08] 2 (010)
00...00000100 mem[0x00...04] 1 (001)
00...00000000 mem[0x00...00] 0 (000)
8-entry x
(1+27+32)-bit
SRAM
27 32
Hit Data
Associative Caches
N-Way Set Associative Cache
Byte
Tag Set Offset
Memory
00
Address Way 1 Way 0
28 2
V Tag Data V Tag Data
28 32 28 32
= =
0
Hit1 Hit0 Hit1
32
Conflict Misses
Hit Data
V Tag Data V Tag Data V Tag Data V Tag Data V Tag Data V Tag Data V Tag Data V Tag Data
Conflict Misses
Spatial Locality
Spatial Locality
• Increase block size:
– Block size, b = 4 words
– C = 8 words
– Direct mapped (1 block per set)
– Number of blocks, B = 2 (C/b = 8/4 = 2)
Block Byte
Tag Set Offset Offset
Memory
00
Address
27 2
V Tag Data
Set 1
Set 0
27 32 32 32 32
11
10
01
00
32
=
Hit Data
Block Byte
Tag Set Offset Offset
Memory
00
Address
27 2
V Tag Data
Set 1
Set 0
27 32 32 32 32
11
10
01
00
32
=
Hit Data
11
10
01
00
32
=
Hit Data
32 Digital Design & Computer Architecture Memory Systems
Types of Misses
• Compulsory: first time data accessed
• Capacity: cache too small to hold all data of
interest
• Conflict: data of interest maps to same
location in cache
Cache Replacement
Policy
Replacement Policy
• Cache is too small to hold all data of interest at
once
• If cache full: program accesses data X and evicts
data Y
• Capacity miss when access Y again
• How to choose Y to minimize chance of needing it
again?
– Least recently used (LRU) replacement: the least
recently used block in a set evicted
Way 1 Way 0
Cache Summary
Cache Summary
• What data is held in the cache?
– Recently used data (temporal locality)
– Nearby data (spatial locality)
• How is data found?
– Set is determined by address of data
– Word within block also determined by address
– In associative caches, data could be in one of several
ways
• What data is replaced?
– Least-recently used way in the set
Adapted from Patterson & Hennessy, Computer Architecture: A Quantitative Approach, 2011
40 Digital Design & Computer Architecture Memory Systems
Miss Rate Trends
© Intel Corp.
Virtual Memory
Virtual Memory
• Gives the illusion of bigger memory
• Main memory (DRAM) acts as cache for hard
disk
Main
Hard
CPU Cache Memory
Disk
Main
Hard
CPU Cache Memory
Disk
DRAM $3 10 - 50 30
Speed
Main Memory
Magnetic
Disks
Read/Write
Head
Address Translation
Address Translation
Virtual Address
30 29 28 ... 14 13 12 11 10 9 ... 2 1 0
VPN Page Offset
19
Translation 12
15
PPN Page Offset
26 25 24 ... 13 12 11 10 9 ... 2 1 0
Physical Address
Page Table
How to Perform Translation
• Page table
– Entry for each virtual page
– Entry fields:
• Valid bit: 1 if page in physical memory
• Physical page number: where the page is located
Physical
V Page Number
0
0
1 0x0000
VPN is 1
0
0x7FFE
Page Table
index into 0
page table 0
0
1 0x0001
0
0
1 0x7FFF
0
0
15 12
Hit
Physical
0x7FFF 47C
Address
59 Digital Design & Computer Architecture Memory Systems
Page Table Example 1
Virtual Page
Page Number Offset
Virtual
0x00005 F20
What is the physical Address
19 12
Page Table
0
address of virtual
Physical
address 0x73E4? V
0
Page Number
0
– VPN = 7 1 0x0000
1 0x7FFE
– Entry 7 is invalid 0
Page Table
0
– Virtual page must be
paged into physical 0
memory from disk 0
1 0x0001
0
0
1 0x7FFF
0
0
15
Hit
Translation Lookaside
Buffer (TLB)
Translation Lookaside Buffer (TLB)
• Small cache of most recent translations
• Reduces number of memory accesses for most
loads/stores from 2 to 1
Entry 1 Entry 0
= =
0
Hit1 Hit0 Hit1
15 12
Physical
Hit Address 0x7FFF 47C
Virtual Memory
Summary
Memory Protection
• Multiple processes (programs) run at once
• Each process has its own page table
• Each process can use entire virtual address
space
• A process can only access a subset of physical
pages: those mapped in its own page table