第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)app

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

1. 靜態RAM (SRAM)ide

晶體管,只要有電,雙穩定狀態,像個倒立的鐘擺fetch

2. 動態RAM優化

3. 傳統的DRAMatom

DRAM芯片中的單元(位)被分紅d個超單元,每一個超單元
都由w個DRAM單元組成。超單元被組織成一個r行c列的列陣。
這樣可減小引腳(pin)數。spa

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是好的

對多維數組,空間局部性尤其重要。

相關文章
相關標籤/搜索