Cache placement policies: Difference between revisions

Content deleted Content added
It's not clear why removal of the detailed information about placement policies is an improvement.
Rescuing 1 sources and tagging 0 as dead.) #IABot (v2.0.9.5
 
(12 intermediate revisions by 9 users not shown)
Line 1:
{{Short description|Design decisions affecting processor cache speeds and sizes}}
{{Distinguish|cache replacement policies}}
A'''Cache [[CPUplacement cache]]policies''' isare policies that determine where a particular memory whichblock holdscan thebe recentlyplaced utilizedwhen datait bygoes theinto processora [[CPU cache]]. A block of memory cannot necessarily be placed randomlyat an arbitrary ___location in the cache; andit may be restricted to a singleparticular [[CPU cache#Cache entries|cache line]] or a set of cache lines<ref name=":0">{{Cite web|url=https://cseweb.ucsd.edu/classes/su07/cse141/cache-handout.pdf|title=The Basics of Cache}}</ref> by the '''cache's placement policy'''.<ref>{{Cite web |title=Cache Placement Policies |url=http://web.cs.iastate.edu/~prabhu/Tutorial/CACHE/bl_place.html |titlearchive-url=Cachehttps://web.archive.org/web/20200221213947/http://web.cs.iastate.edu/~prabhu/Tutorial/CACHE/bl_place.html Placement|archive-date=Feb Policies21, 2020 |url-status=dead}}</ref><ref>{{Cite web|url=http://fourier.eng.hmc.edu/e85_old/lectures/memory/node4.html|title=Placement Policies|archive-url=https://web.archive.org/web/20200814000302/http://fourier.eng.hmc.edu/e85_old/lectures/memory/node4.html|archive-date=August 14, 2020|url-status=dead}}</ref> In other words, the cache placement policy determines where a particular memory block can be placed when it goes into the cache.
 
There are three different policies available for placement of a memory block in the cache: direct-mapped, fully associative, and set-associative. Originally this space of cache organizations was described using the term "congruence mapping".<ref>{{Cite journal|last=Mattson|first=R.L.|author1-link=Richard Mattson|last2=Gecsei|first2=J.|last3=Slutz|first3=D. R.|last4=Traiger|first4=I|date=1970|title= Evaluation Techniques for Storage Hierarchies|journal=IBM Systems Journal|volume=9|issue=2|pages=78–117|doi=10.1147/sj.92.0078}}</ref>
Line 20:
* This placement policy is power efficient as it avoids the search through all the cache lines.
* The placement policy and the [[CPU cache#Replacement policies|replacement policy]] is simple.
* ItSimple requiresand cheaplow-cost hardware can be used, as only one tag needs to be checked at a time.
 
=== Disadvantage ===
* It has lower cache hit rate, as there is only one cache line available in a set. Every time a new memory is referenced to the same set, the cache line is replaced, which causes conflict miss.<ref>{{Cite web|url=http://meseec.ce.rit.edu/eecc551-winter2001/551-1-30-2002.pdf|title=Cache Miss Types|access-date=2016-10-24|archive-date=2016-11-30|archive-url=https://web.archive.org/web/20161130184519/http://meseec.ce.rit.edu/eecc551-winter2001/551-1-30-2002.pdf|url-status=dead}}</ref>
 
=== Example ===
Line 48:
 
=== To place a block in the cache ===
* The cache line is selected based on the [[CPU cache#Flag bits|valid bit]]<ref name=":0" /> associated with it. If the valid bit is 0, the new memory block can be placed in the cache line, else it has to be placed in another cache line with valid bit 0.
* If the cache is completely occupied then a block is evicted and the memory block is placed in that cache line.
* The eviction of memory block from the cache is decided by the [[CPU cache#Replacement policies|replacement policy]].<ref>{{Cite web|url=http://www.cs.umd.edu/class/sum2003/cmsc311/Notes/Memory/fully.html|title=Fully Associative Cache|archive-url=https://web.archive.org/web/20171224054857/http://www.cs.umd.edu/class/sum2003/cmsc311/Notes/Memory/fully.html|archive-date=December 24, 2017|url-status=dead}}</ref>
 
=== To search a word in the cache ===
* The Tag field of the memory address is compared with tag bits associated with all the cache lines. If it matches, the block is present in the cache and is a cache hit. If it doesn'tdoes not match, then it's is a cache miss and has to be fetched from the lower memory.
* Based on the Offset, a byte is selected and returned to the processor.
[[File:Fully-Associative Cache Snehal Img.png|thumb|513x513px|Fully associative cache]]
Line 63:
 
=== Disadvantages ===
* The placement policy is power hungry as itthe comparison circuitry has to iteraterun over the entire cache set to locate a block.
* The placement policy is slow as it takes time to iterate through all the lines.{{Disputed inline|talk=Talk:Cache placement policies#Advantages/disadvantages of the fully associative cache wrong?|date=June 2022}}
* The placement policy is power hungry as it has to iterate over entire cache set to locate a block.
* The most expensive of all methods, due to the high cost of associative-comparison hardware.
 
Line 94 ⟶ 93:
=== To locate a word in the cache ===
* The set is determined by the index bits derived from the address of the memory block.
* The tag bits are compared with the tags of all cache lines present in selected set. If the tag matches any of the cache lines, it is a cache hit and the appropriate line is returned. If the tag doesn'tdoes not match any of the lines, then it is a cache miss and the data is requested from next level in the memory hierarchy.
 
=== Advantages ===
Line 122 ⟶ 121:
 
== Two-way skewed associative cache ==
Other schemes have been suggested, such as the ''skewed cache'',<ref name="Seznec">{{cite journal|author=André Seznec|author-link=André Seznec|year=1993|title=A Case for Two-Way Skewed-Associative Caches|journal=ACM SIGARCH Computer Architecture News|volume=21|issue=2|pages=169–178|doi=10.1145/173682.165152|doi-access=free}}</ref> where the index for way 0 is direct, as above, but the index for way 1 is formed with a [[hash function]]. A good hash function has the property that addresses which conflict with the direct mapping tend not to conflict when mapped with the hash function, and so it is less likely that a program will suffer from an unexpectedly large number of conflict misses due to a pathological access pattern. The downside is extra latency from computing the hash function.<ref name="CK">{{cite web|url=http://www.stanford.edu/class/ee282/08_handouts/L03-Cache.pdf|title=Lecture 3: Advanced Caching Techniques|author=C. Kozyrakis|author-link=Christos Kozyrakis|archive-url=https://web.archive.org/web/20120907012034/http://www.stanford.edu/class/ee282/08_handouts/L03-Cache.pdf|archive-date=September 7, 2012|url-status=dead}}</ref> Additionally, when it comes time to load a new line and evict an old line, it may be difficult to determine which existing line was least recently used, because the new line conflicts with data at different indexes in each way; [[Cache algorithms|LRU]] tracking for non-skewed caches is usually done on a per-set basis. Nevertheless, skewed-associative caches have major advantages over conventional set-associative ones.<ref>
[http://www.irisa.fr/caps/PROJECTS/Architecture/ Micro-Architecture] "Skewed-associative caches have ... major advantages over conventional set-associative caches."
</ref>