Appendix B: Review of Memory Hierarchy

0. Preface

在该书的前言中有对于整本书的导航
在这里插入图片描述
看完第一章并做了点对应习题后本应顺势进入第二章,但是返回到导航发现附录B排在了第二章前面,故而转到附录B学习,此附录开篇也说能够对Memory Hierarchy有个快速了解,就当对知识的快速复习吧!!!!

B.1 Introduction

开篇便是36个术语:如果对某术语不太理解,希望能多搜搜~

cachefully associativewrite allocate
virtual memorydirty bitunified cache
memory stall cyclesblock offsetmisses per instruction
direct mappedwrite backblock
valid bitdata cachelocality
block addresshit timeaddress trace
write throughcache missset
instruction cachepage faultrandom replacement
average memory access timemiss rateindex field
cache hitn-way set associativeno-write allocate
pageleast recently usedwrite buffer
miss penaltytag fieldwrite stall

Cache Performance Review

我们直观意义上来说,测量机器性能都是看给定一个任务,机器执行该任务所花费的时间,高速缓冲存储器也不例外:

在这里插入图片描述
Memory stall cycles: 处理器停顿等待内存获取的周期数量。

而Memory stall cycles 又依赖 the number of misses (未命中数量)the cost per miss (未命中开销):
在这里插入图片描述
当然,上述式子只是一个近似,因为对于readwirte操作来说,Miss rate (未命中率)Miss penalty (未命中惩罚) 经常是不同的。

Four Memory Hierarchy Questions

  1. Where can a block be placed in the upper level? (block placement)
  2. How is a block found if it is in the upper level? (block identification)
  3. Which block should be replaced on a miss? (block replacement)
  4. What happens on a write? (write strategy)

回答这4个问题有助于我们理解在存储器层次结构中不同层级的利弊权衡~

Q1: Where Can a Block be Placed in a Cache?

directed mapped: (不清楚请阅读Directed Mapped Cache
在这里插入图片描述

fully associative: (不清楚请阅读Fully Associative Cache
在这里插入图片描述

set associative: (不清楚请阅读Set Associative Cache
在这里插入图片描述
下图是每种方式的图例:
在这里插入图片描述

Q2:How Is a Block Found If It Is in the Cache?

下图为set associativedirect-mapped cache 的一个地址:

在这里插入图片描述
首先,在 Tag 中必须有 valid bit,该位表明 entry 中是否包含有效地址。

如果对此一点印象都没有,那么请读一读两位大师的另一本书《计算机组成与设计 硬件/软件接口

Q3:Which Block Should be Replaced on a Cache Miss?

  1. Random
  2. Least recently used (LRU)
  3. First In, First Out (FIFO)

Q4:What Happens on a Write?

对于read操作而言,如果block hit (块命中),那么块中的数据立即送到处理器中;如果block miss (块未命中),那么也不会有什么损失,仅仅就是浪费了一些时间与能耗。

write操作就不一样了,写操作不仅比读操作花费的时间长,而且更复杂。

Cache 中写信息有两种方法:

  1. write through:信息不仅写在cache中,而且写到更低级的存储器中。
  2. write back:信息仅仅写到cache中;当被写的块被替换时,信息写到 main memory 中。

write miss(写操作失效) 时,也有两种处理方法:

  1. write allocate:把要写的地址所在的 block 先从main memory 调入到 cache 中,然后把信息写入 cache 中。
  2. no-write allocate:直接把信息写回 main memory 中。

B.2 Cache Performance

比起 miss rate,测量 cache 性能更好的指标为 average memory access time:

在这里插入图片描述
以下是关于 cache 的所有公式:

在这里插入图片描述

B.3 Six Basic Cache Optimizations

  1. Reducing the miss rate
  2. Reducing the miss penalty
  3. Reducing the time to hit in the cache
  4. Compulsory (冷不命中导致)
  5. Capacity (块替换导致)
  6. Conflict (块放置策略为直接映射或组相联)

B.4 Virtual Memory

在这里插入图片描述
虚拟存储系统可以分为两类:

  1. pages: 固定大小的块
  2. segments: 可变大小的块

在这里插入图片描述

B.6 Fallacies and Pitfalls

[Pitfall] 1. Too small an address space. (地址空间太小)

地址空间太小会限制程序的长度,因为程序大小和数据数量不能超过2address size

[Pitfall] 2. Ignoring the impact of the operating system on the performance of the memory hierarchy. (忽视操作系统对存储器层次的影响)

在这里插入图片描述

[Pitfall] 3. Relying on the operating systems to change the page size over time. (依靠操作系统随时间改变页大小)

不要期望操作系统主动改变页面大小的使用习惯。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值