局部性:

局部性分为时间局部性和空间局部性:Locality is typically described as having two distinct forms: temporal locality and spatial locality. In a program with good temporal locality, a memory location that is referenced once is likely to be referenced again multiple times in the near future. In a program with good spatial locality, if a memory location is referenced once, then the program is likely to reference a nearby memory location in the near future.

一个使用局部性的例子:

At the operating system level, the principle of locality allows the system to use the main memory as a cache of the most recently referenced chunks of the virtual address space. Similarly, the operating system uses main memory to cache the most recently used disk blocks in the disk file system.

CSAPP分两个方面说明了局部性的问题:

Locality of References to Program Data 和 Locality of Instruction Fetches

关于前者,CSAPP是举例说明了局部性的问题:

1 int sumvec(int v[N])
2 {
3 int i, sum = 0;
4
5 for (i = 0; i < N; i++)
6     sum += v[i];
7 return sum;
8 }

在这个例子里:

sum每次循环都会被访问一次,所以有好的时间局部性

v是一个接着一个地读取,空间局部性好,时间局部性差

Stride-1 reference patterns are a common and important source of spatial locality in programs. In general, as the stride increases, the spatial locality decreases.

关于取指令的局部性分析,举例:

 int sumarraycols(int a[M][N])
2 {
3 int i, j, sum = 0;
4
5 for (j = 0; j < N; j++)
6     for (i = 0; i < M; i++)
7         sum += a[i][j];
8 return sum;
9 }    

从取指的角度,这个函数时间局部性和空间局部性都很好,解释如下:

The instructions in the body of the for loop are executed in sequential memory order, and thus the loop enjoys good spatial locality. Since the loop body is executed multiple times, it also enjoys good temporal locality.

还顺带解释了指令和数据的区别:

An important property of code that distinguishes it from program data is that it is rarely modified at run time. While a program is executing, the CPU reads its instructions from memory. The CPU rarely overwrites or modifies these instructions.

关于locality的总结:

Programs that repeatedly reference the same variables enjoy good temporal locality(不断引用同一个变量的程序具有好的时间局部性)

For programs with stride-k reference patterns, the smaller the stride the better the spatial locality. Programs with stride-1 reference patterns have good spatial locality. Programs that hop around memory with large strides have poor spatial locality(步长越短,空间局部性越好)

Loops have good temporal and spatial locality with respect to instruction fetches. The smaller the loop body and the greater the number of loop iterations, the better the locality(取指的时候,循环的时间局部性和空间局部性很好,循环体越短,循环次数越多,局部性越好)

存储器的层次图:

值得一提的固态硬盘的位置:

As another example, solid state disks are playing an increasingly important role in the memory hierarchy, bridging the gulf between DRAM and rotating disk.

关于cold misses: An empty cache is sometimes referred to as a cold cache, and misses of this kind are called compulsory misses or cold misses. Cold misses are important because they are often transient events that might not occur in steady state, after the cache has been warmed up by repeated memory accesses

一种设计缓存的方法是利用哈希,使得k+1层的数据按照地址映射到k层的某个位置

working set是程序运行过程中访问的一个大小相对固定的缓存块的一部分

capacity misses: When the size of the working set exceeds the size of the cache, the cache will experience what are known as capacity misses. In other words, the cache is just too small to handle this particular working set.

那么,不同层次的缓存是由谁管理的呢?

The compiler manages the register file, the highest level of the cache hierarchy. It decides when to issue loads when there are misses, and determines which register to store the data in. The caches at levels L1, L2, and L3 are managed entirely by hardware logic built into the caches. In a system with virtual memory, the DRAM main memory serves as a cache for data blocks stored on disk, and is managed by a combination of operating system software and address translation hardware on the CPU. For a machine with a distributed file system such as AFS, the local disk serves as a cache that is managed by the AFS client process running on the local machine. In most cases, caches operate automatically and do not require any specific or explicit actions from the program.

转载于:https://www.cnblogs.com/geeklove01/p/9069296.html

