cpu的高速缓存何时被刷新回主存?

如果您刚刚开始了解多核cpu、缓存、缓存一致性和内存的工作原理,那么一开始可能会有点困惑。有鉴于此,今天的超级用户问答帖子回答了一位好奇的读者的问题。...

cpu的高速缓存何时被刷新回主存?

如果您刚刚开始了解多核cpu、缓存、缓存一致性和内存的工作原理,那么一开始可能会有点困惑。有鉴于此,今天的超级用户问答帖子回答了一位好奇的读者的问题。

今天的问答环节是由SuperUser提供的,SuperUser是Stack Exchange的一个分支,是一个由社区驱动的问答网站分组。

问题

超级用户阅读器CarmeloS想知道CPU的缓存何时被刷新回主内存:

If I have a CPU with two cores and each core has its own L1 cache, is it possible that Core1 and Core2 both cache the same part of memory at the same time? If it is possible, what will the value of main memory be if both Core1 and Core2 have edited their values in cache?

CPU的高速缓存何时被刷新回主存?

答案

超级用户贡献者davidschwartz、sleske和Kimberly W为我们提供了答案。首先,大卫·施瓦茨:

If I have a CPU with two cores and each core has its own L1 cache, is it possible that Core1 and Core2 both cache the same part of memory at the same time?

Yes, performance would be terrible if this was not the case. C***ider two threads running the same code. You want that code in both L1 caches.

If it is possible, what will the value of main memory be if both Core1 and Core2 have edited their values in cache?

The old value will be in main memory, which will not matter since neither core will read it. Before ejecting a modified value from cache, it must be written to memory. Typically, some variant of the MESI protocol is used. In the traditional implementation of MESI, if a value is modified in one cache, it cannot be present at all in any other cache at that same level.

接着是斯莱斯克的回答:

Yes, having two caches cache the same memory region can happen and is actually a problem that occurs a lot in practice. There are various soluti***, for example:

  • The two caches can communicate to make sure they do not disagree
  • You can have some sort of supervisor which monitors all caches and updates them accordingly
  • Each processor monitors the memory areas that it has cached, and when it detects a write, it throws out its (now invalid) cache

The problem is called cache coherency and the Wikipedia article on the topic has a nice overview of the problem and possible soluti***.

金伯利W的最终答案是:

To answer the question in your post’s title, it depends on what the caching protocol is. If it is write-back, the cache will only be flushed back to main memory when the cache controller has no choice but to put a new cache block in already occupied space. The block that previously occupied the space is removed and its value is written back to main memory.

The other protocol is write-through. In that case, anytime the cache block is written on level n, the corresponding block on level n+1 is updated. It is similar in concept to filling out a form with carbon paper underneath; whatever you write on top is copied on the sheet below. This is slower because it obviously involves more writing operati***, but the values between caches are more c***istent. In the write-back scheme, only the highest level cache would have the most up-to-date value for a particular memory block.


有什么要补充的解释吗?在评论中发出声音。想从其他精通技术的Stack Exchange用户那里了解更多答案吗?在这里查看完整的讨论主题。

图片来源:Lemsipmatt(Flickr)

  • 发表于 2021-04-08 07:03
  • 阅读 ( 210 )
  • 分类:互联网

你可能感兴趣的文章

高速缓存(cache memory)和虚拟内存(virtual memory)的区别

...缓存内存和虚拟内存的区别在于它们的用途和物理存在。高速缓冲存储器是一种用来提高主存存取时间的存储器。它位于CPU和主内存之间,可以有多个级别的缓存,如L1、L2和L3。用于高速缓存的硬件类型比用于主存的RAM(随机存...

  • 发布于 2020-10-29 11:12
  • 阅读 ( 865 )

存储器(sram)和德拉姆(dram)的区别

...,速度比容量更为关键。SRAM最突出的用途是在处理器的高速缓存中,在高速缓存中,速度是非常重要的,低功耗意味着需要消耗的热量更少。甚至硬盘、光驱和其他需要高速缓存或缓冲区的设备也使用SRAM模块。 Summary:1. SRAM 是...

  • 发布于 2021-06-22 13:07
  • 阅读 ( 355 )

隐藏物(cache)和缓冲器(buffer)的区别

...备的数据。这样计算机就可以执行其他任务。另一方面,高速缓存是一种高速存储区域,它可以是主存储器的一部分,也可以是硬盘等其他独立存储区域的一部分。这两种缓存方法分别称为内存缓存和磁盘缓存。 为了确保高速...

  • 发布于 2021-06-23 20:36
  • 阅读 ( 248 )

主存储器(primary memory)和辅助存储器(secondary memory)的区别

...的(of primary) vs. 辅助存储器(secondary memory) 计算机内存与高速缓存一起分为主内存和次内存。主存储器是计算机的主存储器或内部存储器,用来存储经常使用的数据和指令。它提供快速的内存访问,因为它的易失性使得处理单元...

  • 发布于 2021-06-25 06:42
  • 阅读 ( 581 )

主存储器(primary storage)和辅助存储器(secondary storage)的区别

...电路中,以便以最小或无延迟的方式立即访问。它是一种高速数据存储介质,通过内存总线直接连接到处理单元,允许活动程序与处理器交互。简单地说,主存储器是指提供对数据或信息的快速有效访问的内部存储设备。但是,...

  • 发布于 2021-06-25 06:44
  • 阅读 ( 473 )

存储器(sram)和德拉姆(dram)的区别

...何复杂的硬件电路。SRAM的主要优点是速度快。Cache是一种高速存储器,它保存CPU经常使用的数据。SRAM用于缓存。由于SRAM的速度比DRAM快,所以它对数据的访问时间最短。 Figure 1: SRAM Cell SRAM用于个人计算机、路由器、外围设备、CP...

  • 发布于 2021-06-30 20:53
  • 阅读 ( 502 )

隐藏物(cache)和猛撞(ram)的区别

...AM是一种计算设备,用于存储CPU当前使用的数据和程序。 高速缓存是计算机中一个更小、更快的内存组件。它保存CPU常用的数据副本。另一方面,RAM是存储当前使用的程序和数据的主存储器。它帮助CPU在最短的时间内访问数据。...

  • 发布于 2021-06-30 23:47
  • 阅读 ( 293 )

登记(register)和主存储器(main memory)的区别

...件,它存储CPU当前使用的数据和程序。 寄存器是CPU中的高速内存位置。它允许CPU暂时存储数据以供处理。可用寄存器的数量可以随计算机的不同而变化。寄存器的总数有助于提高CPU的性能。另一方面,主存储器也称为随机存取...

  • 发布于 2021-06-30 23:50
  • 阅读 ( 708 )

存储器(sram)和德拉姆(dram)的区别

...DR3)。不能长期存放。 CPU中的二级和三级缓存 Typical sizes 智能**和平板电脑为1GB至2GB;笔记本电脑4GB至16GB 1MB到16MB Place Where Present 出现在...

  • 发布于 2021-07-07 10:13
  • 阅读 ( 239 )

主存储器(primary memory)和辅助存储器(secondary memory)的区别

...储在外部硬件设备中,如硬盘、软盘等。分部它可以分为高速缓存和随机存取存储器(RAM)。它们没有这样的分区,是永久存储设备,如CD、DVD等。速度它比辅助存储器快。速度相对较慢。存储的数据它保存计算机当前正在使用...

  • 发布于 2021-07-10 05:53
  • 阅读 ( 505 )
atst04
atst04

0 篇文章

相关推荐