Memory Hierarchy-计算机各级存储器速度对比

这篇文章是抄自亚嵌的教材,觉得不错,分享一下。

由于硬件技术的限制,我们可以制造出容量很小但很快的存储器,也可以制造出容量很大但很慢的存储器,但不可能两边的好处都占着,不可能制造出访问速度又快容量又大的存储器。因此,现代计算机都把存储器分成若干级,称为Memory Hierarchy,按照离CPU由近到远的顺序依次是CPU寄存器、Cache、内存、硬盘,越靠近CPU的存储器容量越小但访问速度越快,下图给出了各种存储器的容量和访问速度的典型值。

 

存储器类型

位于哪里

存储容量

半导体工艺

访问时间

如何访问

CPU寄存器

位于CPU执行单元中。

CPU寄存器通常只有几个到几十个,每个寄存器的容量取决于CPU的字长,所以一共只有几十到几百字节。

“寄存器”这个名字就是一种数字电路的名字,它由一组触发器(Flip-flop)组成,每个触发器保存一个Bit的数据,可以做存取和移位等操作。计算机掉电时寄存器中保存的数据会丢失。

寄存器是访问速度最快的存储器,典型的访问时间是几纳秒。

使用哪个寄存器,如何使用寄存器,这些都是由指令决定的。

Cache

和MMU一样位于CPU核中。

Cache通常分为几级,最典型的是如上图所示的两级Cache,一级Cache更靠近CPU执行单元,二级Cache更靠近物理内存,通常一级Cache有几十到几百KB,二级Cache有几百KB到几MB。

Cache和内存都是由RAM(RandomAccessMemory)组成的,可以根据地址随机访问,计算机掉电时RAM中保存的数据会丢失。不同的是,Cache通常由SRAM(StaticRAM,静态RAM)组成,而内存通常由DRAM(DynamicRAM,动态RAM)组成。DRAM电路比SRAM简单,存储容量可以做得更大,但DRAM的访问速度比SRAM慢。

典型的访问时间是几十纳秒。

Cache缓存最近访问过的内存数据,由于Cache的访问速度是内存的几十倍,所以有效地利用Cache可以大大提高计算机的整体性能。一级Cache是这样工作的:CPU执行单元要访问内存时首先发出VA,Cache利用VA查找相应的数据有没有被缓存,如果Cache中有就不需要访问物理内存了,是读操作就直接将Cache中的数据传给CPU寄存器,是写操作就直接在Cache中改写数据;如果Cache中没有,就去物理内存中取数据,但并不是要哪个字节就取哪个字节,而是把相邻的几十个字节都取上来缓存着,以备下次用到,这称为一个Cache Line,典型的CacheLine大小是32~256字节。如果计算机还配置了二级缓存,则在访问物理内存之前先用PA去二级缓存中查找。一级缓存是用VA寻址的,二级缓存是用PA寻址的,这是它们的区别。Cache所做的工作是由硬件自动完成的,而不是像寄存器一样由指令决定先做什么后做什么。

内存

位于CPU外的芯片,与CPU通过地址和数据总线相连。

典型的存储容量是几百MB到几GB。

由DRAM组成,详见上面关于Cache的说明。

典型的访问时间是几百纳秒。

内存是通过地址来访问的,但是在启用MMU的情况下,程序指令中的地址是VA,而访问内存用的是PA,并无直接关系,这种情况下内存的分配和使用由操作系统通过修改MMU的映射项来协调。

硬盘

位于设备总线上,并不直接和CPU相连,CPU通过设备总线的控制器访问硬盘。

典型的存储容量是几百GB。

硬盘由磁性介质和磁头组成,访问硬盘时存在机械运动,磁头要移动,磁性介质要旋转,机械运动的速度很难提高到电子的速度,所以访问速度很受限制。但是保存在硬盘上的数据掉电后不会丢失。

典型的访问时间是几毫秒,是寄存器的106倍。

由驱动程序操作设备总线控制器去访问。由于硬盘的访问速度较慢,操作系统通常在一次从硬盘上读几个页面(典型值是4KB)到内存中缓存起来,如果这些数据后来都被程序访问到了,那么这一次硬盘访问的时间就可以分摊(Amortize)给多次数据访问了。

 

 

 

  • 5
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Memory hierarchy management refers to the process of organizing and managing the different levels of memory in a computer system, including the cache, main memory, and secondary storage. The goal of memory hierarchy management is to optimize the use of memory resources and improve system performance. This is achieved through a combination of hardware and software techniques that help to minimize the amount of time it takes to access data from memory. At the lowest level of the memory hierarchy is the main memory, which is typically implemented using dynamic random-access memory (DRAM) chips. Main memory is fast but expensive, so it is relatively small compared to the amount of data that needs to be stored in a typical computer system. To make up for the limited capacity of main memory, computer systems use caching techniques to store frequently accessed data in a faster, smaller cache memory. The cache is typically implemented using static random-access memory (SRAM) chips, which are much faster than DRAM but more expensive. Memory hierarchy management involves coordinating the movement of data between the different levels of the memory hierarchy, based on factors such as the frequency of access, the size of the data, and the available memory resources. This is done using algorithms such as cache replacement policies, which determine which data should be evicted from the cache to make room for new data. Other memory management techniques include virtual memory, which allows the operating system to use secondary storage as an extension of main memory, and memory compression, which compresses data in memory to free up space for additional data. Overall, memory hierarchy management is critical to the performance and efficiency of modern computer systems, and requires a careful balance of hardware and software optimizations to achieve optimal results.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值