What does the second-level cache mean? Why is it divided into one, two, and three-level caches?

We know that CPU performance is mainly determined by many factors such as CPU architecture, number of core threads, clock speed, cache, etc., and "cache" is a place that many netizens tend to overlook.
Do you know what CPU cache means? What is a two-pole cache? What are the primary, secondary and tertiary caches? This article is mainly about the introduction of secondary caches and the distinction between primary, secondary and tertiary caches.

Two-pole cache

The CPU cache (Cache Memory) is a temporary storage between the CPU and the memory. Its capacity is smaller than the memory but the exchange speed is faster. The data in the cache is a small part of the memory, but this small part is about to be accessed by the CPU in a short time. When the CPU calls a large amount of data, it can avoid the memory and call it directly from the cache, thereby speeding up the reading speed. . Initially, the cache was only level one, and the second level cache (L2 CACHE) appeared to coordinate the speed between the level one cache and the memory. The second-level cache is slower than the first-level cache and has a larger capacity. It is mainly used for temporary exchange of data between the first-level cache and the memory. In fact, Intel and AMD processors are different in the logical structure design of the first level cache, so the impact of the second level cache on the CPU performance is also different.

The working principle of the cache is that when the CPU wants to read a piece of data, it first looks it up in the cache, if it finds it, it reads it immediately and sends it to the CPU for processing; if it doesn’t find it, it reads it from the memory and sends it to it at a relatively slow speed. CPU processing, and at the same time transfer the data block where this data is located into the cache, so that the entire block of data can be read from the cache in the future, without having to call the memory.

It is this read mechanism that makes the CPU read cache hit rate very high (most CPUs can reach about 90%), which means that 90% of the data that the CPU will read next time are in the cache, only about 10% Need to read from memory. This greatly saves the time for the CPU to directly read the memory, and also makes the CPU basically no need to wait when reading data. In general, the order in which the CPU reads data is cached first and then memory. The earliest CPU cache is a whole, and the capacity is very low, Intel has classified the cache since the Pentium era. At that time, the cache integrated in the CPU core was not enough to meet the needs of the CPU, and the limitations on the manufacturing process could not greatly increase the capacity of the cache. Therefore, there is a cache integrated on the same circuit board or motherboard as the CPU. At this time, the cache integrated with the CPU core is called the first level cache, and the external one is called the second level cache. The first level cache is also divided into data cache (Data Cache, D-Cache) and instruction cache (InstrucTIon Cache, I-Cache). The two are respectively used to store data and execute instructions for these data, and both can be accessed by the CPU at the same time, reducing conflicts caused by contention for Cache, and improving processor performance.

What does the second level cache mean

The second-level cache is the buffer of the first-level cache: the manufacturing cost of the first-level cache is very high, so its capacity is limited. The role of the second-level cache is to store the data that the CPU needs for processing but the first-level cache cannot store. In the same way, the third-level cache and memory can be regarded as the buffers of the second-level cache. Their capacity increases, but the unit manufacturing cost decreases. It should be noted that neither the second-level cache, the third-level cache nor the memory can store the original instructions for processor operations. These instructions can only be stored in the first-level instruction cache of the CPU, while the remaining second-level cache and third-level cache And memory is only used to store data required by the CPU.

Why is it divided into one, two and three levels of cache

What does the second level cache mean? Why is it divided into one, two and three levels of cache?

Memory hierarchy

Generally speaking, the hit rate of each level of cache is about 80%, which means that 80% of the total data volume can be found in the first level cache, and only 20% of the total data volume needs to be from the second level cache. , Level 3 cache or read in memory, it can be seen that Level 1 cache is the most important part of the entire CPU cache architecture.

However, the current level 1 caches of CPUs are almost the same, with relatively small capacities, mostly 64K. Therefore, today’s CPUs rarely mention level 1 caches, mainly because everyone is the same. Although the most important, it is not worth mentioning.

The second-level cache is very important to the CPU, but many friends will find that many Intel CPUs nowadays do not mention the second-level cache much, and only mark the third-level cache. Many of AMD’s new CPUs are mostly marked with L3 cache, and only some models of L2 cache will be marked. For example, AMD Ryzen 5 2600X provides 3M L3 cache and 16M L3 cache, and R7 2700X also has only 16M three. Level cache. The Intel Core i3 8100 has only 6M L3 cache, and the high-end i7 8700K is only marked with 12MB.

What does the second level cache mean? Why is it divided into one, two and three levels of cache?

Therefore, in the current new CPUs, the importance of the second-level cache is waning, and the third-level cache has become the focus.

The cache architecture of modern CPUs is very complex, including hardware prefetching and data forwarding, in order to provide the best cache hit opportunities, and some CPUs even add L4 cache.

The distinction between one, two and three levels of cache

The difference between the first level cache and the second level cache:

The main difference is that their scope of action is different.

The first level cache is session level.

That is, the cache only works in the same session, and the cache does not exist when the session is closed.

The second level cache is the sessionFactory level.

The cache is valid for the sessions produced by the same sessionFactory. For the second-level cache, we usually use some other open source components. For example, Hibernate often uses ECache. This cache will be effective in the entire application server.

