当前位置: 首页 > 编程日记 > 正文

存储器结构层次(二)

局部性:

局部性分为时间局部性和空间局部性: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

相关文章:

python 核心编程 第十三章

python面对对象 类和实例&#xff1a;类是对象的定义&#xff0c;实例是真真的实物。 创建一个类&#xff1a; class AddrBookEnttry(object):def __init__(self, nm, ph):self.name nmself.phone phprint"Created instance for:", self.namedef updatePhone(self,…

python写一个文件下载器_Python3使用TCP编写一个简易的文件下载器

原标题&#xff1a;Python3使用TCP编写一个简易的文件下载器利用Python3来实现TCP协议&#xff0c;和UDP类似。UDP应用于及时通信&#xff0c;而TCP协议用来传送文件、命令等操作&#xff0c;因为这些数据不允许丢失&#xff0c;否则会造成文件错误或命令混乱。下面代码就是模拟…

提取Jar2Exe源代码,JavaAgent监控法

链客&#xff0c;专为开发者而生&#xff0c;有问必答&#xff01; 此文章来自区块链技术社区&#xff0c;未经允许拒绝转载。 最近遇见一个麻烦&#xff0c;明明知道是java写的小软件&#xff0c;但是打包成了exe&#xff0c;木得办法&#xff0c;之前打包的都有缓存能在TEMP…

并发编程之多进程

一 multiprocessing模块介绍 python中的多线程无法利用多核优势&#xff0c;如果想要充分地使用多核CPU的资源&#xff08;os.cpu_count()查看&#xff09;&#xff0c;在python中大部分情况需要使用多进程。Python提供了multiprocessing。 multiprocessing模块用来开启子进…

x9此计算机上没有hasp_mastercam x9安装步骤

大家好&#xff0c;我是时间财富网智能客服时间君&#xff0c;上述问题将由我为大家进行解答。mastercam x9安装步骤是&#xff1a;1、首先&#xff0c;先下载好mastercam软件&#xff0c;下载安装包的大小为3.01G&#xff0c;双击打开setup.exe安装文件&#xff0c;然后再安装…

bitcoinj开发环境搭建

链客&#xff0c;专为开发者而生&#xff0c;有问必答&#xff01; 此文章来自区块链技术社区&#xff0c;未经允许拒绝转载。 bitcoinj开发包是一个Java版本的比特币协议实现&#xff0c;使用bitcoinj就可以实现钱包管理和交易的发送与接收&#xff0c;而无须本地安装bitcoin…

static关键字用法

static关键字 1.修饰成员变量 在我们平时的使用当中&#xff0c;static最常用的功能就是修饰类的属性和方法&#xff0c;让他们成为类的成员属性和方法&#xff0c;我们通常将用static修饰的成员称为类成员或者静态成员&#xff0c;这句话挺起来都点奇怪&#xff0c;其实这是相…

swift x输入流_SwiftUI 探索 - 状态和数据流

SwiftUI是iOS13新出的声明式UI框架&#xff0c;将会完全改变以前命令式操作UI的开发方式。此文章主要介绍SwiftUI中状态管理的方式。可变状态State与React和Flutter中的State类似&#xff0c;只不过React和Flutter中需要显式调用setState方法。在SwiftUI 中直接修改State属性值…

qt 控件 背景色 透明 除去边框

在调试ui的时候&#xff0c;需要将背景色变为透明&#xff0c;与母控件的颜色一致&#xff0c;并且除去边框。 参考链接&#xff1a; http://www.qtcentre.org/threads/12148-how-QTextEdit-transparent-to-his-parent-window 除去背景色&#xff0c;使透明。ui->textBrowse…

A Strange Bitcoin Transaction

链客&#xff0c;专为开发者而生&#xff0c;有问必答&#xff01; 此文章来自区块链技术社区&#xff0c;未经允许拒绝转载。 在之前的谈谈比特币的地址安全问题这篇文章中&#xff0c;我们谈到一个名为”LBC”的项目&#xff0c;这个项目通过暴力碰撞企图打捞到一些什么东西…

