Examine individual changes
Appearance
This page allows you to examine the variables generated by the Edit Filter for an individual change.
Variables generated for this change
Variable | Value |
---|---|
Edit count of the user (user_editcount ) | null |
Name of the user account (user_name ) | '91.196.30.212' |
Age of the user account (user_age ) | 0 |
Groups (including implicit) the user is in (user_groups ) | [
0 => '*'
] |
Rights that the user has (user_rights ) | [
0 => 'createaccount',
1 => 'read',
2 => 'edit',
3 => 'createtalk',
4 => 'writeapi',
5 => 'viewmyprivateinfo',
6 => 'editmyprivateinfo',
7 => 'editmyoptions',
8 => 'abusefilter-log-detail',
9 => 'urlshortener-create-url',
10 => 'centralauth-merge',
11 => 'abusefilter-view',
12 => 'abusefilter-log',
13 => 'vipsscaler-test'
] |
Whether the user is editing from mobile app (user_app ) | false |
Whether or not a user is editing through the mobile interface (user_mobile ) | false |
Page ID (page_id ) | 849181 |
Page namespace (page_namespace ) | 0 |
Page title without namespace (page_title ) | 'CPU cache' |
Full page title (page_prefixedtitle ) | 'CPU cache' |
Edit protection level of the page (page_restrictions_edit ) | [] |
Last ten users to contribute to the page (page_recent_contributors ) | [
0 => 'Bumm13',
1 => 'Guy Harris',
2 => '2407:D000:D:F08E:8947:BBE2:7532:CBAA',
3 => 'OAbot',
4 => 'Citation bot',
5 => 'Wikipedialuva',
6 => 'Niceguyedc',
7 => 'Delta-shadow',
8 => 'WikiCleanerBot',
9 => 'Spinixster'
] |
Page age in seconds (page_age ) | 603936698 |
Action (action ) | 'edit' |
Edit summary/reason (summary ) | '' |
Old content model (old_content_model ) | 'wikitext' |
New content model (new_content_model ) | 'wikitext' |
Old page wikitext, before the edit (old_wikitext ) | '{{Short description|Hardware cache of a central processing unit}}
A '''CPU cache''' is a [[hardware cache]] used by the [[central processing unit]] (CPU) of a [[computer]] to reduce the average cost (time or energy) to access [[data (computer science)|data]] from the [[main memory]].<ref>{{cite web|url=http://www.hardwaresecrets.com/how-the-cache-memory-works/|title=How The Cache Memory Works|author=Gabriel Torres|date=September 12, 2007}}</ref> A cache is a smaller, faster memory, located closer to a [[processor core]], which stores copies of the data from frequently used main [[memory location]]s. Most CPUs have a hierarchy of multiple cache [[#MULTILEVEL|levels]] (L1, L2, often L3, and rarely even L4), with different instruction-specific and data-specific caches at level 1.<ref>{{Cite journal |last1=Su |first1=Chao |last2=Zeng |first2=Qingkai |date=2021-06-10 |editor-last=Nicopolitidis |editor-first=Petros |title=Survey of CPU Cache-Based Side-Channel Attacks: Systematic Analysis, Security Models, and Countermeasures |journal=Security and Communication Networks |language=en |volume=2021 |pages=1–15 |doi=10.1155/2021/5559552 |issn=1939-0122|doi-access=free }}</ref> The cache memory is typically implemented with [[static random-access memory]] (SRAM), in modern CPUs by far the largest part of them by chip area, but SRAM is not always used for all levels (of I- or D-cache), or even any level, sometimes some latter or all levels are implemented with [[eDRAM]].
Other types of caches exist (that are not counted towards the "cache size" of the most important caches mentioned above), such as the [[translation lookaside buffer]] (TLB) which is part of the [[memory management unit]] (MMU) which most CPUs have.
=={{Anchor|ICACHE|DCACHE|instruction cache|data cache}}Overview==
When trying to read from or write to a location in the main memory, the processor checks whether the data from that location is already in the cache. If so, the processor will read from or write to the cache instead of the much slower main memory.
Many modern [[desktop computer|desktop]], [[server (computing)|server]], and industrial CPUs have at least three independent caches:
; Instruction cache: Used to speed up executable instruction fetch
; Data cache: Used to speed up data fetch and store; the data cache is usually organized as a hierarchy of more cache levels (L1, L2, etc.; see also [[#Multi-level caches|multi-level caches]] below).
; [[Translation lookaside buffer]] (TLB): Used to speed up virtual-to-physical address translation for both executable instructions and data. A single TLB can be provided for access to both instructions and data, or a separate Instruction TLB (ITLB) and data TLB (DTLB) can be provided. However, the TLB cache is part of the [[memory management unit]] (MMU) and not directly related to the CPU caches.
==History==
[[File:NeXTcube motherboard.jpg|thumb|[[Motherboard]] of a [[NeXTcube]] computer (1990). At the lower edge of the image left from the middle, there is the CPU [[Motorola 68040]] operated at 25 [[MHz]] with two separate level 1 caches of 4 KiB each on the chip, one for the instructions and one for data. The board has no external L2 cache.]]
Early examples of CPU caches include the [[Titan (1963 computer)|Atlas 2]]<ref>{{cite web|url=http://www.chilton-computing.org.uk/acl/technology/atlas50th/p005.htm|title=Atlas 2 at Cambridge Mathematical Laboratory (and Aldermaston and CAD Centre)|date=November 2012|quote=Two tunnel diode stores were developed at Cambridge; one, which worked very well, speeded up the fetching of operands, the other was intended to speed up the fetching of instructions. The idea was that most instructions are obeyed in sequence, so when an instruction was fetched that word was placed in the slave store in the location given by the fetch address modulo 32; the remaining bits of the fetch address were also stored. If the wanted word was in the slave it was read from there instead of main memory. This would give a major speedup to instruction loops up to 32 instructions long, and reduced effect for loops up to 64 words.}}</ref> and the [[IBM System/360 Model 85]]<ref>{{cite web|url=http://www.bitsavers.org/pdf/ibm/360/functional_characteristics/A22-6916-1_360-85_funcChar_Jun68.pdf|title=IBM System/360 Model 85 Functional Characteristics|publisher=[[IBM]]|id=A22-6916-1|date=June 1968}}</ref> in the 1960s. The first CPUs that used a cache had only one level of cache; unlike later level 1 cache, it was not split into L1d (for data) and L1i (for instructions). Split L1 cache started in 1976 with the [[IBM 801]] CPU,<ref>{{cite journal|url=http://home.eng.iastate.edu/~zzhang/courses/cpre585-f03/reading/smith-csur82-cache.pdf|title=Cache Memories|first=Alan Jay|last=Smith|journal=Computing Surveys|volume=14|issue=3|date=September 1982|pages=473–530|doi=10.1145/356887.356892|s2cid=6023466}}</ref><ref>{{cite journal|title=Altering Computer Architecture is Way to Raise Throughput, Suggests IBM Researchers|journal=[[Electronics (magazine)|Electronics]]|volume=49|issue=25|date=December 23, 1976|pages=30–31}}</ref> became mainstream in the late 1980s, and in 1997 entered the embedded CPU market with the ARMv5TE. In 2015, even sub-dollar SoCs split the L1 cache. They also have L2 caches and, for larger processors, L3 caches as well. The L2 cache is usually not split, and acts as a common repository for the already split L1 cache. Every core of a [[multi-core processor]] has a dedicated L1 cache and is usually not shared between the cores. The L2 cache, and higher-level caches, may be shared between the cores. L4 cache is currently uncommon, and is generally [[dynamic random-access memory]] (DRAM) on a separate die or chip, rather than [[static random-access memory]] (SRAM). An exception to this is when [[eDRAM]] is used for all levels of cache, down to L1. Historically L1 was also on a separate die, however bigger die sizes have allowed integration of it as well as other cache levels, with the possible exception of the last level. Each extra level of cache tends to be bigger and optimized differently.
Caches (like for RAM historically) have generally been sized in powers of: 2, 4, 8, 16 etc. [[Kibibyte|KiB]]; when up to [[Mebibyte|MiB]] sizes (i.e. for larger non-L1), very early on the pattern broke down, to allow for larger caches without being forced into the doubling-in-size paradigm, with e.g. [[Intel Core 2 Duo]] with 3 MiB L2 cache in April 2008. This happened much later for L1 caches, as their size is generally still a small number of KiB. The [[IBM zEC12 (microprocessor)|IBM zEC12]] from 2012 is an exception however, to gain unusually large 96 KiB L1 data cache for its time, and e.g. the [[IBM z13 (microprocessor)|IBM z13]] having a 96 KiB L1 instruction cache (and 128 KiB L1 data cache),<ref>{{cite web|url=https://www.redbooks.ibm.com/redbooks/pdfs/sg248250.pdf|title=IBM z13 and IBM z13s Technical Introduction|page=20|date=March 2016|publisher=[[IBM]]}}</ref> and Intel [[Ice Lake (microprocessor)|Ice Lake]]-based processors from 2018, having 48 KiB L1 data cache and 48 KiB L1 instruction cache. In 2020, some [[Intel Atom]] CPUs (with up to 24 cores) have (multiple of) 4.5 MiB and 15 MiB cache sizes.<ref>{{Cite press release|url=https://newsroom.intel.com/news/product-fact-sheet-accelerating-5g-network-infrastructure-core-edge/|title=Product Fact Sheet: Accelerating 5G Network Infrastructure, from the Core to the Edge|website=Intel Newsroom|quote=L1 cache of 32KB/core, L2 cache of 4.5MB per 4-core cluster and shared LLC cache up to 15MB.|language=en-US|access-date=2020-04-12}}</ref><ref>{{Cite web|url=https://www.anandtech.com/show/15544/intel-launches-atom-p5900-a-10nm-atom-for-radio-access-networks|title=Intel Launches Atom P5900: A 10nm Atom for Radio Access Networks|last=Smith|first=Ryan|website=www.anandtech.com|access-date=2020-04-12}}</ref>
==={{Anchor|cache lines|CACHE-LINES}}Cache entries===
Data is transferred between memory and cache in blocks of fixed size, called ''cache lines'' or ''cache blocks''. When a cache line is copied from memory into the cache, a cache entry is created. The cache entry will include the copied data as well as the requested memory location (called a tag).
When the processor needs to read or write a location in memory, it first checks for a corresponding entry in the cache. The cache checks for the contents of the requested memory location in any cache lines that might contain that address. If the processor finds that the memory location is in the cache, a '''cache hit''' has occurred. However, if the processor does not find the memory location in the cache, a '''cache miss''' has occurred. In the case of a cache hit, the processor immediately reads or writes the data in the cache line. For a cache miss, the cache allocates a new entry and copies data from main memory, then the request is fulfilled from the contents of the cache.
===Policies===
===={{Anchor|EVICTION}}Replacement policies====
{{Main article|Cache replacement policies}}
To make room for the new entry on a cache miss, the cache may have to evict one of the existing entries. The heuristic it uses to choose the entry to evict is called the replacement policy. The fundamental problem with any replacement policy is that it must predict which existing cache entry is least likely to be used in the future. Predicting the future is difficult, so there is no perfect method to choose among the variety of replacement policies available. One popular replacement policy, [[least-recently used]] (LRU), replaces the least recently accessed entry.
Marking some memory ranges as non-cacheable can improve performance, by avoiding caching of memory regions that are rarely re-accessed. This avoids the overhead of loading something into the cache without having any reuse. Cache entries may also be disabled or locked depending on the context.
====Write policies====
{{Main article|Cache (computing)#WRITEPOLICIES|l1=Cache (computing) § Writing policies}}
If data is written to the cache, at some point it must also be written to main memory; the timing of this write is known as the write policy. In a [[write-through]] cache, every write to the cache causes a write to main memory. Alternatively, in a [[write-back]] or copy-back cache, writes are not immediately mirrored to the main memory, and the cache instead tracks which locations have been written over, marking them as [[Dirty bit|dirty]]. The data in these locations is written back to the main memory only when that data is evicted from the cache. For this reason, a read miss in a write-back cache may sometimes require two memory accesses to service: one to first write the dirty location to main memory, and then another to read the new location from memory. Also, a write to a main memory location that is not yet mapped in a write-back cache may evict an already dirty location, thereby freeing that cache space for the new memory location.
There are intermediate policies as well. The cache may be write-through, but the writes may be held in a store data queue temporarily, usually so multiple stores can be processed together (which can reduce bus turnarounds and improve bus utilization).
Cached data from the main memory may be changed by other entities (e.g., peripherals using [[direct memory access]] (DMA) or another core in a [[multi-core processor]]), in which case the copy in the cache may become out-of-date or stale. Alternatively, when a CPU in a [[multiprocessor]] system updates data in the cache, copies of data in caches associated with other CPUs become stale. Communication protocols between the cache managers that keep the data consistent are known as [[cache coherence]] protocols.
===Cache performance===
[[Cache performance measurement and metric|Cache performance measurement]] has become important in recent times where the speed gap between the memory performance and the processor performance is increasing exponentially. The cache was introduced to reduce this speed gap. Thus knowing how well the cache is able to bridge the gap in the speed of processor and memory becomes important, especially in high-performance systems. The cache hit rate and the cache miss rate play an important role in determining this performance. To improve the cache performance, reducing the miss rate becomes one of the necessary steps among other steps. Decreasing the access time to the cache also gives a boost to its performance.
====CPU stalls====
The time taken to fetch one cache line from memory (read [[Latency (engineering)|latency]] due to a cache miss) matters because the CPU will run out of things to do while waiting for the cache line. When a CPU reaches this state, it is called a stall. As CPUs become faster compared to main memory, stalls due to cache misses displace more potential computation; modern CPUs can execute hundreds of instructions in the time taken to fetch a single cache line from main memory.
Various techniques have been employed to keep the CPU busy during this time, including [[out-of-order execution]] in which the CPU attempts to execute independent instructions after the instruction that is waiting for the cache miss data. Another technology, used by many processors, is [[simultaneous multithreading]] (SMT), which allows an alternate thread to use the CPU core while the first thread waits for required CPU resources to become available.
==Associativity==
[[Image:Cache,associative-fill-both.png|thumb|450px|An illustration of different ways in which memory locations can be cached by particular cache locations]]
{{Main|Cache placement policies}}
The [[Cache placement policies|placement policy]] decides where in the cache a copy of a particular entry of main memory will go. If the placement policy is free to choose any entry in the cache to hold the copy, the cache is called ''fully associative''. At the other extreme, if each entry in the main memory can go in just one place in the cache, the cache is ''direct-mapped''. Many caches implement a compromise in which each entry in the main memory can go to any one of N places in the cache, and are described as N-way set associative.<ref>{{cite web|url=https://cseweb.ucsd.edu/classes/fa10/cse240a/pdf/08/CSE240A-MBT-L15-Cache.ppt.pdf|title=Cache design|date=2010-12-02|website=ucsd.edu|page=10–15|access-date=2023-01-29}}</ref> For example, the level-1 data cache in an [[AMD Athlon]] is two-way set associative, which means that any particular location in main memory can be cached in either of two locations in the level-1 data cache.
Choosing the right value of associativity involves a [[trade-off]]. If there are ten places to which the placement policy could have mapped a memory location, then to check if that location is in the cache, ten cache entries must be searched. Checking more places takes more power and chip area, and potentially more time. On the other hand, caches with more associativity suffer fewer misses (see [[Cache performance measurement and metric#Conflict misses|conflict misses]]), so that the CPU wastes less time reading from the slow main memory. The general guideline is that doubling the associativity, from direct mapped to two-way, or from two-way to four-way, has about the same effect on raising the hit rate as doubling the cache size. However, increasing associativity more than four does not improve hit rate as much,<ref>[http://ieeexplore.ieee.org/xpl/freeabs_all.jsp?arnumber=5234663 IEEE Xplore - Phased set-associative cache design for reduced power consumption]. Ieeexplore.ieee.org (2009-08-11). Retrieved on 2013-07-30.</ref> and are generally done for other reasons (see [[#Virtual aliasing|virtual aliasing]]). Some CPUs can dynamically reduce the associativity of their caches in low-power states, which acts as a power-saving measure.<ref>{{cite web|url=http://hotchips.org/wp-content/uploads/hc_archives/hc24/HC24-1-Microprocessor/HC24.28.117-HotChips_IvyBridge_Power_04.pdf#page=18|title=Power Management of the Third Generation Intel Core Micro Architecture formerly codenamed Ivy Bridge|author1=Sanjeev Jahagirdar|author2=Varghese George|year=2012|website=hotchips.org|page=18|format=PDF|access-date=2015-12-16|author3=Inder Sodhi|author4=Ryan Wells|archive-date=2020-07-29|archive-url=https://web.archive.org/web/20200729002711/http://hotchips.org/wp-content/uploads/hc_archives/hc24/HC24-1-Microprocessor/HC24.28.117-HotChips_IvyBridge_Power_04.pdf#page=18|url-status=dead}}</ref>
<!-- where does "pseudo-associative cache" go in this spectrum? -->
In order of worse but simple to better but complex:
* Direct mapped cache{{snd}} good best-case time, but unpredictable in the worst case
* Two-way set associative cache
* Two-way skewed associative cache<ref name="Seznec">{{cite journal|author=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>
* Four-way set-associative cache
* Eight-way set-associative cache, a common choice for later implementations
* 12-way set associative cache, similar to eight-way
* Fully associative cache{{snd}} the best miss rates, but practical only for a small number of entries
===Direct-mapped cache===
In this cache organization, each location in the main memory can go in only one entry in the cache. Therefore, a direct-mapped cache can also be called a "one-way set associative" cache. It does not have a placement policy as such, since there is no choice of which cache entry's contents to evict. This means that if two locations map to the same entry, they may continually knock each other out. Although simpler, a direct-mapped cache needs to be much larger than an associative one to give comparable performance, and it is more unpredictable. Let {{mvar|x}} be block number in cache, {{mvar|y}} be block number of memory, and {{mvar|n}} be number of blocks in cache, then mapping is done with the help of the equation {{math|''x'' {{=}} ''y'' mod ''n''}}.
===Two-way set associative cache===
If each location in the main memory can be cached in either of two locations in the cache, one logical question is: ''which one of the two?'' The simplest and most commonly used scheme, shown in the right-hand diagram above, is to use the least significant bits of the memory location's index as the index for the cache memory, and to have two entries for each index. One benefit of this scheme is that the tags stored in the cache do not have to include that part of the main memory address which is implied by the cache memory's index. Since the cache tags have fewer bits, they require fewer transistors, take less space on the processor circuit board or on the microprocessor chip, and can be read and compared faster. Also [[Cache algorithms|LRU]] is especially simple since only one bit needs to be stored for each pair.
===Speculative execution===
One of the advantages of a direct-mapped cache is that it allows simple and fast [[speculative execution|speculation]]. Once the address has been computed, the one cache index which might have a copy of that location in memory is known. That cache entry can be read, and the processor can continue to work with that data before it finishes checking that the tag actually matches the requested address.
The idea of having the processor use the cached data before the tag match completes can be applied to associative caches as well. A subset of the tag, called a ''hint'', can be used to pick just one of the possible cache entries mapping to the requested address. The entry selected by the hint can then be used in parallel with checking the full tag. The hint technique works best when used in the context of address translation, as explained below.
===Two-way skewed associative cache===
Other schemes have been suggested, such as the ''skewed cache'',<ref name="Seznec" /> 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|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>
{{cite web |url=https://www.irisa.fr/caps/PROJECTS/Architecture/ |title=Micro-Architecture] |quote=Skewed-associative caches have been shown to have two major advantages over conventional set-associative caches.}}</ref>
===Pseudo-associative cache===
A true set-associative cache tests all the possible ways simultaneously, using something like a [[content-addressable memory]]. A pseudo-associative cache tests each possible way one at a time. A hash-rehash cache and a column-associative cache are examples of a pseudo-associative cache.
In the common case of finding a hit in the first way tested, a pseudo-associative cache is as fast as a direct-mapped cache, but it has a much lower conflict miss rate than a direct-mapped cache, closer to the miss rate of a fully associative cache.
<ref name="CK" />
===Multicolumn cache===
Comparing with a direct-mapped cache, a set associative cache has a reduced number of bits for its cache set index that maps to a cache set, where multiple ways or blocks stays, such as 2 blocks for a 2-way set associative cache and 4 blocks for a 4-way set associative cache. Comparing with a direct mapped cache, the unused cache index bits become a part of the tag bits. For example, a 2-way set associative cache contributes 1 bit to the tag and a 4-way set associative cache contributes 2 bits to the tag. The basic idea of the multicolumn cache<ref name="Two-fast">{{Cite journal |author1= Chenxi Zhang |author2 =Xiaodong Zhang |author3= Yong Yan| title=Two fast and high-associativity cache schemes |journal= IEEE Micro |volume= 17 |issue= 5 | date= September–October 1997 |pages = 40–49 |doi= 10.1109/40.621212}}</ref> is to use the set index to map to a cache set as a conventional set associative cache does, and to use the added tag bits to index a way in the set. For example, in a 4-way set associative cache, the two bits are used to index way 00, way 01, way 10, and way 11, respectively. This double cache indexing is called a “major location mapping”, and its latency is equivalent to a direct-mapped access. Extensive experiments in multicolumn cache design<ref name="Two-fast" /> shows that the hit ratio to major locations is as high as 90%. If cache mapping conflicts with a cache block in the major location, the existing cache block will be moved to another cache way in the same set, which is called “selected location”. Because the newly indexed cache block is a most recently used (MRU) block, it is placed in the major location in multicolumn cache with a consideration of temporal locality. Since multicolumn cache is designed for a cache with a high associativity, the number of ways in each set is high; thus, it is easy find a selected location in the set. A selected location index by an additional hardware is maintained for the major location in a cache block.{{Citation needed|date=May 2023}}
Multicolumn cache remains a high hit ratio due to its high associativity, and has a comparable low latency to a direct-mapped cache due to its high percentage of hits in major locations. The concepts of major locations and selected locations in multicolumn cache have been used in several cache designs in ARM Cortex R chip,<ref>{{Cite web |date=2014 |title=ARM® Cortex®-R Series Programmer's Guide |url=https://developer.arm.com/documentation/den0042/latest |access-date=2023-05-04 |website=developer.arm.com}}</ref> Intel's way-predicting cache memory,<ref>{{Cite web|url=https://patents.google.com/patent/US6425055B1/en|title=Way-predicting cache memory}}</ref> IBM's reconfigurable multi-way associative cache memory<ref>{{Cite web |date=November 22, 1994 |title=United States Patent |url=https://rpx-patents.s3.amazonaws.com/US/c530f-US5367653A/US5367653A.pdf |access-date=2023-05-04 |website=rpx-patents.s3.amazonaws.com}}</ref> and Oracle's dynamic cache replacement way selection based on address tab bits.<ref>{{Cite web|url=https://patents.justia.com/patent/20160350229|title=US Patent Application for DYNAMIC CACHE REPLACEMENT WAY SELECTION BASED ON ADDRESS TAG BITS Patent Application (Application #20160350229 issued December 1, 2016) - Justia Patents Search|website=patents.justia.com}}</ref>
==Cache entry structure==
Cache row entries usually have the following structure:
{| style="width:30%; text-align:center" border="1"
|-
| tag || data block || flag bits
|}
The ''data block'' (cache line) contains the actual data fetched from the main memory. The ''tag'' contains (part of) the address of the actual data fetched from the main memory. The flag bits are [[#Flag_bits|discussed below]].
The "size" of the cache is the amount of main memory data it can hold. This size can be calculated as the number of bytes stored in each data block times the number of blocks stored in the cache. (The tag, flag and [[ECC memory#Cache|error correction code]] bits are not included in the size,<ref>{{cite web|author=Nathan N. Sadler|author2=Daniel J. Sorin|url=http://people.ee.duke.edu/~sorin/papers/iccd06_perc.pdf|title=Choosing an Error Protection Scheme for a Microprocessor's L1 Data Cache|year=2006|page=4}}</ref> although they do affect the physical area of a cache.)
An effective memory address which goes along with the cache line (memory block) is split ([[Most significant bit|MSB]] to [[Least significant bit|LSB]]) into the tag, the index and the block offset.<ref>{{cite book|author1=John L. Hennessy|author2=David A. Patterson|title=Computer Architecture: A Quantitative Approach|year=2011|publisher=Elsevier |isbn=978-0-12-383872-8|at=p. B-9|url=https://books.google.com/books?id=v3-1hVwHnHwC&q=Hennessey+%22block+offset%22&pg=PA120}}</ref><ref>{{cite book|author1=David A. Patterson|author2=John L. Hennessy|title=Computer Organization and Design: The Hardware/Software Interface|year=2009|isbn=978-0-12-374493-7|page=484|publisher=Morgan Kaufmann |url=https://books.google.com/books?id=3b63x-0P3_UC&q=Hennessey+%22block+offset%22&pg=PA484}}</ref>
{| style="width:30%; text-align:center" border="1"
|-
| tag || index || block offset
|}
The index describes which cache set that the data has been put in. The index length is <math>\lceil \log_2(s) \rceil</math> bits for {{mvar|s}} cache sets.
The block offset specifies the desired data within the stored data block within the cache row. Typically the effective address is in bytes, so the block offset length is <math>\lceil \log_2(b) \rceil</math> bits, where {{mvar|b}} is the number of bytes per data block.
The tag contains the most significant bits of the address, which are checked against all rows in the current set (the set has been retrieved by index) to see if this set contains the requested address. If it does, a cache hit occurs. The tag length in bits is as follows:
::<code>tag_length = address_length - index_length - block_offset_length</code>
Some authors refer to the block offset as simply the "offset"<ref name="ccs.neu.edu">{{cite web|author=Gene Cooperman|title=Cache Basics|year=2003|url=http://www.ccs.neu.edu/course/com3200/parent/NOTES/cache-basics.html}}</ref> or the "displacement".<ref>{{cite web|author=Ben Dugan|title=Concerning Cache|year=2002|url=http://www.cs.washington.edu/education/courses/cse378/02sp/sections/section9-1.html}}</ref><ref>Harvey G. Cragon.
"Memory systems and pipelined processors".
1996. {{ISBN|0-86720-474-5}}, {{ISBN|978-0-86720-474-2}}.
"Chapter 4.1: Cache Addressing, Virtual or Real"
p. 209
[https://books.google.com/books?id=q2w3JSFD7l4C&dq=displacement+tag+cache&pg=PA209]
</ref>
===Example===
The original [[Pentium 4]] processor had a four-way set associative L1 data cache of 8 [[Kibibyte|KiB]] in size, with 64-byte cache blocks. Hence, there are 8 KiB / 64 = 128 cache blocks. The number of sets is equal to the number of cache blocks divided by the number of ways of associativity, what leads to 128 / 4 = 32 sets, and hence 2<sup>5</sup> = 32 different indices. There are 2<sup>6</sup> = 64 possible offsets. Since the CPU address is 32 bits wide, this implies 32 - 5 - 6 = 21 bits for the tag field.
The original Pentium 4 processor also had an eight-way set associative L2 integrated cache 256 KiB in size, with 128-byte cache blocks. This implies 32 - 8 - 7 = 17 bits for the tag field.<ref name="ccs.neu.edu" />
==={{Anchor|Flag bits}} Flag bits===
An instruction cache requires only one flag bit per cache row entry: a valid bit. The valid bit indicates whether or not a cache block has been loaded with valid data.
On power-up, the hardware sets all the valid bits in all the caches to "invalid". Some systems also set a valid bit to "invalid" at other times, such as when multi-master [[bus snooping]] hardware in the cache of one processor hears an address broadcast from some other processor, and realizes that certain data blocks in the local cache are now stale and should be marked invalid.
A data cache typically requires two flag bits per cache line{{snd}} a valid bit and a [[dirty bit]]. Having a dirty bit set indicates that the associated cache line has been changed since it was read from main memory ("dirty"), meaning that the processor has written data to that line and the new value has not propagated all the way to main memory.
=={{Anchor|CACHE-MISS}}Cache miss==
A cache miss is a failed attempt to read or write a piece of data in the cache, which results in a main memory access with much longer latency. There are three kinds of cache misses: instruction read miss, data read miss, and data write miss.
''Cache read misses'' from an ''instruction'' cache generally cause the largest delay, because the processor, or at least the [[Simultaneous multithreading|thread of execution]], has to wait (stall) until the instruction is fetched from main memory. ''Cache read misses'' from a ''data'' cache usually cause a smaller delay, because instructions not dependent on the cache read can be issued and continue execution until the data is returned from main memory, and the dependent instructions can resume execution. ''Cache write misses'' to a ''data'' cache generally cause the shortest delay, because the write can be queued and there are few limitations on the execution of subsequent instructions; the processor can continue until the queue is full. For a detailed introduction to the types of misses, see [[cache performance measurement and metric]].
=={{Anchor|ADDRTRANS}}Address translation==
Most general purpose CPUs implement some form of [[virtual memory]]. To summarize, either each program running on the machine sees its own simplified [[address space]], which contains code and data for that program only, or all programs run in a common virtual address space. A program executes by calculating, comparing, reading and writing to addresses of its virtual address space, rather than addresses of physical address space, making programs simpler and thus easier to write.
Virtual memory requires the processor to translate virtual addresses generated by the program into physical addresses in main memory. The portion of the processor that does this translation is known as the [[memory management unit]] (MMU). The fast path through the MMU can perform those translations stored in the [[translation lookaside buffer]] (TLB), which is a cache of mappings from the operating system's [[page table]], segment table, or both.
For the purposes of the present discussion, there are three important features of address translation:
* ''Latency:'' The physical address is available from the MMU some time, perhaps a few cycles, after the virtual address is available from the address generator.
* {{Anchor|Virtual aliasing}}''Aliasing:'' Multiple virtual addresses can map to a single physical address. Most processors guarantee that all updates to that single physical address will happen in program order. To deliver on that guarantee, the processor must ensure that only one copy of a physical address resides in the cache at any given time.
* ''Granularity:'' The virtual address space is broken up into pages. For instance, a 4 [[Gibibyte|GiB]] virtual address space might be cut up into 1,048,576 pages of 4 KiB size, each of which can be independently mapped. There may be multiple page sizes supported; see [[virtual memory]] for elaboration.
One early virtual memory system, the [[IBM M44/44X]], required an access to a mapping table held in [[core memory]] before every programmed access to main memory.<ref>{{cite conference|author=R. W. O'Neill|title=Experience using a time sharing multiprogramming system with dynamic address relocation hardware|conference=Proc. AFIPS Computer Conference 30 (Spring Joint Computer Conference, 1967)|pages=611–621|doi=10.1145/1465482.1465581}}</ref>{{refn|The very first paging machine, the [[Ferranti]] [[Atlas Computer (Manchester)|Atlas]]<ref name=AtlasCPU/><ref name=AtlasSup/> had no page tables in main memory; there was an associative memory with one entry for every 512 word page frame of core.|group=NB}} With no caches, and with the mapping table memory running at the same speed as main memory this effectively cut the speed of memory access in half. Two early machines that used a [[page table]] in main memory for mapping, the [[IBM System/360 Model 67]] and the [[GE 645]], both had a small associative memory as a cache for accesses to the in-memory page table. Both machines predated the first machine with a cache for main memory, the [[IBM System/360 Model 85]], so the first hardware cache used in a computer system was not a data or instruction cache, but rather a TLB.
Caches can be divided into four types, based on whether the index or tag correspond to physical or virtual addresses:
* ''Physically indexed, physically tagged'' (PIPT) caches use the physical address for both the index and the tag. While this is simple and avoids problems with aliasing, it is also slow, as the physical address must be looked up (which could involve a TLB miss and access to main memory) before that address can be looked up in the cache.
* ''Virtually indexed, virtually tagged'' (VIVT) caches use the virtual address for both the index and the tag. This caching scheme can result in much faster lookups, since the MMU does not need to be consulted first to determine the physical address for a given virtual address. However, VIVT suffers from aliasing problems, where several different virtual addresses may refer to the same physical address. The result is that such addresses would be cached separately despite referring to the same memory, causing coherency problems. Although solutions to this problem exist<ref>{{cite conference|last1=Kaxiras|first1=Stefanos|last2=Ros|first2=Alberto|title=A New Perspective for Efficient Virtual-Cache Coherence|conference=40th International Symposium on Computer Architecture (ISCA)|date=2013|pages=535–547|doi=10.1145/2485922.2485968|isbn=9781450320795|citeseerx=10.1.1.307.9125|s2cid=15434231}}</ref> they do not work for standard coherence protocols. Another problem is homonyms, where the same virtual address maps to several different physical addresses. It is not possible to distinguish these mappings merely by looking at the virtual index itself, though potential solutions include: flushing the cache after a [[context switch]], forcing address spaces to be non-overlapping, tagging the virtual address with an address space ID (ASID). Additionally, there is a problem that virtual-to-physical mappings can change, which would require flushing cache lines, as the VAs would no longer be valid. All these issues are absent if tags use physical addresses (VIPT).
* ''Virtually indexed, physically tagged'' (VIPT) caches use the virtual address for the index and the physical address in the tag. The advantage over PIPT is lower latency, as the cache line can be looked up in parallel with the TLB translation, however the tag cannot be compared until the physical address is available. The advantage over VIVT is that since the tag has the physical address, the cache can detect homonyms. Theoretically, VIPT requires more tags bits because some of the index bits could differ between the virtual and physical addresses (for example bit 12 and above for 4 KiB pages) and would have to be included both in the virtual index and in the physical tag. In practice this is not an issue because, in order to avoid coherency problems, VIPT caches are designed to have no such index bits (e.g., by limiting the total number of bits for the index and the block offset to 12 for 4 KiB pages); this limits the size of VIPT caches to the page size times the associativity of the cache.
* ''Physically indexed, virtually tagged'' (PIVT) caches are often claimed in literature to be useless and non-existing.<ref>{{cite magazine |url=http://www.linuxjournal.com/article/7105 |title=Understanding Caching |magazine=Linux Journal |access-date=2010-05-02}}</ref> However, the [[MIPS architecture|MIPS]] [[R6000]] uses this cache type as the sole known implementation.<ref>{{cite journal|first1=George|last1=Taylor|first2=Peter|last2=Davies|first3=Michael|last3=Farmwald|title=The TLB Slice - A Low-Cost High-Speed Address Translation Mechanism|year=1990|id=CH2887-8/90/0000/0355$01.OO}}</ref> The R6000 is implemented in [[emitter-coupled logic]], which is an extremely fast technology not suitable for large memories such as a [[Translation lookaside buffer|TLB]]. The R6000 solves the issue by putting the TLB memory into a reserved part of the second-level cache having a tiny, high-speed TLB "slice" on chip. The cache is indexed by the physical address obtained from the TLB slice. However, since the TLB slice only translates those virtual address bits that are necessary to index the cache and does not use any tags, false cache hits may occur, which is solved by tagging with the virtual address.
The speed of this recurrence (the ''load latency'') is crucial to CPU performance, and so most modern level-1 caches are virtually indexed, which at least allows the MMU's TLB lookup to proceed in parallel with fetching the data from the cache RAM.
But virtual indexing is not the best choice for all cache levels. The cost of dealing with virtual aliases grows with cache size, and as a result most level-2 and larger caches are physically indexed.
Caches have historically used both virtual and physical addresses for the cache tags, although virtual tagging is now uncommon. If the TLB lookup can finish before the cache RAM lookup, then the physical address is available in time for tag compare, and there is no need for virtual tagging. Large caches, then, tend to be physically tagged, and only small, very low latency caches are virtually tagged. In recent general-purpose CPUs, virtual tagging has been superseded by vhints, as described below.
===Homonym and synonym problems===
A cache that relies on virtual indexing and tagging becomes inconsistent after the same virtual address is mapped into different physical addresses ([[homonym]]), which can be solved by using physical address for tagging, or by storing the address space identifier in the cache line. However, the latter approach does not help against the [[synonym]] problem, in which several cache lines end up storing data for the same physical address. Writing to such locations may update only one location in the cache, leaving the others with inconsistent data. This issue may be solved by using non-overlapping memory layouts for different address spaces, or otherwise the cache (or a part of it) must be flushed when the mapping changes.<ref>{{cite web
| url = http://www.systems.ethz.ch/education/courses/fs09/aos/lectures/wk3-print.pdf
| archive-url = https://web.archive.org/web/20111007150424/http://www.systems.ethz.ch/education/past-courses/fs09/aos/lectures/wk3-print.pdf |url-status = dead
| title = Advanced Operating Systems Caches and TLBs (263-3800-00L)
| date = 2009-03-03 | access-date = 2016-02-14 | archive-date = 2011-10-07
| author1 = Timothy Roscoe | author2 = Andrew Baumann
| website = systems.ethz.ch }}</ref>
===Virtual tags and vhints===
The great advantage of virtual tags is that, for associative caches, they allow the tag match to proceed before the virtual to physical translation is done. However, coherence probes and evictions present a physical address for action. The hardware must have some means of converting the physical addresses into a cache index, generally by storing physical tags as well as virtual tags. For comparison, a physically tagged cache does not need to keep virtual tags, which is simpler. When a virtual to physical mapping is deleted from the TLB, cache entries with those virtual addresses will have to be flushed somehow. Alternatively, if cache entries are allowed on pages not mapped by the TLB, then those entries will have to be flushed when the access rights on those pages are changed in the page table.
It is also possible for the operating system to ensure that no virtual aliases are simultaneously resident in the cache. The operating system makes this guarantee by enforcing page coloring, which is described below. Some early RISC processors (SPARC, RS/6000) took this approach. It has not been used recently, as the hardware cost of detecting and evicting virtual aliases has fallen and the software complexity and performance penalty of perfect page coloring has risen.
It can be useful to distinguish the two functions of tags in an associative cache: they are used to determine which way of the entry set to select, and they are used to determine if the cache hit or missed. The second function must always be correct, but it is permissible for the first function to guess, and get the wrong answer occasionally.
Some processors (e.g. early SPARCs) have caches with both virtual and physical tags. The virtual tags are used for way selection, and the physical tags are used for determining hit or miss. This kind of cache enjoys the latency advantage of a virtually tagged cache, and the simple software interface of a physically tagged cache. It bears the added cost of duplicated tags, however. Also, during miss processing, the alternate ways of the cache line indexed have to be probed for virtual aliases and any matches evicted.
The extra area (and some latency) can be mitigated by keeping ''virtual hints'' with each cache entry instead of virtual tags. These hints are a subset or hash of the virtual tag, and are used for selecting the way of the cache from which to get data and a physical tag. Like a virtually tagged cache, there may be a virtual hint match but physical tag mismatch, in which case the cache entry with the matching hint must be evicted so that cache accesses after the cache fill at this address will have just one hint match. Since virtual hints have fewer bits than virtual tags distinguishing them from one another, a virtually hinted cache suffers more conflict misses than a virtually tagged cache.
Perhaps the ultimate reduction of virtual hints can be found in the Pentium 4 (Willamette and Northwood cores). In these processors the virtual hint is effectively two bits, and the cache is four-way set associative. Effectively, the hardware maintains a simple permutation from virtual address to cache index, so that no [[content-addressable memory]] (CAM) is necessary to select the right one of the four ways fetched.
===Page coloring===
{{Main article|Cache coloring}}
Large physically indexed caches (usually secondary caches) run into a problem: the operating system rather than the application controls which pages collide with one another in the cache. Differences in page allocation from one program run to the next lead to differences in the cache collision patterns, which can lead to very large differences in program performance. These differences can make it very difficult to get a consistent and repeatable timing for a benchmark run.
To understand the problem, consider a CPU with a 1 MiB physically indexed direct-mapped level-2 cache and 4 KiB virtual memory pages. Sequential physical pages map to sequential locations in the cache until after 256 pages the pattern wraps around. We can label each physical page with a color of 0–255 to denote where in the cache it can go. Locations within physical pages with different colors cannot conflict in the cache.
Programmers attempting to make maximum use of the cache may arrange their programs' access patterns so that only 1 MiB of data need be cached at any given time, thus avoiding capacity misses. But they should also ensure that the access patterns do not have conflict misses. One way to think about this problem is to divide up the virtual pages the program uses and assign them virtual colors in the same way as physical colors were assigned to physical pages before. Programmers can then arrange the access patterns of their code so that no two pages with the same virtual color are in use at the same time. There is a wide literature on such optimizations (e.g. [[loop nest optimization]]), largely coming from the [[High Performance Computing|High Performance Computing (HPC)]] community.
The snag is that while all the pages in use at any given moment may have different virtual colors, some may have the same physical colors. In fact, if the operating system assigns physical pages to virtual pages randomly and uniformly, it is extremely likely that some pages will have the same physical color, and then locations from those pages will collide in the cache (this is the [[birthday paradox]]).
The solution is to have the operating system attempt to assign different physical color pages to different virtual colors, a technique called ''page coloring''. Although the actual mapping from virtual to physical color is irrelevant to system performance, odd mappings are difficult to keep track of and have little benefit, so most approaches to page coloring simply try to keep physical and virtual page colors the same.
If the operating system can guarantee that each physical page maps to only one virtual color, then there are no virtual aliases, and the processor can use virtually indexed caches with no need for extra virtual alias probes during miss handling. Alternatively, the OS can flush a page from the cache whenever it changes from one virtual color to another. As mentioned above, this approach was used for some early SPARC and RS/6000 designs.
The software page coloring technique has been used to effectively partition the shared Last level Cache (LLC) in multicore processors.<ref>{{Cite conference |author1= Jiang Lin |author2=Qingda Lu |author3=Xiaoning Ding |author4=Zhao Zhang |author5=Xiaodong Zhang |author6=P. Sadayappan | title=Gaining insights into multicore cache partitioning: Bridging the gap between simulation and real systems |conference= IEEE 14th International Symposium on High Performance Computer Architecture |location= Salt Lake City, UT |date= 2008 |pages = 367–378 |doi= 10.1109/HPCA.2008.4658653}}</ref> This operating system-based LLC management in multicore processors has been adopted by Intel.<ref>{{Cite web|url=http://web.cse.ohio-state.edu/~zhang.574/OS-cache-software_intel_2010.pdf|title=Letter to Jiang Lin}}</ref>
=={{Anchor|Cache hierarchy}}Cache hierarchy in a modern processor==
[[File:Hwloc.png|thumb|right|300px|Memory hierarchy of an AMD Bulldozer server]]
Modern processors have multiple interacting on-chip caches. The operation of a particular cache can be completely specified by the cache size, the cache block size, the number of blocks in a set, the cache set replacement policy, and the cache write policy (write-through or write-back).<ref name="ccs.neu.edu" />
While all of the cache blocks in a particular cache are the same size and have the same associativity, typically the "lower-level" caches (called Level 1 cache) have a smaller number of blocks, smaller block size, and fewer blocks in a set, but have very short access times. "Higher-level" caches (i.e. Level 2 and above) have progressively larger numbers of blocks, larger block size, more blocks in a set, and relatively longer access times, but are still much faster than main memory.
Cache entry replacement policy is determined by a [[cache algorithm]] selected to be implemented by the processor designers. In some cases, multiple algorithms are provided for different kinds of work loads.
===Specialized caches===
Pipelined CPUs access memory from multiple points in the [[Instruction pipeline|pipeline]]: instruction fetch, [[virtual memory|virtual-to-physical]] address translation, and data fetch (see [[classic RISC pipeline]]). The natural design is to use different physical caches for each of these points, so that no one physical resource has to be scheduled to service two points in the pipeline. Thus the pipeline naturally ends up with at least three separate caches (instruction, [[translation lookaside buffer|TLB]], and data), each specialized to its particular role.
====Victim cache====
{{Main article|Victim cache}}
A '''victim cache''' is a cache used to hold blocks evicted from a CPU cache upon replacement. The victim cache lies between the main cache and its refill path, and holds only those blocks of data that were evicted from the main cache. The victim cache is usually fully associative, and is intended to reduce the number of conflict misses. Many commonly used programs do not require an associative mapping for all the accesses. In fact, only a small fraction of the memory accesses of the program require high associativity. The victim cache exploits this property by providing high associativity to only these accesses. It was introduced by [[Norman Jouppi]] from DEC in 1990.<ref>N.P.Jouppi. "Improving direct-mapped cache performance by the addition of a small {{Sic|hide=y|fully|-}}associative cache and prefetch buffers." - 17th Annual International Symposium on Computer Architecture, 1990. Proceedings., {{doi|10.1109/ISCA.1990.134547}}</ref>
Intel's ''[[Crystalwell]]''<ref name="intel-ark-crystal-well">{{cite web
| url = http://ark.intel.com/products/codename/51802/Crystal-Well
| title = Products (Formerly Crystal Well)
| publisher = [[Intel]]
| access-date = 2013-09-15
}}</ref> variant of its [[Haswell (microarchitecture)|Haswell]] processors introduced an on-package 128 MiB [[eDRAM]] Level 4 cache which serves as a victim cache to the processors' Level 3 cache.<ref name="anandtech-i74950hq">{{cite web
| url = http://www.anandtech.com/show/6993/intel-iris-pro-5200-graphics-review-core-i74950hq-tested/3
| title = Intel Iris Pro 5200 Graphics Review: Core i7-4950HQ Tested
| publisher = [[AnandTech]]
| access-date = 2013-09-16
}}</ref> In the [[Skylake (microarchitecture)|Skylake]] microarchitecture the Level 4 cache no longer works as a victim cache.<ref>{{cite web
| url = http://www.anandtech.com/show/9582/intel-skylake-mobile-desktop-launch-architecture-analysis/5
| title = The Intel Skylake Mobile and Desktop Launch, with Architecture Analysis
| author = Ian Cutress
| date = September 2, 2015
| publisher = AnandTech
}}</ref>
===={{Anchor|TRACE-CACHE}}Trace cache====
{{Main article|Trace cache}}
One of the more extreme examples of cache specialization is the '''trace cache''' (also known as ''execution trace cache'') found in the [[Intel]] [[Pentium 4]] microprocessors. A trace cache is a mechanism for increasing the instruction fetch bandwidth and decreasing power consumption (in the case of the Pentium 4) by storing traces of [[instruction (computer science)|instruction]]s that have already been fetched and decoded.<ref>{{cite web
| url = http://www.anandtech.com/show/661/5
| title = The Pentium 4's Cache – Intel Pentium 4 1.4 GHz & 1.5 GHz
| date = 2000-11-20 | access-date = 2015-11-30
| author = Anand Lal Shimpi | publisher = [[AnandTech]]
}}</ref>
A trace cache stores instructions either after they have been decoded, or as they are retired. Generally, instructions are added to trace caches in groups representing either individual [[basic block]]s or dynamic instruction traces. The Pentium 4's trace cache stores [[micro-operations]] resulting from decoding x86 instructions, providing also the functionality of a micro-operation cache. Having this, the next time an instruction is needed, it does not have to be decoded into micro-ops again.<ref name="agner.org" />{{rp|63–68}}
====Write Coalescing Cache (WCC)====
Write Coalescing Cache<ref>{{cite web|url=http://www.realworldtech.com/bulldozer/9/|title=AMD's Bulldozer Microarchitecture - Memory Subsystem Continued|date=August 26, 2010|author=David Kanter|website=Real World Technologies}}</ref> is a special cache that is part of L2 cache in [[AMD]]'s [[Bulldozer (microarchitecture)|Bulldozer microarchitecture]]. Stores from both L1D caches in the module go through the WCC, where they are buffered and coalesced.
The WCC's task is reducing number of writes to the L2 cache.
===={{Anchor|UOP-CACHE}}Micro-operation (μop or uop) cache====
A '''micro-operation cache''' ('''μop cache''', '''uop cache''' or '''UC''')<ref>{{cite web|url=http://www.realworldtech.com/sandy-bridge/4/|title=Intel's Sandy Bridge Microarchitecture - Instruction Decode and uop Cache|date=September 25, 2010|author=David Kanter|website=Real World Technologies}}</ref> is a specialized cache that stores [[micro-operation]]s of decoded instructions, as received directly from the [[instruction decoder]]s or from the instruction cache. When an instruction needs to be decoded, the μop cache is checked for its decoded form which is re-used if cached; if it is not available, the instruction is decoded and then cached.
One of the early works describing μop cache as an alternative frontend for the Intel [[P6 (microarchitecture)|P6 processor family]] is the 2001 paper ''"Micro-Operation Cache: A Power Aware Frontend for Variable Instruction Length ISA"''.<ref name="uop-intel">{{cite book
| chapter-url = http://cecs.uci.edu/~papers/compendium94-03/papers/2001/islped01/pdffiles/p004.pdf
| chapter = Micro-Operation Cache: A Power Aware Frontend for Variable Instruction Length ISA
| author1 = Baruch Solomon | title = ISLPED'01: Proceedings of the 2001 International Symposium on Low Power Electronics and Design (IEEE Cat. No.01TH8581)
| pages = 4–9
| author2 = Avi Mendelson | author3 = Doron Orenstein | author4 = Yoav Almog | author5 = Ronny Ronen
| date = August 2001 | access-date = 2013-10-06
| publisher = [[Intel]] | doi = 10.1109/LPE.2001.945363
| isbn = 978-1-58113-371-4
| s2cid = 195859085
}}</ref> Later, Intel included μop caches in its [[Sandy Bridge]] processors and in successive microarchitectures like [[Ivy Bridge (microarchitecture)|Ivy Bridge]] and [[Haswell (microarchitecture)|Haswell]].<ref name="agner.org">{{cite web
| url = http://www.agner.org/optimize/microarchitecture.pdf
| title = The microarchitecture of Intel, AMD and VIA CPUs: An optimization guide for assembly programmers and compiler makers
| date = 2014-02-19 | access-date = 2014-03-21
| author = Agner Fog |author-link=Agner Fog| website = agner.org
}}</ref>{{rp|121–123}}<ref name="anandtech-haswell">{{cite web
| url = http://www.anandtech.com/show/6355/intels-haswell-architecture/6
| title = Intel's Haswell Architecture Analyzed
| date = 2012-10-05 | access-date = 2013-10-20
| author = Anand Lal Shimpi | publisher = [[AnandTech]]
}}</ref> AMD implemented a μop cache in their [[Zen (microarchitecture)|Zen microarchitecture]].<ref>{{cite web
| url = http://www.anandtech.com/show/10578/amd-zen-microarchitecture-dual-schedulers-micro-op-cache-memory-hierarchy-revealed
| title = AMD Zen Microarchitecture: Dual Schedulers, Micro-Op Cache and Memory Hierarchy Revealed
| date = 2016-08-18 | access-date = 2017-04-03
| author = Ian Cutress | publisher = AnandTech}}</ref>
Fetching complete pre-decoded instructions eliminates the need to repeatedly decode variable length complex instructions into simpler fixed-length micro-operations, and simplifies the process of predicting, fetching, rotating and aligning fetched instructions. A μop cache effectively offloads the fetch and decode hardware, thus decreasing [[power consumption]] and improving the frontend supply of decoded micro-operations. The μop cache also increases performance by more consistently delivering decoded micro-operations to the backend and eliminating various bottlenecks in the CPU's fetch and decode logic.<ref name="uop-intel" /><ref name="anandtech-haswell" />
A μop cache has many similarities with a trace cache, although a μop cache is much simpler thus providing better power efficiency; this makes it better suited for implementations on battery-powered devices. The main disadvantage of the trace cache, leading to its power inefficiency, is the hardware complexity required for its [[heuristic]] deciding on caching and reusing dynamically created instruction traces.<ref name="tc-slides">{{cite web|url=https://www.cs.cmu.edu/afs/cs/academic/class/15740-f03/www/lectures/TraceCache_slides.pdf|title=Trace Cache|date=October 2003|access-date=2013-10-06|author1=Leon Gu|author2=Dipti Motiani}}</ref>
====Branch target instruction cache====
A '''branch target cache''' or '''branch target instruction cache''', the name used on [[ARM microprocessors]],<ref>{{cite web |title=How does the BTIC (branch target instruction cache) work? |url=https://community.arm.com/processors/f/discussions/5320/how-does-the-btic-branch-target-instruction-cache-works |date=28 May 2015 |author=Kun Niu |access-date=7 April 2018}}</ref> is a specialized cache which holds the first few instructions at the destination of a taken branch. This is used by low-powered processors which do not need a normal instruction cache because the memory system is capable of delivering instructions fast enough to satisfy the CPU without one. However, this only applies to consecutive instructions in sequence; it still takes several cycles of latency to restart instruction fetch at a new address, causing a few cycles of pipeline bubble after a control transfer. A branch target cache provides instructions for those few cycles avoiding a delay after most taken branches.
This allows full-speed operation with a much smaller cache than a traditional full-time instruction cache.
====Smart cache====
'''Smart cache''' is a [[#MULTILEVEL|level 2]] or [[#MULTILEVEL|level 3]] caching method for multiple execution cores, developed by [[Intel]].
Smart Cache shares the actual cache memory between the cores of a [[multi-core processor]]. In comparison to a dedicated per-core cache, the overall [[cache miss]] rate decreases when cores do not require equal parts of the cache space. Consequently, a single core can use the full level 2 or level 3 cache while the other cores are inactive.<ref>{{cite web|url=http://www.intel.com/content/www/us/en/architecture-and-technology/intel-smart-cache.html|title=Intel Smart Cache: Demo|publisher=[[Intel]]|access-date=2012-01-26}}</ref> Furthermore, the shared cache makes it faster to share memory among different execution cores.<ref>{{cite web |url=http://software.intel.com/file/18374/ |archive-url=https://web.archive.org/web/20111229193036/http://software.intel.com/file/18374/ |title=Inside Intel Core Microarchitecture and Smart Memory Access |format=PDF |page=5 |publisher=[[Intel]] |year=2006 |access-date=2012-01-26 |archive-date=2011-12-29}}</ref>
==={{Anchor|MULTILEVEL}}Multi-level caches===
{{See also|Cache hierarchy}}
Another issue is the fundamental tradeoff between cache latency and hit rate. Larger caches have better hit rates but longer latency. To address this tradeoff, many computers use multiple levels of cache, with small fast caches backed up by larger, slower caches. Multi-level caches generally operate by checking the fastest cache, ''level 1'' ('''L1'''), first; if it hits, the processor proceeds at high speed. If that smaller cache misses, the next fastest cache, ''level 2'' ('''L2'''), is checked, and so on, before accessing external memory.
As the latency difference between main memory and the fastest cache has become larger, some processors have begun to utilize as many as three levels of on-chip cache. Price-sensitive designs used this to pull the entire cache hierarchy on-chip, but by the 2010s some of the highest-performance designs returned to having large off-chip caches, which is often implemented in [[eDRAM]] and mounted on a [[multi-chip module]], as a fourth cache level. In rare cases, such as in the mainframe CPU [[IBM z15 (microprocessor)|IBM z15]] (2019), all levels down to L1 are implemented by eDRAM, replacing [[static random-access memory|SRAM]] entirely (for cache, SRAM is still used for registers). The [[ARM architecture family|ARM-based]] [[Apple M1]] has a 192 KiB L1 cache for each of the four high-performance cores, an unusually large amount; however the four high-efficiency cores only have 128 KiB.
The benefits of L3 and L4 caches depend on the application's access patterns. Examples of products incorporating L3 and L4 caches include the following:
* [[Alpha 21164]] (1995) has 1 to 64 MiB off-chip L3 cache.
* [[AMD K6-III]] (1999) has motherboard-based L3 cache.
* IBM [[POWER4]] (2001) has off-chip L3 caches of 32 MiB per processor, shared among several processors.
* [[Itanium 2]] (2003) has a 6 MiB [[unified cache|unified]] level 3 (L3) cache on-die; the [[Itanium 2]] (2003) MX 2 module incorporates two Itanium 2 processors along with a shared 64 MiB L4 cache on a [[multi-chip module]] that was pin compatible with a Madison processor.
* Intel's [[Xeon]] MP product codenamed "Tulsa" (2006) features 16 MiB of on-die L3 cache shared between two processor cores.
* [[AMD Phenom]] (2007) with 2 MiB of L3 cache.
* AMD [[Phenom II]] (2008) has up to 6 MiB on-die unified L3 cache.
* [[List of Intel Core i7 processors|Intel Core i7]] (2008) has an 8 MiB on-die unified L3 cache that is inclusive, shared by all cores.
* Intel [[Haswell (microarchitecture)|Haswell]] CPUs with integrated [[Intel Iris Pro Graphics]] have 128 MiB of eDRAM acting essentially as an L4 cache.<ref>{{cite web|url=http://www.anandtech.com/show/6993/intel-iris-pro-5200-graphics-review-core-i74950hq-tested/3 |title=Intel Iris Pro 5200 Graphics Review: Core i7-4950HQ Tested |publisher=AnandTech |access-date=2014-02-25}}</ref>
Finally, at the other end of the memory hierarchy, the CPU [[register file]] itself can be considered the smallest, fastest cache in the system, with the special characteristic that it is scheduled in software—typically by a compiler, as it allocates registers to hold values retrieved from main memory for, as an example, [[loop nest optimization]]. However, with [[register renaming]] most compiler register assignments are reallocated dynamically by hardware at runtime into a register bank, allowing the CPU to break false data dependencies and thus easing pipeline hazards.
Register files sometimes also have hierarchy: The [[Cray-1]] (circa 1976) had eight address "A" and eight scalar data "S" registers that were generally usable. There was also a set of 64 address "B" and 64 scalar data "T" registers that took longer to access, but were faster than main memory. The "B" and "T" registers were provided because the Cray-1 did not have a data cache. (The Cray-1 did, however, have an instruction cache.)
===={{Anchor|LLC}}Multi-core chips====
When considering a chip with [[Multi-core processor|multiple cores]], there is a question of whether the caches should be shared or local to each core. Implementing shared cache inevitably introduces more wiring and complexity. But then, having one cache per ''chip'', rather than ''core'', greatly reduces the amount of space needed, and thus one can include a larger cache.
Typically, sharing the L1 cache is undesirable because the resulting increase in latency would make each core run considerably slower than a single-core chip. However, for the highest-level cache, the last one called before accessing memory, having a global cache is desirable for several reasons, such as allowing a single core to use the whole cache, reducing data redundancy by making it possible for different processes or threads to share cached data, and reducing the complexity of utilized cache coherency protocols.<ref>{{cite web
| url = https://software.intel.com/en-us/articles/software-techniques-for-shared-cache-multi-core-systems
| title = Software Techniques for Shared-Cache Multi-Core Systems
| date = 2012-03-08 | access-date = 2015-11-24
| author1 = Tian Tian | author2 = Chiu-Pi Shih
| publisher = [[Intel]]
}}</ref> For example, an eight-core chip with three levels may include an L1 cache for each core, one intermediate L2 cache for each pair of cores, and one L3 cache shared between all cores.
Shared highest-level cache, which is called before accessing memory, is usually referred to as the ''last level cache'' (LLC). Additional techniques are used for increasing the level of parallelism when LLC is shared between multiple cores, including slicing it into multiple pieces which are addressing certain ranges of memory addresses, and can be accessed independently.<ref>{{cite web
| url = http://www.hotchips.org/wp-content/uploads/hc_archives/hc23/HC23.19.9-Desktop-CPUs/HC23.19.911-Sandy-Bridge-Lempel-Intel-Rev%207.pdf
| title = 2nd Generation Intel Core Processor Family: Intel Core i7, i5 and i3
| date = 2013-07-28
| access-date = 2014-01-21
| author = Oded Lempel
| website = hotchips.org
| page = 7–10,31–45
| archive-date = 2020-07-29
| archive-url = https://web.archive.org/web/20200729000210/http://www.hotchips.org/wp-content/uploads/hc_archives/hc23/HC23.19.9-Desktop-CPUs/HC23.19.911-Sandy-Bridge-Lempel-Intel-Rev%207.pdf
| url-status = dead
}}</ref>
====Separate versus unified====
In a separate cache structure, instructions and data are cached separately, meaning that a cache line is used to cache either instructions or data, but not both; various benefits have been demonstrated with separate data and instruction [[translation lookaside buffer]]s.<ref>{{cite journal |author1=Chen, J. Bradley |author2=Borg, Anita |author3=Jouppi, Norman P. |title=A Simulation Based Study of TLB Performance |journal=SIGARCH Computer Architecture News |volume=20 |issue=2 |year=1992 |page=114–123 |doi=10.1145/146628.139708|doi-access=free }}</ref> In a unified structure, this constraint is not present, and cache lines can be used to cache both instructions and data.
===={{Anchor|INCLUSIVE|EXCLUSIVE}}Exclusive versus inclusive====
Multi-level caches introduce new design decisions. For instance, in some processors, all data in the L1 cache must also be somewhere in the L2 cache. These caches are called ''strictly inclusive''. Other processors (like the [[AMD Athlon]]) have ''exclusive'' caches: data is guaranteed to be in at most one of the L1 and L2 caches, never in both. Still other processors (like the Intel [[Pentium II]], [[Pentium III|III]], and [[Pentium 4|4]]) do not require that data in the L1 cache also reside in the L2 cache, although it may often do so. There is no universally accepted name for this intermediate policy;<ref>{{cite web
| url = http://www.amecomputers.com/explanation-of-the-l1-and-l2-cache.html
| title = Explanation of the L1 and L2 Cache
| access-date = 2014-06-09
| website = amecomputers.com
| archive-date = 2014-07-14
| archive-url = https://web.archive.org/web/20140714181050/http://www.amecomputers.com/explanation-of-the-l1-and-l2-cache.html
| url-status = dead
}}</ref><ref name="ispass04">{{cite conference
| url = http://mercury.pr.erau.edu/~davisb22/papers/ispass04.pdf
| title = Performance Evaluation of Exclusive Cache Hierarchies
| date = 10–12 March 2004 | access-date = 2014-06-09
| author1 = Ying Zheng | author2 = Brian T. Davis | author3 = Matthew Jordan
| conference = IEEE International Symposium on Performance Analysis of Systems and Software
| location = Austin, TX, USA
| doi = 10.1109/ISPASS.2004.1291359
| isbn = 0-7803-8385-0
| pages = 89–96
| url-status = dead
| archive-url = https://web.archive.org/web/20120813003941/http://mercury.pr.erau.edu/~davisb22/papers/ispass04.pdf
| archive-date = 2012-08-13
}}</ref>
two common names are "non-exclusive" and "partially-inclusive".
The advantage of exclusive caches is that they store more data. This advantage is larger when the exclusive L1 cache is comparable to the L2 cache, and diminishes if the L2 cache is many times larger than the L1 cache. When the L1 misses and the L2 hits on an access, the hitting cache line in the L2 is exchanged with a line in the L1. This exchange is quite a bit more work than just copying a line from L2 to L1, which is what an inclusive cache does.<ref name="ispass04" />
One advantage of strictly inclusive caches is that when external devices or other processors in a multiprocessor system wish to remove a cache line from the processor, they need only have the processor check the L2 cache. In cache hierarchies which do not enforce inclusion, the L1 cache must be checked as well. As a drawback, there is a correlation between the associativities of L1 and L2 caches: if the L2 cache does not have at least as many ways as all L1 caches together, the effective associativity of the L1 caches is restricted. Another disadvantage of inclusive cache is that whenever there is an eviction in L2 cache, the (possibly) corresponding lines in L1 also have to get evicted in order to maintain inclusiveness. This is quite a bit of work, and would result in a higher L1 miss rate.<ref name="ispass04" />
Another advantage of inclusive caches is that the larger cache can use larger cache lines, which reduces the size of the secondary cache tags. (Exclusive caches require both caches to have the same size cache lines, so that cache lines can be swapped on a L1 miss, L2 hit.) If the secondary cache is an order of magnitude larger than the primary, and the cache data is an order of magnitude larger than the cache tags, this tag area saved can be comparable to the incremental area needed to store the L1 cache data in the L2.<ref>{{cite web
| url = http://www.jaleels.org/ajaleel/publications/micro2010-tla.pdf
| title = Achieving Non-Inclusive Cache Performance with Inclusive Caches
| date = 2010-09-27 | access-date = 2014-06-09
| author1 = Aamer Jaleel | author2 = Eric Borch | author3 = Malini Bhandaru
| author4 = Simon C. Steely Jr. | author5 = Joel Emer
| website = jaleels.org }}</ref>
===Scratchpad memory===
{{Main|Scratchpad memory}}
[[Scratchpad memory]] (SPM), also known as scratchpad, scratchpad RAM or local store in computer terminology, is a high-speed internal memory used for temporary storage of calculations, data, and other work in progress.
===Example: the K8===
To illustrate both specialization and multi-level caching, here is the cache hierarchy of the K8 core in the AMD [[Athlon 64]] CPU.<ref>{{cite web|url=http://www.sandpile.org/impl/k8.htm |title=AMD K8 |access-date=2007-06-02 |website=Sandpile.org |url-status=dead |archive-url=https://web.archive.org/web/20070515052223/http://www.sandpile.org/impl/k8.htm |archive-date=2007-05-15 }}</ref>
[[File:Cache,hierarchy-example.svg|thumb|center|500px|Cache hierarchy of the K8 core in the AMD Athlon 64 CPU.]]
The K8 has four specialized caches: an instruction cache, an instruction [[translation lookaside buffer|TLB]], a data TLB, and a data cache. Each of these caches is specialized:
* The instruction cache keeps copies of 64-byte lines of memory, and fetches 16 bytes each cycle. Each byte in this cache is stored in ten bits rather than eight, with the extra bits marking the boundaries of instructions (this is an example of predecoding). The cache has only [[parity bit|parity]] protection rather than [[Error-correcting code|ECC]], because parity is smaller and any damaged data can be replaced by fresh data fetched from memory (which always has an up-to-date copy of instructions).
* The instruction TLB keeps copies of page table entries (PTEs). Each cycle's instruction fetch has its virtual address translated through this TLB into a physical address. Each entry is either four or eight bytes in memory. Because the K8 has a variable page size, each of the TLBs is split into two sections, one to keep PTEs that map 4 KiB pages, and one to keep PTEs that map 4 MiB or 2 MiB pages. The split allows the fully associative match circuitry in each section to be simpler. The operating system maps different sections of the virtual address space with different size PTEs.
* The data TLB has two copies which keep identical entries. The two copies allow two data accesses per cycle to translate virtual addresses to physical addresses. Like the instruction TLB, this TLB is split into two kinds of entries.
* The data cache keeps copies of 64-byte lines of memory. It is split into 8 banks (each storing 8 KiB of data), and can fetch two 8-byte data each cycle so long as those data are in different banks. There are two copies of the tags, because each 64-byte line is spread among all eight banks. Each tag copy handles one of the two accesses per cycle.
The K8 also has multiple-level caches. There are second-level instruction and data TLBs, which store only PTEs mapping 4 KiB. Both instruction and data caches, and the various TLBs, can fill from the large '''unified''' L2 cache. This cache is exclusive to both the L1 instruction and data caches, which means that any 8-byte line can only be in one of the L1 instruction cache, the L1 data cache, or the L2 cache. It is, however, possible for a line in the data cache to have a PTE which is also in one of the TLBs—the operating system is responsible for keeping the TLBs coherent by flushing portions of them when the page tables in memory are updated.
The K8 also caches information that is never stored in memory—prediction information. These caches are not shown in the above diagram. As is usual for this class of CPU, the K8 has fairly complex
[[branch prediction]], with tables that help predict whether branches are taken and other tables which predict the targets of branches and jumps. Some of this information is associated with instructions, in both the level 1 instruction cache and the unified secondary cache.
The K8 uses an interesting trick to store prediction information with instructions in the secondary cache. Lines in the secondary cache are protected from accidental data corruption (e.g. by an [[alpha particle]] strike) by either [[Error-correcting code|ECC]] or [[parity (telecommunication)|parity]], depending on whether those lines were evicted from the data or instruction primary caches. Since the parity code takes fewer bits than the ECC code, lines from the instruction cache have a few spare bits. These bits are used to cache branch prediction information associated with those instructions. The net result is that the branch predictor has a larger effective history table, and so has better accuracy.
===More hierarchies===
<!-- (This section should be rewritten.) -->
Other processors have other kinds of predictors (e.g., the store-to-load bypass predictor in the [[Digital Equipment Corporation|DEC]] [[Alpha 21264]]), and various specialized predictors are likely to flourish in future processors.
These predictors are caches in that they store information that is costly to compute. Some of the terminology used when discussing predictors is the same as that for caches (one speaks of a '''hit''' in a branch predictor), but predictors are not generally thought of as part of the cache hierarchy.
The K8 keeps the instruction and data caches '''[[cache coherency|coherent]]''' in hardware, which means that a store into an instruction closely following the store instruction will change that following instruction. Other processors, like those in the Alpha and MIPS family, have relied on software to keep the instruction cache coherent. Stores are not guaranteed to show up in the instruction stream until a program calls an operating system facility to ensure coherency.
===Tag RAM===
In computer engineering, a ''tag RAM'' is used to specify which of the possible memory locations is currently stored in a CPU cache.<ref>{{cite web
| url = http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0363g/Chdijaed.html
| title = Cortex-R4 and Cortex-R4F Technical Reference Manual
| access-date = 2013-09-28
| publisher = arm.com
}}</ref><ref>{{cite web
| url = http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0284g/Ebddefci.html
| title = L210 Cache Controller Technical Reference Manual
| access-date = 2013-09-28
| publisher = arm.com
}}</ref> For a simple, direct-mapped design fast [[static random-access memory|SRAM]] can be used. Higher [[#Associativity|associative caches]] usually employ [[content-addressable memory]].
==Implementation==
{{Main article|Cache algorithms}}
Cache '''reads''' are the most common CPU operation that takes more than a single cycle. Program execution time tends to be very sensitive to the latency of a level-1 data cache hit. A great deal of design effort, and often power and silicon area are expended making the caches as fast as possible.
The simplest cache is a virtually indexed direct-mapped cache. The virtual address is calculated with an adder, the relevant portion of the address extracted and used to index an SRAM, which returns the loaded data. The data is byte aligned in a byte shifter, and from there is bypassed to the next operation. There is no need for any tag checking in the inner loop{{snd}} in fact, the tags need not even be read. Later in the pipeline, but before the load instruction is retired, the tag for the loaded data must be read, and checked against the virtual address to make sure there was a cache hit. On a miss, the cache is updated with the requested cache line and the pipeline is restarted.
An associative cache is more complicated, because some form of tag must be read to determine which entry of the cache to select. An N-way set-associative level-1 cache usually reads all N possible tags and N data in parallel, and then chooses the data associated with the matching tag. Level-2 caches sometimes save power by reading the tags first, so that only one data element is read from the data SRAM.
[[Image:Cache,associative-read.svg|thumb|right|upright=1.8|Read path for a 2-way associative cache]]
The adjacent diagram is intended to clarify the manner in which the various fields of the address are used. Address bit 31 is most significant, bit 0 is least significant. The diagram shows the SRAMs, indexing, and [[multiplexing]] for a 4 KiB, 2-way set-associative, virtually indexed and virtually tagged cache with 64 byte (B) lines, a 32-bit read width and 32-bit virtual address.
Because the cache is 4 KiB and has 64 B lines, there are just 64 lines in the cache, and we read two at a time from a Tag SRAM which has 32 rows, each with a pair of 21 bit tags. Although any function of virtual address bits 31 through 6 could be used to index the tag and data SRAMs, it is simplest to use the least significant bits.
Similarly, because the cache is 4 KiB and has a 4 B read path, and reads two ways for each access, the Data SRAM is 512 rows by 8 bytes wide.
A more modern cache might be 16 KiB, 4-way set-associative, virtually indexed, virtually hinted, and physically tagged, with 32 B lines, 32-bit read width and 36-bit physical addresses. The read path recurrence for such a cache looks very similar to the path above. Instead of tags, vhints are read, and matched against a subset of the virtual address. Later on in the pipeline, the virtual address is translated into a physical address by the TLB, and the physical tag is read (just one, as the vhint supplies which way of the cache to read). Finally the physical address is compared to the physical tag to determine if a hit has occurred.
Some SPARC designs have improved the speed of their L1 caches by a few gate delays by collapsing the virtual address adder into the SRAM decoders. See [[sum-addressed decoder]].
===History===
The early history of cache technology is closely tied to the invention and use of virtual memory.{{Citation needed|date=March 2008}} <!-- this *is* a truly interesting observation, but are there any sources? Also why was the "CPU-mam speed" part deleted? ~~~~ --> Because of scarcity and cost of semi-conductor memories, early mainframe computers in the 1960s used a complex hierarchy of physical memory, mapped onto a flat virtual memory space used by programs. The memory technologies would span semi-conductor, magnetic core, drum and disc. Virtual memory seen and used by programs would be flat and caching would be used to fetch data and instructions into the fastest memory ahead of processor access. Extensive studies were done to optimize the cache sizes. Optimal values were found to depend greatly on the programming language used with Algol needing the smallest and Fortran and Cobol needing the largest cache sizes.{{Disputed inline|Talk:CPU cache#Dispute sequence of events for paging|reason=sequence of events wrong|date=December 2010}}
In the early days of microcomputer technology, memory access was only slightly slower than [[processor register|register]] access. But since the 1980s<ref>{{cite journal | url=https://epic.hpi.uni-potsdam.de/pub/Home/TrendsAndConceptsII2010/HW_Trends_The_Processor-Memory_bottleneck___Problems_and_Solutions..pdf | title=The processor-memory bottleneck: problems and solutions | journal=Crossroads | volume=5 | issue=3es | pages=2–es | first1=Nihar R. | last1=Mahapatra | first2=Balakrishna | last2=Venkatrao | access-date=2013-03-05 | doi=10.1145/357783.331677 | year=1999 | s2cid=11557476 | url-status=dead | archive-url=https://web.archive.org/web/20140305193233/https://epic.hpi.uni-potsdam.de/pub/Home/TrendsAndConceptsII2010/HW_Trends_The_Processor-Memory_bottleneck___Problems_and_Solutions..pdf | archive-date=2014-03-05 }}</ref> the performance gap between processor and memory has been growing. Microprocessors have advanced much faster than memory, especially in terms of their operating [[frequency]], so memory became a performance [[Von Neumann architecture#Von Neumann bottleneck|bottleneck]]. While it was technically possible to have all the main memory as fast as the CPU, a more economically viable path has been taken: use plenty of low-speed memory, but also introduce a small high-speed cache memory to alleviate the performance gap. This provided an order of magnitude more capacity—for the same price—with only a slightly reduced combined performance.
====First TLB implementations====
The first documented uses of a TLB were on the [[GE 645]]<ref>{{cite book
| publisher = [[General Electric]]
| title = GE-645 System Manual
| date = January 1968
| url = http://bitsavers.org/pdf/ge/GE-645/LSB0468_GE-645_System_Manual_Jan1968.pdf
| access-date = 2020-07-10
}}</ref> and the [[IBM]] [[IBM System/360 Model 67|360/67]],<ref>{{cite book
|publisher = [[IBM]]
|title = IBM System/360 Model 67 Functional Characteristics
|id = GA27-2719-2
|url = http://www.bitsavers.org/pdf/ibm/360/functional_characteristics/GA27-2719-2_360-67_funcChar.pdf
|version = Third Edition
|date = February 1972
}}</ref> both of which used an associative memory as a TLB.
====First instruction cache====
The first documented use of an instruction cache was on the [[CDC 6600]].<ref>{{citation
| author = James E. Thornton
| contribution = Parallel operation in the control data 6600
| contribution-url = https://cs.uwaterloo.ca/~mashti/cs850-f18/papers/cdc6600.pdf
| title = Proc. of the October 27-29, 1964, fall joint computer conference, part II: very high speed computer systems
| date = October 1964}}</ref>
====First data cache====
The first documented use of a data cache was on the [[IBM]] System/360 Model 85.<ref>{{cite book
| author = IBM
| title = IBM System/360 Model 85 Functional Characteristics
| id = A22-6916-1
| url = http://www.bitsavers.org/pdf/ibm/360/functional_characteristics/A22-6916-1_360-85_funcChar_Jun68.pdf
| version = SECOND EDITION
| date = June 1968}}</ref>
====In 68k microprocessors====
The [[68010]], released in 1982, has a "loop mode" which can be considered a tiny and special-case instruction cache that accelerates loops that consist of only two instructions. The [[68020]], released in 1984, replaced that with a typical instruction cache of 256 bytes, being the first 68k series processor to feature true on-chip cache memory.
The [[68030]], released in 1987, is basically a 68020 core with an additional 256-byte data cache, an on-chip [[memory management unit]] (MMU), a process shrink, and added burst mode for the caches. The [[Motorola 68040|68040]], released in 1990, has split instruction and data caches of four kilobytes each. The [[68060]], released in 1994, has the following: 8 KiB data cache (four-way associative), 8 KiB instruction cache (four-way associative), 96-byte FIFO instruction buffer, 256-entry branch cache, and 64-entry address translation cache MMU buffer (four-way associative).
====In x86 microprocessors====
[[File:Motherboard Intel 386.jpg|thumb|Example of a motherboard with an [[i386]] microprocessor (33 MHz), 64 KiB cache (25 ns; 8 chips in the bottom left corner), 2 MiB DRAM (70 ns; 8 [[SIMM]]s to the right of the cache), and a cache controller ([[Austek Microsystems|Austek]] A38202; to the right of the processor)]]
As the [[x86]] microprocessors reached clock rates of 20 MHz and above in the [[Intel 80386|386]], small amounts of fast cache memory began to be featured in systems to improve performance. This was because the [[DRAM]] used for main memory had significant latency, up to 120 ns, as well as refresh cycles. The cache was constructed from more expensive, but significantly faster, [[static random-access memory|SRAM]] [[Memory cell (computing)|memory cells]], which at the time had latencies around 10–25 ns. The early caches were external to the processor and typically located on the motherboard in the form of eight or nine [[Dual in-line package|DIP]] devices placed in sockets to enable the cache as an optional extra or upgrade feature.
Some versions of the Intel 386 processor could support 16 to 256 KiB of external cache.
With the [[Intel 80486|486]] processor, an 8 KiB cache was integrated directly into the CPU die. This cache was termed Level 1 or L1 cache to differentiate it from the slower on-motherboard, or Level 2 (L2) cache. These on-motherboard caches were much larger, with the most common size being 256 KiB. The popularity of on-motherboard cache continued through the [[Intel P5|Pentium MMX]] era but was made obsolete by the introduction of [[SDRAM]] and the growing disparity between bus clock rates and CPU clock rates, which caused on-motherboard cache to be only slightly faster than main memory.
The next development in cache implementation in the x86 microprocessors began with the [[Pentium Pro]], which brought the secondary cache onto the same package as the microprocessor, clocked at the same frequency as the microprocessor.
On-motherboard caches enjoyed prolonged popularity thanks to the [[AMD K6-2]] and [[AMD K6-III]] processors that still used [[Socket 7]], which was previously used by Intel with on-motherboard caches. K6-III included 256 KiB on-die L2 cache and took advantage of the on-board cache as a third level cache, named L3 (motherboards with up to 2 MiB of on-board cache were produced). After the Socket 7 became obsolete, on-motherboard cache disappeared from the x86 systems.
The three-level caches were used again first with the introduction of multiple processor cores, where the L3 cache was added to the CPU die. It became common for the total cache sizes to be increasingly larger in newer processor generations, and recently (as of 2011) it is not uncommon to find Level 3 cache sizes of tens of megabytes.<ref>{{cite web
| url = http://ark.intel.com/products/family/59139/Intel-Xeon-Processor-E7-Family/server
| title = Intel® Xeon® Processor E7 Family
| access-date = 2013-10-10
| publisher = [[Intel]]
}}</ref>
[[Intel]] introduced a Level 4 on-package cache with the [[Haswell (microarchitecture)|Haswell]] [[microarchitecture]]. ''[[Crystalwell]]''<ref name="intel-ark-crystal-well" /> Haswell CPUs, equipped with the [[GT3e]] variant of Intel's integrated Iris Pro graphics, effectively feature 128 MiB of embedded DRAM ([[eDRAM]]) on the same package. This L4 cache is shared dynamically between the on-die GPU and CPU, and serves as a [[victim cache]] to the CPU's L3 cache.<ref name="anandtech-i74950hq" />
====In ARM microprocessors====
[[Apple M1]] CPU has 128 or 192 KiB instruction L1 cache for each core (important for latency/single-thread performance), depending on core type. This is an unusually large L1 cache for any CPU type (not just for a laptop); the total cache memory size is not unusually large (the total is more important for throughput) for a laptop, and much larger total (e.g. L3 or L4) sizes are available in IBM's mainframes.
====Current research====
Early cache designs focused entirely on the direct cost of cache and [[random-access memory|RAM]] and average execution speed.
More recent cache designs also consider [[low-power electronics|energy efficiency]], fault tolerance, and other goals.<ref>{{cite journal
|url=https://spectrum.ieee.org/computing/hardware/chip-design-thwarts-sneak-attack-on-data
|title=Chip Design Thwarts Sneak Attack on Data
|author=Sally Adee
|year=2009
|journal= <!-- This is needed for ‘cite journal’ citation templates - should this be ‘cite news’ instead? (delete note when fixed) -->
}}</ref><ref>{{cite conference|url=http://palms.princeton.edu/system/files/Micro08_Newcache.pdf|title=A novel cache architecture with enhanced performance and security|author1=Zhenghong Wang|author2=Ruby B. Lee|conference=41st annual IEEE/ACM International Symposium on Microarchitecture|pages=83–93|date=November 8–12, 2008|archive-url=https://web.archive.org/web/20120306225926/http://palms.princeton.edu/system/files/Micro08_Newcache.pdf|archive-date=March 6, 2012
| url-status=live
}}</ref>
There are several tools available to computer architects to help explore tradeoffs between the cache cycle time, energy, and area; the CACTI cache simulator<ref>{{cite web|url=https://www.hpl.hp.com/research/cacti/ |title=CACTI |website=HP Labs |access-date=2023-01-29}}</ref> and the SimpleScalar instruction set simulator are two open-source options.
===Multi-ported cache===
A multi-ported cache is a cache which can serve more than one request at a time. When accessing a traditional cache we normally use a single memory address, whereas in a multi-ported cache we may request N addresses at a time{{snd}} where N is the number of ports that connected through the processor and the cache. The benefit of this is that a pipelined processor may access memory from different phases in its pipeline. Another benefit is that it allows the concept of super-scalar processors through different cache levels.
==See also==
{{Div col|colwidth=30em}}
* [[Branch predictor]]
* [[Cache (computing)]]
* [[Cache algorithms]]
* [[Cache coherence]]
* [[Cache control instruction]]s
* [[Cache hierarchy]]
* [[Cache placement policies]]
* [[Cache prefetching]]
* [[Dinero (cache simulator)|Dinero]] (cache simulator by [[University of Wisconsin System]])
* [[Instruction unit]]
* [[Locality of reference]]
* [[Memoization]]
* [[Memory hierarchy]]
* [[Micro-operation]]
* [[No-write allocation]]
* [[Scratchpad RAM]]
* [[Sum-addressed decoder]]
* [[Write buffer]]
{{Div col end}}
==Notes==
{{Reflist|group=NB}}
==References==
{{Reflist|30em|refs=
<ref name=AtlasSup>
{{cite book
| last1 = Kilburn
| first1 = T.
| last2 = Payne
| first2 = R. B.
| last3 = Howarth
| first3 = D. J.
| title = Computers - Key to Total Systems Control
| series = Conferences Proceedings
| pages = 279–294
| chapter = The Atlas Supervisor
| chapter-url = http://www.chilton-computing.org.uk/acl/technology/atlas/p019.htm
| volume = 20 Proceedings of the Eastern Joint Computer Conference Washington, D.C.
|date=December 1961
| publisher = Macmillan}}
</ref>
<ref name=AtlasCPU>
{{cite book
| last1 = Sumner
| first1 = F. H.
| last2 = Haley
| first2 = G.
| last3 = Chenh
| first3 = E. C. Y.
| title = Information Processing 1962
| series = IFIP Congress Proceedings
| chapter = The Central Control Unit of the 'Atlas' Computer
| volume = Proceedings of IFIP Congress 62
| year = 1962
| publisher = Spartan}}
</ref>
}}
==External links==
{{wikibooks
|1= Microprocessor Design
|2= Cache
}}
* [https://lwn.net/Articles/252125/ Memory part 2: CPU caches]{{snd}} an article on lwn.net by Ulrich Drepper describing CPU caches in detail
* [https://minds.wisconsin.edu/bitstream/handle/1793/59076/TR823.pdf Evaluating Associativity in CPU Caches] – Hill and Smith (1989) – introduces capacity, conflict, and compulsory classification
* [http://www.cs.wisc.edu/multifacet/misc/spec2000cache-data/ Cache Performance for SPEC CPU2000 Benchmarks] – Hill and Cantin (2003) – This reference paper has been updated several times. It has thorough and lucidly presented simulation results for a reasonably wide set of benchmarks and cache organizations.
* [http://www.sun.com/blueprints/1102/817-0742.pdf Memory Hierarchy in Cache-Based Systems] {{Webarchive|url=https://web.archive.org/web/20090915041601/http://www.sun.com/blueprints/1102/817-0742.pdf |date=2009-09-15 }} – by Ruud van der Pas, 2002, Sun Microsystems – a nice introductory article to CPU memory caching
* [http://www.freescale.com/files/32bit/doc/app_note/AN2663.pdf A Cache Primer] – by Paul Genua, P.E., 2004, Freescale Semiconductor, another introductory article
* [https://web.archive.org/web/20110718154522/http://www.zipcores.com/skin1/zipdocs/datasheets/cache_8way_set.pdf An 8-way set-associative cache]{{snd}} written in [[VHDL]]
* [https://arstechnica.com/old/content/2002/07/caching.ars Understanding CPU caching and performance]{{snd}} an article on Ars Technica by Jon Stokes
* [http://ixbtlabs.com/articles/ibmpower4/ IBM POWER4 processor review]{{snd}} an article on ixbtlabs by Pavel Danilov
*[https://www.kivabe.in/2020/07/Cache-memory-ki.html/ What is Cache Memory and its Types!]
* [https://www.cs.princeton.edu/courses/archive/fall15/cos375/lectures/16-Cache-2x2.pdf Memory Caching]{{snd}} a Princeton University lecture
{{CPU technologies|state=collapsed}}
{{DEFAULTSORT:Cpu Cache}}
[[Category:Central processing unit]]
[[Category:Computer memory]]
[[Category:Cache (computing)]]' |
New page wikitext, after the edit (new_wikitext ) | 'coputer go brrrrrrrrrrrrrrrr' |
Unified diff of changes made by edit (edit_diff ) | '@@ -1,624 +1,1 @@
-{{Short description|Hardware cache of a central processing unit}}
-A '''CPU cache''' is a [[hardware cache]] used by the [[central processing unit]] (CPU) of a [[computer]] to reduce the average cost (time or energy) to access [[data (computer science)|data]] from the [[main memory]].<ref>{{cite web|url=http://www.hardwaresecrets.com/how-the-cache-memory-works/|title=How The Cache Memory Works|author=Gabriel Torres|date=September 12, 2007}}</ref> A cache is a smaller, faster memory, located closer to a [[processor core]], which stores copies of the data from frequently used main [[memory location]]s. Most CPUs have a hierarchy of multiple cache [[#MULTILEVEL|levels]] (L1, L2, often L3, and rarely even L4), with different instruction-specific and data-specific caches at level 1.<ref>{{Cite journal |last1=Su |first1=Chao |last2=Zeng |first2=Qingkai |date=2021-06-10 |editor-last=Nicopolitidis |editor-first=Petros |title=Survey of CPU Cache-Based Side-Channel Attacks: Systematic Analysis, Security Models, and Countermeasures |journal=Security and Communication Networks |language=en |volume=2021 |pages=1–15 |doi=10.1155/2021/5559552 |issn=1939-0122|doi-access=free }}</ref> The cache memory is typically implemented with [[static random-access memory]] (SRAM), in modern CPUs by far the largest part of them by chip area, but SRAM is not always used for all levels (of I- or D-cache), or even any level, sometimes some latter or all levels are implemented with [[eDRAM]].
-
-Other types of caches exist (that are not counted towards the "cache size" of the most important caches mentioned above), such as the [[translation lookaside buffer]] (TLB) which is part of the [[memory management unit]] (MMU) which most CPUs have.
-
-=={{Anchor|ICACHE|DCACHE|instruction cache|data cache}}Overview==
-When trying to read from or write to a location in the main memory, the processor checks whether the data from that location is already in the cache. If so, the processor will read from or write to the cache instead of the much slower main memory.
-
-Many modern [[desktop computer|desktop]], [[server (computing)|server]], and industrial CPUs have at least three independent caches:
-
-; Instruction cache: Used to speed up executable instruction fetch
-; Data cache: Used to speed up data fetch and store; the data cache is usually organized as a hierarchy of more cache levels (L1, L2, etc.; see also [[#Multi-level caches|multi-level caches]] below).
-; [[Translation lookaside buffer]] (TLB): Used to speed up virtual-to-physical address translation for both executable instructions and data. A single TLB can be provided for access to both instructions and data, or a separate Instruction TLB (ITLB) and data TLB (DTLB) can be provided. However, the TLB cache is part of the [[memory management unit]] (MMU) and not directly related to the CPU caches.
-
-==History==
-[[File:NeXTcube motherboard.jpg|thumb|[[Motherboard]] of a [[NeXTcube]] computer (1990). At the lower edge of the image left from the middle, there is the CPU [[Motorola 68040]] operated at 25 [[MHz]] with two separate level 1 caches of 4 KiB each on the chip, one for the instructions and one for data. The board has no external L2 cache.]]
-Early examples of CPU caches include the [[Titan (1963 computer)|Atlas 2]]<ref>{{cite web|url=http://www.chilton-computing.org.uk/acl/technology/atlas50th/p005.htm|title=Atlas 2 at Cambridge Mathematical Laboratory (and Aldermaston and CAD Centre)|date=November 2012|quote=Two tunnel diode stores were developed at Cambridge; one, which worked very well, speeded up the fetching of operands, the other was intended to speed up the fetching of instructions. The idea was that most instructions are obeyed in sequence, so when an instruction was fetched that word was placed in the slave store in the location given by the fetch address modulo 32; the remaining bits of the fetch address were also stored. If the wanted word was in the slave it was read from there instead of main memory. This would give a major speedup to instruction loops up to 32 instructions long, and reduced effect for loops up to 64 words.}}</ref> and the [[IBM System/360 Model 85]]<ref>{{cite web|url=http://www.bitsavers.org/pdf/ibm/360/functional_characteristics/A22-6916-1_360-85_funcChar_Jun68.pdf|title=IBM System/360 Model 85 Functional Characteristics|publisher=[[IBM]]|id=A22-6916-1|date=June 1968}}</ref> in the 1960s. The first CPUs that used a cache had only one level of cache; unlike later level 1 cache, it was not split into L1d (for data) and L1i (for instructions). Split L1 cache started in 1976 with the [[IBM 801]] CPU,<ref>{{cite journal|url=http://home.eng.iastate.edu/~zzhang/courses/cpre585-f03/reading/smith-csur82-cache.pdf|title=Cache Memories|first=Alan Jay|last=Smith|journal=Computing Surveys|volume=14|issue=3|date=September 1982|pages=473–530|doi=10.1145/356887.356892|s2cid=6023466}}</ref><ref>{{cite journal|title=Altering Computer Architecture is Way to Raise Throughput, Suggests IBM Researchers|journal=[[Electronics (magazine)|Electronics]]|volume=49|issue=25|date=December 23, 1976|pages=30–31}}</ref> became mainstream in the late 1980s, and in 1997 entered the embedded CPU market with the ARMv5TE. In 2015, even sub-dollar SoCs split the L1 cache. They also have L2 caches and, for larger processors, L3 caches as well. The L2 cache is usually not split, and acts as a common repository for the already split L1 cache. Every core of a [[multi-core processor]] has a dedicated L1 cache and is usually not shared between the cores. The L2 cache, and higher-level caches, may be shared between the cores. L4 cache is currently uncommon, and is generally [[dynamic random-access memory]] (DRAM) on a separate die or chip, rather than [[static random-access memory]] (SRAM). An exception to this is when [[eDRAM]] is used for all levels of cache, down to L1. Historically L1 was also on a separate die, however bigger die sizes have allowed integration of it as well as other cache levels, with the possible exception of the last level. Each extra level of cache tends to be bigger and optimized differently.
-
-Caches (like for RAM historically) have generally been sized in powers of: 2, 4, 8, 16 etc. [[Kibibyte|KiB]]; when up to [[Mebibyte|MiB]] sizes (i.e. for larger non-L1), very early on the pattern broke down, to allow for larger caches without being forced into the doubling-in-size paradigm, with e.g. [[Intel Core 2 Duo]] with 3 MiB L2 cache in April 2008. This happened much later for L1 caches, as their size is generally still a small number of KiB. The [[IBM zEC12 (microprocessor)|IBM zEC12]] from 2012 is an exception however, to gain unusually large 96 KiB L1 data cache for its time, and e.g. the [[IBM z13 (microprocessor)|IBM z13]] having a 96 KiB L1 instruction cache (and 128 KiB L1 data cache),<ref>{{cite web|url=https://www.redbooks.ibm.com/redbooks/pdfs/sg248250.pdf|title=IBM z13 and IBM z13s Technical Introduction|page=20|date=March 2016|publisher=[[IBM]]}}</ref> and Intel [[Ice Lake (microprocessor)|Ice Lake]]-based processors from 2018, having 48 KiB L1 data cache and 48 KiB L1 instruction cache. In 2020, some [[Intel Atom]] CPUs (with up to 24 cores) have (multiple of) 4.5 MiB and 15 MiB cache sizes.<ref>{{Cite press release|url=https://newsroom.intel.com/news/product-fact-sheet-accelerating-5g-network-infrastructure-core-edge/|title=Product Fact Sheet: Accelerating 5G Network Infrastructure, from the Core to the Edge|website=Intel Newsroom|quote=L1 cache of 32KB/core, L2 cache of 4.5MB per 4-core cluster and shared LLC cache up to 15MB.|language=en-US|access-date=2020-04-12}}</ref><ref>{{Cite web|url=https://www.anandtech.com/show/15544/intel-launches-atom-p5900-a-10nm-atom-for-radio-access-networks|title=Intel Launches Atom P5900: A 10nm Atom for Radio Access Networks|last=Smith|first=Ryan|website=www.anandtech.com|access-date=2020-04-12}}</ref>
-
-==={{Anchor|cache lines|CACHE-LINES}}Cache entries===
-Data is transferred between memory and cache in blocks of fixed size, called ''cache lines'' or ''cache blocks''. When a cache line is copied from memory into the cache, a cache entry is created. The cache entry will include the copied data as well as the requested memory location (called a tag).
-
-When the processor needs to read or write a location in memory, it first checks for a corresponding entry in the cache. The cache checks for the contents of the requested memory location in any cache lines that might contain that address. If the processor finds that the memory location is in the cache, a '''cache hit''' has occurred. However, if the processor does not find the memory location in the cache, a '''cache miss''' has occurred. In the case of a cache hit, the processor immediately reads or writes the data in the cache line. For a cache miss, the cache allocates a new entry and copies data from main memory, then the request is fulfilled from the contents of the cache.
-
-===Policies===
-
-===={{Anchor|EVICTION}}Replacement policies====
-{{Main article|Cache replacement policies}}
-
-To make room for the new entry on a cache miss, the cache may have to evict one of the existing entries. The heuristic it uses to choose the entry to evict is called the replacement policy. The fundamental problem with any replacement policy is that it must predict which existing cache entry is least likely to be used in the future. Predicting the future is difficult, so there is no perfect method to choose among the variety of replacement policies available. One popular replacement policy, [[least-recently used]] (LRU), replaces the least recently accessed entry.
-
-Marking some memory ranges as non-cacheable can improve performance, by avoiding caching of memory regions that are rarely re-accessed. This avoids the overhead of loading something into the cache without having any reuse. Cache entries may also be disabled or locked depending on the context.
-
-====Write policies====
-{{Main article|Cache (computing)#WRITEPOLICIES|l1=Cache (computing) § Writing policies}}
-
-If data is written to the cache, at some point it must also be written to main memory; the timing of this write is known as the write policy. In a [[write-through]] cache, every write to the cache causes a write to main memory. Alternatively, in a [[write-back]] or copy-back cache, writes are not immediately mirrored to the main memory, and the cache instead tracks which locations have been written over, marking them as [[Dirty bit|dirty]]. The data in these locations is written back to the main memory only when that data is evicted from the cache. For this reason, a read miss in a write-back cache may sometimes require two memory accesses to service: one to first write the dirty location to main memory, and then another to read the new location from memory. Also, a write to a main memory location that is not yet mapped in a write-back cache may evict an already dirty location, thereby freeing that cache space for the new memory location.
-
-There are intermediate policies as well. The cache may be write-through, but the writes may be held in a store data queue temporarily, usually so multiple stores can be processed together (which can reduce bus turnarounds and improve bus utilization).
-
-Cached data from the main memory may be changed by other entities (e.g., peripherals using [[direct memory access]] (DMA) or another core in a [[multi-core processor]]), in which case the copy in the cache may become out-of-date or stale. Alternatively, when a CPU in a [[multiprocessor]] system updates data in the cache, copies of data in caches associated with other CPUs become stale. Communication protocols between the cache managers that keep the data consistent are known as [[cache coherence]] protocols.
-
-===Cache performance===
-[[Cache performance measurement and metric|Cache performance measurement]] has become important in recent times where the speed gap between the memory performance and the processor performance is increasing exponentially. The cache was introduced to reduce this speed gap. Thus knowing how well the cache is able to bridge the gap in the speed of processor and memory becomes important, especially in high-performance systems. The cache hit rate and the cache miss rate play an important role in determining this performance. To improve the cache performance, reducing the miss rate becomes one of the necessary steps among other steps. Decreasing the access time to the cache also gives a boost to its performance.
-
-====CPU stalls====
-The time taken to fetch one cache line from memory (read [[Latency (engineering)|latency]] due to a cache miss) matters because the CPU will run out of things to do while waiting for the cache line. When a CPU reaches this state, it is called a stall. As CPUs become faster compared to main memory, stalls due to cache misses displace more potential computation; modern CPUs can execute hundreds of instructions in the time taken to fetch a single cache line from main memory.
-
-Various techniques have been employed to keep the CPU busy during this time, including [[out-of-order execution]] in which the CPU attempts to execute independent instructions after the instruction that is waiting for the cache miss data. Another technology, used by many processors, is [[simultaneous multithreading]] (SMT), which allows an alternate thread to use the CPU core while the first thread waits for required CPU resources to become available.
-
-==Associativity==
-[[Image:Cache,associative-fill-both.png|thumb|450px|An illustration of different ways in which memory locations can be cached by particular cache locations]]
-{{Main|Cache placement policies}}
-The [[Cache placement policies|placement policy]] decides where in the cache a copy of a particular entry of main memory will go. If the placement policy is free to choose any entry in the cache to hold the copy, the cache is called ''fully associative''. At the other extreme, if each entry in the main memory can go in just one place in the cache, the cache is ''direct-mapped''. Many caches implement a compromise in which each entry in the main memory can go to any one of N places in the cache, and are described as N-way set associative.<ref>{{cite web|url=https://cseweb.ucsd.edu/classes/fa10/cse240a/pdf/08/CSE240A-MBT-L15-Cache.ppt.pdf|title=Cache design|date=2010-12-02|website=ucsd.edu|page=10–15|access-date=2023-01-29}}</ref> For example, the level-1 data cache in an [[AMD Athlon]] is two-way set associative, which means that any particular location in main memory can be cached in either of two locations in the level-1 data cache.
-
-Choosing the right value of associativity involves a [[trade-off]]. If there are ten places to which the placement policy could have mapped a memory location, then to check if that location is in the cache, ten cache entries must be searched. Checking more places takes more power and chip area, and potentially more time. On the other hand, caches with more associativity suffer fewer misses (see [[Cache performance measurement and metric#Conflict misses|conflict misses]]), so that the CPU wastes less time reading from the slow main memory. The general guideline is that doubling the associativity, from direct mapped to two-way, or from two-way to four-way, has about the same effect on raising the hit rate as doubling the cache size. However, increasing associativity more than four does not improve hit rate as much,<ref>[http://ieeexplore.ieee.org/xpl/freeabs_all.jsp?arnumber=5234663 IEEE Xplore - Phased set-associative cache design for reduced power consumption]. Ieeexplore.ieee.org (2009-08-11). Retrieved on 2013-07-30.</ref> and are generally done for other reasons (see [[#Virtual aliasing|virtual aliasing]]). Some CPUs can dynamically reduce the associativity of their caches in low-power states, which acts as a power-saving measure.<ref>{{cite web|url=http://hotchips.org/wp-content/uploads/hc_archives/hc24/HC24-1-Microprocessor/HC24.28.117-HotChips_IvyBridge_Power_04.pdf#page=18|title=Power Management of the Third Generation Intel Core Micro Architecture formerly codenamed Ivy Bridge|author1=Sanjeev Jahagirdar|author2=Varghese George|year=2012|website=hotchips.org|page=18|format=PDF|access-date=2015-12-16|author3=Inder Sodhi|author4=Ryan Wells|archive-date=2020-07-29|archive-url=https://web.archive.org/web/20200729002711/http://hotchips.org/wp-content/uploads/hc_archives/hc24/HC24-1-Microprocessor/HC24.28.117-HotChips_IvyBridge_Power_04.pdf#page=18|url-status=dead}}</ref>
-
-<!-- where does "pseudo-associative cache" go in this spectrum? -->
-In order of worse but simple to better but complex:
-
-* Direct mapped cache{{snd}} good best-case time, but unpredictable in the worst case
-* Two-way set associative cache
-* Two-way skewed associative cache<ref name="Seznec">{{cite journal|author=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>
-* Four-way set-associative cache
-* Eight-way set-associative cache, a common choice for later implementations
-* 12-way set associative cache, similar to eight-way
-* Fully associative cache{{snd}} the best miss rates, but practical only for a small number of entries
-
-===Direct-mapped cache===
-In this cache organization, each location in the main memory can go in only one entry in the cache. Therefore, a direct-mapped cache can also be called a "one-way set associative" cache. It does not have a placement policy as such, since there is no choice of which cache entry's contents to evict. This means that if two locations map to the same entry, they may continually knock each other out. Although simpler, a direct-mapped cache needs to be much larger than an associative one to give comparable performance, and it is more unpredictable. Let {{mvar|x}} be block number in cache, {{mvar|y}} be block number of memory, and {{mvar|n}} be number of blocks in cache, then mapping is done with the help of the equation {{math|''x'' {{=}} ''y'' mod ''n''}}.
-
-===Two-way set associative cache===
-If each location in the main memory can be cached in either of two locations in the cache, one logical question is: ''which one of the two?'' The simplest and most commonly used scheme, shown in the right-hand diagram above, is to use the least significant bits of the memory location's index as the index for the cache memory, and to have two entries for each index. One benefit of this scheme is that the tags stored in the cache do not have to include that part of the main memory address which is implied by the cache memory's index. Since the cache tags have fewer bits, they require fewer transistors, take less space on the processor circuit board or on the microprocessor chip, and can be read and compared faster. Also [[Cache algorithms|LRU]] is especially simple since only one bit needs to be stored for each pair.
-
-===Speculative execution===
-One of the advantages of a direct-mapped cache is that it allows simple and fast [[speculative execution|speculation]]. Once the address has been computed, the one cache index which might have a copy of that location in memory is known. That cache entry can be read, and the processor can continue to work with that data before it finishes checking that the tag actually matches the requested address.
-
-The idea of having the processor use the cached data before the tag match completes can be applied to associative caches as well. A subset of the tag, called a ''hint'', can be used to pick just one of the possible cache entries mapping to the requested address. The entry selected by the hint can then be used in parallel with checking the full tag. The hint technique works best when used in the context of address translation, as explained below.
-
-===Two-way skewed associative cache===
-Other schemes have been suggested, such as the ''skewed cache'',<ref name="Seznec" /> 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|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>
-{{cite web |url=https://www.irisa.fr/caps/PROJECTS/Architecture/ |title=Micro-Architecture] |quote=Skewed-associative caches have been shown to have two major advantages over conventional set-associative caches.}}</ref>
-
-===Pseudo-associative cache===
-A true set-associative cache tests all the possible ways simultaneously, using something like a [[content-addressable memory]]. A pseudo-associative cache tests each possible way one at a time. A hash-rehash cache and a column-associative cache are examples of a pseudo-associative cache.
-
-In the common case of finding a hit in the first way tested, a pseudo-associative cache is as fast as a direct-mapped cache, but it has a much lower conflict miss rate than a direct-mapped cache, closer to the miss rate of a fully associative cache.
-<ref name="CK" />
-
-===Multicolumn cache===
-Comparing with a direct-mapped cache, a set associative cache has a reduced number of bits for its cache set index that maps to a cache set, where multiple ways or blocks stays, such as 2 blocks for a 2-way set associative cache and 4 blocks for a 4-way set associative cache. Comparing with a direct mapped cache, the unused cache index bits become a part of the tag bits. For example, a 2-way set associative cache contributes 1 bit to the tag and a 4-way set associative cache contributes 2 bits to the tag. The basic idea of the multicolumn cache<ref name="Two-fast">{{Cite journal |author1= Chenxi Zhang |author2 =Xiaodong Zhang |author3= Yong Yan| title=Two fast and high-associativity cache schemes |journal= IEEE Micro |volume= 17 |issue= 5 | date= September–October 1997 |pages = 40–49 |doi= 10.1109/40.621212}}</ref> is to use the set index to map to a cache set as a conventional set associative cache does, and to use the added tag bits to index a way in the set. For example, in a 4-way set associative cache, the two bits are used to index way 00, way 01, way 10, and way 11, respectively. This double cache indexing is called a “major location mapping”, and its latency is equivalent to a direct-mapped access. Extensive experiments in multicolumn cache design<ref name="Two-fast" /> shows that the hit ratio to major locations is as high as 90%. If cache mapping conflicts with a cache block in the major location, the existing cache block will be moved to another cache way in the same set, which is called “selected location”. Because the newly indexed cache block is a most recently used (MRU) block, it is placed in the major location in multicolumn cache with a consideration of temporal locality. Since multicolumn cache is designed for a cache with a high associativity, the number of ways in each set is high; thus, it is easy find a selected location in the set. A selected location index by an additional hardware is maintained for the major location in a cache block.{{Citation needed|date=May 2023}}
-
-Multicolumn cache remains a high hit ratio due to its high associativity, and has a comparable low latency to a direct-mapped cache due to its high percentage of hits in major locations. The concepts of major locations and selected locations in multicolumn cache have been used in several cache designs in ARM Cortex R chip,<ref>{{Cite web |date=2014 |title=ARM® Cortex®-R Series Programmer's Guide |url=https://developer.arm.com/documentation/den0042/latest |access-date=2023-05-04 |website=developer.arm.com}}</ref> Intel's way-predicting cache memory,<ref>{{Cite web|url=https://patents.google.com/patent/US6425055B1/en|title=Way-predicting cache memory}}</ref> IBM's reconfigurable multi-way associative cache memory<ref>{{Cite web |date=November 22, 1994 |title=United States Patent |url=https://rpx-patents.s3.amazonaws.com/US/c530f-US5367653A/US5367653A.pdf |access-date=2023-05-04 |website=rpx-patents.s3.amazonaws.com}}</ref> and Oracle's dynamic cache replacement way selection based on address tab bits.<ref>{{Cite web|url=https://patents.justia.com/patent/20160350229|title=US Patent Application for DYNAMIC CACHE REPLACEMENT WAY SELECTION BASED ON ADDRESS TAG BITS Patent Application (Application #20160350229 issued December 1, 2016) - Justia Patents Search|website=patents.justia.com}}</ref>
-
-==Cache entry structure==
-Cache row entries usually have the following structure:
-
-{| style="width:30%; text-align:center" border="1"
-|-
-| tag || data block || flag bits
-|}
-
-The ''data block'' (cache line) contains the actual data fetched from the main memory. The ''tag'' contains (part of) the address of the actual data fetched from the main memory. The flag bits are [[#Flag_bits|discussed below]].
-
-The "size" of the cache is the amount of main memory data it can hold. This size can be calculated as the number of bytes stored in each data block times the number of blocks stored in the cache. (The tag, flag and [[ECC memory#Cache|error correction code]] bits are not included in the size,<ref>{{cite web|author=Nathan N. Sadler|author2=Daniel J. Sorin|url=http://people.ee.duke.edu/~sorin/papers/iccd06_perc.pdf|title=Choosing an Error Protection Scheme for a Microprocessor's L1 Data Cache|year=2006|page=4}}</ref> although they do affect the physical area of a cache.)
-
-An effective memory address which goes along with the cache line (memory block) is split ([[Most significant bit|MSB]] to [[Least significant bit|LSB]]) into the tag, the index and the block offset.<ref>{{cite book|author1=John L. Hennessy|author2=David A. Patterson|title=Computer Architecture: A Quantitative Approach|year=2011|publisher=Elsevier |isbn=978-0-12-383872-8|at=p. B-9|url=https://books.google.com/books?id=v3-1hVwHnHwC&q=Hennessey+%22block+offset%22&pg=PA120}}</ref><ref>{{cite book|author1=David A. Patterson|author2=John L. Hennessy|title=Computer Organization and Design: The Hardware/Software Interface|year=2009|isbn=978-0-12-374493-7|page=484|publisher=Morgan Kaufmann |url=https://books.google.com/books?id=3b63x-0P3_UC&q=Hennessey+%22block+offset%22&pg=PA484}}</ref>
-
-{| style="width:30%; text-align:center" border="1"
-|-
-| tag || index || block offset
-|}
-
-The index describes which cache set that the data has been put in. The index length is <math>\lceil \log_2(s) \rceil</math> bits for {{mvar|s}} cache sets.
-
-The block offset specifies the desired data within the stored data block within the cache row. Typically the effective address is in bytes, so the block offset length is <math>\lceil \log_2(b) \rceil</math> bits, where {{mvar|b}} is the number of bytes per data block.
-The tag contains the most significant bits of the address, which are checked against all rows in the current set (the set has been retrieved by index) to see if this set contains the requested address. If it does, a cache hit occurs. The tag length in bits is as follows:
-
-::<code>tag_length = address_length - index_length - block_offset_length</code>
-
-Some authors refer to the block offset as simply the "offset"<ref name="ccs.neu.edu">{{cite web|author=Gene Cooperman|title=Cache Basics|year=2003|url=http://www.ccs.neu.edu/course/com3200/parent/NOTES/cache-basics.html}}</ref> or the "displacement".<ref>{{cite web|author=Ben Dugan|title=Concerning Cache|year=2002|url=http://www.cs.washington.edu/education/courses/cse378/02sp/sections/section9-1.html}}</ref><ref>Harvey G. Cragon.
-"Memory systems and pipelined processors".
-1996. {{ISBN|0-86720-474-5}}, {{ISBN|978-0-86720-474-2}}.
-"Chapter 4.1: Cache Addressing, Virtual or Real"
-p. 209
-[https://books.google.com/books?id=q2w3JSFD7l4C&dq=displacement+tag+cache&pg=PA209]
-</ref>
-
-===Example===
-The original [[Pentium 4]] processor had a four-way set associative L1 data cache of 8 [[Kibibyte|KiB]] in size, with 64-byte cache blocks. Hence, there are 8 KiB / 64 = 128 cache blocks. The number of sets is equal to the number of cache blocks divided by the number of ways of associativity, what leads to 128 / 4 = 32 sets, and hence 2<sup>5</sup> = 32 different indices. There are 2<sup>6</sup> = 64 possible offsets. Since the CPU address is 32 bits wide, this implies 32 - 5 - 6 = 21 bits for the tag field.
-
-The original Pentium 4 processor also had an eight-way set associative L2 integrated cache 256 KiB in size, with 128-byte cache blocks. This implies 32 - 8 - 7 = 17 bits for the tag field.<ref name="ccs.neu.edu" />
-
-==={{Anchor|Flag bits}} Flag bits===
-An instruction cache requires only one flag bit per cache row entry: a valid bit. The valid bit indicates whether or not a cache block has been loaded with valid data.
-
-On power-up, the hardware sets all the valid bits in all the caches to "invalid". Some systems also set a valid bit to "invalid" at other times, such as when multi-master [[bus snooping]] hardware in the cache of one processor hears an address broadcast from some other processor, and realizes that certain data blocks in the local cache are now stale and should be marked invalid.
-
-A data cache typically requires two flag bits per cache line{{snd}} a valid bit and a [[dirty bit]]. Having a dirty bit set indicates that the associated cache line has been changed since it was read from main memory ("dirty"), meaning that the processor has written data to that line and the new value has not propagated all the way to main memory.
-
-=={{Anchor|CACHE-MISS}}Cache miss==
-A cache miss is a failed attempt to read or write a piece of data in the cache, which results in a main memory access with much longer latency. There are three kinds of cache misses: instruction read miss, data read miss, and data write miss.
-
-''Cache read misses'' from an ''instruction'' cache generally cause the largest delay, because the processor, or at least the [[Simultaneous multithreading|thread of execution]], has to wait (stall) until the instruction is fetched from main memory. ''Cache read misses'' from a ''data'' cache usually cause a smaller delay, because instructions not dependent on the cache read can be issued and continue execution until the data is returned from main memory, and the dependent instructions can resume execution. ''Cache write misses'' to a ''data'' cache generally cause the shortest delay, because the write can be queued and there are few limitations on the execution of subsequent instructions; the processor can continue until the queue is full. For a detailed introduction to the types of misses, see [[cache performance measurement and metric]].
-
-=={{Anchor|ADDRTRANS}}Address translation==
-Most general purpose CPUs implement some form of [[virtual memory]]. To summarize, either each program running on the machine sees its own simplified [[address space]], which contains code and data for that program only, or all programs run in a common virtual address space. A program executes by calculating, comparing, reading and writing to addresses of its virtual address space, rather than addresses of physical address space, making programs simpler and thus easier to write.
-
-Virtual memory requires the processor to translate virtual addresses generated by the program into physical addresses in main memory. The portion of the processor that does this translation is known as the [[memory management unit]] (MMU). The fast path through the MMU can perform those translations stored in the [[translation lookaside buffer]] (TLB), which is a cache of mappings from the operating system's [[page table]], segment table, or both.
-
-For the purposes of the present discussion, there are three important features of address translation:
-
-* ''Latency:'' The physical address is available from the MMU some time, perhaps a few cycles, after the virtual address is available from the address generator.
-* {{Anchor|Virtual aliasing}}''Aliasing:'' Multiple virtual addresses can map to a single physical address. Most processors guarantee that all updates to that single physical address will happen in program order. To deliver on that guarantee, the processor must ensure that only one copy of a physical address resides in the cache at any given time.
-* ''Granularity:'' The virtual address space is broken up into pages. For instance, a 4 [[Gibibyte|GiB]] virtual address space might be cut up into 1,048,576 pages of 4 KiB size, each of which can be independently mapped. There may be multiple page sizes supported; see [[virtual memory]] for elaboration.
-
-One early virtual memory system, the [[IBM M44/44X]], required an access to a mapping table held in [[core memory]] before every programmed access to main memory.<ref>{{cite conference|author=R. W. O'Neill|title=Experience using a time sharing multiprogramming system with dynamic address relocation hardware|conference=Proc. AFIPS Computer Conference 30 (Spring Joint Computer Conference, 1967)|pages=611–621|doi=10.1145/1465482.1465581}}</ref>{{refn|The very first paging machine, the [[Ferranti]] [[Atlas Computer (Manchester)|Atlas]]<ref name=AtlasCPU/><ref name=AtlasSup/> had no page tables in main memory; there was an associative memory with one entry for every 512 word page frame of core.|group=NB}} With no caches, and with the mapping table memory running at the same speed as main memory this effectively cut the speed of memory access in half. Two early machines that used a [[page table]] in main memory for mapping, the [[IBM System/360 Model 67]] and the [[GE 645]], both had a small associative memory as a cache for accesses to the in-memory page table. Both machines predated the first machine with a cache for main memory, the [[IBM System/360 Model 85]], so the first hardware cache used in a computer system was not a data or instruction cache, but rather a TLB.
-
-Caches can be divided into four types, based on whether the index or tag correspond to physical or virtual addresses:
-
-* ''Physically indexed, physically tagged'' (PIPT) caches use the physical address for both the index and the tag. While this is simple and avoids problems with aliasing, it is also slow, as the physical address must be looked up (which could involve a TLB miss and access to main memory) before that address can be looked up in the cache.
-* ''Virtually indexed, virtually tagged'' (VIVT) caches use the virtual address for both the index and the tag. This caching scheme can result in much faster lookups, since the MMU does not need to be consulted first to determine the physical address for a given virtual address. However, VIVT suffers from aliasing problems, where several different virtual addresses may refer to the same physical address. The result is that such addresses would be cached separately despite referring to the same memory, causing coherency problems. Although solutions to this problem exist<ref>{{cite conference|last1=Kaxiras|first1=Stefanos|last2=Ros|first2=Alberto|title=A New Perspective for Efficient Virtual-Cache Coherence|conference=40th International Symposium on Computer Architecture (ISCA)|date=2013|pages=535–547|doi=10.1145/2485922.2485968|isbn=9781450320795|citeseerx=10.1.1.307.9125|s2cid=15434231}}</ref> they do not work for standard coherence protocols. Another problem is homonyms, where the same virtual address maps to several different physical addresses. It is not possible to distinguish these mappings merely by looking at the virtual index itself, though potential solutions include: flushing the cache after a [[context switch]], forcing address spaces to be non-overlapping, tagging the virtual address with an address space ID (ASID). Additionally, there is a problem that virtual-to-physical mappings can change, which would require flushing cache lines, as the VAs would no longer be valid. All these issues are absent if tags use physical addresses (VIPT).
-* ''Virtually indexed, physically tagged'' (VIPT) caches use the virtual address for the index and the physical address in the tag. The advantage over PIPT is lower latency, as the cache line can be looked up in parallel with the TLB translation, however the tag cannot be compared until the physical address is available. The advantage over VIVT is that since the tag has the physical address, the cache can detect homonyms. Theoretically, VIPT requires more tags bits because some of the index bits could differ between the virtual and physical addresses (for example bit 12 and above for 4 KiB pages) and would have to be included both in the virtual index and in the physical tag. In practice this is not an issue because, in order to avoid coherency problems, VIPT caches are designed to have no such index bits (e.g., by limiting the total number of bits for the index and the block offset to 12 for 4 KiB pages); this limits the size of VIPT caches to the page size times the associativity of the cache.
-* ''Physically indexed, virtually tagged'' (PIVT) caches are often claimed in literature to be useless and non-existing.<ref>{{cite magazine |url=http://www.linuxjournal.com/article/7105 |title=Understanding Caching |magazine=Linux Journal |access-date=2010-05-02}}</ref> However, the [[MIPS architecture|MIPS]] [[R6000]] uses this cache type as the sole known implementation.<ref>{{cite journal|first1=George|last1=Taylor|first2=Peter|last2=Davies|first3=Michael|last3=Farmwald|title=The TLB Slice - A Low-Cost High-Speed Address Translation Mechanism|year=1990|id=CH2887-8/90/0000/0355$01.OO}}</ref> The R6000 is implemented in [[emitter-coupled logic]], which is an extremely fast technology not suitable for large memories such as a [[Translation lookaside buffer|TLB]]. The R6000 solves the issue by putting the TLB memory into a reserved part of the second-level cache having a tiny, high-speed TLB "slice" on chip. The cache is indexed by the physical address obtained from the TLB slice. However, since the TLB slice only translates those virtual address bits that are necessary to index the cache and does not use any tags, false cache hits may occur, which is solved by tagging with the virtual address.
-
-The speed of this recurrence (the ''load latency'') is crucial to CPU performance, and so most modern level-1 caches are virtually indexed, which at least allows the MMU's TLB lookup to proceed in parallel with fetching the data from the cache RAM.
-
-But virtual indexing is not the best choice for all cache levels. The cost of dealing with virtual aliases grows with cache size, and as a result most level-2 and larger caches are physically indexed.
-
-Caches have historically used both virtual and physical addresses for the cache tags, although virtual tagging is now uncommon. If the TLB lookup can finish before the cache RAM lookup, then the physical address is available in time for tag compare, and there is no need for virtual tagging. Large caches, then, tend to be physically tagged, and only small, very low latency caches are virtually tagged. In recent general-purpose CPUs, virtual tagging has been superseded by vhints, as described below.
-
-===Homonym and synonym problems===
-A cache that relies on virtual indexing and tagging becomes inconsistent after the same virtual address is mapped into different physical addresses ([[homonym]]), which can be solved by using physical address for tagging, or by storing the address space identifier in the cache line. However, the latter approach does not help against the [[synonym]] problem, in which several cache lines end up storing data for the same physical address. Writing to such locations may update only one location in the cache, leaving the others with inconsistent data. This issue may be solved by using non-overlapping memory layouts for different address spaces, or otherwise the cache (or a part of it) must be flushed when the mapping changes.<ref>{{cite web
- | url = http://www.systems.ethz.ch/education/courses/fs09/aos/lectures/wk3-print.pdf
- | archive-url = https://web.archive.org/web/20111007150424/http://www.systems.ethz.ch/education/past-courses/fs09/aos/lectures/wk3-print.pdf |url-status = dead
- | title = Advanced Operating Systems Caches and TLBs (263-3800-00L)
- | date = 2009-03-03 | access-date = 2016-02-14 | archive-date = 2011-10-07
- | author1 = Timothy Roscoe | author2 = Andrew Baumann
- | website = systems.ethz.ch }}</ref>
-
-===Virtual tags and vhints===
-The great advantage of virtual tags is that, for associative caches, they allow the tag match to proceed before the virtual to physical translation is done. However, coherence probes and evictions present a physical address for action. The hardware must have some means of converting the physical addresses into a cache index, generally by storing physical tags as well as virtual tags. For comparison, a physically tagged cache does not need to keep virtual tags, which is simpler. When a virtual to physical mapping is deleted from the TLB, cache entries with those virtual addresses will have to be flushed somehow. Alternatively, if cache entries are allowed on pages not mapped by the TLB, then those entries will have to be flushed when the access rights on those pages are changed in the page table.
-
-It is also possible for the operating system to ensure that no virtual aliases are simultaneously resident in the cache. The operating system makes this guarantee by enforcing page coloring, which is described below. Some early RISC processors (SPARC, RS/6000) took this approach. It has not been used recently, as the hardware cost of detecting and evicting virtual aliases has fallen and the software complexity and performance penalty of perfect page coloring has risen.
-
-It can be useful to distinguish the two functions of tags in an associative cache: they are used to determine which way of the entry set to select, and they are used to determine if the cache hit or missed. The second function must always be correct, but it is permissible for the first function to guess, and get the wrong answer occasionally.
-
-Some processors (e.g. early SPARCs) have caches with both virtual and physical tags. The virtual tags are used for way selection, and the physical tags are used for determining hit or miss. This kind of cache enjoys the latency advantage of a virtually tagged cache, and the simple software interface of a physically tagged cache. It bears the added cost of duplicated tags, however. Also, during miss processing, the alternate ways of the cache line indexed have to be probed for virtual aliases and any matches evicted.
-
-The extra area (and some latency) can be mitigated by keeping ''virtual hints'' with each cache entry instead of virtual tags. These hints are a subset or hash of the virtual tag, and are used for selecting the way of the cache from which to get data and a physical tag. Like a virtually tagged cache, there may be a virtual hint match but physical tag mismatch, in which case the cache entry with the matching hint must be evicted so that cache accesses after the cache fill at this address will have just one hint match. Since virtual hints have fewer bits than virtual tags distinguishing them from one another, a virtually hinted cache suffers more conflict misses than a virtually tagged cache.
-
-Perhaps the ultimate reduction of virtual hints can be found in the Pentium 4 (Willamette and Northwood cores). In these processors the virtual hint is effectively two bits, and the cache is four-way set associative. Effectively, the hardware maintains a simple permutation from virtual address to cache index, so that no [[content-addressable memory]] (CAM) is necessary to select the right one of the four ways fetched.
-
-===Page coloring===
-{{Main article|Cache coloring}}
-
-Large physically indexed caches (usually secondary caches) run into a problem: the operating system rather than the application controls which pages collide with one another in the cache. Differences in page allocation from one program run to the next lead to differences in the cache collision patterns, which can lead to very large differences in program performance. These differences can make it very difficult to get a consistent and repeatable timing for a benchmark run.
-
-To understand the problem, consider a CPU with a 1 MiB physically indexed direct-mapped level-2 cache and 4 KiB virtual memory pages. Sequential physical pages map to sequential locations in the cache until after 256 pages the pattern wraps around. We can label each physical page with a color of 0–255 to denote where in the cache it can go. Locations within physical pages with different colors cannot conflict in the cache.
-
-Programmers attempting to make maximum use of the cache may arrange their programs' access patterns so that only 1 MiB of data need be cached at any given time, thus avoiding capacity misses. But they should also ensure that the access patterns do not have conflict misses. One way to think about this problem is to divide up the virtual pages the program uses and assign them virtual colors in the same way as physical colors were assigned to physical pages before. Programmers can then arrange the access patterns of their code so that no two pages with the same virtual color are in use at the same time. There is a wide literature on such optimizations (e.g. [[loop nest optimization]]), largely coming from the [[High Performance Computing|High Performance Computing (HPC)]] community.
-
-The snag is that while all the pages in use at any given moment may have different virtual colors, some may have the same physical colors. In fact, if the operating system assigns physical pages to virtual pages randomly and uniformly, it is extremely likely that some pages will have the same physical color, and then locations from those pages will collide in the cache (this is the [[birthday paradox]]).
-
-The solution is to have the operating system attempt to assign different physical color pages to different virtual colors, a technique called ''page coloring''. Although the actual mapping from virtual to physical color is irrelevant to system performance, odd mappings are difficult to keep track of and have little benefit, so most approaches to page coloring simply try to keep physical and virtual page colors the same.
-
-If the operating system can guarantee that each physical page maps to only one virtual color, then there are no virtual aliases, and the processor can use virtually indexed caches with no need for extra virtual alias probes during miss handling. Alternatively, the OS can flush a page from the cache whenever it changes from one virtual color to another. As mentioned above, this approach was used for some early SPARC and RS/6000 designs.
-
-The software page coloring technique has been used to effectively partition the shared Last level Cache (LLC) in multicore processors.<ref>{{Cite conference |author1= Jiang Lin |author2=Qingda Lu |author3=Xiaoning Ding |author4=Zhao Zhang |author5=Xiaodong Zhang |author6=P. Sadayappan | title=Gaining insights into multicore cache partitioning: Bridging the gap between simulation and real systems |conference= IEEE 14th International Symposium on High Performance Computer Architecture |location= Salt Lake City, UT |date= 2008 |pages = 367–378 |doi= 10.1109/HPCA.2008.4658653}}</ref> This operating system-based LLC management in multicore processors has been adopted by Intel.<ref>{{Cite web|url=http://web.cse.ohio-state.edu/~zhang.574/OS-cache-software_intel_2010.pdf|title=Letter to Jiang Lin}}</ref>
-
-=={{Anchor|Cache hierarchy}}Cache hierarchy in a modern processor==
-[[File:Hwloc.png|thumb|right|300px|Memory hierarchy of an AMD Bulldozer server]]
-
-Modern processors have multiple interacting on-chip caches. The operation of a particular cache can be completely specified by the cache size, the cache block size, the number of blocks in a set, the cache set replacement policy, and the cache write policy (write-through or write-back).<ref name="ccs.neu.edu" />
-
-While all of the cache blocks in a particular cache are the same size and have the same associativity, typically the "lower-level" caches (called Level 1 cache) have a smaller number of blocks, smaller block size, and fewer blocks in a set, but have very short access times. "Higher-level" caches (i.e. Level 2 and above) have progressively larger numbers of blocks, larger block size, more blocks in a set, and relatively longer access times, but are still much faster than main memory.
-
-Cache entry replacement policy is determined by a [[cache algorithm]] selected to be implemented by the processor designers. In some cases, multiple algorithms are provided for different kinds of work loads.
-
-===Specialized caches===
-Pipelined CPUs access memory from multiple points in the [[Instruction pipeline|pipeline]]: instruction fetch, [[virtual memory|virtual-to-physical]] address translation, and data fetch (see [[classic RISC pipeline]]). The natural design is to use different physical caches for each of these points, so that no one physical resource has to be scheduled to service two points in the pipeline. Thus the pipeline naturally ends up with at least three separate caches (instruction, [[translation lookaside buffer|TLB]], and data), each specialized to its particular role.
-
-====Victim cache====
-{{Main article|Victim cache}}
-A '''victim cache''' is a cache used to hold blocks evicted from a CPU cache upon replacement. The victim cache lies between the main cache and its refill path, and holds only those blocks of data that were evicted from the main cache. The victim cache is usually fully associative, and is intended to reduce the number of conflict misses. Many commonly used programs do not require an associative mapping for all the accesses. In fact, only a small fraction of the memory accesses of the program require high associativity. The victim cache exploits this property by providing high associativity to only these accesses. It was introduced by [[Norman Jouppi]] from DEC in 1990.<ref>N.P.Jouppi. "Improving direct-mapped cache performance by the addition of a small {{Sic|hide=y|fully|-}}associative cache and prefetch buffers." - 17th Annual International Symposium on Computer Architecture, 1990. Proceedings., {{doi|10.1109/ISCA.1990.134547}}</ref>
-
-Intel's ''[[Crystalwell]]''<ref name="intel-ark-crystal-well">{{cite web
- | url = http://ark.intel.com/products/codename/51802/Crystal-Well
- | title = Products (Formerly Crystal Well)
- | publisher = [[Intel]]
- | access-date = 2013-09-15
-}}</ref> variant of its [[Haswell (microarchitecture)|Haswell]] processors introduced an on-package 128 MiB [[eDRAM]] Level 4 cache which serves as a victim cache to the processors' Level 3 cache.<ref name="anandtech-i74950hq">{{cite web
- | url = http://www.anandtech.com/show/6993/intel-iris-pro-5200-graphics-review-core-i74950hq-tested/3
- | title = Intel Iris Pro 5200 Graphics Review: Core i7-4950HQ Tested
- | publisher = [[AnandTech]]
- | access-date = 2013-09-16
-}}</ref> In the [[Skylake (microarchitecture)|Skylake]] microarchitecture the Level 4 cache no longer works as a victim cache.<ref>{{cite web
- | url = http://www.anandtech.com/show/9582/intel-skylake-mobile-desktop-launch-architecture-analysis/5
- | title = The Intel Skylake Mobile and Desktop Launch, with Architecture Analysis
- | author = Ian Cutress
- | date = September 2, 2015
- | publisher = AnandTech
-}}</ref>
-
-===={{Anchor|TRACE-CACHE}}Trace cache====
-{{Main article|Trace cache}}
-
-One of the more extreme examples of cache specialization is the '''trace cache''' (also known as ''execution trace cache'') found in the [[Intel]] [[Pentium 4]] microprocessors. A trace cache is a mechanism for increasing the instruction fetch bandwidth and decreasing power consumption (in the case of the Pentium 4) by storing traces of [[instruction (computer science)|instruction]]s that have already been fetched and decoded.<ref>{{cite web
- | url = http://www.anandtech.com/show/661/5
- | title = The Pentium 4's Cache – Intel Pentium 4 1.4 GHz & 1.5 GHz
- | date = 2000-11-20 | access-date = 2015-11-30
- | author = Anand Lal Shimpi | publisher = [[AnandTech]]
-}}</ref>
-
-A trace cache stores instructions either after they have been decoded, or as they are retired. Generally, instructions are added to trace caches in groups representing either individual [[basic block]]s or dynamic instruction traces. The Pentium 4's trace cache stores [[micro-operations]] resulting from decoding x86 instructions, providing also the functionality of a micro-operation cache. Having this, the next time an instruction is needed, it does not have to be decoded into micro-ops again.<ref name="agner.org" />{{rp|63–68}}
-
-====Write Coalescing Cache (WCC)====
-Write Coalescing Cache<ref>{{cite web|url=http://www.realworldtech.com/bulldozer/9/|title=AMD's Bulldozer Microarchitecture - Memory Subsystem Continued|date=August 26, 2010|author=David Kanter|website=Real World Technologies}}</ref> is a special cache that is part of L2 cache in [[AMD]]'s [[Bulldozer (microarchitecture)|Bulldozer microarchitecture]]. Stores from both L1D caches in the module go through the WCC, where they are buffered and coalesced.
-The WCC's task is reducing number of writes to the L2 cache.
-
-===={{Anchor|UOP-CACHE}}Micro-operation (μop or uop) cache====
-A '''micro-operation cache''' ('''μop cache''', '''uop cache''' or '''UC''')<ref>{{cite web|url=http://www.realworldtech.com/sandy-bridge/4/|title=Intel's Sandy Bridge Microarchitecture - Instruction Decode and uop Cache|date=September 25, 2010|author=David Kanter|website=Real World Technologies}}</ref> is a specialized cache that stores [[micro-operation]]s of decoded instructions, as received directly from the [[instruction decoder]]s or from the instruction cache. When an instruction needs to be decoded, the μop cache is checked for its decoded form which is re-used if cached; if it is not available, the instruction is decoded and then cached.
-
-One of the early works describing μop cache as an alternative frontend for the Intel [[P6 (microarchitecture)|P6 processor family]] is the 2001 paper ''"Micro-Operation Cache: A Power Aware Frontend for Variable Instruction Length ISA"''.<ref name="uop-intel">{{cite book
- | chapter-url = http://cecs.uci.edu/~papers/compendium94-03/papers/2001/islped01/pdffiles/p004.pdf
- | chapter = Micro-Operation Cache: A Power Aware Frontend for Variable Instruction Length ISA
- | author1 = Baruch Solomon | title = ISLPED'01: Proceedings of the 2001 International Symposium on Low Power Electronics and Design (IEEE Cat. No.01TH8581)
- | pages = 4–9
- | author2 = Avi Mendelson | author3 = Doron Orenstein | author4 = Yoav Almog | author5 = Ronny Ronen
- | date = August 2001 | access-date = 2013-10-06
- | publisher = [[Intel]] | doi = 10.1109/LPE.2001.945363
-| isbn = 978-1-58113-371-4
- | s2cid = 195859085
- }}</ref> Later, Intel included μop caches in its [[Sandy Bridge]] processors and in successive microarchitectures like [[Ivy Bridge (microarchitecture)|Ivy Bridge]] and [[Haswell (microarchitecture)|Haswell]].<ref name="agner.org">{{cite web
- | url = http://www.agner.org/optimize/microarchitecture.pdf
- | title = The microarchitecture of Intel, AMD and VIA CPUs: An optimization guide for assembly programmers and compiler makers
- | date = 2014-02-19 | access-date = 2014-03-21
- | author = Agner Fog |author-link=Agner Fog| website = agner.org
- }}</ref>{{rp|121–123}}<ref name="anandtech-haswell">{{cite web
- | url = http://www.anandtech.com/show/6355/intels-haswell-architecture/6
- | title = Intel's Haswell Architecture Analyzed
- | date = 2012-10-05 | access-date = 2013-10-20
- | author = Anand Lal Shimpi | publisher = [[AnandTech]]
-}}</ref> AMD implemented a μop cache in their [[Zen (microarchitecture)|Zen microarchitecture]].<ref>{{cite web
- | url = http://www.anandtech.com/show/10578/amd-zen-microarchitecture-dual-schedulers-micro-op-cache-memory-hierarchy-revealed
- | title = AMD Zen Microarchitecture: Dual Schedulers, Micro-Op Cache and Memory Hierarchy Revealed
- | date = 2016-08-18 | access-date = 2017-04-03
- | author = Ian Cutress | publisher = AnandTech}}</ref>
-
-Fetching complete pre-decoded instructions eliminates the need to repeatedly decode variable length complex instructions into simpler fixed-length micro-operations, and simplifies the process of predicting, fetching, rotating and aligning fetched instructions. A μop cache effectively offloads the fetch and decode hardware, thus decreasing [[power consumption]] and improving the frontend supply of decoded micro-operations. The μop cache also increases performance by more consistently delivering decoded micro-operations to the backend and eliminating various bottlenecks in the CPU's fetch and decode logic.<ref name="uop-intel" /><ref name="anandtech-haswell" />
-
-A μop cache has many similarities with a trace cache, although a μop cache is much simpler thus providing better power efficiency; this makes it better suited for implementations on battery-powered devices. The main disadvantage of the trace cache, leading to its power inefficiency, is the hardware complexity required for its [[heuristic]] deciding on caching and reusing dynamically created instruction traces.<ref name="tc-slides">{{cite web|url=https://www.cs.cmu.edu/afs/cs/academic/class/15740-f03/www/lectures/TraceCache_slides.pdf|title=Trace Cache|date=October 2003|access-date=2013-10-06|author1=Leon Gu|author2=Dipti Motiani}}</ref>
-
-====Branch target instruction cache====
-A '''branch target cache''' or '''branch target instruction cache''', the name used on [[ARM microprocessors]],<ref>{{cite web |title=How does the BTIC (branch target instruction cache) work? |url=https://community.arm.com/processors/f/discussions/5320/how-does-the-btic-branch-target-instruction-cache-works |date=28 May 2015 |author=Kun Niu |access-date=7 April 2018}}</ref> is a specialized cache which holds the first few instructions at the destination of a taken branch. This is used by low-powered processors which do not need a normal instruction cache because the memory system is capable of delivering instructions fast enough to satisfy the CPU without one. However, this only applies to consecutive instructions in sequence; it still takes several cycles of latency to restart instruction fetch at a new address, causing a few cycles of pipeline bubble after a control transfer. A branch target cache provides instructions for those few cycles avoiding a delay after most taken branches.
-
-This allows full-speed operation with a much smaller cache than a traditional full-time instruction cache.
-
-====Smart cache====
-'''Smart cache''' is a [[#MULTILEVEL|level 2]] or [[#MULTILEVEL|level 3]] caching method for multiple execution cores, developed by [[Intel]].
-
-Smart Cache shares the actual cache memory between the cores of a [[multi-core processor]]. In comparison to a dedicated per-core cache, the overall [[cache miss]] rate decreases when cores do not require equal parts of the cache space. Consequently, a single core can use the full level 2 or level 3 cache while the other cores are inactive.<ref>{{cite web|url=http://www.intel.com/content/www/us/en/architecture-and-technology/intel-smart-cache.html|title=Intel Smart Cache: Demo|publisher=[[Intel]]|access-date=2012-01-26}}</ref> Furthermore, the shared cache makes it faster to share memory among different execution cores.<ref>{{cite web |url=http://software.intel.com/file/18374/ |archive-url=https://web.archive.org/web/20111229193036/http://software.intel.com/file/18374/ |title=Inside Intel Core Microarchitecture and Smart Memory Access |format=PDF |page=5 |publisher=[[Intel]] |year=2006 |access-date=2012-01-26 |archive-date=2011-12-29}}</ref>
-
-==={{Anchor|MULTILEVEL}}Multi-level caches===
-{{See also|Cache hierarchy}}
-Another issue is the fundamental tradeoff between cache latency and hit rate. Larger caches have better hit rates but longer latency. To address this tradeoff, many computers use multiple levels of cache, with small fast caches backed up by larger, slower caches. Multi-level caches generally operate by checking the fastest cache, ''level 1'' ('''L1'''), first; if it hits, the processor proceeds at high speed. If that smaller cache misses, the next fastest cache, ''level 2'' ('''L2'''), is checked, and so on, before accessing external memory.
-
-As the latency difference between main memory and the fastest cache has become larger, some processors have begun to utilize as many as three levels of on-chip cache. Price-sensitive designs used this to pull the entire cache hierarchy on-chip, but by the 2010s some of the highest-performance designs returned to having large off-chip caches, which is often implemented in [[eDRAM]] and mounted on a [[multi-chip module]], as a fourth cache level. In rare cases, such as in the mainframe CPU [[IBM z15 (microprocessor)|IBM z15]] (2019), all levels down to L1 are implemented by eDRAM, replacing [[static random-access memory|SRAM]] entirely (for cache, SRAM is still used for registers). The [[ARM architecture family|ARM-based]] [[Apple M1]] has a 192 KiB L1 cache for each of the four high-performance cores, an unusually large amount; however the four high-efficiency cores only have 128 KiB.
-
-The benefits of L3 and L4 caches depend on the application's access patterns. Examples of products incorporating L3 and L4 caches include the following:
-
-* [[Alpha 21164]] (1995) has 1 to 64 MiB off-chip L3 cache.
-* [[AMD K6-III]] (1999) has motherboard-based L3 cache.
-* IBM [[POWER4]] (2001) has off-chip L3 caches of 32 MiB per processor, shared among several processors.
-* [[Itanium 2]] (2003) has a 6 MiB [[unified cache|unified]] level 3 (L3) cache on-die; the [[Itanium 2]] (2003) MX 2 module incorporates two Itanium 2 processors along with a shared 64 MiB L4 cache on a [[multi-chip module]] that was pin compatible with a Madison processor.
-* Intel's [[Xeon]] MP product codenamed "Tulsa" (2006) features 16 MiB of on-die L3 cache shared between two processor cores.
-* [[AMD Phenom]] (2007) with 2 MiB of L3 cache.
-* AMD [[Phenom II]] (2008) has up to 6 MiB on-die unified L3 cache.
-* [[List of Intel Core i7 processors|Intel Core i7]] (2008) has an 8 MiB on-die unified L3 cache that is inclusive, shared by all cores.
-* Intel [[Haswell (microarchitecture)|Haswell]] CPUs with integrated [[Intel Iris Pro Graphics]] have 128 MiB of eDRAM acting essentially as an L4 cache.<ref>{{cite web|url=http://www.anandtech.com/show/6993/intel-iris-pro-5200-graphics-review-core-i74950hq-tested/3 |title=Intel Iris Pro 5200 Graphics Review: Core i7-4950HQ Tested |publisher=AnandTech |access-date=2014-02-25}}</ref>
-
-Finally, at the other end of the memory hierarchy, the CPU [[register file]] itself can be considered the smallest, fastest cache in the system, with the special characteristic that it is scheduled in software—typically by a compiler, as it allocates registers to hold values retrieved from main memory for, as an example, [[loop nest optimization]]. However, with [[register renaming]] most compiler register assignments are reallocated dynamically by hardware at runtime into a register bank, allowing the CPU to break false data dependencies and thus easing pipeline hazards.
-
-Register files sometimes also have hierarchy: The [[Cray-1]] (circa 1976) had eight address "A" and eight scalar data "S" registers that were generally usable. There was also a set of 64 address "B" and 64 scalar data "T" registers that took longer to access, but were faster than main memory. The "B" and "T" registers were provided because the Cray-1 did not have a data cache. (The Cray-1 did, however, have an instruction cache.)
-
-===={{Anchor|LLC}}Multi-core chips====
-When considering a chip with [[Multi-core processor|multiple cores]], there is a question of whether the caches should be shared or local to each core. Implementing shared cache inevitably introduces more wiring and complexity. But then, having one cache per ''chip'', rather than ''core'', greatly reduces the amount of space needed, and thus one can include a larger cache.
-
-Typically, sharing the L1 cache is undesirable because the resulting increase in latency would make each core run considerably slower than a single-core chip. However, for the highest-level cache, the last one called before accessing memory, having a global cache is desirable for several reasons, such as allowing a single core to use the whole cache, reducing data redundancy by making it possible for different processes or threads to share cached data, and reducing the complexity of utilized cache coherency protocols.<ref>{{cite web
- | url = https://software.intel.com/en-us/articles/software-techniques-for-shared-cache-multi-core-systems
- | title = Software Techniques for Shared-Cache Multi-Core Systems
- | date = 2012-03-08 | access-date = 2015-11-24
- | author1 = Tian Tian | author2 = Chiu-Pi Shih
- | publisher = [[Intel]]
-}}</ref> For example, an eight-core chip with three levels may include an L1 cache for each core, one intermediate L2 cache for each pair of cores, and one L3 cache shared between all cores.
-
-Shared highest-level cache, which is called before accessing memory, is usually referred to as the ''last level cache'' (LLC). Additional techniques are used for increasing the level of parallelism when LLC is shared between multiple cores, including slicing it into multiple pieces which are addressing certain ranges of memory addresses, and can be accessed independently.<ref>{{cite web
- | url = http://www.hotchips.org/wp-content/uploads/hc_archives/hc23/HC23.19.9-Desktop-CPUs/HC23.19.911-Sandy-Bridge-Lempel-Intel-Rev%207.pdf
- | title = 2nd Generation Intel Core Processor Family: Intel Core i7, i5 and i3
- | date = 2013-07-28
- | access-date = 2014-01-21
- | author = Oded Lempel
- | website = hotchips.org
- | page = 7–10,31–45
- | archive-date = 2020-07-29
- | archive-url = https://web.archive.org/web/20200729000210/http://www.hotchips.org/wp-content/uploads/hc_archives/hc23/HC23.19.9-Desktop-CPUs/HC23.19.911-Sandy-Bridge-Lempel-Intel-Rev%207.pdf
- | url-status = dead
- }}</ref>
-
-====Separate versus unified====
-In a separate cache structure, instructions and data are cached separately, meaning that a cache line is used to cache either instructions or data, but not both; various benefits have been demonstrated with separate data and instruction [[translation lookaside buffer]]s.<ref>{{cite journal |author1=Chen, J. Bradley |author2=Borg, Anita |author3=Jouppi, Norman P. |title=A Simulation Based Study of TLB Performance |journal=SIGARCH Computer Architecture News |volume=20 |issue=2 |year=1992 |page=114–123 |doi=10.1145/146628.139708|doi-access=free }}</ref> In a unified structure, this constraint is not present, and cache lines can be used to cache both instructions and data.
-
-===={{Anchor|INCLUSIVE|EXCLUSIVE}}Exclusive versus inclusive====
-Multi-level caches introduce new design decisions. For instance, in some processors, all data in the L1 cache must also be somewhere in the L2 cache. These caches are called ''strictly inclusive''. Other processors (like the [[AMD Athlon]]) have ''exclusive'' caches: data is guaranteed to be in at most one of the L1 and L2 caches, never in both. Still other processors (like the Intel [[Pentium II]], [[Pentium III|III]], and [[Pentium 4|4]]) do not require that data in the L1 cache also reside in the L2 cache, although it may often do so. There is no universally accepted name for this intermediate policy;<ref>{{cite web
- | url = http://www.amecomputers.com/explanation-of-the-l1-and-l2-cache.html
- | title = Explanation of the L1 and L2 Cache
- | access-date = 2014-06-09
- | website = amecomputers.com
- | archive-date = 2014-07-14
- | archive-url = https://web.archive.org/web/20140714181050/http://www.amecomputers.com/explanation-of-the-l1-and-l2-cache.html
- | url-status = dead
- }}</ref><ref name="ispass04">{{cite conference
- | url = http://mercury.pr.erau.edu/~davisb22/papers/ispass04.pdf
- | title = Performance Evaluation of Exclusive Cache Hierarchies
- | date = 10–12 March 2004 | access-date = 2014-06-09
- | author1 = Ying Zheng | author2 = Brian T. Davis | author3 = Matthew Jordan
- | conference = IEEE International Symposium on Performance Analysis of Systems and Software
- | location = Austin, TX, USA
- | doi = 10.1109/ISPASS.2004.1291359
- | isbn = 0-7803-8385-0
- | pages = 89–96
- | url-status = dead
- | archive-url = https://web.archive.org/web/20120813003941/http://mercury.pr.erau.edu/~davisb22/papers/ispass04.pdf
- | archive-date = 2012-08-13
- }}</ref>
-two common names are "non-exclusive" and "partially-inclusive".
-
-The advantage of exclusive caches is that they store more data. This advantage is larger when the exclusive L1 cache is comparable to the L2 cache, and diminishes if the L2 cache is many times larger than the L1 cache. When the L1 misses and the L2 hits on an access, the hitting cache line in the L2 is exchanged with a line in the L1. This exchange is quite a bit more work than just copying a line from L2 to L1, which is what an inclusive cache does.<ref name="ispass04" />
-
-One advantage of strictly inclusive caches is that when external devices or other processors in a multiprocessor system wish to remove a cache line from the processor, they need only have the processor check the L2 cache. In cache hierarchies which do not enforce inclusion, the L1 cache must be checked as well. As a drawback, there is a correlation between the associativities of L1 and L2 caches: if the L2 cache does not have at least as many ways as all L1 caches together, the effective associativity of the L1 caches is restricted. Another disadvantage of inclusive cache is that whenever there is an eviction in L2 cache, the (possibly) corresponding lines in L1 also have to get evicted in order to maintain inclusiveness. This is quite a bit of work, and would result in a higher L1 miss rate.<ref name="ispass04" />
-
-Another advantage of inclusive caches is that the larger cache can use larger cache lines, which reduces the size of the secondary cache tags. (Exclusive caches require both caches to have the same size cache lines, so that cache lines can be swapped on a L1 miss, L2 hit.) If the secondary cache is an order of magnitude larger than the primary, and the cache data is an order of magnitude larger than the cache tags, this tag area saved can be comparable to the incremental area needed to store the L1 cache data in the L2.<ref>{{cite web
- | url = http://www.jaleels.org/ajaleel/publications/micro2010-tla.pdf
- | title = Achieving Non-Inclusive Cache Performance with Inclusive Caches
- | date = 2010-09-27 | access-date = 2014-06-09
- | author1 = Aamer Jaleel | author2 = Eric Borch | author3 = Malini Bhandaru
- | author4 = Simon C. Steely Jr. | author5 = Joel Emer
- | website = jaleels.org }}</ref>
-
-===Scratchpad memory===
-
-{{Main|Scratchpad memory}}
-[[Scratchpad memory]] (SPM), also known as scratchpad, scratchpad RAM or local store in computer terminology, is a high-speed internal memory used for temporary storage of calculations, data, and other work in progress.
-
-===Example: the K8===
-To illustrate both specialization and multi-level caching, here is the cache hierarchy of the K8 core in the AMD [[Athlon 64]] CPU.<ref>{{cite web|url=http://www.sandpile.org/impl/k8.htm |title=AMD K8 |access-date=2007-06-02 |website=Sandpile.org |url-status=dead |archive-url=https://web.archive.org/web/20070515052223/http://www.sandpile.org/impl/k8.htm |archive-date=2007-05-15 }}</ref>
-
-[[File:Cache,hierarchy-example.svg|thumb|center|500px|Cache hierarchy of the K8 core in the AMD Athlon 64 CPU.]]
-
-The K8 has four specialized caches: an instruction cache, an instruction [[translation lookaside buffer|TLB]], a data TLB, and a data cache. Each of these caches is specialized:
-
-* The instruction cache keeps copies of 64-byte lines of memory, and fetches 16 bytes each cycle. Each byte in this cache is stored in ten bits rather than eight, with the extra bits marking the boundaries of instructions (this is an example of predecoding). The cache has only [[parity bit|parity]] protection rather than [[Error-correcting code|ECC]], because parity is smaller and any damaged data can be replaced by fresh data fetched from memory (which always has an up-to-date copy of instructions).
-* The instruction TLB keeps copies of page table entries (PTEs). Each cycle's instruction fetch has its virtual address translated through this TLB into a physical address. Each entry is either four or eight bytes in memory. Because the K8 has a variable page size, each of the TLBs is split into two sections, one to keep PTEs that map 4 KiB pages, and one to keep PTEs that map 4 MiB or 2 MiB pages. The split allows the fully associative match circuitry in each section to be simpler. The operating system maps different sections of the virtual address space with different size PTEs.
-* The data TLB has two copies which keep identical entries. The two copies allow two data accesses per cycle to translate virtual addresses to physical addresses. Like the instruction TLB, this TLB is split into two kinds of entries.
-* The data cache keeps copies of 64-byte lines of memory. It is split into 8 banks (each storing 8 KiB of data), and can fetch two 8-byte data each cycle so long as those data are in different banks. There are two copies of the tags, because each 64-byte line is spread among all eight banks. Each tag copy handles one of the two accesses per cycle.
-
-The K8 also has multiple-level caches. There are second-level instruction and data TLBs, which store only PTEs mapping 4 KiB. Both instruction and data caches, and the various TLBs, can fill from the large '''unified''' L2 cache. This cache is exclusive to both the L1 instruction and data caches, which means that any 8-byte line can only be in one of the L1 instruction cache, the L1 data cache, or the L2 cache. It is, however, possible for a line in the data cache to have a PTE which is also in one of the TLBs—the operating system is responsible for keeping the TLBs coherent by flushing portions of them when the page tables in memory are updated.
-
-The K8 also caches information that is never stored in memory—prediction information. These caches are not shown in the above diagram. As is usual for this class of CPU, the K8 has fairly complex
-[[branch prediction]], with tables that help predict whether branches are taken and other tables which predict the targets of branches and jumps. Some of this information is associated with instructions, in both the level 1 instruction cache and the unified secondary cache.
-
-The K8 uses an interesting trick to store prediction information with instructions in the secondary cache. Lines in the secondary cache are protected from accidental data corruption (e.g. by an [[alpha particle]] strike) by either [[Error-correcting code|ECC]] or [[parity (telecommunication)|parity]], depending on whether those lines were evicted from the data or instruction primary caches. Since the parity code takes fewer bits than the ECC code, lines from the instruction cache have a few spare bits. These bits are used to cache branch prediction information associated with those instructions. The net result is that the branch predictor has a larger effective history table, and so has better accuracy.
-
-===More hierarchies===
-<!-- (This section should be rewritten.) -->
-Other processors have other kinds of predictors (e.g., the store-to-load bypass predictor in the [[Digital Equipment Corporation|DEC]] [[Alpha 21264]]), and various specialized predictors are likely to flourish in future processors.
-
-These predictors are caches in that they store information that is costly to compute. Some of the terminology used when discussing predictors is the same as that for caches (one speaks of a '''hit''' in a branch predictor), but predictors are not generally thought of as part of the cache hierarchy.
-
-The K8 keeps the instruction and data caches '''[[cache coherency|coherent]]''' in hardware, which means that a store into an instruction closely following the store instruction will change that following instruction. Other processors, like those in the Alpha and MIPS family, have relied on software to keep the instruction cache coherent. Stores are not guaranteed to show up in the instruction stream until a program calls an operating system facility to ensure coherency.
-
-===Tag RAM===
-In computer engineering, a ''tag RAM'' is used to specify which of the possible memory locations is currently stored in a CPU cache.<ref>{{cite web
- | url = http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0363g/Chdijaed.html
- | title = Cortex-R4 and Cortex-R4F Technical Reference Manual
- | access-date = 2013-09-28
- | publisher = arm.com
-}}</ref><ref>{{cite web
- | url = http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0284g/Ebddefci.html
- | title = L210 Cache Controller Technical Reference Manual
- | access-date = 2013-09-28
- | publisher = arm.com
-}}</ref> For a simple, direct-mapped design fast [[static random-access memory|SRAM]] can be used. Higher [[#Associativity|associative caches]] usually employ [[content-addressable memory]].
-
-==Implementation==
-{{Main article|Cache algorithms}}
-
-Cache '''reads''' are the most common CPU operation that takes more than a single cycle. Program execution time tends to be very sensitive to the latency of a level-1 data cache hit. A great deal of design effort, and often power and silicon area are expended making the caches as fast as possible.
-
-The simplest cache is a virtually indexed direct-mapped cache. The virtual address is calculated with an adder, the relevant portion of the address extracted and used to index an SRAM, which returns the loaded data. The data is byte aligned in a byte shifter, and from there is bypassed to the next operation. There is no need for any tag checking in the inner loop{{snd}} in fact, the tags need not even be read. Later in the pipeline, but before the load instruction is retired, the tag for the loaded data must be read, and checked against the virtual address to make sure there was a cache hit. On a miss, the cache is updated with the requested cache line and the pipeline is restarted.
-
-An associative cache is more complicated, because some form of tag must be read to determine which entry of the cache to select. An N-way set-associative level-1 cache usually reads all N possible tags and N data in parallel, and then chooses the data associated with the matching tag. Level-2 caches sometimes save power by reading the tags first, so that only one data element is read from the data SRAM.
-
-[[Image:Cache,associative-read.svg|thumb|right|upright=1.8|Read path for a 2-way associative cache]]
-
-The adjacent diagram is intended to clarify the manner in which the various fields of the address are used. Address bit 31 is most significant, bit 0 is least significant. The diagram shows the SRAMs, indexing, and [[multiplexing]] for a 4 KiB, 2-way set-associative, virtually indexed and virtually tagged cache with 64 byte (B) lines, a 32-bit read width and 32-bit virtual address.
-
-Because the cache is 4 KiB and has 64 B lines, there are just 64 lines in the cache, and we read two at a time from a Tag SRAM which has 32 rows, each with a pair of 21 bit tags. Although any function of virtual address bits 31 through 6 could be used to index the tag and data SRAMs, it is simplest to use the least significant bits.
-
-Similarly, because the cache is 4 KiB and has a 4 B read path, and reads two ways for each access, the Data SRAM is 512 rows by 8 bytes wide.
-
-A more modern cache might be 16 KiB, 4-way set-associative, virtually indexed, virtually hinted, and physically tagged, with 32 B lines, 32-bit read width and 36-bit physical addresses. The read path recurrence for such a cache looks very similar to the path above. Instead of tags, vhints are read, and matched against a subset of the virtual address. Later on in the pipeline, the virtual address is translated into a physical address by the TLB, and the physical tag is read (just one, as the vhint supplies which way of the cache to read). Finally the physical address is compared to the physical tag to determine if a hit has occurred.
-
-Some SPARC designs have improved the speed of their L1 caches by a few gate delays by collapsing the virtual address adder into the SRAM decoders. See [[sum-addressed decoder]].
-
-===History===
-The early history of cache technology is closely tied to the invention and use of virtual memory.{{Citation needed|date=March 2008}} <!-- this *is* a truly interesting observation, but are there any sources? Also why was the "CPU-mam speed" part deleted? ~~~~ --> Because of scarcity and cost of semi-conductor memories, early mainframe computers in the 1960s used a complex hierarchy of physical memory, mapped onto a flat virtual memory space used by programs. The memory technologies would span semi-conductor, magnetic core, drum and disc. Virtual memory seen and used by programs would be flat and caching would be used to fetch data and instructions into the fastest memory ahead of processor access. Extensive studies were done to optimize the cache sizes. Optimal values were found to depend greatly on the programming language used with Algol needing the smallest and Fortran and Cobol needing the largest cache sizes.{{Disputed inline|Talk:CPU cache#Dispute sequence of events for paging|reason=sequence of events wrong|date=December 2010}}
-
-In the early days of microcomputer technology, memory access was only slightly slower than [[processor register|register]] access. But since the 1980s<ref>{{cite journal | url=https://epic.hpi.uni-potsdam.de/pub/Home/TrendsAndConceptsII2010/HW_Trends_The_Processor-Memory_bottleneck___Problems_and_Solutions..pdf | title=The processor-memory bottleneck: problems and solutions | journal=Crossroads | volume=5 | issue=3es | pages=2–es | first1=Nihar R. | last1=Mahapatra | first2=Balakrishna | last2=Venkatrao | access-date=2013-03-05 | doi=10.1145/357783.331677 | year=1999 | s2cid=11557476 | url-status=dead | archive-url=https://web.archive.org/web/20140305193233/https://epic.hpi.uni-potsdam.de/pub/Home/TrendsAndConceptsII2010/HW_Trends_The_Processor-Memory_bottleneck___Problems_and_Solutions..pdf | archive-date=2014-03-05 }}</ref> the performance gap between processor and memory has been growing. Microprocessors have advanced much faster than memory, especially in terms of their operating [[frequency]], so memory became a performance [[Von Neumann architecture#Von Neumann bottleneck|bottleneck]]. While it was technically possible to have all the main memory as fast as the CPU, a more economically viable path has been taken: use plenty of low-speed memory, but also introduce a small high-speed cache memory to alleviate the performance gap. This provided an order of magnitude more capacity—for the same price—with only a slightly reduced combined performance.
-
-====First TLB implementations====
-The first documented uses of a TLB were on the [[GE 645]]<ref>{{cite book
- | publisher = [[General Electric]]
- | title = GE-645 System Manual
- | date = January 1968
- | url = http://bitsavers.org/pdf/ge/GE-645/LSB0468_GE-645_System_Manual_Jan1968.pdf
- | access-date = 2020-07-10
- }}</ref> and the [[IBM]] [[IBM System/360 Model 67|360/67]],<ref>{{cite book
- |publisher = [[IBM]]
- |title = IBM System/360 Model 67 Functional Characteristics
- |id = GA27-2719-2
- |url = http://www.bitsavers.org/pdf/ibm/360/functional_characteristics/GA27-2719-2_360-67_funcChar.pdf
- |version = Third Edition
- |date = February 1972
-}}</ref> both of which used an associative memory as a TLB.
-
-====First instruction cache====
-The first documented use of an instruction cache was on the [[CDC 6600]].<ref>{{citation
- | author = James E. Thornton
- | contribution = Parallel operation in the control data 6600
- | contribution-url = https://cs.uwaterloo.ca/~mashti/cs850-f18/papers/cdc6600.pdf
- | title = Proc. of the October 27-29, 1964, fall joint computer conference, part II: very high speed computer systems
- | date = October 1964}}</ref>
-
-====First data cache====
-The first documented use of a data cache was on the [[IBM]] System/360 Model 85.<ref>{{cite book
- | author = IBM
- | title = IBM System/360 Model 85 Functional Characteristics
- | id = A22-6916-1
- | url = http://www.bitsavers.org/pdf/ibm/360/functional_characteristics/A22-6916-1_360-85_funcChar_Jun68.pdf
- | version = SECOND EDITION
- | date = June 1968}}</ref>
-
-====In 68k microprocessors====
-The [[68010]], released in 1982, has a "loop mode" which can be considered a tiny and special-case instruction cache that accelerates loops that consist of only two instructions. The [[68020]], released in 1984, replaced that with a typical instruction cache of 256 bytes, being the first 68k series processor to feature true on-chip cache memory.
-
-The [[68030]], released in 1987, is basically a 68020 core with an additional 256-byte data cache, an on-chip [[memory management unit]] (MMU), a process shrink, and added burst mode for the caches. The [[Motorola 68040|68040]], released in 1990, has split instruction and data caches of four kilobytes each. The [[68060]], released in 1994, has the following: 8 KiB data cache (four-way associative), 8 KiB instruction cache (four-way associative), 96-byte FIFO instruction buffer, 256-entry branch cache, and 64-entry address translation cache MMU buffer (four-way associative).
-
-====In x86 microprocessors====
-[[File:Motherboard Intel 386.jpg|thumb|Example of a motherboard with an [[i386]] microprocessor (33 MHz), 64 KiB cache (25 ns; 8 chips in the bottom left corner), 2 MiB DRAM (70 ns; 8 [[SIMM]]s to the right of the cache), and a cache controller ([[Austek Microsystems|Austek]] A38202; to the right of the processor)]]
-As the [[x86]] microprocessors reached clock rates of 20 MHz and above in the [[Intel 80386|386]], small amounts of fast cache memory began to be featured in systems to improve performance. This was because the [[DRAM]] used for main memory had significant latency, up to 120 ns, as well as refresh cycles. The cache was constructed from more expensive, but significantly faster, [[static random-access memory|SRAM]] [[Memory cell (computing)|memory cells]], which at the time had latencies around 10–25 ns. The early caches were external to the processor and typically located on the motherboard in the form of eight or nine [[Dual in-line package|DIP]] devices placed in sockets to enable the cache as an optional extra or upgrade feature.
-
-Some versions of the Intel 386 processor could support 16 to 256 KiB of external cache.
-
-With the [[Intel 80486|486]] processor, an 8 KiB cache was integrated directly into the CPU die. This cache was termed Level 1 or L1 cache to differentiate it from the slower on-motherboard, or Level 2 (L2) cache. These on-motherboard caches were much larger, with the most common size being 256 KiB. The popularity of on-motherboard cache continued through the [[Intel P5|Pentium MMX]] era but was made obsolete by the introduction of [[SDRAM]] and the growing disparity between bus clock rates and CPU clock rates, which caused on-motherboard cache to be only slightly faster than main memory.
-
-The next development in cache implementation in the x86 microprocessors began with the [[Pentium Pro]], which brought the secondary cache onto the same package as the microprocessor, clocked at the same frequency as the microprocessor.
-
-On-motherboard caches enjoyed prolonged popularity thanks to the [[AMD K6-2]] and [[AMD K6-III]] processors that still used [[Socket 7]], which was previously used by Intel with on-motherboard caches. K6-III included 256 KiB on-die L2 cache and took advantage of the on-board cache as a third level cache, named L3 (motherboards with up to 2 MiB of on-board cache were produced). After the Socket 7 became obsolete, on-motherboard cache disappeared from the x86 systems.
-
-The three-level caches were used again first with the introduction of multiple processor cores, where the L3 cache was added to the CPU die. It became common for the total cache sizes to be increasingly larger in newer processor generations, and recently (as of 2011) it is not uncommon to find Level 3 cache sizes of tens of megabytes.<ref>{{cite web
- | url = http://ark.intel.com/products/family/59139/Intel-Xeon-Processor-E7-Family/server
- | title = Intel® Xeon® Processor E7 Family
- | access-date = 2013-10-10
- | publisher = [[Intel]]
-}}</ref>
-
-[[Intel]] introduced a Level 4 on-package cache with the [[Haswell (microarchitecture)|Haswell]] [[microarchitecture]]. ''[[Crystalwell]]''<ref name="intel-ark-crystal-well" /> Haswell CPUs, equipped with the [[GT3e]] variant of Intel's integrated Iris Pro graphics, effectively feature 128 MiB of embedded DRAM ([[eDRAM]]) on the same package. This L4 cache is shared dynamically between the on-die GPU and CPU, and serves as a [[victim cache]] to the CPU's L3 cache.<ref name="anandtech-i74950hq" />
-
-====In ARM microprocessors====
-[[Apple M1]] CPU has 128 or 192 KiB instruction L1 cache for each core (important for latency/single-thread performance), depending on core type. This is an unusually large L1 cache for any CPU type (not just for a laptop); the total cache memory size is not unusually large (the total is more important for throughput) for a laptop, and much larger total (e.g. L3 or L4) sizes are available in IBM's mainframes.
-
-====Current research====
-Early cache designs focused entirely on the direct cost of cache and [[random-access memory|RAM]] and average execution speed.
-More recent cache designs also consider [[low-power electronics|energy efficiency]], fault tolerance, and other goals.<ref>{{cite journal
- |url=https://spectrum.ieee.org/computing/hardware/chip-design-thwarts-sneak-attack-on-data
- |title=Chip Design Thwarts Sneak Attack on Data
- |author=Sally Adee
- |year=2009
- |journal= <!-- This is needed for ‘cite journal’ citation templates - should this be ‘cite news’ instead? (delete note when fixed) -->
-}}</ref><ref>{{cite conference|url=http://palms.princeton.edu/system/files/Micro08_Newcache.pdf|title=A novel cache architecture with enhanced performance and security|author1=Zhenghong Wang|author2=Ruby B. Lee|conference=41st annual IEEE/ACM International Symposium on Microarchitecture|pages=83–93|date=November 8–12, 2008|archive-url=https://web.archive.org/web/20120306225926/http://palms.princeton.edu/system/files/Micro08_Newcache.pdf|archive-date=March 6, 2012
- | url-status=live
-}}</ref>
-
-There are several tools available to computer architects to help explore tradeoffs between the cache cycle time, energy, and area; the CACTI cache simulator<ref>{{cite web|url=https://www.hpl.hp.com/research/cacti/ |title=CACTI |website=HP Labs |access-date=2023-01-29}}</ref> and the SimpleScalar instruction set simulator are two open-source options.
-
-===Multi-ported cache===
-A multi-ported cache is a cache which can serve more than one request at a time. When accessing a traditional cache we normally use a single memory address, whereas in a multi-ported cache we may request N addresses at a time{{snd}} where N is the number of ports that connected through the processor and the cache. The benefit of this is that a pipelined processor may access memory from different phases in its pipeline. Another benefit is that it allows the concept of super-scalar processors through different cache levels.
-
-==See also==
-{{Div col|colwidth=30em}}
-* [[Branch predictor]]
-* [[Cache (computing)]]
-* [[Cache algorithms]]
-* [[Cache coherence]]
-* [[Cache control instruction]]s
-* [[Cache hierarchy]]
-* [[Cache placement policies]]
-* [[Cache prefetching]]
-* [[Dinero (cache simulator)|Dinero]] (cache simulator by [[University of Wisconsin System]])
-* [[Instruction unit]]
-* [[Locality of reference]]
-* [[Memoization]]
-* [[Memory hierarchy]]
-* [[Micro-operation]]
-* [[No-write allocation]]
-* [[Scratchpad RAM]]
-* [[Sum-addressed decoder]]
-* [[Write buffer]]
-{{Div col end}}
-
-==Notes==
-{{Reflist|group=NB}}
-
-==References==
-{{Reflist|30em|refs=
-<ref name=AtlasSup>
-{{cite book
- | last1 = Kilburn
- | first1 = T.
- | last2 = Payne
- | first2 = R. B.
- | last3 = Howarth
- | first3 = D. J.
- | title = Computers - Key to Total Systems Control
- | series = Conferences Proceedings
- | pages = 279–294
- | chapter = The Atlas Supervisor
- | chapter-url = http://www.chilton-computing.org.uk/acl/technology/atlas/p019.htm
- | volume = 20 Proceedings of the Eastern Joint Computer Conference Washington, D.C.
- |date=December 1961
- | publisher = Macmillan}}
-</ref>
-
-<ref name=AtlasCPU>
-{{cite book
- | last1 = Sumner
- | first1 = F. H.
- | last2 = Haley
- | first2 = G.
- | last3 = Chenh
- | first3 = E. C. Y.
- | title = Information Processing 1962
- | series = IFIP Congress Proceedings
- | chapter = The Central Control Unit of the 'Atlas' Computer
- | volume = Proceedings of IFIP Congress 62
- | year = 1962
- | publisher = Spartan}}
-</ref>
-}}
-
-==External links==
-{{wikibooks
- |1= Microprocessor Design
- |2= Cache
-}}
-* [https://lwn.net/Articles/252125/ Memory part 2: CPU caches]{{snd}} an article on lwn.net by Ulrich Drepper describing CPU caches in detail
-* [https://minds.wisconsin.edu/bitstream/handle/1793/59076/TR823.pdf Evaluating Associativity in CPU Caches] – Hill and Smith (1989) – introduces capacity, conflict, and compulsory classification
-* [http://www.cs.wisc.edu/multifacet/misc/spec2000cache-data/ Cache Performance for SPEC CPU2000 Benchmarks] – Hill and Cantin (2003) – This reference paper has been updated several times. It has thorough and lucidly presented simulation results for a reasonably wide set of benchmarks and cache organizations.
-* [http://www.sun.com/blueprints/1102/817-0742.pdf Memory Hierarchy in Cache-Based Systems] {{Webarchive|url=https://web.archive.org/web/20090915041601/http://www.sun.com/blueprints/1102/817-0742.pdf |date=2009-09-15 }} – by Ruud van der Pas, 2002, Sun Microsystems – a nice introductory article to CPU memory caching
-* [http://www.freescale.com/files/32bit/doc/app_note/AN2663.pdf A Cache Primer] – by Paul Genua, P.E., 2004, Freescale Semiconductor, another introductory article
-* [https://web.archive.org/web/20110718154522/http://www.zipcores.com/skin1/zipdocs/datasheets/cache_8way_set.pdf An 8-way set-associative cache]{{snd}} written in [[VHDL]]
-* [https://arstechnica.com/old/content/2002/07/caching.ars Understanding CPU caching and performance]{{snd}} an article on Ars Technica by Jon Stokes
-* [http://ixbtlabs.com/articles/ibmpower4/ IBM POWER4 processor review]{{snd}} an article on ixbtlabs by Pavel Danilov
-*[https://www.kivabe.in/2020/07/Cache-memory-ki.html/ What is Cache Memory and its Types!]
-* [https://www.cs.princeton.edu/courses/archive/fall15/cos375/lectures/16-Cache-2x2.pdf Memory Caching]{{snd}} a Princeton University lecture
-
-{{CPU technologies|state=collapsed}}
-
-{{DEFAULTSORT:Cpu Cache}}
-[[Category:Central processing unit]]
-[[Category:Computer memory]]
-[[Category:Cache (computing)]]
+coputer go brrrrrrrrrrrrrrrr
' |
New page size (new_size ) | 28 |
Old page size (old_size ) | 96691 |
Size change in edit (edit_delta ) | -96663 |
Lines added in edit (added_lines ) | [
0 => 'coputer go brrrrrrrrrrrrrrrr'
] |
Lines removed in edit (removed_lines ) | [
0 => '{{Short description|Hardware cache of a central processing unit}}',
1 => 'A '''CPU cache''' is a [[hardware cache]] used by the [[central processing unit]] (CPU) of a [[computer]] to reduce the average cost (time or energy) to access [[data (computer science)|data]] from the [[main memory]].<ref>{{cite web|url=http://www.hardwaresecrets.com/how-the-cache-memory-works/|title=How The Cache Memory Works|author=Gabriel Torres|date=September 12, 2007}}</ref> A cache is a smaller, faster memory, located closer to a [[processor core]], which stores copies of the data from frequently used main [[memory location]]s. Most CPUs have a hierarchy of multiple cache [[#MULTILEVEL|levels]] (L1, L2, often L3, and rarely even L4), with different instruction-specific and data-specific caches at level 1.<ref>{{Cite journal |last1=Su |first1=Chao |last2=Zeng |first2=Qingkai |date=2021-06-10 |editor-last=Nicopolitidis |editor-first=Petros |title=Survey of CPU Cache-Based Side-Channel Attacks: Systematic Analysis, Security Models, and Countermeasures |journal=Security and Communication Networks |language=en |volume=2021 |pages=1–15 |doi=10.1155/2021/5559552 |issn=1939-0122|doi-access=free }}</ref> The cache memory is typically implemented with [[static random-access memory]] (SRAM), in modern CPUs by far the largest part of them by chip area, but SRAM is not always used for all levels (of I- or D-cache), or even any level, sometimes some latter or all levels are implemented with [[eDRAM]].',
2 => '',
3 => 'Other types of caches exist (that are not counted towards the "cache size" of the most important caches mentioned above), such as the [[translation lookaside buffer]] (TLB) which is part of the [[memory management unit]] (MMU) which most CPUs have.',
4 => '',
5 => '=={{Anchor|ICACHE|DCACHE|instruction cache|data cache}}Overview==',
6 => 'When trying to read from or write to a location in the main memory, the processor checks whether the data from that location is already in the cache. If so, the processor will read from or write to the cache instead of the much slower main memory.',
7 => '',
8 => 'Many modern [[desktop computer|desktop]], [[server (computing)|server]], and industrial CPUs have at least three independent caches:',
9 => '',
10 => '; Instruction cache: Used to speed up executable instruction fetch',
11 => '; Data cache: Used to speed up data fetch and store; the data cache is usually organized as a hierarchy of more cache levels (L1, L2, etc.; see also [[#Multi-level caches|multi-level caches]] below). ',
12 => '; [[Translation lookaside buffer]] (TLB): Used to speed up virtual-to-physical address translation for both executable instructions and data. A single TLB can be provided for access to both instructions and data, or a separate Instruction TLB (ITLB) and data TLB (DTLB) can be provided. However, the TLB cache is part of the [[memory management unit]] (MMU) and not directly related to the CPU caches.',
13 => '',
14 => '==History==',
15 => '[[File:NeXTcube motherboard.jpg|thumb|[[Motherboard]] of a [[NeXTcube]] computer (1990). At the lower edge of the image left from the middle, there is the CPU [[Motorola 68040]] operated at 25 [[MHz]] with two separate level 1 caches of 4 KiB each on the chip, one for the instructions and one for data. The board has no external L2 cache.]]',
16 => 'Early examples of CPU caches include the [[Titan (1963 computer)|Atlas 2]]<ref>{{cite web|url=http://www.chilton-computing.org.uk/acl/technology/atlas50th/p005.htm|title=Atlas 2 at Cambridge Mathematical Laboratory (and Aldermaston and CAD Centre)|date=November 2012|quote=Two tunnel diode stores were developed at Cambridge; one, which worked very well, speeded up the fetching of operands, the other was intended to speed up the fetching of instructions. The idea was that most instructions are obeyed in sequence, so when an instruction was fetched that word was placed in the slave store in the location given by the fetch address modulo 32; the remaining bits of the fetch address were also stored. If the wanted word was in the slave it was read from there instead of main memory. This would give a major speedup to instruction loops up to 32 instructions long, and reduced effect for loops up to 64 words.}}</ref> and the [[IBM System/360 Model 85]]<ref>{{cite web|url=http://www.bitsavers.org/pdf/ibm/360/functional_characteristics/A22-6916-1_360-85_funcChar_Jun68.pdf|title=IBM System/360 Model 85 Functional Characteristics|publisher=[[IBM]]|id=A22-6916-1|date=June 1968}}</ref> in the 1960s. The first CPUs that used a cache had only one level of cache; unlike later level 1 cache, it was not split into L1d (for data) and L1i (for instructions). Split L1 cache started in 1976 with the [[IBM 801]] CPU,<ref>{{cite journal|url=http://home.eng.iastate.edu/~zzhang/courses/cpre585-f03/reading/smith-csur82-cache.pdf|title=Cache Memories|first=Alan Jay|last=Smith|journal=Computing Surveys|volume=14|issue=3|date=September 1982|pages=473–530|doi=10.1145/356887.356892|s2cid=6023466}}</ref><ref>{{cite journal|title=Altering Computer Architecture is Way to Raise Throughput, Suggests IBM Researchers|journal=[[Electronics (magazine)|Electronics]]|volume=49|issue=25|date=December 23, 1976|pages=30–31}}</ref> became mainstream in the late 1980s, and in 1997 entered the embedded CPU market with the ARMv5TE. In 2015, even sub-dollar SoCs split the L1 cache. They also have L2 caches and, for larger processors, L3 caches as well. The L2 cache is usually not split, and acts as a common repository for the already split L1 cache. Every core of a [[multi-core processor]] has a dedicated L1 cache and is usually not shared between the cores. The L2 cache, and higher-level caches, may be shared between the cores. L4 cache is currently uncommon, and is generally [[dynamic random-access memory]] (DRAM) on a separate die or chip, rather than [[static random-access memory]] (SRAM). An exception to this is when [[eDRAM]] is used for all levels of cache, down to L1. Historically L1 was also on a separate die, however bigger die sizes have allowed integration of it as well as other cache levels, with the possible exception of the last level. Each extra level of cache tends to be bigger and optimized differently.',
17 => '',
18 => 'Caches (like for RAM historically) have generally been sized in powers of: 2, 4, 8, 16 etc. [[Kibibyte|KiB]]; when up to [[Mebibyte|MiB]] sizes (i.e. for larger non-L1), very early on the pattern broke down, to allow for larger caches without being forced into the doubling-in-size paradigm, with e.g. [[Intel Core 2 Duo]] with 3 MiB L2 cache in April 2008. This happened much later for L1 caches, as their size is generally still a small number of KiB. The [[IBM zEC12 (microprocessor)|IBM zEC12]] from 2012 is an exception however, to gain unusually large 96 KiB L1 data cache for its time, and e.g. the [[IBM z13 (microprocessor)|IBM z13]] having a 96 KiB L1 instruction cache (and 128 KiB L1 data cache),<ref>{{cite web|url=https://www.redbooks.ibm.com/redbooks/pdfs/sg248250.pdf|title=IBM z13 and IBM z13s Technical Introduction|page=20|date=March 2016|publisher=[[IBM]]}}</ref> and Intel [[Ice Lake (microprocessor)|Ice Lake]]-based processors from 2018, having 48 KiB L1 data cache and 48 KiB L1 instruction cache. In 2020, some [[Intel Atom]] CPUs (with up to 24 cores) have (multiple of) 4.5 MiB and 15 MiB cache sizes.<ref>{{Cite press release|url=https://newsroom.intel.com/news/product-fact-sheet-accelerating-5g-network-infrastructure-core-edge/|title=Product Fact Sheet: Accelerating 5G Network Infrastructure, from the Core to the Edge|website=Intel Newsroom|quote=L1 cache of 32KB/core, L2 cache of 4.5MB per 4-core cluster and shared LLC cache up to 15MB.|language=en-US|access-date=2020-04-12}}</ref><ref>{{Cite web|url=https://www.anandtech.com/show/15544/intel-launches-atom-p5900-a-10nm-atom-for-radio-access-networks|title=Intel Launches Atom P5900: A 10nm Atom for Radio Access Networks|last=Smith|first=Ryan|website=www.anandtech.com|access-date=2020-04-12}}</ref>',
19 => '',
20 => '==={{Anchor|cache lines|CACHE-LINES}}Cache entries===',
21 => 'Data is transferred between memory and cache in blocks of fixed size, called ''cache lines'' or ''cache blocks''. When a cache line is copied from memory into the cache, a cache entry is created. The cache entry will include the copied data as well as the requested memory location (called a tag).',
22 => '',
23 => 'When the processor needs to read or write a location in memory, it first checks for a corresponding entry in the cache. The cache checks for the contents of the requested memory location in any cache lines that might contain that address. If the processor finds that the memory location is in the cache, a '''cache hit''' has occurred. However, if the processor does not find the memory location in the cache, a '''cache miss''' has occurred. In the case of a cache hit, the processor immediately reads or writes the data in the cache line. For a cache miss, the cache allocates a new entry and copies data from main memory, then the request is fulfilled from the contents of the cache.',
24 => '',
25 => '===Policies===',
26 => '',
27 => '===={{Anchor|EVICTION}}Replacement policies====',
28 => '{{Main article|Cache replacement policies}}',
29 => '',
30 => 'To make room for the new entry on a cache miss, the cache may have to evict one of the existing entries. The heuristic it uses to choose the entry to evict is called the replacement policy. The fundamental problem with any replacement policy is that it must predict which existing cache entry is least likely to be used in the future. Predicting the future is difficult, so there is no perfect method to choose among the variety of replacement policies available. One popular replacement policy, [[least-recently used]] (LRU), replaces the least recently accessed entry.',
31 => '',
32 => 'Marking some memory ranges as non-cacheable can improve performance, by avoiding caching of memory regions that are rarely re-accessed. This avoids the overhead of loading something into the cache without having any reuse. Cache entries may also be disabled or locked depending on the context.',
33 => '',
34 => '====Write policies====',
35 => '{{Main article|Cache (computing)#WRITEPOLICIES|l1=Cache (computing) § Writing policies}}',
36 => '',
37 => 'If data is written to the cache, at some point it must also be written to main memory; the timing of this write is known as the write policy. In a [[write-through]] cache, every write to the cache causes a write to main memory. Alternatively, in a [[write-back]] or copy-back cache, writes are not immediately mirrored to the main memory, and the cache instead tracks which locations have been written over, marking them as [[Dirty bit|dirty]]. The data in these locations is written back to the main memory only when that data is evicted from the cache. For this reason, a read miss in a write-back cache may sometimes require two memory accesses to service: one to first write the dirty location to main memory, and then another to read the new location from memory. Also, a write to a main memory location that is not yet mapped in a write-back cache may evict an already dirty location, thereby freeing that cache space for the new memory location.',
38 => '',
39 => 'There are intermediate policies as well. The cache may be write-through, but the writes may be held in a store data queue temporarily, usually so multiple stores can be processed together (which can reduce bus turnarounds and improve bus utilization).',
40 => '',
41 => 'Cached data from the main memory may be changed by other entities (e.g., peripherals using [[direct memory access]] (DMA) or another core in a [[multi-core processor]]), in which case the copy in the cache may become out-of-date or stale. Alternatively, when a CPU in a [[multiprocessor]] system updates data in the cache, copies of data in caches associated with other CPUs become stale. Communication protocols between the cache managers that keep the data consistent are known as [[cache coherence]] protocols.',
42 => '',
43 => '===Cache performance===',
44 => '[[Cache performance measurement and metric|Cache performance measurement]] has become important in recent times where the speed gap between the memory performance and the processor performance is increasing exponentially. The cache was introduced to reduce this speed gap. Thus knowing how well the cache is able to bridge the gap in the speed of processor and memory becomes important, especially in high-performance systems. The cache hit rate and the cache miss rate play an important role in determining this performance. To improve the cache performance, reducing the miss rate becomes one of the necessary steps among other steps. Decreasing the access time to the cache also gives a boost to its performance.',
45 => '',
46 => '====CPU stalls====',
47 => 'The time taken to fetch one cache line from memory (read [[Latency (engineering)|latency]] due to a cache miss) matters because the CPU will run out of things to do while waiting for the cache line. When a CPU reaches this state, it is called a stall. As CPUs become faster compared to main memory, stalls due to cache misses displace more potential computation; modern CPUs can execute hundreds of instructions in the time taken to fetch a single cache line from main memory.',
48 => '',
49 => 'Various techniques have been employed to keep the CPU busy during this time, including [[out-of-order execution]] in which the CPU attempts to execute independent instructions after the instruction that is waiting for the cache miss data. Another technology, used by many processors, is [[simultaneous multithreading]] (SMT), which allows an alternate thread to use the CPU core while the first thread waits for required CPU resources to become available.',
50 => '',
51 => '==Associativity==',
52 => '[[Image:Cache,associative-fill-both.png|thumb|450px|An illustration of different ways in which memory locations can be cached by particular cache locations]]',
53 => '{{Main|Cache placement policies}}',
54 => 'The [[Cache placement policies|placement policy]] decides where in the cache a copy of a particular entry of main memory will go. If the placement policy is free to choose any entry in the cache to hold the copy, the cache is called ''fully associative''. At the other extreme, if each entry in the main memory can go in just one place in the cache, the cache is ''direct-mapped''. Many caches implement a compromise in which each entry in the main memory can go to any one of N places in the cache, and are described as N-way set associative.<ref>{{cite web|url=https://cseweb.ucsd.edu/classes/fa10/cse240a/pdf/08/CSE240A-MBT-L15-Cache.ppt.pdf|title=Cache design|date=2010-12-02|website=ucsd.edu|page=10–15|access-date=2023-01-29}}</ref> For example, the level-1 data cache in an [[AMD Athlon]] is two-way set associative, which means that any particular location in main memory can be cached in either of two locations in the level-1 data cache.',
55 => '',
56 => 'Choosing the right value of associativity involves a [[trade-off]]. If there are ten places to which the placement policy could have mapped a memory location, then to check if that location is in the cache, ten cache entries must be searched. Checking more places takes more power and chip area, and potentially more time. On the other hand, caches with more associativity suffer fewer misses (see [[Cache performance measurement and metric#Conflict misses|conflict misses]]), so that the CPU wastes less time reading from the slow main memory. The general guideline is that doubling the associativity, from direct mapped to two-way, or from two-way to four-way, has about the same effect on raising the hit rate as doubling the cache size. However, increasing associativity more than four does not improve hit rate as much,<ref>[http://ieeexplore.ieee.org/xpl/freeabs_all.jsp?arnumber=5234663 IEEE Xplore - Phased set-associative cache design for reduced power consumption]. Ieeexplore.ieee.org (2009-08-11). Retrieved on 2013-07-30.</ref> and are generally done for other reasons (see [[#Virtual aliasing|virtual aliasing]]). Some CPUs can dynamically reduce the associativity of their caches in low-power states, which acts as a power-saving measure.<ref>{{cite web|url=http://hotchips.org/wp-content/uploads/hc_archives/hc24/HC24-1-Microprocessor/HC24.28.117-HotChips_IvyBridge_Power_04.pdf#page=18|title=Power Management of the Third Generation Intel Core Micro Architecture formerly codenamed Ivy Bridge|author1=Sanjeev Jahagirdar|author2=Varghese George|year=2012|website=hotchips.org|page=18|format=PDF|access-date=2015-12-16|author3=Inder Sodhi|author4=Ryan Wells|archive-date=2020-07-29|archive-url=https://web.archive.org/web/20200729002711/http://hotchips.org/wp-content/uploads/hc_archives/hc24/HC24-1-Microprocessor/HC24.28.117-HotChips_IvyBridge_Power_04.pdf#page=18|url-status=dead}}</ref>',
57 => '',
58 => '<!-- where does "pseudo-associative cache" go in this spectrum? -->',
59 => 'In order of worse but simple to better but complex:',
60 => '',
61 => '* Direct mapped cache{{snd}} good best-case time, but unpredictable in the worst case',
62 => '* Two-way set associative cache',
63 => '* Two-way skewed associative cache<ref name="Seznec">{{cite journal|author=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>',
64 => '* Four-way set-associative cache',
65 => '* Eight-way set-associative cache, a common choice for later implementations',
66 => '* 12-way set associative cache, similar to eight-way',
67 => '* Fully associative cache{{snd}} the best miss rates, but practical only for a small number of entries',
68 => '',
69 => '===Direct-mapped cache===',
70 => 'In this cache organization, each location in the main memory can go in only one entry in the cache. Therefore, a direct-mapped cache can also be called a "one-way set associative" cache. It does not have a placement policy as such, since there is no choice of which cache entry's contents to evict. This means that if two locations map to the same entry, they may continually knock each other out. Although simpler, a direct-mapped cache needs to be much larger than an associative one to give comparable performance, and it is more unpredictable. Let {{mvar|x}} be block number in cache, {{mvar|y}} be block number of memory, and {{mvar|n}} be number of blocks in cache, then mapping is done with the help of the equation {{math|''x'' {{=}} ''y'' mod ''n''}}.',
71 => '',
72 => '===Two-way set associative cache===',
73 => 'If each location in the main memory can be cached in either of two locations in the cache, one logical question is: ''which one of the two?'' The simplest and most commonly used scheme, shown in the right-hand diagram above, is to use the least significant bits of the memory location's index as the index for the cache memory, and to have two entries for each index. One benefit of this scheme is that the tags stored in the cache do not have to include that part of the main memory address which is implied by the cache memory's index. Since the cache tags have fewer bits, they require fewer transistors, take less space on the processor circuit board or on the microprocessor chip, and can be read and compared faster. Also [[Cache algorithms|LRU]] is especially simple since only one bit needs to be stored for each pair.',
74 => '',
75 => '===Speculative execution===',
76 => 'One of the advantages of a direct-mapped cache is that it allows simple and fast [[speculative execution|speculation]]. Once the address has been computed, the one cache index which might have a copy of that location in memory is known. That cache entry can be read, and the processor can continue to work with that data before it finishes checking that the tag actually matches the requested address.',
77 => '',
78 => 'The idea of having the processor use the cached data before the tag match completes can be applied to associative caches as well. A subset of the tag, called a ''hint'', can be used to pick just one of the possible cache entries mapping to the requested address. The entry selected by the hint can then be used in parallel with checking the full tag. The hint technique works best when used in the context of address translation, as explained below.',
79 => '',
80 => '===Two-way skewed associative cache===',
81 => 'Other schemes have been suggested, such as the ''skewed cache'',<ref name="Seznec" /> 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|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>',
82 => '{{cite web |url=https://www.irisa.fr/caps/PROJECTS/Architecture/ |title=Micro-Architecture] |quote=Skewed-associative caches have been shown to have two major advantages over conventional set-associative caches.}}</ref>',
83 => '',
84 => '===Pseudo-associative cache===',
85 => 'A true set-associative cache tests all the possible ways simultaneously, using something like a [[content-addressable memory]]. A pseudo-associative cache tests each possible way one at a time. A hash-rehash cache and a column-associative cache are examples of a pseudo-associative cache.',
86 => '',
87 => 'In the common case of finding a hit in the first way tested, a pseudo-associative cache is as fast as a direct-mapped cache, but it has a much lower conflict miss rate than a direct-mapped cache, closer to the miss rate of a fully associative cache.',
88 => '<ref name="CK" />',
89 => '',
90 => '===Multicolumn cache===',
91 => 'Comparing with a direct-mapped cache, a set associative cache has a reduced number of bits for its cache set index that maps to a cache set, where multiple ways or blocks stays, such as 2 blocks for a 2-way set associative cache and 4 blocks for a 4-way set associative cache. Comparing with a direct mapped cache, the unused cache index bits become a part of the tag bits. For example, a 2-way set associative cache contributes 1 bit to the tag and a 4-way set associative cache contributes 2 bits to the tag. The basic idea of the multicolumn cache<ref name="Two-fast">{{Cite journal |author1= Chenxi Zhang |author2 =Xiaodong Zhang |author3= Yong Yan| title=Two fast and high-associativity cache schemes |journal= IEEE Micro |volume= 17 |issue= 5 | date= September–October 1997 |pages = 40–49 |doi= 10.1109/40.621212}}</ref> is to use the set index to map to a cache set as a conventional set associative cache does, and to use the added tag bits to index a way in the set. For example, in a 4-way set associative cache, the two bits are used to index way 00, way 01, way 10, and way 11, respectively. This double cache indexing is called a “major location mapping”, and its latency is equivalent to a direct-mapped access. Extensive experiments in multicolumn cache design<ref name="Two-fast" /> shows that the hit ratio to major locations is as high as 90%. If cache mapping conflicts with a cache block in the major location, the existing cache block will be moved to another cache way in the same set, which is called “selected location”. Because the newly indexed cache block is a most recently used (MRU) block, it is placed in the major location in multicolumn cache with a consideration of temporal locality. Since multicolumn cache is designed for a cache with a high associativity, the number of ways in each set is high; thus, it is easy find a selected location in the set. A selected location index by an additional hardware is maintained for the major location in a cache block.{{Citation needed|date=May 2023}}',
92 => '',
93 => 'Multicolumn cache remains a high hit ratio due to its high associativity, and has a comparable low latency to a direct-mapped cache due to its high percentage of hits in major locations. The concepts of major locations and selected locations in multicolumn cache have been used in several cache designs in ARM Cortex R chip,<ref>{{Cite web |date=2014 |title=ARM® Cortex®-R Series Programmer's Guide |url=https://developer.arm.com/documentation/den0042/latest |access-date=2023-05-04 |website=developer.arm.com}}</ref> Intel's way-predicting cache memory,<ref>{{Cite web|url=https://patents.google.com/patent/US6425055B1/en|title=Way-predicting cache memory}}</ref> IBM's reconfigurable multi-way associative cache memory<ref>{{Cite web |date=November 22, 1994 |title=United States Patent |url=https://rpx-patents.s3.amazonaws.com/US/c530f-US5367653A/US5367653A.pdf |access-date=2023-05-04 |website=rpx-patents.s3.amazonaws.com}}</ref> and Oracle's dynamic cache replacement way selection based on address tab bits.<ref>{{Cite web|url=https://patents.justia.com/patent/20160350229|title=US Patent Application for DYNAMIC CACHE REPLACEMENT WAY SELECTION BASED ON ADDRESS TAG BITS Patent Application (Application #20160350229 issued December 1, 2016) - Justia Patents Search|website=patents.justia.com}}</ref>',
94 => '',
95 => '==Cache entry structure==',
96 => 'Cache row entries usually have the following structure:',
97 => '',
98 => '{| style="width:30%; text-align:center" border="1"',
99 => '|-',
100 => '| tag || data block || flag bits',
101 => '|}',
102 => '',
103 => 'The ''data block'' (cache line) contains the actual data fetched from the main memory. The ''tag'' contains (part of) the address of the actual data fetched from the main memory. The flag bits are [[#Flag_bits|discussed below]].',
104 => '',
105 => 'The "size" of the cache is the amount of main memory data it can hold. This size can be calculated as the number of bytes stored in each data block times the number of blocks stored in the cache. (The tag, flag and [[ECC memory#Cache|error correction code]] bits are not included in the size,<ref>{{cite web|author=Nathan N. Sadler|author2=Daniel J. Sorin|url=http://people.ee.duke.edu/~sorin/papers/iccd06_perc.pdf|title=Choosing an Error Protection Scheme for a Microprocessor's L1 Data Cache|year=2006|page=4}}</ref> although they do affect the physical area of a cache.)',
106 => '',
107 => 'An effective memory address which goes along with the cache line (memory block) is split ([[Most significant bit|MSB]] to [[Least significant bit|LSB]]) into the tag, the index and the block offset.<ref>{{cite book|author1=John L. Hennessy|author2=David A. Patterson|title=Computer Architecture: A Quantitative Approach|year=2011|publisher=Elsevier |isbn=978-0-12-383872-8|at=p. B-9|url=https://books.google.com/books?id=v3-1hVwHnHwC&q=Hennessey+%22block+offset%22&pg=PA120}}</ref><ref>{{cite book|author1=David A. Patterson|author2=John L. Hennessy|title=Computer Organization and Design: The Hardware/Software Interface|year=2009|isbn=978-0-12-374493-7|page=484|publisher=Morgan Kaufmann |url=https://books.google.com/books?id=3b63x-0P3_UC&q=Hennessey+%22block+offset%22&pg=PA484}}</ref>',
108 => '',
109 => '{| style="width:30%; text-align:center" border="1"',
110 => '|-',
111 => '| tag || index || block offset',
112 => '|}',
113 => '',
114 => 'The index describes which cache set that the data has been put in. The index length is <math>\lceil \log_2(s) \rceil</math> bits for {{mvar|s}} cache sets.',
115 => '',
116 => 'The block offset specifies the desired data within the stored data block within the cache row. Typically the effective address is in bytes, so the block offset length is <math>\lceil \log_2(b) \rceil</math> bits, where {{mvar|b}} is the number of bytes per data block.',
117 => 'The tag contains the most significant bits of the address, which are checked against all rows in the current set (the set has been retrieved by index) to see if this set contains the requested address. If it does, a cache hit occurs. The tag length in bits is as follows:',
118 => '',
119 => '::<code>tag_length = address_length - index_length - block_offset_length</code>',
120 => '',
121 => 'Some authors refer to the block offset as simply the "offset"<ref name="ccs.neu.edu">{{cite web|author=Gene Cooperman|title=Cache Basics|year=2003|url=http://www.ccs.neu.edu/course/com3200/parent/NOTES/cache-basics.html}}</ref> or the "displacement".<ref>{{cite web|author=Ben Dugan|title=Concerning Cache|year=2002|url=http://www.cs.washington.edu/education/courses/cse378/02sp/sections/section9-1.html}}</ref><ref>Harvey G. Cragon.',
122 => '"Memory systems and pipelined processors".',
123 => '1996. {{ISBN|0-86720-474-5}}, {{ISBN|978-0-86720-474-2}}.',
124 => '"Chapter 4.1: Cache Addressing, Virtual or Real"',
125 => 'p. 209',
126 => '[https://books.google.com/books?id=q2w3JSFD7l4C&dq=displacement+tag+cache&pg=PA209]',
127 => '</ref>',
128 => '',
129 => '===Example===',
130 => 'The original [[Pentium 4]] processor had a four-way set associative L1 data cache of 8 [[Kibibyte|KiB]] in size, with 64-byte cache blocks. Hence, there are 8 KiB / 64 = 128 cache blocks. The number of sets is equal to the number of cache blocks divided by the number of ways of associativity, what leads to 128 / 4 = 32 sets, and hence 2<sup>5</sup> = 32 different indices. There are 2<sup>6</sup> = 64 possible offsets. Since the CPU address is 32 bits wide, this implies 32 - 5 - 6 = 21 bits for the tag field.',
131 => '',
132 => 'The original Pentium 4 processor also had an eight-way set associative L2 integrated cache 256 KiB in size, with 128-byte cache blocks. This implies 32 - 8 - 7 = 17 bits for the tag field.<ref name="ccs.neu.edu" />',
133 => '',
134 => '==={{Anchor|Flag bits}} Flag bits===',
135 => 'An instruction cache requires only one flag bit per cache row entry: a valid bit. The valid bit indicates whether or not a cache block has been loaded with valid data.',
136 => '',
137 => 'On power-up, the hardware sets all the valid bits in all the caches to "invalid". Some systems also set a valid bit to "invalid" at other times, such as when multi-master [[bus snooping]] hardware in the cache of one processor hears an address broadcast from some other processor, and realizes that certain data blocks in the local cache are now stale and should be marked invalid.',
138 => '',
139 => 'A data cache typically requires two flag bits per cache line{{snd}} a valid bit and a [[dirty bit]]. Having a dirty bit set indicates that the associated cache line has been changed since it was read from main memory ("dirty"), meaning that the processor has written data to that line and the new value has not propagated all the way to main memory.',
140 => '',
141 => '=={{Anchor|CACHE-MISS}}Cache miss==',
142 => 'A cache miss is a failed attempt to read or write a piece of data in the cache, which results in a main memory access with much longer latency. There are three kinds of cache misses: instruction read miss, data read miss, and data write miss.',
143 => '',
144 => '''Cache read misses'' from an ''instruction'' cache generally cause the largest delay, because the processor, or at least the [[Simultaneous multithreading|thread of execution]], has to wait (stall) until the instruction is fetched from main memory. ''Cache read misses'' from a ''data'' cache usually cause a smaller delay, because instructions not dependent on the cache read can be issued and continue execution until the data is returned from main memory, and the dependent instructions can resume execution. ''Cache write misses'' to a ''data'' cache generally cause the shortest delay, because the write can be queued and there are few limitations on the execution of subsequent instructions; the processor can continue until the queue is full. For a detailed introduction to the types of misses, see [[cache performance measurement and metric]].',
145 => '',
146 => '=={{Anchor|ADDRTRANS}}Address translation==',
147 => 'Most general purpose CPUs implement some form of [[virtual memory]]. To summarize, either each program running on the machine sees its own simplified [[address space]], which contains code and data for that program only, or all programs run in a common virtual address space. A program executes by calculating, comparing, reading and writing to addresses of its virtual address space, rather than addresses of physical address space, making programs simpler and thus easier to write.',
148 => '',
149 => 'Virtual memory requires the processor to translate virtual addresses generated by the program into physical addresses in main memory. The portion of the processor that does this translation is known as the [[memory management unit]] (MMU). The fast path through the MMU can perform those translations stored in the [[translation lookaside buffer]] (TLB), which is a cache of mappings from the operating system's [[page table]], segment table, or both.',
150 => '',
151 => 'For the purposes of the present discussion, there are three important features of address translation:',
152 => '',
153 => '* ''Latency:'' The physical address is available from the MMU some time, perhaps a few cycles, after the virtual address is available from the address generator.',
154 => '* {{Anchor|Virtual aliasing}}''Aliasing:'' Multiple virtual addresses can map to a single physical address. Most processors guarantee that all updates to that single physical address will happen in program order. To deliver on that guarantee, the processor must ensure that only one copy of a physical address resides in the cache at any given time.',
155 => '* ''Granularity:'' The virtual address space is broken up into pages. For instance, a 4 [[Gibibyte|GiB]] virtual address space might be cut up into 1,048,576 pages of 4 KiB size, each of which can be independently mapped. There may be multiple page sizes supported; see [[virtual memory]] for elaboration.',
156 => '',
157 => 'One early virtual memory system, the [[IBM M44/44X]], required an access to a mapping table held in [[core memory]] before every programmed access to main memory.<ref>{{cite conference|author=R. W. O'Neill|title=Experience using a time sharing multiprogramming system with dynamic address relocation hardware|conference=Proc. AFIPS Computer Conference 30 (Spring Joint Computer Conference, 1967)|pages=611–621|doi=10.1145/1465482.1465581}}</ref>{{refn|The very first paging machine, the [[Ferranti]] [[Atlas Computer (Manchester)|Atlas]]<ref name=AtlasCPU/><ref name=AtlasSup/> had no page tables in main memory; there was an associative memory with one entry for every 512 word page frame of core.|group=NB}} With no caches, and with the mapping table memory running at the same speed as main memory this effectively cut the speed of memory access in half. Two early machines that used a [[page table]] in main memory for mapping, the [[IBM System/360 Model 67]] and the [[GE 645]], both had a small associative memory as a cache for accesses to the in-memory page table. Both machines predated the first machine with a cache for main memory, the [[IBM System/360 Model 85]], so the first hardware cache used in a computer system was not a data or instruction cache, but rather a TLB.',
158 => '',
159 => 'Caches can be divided into four types, based on whether the index or tag correspond to physical or virtual addresses:',
160 => '',
161 => '* ''Physically indexed, physically tagged'' (PIPT) caches use the physical address for both the index and the tag. While this is simple and avoids problems with aliasing, it is also slow, as the physical address must be looked up (which could involve a TLB miss and access to main memory) before that address can be looked up in the cache.',
162 => '* ''Virtually indexed, virtually tagged'' (VIVT) caches use the virtual address for both the index and the tag. This caching scheme can result in much faster lookups, since the MMU does not need to be consulted first to determine the physical address for a given virtual address. However, VIVT suffers from aliasing problems, where several different virtual addresses may refer to the same physical address. The result is that such addresses would be cached separately despite referring to the same memory, causing coherency problems. Although solutions to this problem exist<ref>{{cite conference|last1=Kaxiras|first1=Stefanos|last2=Ros|first2=Alberto|title=A New Perspective for Efficient Virtual-Cache Coherence|conference=40th International Symposium on Computer Architecture (ISCA)|date=2013|pages=535–547|doi=10.1145/2485922.2485968|isbn=9781450320795|citeseerx=10.1.1.307.9125|s2cid=15434231}}</ref> they do not work for standard coherence protocols. Another problem is homonyms, where the same virtual address maps to several different physical addresses. It is not possible to distinguish these mappings merely by looking at the virtual index itself, though potential solutions include: flushing the cache after a [[context switch]], forcing address spaces to be non-overlapping, tagging the virtual address with an address space ID (ASID). Additionally, there is a problem that virtual-to-physical mappings can change, which would require flushing cache lines, as the VAs would no longer be valid. All these issues are absent if tags use physical addresses (VIPT).',
163 => '* ''Virtually indexed, physically tagged'' (VIPT) caches use the virtual address for the index and the physical address in the tag. The advantage over PIPT is lower latency, as the cache line can be looked up in parallel with the TLB translation, however the tag cannot be compared until the physical address is available. The advantage over VIVT is that since the tag has the physical address, the cache can detect homonyms. Theoretically, VIPT requires more tags bits because some of the index bits could differ between the virtual and physical addresses (for example bit 12 and above for 4 KiB pages) and would have to be included both in the virtual index and in the physical tag. In practice this is not an issue because, in order to avoid coherency problems, VIPT caches are designed to have no such index bits (e.g., by limiting the total number of bits for the index and the block offset to 12 for 4 KiB pages); this limits the size of VIPT caches to the page size times the associativity of the cache.',
164 => '* ''Physically indexed, virtually tagged'' (PIVT) caches are often claimed in literature to be useless and non-existing.<ref>{{cite magazine |url=http://www.linuxjournal.com/article/7105 |title=Understanding Caching |magazine=Linux Journal |access-date=2010-05-02}}</ref> However, the [[MIPS architecture|MIPS]] [[R6000]] uses this cache type as the sole known implementation.<ref>{{cite journal|first1=George|last1=Taylor|first2=Peter|last2=Davies|first3=Michael|last3=Farmwald|title=The TLB Slice - A Low-Cost High-Speed Address Translation Mechanism|year=1990|id=CH2887-8/90/0000/0355$01.OO}}</ref> The R6000 is implemented in [[emitter-coupled logic]], which is an extremely fast technology not suitable for large memories such as a [[Translation lookaside buffer|TLB]]. The R6000 solves the issue by putting the TLB memory into a reserved part of the second-level cache having a tiny, high-speed TLB "slice" on chip. The cache is indexed by the physical address obtained from the TLB slice. However, since the TLB slice only translates those virtual address bits that are necessary to index the cache and does not use any tags, false cache hits may occur, which is solved by tagging with the virtual address.',
165 => '',
166 => 'The speed of this recurrence (the ''load latency'') is crucial to CPU performance, and so most modern level-1 caches are virtually indexed, which at least allows the MMU's TLB lookup to proceed in parallel with fetching the data from the cache RAM.',
167 => '',
168 => 'But virtual indexing is not the best choice for all cache levels. The cost of dealing with virtual aliases grows with cache size, and as a result most level-2 and larger caches are physically indexed.',
169 => '',
170 => 'Caches have historically used both virtual and physical addresses for the cache tags, although virtual tagging is now uncommon. If the TLB lookup can finish before the cache RAM lookup, then the physical address is available in time for tag compare, and there is no need for virtual tagging. Large caches, then, tend to be physically tagged, and only small, very low latency caches are virtually tagged. In recent general-purpose CPUs, virtual tagging has been superseded by vhints, as described below.',
171 => '',
172 => '===Homonym and synonym problems===',
173 => 'A cache that relies on virtual indexing and tagging becomes inconsistent after the same virtual address is mapped into different physical addresses ([[homonym]]), which can be solved by using physical address for tagging, or by storing the address space identifier in the cache line. However, the latter approach does not help against the [[synonym]] problem, in which several cache lines end up storing data for the same physical address. Writing to such locations may update only one location in the cache, leaving the others with inconsistent data. This issue may be solved by using non-overlapping memory layouts for different address spaces, or otherwise the cache (or a part of it) must be flushed when the mapping changes.<ref>{{cite web',
174 => ' | url = http://www.systems.ethz.ch/education/courses/fs09/aos/lectures/wk3-print.pdf',
175 => ' | archive-url = https://web.archive.org/web/20111007150424/http://www.systems.ethz.ch/education/past-courses/fs09/aos/lectures/wk3-print.pdf |url-status = dead',
176 => ' | title = Advanced Operating Systems Caches and TLBs (263-3800-00L)',
177 => ' | date = 2009-03-03 | access-date = 2016-02-14 | archive-date = 2011-10-07',
178 => ' | author1 = Timothy Roscoe | author2 = Andrew Baumann',
179 => ' | website = systems.ethz.ch }}</ref>',
180 => '',
181 => '===Virtual tags and vhints===',
182 => 'The great advantage of virtual tags is that, for associative caches, they allow the tag match to proceed before the virtual to physical translation is done. However, coherence probes and evictions present a physical address for action. The hardware must have some means of converting the physical addresses into a cache index, generally by storing physical tags as well as virtual tags. For comparison, a physically tagged cache does not need to keep virtual tags, which is simpler. When a virtual to physical mapping is deleted from the TLB, cache entries with those virtual addresses will have to be flushed somehow. Alternatively, if cache entries are allowed on pages not mapped by the TLB, then those entries will have to be flushed when the access rights on those pages are changed in the page table.',
183 => '',
184 => 'It is also possible for the operating system to ensure that no virtual aliases are simultaneously resident in the cache. The operating system makes this guarantee by enforcing page coloring, which is described below. Some early RISC processors (SPARC, RS/6000) took this approach. It has not been used recently, as the hardware cost of detecting and evicting virtual aliases has fallen and the software complexity and performance penalty of perfect page coloring has risen.',
185 => '',
186 => 'It can be useful to distinguish the two functions of tags in an associative cache: they are used to determine which way of the entry set to select, and they are used to determine if the cache hit or missed. The second function must always be correct, but it is permissible for the first function to guess, and get the wrong answer occasionally.',
187 => '',
188 => 'Some processors (e.g. early SPARCs) have caches with both virtual and physical tags. The virtual tags are used for way selection, and the physical tags are used for determining hit or miss. This kind of cache enjoys the latency advantage of a virtually tagged cache, and the simple software interface of a physically tagged cache. It bears the added cost of duplicated tags, however. Also, during miss processing, the alternate ways of the cache line indexed have to be probed for virtual aliases and any matches evicted.',
189 => '',
190 => 'The extra area (and some latency) can be mitigated by keeping ''virtual hints'' with each cache entry instead of virtual tags. These hints are a subset or hash of the virtual tag, and are used for selecting the way of the cache from which to get data and a physical tag. Like a virtually tagged cache, there may be a virtual hint match but physical tag mismatch, in which case the cache entry with the matching hint must be evicted so that cache accesses after the cache fill at this address will have just one hint match. Since virtual hints have fewer bits than virtual tags distinguishing them from one another, a virtually hinted cache suffers more conflict misses than a virtually tagged cache.',
191 => '',
192 => 'Perhaps the ultimate reduction of virtual hints can be found in the Pentium 4 (Willamette and Northwood cores). In these processors the virtual hint is effectively two bits, and the cache is four-way set associative. Effectively, the hardware maintains a simple permutation from virtual address to cache index, so that no [[content-addressable memory]] (CAM) is necessary to select the right one of the four ways fetched.',
193 => '',
194 => '===Page coloring===',
195 => '{{Main article|Cache coloring}}',
196 => '',
197 => 'Large physically indexed caches (usually secondary caches) run into a problem: the operating system rather than the application controls which pages collide with one another in the cache. Differences in page allocation from one program run to the next lead to differences in the cache collision patterns, which can lead to very large differences in program performance. These differences can make it very difficult to get a consistent and repeatable timing for a benchmark run.',
198 => '',
199 => 'To understand the problem, consider a CPU with a 1 MiB physically indexed direct-mapped level-2 cache and 4 KiB virtual memory pages. Sequential physical pages map to sequential locations in the cache until after 256 pages the pattern wraps around. We can label each physical page with a color of 0–255 to denote where in the cache it can go. Locations within physical pages with different colors cannot conflict in the cache.',
200 => '',
201 => 'Programmers attempting to make maximum use of the cache may arrange their programs' access patterns so that only 1 MiB of data need be cached at any given time, thus avoiding capacity misses. But they should also ensure that the access patterns do not have conflict misses. One way to think about this problem is to divide up the virtual pages the program uses and assign them virtual colors in the same way as physical colors were assigned to physical pages before. Programmers can then arrange the access patterns of their code so that no two pages with the same virtual color are in use at the same time. There is a wide literature on such optimizations (e.g. [[loop nest optimization]]), largely coming from the [[High Performance Computing|High Performance Computing (HPC)]] community.',
202 => '',
203 => 'The snag is that while all the pages in use at any given moment may have different virtual colors, some may have the same physical colors. In fact, if the operating system assigns physical pages to virtual pages randomly and uniformly, it is extremely likely that some pages will have the same physical color, and then locations from those pages will collide in the cache (this is the [[birthday paradox]]).',
204 => '',
205 => 'The solution is to have the operating system attempt to assign different physical color pages to different virtual colors, a technique called ''page coloring''. Although the actual mapping from virtual to physical color is irrelevant to system performance, odd mappings are difficult to keep track of and have little benefit, so most approaches to page coloring simply try to keep physical and virtual page colors the same.',
206 => '',
207 => 'If the operating system can guarantee that each physical page maps to only one virtual color, then there are no virtual aliases, and the processor can use virtually indexed caches with no need for extra virtual alias probes during miss handling. Alternatively, the OS can flush a page from the cache whenever it changes from one virtual color to another. As mentioned above, this approach was used for some early SPARC and RS/6000 designs.',
208 => '',
209 => 'The software page coloring technique has been used to effectively partition the shared Last level Cache (LLC) in multicore processors.<ref>{{Cite conference |author1= Jiang Lin |author2=Qingda Lu |author3=Xiaoning Ding |author4=Zhao Zhang |author5=Xiaodong Zhang |author6=P. Sadayappan | title=Gaining insights into multicore cache partitioning: Bridging the gap between simulation and real systems |conference= IEEE 14th International Symposium on High Performance Computer Architecture |location= Salt Lake City, UT |date= 2008 |pages = 367–378 |doi= 10.1109/HPCA.2008.4658653}}</ref> This operating system-based LLC management in multicore processors has been adopted by Intel.<ref>{{Cite web|url=http://web.cse.ohio-state.edu/~zhang.574/OS-cache-software_intel_2010.pdf|title=Letter to Jiang Lin}}</ref>',
210 => '',
211 => '=={{Anchor|Cache hierarchy}}Cache hierarchy in a modern processor==',
212 => '[[File:Hwloc.png|thumb|right|300px|Memory hierarchy of an AMD Bulldozer server]]',
213 => '',
214 => 'Modern processors have multiple interacting on-chip caches. The operation of a particular cache can be completely specified by the cache size, the cache block size, the number of blocks in a set, the cache set replacement policy, and the cache write policy (write-through or write-back).<ref name="ccs.neu.edu" />',
215 => '',
216 => 'While all of the cache blocks in a particular cache are the same size and have the same associativity, typically the "lower-level" caches (called Level 1 cache) have a smaller number of blocks, smaller block size, and fewer blocks in a set, but have very short access times. "Higher-level" caches (i.e. Level 2 and above) have progressively larger numbers of blocks, larger block size, more blocks in a set, and relatively longer access times, but are still much faster than main memory.',
217 => '',
218 => 'Cache entry replacement policy is determined by a [[cache algorithm]] selected to be implemented by the processor designers. In some cases, multiple algorithms are provided for different kinds of work loads.',
219 => '',
220 => '===Specialized caches===',
221 => 'Pipelined CPUs access memory from multiple points in the [[Instruction pipeline|pipeline]]: instruction fetch, [[virtual memory|virtual-to-physical]] address translation, and data fetch (see [[classic RISC pipeline]]). The natural design is to use different physical caches for each of these points, so that no one physical resource has to be scheduled to service two points in the pipeline. Thus the pipeline naturally ends up with at least three separate caches (instruction, [[translation lookaside buffer|TLB]], and data), each specialized to its particular role.',
222 => '',
223 => '====Victim cache====',
224 => '{{Main article|Victim cache}}',
225 => 'A '''victim cache''' is a cache used to hold blocks evicted from a CPU cache upon replacement. The victim cache lies between the main cache and its refill path, and holds only those blocks of data that were evicted from the main cache. The victim cache is usually fully associative, and is intended to reduce the number of conflict misses. Many commonly used programs do not require an associative mapping for all the accesses. In fact, only a small fraction of the memory accesses of the program require high associativity. The victim cache exploits this property by providing high associativity to only these accesses. It was introduced by [[Norman Jouppi]] from DEC in 1990.<ref>N.P.Jouppi. "Improving direct-mapped cache performance by the addition of a small {{Sic|hide=y|fully|-}}associative cache and prefetch buffers." - 17th Annual International Symposium on Computer Architecture, 1990. Proceedings., {{doi|10.1109/ISCA.1990.134547}}</ref>',
226 => '',
227 => 'Intel's ''[[Crystalwell]]''<ref name="intel-ark-crystal-well">{{cite web',
228 => ' | url = http://ark.intel.com/products/codename/51802/Crystal-Well',
229 => ' | title = Products (Formerly Crystal Well)',
230 => ' | publisher = [[Intel]]',
231 => ' | access-date = 2013-09-15',
232 => '}}</ref> variant of its [[Haswell (microarchitecture)|Haswell]] processors introduced an on-package 128 MiB [[eDRAM]] Level 4 cache which serves as a victim cache to the processors' Level 3 cache.<ref name="anandtech-i74950hq">{{cite web',
233 => ' | url = http://www.anandtech.com/show/6993/intel-iris-pro-5200-graphics-review-core-i74950hq-tested/3',
234 => ' | title = Intel Iris Pro 5200 Graphics Review: Core i7-4950HQ Tested',
235 => ' | publisher = [[AnandTech]]',
236 => ' | access-date = 2013-09-16',
237 => '}}</ref> In the [[Skylake (microarchitecture)|Skylake]] microarchitecture the Level 4 cache no longer works as a victim cache.<ref>{{cite web',
238 => ' | url = http://www.anandtech.com/show/9582/intel-skylake-mobile-desktop-launch-architecture-analysis/5',
239 => ' | title = The Intel Skylake Mobile and Desktop Launch, with Architecture Analysis',
240 => ' | author = Ian Cutress',
241 => ' | date = September 2, 2015',
242 => ' | publisher = AnandTech',
243 => '}}</ref>',
244 => '',
245 => '===={{Anchor|TRACE-CACHE}}Trace cache====',
246 => '{{Main article|Trace cache}}',
247 => '',
248 => 'One of the more extreme examples of cache specialization is the '''trace cache''' (also known as ''execution trace cache'') found in the [[Intel]] [[Pentium 4]] microprocessors. A trace cache is a mechanism for increasing the instruction fetch bandwidth and decreasing power consumption (in the case of the Pentium 4) by storing traces of [[instruction (computer science)|instruction]]s that have already been fetched and decoded.<ref>{{cite web',
249 => ' | url = http://www.anandtech.com/show/661/5',
250 => ' | title = The Pentium 4's Cache – Intel Pentium 4 1.4 GHz & 1.5 GHz',
251 => ' | date = 2000-11-20 | access-date = 2015-11-30',
252 => ' | author = Anand Lal Shimpi | publisher = [[AnandTech]]',
253 => '}}</ref>',
254 => '',
255 => 'A trace cache stores instructions either after they have been decoded, or as they are retired. Generally, instructions are added to trace caches in groups representing either individual [[basic block]]s or dynamic instruction traces. The Pentium 4's trace cache stores [[micro-operations]] resulting from decoding x86 instructions, providing also the functionality of a micro-operation cache. Having this, the next time an instruction is needed, it does not have to be decoded into micro-ops again.<ref name="agner.org" />{{rp|63–68}}',
256 => '',
257 => '====Write Coalescing Cache (WCC)====',
258 => 'Write Coalescing Cache<ref>{{cite web|url=http://www.realworldtech.com/bulldozer/9/|title=AMD's Bulldozer Microarchitecture - Memory Subsystem Continued|date=August 26, 2010|author=David Kanter|website=Real World Technologies}}</ref> is a special cache that is part of L2 cache in [[AMD]]'s [[Bulldozer (microarchitecture)|Bulldozer microarchitecture]]. Stores from both L1D caches in the module go through the WCC, where they are buffered and coalesced.',
259 => 'The WCC's task is reducing number of writes to the L2 cache.',
260 => '',
261 => '===={{Anchor|UOP-CACHE}}Micro-operation (μop or uop) cache====',
262 => 'A '''micro-operation cache''' ('''μop cache''', '''uop cache''' or '''UC''')<ref>{{cite web|url=http://www.realworldtech.com/sandy-bridge/4/|title=Intel's Sandy Bridge Microarchitecture - Instruction Decode and uop Cache|date=September 25, 2010|author=David Kanter|website=Real World Technologies}}</ref> is a specialized cache that stores [[micro-operation]]s of decoded instructions, as received directly from the [[instruction decoder]]s or from the instruction cache. When an instruction needs to be decoded, the μop cache is checked for its decoded form which is re-used if cached; if it is not available, the instruction is decoded and then cached.',
263 => '',
264 => 'One of the early works describing μop cache as an alternative frontend for the Intel [[P6 (microarchitecture)|P6 processor family]] is the 2001 paper ''"Micro-Operation Cache: A Power Aware Frontend for Variable Instruction Length ISA"''.<ref name="uop-intel">{{cite book',
265 => ' | chapter-url = http://cecs.uci.edu/~papers/compendium94-03/papers/2001/islped01/pdffiles/p004.pdf',
266 => ' | chapter = Micro-Operation Cache: A Power Aware Frontend for Variable Instruction Length ISA',
267 => ' | author1 = Baruch Solomon | title = ISLPED'01: Proceedings of the 2001 International Symposium on Low Power Electronics and Design (IEEE Cat. No.01TH8581)',
268 => ' | pages = 4–9',
269 => ' | author2 = Avi Mendelson | author3 = Doron Orenstein | author4 = Yoav Almog | author5 = Ronny Ronen',
270 => ' | date = August 2001 | access-date = 2013-10-06',
271 => ' | publisher = [[Intel]] | doi = 10.1109/LPE.2001.945363',
272 => '| isbn = 978-1-58113-371-4',
273 => ' | s2cid = 195859085',
274 => ' }}</ref> Later, Intel included μop caches in its [[Sandy Bridge]] processors and in successive microarchitectures like [[Ivy Bridge (microarchitecture)|Ivy Bridge]] and [[Haswell (microarchitecture)|Haswell]].<ref name="agner.org">{{cite web',
275 => ' | url = http://www.agner.org/optimize/microarchitecture.pdf',
276 => ' | title = The microarchitecture of Intel, AMD and VIA CPUs: An optimization guide for assembly programmers and compiler makers',
277 => ' | date = 2014-02-19 | access-date = 2014-03-21',
278 => ' | author = Agner Fog |author-link=Agner Fog| website = agner.org',
279 => ' }}</ref>{{rp|121–123}}<ref name="anandtech-haswell">{{cite web',
280 => ' | url = http://www.anandtech.com/show/6355/intels-haswell-architecture/6',
281 => ' | title = Intel's Haswell Architecture Analyzed',
282 => ' | date = 2012-10-05 | access-date = 2013-10-20',
283 => ' | author = Anand Lal Shimpi | publisher = [[AnandTech]]',
284 => '}}</ref> AMD implemented a μop cache in their [[Zen (microarchitecture)|Zen microarchitecture]].<ref>{{cite web',
285 => ' | url = http://www.anandtech.com/show/10578/amd-zen-microarchitecture-dual-schedulers-micro-op-cache-memory-hierarchy-revealed',
286 => ' | title = AMD Zen Microarchitecture: Dual Schedulers, Micro-Op Cache and Memory Hierarchy Revealed',
287 => ' | date = 2016-08-18 | access-date = 2017-04-03',
288 => ' | author = Ian Cutress | publisher = AnandTech}}</ref>',
289 => '',
290 => 'Fetching complete pre-decoded instructions eliminates the need to repeatedly decode variable length complex instructions into simpler fixed-length micro-operations, and simplifies the process of predicting, fetching, rotating and aligning fetched instructions. A μop cache effectively offloads the fetch and decode hardware, thus decreasing [[power consumption]] and improving the frontend supply of decoded micro-operations. The μop cache also increases performance by more consistently delivering decoded micro-operations to the backend and eliminating various bottlenecks in the CPU's fetch and decode logic.<ref name="uop-intel" /><ref name="anandtech-haswell" />',
291 => '',
292 => 'A μop cache has many similarities with a trace cache, although a μop cache is much simpler thus providing better power efficiency; this makes it better suited for implementations on battery-powered devices. The main disadvantage of the trace cache, leading to its power inefficiency, is the hardware complexity required for its [[heuristic]] deciding on caching and reusing dynamically created instruction traces.<ref name="tc-slides">{{cite web|url=https://www.cs.cmu.edu/afs/cs/academic/class/15740-f03/www/lectures/TraceCache_slides.pdf|title=Trace Cache|date=October 2003|access-date=2013-10-06|author1=Leon Gu|author2=Dipti Motiani}}</ref>',
293 => '',
294 => '====Branch target instruction cache====',
295 => 'A '''branch target cache''' or '''branch target instruction cache''', the name used on [[ARM microprocessors]],<ref>{{cite web |title=How does the BTIC (branch target instruction cache) work? |url=https://community.arm.com/processors/f/discussions/5320/how-does-the-btic-branch-target-instruction-cache-works |date=28 May 2015 |author=Kun Niu |access-date=7 April 2018}}</ref> is a specialized cache which holds the first few instructions at the destination of a taken branch. This is used by low-powered processors which do not need a normal instruction cache because the memory system is capable of delivering instructions fast enough to satisfy the CPU without one. However, this only applies to consecutive instructions in sequence; it still takes several cycles of latency to restart instruction fetch at a new address, causing a few cycles of pipeline bubble after a control transfer. A branch target cache provides instructions for those few cycles avoiding a delay after most taken branches.',
296 => '',
297 => 'This allows full-speed operation with a much smaller cache than a traditional full-time instruction cache.',
298 => '',
299 => '====Smart cache====',
300 => ''''Smart cache''' is a [[#MULTILEVEL|level 2]] or [[#MULTILEVEL|level 3]] caching method for multiple execution cores, developed by [[Intel]].',
301 => '',
302 => 'Smart Cache shares the actual cache memory between the cores of a [[multi-core processor]]. In comparison to a dedicated per-core cache, the overall [[cache miss]] rate decreases when cores do not require equal parts of the cache space. Consequently, a single core can use the full level 2 or level 3 cache while the other cores are inactive.<ref>{{cite web|url=http://www.intel.com/content/www/us/en/architecture-and-technology/intel-smart-cache.html|title=Intel Smart Cache: Demo|publisher=[[Intel]]|access-date=2012-01-26}}</ref> Furthermore, the shared cache makes it faster to share memory among different execution cores.<ref>{{cite web |url=http://software.intel.com/file/18374/ |archive-url=https://web.archive.org/web/20111229193036/http://software.intel.com/file/18374/ |title=Inside Intel Core Microarchitecture and Smart Memory Access |format=PDF |page=5 |publisher=[[Intel]] |year=2006 |access-date=2012-01-26 |archive-date=2011-12-29}}</ref>',
303 => '',
304 => '==={{Anchor|MULTILEVEL}}Multi-level caches===',
305 => '{{See also|Cache hierarchy}}',
306 => 'Another issue is the fundamental tradeoff between cache latency and hit rate. Larger caches have better hit rates but longer latency. To address this tradeoff, many computers use multiple levels of cache, with small fast caches backed up by larger, slower caches. Multi-level caches generally operate by checking the fastest cache, ''level 1'' ('''L1'''), first; if it hits, the processor proceeds at high speed. If that smaller cache misses, the next fastest cache, ''level 2'' ('''L2'''), is checked, and so on, before accessing external memory.',
307 => '',
308 => 'As the latency difference between main memory and the fastest cache has become larger, some processors have begun to utilize as many as three levels of on-chip cache. Price-sensitive designs used this to pull the entire cache hierarchy on-chip, but by the 2010s some of the highest-performance designs returned to having large off-chip caches, which is often implemented in [[eDRAM]] and mounted on a [[multi-chip module]], as a fourth cache level. In rare cases, such as in the mainframe CPU [[IBM z15 (microprocessor)|IBM z15]] (2019), all levels down to L1 are implemented by eDRAM, replacing [[static random-access memory|SRAM]] entirely (for cache, SRAM is still used for registers). The [[ARM architecture family|ARM-based]] [[Apple M1]] has a 192 KiB L1 cache for each of the four high-performance cores, an unusually large amount; however the four high-efficiency cores only have 128 KiB.',
309 => '',
310 => 'The benefits of L3 and L4 caches depend on the application's access patterns. Examples of products incorporating L3 and L4 caches include the following:',
311 => '',
312 => '* [[Alpha 21164]] (1995) has 1 to 64 MiB off-chip L3 cache.',
313 => '* [[AMD K6-III]] (1999) has motherboard-based L3 cache.',
314 => '* IBM [[POWER4]] (2001) has off-chip L3 caches of 32 MiB per processor, shared among several processors.',
315 => '* [[Itanium 2]] (2003) has a 6 MiB [[unified cache|unified]] level 3 (L3) cache on-die; the [[Itanium 2]] (2003) MX 2 module incorporates two Itanium 2 processors along with a shared 64 MiB L4 cache on a [[multi-chip module]] that was pin compatible with a Madison processor.',
316 => '* Intel's [[Xeon]] MP product codenamed "Tulsa" (2006) features 16 MiB of on-die L3 cache shared between two processor cores.',
317 => '* [[AMD Phenom]] (2007) with 2 MiB of L3 cache.',
318 => '* AMD [[Phenom II]] (2008) has up to 6 MiB on-die unified L3 cache.',
319 => '* [[List of Intel Core i7 processors|Intel Core i7]] (2008) has an 8 MiB on-die unified L3 cache that is inclusive, shared by all cores.',
320 => '* Intel [[Haswell (microarchitecture)|Haswell]] CPUs with integrated [[Intel Iris Pro Graphics]] have 128 MiB of eDRAM acting essentially as an L4 cache.<ref>{{cite web|url=http://www.anandtech.com/show/6993/intel-iris-pro-5200-graphics-review-core-i74950hq-tested/3 |title=Intel Iris Pro 5200 Graphics Review: Core i7-4950HQ Tested |publisher=AnandTech |access-date=2014-02-25}}</ref>',
321 => '',
322 => 'Finally, at the other end of the memory hierarchy, the CPU [[register file]] itself can be considered the smallest, fastest cache in the system, with the special characteristic that it is scheduled in software—typically by a compiler, as it allocates registers to hold values retrieved from main memory for, as an example, [[loop nest optimization]]. However, with [[register renaming]] most compiler register assignments are reallocated dynamically by hardware at runtime into a register bank, allowing the CPU to break false data dependencies and thus easing pipeline hazards.',
323 => '',
324 => 'Register files sometimes also have hierarchy: The [[Cray-1]] (circa 1976) had eight address "A" and eight scalar data "S" registers that were generally usable. There was also a set of 64 address "B" and 64 scalar data "T" registers that took longer to access, but were faster than main memory. The "B" and "T" registers were provided because the Cray-1 did not have a data cache. (The Cray-1 did, however, have an instruction cache.)',
325 => '',
326 => '===={{Anchor|LLC}}Multi-core chips====',
327 => 'When considering a chip with [[Multi-core processor|multiple cores]], there is a question of whether the caches should be shared or local to each core. Implementing shared cache inevitably introduces more wiring and complexity. But then, having one cache per ''chip'', rather than ''core'', greatly reduces the amount of space needed, and thus one can include a larger cache.',
328 => '',
329 => 'Typically, sharing the L1 cache is undesirable because the resulting increase in latency would make each core run considerably slower than a single-core chip. However, for the highest-level cache, the last one called before accessing memory, having a global cache is desirable for several reasons, such as allowing a single core to use the whole cache, reducing data redundancy by making it possible for different processes or threads to share cached data, and reducing the complexity of utilized cache coherency protocols.<ref>{{cite web',
330 => ' | url = https://software.intel.com/en-us/articles/software-techniques-for-shared-cache-multi-core-systems',
331 => ' | title = Software Techniques for Shared-Cache Multi-Core Systems',
332 => ' | date = 2012-03-08 | access-date = 2015-11-24',
333 => ' | author1 = Tian Tian | author2 = Chiu-Pi Shih',
334 => ' | publisher = [[Intel]]',
335 => '}}</ref> For example, an eight-core chip with three levels may include an L1 cache for each core, one intermediate L2 cache for each pair of cores, and one L3 cache shared between all cores.',
336 => '',
337 => 'Shared highest-level cache, which is called before accessing memory, is usually referred to as the ''last level cache'' (LLC). Additional techniques are used for increasing the level of parallelism when LLC is shared between multiple cores, including slicing it into multiple pieces which are addressing certain ranges of memory addresses, and can be accessed independently.<ref>{{cite web',
338 => ' | url = http://www.hotchips.org/wp-content/uploads/hc_archives/hc23/HC23.19.9-Desktop-CPUs/HC23.19.911-Sandy-Bridge-Lempel-Intel-Rev%207.pdf',
339 => ' | title = 2nd Generation Intel Core Processor Family: Intel Core i7, i5 and i3',
340 => ' | date = 2013-07-28',
341 => ' | access-date = 2014-01-21',
342 => ' | author = Oded Lempel',
343 => ' | website = hotchips.org',
344 => ' | page = 7–10,31–45',
345 => ' | archive-date = 2020-07-29',
346 => ' | archive-url = https://web.archive.org/web/20200729000210/http://www.hotchips.org/wp-content/uploads/hc_archives/hc23/HC23.19.9-Desktop-CPUs/HC23.19.911-Sandy-Bridge-Lempel-Intel-Rev%207.pdf',
347 => ' | url-status = dead',
348 => ' }}</ref>',
349 => '',
350 => '====Separate versus unified====',
351 => 'In a separate cache structure, instructions and data are cached separately, meaning that a cache line is used to cache either instructions or data, but not both; various benefits have been demonstrated with separate data and instruction [[translation lookaside buffer]]s.<ref>{{cite journal |author1=Chen, J. Bradley |author2=Borg, Anita |author3=Jouppi, Norman P. |title=A Simulation Based Study of TLB Performance |journal=SIGARCH Computer Architecture News |volume=20 |issue=2 |year=1992 |page=114–123 |doi=10.1145/146628.139708|doi-access=free }}</ref> In a unified structure, this constraint is not present, and cache lines can be used to cache both instructions and data.',
352 => '',
353 => '===={{Anchor|INCLUSIVE|EXCLUSIVE}}Exclusive versus inclusive====',
354 => 'Multi-level caches introduce new design decisions. For instance, in some processors, all data in the L1 cache must also be somewhere in the L2 cache. These caches are called ''strictly inclusive''. Other processors (like the [[AMD Athlon]]) have ''exclusive'' caches: data is guaranteed to be in at most one of the L1 and L2 caches, never in both. Still other processors (like the Intel [[Pentium II]], [[Pentium III|III]], and [[Pentium 4|4]]) do not require that data in the L1 cache also reside in the L2 cache, although it may often do so. There is no universally accepted name for this intermediate policy;<ref>{{cite web',
355 => ' | url = http://www.amecomputers.com/explanation-of-the-l1-and-l2-cache.html',
356 => ' | title = Explanation of the L1 and L2 Cache',
357 => ' | access-date = 2014-06-09',
358 => ' | website = amecomputers.com',
359 => ' | archive-date = 2014-07-14',
360 => ' | archive-url = https://web.archive.org/web/20140714181050/http://www.amecomputers.com/explanation-of-the-l1-and-l2-cache.html',
361 => ' | url-status = dead',
362 => ' }}</ref><ref name="ispass04">{{cite conference',
363 => ' | url = http://mercury.pr.erau.edu/~davisb22/papers/ispass04.pdf',
364 => ' | title = Performance Evaluation of Exclusive Cache Hierarchies',
365 => ' | date = 10–12 March 2004 | access-date = 2014-06-09',
366 => ' | author1 = Ying Zheng | author2 = Brian T. Davis | author3 = Matthew Jordan',
367 => ' | conference = IEEE International Symposium on Performance Analysis of Systems and Software',
368 => ' | location = Austin, TX, USA',
369 => ' | doi = 10.1109/ISPASS.2004.1291359',
370 => ' | isbn = 0-7803-8385-0',
371 => ' | pages = 89–96',
372 => ' | url-status = dead',
373 => ' | archive-url = https://web.archive.org/web/20120813003941/http://mercury.pr.erau.edu/~davisb22/papers/ispass04.pdf',
374 => ' | archive-date = 2012-08-13',
375 => ' }}</ref>',
376 => 'two common names are "non-exclusive" and "partially-inclusive".',
377 => '',
378 => 'The advantage of exclusive caches is that they store more data. This advantage is larger when the exclusive L1 cache is comparable to the L2 cache, and diminishes if the L2 cache is many times larger than the L1 cache. When the L1 misses and the L2 hits on an access, the hitting cache line in the L2 is exchanged with a line in the L1. This exchange is quite a bit more work than just copying a line from L2 to L1, which is what an inclusive cache does.<ref name="ispass04" />',
379 => '',
380 => 'One advantage of strictly inclusive caches is that when external devices or other processors in a multiprocessor system wish to remove a cache line from the processor, they need only have the processor check the L2 cache. In cache hierarchies which do not enforce inclusion, the L1 cache must be checked as well. As a drawback, there is a correlation between the associativities of L1 and L2 caches: if the L2 cache does not have at least as many ways as all L1 caches together, the effective associativity of the L1 caches is restricted. Another disadvantage of inclusive cache is that whenever there is an eviction in L2 cache, the (possibly) corresponding lines in L1 also have to get evicted in order to maintain inclusiveness. This is quite a bit of work, and would result in a higher L1 miss rate.<ref name="ispass04" />',
381 => '',
382 => 'Another advantage of inclusive caches is that the larger cache can use larger cache lines, which reduces the size of the secondary cache tags. (Exclusive caches require both caches to have the same size cache lines, so that cache lines can be swapped on a L1 miss, L2 hit.) If the secondary cache is an order of magnitude larger than the primary, and the cache data is an order of magnitude larger than the cache tags, this tag area saved can be comparable to the incremental area needed to store the L1 cache data in the L2.<ref>{{cite web',
383 => ' | url = http://www.jaleels.org/ajaleel/publications/micro2010-tla.pdf',
384 => ' | title = Achieving Non-Inclusive Cache Performance with Inclusive Caches',
385 => ' | date = 2010-09-27 | access-date = 2014-06-09',
386 => ' | author1 = Aamer Jaleel | author2 = Eric Borch | author3 = Malini Bhandaru',
387 => ' | author4 = Simon C. Steely Jr. | author5 = Joel Emer',
388 => ' | website = jaleels.org }}</ref>',
389 => '',
390 => '===Scratchpad memory===',
391 => '',
392 => '{{Main|Scratchpad memory}}',
393 => '[[Scratchpad memory]] (SPM), also known as scratchpad, scratchpad RAM or local store in computer terminology, is a high-speed internal memory used for temporary storage of calculations, data, and other work in progress.',
394 => '',
395 => '===Example: the K8===',
396 => 'To illustrate both specialization and multi-level caching, here is the cache hierarchy of the K8 core in the AMD [[Athlon 64]] CPU.<ref>{{cite web|url=http://www.sandpile.org/impl/k8.htm |title=AMD K8 |access-date=2007-06-02 |website=Sandpile.org |url-status=dead |archive-url=https://web.archive.org/web/20070515052223/http://www.sandpile.org/impl/k8.htm |archive-date=2007-05-15 }}</ref>',
397 => '',
398 => '[[File:Cache,hierarchy-example.svg|thumb|center|500px|Cache hierarchy of the K8 core in the AMD Athlon 64 CPU.]]',
399 => '',
400 => 'The K8 has four specialized caches: an instruction cache, an instruction [[translation lookaside buffer|TLB]], a data TLB, and a data cache. Each of these caches is specialized:',
401 => '',
402 => '* The instruction cache keeps copies of 64-byte lines of memory, and fetches 16 bytes each cycle. Each byte in this cache is stored in ten bits rather than eight, with the extra bits marking the boundaries of instructions (this is an example of predecoding). The cache has only [[parity bit|parity]] protection rather than [[Error-correcting code|ECC]], because parity is smaller and any damaged data can be replaced by fresh data fetched from memory (which always has an up-to-date copy of instructions).',
403 => '* The instruction TLB keeps copies of page table entries (PTEs). Each cycle's instruction fetch has its virtual address translated through this TLB into a physical address. Each entry is either four or eight bytes in memory. Because the K8 has a variable page size, each of the TLBs is split into two sections, one to keep PTEs that map 4 KiB pages, and one to keep PTEs that map 4 MiB or 2 MiB pages. The split allows the fully associative match circuitry in each section to be simpler. The operating system maps different sections of the virtual address space with different size PTEs.',
404 => '* The data TLB has two copies which keep identical entries. The two copies allow two data accesses per cycle to translate virtual addresses to physical addresses. Like the instruction TLB, this TLB is split into two kinds of entries.',
405 => '* The data cache keeps copies of 64-byte lines of memory. It is split into 8 banks (each storing 8 KiB of data), and can fetch two 8-byte data each cycle so long as those data are in different banks. There are two copies of the tags, because each 64-byte line is spread among all eight banks. Each tag copy handles one of the two accesses per cycle.',
406 => '',
407 => 'The K8 also has multiple-level caches. There are second-level instruction and data TLBs, which store only PTEs mapping 4 KiB. Both instruction and data caches, and the various TLBs, can fill from the large '''unified''' L2 cache. This cache is exclusive to both the L1 instruction and data caches, which means that any 8-byte line can only be in one of the L1 instruction cache, the L1 data cache, or the L2 cache. It is, however, possible for a line in the data cache to have a PTE which is also in one of the TLBs—the operating system is responsible for keeping the TLBs coherent by flushing portions of them when the page tables in memory are updated.',
408 => '',
409 => 'The K8 also caches information that is never stored in memory—prediction information. These caches are not shown in the above diagram. As is usual for this class of CPU, the K8 has fairly complex',
410 => '[[branch prediction]], with tables that help predict whether branches are taken and other tables which predict the targets of branches and jumps. Some of this information is associated with instructions, in both the level 1 instruction cache and the unified secondary cache.',
411 => '',
412 => 'The K8 uses an interesting trick to store prediction information with instructions in the secondary cache. Lines in the secondary cache are protected from accidental data corruption (e.g. by an [[alpha particle]] strike) by either [[Error-correcting code|ECC]] or [[parity (telecommunication)|parity]], depending on whether those lines were evicted from the data or instruction primary caches. Since the parity code takes fewer bits than the ECC code, lines from the instruction cache have a few spare bits. These bits are used to cache branch prediction information associated with those instructions. The net result is that the branch predictor has a larger effective history table, and so has better accuracy.',
413 => '',
414 => '===More hierarchies===',
415 => '<!-- (This section should be rewritten.) -->',
416 => 'Other processors have other kinds of predictors (e.g., the store-to-load bypass predictor in the [[Digital Equipment Corporation|DEC]] [[Alpha 21264]]), and various specialized predictors are likely to flourish in future processors.',
417 => '',
418 => 'These predictors are caches in that they store information that is costly to compute. Some of the terminology used when discussing predictors is the same as that for caches (one speaks of a '''hit''' in a branch predictor), but predictors are not generally thought of as part of the cache hierarchy.',
419 => '',
420 => 'The K8 keeps the instruction and data caches '''[[cache coherency|coherent]]''' in hardware, which means that a store into an instruction closely following the store instruction will change that following instruction. Other processors, like those in the Alpha and MIPS family, have relied on software to keep the instruction cache coherent. Stores are not guaranteed to show up in the instruction stream until a program calls an operating system facility to ensure coherency.',
421 => '',
422 => '===Tag RAM===',
423 => 'In computer engineering, a ''tag RAM'' is used to specify which of the possible memory locations is currently stored in a CPU cache.<ref>{{cite web',
424 => ' | url = http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0363g/Chdijaed.html',
425 => ' | title = Cortex-R4 and Cortex-R4F Technical Reference Manual',
426 => ' | access-date = 2013-09-28',
427 => ' | publisher = arm.com',
428 => '}}</ref><ref>{{cite web',
429 => ' | url = http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0284g/Ebddefci.html',
430 => ' | title = L210 Cache Controller Technical Reference Manual',
431 => ' | access-date = 2013-09-28',
432 => ' | publisher = arm.com',
433 => '}}</ref> For a simple, direct-mapped design fast [[static random-access memory|SRAM]] can be used. Higher [[#Associativity|associative caches]] usually employ [[content-addressable memory]].',
434 => '',
435 => '==Implementation==',
436 => '{{Main article|Cache algorithms}}',
437 => '',
438 => 'Cache '''reads''' are the most common CPU operation that takes more than a single cycle. Program execution time tends to be very sensitive to the latency of a level-1 data cache hit. A great deal of design effort, and often power and silicon area are expended making the caches as fast as possible.',
439 => '',
440 => 'The simplest cache is a virtually indexed direct-mapped cache. The virtual address is calculated with an adder, the relevant portion of the address extracted and used to index an SRAM, which returns the loaded data. The data is byte aligned in a byte shifter, and from there is bypassed to the next operation. There is no need for any tag checking in the inner loop{{snd}} in fact, the tags need not even be read. Later in the pipeline, but before the load instruction is retired, the tag for the loaded data must be read, and checked against the virtual address to make sure there was a cache hit. On a miss, the cache is updated with the requested cache line and the pipeline is restarted.',
441 => '',
442 => 'An associative cache is more complicated, because some form of tag must be read to determine which entry of the cache to select. An N-way set-associative level-1 cache usually reads all N possible tags and N data in parallel, and then chooses the data associated with the matching tag. Level-2 caches sometimes save power by reading the tags first, so that only one data element is read from the data SRAM.',
443 => '',
444 => '[[Image:Cache,associative-read.svg|thumb|right|upright=1.8|Read path for a 2-way associative cache]]',
445 => '',
446 => 'The adjacent diagram is intended to clarify the manner in which the various fields of the address are used. Address bit 31 is most significant, bit 0 is least significant. The diagram shows the SRAMs, indexing, and [[multiplexing]] for a 4 KiB, 2-way set-associative, virtually indexed and virtually tagged cache with 64 byte (B) lines, a 32-bit read width and 32-bit virtual address.',
447 => '',
448 => 'Because the cache is 4 KiB and has 64 B lines, there are just 64 lines in the cache, and we read two at a time from a Tag SRAM which has 32 rows, each with a pair of 21 bit tags. Although any function of virtual address bits 31 through 6 could be used to index the tag and data SRAMs, it is simplest to use the least significant bits.',
449 => '',
450 => 'Similarly, because the cache is 4 KiB and has a 4 B read path, and reads two ways for each access, the Data SRAM is 512 rows by 8 bytes wide.',
451 => '',
452 => 'A more modern cache might be 16 KiB, 4-way set-associative, virtually indexed, virtually hinted, and physically tagged, with 32 B lines, 32-bit read width and 36-bit physical addresses. The read path recurrence for such a cache looks very similar to the path above. Instead of tags, vhints are read, and matched against a subset of the virtual address. Later on in the pipeline, the virtual address is translated into a physical address by the TLB, and the physical tag is read (just one, as the vhint supplies which way of the cache to read). Finally the physical address is compared to the physical tag to determine if a hit has occurred.',
453 => '',
454 => 'Some SPARC designs have improved the speed of their L1 caches by a few gate delays by collapsing the virtual address adder into the SRAM decoders. See [[sum-addressed decoder]].',
455 => '',
456 => '===History===',
457 => 'The early history of cache technology is closely tied to the invention and use of virtual memory.{{Citation needed|date=March 2008}} <!-- this *is* a truly interesting observation, but are there any sources? Also why was the "CPU-mam speed" part deleted? ~~~~ --> Because of scarcity and cost of semi-conductor memories, early mainframe computers in the 1960s used a complex hierarchy of physical memory, mapped onto a flat virtual memory space used by programs. The memory technologies would span semi-conductor, magnetic core, drum and disc. Virtual memory seen and used by programs would be flat and caching would be used to fetch data and instructions into the fastest memory ahead of processor access. Extensive studies were done to optimize the cache sizes. Optimal values were found to depend greatly on the programming language used with Algol needing the smallest and Fortran and Cobol needing the largest cache sizes.{{Disputed inline|Talk:CPU cache#Dispute sequence of events for paging|reason=sequence of events wrong|date=December 2010}}',
458 => '',
459 => 'In the early days of microcomputer technology, memory access was only slightly slower than [[processor register|register]] access. But since the 1980s<ref>{{cite journal | url=https://epic.hpi.uni-potsdam.de/pub/Home/TrendsAndConceptsII2010/HW_Trends_The_Processor-Memory_bottleneck___Problems_and_Solutions..pdf | title=The processor-memory bottleneck: problems and solutions | journal=Crossroads | volume=5 | issue=3es | pages=2–es | first1=Nihar R. | last1=Mahapatra | first2=Balakrishna | last2=Venkatrao | access-date=2013-03-05 | doi=10.1145/357783.331677 | year=1999 | s2cid=11557476 | url-status=dead | archive-url=https://web.archive.org/web/20140305193233/https://epic.hpi.uni-potsdam.de/pub/Home/TrendsAndConceptsII2010/HW_Trends_The_Processor-Memory_bottleneck___Problems_and_Solutions..pdf | archive-date=2014-03-05 }}</ref> the performance gap between processor and memory has been growing. Microprocessors have advanced much faster than memory, especially in terms of their operating [[frequency]], so memory became a performance [[Von Neumann architecture#Von Neumann bottleneck|bottleneck]]. While it was technically possible to have all the main memory as fast as the CPU, a more economically viable path has been taken: use plenty of low-speed memory, but also introduce a small high-speed cache memory to alleviate the performance gap. This provided an order of magnitude more capacity—for the same price—with only a slightly reduced combined performance.',
460 => '',
461 => '====First TLB implementations====',
462 => 'The first documented uses of a TLB were on the [[GE 645]]<ref>{{cite book',
463 => ' | publisher = [[General Electric]]',
464 => ' | title = GE-645 System Manual',
465 => ' | date = January 1968',
466 => ' | url = http://bitsavers.org/pdf/ge/GE-645/LSB0468_GE-645_System_Manual_Jan1968.pdf',
467 => ' | access-date = 2020-07-10',
468 => ' }}</ref> and the [[IBM]] [[IBM System/360 Model 67|360/67]],<ref>{{cite book',
469 => ' |publisher = [[IBM]]',
470 => ' |title = IBM System/360 Model 67 Functional Characteristics',
471 => ' |id = GA27-2719-2',
472 => ' |url = http://www.bitsavers.org/pdf/ibm/360/functional_characteristics/GA27-2719-2_360-67_funcChar.pdf',
473 => ' |version = Third Edition',
474 => ' |date = February 1972',
475 => '}}</ref> both of which used an associative memory as a TLB.',
476 => '',
477 => '====First instruction cache====',
478 => 'The first documented use of an instruction cache was on the [[CDC 6600]].<ref>{{citation',
479 => ' | author = James E. Thornton',
480 => ' | contribution = Parallel operation in the control data 6600',
481 => ' | contribution-url = https://cs.uwaterloo.ca/~mashti/cs850-f18/papers/cdc6600.pdf',
482 => ' | title = Proc. of the October 27-29, 1964, fall joint computer conference, part II: very high speed computer systems',
483 => ' | date = October 1964}}</ref>',
484 => '',
485 => '====First data cache====',
486 => 'The first documented use of a data cache was on the [[IBM]] System/360 Model 85.<ref>{{cite book',
487 => ' | author = IBM',
488 => ' | title = IBM System/360 Model 85 Functional Characteristics',
489 => ' | id = A22-6916-1',
490 => ' | url = http://www.bitsavers.org/pdf/ibm/360/functional_characteristics/A22-6916-1_360-85_funcChar_Jun68.pdf',
491 => ' | version = SECOND EDITION',
492 => ' | date = June 1968}}</ref>',
493 => '',
494 => '====In 68k microprocessors====',
495 => 'The [[68010]], released in 1982, has a "loop mode" which can be considered a tiny and special-case instruction cache that accelerates loops that consist of only two instructions. The [[68020]], released in 1984, replaced that with a typical instruction cache of 256 bytes, being the first 68k series processor to feature true on-chip cache memory.',
496 => '',
497 => 'The [[68030]], released in 1987, is basically a 68020 core with an additional 256-byte data cache, an on-chip [[memory management unit]] (MMU), a process shrink, and added burst mode for the caches. The [[Motorola 68040|68040]], released in 1990, has split instruction and data caches of four kilobytes each. The [[68060]], released in 1994, has the following: 8 KiB data cache (four-way associative), 8 KiB instruction cache (four-way associative), 96-byte FIFO instruction buffer, 256-entry branch cache, and 64-entry address translation cache MMU buffer (four-way associative).',
498 => '',
499 => '====In x86 microprocessors====',
500 => '[[File:Motherboard Intel 386.jpg|thumb|Example of a motherboard with an [[i386]] microprocessor (33 MHz), 64 KiB cache (25 ns; 8 chips in the bottom left corner), 2 MiB DRAM (70 ns; 8 [[SIMM]]s to the right of the cache), and a cache controller ([[Austek Microsystems|Austek]] A38202; to the right of the processor)]]',
501 => 'As the [[x86]] microprocessors reached clock rates of 20 MHz and above in the [[Intel 80386|386]], small amounts of fast cache memory began to be featured in systems to improve performance. This was because the [[DRAM]] used for main memory had significant latency, up to 120 ns, as well as refresh cycles. The cache was constructed from more expensive, but significantly faster, [[static random-access memory|SRAM]] [[Memory cell (computing)|memory cells]], which at the time had latencies around 10–25 ns. The early caches were external to the processor and typically located on the motherboard in the form of eight or nine [[Dual in-line package|DIP]] devices placed in sockets to enable the cache as an optional extra or upgrade feature.',
502 => '',
503 => 'Some versions of the Intel 386 processor could support 16 to 256 KiB of external cache.',
504 => '',
505 => 'With the [[Intel 80486|486]] processor, an 8 KiB cache was integrated directly into the CPU die. This cache was termed Level 1 or L1 cache to differentiate it from the slower on-motherboard, or Level 2 (L2) cache. These on-motherboard caches were much larger, with the most common size being 256 KiB. The popularity of on-motherboard cache continued through the [[Intel P5|Pentium MMX]] era but was made obsolete by the introduction of [[SDRAM]] and the growing disparity between bus clock rates and CPU clock rates, which caused on-motherboard cache to be only slightly faster than main memory.',
506 => '',
507 => 'The next development in cache implementation in the x86 microprocessors began with the [[Pentium Pro]], which brought the secondary cache onto the same package as the microprocessor, clocked at the same frequency as the microprocessor.',
508 => '',
509 => 'On-motherboard caches enjoyed prolonged popularity thanks to the [[AMD K6-2]] and [[AMD K6-III]] processors that still used [[Socket 7]], which was previously used by Intel with on-motherboard caches. K6-III included 256 KiB on-die L2 cache and took advantage of the on-board cache as a third level cache, named L3 (motherboards with up to 2 MiB of on-board cache were produced). After the Socket 7 became obsolete, on-motherboard cache disappeared from the x86 systems.',
510 => '',
511 => 'The three-level caches were used again first with the introduction of multiple processor cores, where the L3 cache was added to the CPU die. It became common for the total cache sizes to be increasingly larger in newer processor generations, and recently (as of 2011) it is not uncommon to find Level 3 cache sizes of tens of megabytes.<ref>{{cite web',
512 => ' | url = http://ark.intel.com/products/family/59139/Intel-Xeon-Processor-E7-Family/server',
513 => ' | title = Intel® Xeon® Processor E7 Family',
514 => ' | access-date = 2013-10-10',
515 => ' | publisher = [[Intel]]',
516 => '}}</ref>',
517 => '',
518 => '[[Intel]] introduced a Level 4 on-package cache with the [[Haswell (microarchitecture)|Haswell]] [[microarchitecture]]. ''[[Crystalwell]]''<ref name="intel-ark-crystal-well" /> Haswell CPUs, equipped with the [[GT3e]] variant of Intel's integrated Iris Pro graphics, effectively feature 128 MiB of embedded DRAM ([[eDRAM]]) on the same package. This L4 cache is shared dynamically between the on-die GPU and CPU, and serves as a [[victim cache]] to the CPU's L3 cache.<ref name="anandtech-i74950hq" />',
519 => '',
520 => '====In ARM microprocessors====',
521 => '[[Apple M1]] CPU has 128 or 192 KiB instruction L1 cache for each core (important for latency/single-thread performance), depending on core type. This is an unusually large L1 cache for any CPU type (not just for a laptop); the total cache memory size is not unusually large (the total is more important for throughput) for a laptop, and much larger total (e.g. L3 or L4) sizes are available in IBM's mainframes.',
522 => '',
523 => '====Current research====',
524 => 'Early cache designs focused entirely on the direct cost of cache and [[random-access memory|RAM]] and average execution speed.',
525 => 'More recent cache designs also consider [[low-power electronics|energy efficiency]], fault tolerance, and other goals.<ref>{{cite journal',
526 => ' |url=https://spectrum.ieee.org/computing/hardware/chip-design-thwarts-sneak-attack-on-data',
527 => ' |title=Chip Design Thwarts Sneak Attack on Data',
528 => ' |author=Sally Adee',
529 => ' |year=2009',
530 => ' |journal= <!-- This is needed for ‘cite journal’ citation templates - should this be ‘cite news’ instead? (delete note when fixed) -->',
531 => '}}</ref><ref>{{cite conference|url=http://palms.princeton.edu/system/files/Micro08_Newcache.pdf|title=A novel cache architecture with enhanced performance and security|author1=Zhenghong Wang|author2=Ruby B. Lee|conference=41st annual IEEE/ACM International Symposium on Microarchitecture|pages=83–93|date=November 8–12, 2008|archive-url=https://web.archive.org/web/20120306225926/http://palms.princeton.edu/system/files/Micro08_Newcache.pdf|archive-date=March 6, 2012',
532 => ' | url-status=live',
533 => '}}</ref>',
534 => '',
535 => 'There are several tools available to computer architects to help explore tradeoffs between the cache cycle time, energy, and area; the CACTI cache simulator<ref>{{cite web|url=https://www.hpl.hp.com/research/cacti/ |title=CACTI |website=HP Labs |access-date=2023-01-29}}</ref> and the SimpleScalar instruction set simulator are two open-source options.',
536 => '',
537 => '===Multi-ported cache===',
538 => 'A multi-ported cache is a cache which can serve more than one request at a time. When accessing a traditional cache we normally use a single memory address, whereas in a multi-ported cache we may request N addresses at a time{{snd}} where N is the number of ports that connected through the processor and the cache. The benefit of this is that a pipelined processor may access memory from different phases in its pipeline. Another benefit is that it allows the concept of super-scalar processors through different cache levels.',
539 => '',
540 => '==See also==',
541 => '{{Div col|colwidth=30em}}',
542 => '* [[Branch predictor]]',
543 => '* [[Cache (computing)]]',
544 => '* [[Cache algorithms]]',
545 => '* [[Cache coherence]]',
546 => '* [[Cache control instruction]]s',
547 => '* [[Cache hierarchy]]',
548 => '* [[Cache placement policies]]',
549 => '* [[Cache prefetching]]',
550 => '* [[Dinero (cache simulator)|Dinero]] (cache simulator by [[University of Wisconsin System]])',
551 => '* [[Instruction unit]]',
552 => '* [[Locality of reference]]',
553 => '* [[Memoization]]',
554 => '* [[Memory hierarchy]]',
555 => '* [[Micro-operation]]',
556 => '* [[No-write allocation]]',
557 => '* [[Scratchpad RAM]]',
558 => '* [[Sum-addressed decoder]]',
559 => '* [[Write buffer]]',
560 => '{{Div col end}}',
561 => '',
562 => '==Notes==',
563 => '{{Reflist|group=NB}}',
564 => '',
565 => '==References==',
566 => '{{Reflist|30em|refs=',
567 => '<ref name=AtlasSup>',
568 => '{{cite book',
569 => ' | last1 = Kilburn',
570 => ' | first1 = T.',
571 => ' | last2 = Payne',
572 => ' | first2 = R. B.',
573 => ' | last3 = Howarth',
574 => ' | first3 = D. J.',
575 => ' | title = Computers - Key to Total Systems Control',
576 => ' | series = Conferences Proceedings',
577 => ' | pages = 279–294',
578 => ' | chapter = The Atlas Supervisor',
579 => ' | chapter-url = http://www.chilton-computing.org.uk/acl/technology/atlas/p019.htm',
580 => ' | volume = 20 Proceedings of the Eastern Joint Computer Conference Washington, D.C.',
581 => ' |date=December 1961',
582 => ' | publisher = Macmillan}}',
583 => '</ref>',
584 => '',
585 => '<ref name=AtlasCPU>',
586 => '{{cite book',
587 => ' | last1 = Sumner',
588 => ' | first1 = F. H.',
589 => ' | last2 = Haley',
590 => ' | first2 = G.',
591 => ' | last3 = Chenh',
592 => ' | first3 = E. C. Y.',
593 => ' | title = Information Processing 1962',
594 => ' | series = IFIP Congress Proceedings',
595 => ' | chapter = The Central Control Unit of the 'Atlas' Computer',
596 => ' | volume = Proceedings of IFIP Congress 62',
597 => ' | year = 1962',
598 => ' | publisher = Spartan}}',
599 => '</ref>',
600 => '}}',
601 => '',
602 => '==External links==',
603 => '{{wikibooks',
604 => ' |1= Microprocessor Design',
605 => ' |2= Cache',
606 => '}}',
607 => '* [https://lwn.net/Articles/252125/ Memory part 2: CPU caches]{{snd}} an article on lwn.net by Ulrich Drepper describing CPU caches in detail',
608 => '* [https://minds.wisconsin.edu/bitstream/handle/1793/59076/TR823.pdf Evaluating Associativity in CPU Caches] – Hill and Smith (1989) – introduces capacity, conflict, and compulsory classification',
609 => '* [http://www.cs.wisc.edu/multifacet/misc/spec2000cache-data/ Cache Performance for SPEC CPU2000 Benchmarks] – Hill and Cantin (2003) – This reference paper has been updated several times. It has thorough and lucidly presented simulation results for a reasonably wide set of benchmarks and cache organizations.',
610 => '* [http://www.sun.com/blueprints/1102/817-0742.pdf Memory Hierarchy in Cache-Based Systems] {{Webarchive|url=https://web.archive.org/web/20090915041601/http://www.sun.com/blueprints/1102/817-0742.pdf |date=2009-09-15 }} – by Ruud van der Pas, 2002, Sun Microsystems – a nice introductory article to CPU memory caching',
611 => '* [http://www.freescale.com/files/32bit/doc/app_note/AN2663.pdf A Cache Primer] – by Paul Genua, P.E., 2004, Freescale Semiconductor, another introductory article',
612 => '* [https://web.archive.org/web/20110718154522/http://www.zipcores.com/skin1/zipdocs/datasheets/cache_8way_set.pdf An 8-way set-associative cache]{{snd}} written in [[VHDL]]',
613 => '* [https://arstechnica.com/old/content/2002/07/caching.ars Understanding CPU caching and performance]{{snd}} an article on Ars Technica by Jon Stokes',
614 => '* [http://ixbtlabs.com/articles/ibmpower4/ IBM POWER4 processor review]{{snd}} an article on ixbtlabs by Pavel Danilov',
615 => '*[https://www.kivabe.in/2020/07/Cache-memory-ki.html/ What is Cache Memory and its Types!]',
616 => '* [https://www.cs.princeton.edu/courses/archive/fall15/cos375/lectures/16-Cache-2x2.pdf Memory Caching]{{snd}} a Princeton University lecture',
617 => '',
618 => '{{CPU technologies|state=collapsed}}',
619 => '',
620 => '{{DEFAULTSORT:Cpu Cache}}',
621 => '[[Category:Central processing unit]]',
622 => '[[Category:Computer memory]]',
623 => '[[Category:Cache (computing)]]'
] |
All external links added in the edit (added_links ) | [] |
All external links removed in the edit (removed_links ) | [
0 => 'http://people.ee.duke.edu/~sorin/papers/iccd06_perc.pdf',
1 => 'http://www.ccs.neu.edu/course/com3200/parent/NOTES/cache-basics.html',
2 => 'http://www.cs.washington.edu/education/courses/cse378/02sp/sections/section9-1.html',
3 => 'http://ieeexplore.ieee.org/xpl/freeabs_all.jsp?arnumber=5234663',
4 => 'http://hotchips.org/wp-content/uploads/hc_archives/hc24/HC24-1-Microprocessor/HC24.28.117-HotChips_IvyBridge_Power_04.pdf#page=18',
5 => 'http://www.stanford.edu/class/ee282/08_handouts/L03-Cache.pdf',
6 => 'http://www.cs.wisc.edu/multifacet/misc/spec2000cache-data/',
7 => 'http://www.chilton-computing.org.uk/acl/technology/atlas/p019.htm',
8 => 'http://www.systems.ethz.ch/education/courses/fs09/aos/lectures/wk3-print.pdf',
9 => 'http://ark.intel.com/products/codename/51802/Crystal-Well',
10 => 'http://www.anandtech.com/show/6993/intel-iris-pro-5200-graphics-review-core-i74950hq-tested/3',
11 => 'http://www.anandtech.com/show/661/5',
12 => 'http://www.agner.org/optimize/microarchitecture.pdf',
13 => 'http://cecs.uci.edu/~papers/compendium94-03/papers/2001/islped01/pdffiles/p004.pdf',
14 => 'http://www.anandtech.com/show/6355/intels-haswell-architecture/6',
15 => 'https://software.intel.com/en-us/articles/software-techniques-for-shared-cache-multi-core-systems',
16 => 'http://www.hotchips.org/wp-content/uploads/hc_archives/hc23/HC23.19.9-Desktop-CPUs/HC23.19.911-Sandy-Bridge-Lempel-Intel-Rev%207.pdf',
17 => 'http://www.amecomputers.com/explanation-of-the-l1-and-l2-cache.html',
18 => 'http://mercury.pr.erau.edu/~davisb22/papers/ispass04.pdf',
19 => 'http://www.jaleels.org/ajaleel/publications/micro2010-tla.pdf',
20 => 'http://www.sandpile.org/impl/k8.htm',
21 => 'https://epic.hpi.uni-potsdam.de/pub/Home/TrendsAndConceptsII2010/HW_Trends_The_Processor-Memory_bottleneck___Problems_and_Solutions..pdf',
22 => 'http://ark.intel.com/products/family/59139/Intel-Xeon-Processor-E7-Family/server',
23 => 'http://palms.princeton.edu/system/files/Micro08_Newcache.pdf',
24 => 'http://www.sun.com/blueprints/1102/817-0742.pdf',
25 => 'http://www.freescale.com/files/32bit/doc/app_note/AN2663.pdf',
26 => 'http://ixbtlabs.com/articles/ibmpower4/',
27 => 'https://web.archive.org/web/20111007150424/http://www.systems.ethz.ch/education/past-courses/fs09/aos/lectures/wk3-print.pdf',
28 => 'https://lwn.net/Articles/252125/',
29 => 'https://web.archive.org/web/20120907012034/http://www.stanford.edu/class/ee282/08_handouts/L03-Cache.pdf',
30 => 'http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0363g/Chdijaed.html',
31 => 'http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0284g/Ebddefci.html',
32 => 'https://www.cs.princeton.edu/courses/archive/fall15/cos375/lectures/16-Cache-2x2.pdf',
33 => 'http://www.anandtech.com/show/9582/intel-skylake-mobile-desktop-launch-architecture-analysis/5',
34 => 'http://www.realworldtech.com/sandy-bridge/4/',
35 => 'http://www.realworldtech.com/bulldozer/9/',
36 => 'http://www.anandtech.com/show/10578/amd-zen-microarchitecture-dual-schedulers-micro-op-cache-memory-hierarchy-revealed',
37 => 'https://web.archive.org/web/20070515052223/http://www.sandpile.org/impl/k8.htm',
38 => 'https://arstechnica.com/old/content/2002/07/caching.ars',
39 => 'https://web.archive.org/web/20110718154522/http://www.zipcores.com/skin1/zipdocs/datasheets/cache_8way_set.pdf',
40 => 'https://community.arm.com/processors/f/discussions/5320/how-does-the-btic-branch-target-instruction-cache-works',
41 => 'https://doi.org/10.1109%2FISCA.1990.134547',
42 => 'http://www.intel.com/content/www/us/en/architecture-and-technology/intel-smart-cache.html',
43 => 'https://web.archive.org/web/20111229193036/http://software.intel.com/file/18374/',
44 => 'http://software.intel.com/file/18374/',
45 => 'https://web.archive.org/web/20120306225926/http://palms.princeton.edu/system/files/Micro08_Newcache.pdf',
46 => 'https://www.cs.cmu.edu/afs/cs/academic/class/15740-f03/www/lectures/TraceCache_slides.pdf',
47 => 'https://spectrum.ieee.org/computing/hardware/chip-design-thwarts-sneak-attack-on-data',
48 => 'https://cs.uwaterloo.ca/~mashti/cs850-f18/papers/cdc6600.pdf',
49 => 'http://bitsavers.org/pdf/ge/GE-645/LSB0468_GE-645_System_Manual_Jan1968.pdf',
50 => 'https://www.kivabe.in/2020/07/Cache-memory-ki.html/',
51 => 'http://home.eng.iastate.edu/~zzhang/courses/cpre585-f03/reading/smith-csur82-cache.pdf',
52 => 'https://newsroom.intel.com/news/product-fact-sheet-accelerating-5g-network-infrastructure-core-edge/',
53 => 'https://www.anandtech.com/show/15544/intel-launches-atom-p5900-a-10nm-atom-for-radio-access-networks',
54 => 'https://api.semanticscholar.org/CorpusID:6023466',
55 => 'https://api.semanticscholar.org/CorpusID:195859085',
56 => 'https://api.semanticscholar.org/CorpusID:11557476',
57 => 'https://books.google.com/books?id=v3-1hVwHnHwC&q=Hennessey+%22block+offset%22&pg=PA120',
58 => 'https://books.google.com/books?id=3b63x-0P3_UC&q=Hennessey+%22block+offset%22&pg=PA484',
59 => 'https://web.archive.org/web/20090915041601/http://www.sun.com/blueprints/1102/817-0742.pdf',
60 => 'https://minds.wisconsin.edu/bitstream/handle/1793/59076/TR823.pdf',
61 => 'http://www.bitsavers.org/pdf/ibm/360/functional_characteristics/GA27-2719-2_360-67_funcChar.pdf',
62 => 'http://www.bitsavers.org/pdf/ibm/360/functional_characteristics/A22-6916-1_360-85_funcChar_Jun68.pdf',
63 => 'https://web.archive.org/web/20200729002711/http://hotchips.org/wp-content/uploads/hc_archives/hc24/HC24-1-Microprocessor/HC24.28.117-HotChips_IvyBridge_Power_04.pdf#page=18',
64 => 'https://web.archive.org/web/20200729000210/http://www.hotchips.org/wp-content/uploads/hc_archives/hc23/HC23.19.9-Desktop-CPUs/HC23.19.911-Sandy-Bridge-Lempel-Intel-Rev%207.pdf',
65 => 'https://web.archive.org/web/20140714181050/http://www.amecomputers.com/explanation-of-the-l1-and-l2-cache.html',
66 => 'http://www.chilton-computing.org.uk/acl/technology/atlas50th/p005.htm',
67 => 'https://api.semanticscholar.org/CorpusID:15434231',
68 => 'http://www.linuxjournal.com/article/7105',
69 => 'https://patents.google.com/patent/US6425055B1/en',
70 => 'https://rpx-patents.s3.amazonaws.com/US/c530f-US5367653A/US5367653A.pdf',
71 => 'https://patents.justia.com/patent/20160350229',
72 => 'http://web.cse.ohio-state.edu/~zhang.574/OS-cache-software_intel_2010.pdf',
73 => 'http://www.hardwaresecrets.com/how-the-cache-memory-works/',
74 => 'https://www.redbooks.ibm.com/redbooks/pdfs/sg248250.pdf',
75 => 'https://www.irisa.fr/caps/PROJECTS/Architecture/',
76 => 'https://www.hpl.hp.com/research/cacti/',
77 => 'https://cseweb.ucsd.edu/classes/fa10/cse240a/pdf/08/CSE240A-MBT-L15-Cache.ppt.pdf',
78 => 'https://web.archive.org/web/20120813003941/http://mercury.pr.erau.edu/~davisb22/papers/ispass04.pdf',
79 => 'https://doi.org/10.1155%2F2021%2F5559552',
80 => 'https://www.worldcat.org/issn/1939-0122',
81 => 'https://doi.org/10.1145%2F356887.356892',
82 => 'https://doi.org/10.1145%2F173682.165152',
83 => 'https://doi.org/10.1109%2F40.621212',
84 => 'https://doi.org/10.1145%2F1465482.1465581',
85 => 'https://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.307.9125',
86 => 'https://doi.org/10.1145%2F2485922.2485968',
87 => 'https://doi.org/10.1109%2FHPCA.2008.4658653',
88 => 'https://doi.org/10.1109%2FLPE.2001.945363',
89 => 'https://doi.org/10.1145%2F146628.139708',
90 => 'https://doi.org/10.1109%2FISPASS.2004.1291359',
91 => 'https://doi.org/10.1145%2F357783.331677',
92 => 'https://books.google.com/books?id=q2w3JSFD7l4C&dq=displacement+tag+cache&pg=PA209',
93 => 'https://web.archive.org/web/20140305193233/https://epic.hpi.uni-potsdam.de/pub/Home/TrendsAndConceptsII2010/HW_Trends_The_Processor-Memory_bottleneck___Problems_and_Solutions..pdf',
94 => 'https://developer.arm.com/documentation/den0042/latest'
] |
All external links in the new text (all_links ) | [] |
Links in the page, before the edit (old_links ) | [
0 => 'http://people.ee.duke.edu/~sorin/papers/iccd06_perc.pdf',
1 => 'http://www.ccs.neu.edu/course/com3200/parent/NOTES/cache-basics.html',
2 => 'http://www.cs.washington.edu/education/courses/cse378/02sp/sections/section9-1.html',
3 => 'http://ieeexplore.ieee.org/xpl/freeabs_all.jsp?arnumber=5234663',
4 => 'http://hotchips.org/wp-content/uploads/hc_archives/hc24/HC24-1-Microprocessor/HC24.28.117-HotChips_IvyBridge_Power_04.pdf#page=18',
5 => 'http://www.stanford.edu/class/ee282/08_handouts/L03-Cache.pdf',
6 => 'http://www.cs.wisc.edu/multifacet/misc/spec2000cache-data/',
7 => 'http://www.chilton-computing.org.uk/acl/technology/atlas/p019.htm',
8 => 'http://www.systems.ethz.ch/education/courses/fs09/aos/lectures/wk3-print.pdf',
9 => 'http://ark.intel.com/products/codename/51802/Crystal-Well',
10 => 'http://www.anandtech.com/show/6993/intel-iris-pro-5200-graphics-review-core-i74950hq-tested/3',
11 => 'http://www.anandtech.com/show/661/5',
12 => 'http://www.agner.org/optimize/microarchitecture.pdf',
13 => 'http://cecs.uci.edu/~papers/compendium94-03/papers/2001/islped01/pdffiles/p004.pdf',
14 => 'http://www.anandtech.com/show/6355/intels-haswell-architecture/6',
15 => 'https://software.intel.com/en-us/articles/software-techniques-for-shared-cache-multi-core-systems',
16 => 'http://www.hotchips.org/wp-content/uploads/hc_archives/hc23/HC23.19.9-Desktop-CPUs/HC23.19.911-Sandy-Bridge-Lempel-Intel-Rev%207.pdf',
17 => 'http://www.amecomputers.com/explanation-of-the-l1-and-l2-cache.html',
18 => 'http://mercury.pr.erau.edu/~davisb22/papers/ispass04.pdf',
19 => 'http://www.jaleels.org/ajaleel/publications/micro2010-tla.pdf',
20 => 'http://www.sandpile.org/impl/k8.htm',
21 => 'https://epic.hpi.uni-potsdam.de/pub/Home/TrendsAndConceptsII2010/HW_Trends_The_Processor-Memory_bottleneck___Problems_and_Solutions..pdf',
22 => 'http://ark.intel.com/products/family/59139/Intel-Xeon-Processor-E7-Family/server',
23 => 'http://palms.princeton.edu/system/files/Micro08_Newcache.pdf',
24 => 'http://www.sun.com/blueprints/1102/817-0742.pdf',
25 => 'http://www.freescale.com/files/32bit/doc/app_note/AN2663.pdf',
26 => 'http://ixbtlabs.com/articles/ibmpower4/',
27 => 'https://web.archive.org/web/20111007150424/http://www.systems.ethz.ch/education/past-courses/fs09/aos/lectures/wk3-print.pdf',
28 => 'https://lwn.net/Articles/252125/',
29 => 'https://web.archive.org/web/20120907012034/http://www.stanford.edu/class/ee282/08_handouts/L03-Cache.pdf',
30 => 'http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0363g/Chdijaed.html',
31 => 'http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0284g/Ebddefci.html',
32 => 'https://www.cs.princeton.edu/courses/archive/fall15/cos375/lectures/16-Cache-2x2.pdf',
33 => 'http://www.anandtech.com/show/9582/intel-skylake-mobile-desktop-launch-architecture-analysis/5',
34 => 'http://www.realworldtech.com/sandy-bridge/4/',
35 => 'http://www.realworldtech.com/bulldozer/9/',
36 => 'http://www.anandtech.com/show/10578/amd-zen-microarchitecture-dual-schedulers-micro-op-cache-memory-hierarchy-revealed',
37 => 'https://web.archive.org/web/20070515052223/http://www.sandpile.org/impl/k8.htm',
38 => 'https://arstechnica.com/old/content/2002/07/caching.ars',
39 => 'https://web.archive.org/web/20110718154522/http://www.zipcores.com/skin1/zipdocs/datasheets/cache_8way_set.pdf',
40 => 'https://community.arm.com/processors/f/discussions/5320/how-does-the-btic-branch-target-instruction-cache-works',
41 => 'https://doi.org/10.1109%2FISCA.1990.134547',
42 => 'http://www.intel.com/content/www/us/en/architecture-and-technology/intel-smart-cache.html',
43 => 'https://web.archive.org/web/20111229193036/http://software.intel.com/file/18374/',
44 => 'http://software.intel.com/file/18374/',
45 => 'https://web.archive.org/web/20120306225926/http://palms.princeton.edu/system/files/Micro08_Newcache.pdf',
46 => 'https://www.cs.cmu.edu/afs/cs/academic/class/15740-f03/www/lectures/TraceCache_slides.pdf',
47 => 'https://spectrum.ieee.org/computing/hardware/chip-design-thwarts-sneak-attack-on-data',
48 => 'https://cs.uwaterloo.ca/~mashti/cs850-f18/papers/cdc6600.pdf',
49 => 'http://bitsavers.org/pdf/ge/GE-645/LSB0468_GE-645_System_Manual_Jan1968.pdf',
50 => 'https://www.kivabe.in/2020/07/Cache-memory-ki.html/',
51 => 'http://home.eng.iastate.edu/~zzhang/courses/cpre585-f03/reading/smith-csur82-cache.pdf',
52 => 'https://newsroom.intel.com/news/product-fact-sheet-accelerating-5g-network-infrastructure-core-edge/',
53 => 'https://www.anandtech.com/show/15544/intel-launches-atom-p5900-a-10nm-atom-for-radio-access-networks',
54 => 'https://api.semanticscholar.org/CorpusID:6023466',
55 => 'https://api.semanticscholar.org/CorpusID:195859085',
56 => 'https://api.semanticscholar.org/CorpusID:11557476',
57 => 'https://books.google.com/books?id=v3-1hVwHnHwC&q=Hennessey+%22block+offset%22&pg=PA120',
58 => 'https://books.google.com/books?id=3b63x-0P3_UC&q=Hennessey+%22block+offset%22&pg=PA484',
59 => 'https://web.archive.org/web/20090915041601/http://www.sun.com/blueprints/1102/817-0742.pdf',
60 => 'https://minds.wisconsin.edu/bitstream/handle/1793/59076/TR823.pdf',
61 => 'http://www.bitsavers.org/pdf/ibm/360/functional_characteristics/GA27-2719-2_360-67_funcChar.pdf',
62 => 'http://www.bitsavers.org/pdf/ibm/360/functional_characteristics/A22-6916-1_360-85_funcChar_Jun68.pdf',
63 => 'https://web.archive.org/web/20200729002711/http://hotchips.org/wp-content/uploads/hc_archives/hc24/HC24-1-Microprocessor/HC24.28.117-HotChips_IvyBridge_Power_04.pdf#page=18',
64 => 'https://web.archive.org/web/20200729000210/http://www.hotchips.org/wp-content/uploads/hc_archives/hc23/HC23.19.9-Desktop-CPUs/HC23.19.911-Sandy-Bridge-Lempel-Intel-Rev%207.pdf',
65 => 'https://web.archive.org/web/20140714181050/http://www.amecomputers.com/explanation-of-the-l1-and-l2-cache.html',
66 => 'http://www.chilton-computing.org.uk/acl/technology/atlas50th/p005.htm',
67 => 'https://api.semanticscholar.org/CorpusID:15434231',
68 => 'http://www.linuxjournal.com/article/7105',
69 => 'https://patents.google.com/patent/US6425055B1/en',
70 => 'https://rpx-patents.s3.amazonaws.com/US/c530f-US5367653A/US5367653A.pdf',
71 => 'https://patents.justia.com/patent/20160350229',
72 => 'http://web.cse.ohio-state.edu/~zhang.574/OS-cache-software_intel_2010.pdf',
73 => 'http://www.hardwaresecrets.com/how-the-cache-memory-works/',
74 => 'https://www.redbooks.ibm.com/redbooks/pdfs/sg248250.pdf',
75 => 'https://www.irisa.fr/caps/PROJECTS/Architecture/',
76 => 'https://www.hpl.hp.com/research/cacti/',
77 => 'https://cseweb.ucsd.edu/classes/fa10/cse240a/pdf/08/CSE240A-MBT-L15-Cache.ppt.pdf',
78 => 'https://web.archive.org/web/20120813003941/http://mercury.pr.erau.edu/~davisb22/papers/ispass04.pdf',
79 => 'https://doi.org/10.1155%2F2021%2F5559552',
80 => 'https://www.worldcat.org/issn/1939-0122',
81 => 'https://doi.org/10.1145%2F356887.356892',
82 => 'https://doi.org/10.1145%2F173682.165152',
83 => 'https://doi.org/10.1109%2F40.621212',
84 => 'https://doi.org/10.1145%2F1465482.1465581',
85 => 'https://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.307.9125',
86 => 'https://doi.org/10.1145%2F2485922.2485968',
87 => 'https://doi.org/10.1109%2FHPCA.2008.4658653',
88 => 'https://doi.org/10.1109%2FLPE.2001.945363',
89 => 'https://doi.org/10.1145%2F146628.139708',
90 => 'https://doi.org/10.1109%2FISPASS.2004.1291359',
91 => 'https://doi.org/10.1145%2F357783.331677',
92 => 'https://books.google.com/books?id=q2w3JSFD7l4C&dq=displacement+tag+cache&pg=PA209',
93 => 'https://web.archive.org/web/20140305193233/https://epic.hpi.uni-potsdam.de/pub/Home/TrendsAndConceptsII2010/HW_Trends_The_Processor-Memory_bottleneck___Problems_and_Solutions..pdf',
94 => 'https://developer.arm.com/documentation/den0042/latest'
] |
Parsed HTML source of the new revision (new_html ) | '<div class="mw-parser-output"><p>coputer go brrrrrrrrrrrrrrrr
</p></div>' |
Whether or not the change was made through a Tor exit node (tor_exit_node ) | false |
Unix timestamp of change (timestamp ) | '1694421287' |