存储器结构层次(二)相关推荐

  1. 计算机组成原理 存储器

    一.概述 1.存储器分类 按 存储介质 分: 半导体器件:分双极型(TTL)和 MOS 管两种 磁表面存储器:非易失性 磁芯存储器:非易失性,已淘汰 光盘:非易失性 按 存储方式 分: RAM  随机 ...

  2. 【沧海拾昧】微机原理:存储器系统

    #C0302 沧海茫茫千钟粟,且拾吾昧一微尘 --<沧海拾昧集>@CuPhoenix [阅前敬告] 沧海拾昧集仅做个人学习笔记之用,所述内容不专业不严谨不成体系 如有问题定为本集记录有谬, ...

  3. 【51单片机】AT24C02存储器(I²C总线)/DS18B20温度传感器(单总线)

    目录 一.AT24C02存储器 1.AT24C02存储器介绍 2.存储器简化模型 3.AT24C02存储器原理图 二.I²C总线 1.I²C总线的介绍 2.I²C电路 3.I²C时序图 3.1I²C开 ...

  4. 51单片机存储器原理

    一. 80C51单片机的存储器结构 80C51单片机的存储器包括两类:程序存储器和数据存储器. 程序存储器用来存放用户程序和常用的表格.常数,采用只读存储器(ROM)作为程序存储器. 数据存储器用来存 ...

  5. 计算机存储器四上,第一课 计算机的存储器(四上).doc

    第一课 计算机的存储器(四上) 攀枝花市东区教育信息技术中心 龙慧琼 一.教学内容分析 本课是四川省义务教育课程改革实验教科书小学<信息技术>四年级上册的<第一课 计算机的存储器&g ...

  6. 【瑞萨RA_FSP】常用存储器介绍

    文章目录 一.存储器种类 二. RAM存储器 1. DRAM 1.1 SDRAM 1.2 DDR SDRAM 2. SRAM 3. DRAM与SRAM的应用场合 三.非易失性存储器 1. ROM存储器 ...

  7. Computer OS系统基本原理

    Computer OS系统基本原理 第一章 绪论(考概念) 什么是OS? o 操作系统是一组控制和管理计算机软硬件资源.合理地对各类作业进行调度以及方便用户使用的程序集合. o 操作系统是位于硬件层( ...

  8. 20145223 《信息安全系统设计基础》课程总结

    20145223 <信息安全系统设计基础>课程总结 每周作业链接汇总 •第0周作业: •简要内容:学会了安装虚拟机VirtualBox和Linux系统,预习了Linux基础入门,对课程的内 ...

  9. 2018-2019-1 20189215 书籍速读

    书籍.课程速读提问:<文献管理与信息分析>.<构建之法>.<深入理解计算机系统>.<从问题到程序>还未读. <文献管理与信息分析> 本课程主 ...

最新文章

  1. 生产上如何设置线程池参数?拒绝策略怎么配?|| Executors 中 JDK 给你提供了,为什么不用??
  2. NYOJ 303 序号转换 数学题
  3. codelite 教程
  4. machine learning for hacker记录(3) 贝叶斯分类器
  5. 基于CentOS7安装CM
  6. 彻底解决 Gson 将 int 转换为 double 的问题
  7. 电场在计算机专业的应用,电磁场毕业论文题目范文 数值计算和教学理论方面本科论文范文8000字...
  8. win11拉伸屏幕_win11系统出现拉伸屏幕问题修复办法
  9. win7计算机怎么重置,win7系统的电脑如何重置 win7重置电脑的方法
  10. 魔板游戏java_Java魔板游戏完整代码及注释
  11. 理解 Rack 应用及其中间件
  12. 【技术分享】使用opencv进行火焰分割
  13. 【C++入门】烦人的引用
  14. 温度传感器DS18B20的使用
  15. discuz的htm模板代码分析
  16. 带分数(全排列详解)
  17. 【C语言】 求水仙花数
  18. 西电毕业论文Latex排版教程
  19. VS2013配置VTK7.1.1
  20. mysql使用教程图文_MySQL使用教程图文详解

热门文章

  1. 计算机检索的优点,专利检索与分析系统拥有哪些优势?
  2. redis消息队列写入mysql_redis怎么实现将消息队列持久化到数据库中?
  3. kettle读取不到oracle,kettle链接Oracle数据库,百试不爽!
  4. http和dubbo的区别_(转载)Dubbo 接口是什么? 与http 接口有什么区别
  5. vscode 格式化某一段代码_VSCode格式化代码功能失效的bug解决方法
  6. redis java切片_jedis 单点配置
  7. 虚拟服务器的运行原理,虚拟机复制的工作原理
  8. Ubuntu解决开机屏幕默认亮度偏低问题
  9. Python OpenCV分水岭算法分割和提取重叠或有衔接的图像中的对象
  10. OpenCV中的快速特征检测——FAST(Features from Accelerated Segment Test)