What about cache?

Source: Internet
Author: User

Cache is a type of high-speed buffer memory. Its main function is to increase the CPU data input rate and reconcile the huge difference between the CPU speed and the memory storage speed.

In other words, the CPU is too fast, the memory speed is relatively slow, and the cache speed is fast, but the cache price is relatively high. One way people think of is to use the small-capacity cache as a bridge between the CPU and the memory, that is, to save the data that the CPU needs to use in the next time period to the cache in advance, when the CPU needs it, it can quickly obtain data from the cache, which can improve the computer performance to a certain extent. But how can we know the data in the memory used by the CPU in the next time period? The Locality Principle can solve this problem.

The reason for using cache to improve system performance is the local principle.

The principle of locality is actually very commonly used in our lives. People we usually talk about are expressed in a general sense by clustering, group by group, and locality. That is to say, the people around you are both bad guys, and you can't go anywhere. If you are surrounded by good people, you will never go anywhere. The locality principle is reflected in the computer. If the CPU current time uses a piece of data in the memory, the data around this piece of data may be used by the CPU in the next time period. In this case, the cache comes in handy. store the data around the data used by the CPU in this time period into the cache to prepare for the CPU usage in the next time period, in this way, when the CPU needs data in the next time period, you can directly obtain the required data from the cache, which naturally improves the computer performance.

This also involves a problem. The data in the cache is the same as some data in the memory. How can I know the specific address of the data in the memory after the CPU obtains the data from the cache? As a result, people think of the ing method to map the data in the cache to the data in the memory in a specific way, so that the CPU can easily find the real location of the data in the cache in the memory.

There are currently three ing methods, which can be understood in a general sense. Cache is equivalent to a girl in a major, while memory is equivalent to all boys in a major. In college, there are usually fewer girls and more boys (here, for ease of understanding, the number of girls is set to the number of people in one dormitory, that is, the cache capacity; the number of boys is set to N dormitories, is the memory capacity ). The so-called ing can be understood as follows: a professional male and female fall in love with each other and tell you the girl's information to find the boy corresponding to the girl according to the specific ing method. The following describes the three ing methods one by one.

  • Direct image:

A primary block can only be mapped to an exact block in the cache.

In other words, a girl in a dormitory can only fall in love with a specific boys' dormitory. For example, a girl in 407 and a girl in 407 can talk with each other, and the bed must correspond to each other, the girls in the No. 1 shop correspond to the boys in the No. 1 shop, the girls in the No. 2 shop correspond to the boys in the No. 2 shop, and so on ...... (Abnormal ~~)

Features: the main storage block can only correspond to a fixed cache block, with direct mode and low utilization.

In layman's terms, it may be very easy to understand. This ing method is for dormitory-to-dormitory, and for eight people, for eight people. That is to say, not 407 of students in this major have no chance to find their lover (other non-407 students say they are not feeling well ), therefore, a majority of professional boys are wasted, and 407 of the cost is low. Therefore, the utilization rate of boys is very low. In addition, because the selection range of girls is small, it is difficult for girls to find their favorite prince charming, so the hit rate is very low.


  • Fully Connected image:

A primary block can be mapped to any block of the entire cache.

Features: The stored word block can correspond to any word block in the cache. It features high utilization, flexible mode, long tag space, and high usage costs.

In layman's terms, girls can fall in love with boys in their major fields without any dormitory restrictions. In this case, because the number of boys is large, we always need to compare them. Naturally, it takes a long time to find out, and the cost is of course high. However, this method can basically ensure that girls can find their favorite prince charming, that is to say, the utilization rate of boys is improved, basically good boys will come with their lover. (Oh, too ~)


  • Associated image:

It is a compromise solution for fully-connected and direct images. It neither completely maps word blocks between the primary storage and cache nor implements multiple-to-one correspondence between the primary storage and cache, instead, it achieves a limited random correspondence.

Features: compromise plan. All groups are connected, and direct images in the group are displayed. Focuses on the advantages of two methods. The cost is not very high. The most common cache image method.

In other words, it is similar to directly connecting to a dormitory. It is also a female dormitory that corresponds to a male dormitory. The difference is that no bed is required to correspond to a bed, as long as it is within a dormitory. That is to say, 407 of girls can fall in love with 407 of boys. (Abnormal ~~)




[Previous]
[Back To Directory]
[Next]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.