The basis for using cache to improve system performance is the principle of locality of the program. When the CPU needs to read data, it first searches the cache to see if there is the required content. If so, it reads it directly from the cache. If most of the content that the CPU needs to access can be found in the cache (called an access hit), system performance can be greatly improved.
The operating environment of this tutorial: Windows 7 system, Dell G3 computer.
The basis for using cache to improve system performance is the principle of locality of the program. Based on the principle of locality, content with high access probability in the main memory is stored in the cache. When the CPU needs to read data, it first searches the cache to see if there is the required content. If so, it reads it directly from the cache; if not, it reads the data from the main memory and then sends it to the CPU and cache at the same time. . If most of the content that the CPU needs to access can be found in the cache (called an access hit), system performance can be greatly improved.
The average storage cycle of the system is closely related to the hit rate. Even a small increase in the hit rate can bring about a large improvement in performance.
After the CPU issues a memory access request, the memory address is first sent to the cache controller to determine whether the required data is already in the cache. If there is a hit, the cache is accessed directly. This process is called cache address mapping. Common mapping methods include direct mapping, associative mapping and group associative mapping.
After an access miss occurs in the cache memory, the corresponding data should be read into the CPU and cache at the same time. But after the cache is full of data, new data must eliminate some old data in the cache. The most commonly used elimination algorithms are random elimination, first-in-first-out (FIFO) and least recently used elimination (LRU).
Because it is necessary to ensure that the data cached in the cache is consistent with the content in the main memory, the write operation of the cache is more complicated than the read operation. The following methods are commonly used:
(1)Write through. When writing to the cache, the data is written back to main memory at the same time, sometimes called a write-through.
(2) Write back. After the CPU modifies a certain line in the cache, the corresponding data is not written immediately to the main memory unit. Instead, the data is written back to the main memory when the line is eliminated from the cache.
(3) Notation. Set a valid bit for each data in the cache. When the data enters the cache, the valid bit is set to 1; when the CPU wants to modify the data, it only needs to write it to the main memory and clear the valid bit to 0 at the same time. When you want to read data from the cache, you need to test its valid bit: if it is 1, fetch the number directly from the cache, otherwise fetch the number from the main memory.
For more related knowledge, please visit the FAQ column!
The above is the detailed content of What is the basis for using cache to improve system performance?. For more information, please follow other related articles on the PHP Chinese website!