Jsoncpp 使用方法解析

Jsoncpp是目前比较好用的开源Json解析库&#xff0c;现在总结一下它的使用方法&#xff0c;理解&#xff0c;以供以后查阅。 在引入Jsoncpp的时候我们看到Jsoncpp里边的常用的cpp文件&#xff0c;有json_reader.cpp,json_value.cpp,json_writer.cpp, 其中&#xff1a; json_val…

tomcat限速_WEB服务的下载限速(二)(限速模块安装与配置)

一、准备工作1、下载mod_bw-0.92.tgz2、安装httpd-develyum install httpd-devel二、安装限速模块tar -xvf mod_bw-0.92.tgzapxs -c -i -a mod_bw.c三、配置apachevim /usr/local/apache/conf/httpd.conf查看是否已加载 LoadModule bw_module modules/mod_bw.so如果没…

EntityFrameworkCore 安装

映射现有&#xff08;多个&#xff09;数据库&#xff1a; 安装Microsoft.EntityFrameworkCore最新版本Tools -> NuGet Package Manager -> Package Manager Console 分别输入&#xff1a; Scaffold-DbContext "Server.;DatabaseSxh;Trusted_ConnectionTrue;" …

python神秘的魔法函数_Python魔法函数

1.什么是魔法函数魔法函数即Python类中以__(双下划线)开头&#xff0c;以__(双下划线)结尾的函数&#xff0c;Python提供的函数&#xff0c;可让咱们随意定义类的特性示例&#xff1a;class Company(object):def __init__(self, employee_list):self.employee employee_listde…

HDU-4738-Caocao's Bridges(tarjan)

转载于:https://www.cnblogs.com/GrowingJlx/p/6642692.html

博客园美化技巧汇总

