How the Cache works
The cache works based on the locality of program Access .
The analysis of the operation of a large number of typical programs shows that in a short time interval, the address generated by the program tends to be concentrated in a small area of the memory logical address space. The distribution of the instruction address is sequential, plus the loop program and subroutine segments are repeated multiple times. Therefore, access to these addresses naturally has a tendency to centralize distribution over time.
This concentration of data distribution tends to be less obvious than instructions , but the storage and access of arrays and the selection of work cells can make the memory addresses relatively concentrated. This is frequently accessed for local-scope memory addresses, and the lack of access to addresses outside of this range is known as the locality of program Access .
According to the local principle of the program, a high-speed memory can be set between the main memory and the CPU General register, and a part of the instruction or data near the executing instruction address is transferred from main memory to the memory . For the CPU to use over a period of time. This has a great effect on improving the running speed of the program. This high-speed, small-capacity memory between main memory and CPU is called the cache.
Based on this principle, the system constantly reads a less large set of subsequent instructions associated with the current instruction set from memory to the cache, and then transmits it to the CPU at high speed, thus achieving speed matching.
The cache is usually accessed first by the CPU when it requests data from the memory. Because the local principle does not guarantee that the requested data is completely in the cache, there is a hit rate. The chance that the CPU will reliably get data from the cache at any one time.
The higher the hit rate, the greater the reliability of the correct data acquisition. In general, the cache storage capacity is much smaller than the capacity of main memory, but not too small, too small to make the hit rate is too low, it is not necessary too large, too large will not only increase the cost, and when the capacity exceeds a certain value, the rate of increase will not be significantly increased with capacity.
As long as the cache space and main memory space within a certain extent to maintain a proper proportion of the mapping relationship, the cache hit rate is still quite high.
Generally, the cache and memory space ratio is 4:1000, that is, 128kB cache can map 32MB memory, 256kB cache can be mapped 64MB memory. In this case, the hit rate is above 90%. As for data that is not hit, the CPU has to be fetched directly from memory. get it and copy it into the Cache for the next visit .
(1) What is "Cache"?
The cache ( cache memory) is one of the most common words we hear.
(2) Why to design the cache
We know that the computer's memory is operating on the system bus clock frequency, which is usually the CPU FSB (for Thunderbird, Poison Dragon series of processors, because in the design of the use of DDR technology, the CPU is working FSB of the system bus frequency of twice times). However, the operating frequency of the CPU (clock) is the product of the FSB and multiplier factors. In this way, the memory frequency is much lower than the CPU operating frequency. The direct result of this is that the CPU often needs to "wait" for some time to access memory again after executing an instruction, greatly reducing CPU productivity. In such a case, the cache was born!
(3) What is the cache?
The cache is a special kind of memory that consists of the cache storage part and the cache control part. The Cache storage parts generally use the same type of semiconductor memory as the CPU, and access speed is several times or even more than 10 times faster than memory. The cache controller components include main memory address register, cache address register, main memory-cache address transform parts and replacement control parts. As to how they each work, what role, and so on, there is no need to do further research, know that the general cache is divided into L1 cache (which is divided into data cache, code cache), L2 cache on the line.
(4) How the Cache works
We know that the CPU running program is an instruction to execute a command, and the instruction address is often continuous, meaning that the CPU in the memory, in a short period of time tend to focus on a certain part, it may encounter some need to call the subroutine repeatedly. While the computer is working, these active subroutines are stored in a much faster cache than memory. When the CPU accesses memory, it first determines if the content to be accessed is in the cache, and if it is called "hit", the CPU calls the content directly from the cache, otherwise it is called "Miss" and the CPU has to go to the memory to invoke the required subroutine or instruction. The CPU can read content directly from the cache or directly into it. Because the cache has a fairly fast access rate , the CPU utilization is greatly increased and the performance of the whole system is improved.
(5) Application of the cache
As early as in the 486 era, the motherboard on the design of the cache slot, the user can configure their own cache;586-level CPU chips have been integrated with some cache, but also retained the cache slot for the user to expand, and after the Pentiumⅱ era, The cache is fully integrated into the CPU chip and there is no cache slot on the motherboard. Now the more popular CPU chips are generally integrated with at least 16KB of code cache and 16KB of data cache (as L1 cache), and at least 64KB of L2 cache.
Some friends may ask, since the role of the cache is so important, that is not the entire memory of the computer into the cache, that is not better? In fact, aside from the price factor, it is not necessary for its practicality alone, after all, the computer in the task, the use of very high frequency of subroutines or instructions are not many , so those who use less frequent content only need to be kept in the relatively low speed of memory!
In the practical application, the Cache, especially the L2cache, has a great influence on the performance of the system, especially on the floating-point computing ability. And we know that most of the smooth running of the game requires frequent floating-point arithmetic. Therefore, the performance of the CPU running game has a great relationship with the capacity and speed of L2cache .
Cache Chinese name is a buffer memory, is a French word, specifically what meaning I forgot, probably hidden meaning it?
It is a small capacity relative to memory, speed thief fast, with static memory implementation of the storage system, to solve the memory is not up to the CPU speed problem .
It works by using a small amount of information that the CPU may have recently used, possibly data, or instructions, from memory to cache, which allows the CPU to access the data at higher speeds, increasing productivity.
The key indicator for evaluating cache performance is the cache hit ratio. Because the cache's capacity is much smaller than memory, it can only hold part of the memory data. The CPU is the first to access the cache, and then access the main memory, if the data in the cache as a hit, in memory is not a hit, there is a proportional problem, this ratio is hit rate, the factors affecting the hit ratio of a few
1. CACHE capacity , bigger good
2. Cache size (cache line Size) is moderate for each exchange of information with the main memory
3. CACHE different organization mode, Multi-channel group is better
4. CACHE Multi-level organization can increase hit ratio
5. The word changer after the CACHE is fully loaded
To explain the problem of multi-level cache, simply say that the cache is a memory image, can improve the CPU speed, then add a cache to the previous cache image can be more efficient. Currently the CPU is usually level 2 cache, which is L1 and L2
The cache is what caching means.
Many devices in a computer have a cache
such as CPU, hard disk, optical drive, etc.
Let's say that the Cache uses the CPU to process data from L1cache if the L1 cache does not have the required data CPU to look for in the L2 cache! If there is no data required in the L2 cache, then the CPU will be called directly from memory! But the memory speed is much lower than the cache speed! If you allow the CPU to call data directly from memory, the processing speed will be extremely slow! It's no use even if the CPU is running faster! If we increase the cache in the CPU by one more then the CPU is more likely to find the desired data from the extra cache, which is what you mean by the hit rate!
Knowing what the hit rate is, we're not hard to find. If the CPU cache of the same kernel is larger, the CPU's performance will be better!
Cache and hit ratio