What is cached data and caching?

The computer, alas, does not instantly execute commands that it receives from people. A number of tricks are used to speed up this process, and caching is an honorable place among them. What it is? What is cached data? How does this process actually happen? What is cached data in a Samsung smartphone, for example, and do they differ in some ways from those on a computer? Let's get to the answers to these questions.

What is a cache?

This is the name of the intermediate buffer, which provides quick access to information, the probability of which is the highest. All data is contained in it. An important advantage is that you can extract all the necessary information from the cache much faster than from the original storage. But there is a significant drawback - the size. Cached data is used in browsers, hard drives, CPUs, web servers, WINS, and DNS. The basis of the structure are record sets. Each of them is associated with a specific element or block of data that acts as a copy of what is in main memory. Records have an identifier (tag), with the help of which the correspondence is determined. Let's look from a slightly different perspective: what is cached data on a Samsung phone or another manufacturer? Do they differ from those created in the computer? From the fundamental point of view - no, the difference is only in size.

Use process

When the client (they were listed above) requests data, the first thing the computer does is examine the cache. If it contains the necessary record, then it is used. In these cases, a hit occurs. Periodically, data from the cache is copied to the main memory. But if the desired record was not found, then the content is searched in the underlying storage. All taken information is transferred to the cache so that later it can be accessed more quickly. The percentage when requests are successful is called the level or hit rate.

Data update

When using, say, a web browser, it checks the local cache in order to find a copy of the page. Given the limited nature of this type of memory, a missed decision is made to discard some of the information in order to free up space. To decide what exactly will be replaced, use various extrusion algorithms. By the way, if we talk about what cached data is on Android, then for the most part they are used to work with pictures and application data.

Recording Policy

During the modification of the contents of the cache, the data in the main memory is also updated. The time delay that elapses between entering information depends on the recording policy. There are two main types:

  1. Instant recording. Each change is synchronously recorded in the main memory.
  2. Delayed or written back. Data is updated periodically or upon request from the client. To track whether a change has been made, a sign with two states is used: dirty or changed. In case of a miss, two calls can be made directed to the main memory: the first is used to write data that has been changed from the cache, and the second is to read the necessary element.

It may be that the information in the intermediate buffer becomes irrelevant. This happens when changing data in the main memory without making adjustments to the cache. For consistency of all editing processes, coherence protocols are used.

Modern challenges

With an increase in the frequency of processors and an increase in the performance of RAM, a new problematic place appeared - the limited interface of data transfer. What knowledgeable person can notice from this? Cache is very useful if the frequency in RAM is less than in the processor. Many of them have their own intermediate buffer to reduce access time to RAM, which is slower than registers. CPUs that support virtual addressing often place a small but very fast address translation buffer. But in other cases, the cache is not very useful, and sometimes it only creates problems (but this is usually on computers that have been modified by a layperson). By the way, speaking about what cached data is in the smartphone’s memory, it should be noted that due to the small size of the device, new miniature cache implementations have to be created. Now some phones can boast of parameters like advanced computers ten years ago - and what a difference in their size!

Data synchronization between different buffers

A cache is useful when alone, but how to maintain the effectiveness of a given technology if there are a lot of them? This problem is solved by the coherence of the buffer. There are three options for exchanging data:

  1. Inclusive. The cache can behave arbitrarily.
  2. Exclusive. Developed for each specific case.
  3. Nonexclusive. Widespread standard.

Caching levels

Their number is usually three or four. The higher the memory level, the larger and slower it is:

  1. L1 cache. The fastest cache level is the first. In fact, it is part of the processor, since it is located on one chip and belongs to functional blocks. Usually divided into two types: instruction cache and data. Most modern processors do not work without this level. This cache operates at the processor frequency, so every clock cycle can access it.
  2. L2 cache. Usually located with the previous one. It is a shared memory. To find out its value, it is necessary to divide the entire volume allocated for data caching by the number of cores that are in the processor.
  3. L3 cache. Slow but biggest dependent cache. Usually more than 24 MB. Used to synchronize data that comes from various second level caches.
  4. L4 cache. Use is justified only for high-performance multiprocessor mainframes and servers. It is implemented as a separate chip. If you ask a question about what data caching is in the Samsung smartphone and you are looking for this level in it, I can say that for 5 years you were definitely in a hurry.

Cache associativity

This is a fundamental characteristic. The associativity of cached data is necessary to display logical segmentation. It, in turn, is needed due to the fact that a sequential search of all available lines takes dozens of clock cycles and brings to naught all the advantages. Therefore, tight binding of RAM cells to cache data is used to reduce the search time. If we compare the intermediate buffers, which have the same volume but different associativity, then the one with whom it is large will work less quickly, but with significant specific efficiency.

Conclusion

As you can see, cached data under certain conditions allows your computer to act more quickly. But, alas, there are still quite a few aspects that can be worked on for a long time.

Source: https://habr.com/ru/post/C46031/


All Articles