Cache Memory and Pipelining
1. Introduction – Memory Cache
1.1 Cache Memory
- main memory用于储存程序和数据,容量较大但速度较慢,通常使用DRAM
- cache memory是一种缓冲区,可以让电脑在lower DRAM speeds的情况下更高效的运行,容量较小但速度较快,通常使用SRAM
- 对于需要多次访问的数据,高速缓存可以提高内存系统的整体性能

1.2 Memory Hierarchy
- Register - 位于CPU内部,容量最小速度最快
- L1 Cache - 离CPU核心最近,访问速度很快
- L2 Cache - 容量通常大于L1,但速度较慢
- Main memory - 容量更大,速度更慢
- Magnetic Disk - 容量大,速度最慢
2. Locality of Reference
2.1 Locality Principle of Reference
- temporal locality(时间局限性):在短时间内程序很可能再次访问之前使用过的数据或指令
- space locality(空间局限性):程序在访问某个内存地址后,很可能接着访问附近的内存地址
2.2 Locality 与 Cache Memory 的关系
- 出于这种处理器在短时间内反复访问同一组内存位置的倾向:当首次需要某个信息项时,将其放入缓存(时间局限性),同时获取相邻地址处的整个数据块(空间局限性)
3. Cache Design
3.1 Cache Hit and Miss(命中与未命中)
3.2 Elements of Cache Design(设计要素)
3.2.1 Cache Size(缓存容量)
3.2.2 Mapping Function(映射方式)
-
Direct Mapped(直接映射)P.21–29
-
Fully Associative(全相联映射)P.30
-
Set Associative(组相联映射)P.31–36
3.2.3 Replacement Algorithms(替换算法)
P.37–45
-
Least Recently Used (LRU)
-
FIFO / LFU / Random
-
Cache Directory 与替换管理
-
Cache 查询流程与例题(P.39–44)
3.2.4 Read and Write Policies(读写策略)
P.46
-
Cache Read / Write
-
Write Through / Write Back
-
Write Allocate / Write No-Allocate
-
Dirty Bit
3.2.5 Line Size(缓存行大小)
3.2.6 Number of Caches(缓存数量)
4. Performance Measures(缓存性能评估)
P.50–58
4.1 Cache Memory(缓存结构与发展)
4.2 Cache Hit and Miss(回顾)
4.3 Performance Measurement(性能指标)
4.3.1 Hit Ratio (HR)
4.3.2 Effective Access Time (EAT)
4.4 Two-Level Cache Memory(两级缓存)
4.5 Direct Mapped Cache Example(计算例题)
4.5.1 Memory Access 与 Cache Mapping
4.5.2 Hit Ratio 计算
4.5.3 Effective Access Time 计算
5. Pipelining(流水线)
P.60–62
5.1 Pipelining 基本原理
5.2 Pipeline Stages(流水线阶段)
5.3 Serial vs. Pipelined Execution(串行与流水线执行)
5.4 Pipeline Timing(流水线时间分析)
6. Advanced Techniques for Pipelining(流水线高级技术)
P.64–69