第6章 存储器层次结构

第6章 存储器层次结构 18 Dec 2017
-- The Memory Hierarchy

6.1 Storage Technologies 581
6.2 Locality 604
6.3 The memory hirarchy 609
6.4 cache memories 614
6.5 writing Cache-friendly code 633
6.6 putting it together: The impact of caches on
program performance 639
6.7 summary 648
--------------------------------------------------

# 6.1 存储技术

6.11 随机访问存储器 (random-access memory, RAM)

SRAM is used for cache memories. DRAM(dynamic RAM)
is used for the main memory plus the frame buffer of a
graphics system.

1. 静态RAM (SRAM)

晶体管,只要有电,双稳定状态,像个倒立的钟摆

2. 动态RAM

3. 传统的DRAM

DRAM芯片中的单元(位)被分成d个超单元,每个超单元
都由w个DRAM单元组成。超单元被组织成一个r行c列的列阵。
这样可减少引脚(pin)数。

4. 内存模块(memory module)

DRAM芯片封装在内存模块中,插到主板扩展槽上。

5. 增强的DRAM

基于传统的DRAM单元,以提高速度

+ 快页模式DRAM(Fast Page Mode DRAM, FPM DRAM).

连续访问同一行时,可以直接从行缓冲区中读取,而不是
丢弃后,再从新缓冲。

+ 扩展数据输出DRAM( Extended Data Out DRAM, EDO DRAM).

是FPM DRAM的增强的形式,允许CAS(列访问脉冲)在时间
上靠的更紧一点.

+ 同步DRAM( Synchronous DRAM, SDRAM).

控制信号是同步的.

+ 双倍数据速率同步DRAM( Double Data-Rate Synchronous
DRAM, DDR SDRAM).

+ 视频RAM( video RAM, VRAM).

用于图形系统的帧缓存区. 与FPM DRAM类似。区别是:
1. VRAM是输出是对内部缓冲区的整个内容移位得到的。
2. 可以同时读和写。

6. 非易失性存储器(ROM,read-only memory)

如果断电,DRAM和SRAM会丢失信息(volatile).

+ PROM(programmble ROM,可编程ROM)只能编程一次。
+ 可擦写可编程ROM(Erasable Programmable ROM, EPROM).
+ 闪存(flash memory),基于EEPROM(Electrically EPROM).

7. 访问主存

6.1.2 磁盘存储

the CPU issues commands to I/O devices using a tech-
nique called memory-mapped I/O.

In a system with memory-mapped I/O, a block of
addresses in the address spcace is reserved for commu-
nicating with I/O devices. Each of these addresses is
known as an I/O port. Each device is associated with (or
mapped to) one or more when it is attached to the bus.

6.2 locality

LOcality is typically described as having two distinct
forms: temporal locality and spatial locality.

6.2.1 locality of references to program data
6.2.2 locality of instruction fetches
6.2.3 summary

- 重复引用相同的变量的程序有良好的时间局部性
- 对于具有步长为k的引用模式的程序,步长越小,空间
局部性越好。
- 对于取指令来说,循环有好的时间和空间局部性。循环体
越小,循环迭代次数越多,局部性越好.

6.3 memory hierarchy

1. 缓存命中(cache hits)
2. 缓存不命中:如果第k层中没有缓存数据对象d,叫cache miss.

此时,第k层缓存从第k+1层缓存中取出包含d的快,如果第k层
已满,可能就会覆盖现存的一个快 -- 替换(replacing)或驱逐
(evicting).

替换策略:随机替换或最近最少使用(LRU,least recent use)

4. 缓存管理

存储器层次结构的本质是,每一个存储设备都是较低一层的缓
存。

在每一层上,某种形式的逻辑必须管理缓存。即某个东西要将
缓存划分成快,在不同的层之间传送快,判定是否命中,并处理之
。管理缓存的逻辑可以是硬件,软件,或两者的结合。

6.3.2.小结

6.4 高速缓存存储器

高速缓存的结构可用元组(S,E,B,m)来描述。
容量 C = S x E x B
S: 组的个数。E:行的个数。B:块是大小。
m:总位数。

t = m-(s+b) //t 标记位

6.4.2 直接映射高速缓存

根据每个组的高速缓存行数E,告诉缓存被分配为不同的类。
每组只有一行(E=1)的为直接映射高速缓存(direct-mapped)

高速缓存确定请求是否命中,再抽取出被请求的字的过程:
1. 组选择;2. 行匹配;3. 字抽取.

Conflict Misses in Direct-Mapped Caches

Conflict misses in direct-mapped caches typically
occur when programs access arrays whose sizes are a
power of 2.

6.4.3 Set Associative Caches

A cache with 1 < E < C/B is often called an E-way
set associative cache.

6.4.4 Fully Associative Caches

A fully associative cache consists of a single set
(i.e.,E = C/B) that contains all of the cache lines.

6.4.5 issue with writes

write-through \ write-back
write-allocate \ no-write-allocate

6.4.6 Anatomy of a real cache hierarchy

+ A cache holds instructions only is called i-cache
+ holds program data only called d-cache.
+ holds both called unified cache.

6.5 良好的优化

+ 对局部变量反复引用是好的
+ 步长为1是好的

对多维数组,空间局部性尤为重要。

posted @ 2018-03-28 23:25  孤灯下的守护者  阅读(250)  评论(0编辑  收藏  举报