First of all, we must understand what the cache is. The cache is to cache some frequently used data in the memory or various storage media. When it is used again, it does not need to query in the database, reducing the interaction with the database and improving performance.

Then explain the role of the first and second level caches: the first level cache is Session level, that is to say, it will be activated in a transaction. For example, if you query the same object in a transaction at the same time, you will not query the database twice.

The second-level cache is at the sessionFactory level, and different transactions can be shared. Some permissions, when the user logs in for the first time, put the associated permissions in the second-level cache, so that there is no need to query the database every time permissions are needed Up.

Finally, explain why the design is designed like this: Under normal circumstances, the data we query is generally real-time. Using the second-level cache will definitely not work. Using the first-level cache will not only use the cache but will not affect the real-time.

The second level cache is used to store some relatively stable data, such as permissions, which can only take effect when the user modifies the permissions and logs in again

The first level cache and the second level cache and the third level cache in the cpu

What is the first level cache:

The first level cache is built into the CPU and runs at the same speed as the CPU, which can effectively improve the operating efficiency of the CPU. The larger the first level cache, the higher the operating efficiency of the CPU, but due to the limitation of the internal structure of the CPU, the capacity of the first level cache is very small.

The CPU cache (Cache Memory) is a temporary storage located between the CPU and the memory. Its capacity is much smaller than that of the memory but the exchange speed is much faster than that of the memory. The appearance of the cache is mainly to solve the contradiction between the CPU operation speed and the memory read and write speed, because the CPU operation speed is much faster than the memory read and write speed, which will make the CPU spend a long time waiting for the data to arrive or write the data into the memory . The data in the cache is a small part of the memory, but this small part is about to be accessed by the CPU in a short time. When the CPU calls a large amount of data, it can avoid the memory and call it directly from the cache, thereby speeding up the reading speed. . It can be seen that adding a cache to the CPU is an efficient solution, so that the entire internal memory (cache + memory) becomes a storage system with both the high speed of the cache and the large capacity of the memory. The cache has a great impact on the performance of the CPU, mainly due to the CPU's data exchange sequence and the bandwidth between the CPU and the cache.

classification

The first-level cache can be divided into the first-level data cache (Data Cache, D-Cache) and the first-level instruction cache (InstrucTIon Cache, I-Cache). The two are used to store data and decode the instructions that execute these data in real time, and both can be accessed by the CPU at the same time, reducing conflicts caused by contention for Cache, and improving processor performance. At present, the first level data cache and the first level instruction cache of most CPUs have the same capacity. For example, AMD’s Athlon XP has a 64KB level one data cache and a 64KB level one instruction cache. The first level cache is 64KB+64KB. Indicates that the representation method of the first level cache of the rest of the CPU is analogized.

What is the secondary cache:

The CPU cache (Cache Memory) is a temporary storage between the CPU and the memory. Its capacity is smaller than the memory but the exchange speed is faster. The data in the cache is a small part of the memory, but this small part is about to be accessed by the CPU in a short time. When the CPU calls a large amount of data, it can avoid the memory and call it directly from the cache, thereby speeding up the reading speed. . Initially, the cache was only level one, and the second level cache (L2 CACHE) appeared to coordinate the speed between the level one cache and the memory. The second-level cache is slower than the first-level cache and has a larger capacity. It is mainly used for temporary exchange of data between the first-level cache and the memory. In fact, Intel and AMD processors are different in the logical structure design of the first level cache, so the impact of the second level cache on the CPU performance is also different.

working principle

The working principle of the cache is that when the CPU wants to read a piece of data, it first looks it up in the cache, if it finds it, it reads it immediately and sends it to the CPU for processing; if it doesn’t find it, it reads it from the memory and sends it to it at a relatively slow speed. CPU processing, and at the same time transfer the data block where this data is located into the cache, so that the entire block of data can be read from the cache in the future, without having to call the memory.

What is the third-level cache:

The third-level cache is designed for the missed data after reading the second-level cache. In a CPU with a third-level cache, only about 5% of the data needs to be called from the memory, which further improves the efficiency of the CPU. The principle of operation is to use a faster storage device to keep a copy of the data read from the slow storage device and copy it. When it is necessary to read and write data from the slower storage, the cache can make the read The writing action is first completed on a fast device, so that the system will respond more quickly.

Note: Only the first-level cache is in the CPU. The reading of the first-level cache requires 2-4 clock cycles; the reading of the second-level cache requires about 10 clock cycles; and the third-level cache requires 30-40 clocks Cycle, but the capacity increases once.

Conclusion

The above is the introduction of the distinction between the two-pole cache and the first, second, and third-level cache. There are many more details about the second-level cache, so I won’t repeat it in this article. I hope this article will give you a deeper understanding of the two-level cache. Understanding.

Flex Power Supply

Flex Power Supply,Flex Power Supply 80Plus,700W Adapter Server Power Supply,Flex 700W Power Supply

Boluo Xurong Electronics Co., Ltd. , https://www.greenleaf-pc.com

Posted on