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
  • 閱讀 ( 41 )
  • 分類:網際網路

你可能感興趣的文章

快取記憶體(cache memory)和虛擬記憶體(virtual memory)的區別

快取記憶體與虛擬記憶體 快取記憶體和虛擬記憶體的區別在於它們的用途和物理存在。高速緩衝儲存器是一種用來提高主存存取時間的儲存器。它位於CPU和主記憶體之間,可以有多個級別的快取,如L1、L2和L3。用於快取記憶...

  • 發佈於 2020-10-29 11:12
  • 閲讀 ( 77 )

什麼使英特爾酷睿i9成為最快的處理器?你應該買它嗎?

... 重新平衡快取層次結構 ...

  • 發佈於 2021-03-14 04:57
  • 閲讀 ( 48 )

7種有效的工具,可在windows上提高硬碟效能

...使用的Windows工具是裝置管理器。您可以使用它來確保寫快取已開啟。 ...

  • 發佈於 2021-03-18 01:20
  • 閲讀 ( 49 )

mac清潔應用程式一文不值嗎?需要考慮的7個因素

...行各種維護任務的快速而簡單的方法。其中包括透過刪除快取、日誌和其他不需要的檔案來釋放磁碟空間。他們還應該刪除未安裝的應用程式的殘餘,修復啟動問題,糾正磁碟問題,等等。 ...

  • 發佈於 2021-03-21 12:01
  • 閲讀 ( 45 )

英特爾酷睿i3與i5與i7:您應該購買哪種cpu?

... 英特爾酷睿i7與i5與i3:快取大小 ...

  • 發佈於 2021-03-23 11:33
  • 閲讀 ( 49 )

什麼是amd智慧存取儲存器,它能讓遊戲變得更好嗎?

... amd無限快取 ...

  • 發佈於 2021-03-27 03:51
  • 閲讀 ( 62 )

如何從linux終端檢查記憶體使用情況

...憶體、已用記憶體、可用記憶體、共享記憶體、緩衝區/快取和可用記憶體。它還顯示配置的交換空間總量,以及已使用和可用的交換空間量。 在我們的示例中,我們將使用-m(mebibytes)選項。但是,也可以使用-b(位元組)、-k...

  • 發佈於 2021-04-02 13:03
  • 閲讀 ( 50 )

如何在linux上使用free命令

...享:tmpfs檔案系統使用的記憶體。 Buff/cache:用於緩衝和快取的記憶體。 可用:這是對可用於處理來自應用程式、計算機內任何其他功能軟體(如圖形桌面環境和Linux命令)的記憶體請求的記憶體的估計。 對於交換行,列為: ...

  • 發佈於 2021-04-02 19:12
  • 閲讀 ( 47 )

linux上的交換是什麼?(以及如何更改)

...獲得指導。通常,這些應用程式都有自己專門設計的檔案快取和記憶體管理例程,您最好依賴這些例程。軟體供應商可能會根據機器規格和工作負載建議Linux交換值。 對於擁有最新硬體的普通桌面使用者來說?保持原樣。 如何...

  • 發佈於 2021-04-02 20:43
  • 閲讀 ( 52 )

chrome的“標籤凍結”將如何節省cpu和電池

...憶體“非常低”的時候才會丟棄tab的原因,最好使用RAM來快取。但是,自動丟棄一個標籤並快速重新開啟它比強制Chrome使用者手動新增書籤和關閉標籤要好。 當一個選項卡被丟棄時,它的程序實際上會從Chrome的內建工作管理員...

  • 發佈於 2021-04-03 01:49
  • 閲讀 ( 52 )
atst04
atst04

0 篇文章

作家榜

  1. admin 0 文章
  2. 孫小欽 0 文章
  3. JVhby0 0 文章
  4. fvpvzrr 0 文章
  5. 0sus8kksc 0 文章
  6. zsfn1903 0 文章
  7. w91395898 0 文章
  8. SuperQueen123 0 文章

相關推薦