Memory – Hierarchy Design 存储层次设计
1. Intro
存储器件的 存储速度&离cpu的距离&价格/大小
逆相关,离CPU越近,速度越快,空间越小,价格越高。
时间局部性(Temporal Locality):If an item is referenced, the same item will tend to be referenced again soon.
空间局部性(Spatial Locality):If an item is referenced, nearby itemswill tend to be referenced soon.
2. ABCs 36个名词
3. Cache设计的四类问题
- Block placement(映射关系)
- Fully Associative, Set Associative, Direct Mapped
- Block identification(识别机制)
- Tag/Block
- Block replacement(替换策略)
- Random, LRU,FIFO
- Write strategy(写策略)
- Write Back or Write Through (with Write Buffer)
4. Block Placement
Direct Mapped
主存中的一个 Block 只能映射到 Cache 上的唯一位置。
*可以看作将 Cache 分成了八个组,每个组只有一个 Block。算法:Mod 取模。
Full-associative
主存中的一个 Block 可以映射到 Cache 上的任何位置。
* 可以看作将Cache 分成了一个组。
n-way associative
主存中的一个 Block 可以映射到 Cache 唯一个组的任何位置。
5. The Format of the Physical Address
Tag/Index/Byte Offset
Index
「采用n-way:选择组;采用直接映射:选择block」
Tag
「采用n-way:有log2(#sets)位 ;采用直接映射:有log2(#blocks)位」
Byte Offset
「有log2(block size)位」
6. Block Replacement
- 在直接映射的 Cache 里,只有一个 Block 能够被替换。(不需要块替换策略)
- 在全关联和组关联的 Cache 里,有多个 Block 能够被替换。
Random replacement
随机替换
Least-recently used (LRU)
最近最少使用
First in,first out(FIFO)
先进先出
7. Write Strategy
Write-through cache
written to memory 直接写回内存
Write-back cache
NOT written to memory 不直接写回,在块替换时统一写回
8. Write stall
Write stall
CPU等待写执行的停顿
Write buffers
防止大量写操作堵塞,先写入write buffer,在其他时候再写回内存。
9. Write misses 写操作在 write 时未命中
Write allocate
先载入到cache中,再进行操作。
Write around
只写入主存中,不存储在cache中。
- 一般的,write-back使用write-allocate,write-through使用write-around。
10. Cache performance
CPU Execution Time
Average Memory Access Time
= Hit time + Miss Rate * Miss Penalty
= (Accesses time on hitting + Accesses time on miss) / All memory accesses in program
= HitTimeinst + MissRataInst * Miss
- 如果100条指令里有26条LS指令,则INST%为100/126,DATA%为26/100。
0 条评论