# 計算機結構.Chap9+10 - Cache_ ###### tags: `計算機結構 Computer Architecture note`, `110-1` * # Contents * [TOC] * * --- * # 一些小定義 1. ## Hit - Hit Time: RAM access time + Time to determine hit/miss 2. ## Miss - Miss Penalty: Time to replace a block in the upper level + Time to deliver the block to the processor (在 miss 的那層記憶體找一個空間讓自己塞進去 + 從找到的地方(lower level)回傳自己給 processor) ![](https://i.imgur.com/ltBDGFA.png) 3. ## Little Conclusion - Hit Rate + Miss Rate = 1 - 在 upper level 找到想要找的 address ,就直接回傳自己的 data 給 processor ➜ **Hit(命中)** - 在 upper level 找不到想要找的 address ,所以得到下一層記憶體空間尋找,找到後回傳自己的 data 給 processor ➜ **Miss(沒命中)** - Hit Time << Miss Penalty (上百萬倍時間的差異) # Chap9-Cache Summary ## Locality - The Principle of Locality: Program likely to access a relatively small portion of the address space at any instant of tim ### Temporal Locality: (Locality in Time) - 時間上的聚集性。 - 當一個 data 被存取後,再次被存取的機率是很高的。 > - Keep **most recently accessed** data items closer to the processor ### Spatial Locality: (Locality in Space) - 空間上的聚集性。 - 當一個 data 被存取後,該 data location 附近的 data 被存取的可能性也很高。 > - Move blocks consisting of **contiguous words** to the upper levels # Example of Cache ## Direct Mapped Cache - lots of **items at the lower level** must **share locations in the upper level.** - ![](https://i.imgur.com/lcdiUqn.png) - 《Mapping 的方式》 - 取 memory address 除以 cache block 數量的**餘數**,就是上方的紅字 ![](https://i.imgur.com/VBNzKXN.png) ## cache Misses >- Three major categories of cache misses: 1. ### Compulsory misses: - sad facts of life. Example: cold start misses 2. ### Conflict misses: - increase cache size and/or associativity - Nightmare Scenario: **ping pong effect!** ![](https://i.imgur.com/mYsEQPx.png) 3. ### Capacity misses: increase cache size ## Cache design space ### 1. total size, block size, associativity (replacement policy) ### 2. write-hit policy (write-through, write-back) - ## = cache Hit ![](https://i.imgur.com/24U0w4n.png) ![](https://i.imgur.com/GH2L4vS.png) ### 3. write-miss policy (write allocate, write buffers # 來不及ㄌ我放棄 你各位加油。