首先得有js权限 1.1 页脚js代码 <script type"text/javascript"> /*功能&#xff1a;生成博客目录的JS工具测试&#xff1a;IE8&#xff0c;火狐&#xff0c;google测试通过zhang_derek2018-01-03 */ var BlogDirectory {/*获取元素位置&#xff0c;距浏览器左…

数据事务四种隔离机制和七种传播行为

数据事务四种隔离机制和七种传播行为 一、隔离级别&#xff1a; 数据库事务的隔离级别有4个&#xff0c;由低到高依次为Read uncommitted、Read committed、Repeatable read、Serializable&#xff0c;这四个级别可以逐个解决脏读、不可重复读、幻读这几类问题。 &#xff11;.…

vue注册新节点_vue怎么重新组装slots节点

在后台列表中通常会有比较多的操作按钮 过多的按钮影响布局 也影响操作 因此想通过vue的组件来控制显示的按钮个数 多余的按钮自动被收进一个特殊的 更多 按钮里面&#xff0c;效果图&#xff1a;组件定义&#xff1a;Vue.component(button-groups, {render(createElement) {re…

什么是EOS?

链客&#xff0c;专为开发者而生&#xff0c;有问必答&#xff01; 此文章来自区块链技术社区&#xff0c;未经允许拒绝转载。 关于EOS有很多炒作。2017年5月&#xff0c;EOS的创始人丹•拉莫(Dan Larimer)在纽约宣布这一消息时&#xff0c;一幅巨大的巨型屏幕广告在时代广场上…

【GDKOI2016Day1T1-魔卡少女】【拆位】线段树维护区间内所有连续子区间的异或和...

题意&#xff1a;给出N个数&#xff0c;M个操作。操作有修改和询问两种&#xff0c;每次修改将一个数改成另一个数&#xff0c;每次询问一个区间的所有连续子区间的异或和。n,m<100000,ai<1000 题解&#xff1a; 当年&#xff08;其实也就是今年&#xff09;做不出来的题…

用composer安装laravel-bjyblog

前面讲了两行命令composer的安装&#xff0c;现在我们来操作一下composer安装基于laravel的博客laravel-bjyblog。测试环境是linux&#xff0c;bt面板&#xff0c;php7.2安装扩展fileinfo/opcache/redis/imagemagick/imap/exif&#xff0c;禁用 proc_open 函数 下面开始安装&am…

微信小程序多项选择器_微信小程序三级联动之多列选择器

有些时候&#xff0c;三级联动业务场景并不只是全国地区选择&#xff0c;可能还涉及到自定义分类的三级联动&#xff0c;这时就需要使用微信的多列选择器。如果只是一列字段&#xff0c;或者每次拖动一次都去服务端取&#xff0c;会比较容易。 如果想一次定义好json,关联数据相…

eosjs-ecc中文文档

链客&#xff0c;专为开发者而生&#xff0c;有问必答&#xff01; 此文章来自区块链技术社区&#xff0c;未经允许拒绝转载。 eosjs-ecc是eos官方处理密钥和签名的javascript开发包。访问地址&#xff1a;eosjs-ecc中文手册。 eosjs-ecc安装 nodejs环境下&#xff0c;使用N…

rocketmq 组监听_最全的RocketMQ学习指南,程序员必备的中间件技能

一、简介RocketMq是阿里开发出来的一个消息中间件&#xff0c;后捐献给Apache。官网上是这样介绍的&#xff1a; Apache RocketMQ™ is a unified messaging engine, lightweight data processing platform.RocketMQ是一个统一的处理消息引擎&#xff0c;轻量级的数据处理平台。…

【刷题】BZOJ 4516 [Sdoi2016]生成魔咒

Description 魔咒串由许多魔咒字符组成&#xff0c;魔咒字符可以用数字表示。例如可以将魔咒字符 1、2 拼凑起来形成一个魔咒串 [1,2]。 一个魔咒串 S 的非空字串被称为魔咒串 S 的生成魔咒。 例如 S[1,2,1] 时&#xff0c;它的生成魔咒有 [1]、[2]、[1,2]、[2,1]、[1,2,1] 五种…

jQuery的文档操作方法

jQuery 文档操作方法 这些方法对于 XML 文档和 HTML 文档均是适用的&#xff0c;除了&#xff1a;html()。 方法描述addClass()向匹配的元素添加指定的类名。after()在匹配的元素之后插入内容。append()向匹配元素集合中的每个元素结尾插入由参数指定的内容。appendTo()向目标结…

原 EOS智能合约开发入门

链客&#xff0c;专为开发者而生&#xff0c;有问必答&#xff01; 此文章来自区块链技术社区&#xff0c;未经允许拒绝转载。 EOS智能合约的开发需要使用llvm和abigen来生成abi文件。 为此eos提供了一个 名为eosiocpp的工具。 在这篇文章中&#xff0c;我们介绍如何使用这个工…

python安装虚拟环境virtualenv

虚拟环境 虚拟环境是一个将不同项目所需求的依赖分别放在独立的地方的一个工具&#xff0c;它给这些工程创建虚拟的Python环境。它解决了“项目X依赖于版本1.x&#xff0c;而项目Y需要项目4.x”的两难问题&#xff0c;而且使你的全局site-packages目录保持干净和可管理。 比如&…

可变分区存储管理实验报告总结_操作系统实验报告-可变分区存储管理方式的内存分配回收...

一&#xff0e;实验目的(1)深入了解可变分区存储管理方式的内存分配回收的实现。二&#xff0e;实验内容编写程序完成可变分区存储管理方式的内存分配回收&#xff0c;要求有内存空间分配表&#xff0c;并采用最优适应算法完成内存的分配与回收。三&#xff0e;实验原理在可变分…

ubuntu/linuxmint如何添加和删除PPA源

【添加】 1、sudo add-apt-repository ppa:user/ppa-name 2、sudo apt-get update (然后再安装软件sudo apt-get install <package-name>或更新软件sudo apt-get upgrade) 【删除】 1、cd /etc/apt/source.list.d/ 2、sudo rm <ppa-name> 转载于:https://www.cnblo…