Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Processor (Cont.) _ cache (cache)

2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

4. Processor (Cont.) _ cache (cache) 4.1 hardware processing speed

Due to economic factors, the semiconductor process used by the processor and memory is different, and the process difference leads to the speed difference between the processor and memory. The processor always has to wait for memory, and the processor speed is much faster than memory. So it is very necessary to add a cache between the two.

Generally, V processing > V processor internal register > V cache > V memory > Vflash

4.2 locality of program access

When the program is running, there is a characteristic that the storage space accessed by the processor is a very small range in a short period of time.

a. Time locality: a memory cell is likely to be accessed again in a short period of time

b. Spatial locality: adjacent cells of a memory cell may also be accessed in a short period of time

4.3 cache

Cache is a kind of small capacity high-speed memory, and its access speed is almost the same as that of the processor. Modern computers usually put it in the processor chip.

Set cache between processor and memory to copy instructions and data that are not accessed frequently in memory to cache. In most cases, the processor can get instructions and data directly from the cache.

4.4 Mapping between memory and cache

The easiest way to map between memory and cache is direct mapping. The feature is that any memory address can be mapped to a fixed location in cache.

Direct mapping method

 divides cache and memory into fixed-size blocks (such as 512Byte/ blocks)

Each block in  memory has a fixed mapping location in cache.

The  mapping formula is: pos_cache = memory block number% cache total number of blocks, as shown below:

Address division:! [] (https://s1.51cto.com/images/blog/201803/09/1037cd3857ebfbac7c4c45dc02e2a74c.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=) mapping principle:

Find the corresponding block in the cache according to the c bit in the access address, and compare whether the t bit in the address and the flag corresponding to the block number are the same.

If the  is the same, the data is read directly according to the intra-block address as the offset.

 is different, indicating that the memory data to be accessed is not in the cache, then the block contents are copied from memory to the cache.

Example of direct mapping method:

The characteristics of direct mapping method:

Advantages: the mapping process is simple and takes a short time

Disadvantages: when the address accessed for a short time has congruence conflicts (two pieces of memory correspond to the same cache), the cache will be invalidated.

4.5 Cache principle software application:

Background: the log system has a great impact on the efficiency of the system, and it is not easy to analyze, so it is unable to print binary data efficiently, so it needs to define the parsing format of the log, and it can classify the log and control its output.

The original plan: develop a log parsing software, cooperate with the script to achieve log parsing, each log has its own corresponding parsing program. When there is a log, find the corresponding parser through the log type.

Problem: when there are a large number of logs to be printed in a short period of time, the performance can not meet the requirements. The bottleneck in performance is that each frequent search takes too much time.

Solution: according to the principle of cache, set the second-level cache to avoid lookup 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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report