In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
Today we are going to look at the cache. In our everyday lives, we know that processors and memory are different. They use different semiconductor device processes, and the differences in processes lead to differences in the speed of processors and memories. Processor devices are much better than memory, so its capacity is bound to be small; while memory is slow, but it is very cheap, so the capacity is generally large. When processing data, the processor always needs to wait for memory, and the speed of the processor is much faster than that of memory.
When accessed by ordinary programs, it presents the concept of locality. In other words, the memory space accessed by the processor is a small range in a short time. Locality is divided into two categories: temporal locality and spatial locality. Temporal locality means that a memory location is likely to be accessed again in a short time, while spatial locality means that neighboring locations of a memory location are also accessed in a short time. We introduced an intermediate medium between the processor and memory, which is called cache memory, commonly known as cache. The following describes its characteristics: 1, cache is a small capacity of high-speed memory;2, cache access speed and processor speed almost the same magnitude;3, cache in modern computer systems built into the processor chip. Setting cache between processor and memory can greatly improve efficiency, copying frequently accessed instructions and data from memory to cache. In most cases, the processor can fetch instructions and data directly from cache.
Let's take a look at the specific flow of processor data access, as follows
So how does memory and cache map? It uses direct mapping. 1. Divide cache and memory into blocks of fixed size (such as 512 Byte/block);2. Each block in memory has a fixed mapping position in cache;3. Mapping formula: Pcache = memory block number % cache total blocks. The following diagram is an example of a direct mapping
It is characterized by any memory address can be mapped to a fixed location in the cache. Its address is divided as follows
The mapping principle is to find the corresponding block in the cache according to the middle c bit of the access address, and then compare whether the high t bit of the address is the same as the flag. If the same task reads the data directly, copy the block content from the memory. For example, the current processor needs to access memory address 0x02140 CH.
1. Address division:
0000 001
0010
0 0000 1100
2. Directly access the 0010th block in the cache according to 0010
3. Whether the flag matching 0010 block is equal to 0000 001, if equal, access the data at 1100 in 0010 block, if not equal, read the block data from memory and update cache.
The advantage of direct mapping method is that the mapping process is simple and time-consuming, but the disadvantage is that it will cause cache failure when there is congruence conflict between addresses accessed in a short time. Here's a look at software applications based on cache principles. The project background is to develop a log debugging tool (Log Dog). The problems to be solved are: 1. Log has a huge impact on system efficiency, and it is not easy to analyze and view;2. Existing log systems cannot print binary data efficiently;3. Customize the parsing method of log contents;4. Classify logs and control whether logs are output. Performance issues that have occurred are when there are a large number of logs to print in a short period of time, and the performance is not enough for debugging needs. The final solution is to set up a secondary cache mechanism according to cache principle to avoid searching as much as possible.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.