A cache replacement method, device, electronic device and readable storage medium

By setting the data structure in the last-level cache of the processor to record the usage and access history of data blocks, the problem of losing history after data blocks is replaced is solved, the decision-making performance of the cache replacement algorithm is improved, and the processor performance is improved .

CN118550853BActive Publication Date: 2024-11-08BEIJING INSTITUTE OF OPEN SOURCE CHIP
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411025855.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-29
Publication Date
2024-11-08
Estimated Expiration
2044-07-29

AI Technical Summary

Technical Problem

In the last-level cache of the processor, the access history will be lost after the data block is replaced, affecting the decision performance of the replacement algorithm.

Method used

By setting the first data structure to record the usage of the data block in the last level cache and the usage of the previous level cache, and recording the existence and access hit situations in the second data structure, the replacement priority of the data block is determined. So that even if the data block is replaced out of the last-level cache, historical information can still be used in the cache replacement algorithm.

Benefits of technology

Improves the decision performance of the cache replacement algorithm, ensuring that even if the data blocks are replaced from the last-level cache, historical information can still be provided to support optimized replacement decisions and improves processor performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118550853B_ABST
    Figure CN118550853B_ABST
Patent Text Reader

Abstract

The embodiment of the present invention provides a cache replacement method, device, electronic device and readable storage medium, the method comprising: setting a first data structure for each data block appearing in the final-level cache of the processor, recording the usage of the data block in the final-level cache and the usage in the previous-level cache of the final-level cache in the first data structure; setting a second data structure in the final-level cache for each first data structure, and recording the existence and access hit of the data block corresponding to the first data structure in the final-level cache in the second data structure; determining the replacement priority of the data block in the final-level cache according to the information recorded in the first data structure and the second data structure; determining the replacement block according to the replacement priority of each data block in the final-level cache. The embodiment of the present invention is conducive to improving the decision-making performance of the cache replacement algorithm.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a cache replacement method, device, electronic device and readable storage medium. Background Art

[0002] The traditional processor cache design adopts an inclusive structure. As the amount of data increases, the capacity problem of the inclusive structure greatly affects the performance of the processor. Therefore, the last-level cache of modern processors basically adopts an exclusive or non-inclusive structure. Under these two structures, when the upper cache requests a data block (Acquire) from the lower cache and hits it, the data block in the lower cache may be kicked out, and the access history of the data block will be lost. The replacement algorithm (such as LRU, etc.) needs to use the access history of the data block to predict the replacement block, which will cause the replacement algorithm such as LRU to lose reference information and affect the decision-making performance of the replacement algorithm. Summary of the invention

[0003] The embodiments of the present invention provide a cache replacement method, device, electronic device and readable storage medium, which can solve the problem in the related art that after a data block is replaced out of the last-level cache, the corresponding access history record will be lost, affecting the decision-making performance of the replacement algorithm.

[0004] In order to solve the above problem, an embodiment of the present invention discloses a cache replacement method, which includes:

[0005] A first data structure is set for each data block appearing in the last-level cache of the processor, and the usage of the data block in the last-level cache and the usage of the data block in the last-level cache are recorded in the first data structure; the first data structure moves with the data block in the cache system of the processor;

[0006] For each first data structure, a second data structure is set in the final-level cache, and the existence and access hit status of the data block corresponding to the first data structure in the final-level cache are recorded in the second data structure;

[0007] Determining a replacement priority of the data block in the last-level cache according to information recorded in the first data structure and the second data structure;

[0008] The replacement block is determined according to the replacement priority of each data block in the last-level cache.

[0009] Optionally, determining the replacement priority of the data block in the last-level cache according to the information recorded in the first data structure and the second data structure includes:

[0010] When the first data structure and the second data structure indicate that the data block is accessed by an upper level cache of the last level cache and the access is a hit, setting the replacement priority of the data block to the highest priority;

[0011] When the first data structure and the second data structure indicate that the data block is accessed by a previous level cache of the last level cache and the access misses, keeping the current replacement priority of the data block unchanged;

[0012] When the first data structure and the second data structure indicate that the data block is pre-fetched by an upper level cache of the last level cache and the pre-fetch hits, setting the replacement priority of the data block to the lowest priority;

[0013] When the first data structure and the second data structure indicate that the data block is released by an upper-level cache of the last-level cache, a replacement priority of the data block is determined according to a preset rule.

[0014] Optionally, the first data structure includes a first counter and a second counter; the first data structure is set for each data block appearing in the last-level cache of the processor, and the usage of the data block in the last-level cache and the usage of the data block in the previous-level cache of the last-level cache are recorded in the first data structure, including:

[0015] A first counter and a second counter are respectively set for each data block present in the last level cache of the processor;

[0016] The first counter is used to record the number of times the data block is used in the last-level cache; the second counter is used to record the number of times the data block is used in the previous-level cache of the last-level cache.

[0017] Optionally, the second data structure includes a third counter and a fourth counter; for each first data structure, setting a second data structure in the final-level cache, and recording in the second data structure the existence and access hit status of a data block corresponding to the first data structure in the final-level cache, including:

[0018] According to the value ranges of the first counter and the second counter, a third counter and a fourth counter are respectively set for each array;

[0019] Wherein, the array includes a value of the first counter and a value of the second counter; the third counter is used to record the number of times the data block appears in the last-level cache; and the fourth counter is used to record the number of times the data block hits in the last-level cache.

[0020] Optionally, determining the replacement priority of the data block in the last-level cache according to the information recorded in the first data structure and the second data structure includes:

[0021] According to the request type and hit status of the memory access request received by the last-level cache, a first counter and a second counter corresponding to the requested target data block are updated;

[0022] Determine a target array according to the count values ​​of a first counter and a second counter corresponding to the target data block;

[0023] According to the request type and hit status of the memory access request received by the last-level cache, a third counter and a fourth counter corresponding to the target array are updated;

[0024] A replacement priority of the target data block in the last-level cache is determined according to the first counter, the second counter, the third counter, and the fourth counter.

[0025] Optionally, updating a first counter and a second counter corresponding to a requested target data block according to a request type and a hit condition of a memory access request received by the last-level cache includes:

[0026] When the last-level cache receives a first access request for a target data block from the previous-level cache and the access is hit, the count value of the first counter corresponding to the target data block is increased by 1, and the count value of the second counter remains unchanged;

[0027] When the upper level cache of the last level cache receives a second access request for the target data block and the access is hit, the count value of the second counter corresponding to the target data block is increased by 1, and the count value of the first counter remains unchanged.

[0028] Optionally, the method further comprises:

[0029] When the first condition is met, keeping the current count values ​​of the first counter and the second counter unchanged;

[0030] The first condition includes at least one of the following:

[0031] The last level cache receives a pre-fetch request for the target data block, and the pre-fetch request hits;

[0032] The last level cache receives a first access request from the previous level cache for the target data block, and the access is a miss;

[0033] The last-level cache receives a release request for the target data block from the previous-level cache.

[0034] Optionally, the method further comprises:

[0035] When the last-level cache receives a pre-fetch request for the target data block and the pre-fetch request does not hit, the count values ​​of the first counter and the second counter are initialized.

[0036] Optionally, updating the third counter and the fourth counter corresponding to the target array according to the request type and the hit status of the memory access request received by the last-level cache includes:

[0037] When the second condition is met, the count value of the fourth counter corresponding to the target array is increased by 1, and the count value of the third counter corresponding to the target array remains unchanged;

[0038] The second condition includes at least one of the following:

[0039] The last level cache receives a first access request from the previous level cache for a target data block, and the access is a hit;

[0040] The last-level cache receives a pre-fetch request for the target data block, and the pre-fetch request is successful.

[0041] Optionally, the method further comprises:

[0042] When the third condition is met, the count value of the third counter corresponding to the target array is increased by 1, and the count value of the fourth counter corresponding to the target array remains unchanged;

[0043] The third condition includes at least one of the following:

[0044] The last level cache receives a pre-fetch request for the target data block, and the pre-fetch request does not hit;

[0045] The last-level cache receives a release request for the target data block from the previous-level cache.

[0046] Optionally, the method further comprises:

[0047] When the last-level cache receives a first access request from the previous-level cache for a target data block and the access fails, the count values ​​of the third counter and the fourth counter corresponding to the target array remain unchanged.

[0048] On the other hand, an embodiment of the present invention discloses a cache replacement device, the device comprising:

[0049] A first setting module is used to set a first data structure for each data block appearing in the last-level cache of the processor, and record the usage of the data block in the last-level cache and the usage of the data block in the last-level cache in the first data structure; the first data structure moves with the data block in the cache system of the processor;

[0050] a second setting module, configured to set a second data structure in the final-level cache for each first data structure, and record in the second data structure the existence and access hit status of a data block corresponding to the first data structure in the final-level cache;

[0051] A first determining module, configured to determine a replacement priority of the data block in the last-level cache according to information recorded in the first data structure and the second data structure;

[0052] The second determining module is used to determine the replacement block according to the replacement priority of each data block in the last-level cache.

[0053] On the other hand, an embodiment of the present invention further discloses an electronic device, which includes a processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface communicate with each other through the communication bus; the memory is used to store executable instructions, and the executable instructions enable the processor to execute the aforementioned cache replacement method.

[0054] The embodiment of the present invention further discloses a readable storage medium. When instructions in the readable storage medium are executed by a processor of an electronic device, the electronic device can execute the aforementioned cache replacement method.

[0055] The embodiments of the present invention include the following advantages:

[0056] The cache replacement algorithm provided by the embodiment of the present invention records the usage of data blocks in the final-level cache and the usage of the data blocks in the previous-level cache of the final-level cache through a first data structure; and records the existence and access hit status of the data blocks corresponding to the first data structure in the final-level cache through a second data structure. The first data structure moves with the data blocks in the cache system of the processor, and the second data structure is stored in the final-level cache. The first data structure and the second data structure in the embodiment of the present invention reflect the historical information of the data blocks in the cache system, and even if the first data structure is replaced out of the final-level cache with the data blocks, the second data structure will always be stored in the final-level cache, providing historical information for the cache replacement algorithm, which is beneficial to improving the decision-making performance of the cache replacement algorithm. BRIEF DESCRIPTION OF THE DRAWINGS

[0057] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments of the present invention will be briefly introduced below. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative labor.

[0058] Figure 1 is a flow chart of steps of an embodiment of a cache replacement method of the present invention;

[0059] Figure 2 is a structural block diagram of an embodiment of a cache replacement device of the present invention;

[0060] Figure 3 It is a structural block diagram of an electronic device provided by an example of the present invention. DETAILED DESCRIPTION

[0061] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0062] The terms "first", "second", etc. in the specification and claims of the present invention are used to distinguish similar objects, and are not used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable when appropriate, so that the embodiments of the present invention can be implemented in an order other than those illustrated or described here, and the objects distinguished by "first", "second", etc. are generally of one type, and the number of objects is not limited. For example, the first object can be one or more. In addition, the term "and / or" in the specification and claims is used to describe the association relationship of associated objects, indicating that three relationships can exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the objects associated before and after are in an "or" relationship. In the embodiments of the present invention, the term "multiple" refers to two or more, and other quantifiers are similar.

[0063] Method Embodiment

[0064] Reference Figure 1 , shows a flow chart of steps of a cache replacement method embodiment of the present invention, the method may specifically include the following steps:

[0065] Step 101: for each data block in the last-level cache of the processor, a first data structure is set, in which the usage of the data block in the last-level cache and the usage of the data block in the last-level cache are recorded; the first data structure moves with the data block in the cache system of the processor;

[0066] Step 102: for each first data structure, set a second data structure in the final-level cache, and record in the second data structure the existence and access hit status of the data block corresponding to the first data structure in the final-level cache;

[0067] Step 103: Determine the replacement priority of the data block in the last-level cache according to the information recorded in the first data structure and the second data structure;

[0068] Step 104: Determine a replacement block according to the replacement priority of each data block in the last-level cache.

[0069] The cache replacement method provided in the embodiment of the present invention can be applied to the cache of the processor. Cache is one of the important components of the computer processor. It is a memory with a storage speed between the register and the memory, and is usually composed of a static memory unit (SRAM). In a computer system, various storage components (including registers, caches, memories, hard disks, etc.) can be divided into different levels according to working speed and unit cost. The closer to the processor end, the faster the working speed of the storage component, the smaller the capacity, and the higher the cost per unit capacity; the closer to the memory end, the larger the capacity of the storage component, the slower the working speed, and the lower the cost per unit capacity. The running speed of the cache is usually slower than the processor but faster than the memory. Using the principle of locality of program execution, the data that may be accessed repeatedly recently is copied to the cache with a faster working speed. When the processor needs the data, the data can be submitted to the processor with a very small time delay, which can effectively reduce the time consumed by accessing the memory, thereby covering up the working speed gap between the processor and the memory to a certain extent and improving the processor performance.

[0070] Modern processors usually use a three-level cache architecture (L1, L2, L3), and the last level cache generally refers to L3.

[0071] The cache architecture of a processor generally includes: an Inclusive structure, a Non-inclusive structure, and an Exclusive structure. Among them, the Inclusive structure means that the lower-level cache includes all the contents of the upper-level cache, the Non-inclusive structure means that the lower-level cache includes part of the contents of the upper-level cache, and the Exclusive structure means that the lower-level cache does not include any contents of the upper-level cache at all. The embodiments of the present invention can be applied to caches using the Inclusive structure, the Non-inclusive structure, and the Exclusive structure, and the optimization effect in the caches using the Non-inclusive structure and the Exclusive structure is better.

[0072] In an embodiment of the present invention, a first data structure is set for each data block that appears in the last-level cache of the processor. The first data structure is used to record the usage of the data block in the last-level cache and the usage of the data block in the last-level cache of the last-level cache. The first data structure moves with the data block in the cache system of the processor.

[0073] Exemplarily, the first data structure may be an array, which includes two elements, which are respectively recorded as a first parameter and a second parameter, wherein the first parameter is used to record the usage of the data block in the last-level cache, and the second parameter is used to record the usage of the data block in the last-level cache. For example, the parameter value of the first parameter is incremented when the data block is accessed in L3 and the access is hit, and the parameter value of the second parameter is incremented when the data block is accessed in L2 and the access is hit.

[0074] Alternatively, the first data structure may be a queue, and specifically may include two queues: a first queue and a second queue, wherein the first queue is used to record the usage of the data block in the last-level cache, and the second queue is used to record the usage of the data block in the last-level cache. For example, the first queue and the second queue are both "first-in-first-out" queues, and when the data block is accessed in L3 and the access is hit, the address tag of the data block is written to the first queue, and when the data block is accessed in L2 and the access is hit, the address tag of the data block is written to the second queue, and so on.

[0075] It should be noted that the first data structure is bound to the data block and moves with the data block in the cache system of the processor. Exemplarily, a new field can be added to the data block as the first data structure.

[0076] For each first data structure, a second data structure is set in the final cache, and the second data structure records the existence and access hit status of the data block corresponding to the first data structure in the final cache. It can be understood that the information recorded in the second data structure is stored in the final cache and will not be moved with the data block in the cache system.

[0077] As an example, the second data structure may be a historical information record table, which records the existence and access hit of each data block corresponding to the first data structure in the final cache. For example, the second data structure is a record table, with the first data structure as a table item index, and each table item index corresponds to two table items: a first table item and a second table item, wherein the first table item is used to record the existence of the data block in the final cache, and the second table item is used to record the hit of the data block in the final cache. For example, when a data block corresponding to a first data structure appears in L3, including L2 pre-fetching the data block from L3 but the pre-fetching does not hit (at this time, L3 will read the data block from the memory and backfill), or L2 releases the data block to L3, at this time, the parameter value in the first table item corresponding to the first data structure is incremented, or the address tag of the data block is recorded in the first table item. When the data block corresponding to the first data structure is accessed and hit in L3, the parameter value in the second table item corresponding to the first data structure is incremented, or the address tag of the data block is recorded in the second table item, and so on.

[0078] Next, according to the information recorded in the first data structure and the second data structure, the replacement priority of the data block in the last-level cache can be determined.

[0079] The first data structure and the second data structure reflect the historical information of the data block in the cache system, and even if the first data structure is replaced out of the final cache along with the data block, the second data structure will always be stored in the final cache to provide historical information for the cache replacement algorithm.

[0080] It is understandable that when the last-level cache adopts different replacement strategies, the replacement priority of the data block will also be different. In the embodiment of the present invention, the last-level cache can adopt any replacement strategy to determine the replacement priority of the data block based on the replacement strategy and the historical information recorded in the first data structure and the second data structure.

[0081] Exemplarily, the last-level cache can adopt a random replacement strategy (Random), a first-in first-out replacement strategy (FIFO), a last-in first out replacement strategy (LIFO), a least recently used replacement strategy (Least Recently Used, LRU), a least recently frequently used replacement strategy (Least Frequently Used, LFU), an adaptive replacement strategy (Adaptive Replacement Cache, ARC), a bimodal re-reference interval prediction replacement strategy (Bimodal Re-Reference Interval Prediction, BRRIP), etc.

[0082] In a cache that uses an ideal LRU replacement strategy, each cache line maintains a timestamp counter that records the clock count when the cache line was last accessed. Each time an access fails, the data in the cache line with the smallest timestamp count in the same cache group will be replaced from the cache, and the cache line will be used to store the newly read data from the memory. At the same time, each access, including access to newly added data after an failure, will update the timestamp in the cache line of the corresponding data, thereby ensuring that each replaced data comes from the least recently used cache line, that is, the cache line with the smallest timestamp in the same group.

[0083] The FIFO strategy replaces data in the order in which it enters the cache. The earliest data to enter the cache will be replaced first, while the latest data to enter the cache will be retained.

[0084] The LFU strategy is to replace each data item based on how frequently it is accessed. Less frequently accessed data will be replaced first to make room for more frequently accessed data.

[0085] The random replacement strategy is a simple and direct method that randomly selects a data to replace. Due to the existence of randomness, this strategy cannot guarantee that the most useful data is stored in the cache.

[0086] When a data block in the last-level cache needs to be replaced, the replacement block to be replaced out of the last-level cache can be determined according to the replacement priorities of the data blocks.

[0087] The cache replacement method provided in the embodiment of the present invention records the usage of data blocks in the final-level cache and the usage of the data blocks in the previous-level cache of the final-level cache through a first data structure; and records the existence and access hit status of the data blocks corresponding to the first data structure in the final-level cache through a second data structure. The first data structure moves with the data blocks in the cache system of the processor, and the second data structure is stored in the final-level cache. The first data structure and the second data structure in the embodiment of the present invention reflect the historical information of the data blocks in the cache system, and even if the first data structure is replaced out of the final-level cache with the data blocks, the second data structure will always be stored in the final-level cache, providing historical information for the cache replacement algorithm, which is beneficial to improving the decision-making performance of the cache replacement algorithm.

[0088] In an optional embodiment of the present invention, the first data structure includes a first counter and a second counter; the first data structure is set for each data block appearing in the last-level cache of the processor, and the use of the data block in the last-level cache and the use of the data block in the previous-level cache of the last-level cache are recorded in the first data structure, including:

[0089] A first counter and a second counter are respectively set for each data block present in the last level cache of the processor.

[0090] The first counter is used to record the number of times the data block is used in the last-level cache; the second counter is used to record the number of times the data block is used in the previous-level cache of the last-level cache.

[0091] In the embodiment of the present invention, two counters may be set for each data block in the last level cache of the processor, which are recorded as a first counter TC and a second counter UC. The first counter TC is used to record the number of times the data block is used in the last level cache; the second counter UC is used to record the number of times the data block is used in the last level cache.

[0092] Exemplarily, when a data block is accessed in L3 and the access is successful, the counter of the first counter TC is incremented; when a data block is accessed in L2 and the access is successful, the counter of the second counter UC is incremented.

[0093] Optionally, the second data structure includes a third counter and a fourth counter; for each first data structure, a second data structure is set in the final-level cache, and the existence and access hit status of the data block corresponding to the first data structure in the final-level cache are recorded in the second data structure, including:

[0094] According to the value ranges of the first counter and the second counter, a third counter and a fourth counter are respectively set for each array.

[0095] Wherein, the array includes a value of the first counter and a value of the second counter; the third counter is used to record the number of times the data block appears in the last-level cache; and the fourth counter is used to record the number of times the data block hits in the last-level cache.

[0096] In the embodiment of the present invention, the possible values ​​of the first counter and the second counter are arranged and combined to obtain a TC-UC pair, that is, an array in the embodiment of the present invention. Two counters are set for each TC-UC pair, which are recorded as a third counter D and a fourth counter L. The third counter is used to record the number of occurrences of the data block in the last-level cache; the fourth counter is used to record the number of hits of the data block in the last-level cache.

[0097] Exemplarily, the first counter and the second counter are both 2-bit counters, so the first counter and the second counter each have 4 values ​​(0, 1, 2, 3), so 16 TC-UC pairs are generated, as shown in Table 1:

[0098]

[0099] Each TC-UC pair corresponds to a third counter D and a fourth counter L. D and L indicate the activity level of the data block of the TC-UC pair in L3. L3 can predict whether a data block will be used in the future based on the four counters TC, UC, D and L, and further determine the replacement priority of the data block in L3.

[0100] Optionally, determining the replacement priority of the data block in the last-level cache according to the information recorded in the first data structure and the second data structure includes:

[0101] Step S11, updating a first counter and a second counter corresponding to a requested target data block according to a request type and a hit condition of a memory access request received by the last-level cache;

[0102] Step S12, determining a target array according to the count values ​​of the first counter and the second counter corresponding to the target data block;

[0103] Step S13: updating a third counter and a fourth counter corresponding to the target array according to the request type and hit status of the memory access request received by the last-level cache;

[0104] Step S14: Determine the replacement priority of the target data block in the last-level cache according to the first counter, the second counter, the third counter and the fourth counter.

[0105] In an embodiment of the present invention, the first counter, the second counter, the third counter and the fourth counter can be updated according to the request type and hit status of the memory access request received by the last-level cache. Among them, the request type of the memory access request may include: access request (Acquire), pre-fetch request (Hint) and release request (Release). Acquire means that the upper-level cache asks the lower-level cache for a data block. Release means that the upper-level cache releases the data block it does not want to the lower-level cache for storage. Hint means that the upper-level cache sends a pre-fetch request to the lower-level cache, indicating that this data block may be used later.

[0106] Exemplarily, when L3 receives the Acquire request sent by L2 and the request is successful, the count value of the first counter TC is increased by 1; when L2 receives the Acquire request sent by L1 and the request is successful, the count value of the second counter UC is increased by 1.

[0107] In the embodiment of the present invention, each TC-UC pair corresponds to a third counter D and a fourth counter L. Exemplarily, a dedicated area may be allocated in L3 to store TC values ​​and UC values ​​of all data blocks, and another dedicated area may be allocated to store the count values ​​of the corresponding third counter D and fourth counter L for each TC-UC pair.

[0108] When L3 receives a memory access request for a data block, it first updates the TC and UC corresponding to the data block according to the request type and hit status, and then determines the third counter D and the fourth counter L corresponding to the target array based on the target array composed of the count values ​​after the TC-UC update, and updates D and L.

[0109] For example, when L3 receives an Acquire request from L2 and it hits, it first updates TC and UC, then searches for L corresponding to TC-UC and increases its count by 1. Alternatively, when L3 receives a Release request from L2, it does not update the counts of TC and UC. In this case, it needs to search for D corresponding to the current TC-UC and increase the count of D by 1 regardless of whether it hits or not.

[0110] Optionally, updating a first counter and a second counter corresponding to a requested target data block according to a request type and a hit condition of a memory access request received by the last-level cache includes:

[0111] Step S21: when the last-level cache receives a first access request for a target data block from a previous-level cache and the access is a hit, the count value of the first counter corresponding to the target data block is increased by 1, and the count value of the second counter remains unchanged;

[0112] Step S22: When the previous level cache of the last level cache receives a second access request for the target data block and the access is hit, the count value of the second counter corresponding to the target data block is increased by 1, and the count value of the first counter remains unchanged.

[0113] As an example, when L3 receives the Acquire request sent by L2 and hits, the count value of the first counter TC is increased by 1, and the count value of the second counter UC remains unchanged; when L2 receives the Acquire request sent by L1 and hits, the count value of the second counter UC is increased by 1, and the count value of the first counter TC remains unchanged.

[0114] Optionally, the method further comprises:

[0115] When the first condition is met, the current count values ​​of the first counter and the second counter are kept unchanged.

[0116] The first condition includes at least one of the following:

[0117] The last level cache receives a pre-fetch request for the target data block, and the pre-fetch request hits;

[0118] The last level cache receives a first access request from the previous level cache for the target data block, and the access is a miss;

[0119] The last-level cache receives a release request for the target data block from the previous-level cache.

[0120] If L3 receives a prefetch request Hint sent by L2 for the target data block and the prefetch hits, or, L3 receives a first access request Acquire sent by L2 for the target data block and the access hits, or, L3 receives a release request Release sent by L2 for the target data block, the current count values ​​of the first counter TC and the second counter UC corresponding to the target data block can be kept unchanged, that is, the count values ​​of TC and UC can be updated.

[0121] It can be understood that when L3 receives a release request from L2 for a target data block, the count values ​​of the first counter TC and the second counter UC corresponding to the target data block are carried by the data block and are released from L2 to L3 together with the target data block.

[0122] Optionally, the method further comprises:

[0123] When the last-level cache receives a pre-fetch request for the target data block and the pre-fetch request does not hit, the count values ​​of the first counter and the second counter are initialized.

[0124] If L3 receives a prefetch request Hint from L2 for a target data block and the prefetch fails, it means that the target data block is not contained in L3 at this time. L3 needs to read the target data block from the memory and backfill it. The target data block backfilled into L3 needs to be re-counted. Therefore, the count values ​​of the first counter TC and the second counter UC corresponding to the target data block can be initialized so that the counting can be restarted later.

[0125] Optionally, updating the third counter and the fourth counter corresponding to the target array according to the request type and the hit status of the memory access request received by the last-level cache includes:

[0126] When the second condition is met, the count value of the fourth counter corresponding to the target array is increased by 1, and the count value of the third counter corresponding to the target array remains unchanged.

[0127] The second condition includes at least one of the following:

[0128] The last level cache receives a first access request from the previous level cache for a target data block, and the access is a hit;

[0129] The last-level cache receives a pre-fetch request for the target data block, and the pre-fetch request is successful.

[0130] As an example, if L3 receives a first access request Acquire from L2 for a target data block and the access is successful, or L3 receives a prefetch request Hint from L2 for a target data block and the prefetch is successful, the count value of the first counter TC of the target data block is increased by 1, the count value of the second counter UC remains unchanged, and then the third counter D and the fourth counter L corresponding to the target array composed of the current count values ​​of TC-UC are found, the count value of the fourth counter L is increased by 1, and the count value of the third counter D remains unchanged.

[0131] Optionally, the method further comprises:

[0132] When the third condition is met, the count value of the third counter corresponding to the target array is increased by 1, and the count value of the fourth counter corresponding to the target array remains unchanged.

[0133] The third condition includes at least one of the following:

[0134] The last level cache receives a pre-fetch request for the target data block, and the pre-fetch request does not hit;

[0135] The last-level cache receives a release request for the target data block from the previous-level cache.

[0136] As an example, if L3 receives a prefetch request Hint from L2 for a target data block and the prefetch fails, or L3 receives a release request Release from L2 for a target data block (regardless of whether it hits or not), the count values ​​of the first counter TC and the second counter UC corresponding to the target data block may be updated first, and then the third counter D and the fourth counter L corresponding to the target array composed of the updated TC-UC may be searched, the count value of the third counter D may be increased by 1, and the count value of the fourth counter L may remain unchanged.

[0137] Optionally, the method further comprises:

[0138] When the last-level cache receives a first access request from the previous-level cache for a target data block and the access fails, the count values ​​of the third counter and the fourth counter corresponding to the target array remain unchanged.

[0139] Exemplarily, if L3 receives the first access request Acquire sent by L2 for the target data block and the access misses, the count values ​​of the first counter TC and the second counter UC corresponding to the target data block can be kept unchanged, and then the third counter D and the fourth counter L corresponding to the current target array composed of TC-UC are searched, and the count values ​​of the third counter D and the fourth counter L also remain unchanged.

[0140] Optionally, determining the replacement priority of the data block in the last-level cache according to the information recorded in the first data structure and the second data structure includes:

[0141] Step S31: when the first data structure and the second data structure indicate that the data block is accessed by the previous level cache of the last level cache and the access is a hit, setting the replacement priority of the data block to the highest priority;

[0142] Step S32: when the first data structure and the second data structure indicate that the data block is accessed by the previous level cache of the last level cache and the access misses, keep the current replacement priority of the data block unchanged;

[0143] Step S33: when the first data structure and the second data structure indicate that the data block is pre-fetched by the previous level cache of the last level cache and the pre-fetch hits, setting the replacement priority of the data block to the lowest priority;

[0144] Step S34: when the first data structure and the second data structure indicate that the data block is released by the previous level cache of the last level cache, determine the replacement priority of the data block according to a preset rule.

[0145] In an optional embodiment of the present invention, if the information recorded in the first data structure and the second data structure of a data block reflects that the data block is accessed (Acquire) by L2 in L3 and the access is hit, the replacement priority of the data block can be set to the highest priority.

[0146] It can be understood that the higher the replacement priority, the easier it is for the data block to be replaced out of L3.

[0147] If the information recorded in the first data structure and the second data structure of a data block reflects that the data block is accessed (Acquire) by L2 and the access does not hit, it means that the data block may continue to be accessed later. At this time, the current replacement priority of the data block can be kept unchanged.

[0148] If the information recorded in the first data structure and the second data structure of a data block reflects that the data block is prefetched (Hint) by L2 and the prefetch hits, it means that the data block may be used later. At this time, the replacement priority of the data block can be set to the lowest priority, so that when the data block replacement occurs in L3, the data block is least likely to be replaced out of L3.

[0149] If the information recorded in the first data structure and the second data structure of a data block reflects that the data block is released by L2, the replacement priority of the data block can be determined according to a preset rule, for example, according to a cache replacement policy adopted by the processor.

[0150] As an example, in a processor using a non-inclusive structure, requests to access the last-level cache L3 can be divided into six categories according to the request type and hit status:

[0151] (1) Acquire hit;

[0152] (2) Acquire miss;

[0153] (3) Hint hit;

[0154] (4) Prefetch miss (Hint miss);

[0155] (5) Release hit;

[0156] (6) Release miss.

[0157] In the embodiment of the present invention, the update rules of the four counters corresponding to the data blocks in L3 are shown in Table 2 below:

[0158]

[0159] Among them, req.TC and req.UC refer to the TC and UC carried when L2 releases the data block to L3.

[0160] L2 only includes a first counter TC and a second counter UC corresponding to the data block, and only the count value of UC is updated when an access hit occurs.

[0161] It should be noted that, for a data block that first appears in L2, the first counter and the second counter of the data block may be assigned initial values, for example, TC = 1 and UC = 1 corresponding to the data block. When the data block in L2 is released to L3, the TC value and UC value corresponding to the data block are also moved to L3.

[0162] Assuming that a 2-bit value is used to represent the replacement priority of each data block, there are four priorities: 0, 1, 2, and 3. The data block with a priority of 3 is most likely to be replaced, and the data block with a priority of 0 is least likely to be replaced.

[0163] In L3, the setting rule of the data block replacement priority insertion-age can be expressed as:

[0164] (1) If the selected way is an invalid way, age is set to 0;

[0165] (2) If the selected way is not an invalid way, age is set according to Table 3 below:

[0166]

[0167] Wherein, formula (1) is used to represent the setting rule of replacement priority. Exemplarily, formula (1) can be: if the difference between D and L corresponding to the current cache block is greater than half of the difference between all D and L, and the L counter value corresponding to the current cache block is less than half of the maximum and minimum values ​​of all L, then the replacement priority age=2; if the D corresponding to the current cache block is greater than 7 times L and greater than one-quarter of the maximum D, or the D corresponding to the current cache block is greater than 3 times L and greater than one-quarter of the sum of all D, then the replacement priority age=1, which can be specifically expressed as:

[0168] age=2,if

[0169] (DL)>sum(DL) / 2&&L<(maxL+minL) / 2

[0170] age=1,if

[0171] D>7L&&D>maxD / 4 or

[0172] D>3L&&D>sumD / 4

[0173] Among them, sum(DL) represents the sum of all differences between D and L, "&&" means "and", which means that the previous and next conditions must be met at the same time, "maxL" represents the maximum value of L, "minL" represents the minimum value of L, "maxD" represents the maximum value of D, and "sumD" represents the sum of all D values.

[0174] It is understandable that the D counter represents inactivity to a certain extent, and the L counter represents activity to a certain extent. When D is large enough and L is small enough, the cache block corresponding to this TC-UC pair is considered to be inactive, so the replacement priority is high; formula (1) is used to measure what is considered "D is large enough and L is small enough", which is an empirical formula after multiple experiments. For different cache architectures and memory access modes, formula (1) can be adjusted to ensure the best cache replacement effect.

[0175] For the last-level cache, every time a miss occurs, it needs to fetch data from the main memory, which costs more than several hundred beats. However, data access between L2 and L3 only takes a dozen to dozens of beats. It can be seen that once a miss occurs in L3, the cost is huge.

[0176] The cache replacement method provided in the embodiment of the present invention can affect the processor performance in two aspects: (1) it can improve the overall cache hit rate, thereby reducing the processor's memory access latency and further improving the processor's performance; (2) even if the overall cache hit rate does not change much, by improving the hit rate of individual memory access requests in the critical path, the processor's memory access latency can be effectively reduced and the processor performance can be improved.

[0177] Furthermore, experimental results show that in the presence of multiple prefetchers, in some test programs that are sensitive to memory access (such as SPEC programs), the cache replacement method provided by the embodiments of the present invention can bring about significant improvements in hit rate and performance score.

[0178] In summary, an embodiment of the present invention provides a cache replacement method, which records the usage of a data block in a final-level cache and the usage of the data block in a previous-level cache of the final-level cache through a first data structure; and records the existence and access hit status of the data block corresponding to the first data structure in the final-level cache through a second data structure. The first data structure moves with the data block in the cache system of the processor, and the second data structure is stored in the final-level cache. The first data structure and the second data structure in the embodiment of the present invention reflect the historical information of the data block in the cache system, and even if the first data structure is replaced out of the final-level cache with the data block, the second data structure will always be stored in the final-level cache, providing historical information for the cache replacement algorithm, which is beneficial to improving the decision-making performance of the cache replacement algorithm.

[0179] It should be noted that, for the sake of simplicity, the method embodiments are described as a series of action combinations, but those skilled in the art should be aware that the embodiments of the present invention are not limited by the order of the actions described, because according to the embodiments of the present invention, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily required by the embodiments of the present invention.

[0180] Device Embodiment

[0181] Reference Figure 2 , shows a structural block diagram of a cache replacement device of the present invention, and the device may specifically include:

[0182] A first setting module 201 is used to set a first data structure for each data block appearing in the last-level cache of the processor, and record the usage of the data block in the last-level cache and the usage of the data block in the last-level cache in the first data structure; the first data structure moves with the data block in the cache system of the processor;

[0183] A second setting module 202, configured to set a second data structure in the final-level cache for each first data structure, and record in the second data structure the existence and access hit status of the data block corresponding to the first data structure in the final-level cache;

[0184] A first determining module 203, configured to determine a replacement priority of the data block in the last-level cache according to information recorded in the first data structure and the second data structure;

[0185] The second determining module 204 is configured to determine a replacement block according to the replacement priority of each data block in the last-level cache.

[0186] Optionally, the first determining module includes:

[0187] A first determining submodule, configured to set the replacement priority of the data block to the highest priority when the first data structure and the second data structure indicate that the data block is accessed by an upper level cache of the last level cache and the access is hit;

[0188] A second determining submodule, configured to keep the current replacement priority of the data block unchanged when the first data structure and the second data structure indicate that the data block is accessed by an upper level cache of the last level cache and the access does not hit;

[0189] A third determining submodule, configured to set the replacement priority of the data block to the lowest priority when the first data structure and the second data structure indicate that the data block is prefetched by an upper level cache of the last level cache and the prefetch hits;

[0190] The fourth determining submodule is used to determine the replacement priority of the data block according to a preset rule when the first data structure and the second data structure indicate that the data block is released by the previous level cache of the last level cache.

[0191] Optionally, the first data structure includes a first counter and a second counter; and the first setting module includes:

[0192] A first setting submodule, used for setting a first counter and a second counter respectively for each data block appearing in the last level cache of the processor;

[0193] The first counter is used to record the number of times the data block is used in the last-level cache; the second counter is used to record the number of times the data block is used in the previous-level cache of the last-level cache.

[0194] Optionally, the second data structure includes a third counter and a fourth counter; and the second setting module includes:

[0195] A second setting submodule, configured to set a third counter and a fourth counter for each array according to the value ranges of the first counter and the second counter;

[0196] Wherein, the array includes a value of the first counter and a value of the second counter; the third counter is used to record the number of times the data block appears in the last-level cache; and the fourth counter is used to record the number of times the data block hits in the last-level cache.

[0197] Optionally, the first determining module includes:

[0198] A first updating submodule, configured to update a first counter and a second counter corresponding to a target data block of the request according to a request type and a hit condition of a memory access request received by the last-level cache;

[0199] An array determination submodule, used to determine a target array according to count values ​​of a first counter and a second counter corresponding to the target data block;

[0200] A second updating submodule, configured to update a third counter and a fourth counter corresponding to the target array according to a request type and a hit condition of a memory access request received by the last-level cache;

[0201] The priority determination submodule is used to determine the replacement priority of the target data block in the last-level cache according to the first counter, the second counter, the third counter and the fourth counter.

[0202] Optionally, the first updating submodule includes:

[0203] A first updating unit is configured to, when the last-level cache receives a first access request for a target data block from a previous-level cache and the access is hit, increase the count value of a first counter corresponding to the target data block by 1, and keep the count value of the second counter unchanged;

[0204] The second updating unit is used to increase the count value of the second counter corresponding to the target data block by 1 when the previous level cache of the last level cache receives a second access request for the target data block and the access hits, and the count value of the first counter remains unchanged.

[0205] Optionally, the first updating submodule further includes:

[0206] A first holding unit, configured to keep current count values ​​of the first counter and the second counter unchanged when a first condition is met;

[0207] The first condition includes at least one of the following:

[0208] The last level cache receives a pre-fetch request for the target data block, and the pre-fetch request hits;

[0209] The last level cache receives a first access request from the previous level cache for the target data block, and the access is a miss;

[0210] The last-level cache receives a release request for the target data block from the previous-level cache.

[0211] Optionally, the first updating submodule further includes:

[0212] An initialization unit is used to initialize the count values ​​of the first counter and the second counter when the last-level cache receives a prefetch request for the target data block and the prefetch request does not hit.

[0213] Optionally, the second updating submodule includes:

[0214] A third updating unit, configured to increase the count value of the fourth counter corresponding to the target array by 1 when the second condition is met, and the count value of the third counter corresponding to the target array remains unchanged;

[0215] The second condition includes at least one of the following:

[0216] The last level cache receives a first access request from the previous level cache for a target data block, and the access is a hit;

[0217] The last-level cache receives a pre-fetch request for the target data block, and the pre-fetch request is successful.

[0218] Optionally, the second updating submodule further includes:

[0219] A second holding unit is used to increase the count value of the third counter corresponding to the target array by 1 when a third condition is met, and the count value of the fourth counter corresponding to the target array remains unchanged;

[0220] The third condition includes at least one of the following:

[0221] The last level cache receives a pre-fetch request for the target data block, and the pre-fetch request does not hit;

[0222] The last-level cache receives a release request for the target data block from the previous-level cache.

[0223] Optionally, the second updating submodule further includes:

[0224] The third holding unit is used to keep the count values ​​of the third counter and the fourth counter corresponding to the target array unchanged when the last-level cache receives a first access request for the target data block from the previous-level cache and the access misses.

[0225] In summary, an embodiment of the present invention provides a cache replacement device, which records the usage of a data block in a final-level cache and the usage of the data block in a previous-level cache of the final-level cache through a first data structure; and records the existence and access hit status of the data block corresponding to the first data structure in the final-level cache through a second data structure. The first data structure moves with the data block in the cache system of the processor, and the second data structure is stored in the final-level cache. The first data structure and the second data structure in the embodiment of the present invention reflect the historical information of the data block in the cache system, and even if the first data structure is replaced out of the final-level cache with the data block, the second data structure will always be stored in the final-level cache, providing historical information for the cache replacement algorithm, which is beneficial to improving the decision-making performance of the cache replacement algorithm.

[0226] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0227] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.

[0228] Regarding the processor in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.

[0229] Reference Figure 3 , is a structural block diagram of an electronic device for accessing memory provided by an embodiment of the present invention. Figure 3 As shown, the electronic device includes: a processor, a memory, a communication interface and a communication bus, and the processor, the memory and the communication interface communicate with each other through the communication bus; the memory is used to store executable instructions, and the executable instructions enable the processor to execute the cache replacement method of the aforementioned embodiment.

[0230] The processor may be a CPU (Central Processing Unit), a general-purpose processor, a DSP (Digital Signal Processor), an ASIC (Application Specific Integrated Circuit), an FPGA (Field Programmable Gate Array) or other editable devices, transistor logic devices, hardware components or any combination thereof. The processor may also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of a DSP and a microprocessor, etc.

[0231] The communication bus may include a path for transmitting information between the memory and the communication interface. The communication bus may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus, etc. The communication bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 3 The fact that only one line is used in the diagram does not mean that there is only one bus or only one type of bus.

[0232] The memory may be a ROM (Read Only Memory) or other types of static storage devices that can store static information and instructions, a RAM (Random Access Memory) or other types of dynamic storage devices that can store information and instructions, or an EEPROM (Electrically Erasable Programmable Read Only Memory), a CD-ROM (Compact Disc Read Only Memory), a magnetic tape, a floppy disk, an optical data storage device, etc.

[0233] The embodiment of the present invention also provides a non-transitory computer-readable storage medium, when the instructions in the storage medium are executed by a processor of an electronic device (server or terminal), the processor can execute Figure 1 The cache replacement method shown.

[0234] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.

[0235] It should be understood by those skilled in the art that the embodiments of the present invention may be provided as methods, devices or computer program products. Therefore, the embodiments of the present invention may take the form of a complete hardware embodiment, a complete software embodiment or an embodiment combining software and hardware aspects. Moreover, the embodiments of the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0236] The embodiments of the present invention are described with reference to the flowcharts and / or block diagrams of the methods, terminal devices (systems) and computer program products according to the embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of the processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor or other programmable data processing terminal device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0237] These computer program instructions may also be stored in a computer readable memory capable of directing a computer or other programmable data processing terminal device to operate in a predictable manner, so that the instructions stored in the computer readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0238] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable terminal device to implement the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0239] Although the preferred embodiments of the present invention have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present invention.

[0240] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or terminal device including the elements.

[0241] The cache replacement method, device, electronic device and readable storage medium provided by the present invention are introduced in detail above. Specific examples are used in this article to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for those skilled in the art, according to the idea of ​​the present invention, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.

Claims

1. A cache replacement method, characterized in that: The method comprises: A first data structure is set for each data block appearing in the last-level cache of the processor, and the usage of the data block in the last-level cache and the usage of the data block in the last-level cache are recorded in the first data structure; the first data structure moves with the data block in the cache system of the processor; For each first data structure, a second data structure is set in the final-level cache, and the existence and access hit status of the data block corresponding to the first data structure in the final-level cache are recorded in the second data structure; Determining a replacement priority of the data block in the last-level cache according to information recorded in the first data structure and the second data structure; Determining a replacement block according to the replacement priority of each data block in the last-level cache; The information recorded in the second data structure is stored in the last-level cache and will not be moved in the cache system along with the data block; The second data structure includes a history information record table, with the first data structure as a table item index, each table item index corresponds to a first table item and a second table item, the first table item is used to record the existence of the data block in the final-level cache, and the second table item is used to record the hit status of the data block in the final-level cache; or The second data structure includes a third counter and a fourth counter, the third counter is used to record the number of times the data block corresponding to the first data structure appears in the final-level cache, and the fourth counter is used to record the number of times the data block corresponding to the first data structure hits in the final-level cache.

2. The method according to claim 1, characterized in that: The step of determining the replacement priority of the data block in the last-level cache according to the information recorded in the first data structure and the second data structure includes: When the first data structure and the second data structure indicate that the data block is accessed by an upper level cache of the last level cache and the access is a hit, setting the replacement priority of the data block to the highest priority; When the first data structure and the second data structure indicate that the data block is accessed by a previous level cache of the last level cache and the access misses, keeping the current replacement priority of the data block unchanged; When the first data structure and the second data structure indicate that the data block is pre-fetched by an upper level cache of the last level cache and the pre-fetch hits, setting the replacement priority of the data block to the lowest priority; When the first data structure and the second data structure indicate that the data block is released by an upper-level cache of the last-level cache, a replacement priority of the data block is determined according to a preset rule.

3. The method according to claim 1, characterized in that The first data structure includes a first counter and a second counter; the first data structure is set for each data block appearing in the last-level cache of the processor, and the usage of the data block in the last-level cache and the usage of the data block in the last-level cache are recorded in the first data structure, including: A first counter and a second counter are respectively set for each data block present in the last level cache of the processor; The first counter is used to record the number of times the data block is used in the last-level cache; the second counter is used to record the number of times the data block is used in the previous-level cache of the last-level cache.

4. The method according to claim 3, characterized in that The second data structure includes a third counter and a fourth counter; for each first data structure, setting a second data structure in the final-level cache, and recording in the second data structure the existence and access hit status of a data block corresponding to the first data structure in the final-level cache, including: According to the value ranges of the first counter and the second counter, a third counter and a fourth counter are respectively set for each array; Wherein, the array includes a value of the first counter and a value of the second counter; the third counter is used to record the number of times the data block appears in the last-level cache; and the fourth counter is used to record the number of times the data block hits in the last-level cache.

5. The method according to claim 4, characterized in that The step of determining the replacement priority of the data block in the last-level cache according to the information recorded in the first data structure and the second data structure includes: According to the request type and hit status of the memory access request received by the last-level cache, a first counter and a second counter corresponding to the requested target data block are updated; Determine a target array according to the count values ​​of a first counter and a second counter corresponding to the target data block; According to the request type and hit status of the memory access request received by the last-level cache, a third counter and a fourth counter corresponding to the target array are updated; A replacement priority of the target data block in the last-level cache is determined according to the first counter, the second counter, the third counter, and the fourth counter.

6. The method according to claim 5, characterized in that The updating of the first counter and the second counter corresponding to the requested target data block according to the request type and the hit status of the memory access request received by the last-level cache comprises: When the last-level cache receives a first access request for a target data block from the previous-level cache and the access is hit, the count value of the first counter corresponding to the target data block is increased by 1, and the count value of the second counter remains unchanged; When the upper level cache of the last level cache receives a second access request for the target data block and the access is hit, the count value of the second counter corresponding to the target data block is increased by 1, and the count value of the first counter remains unchanged.

7. The method according to claim 6, characterized in that The method further comprises: When the first condition is met, keeping the current count values ​​of the first counter and the second counter unchanged; The first condition includes at least one of the following: The last level cache receives a pre-fetch request for the target data block, and the pre-fetch request hits; The last level cache receives a first access request from the previous level cache for the target data block, and the access is a miss; The last-level cache receives a release request for the target data block from the previous-level cache.

8. The method according to claim 6, characterized in that The method further comprises: When the last-level cache receives a pre-fetch request for the target data block and the pre-fetch request does not hit, the count values ​​of the first counter and the second counter are initialized.

9. The method according to claim 5, characterized in that The updating of the third counter and the fourth counter corresponding to the target array according to the request type and the hit status of the memory access request received by the last-level cache comprises: When the second condition is met, the count value of the fourth counter corresponding to the target array is increased by 1, and the count value of the third counter corresponding to the target array remains unchanged; The second condition includes at least one of the following: The last level cache receives a first access request from the previous level cache for a target data block, and the access is a hit; The last-level cache receives a pre-fetch request for the target data block, and the pre-fetch request is successful.

10. The method according to claim 9, characterized in that The method further comprises: When the third condition is met, the count value of the third counter corresponding to the target array is increased by 1, and the count value of the fourth counter corresponding to the target array remains unchanged; The third condition includes at least one of the following: The last level cache receives a pre-fetch request for the target data block, and the pre-fetch request does not hit; The last-level cache receives a release request for the target data block from the previous-level cache.

11. The method according to claim 9, characterized in that The method further comprises: When the last-level cache receives a first access request from the previous-level cache for a target data block and the access fails, the count values ​​of the third counter and the fourth counter corresponding to the target array remain unchanged.

12. A cache replacement device, characterized in that: The device comprises: A first setting module is used to set a first data structure for each data block appearing in the last-level cache of the processor, and record the usage of the data block in the last-level cache and the usage of the data block in the last-level cache in the first data structure; the first data structure moves with the data block in the cache system of the processor; a second setting module, configured to set a second data structure in the final-level cache for each first data structure, and record in the second data structure the existence and access hit status of a data block corresponding to the first data structure in the final-level cache; A first determining module, configured to determine a replacement priority of the data block in the last-level cache according to information recorded in the first data structure and the second data structure; A second determination module, configured to determine a replacement block according to a replacement priority of each data block in the last-level cache; The information recorded in the second data structure is stored in the last-level cache and will not be moved in the cache system along with the data block; The second data structure includes a history information record table, with the first data structure as a table item index, each table item index corresponds to a first table item and a second table item, the first table item is used to record the existence of the data block in the final-level cache, and the second table item is used to record the hit status of the data block in the final-level cache; or The second data structure includes a third counter and a fourth counter, the third counter is used to record the number of times the data block corresponding to the first data structure appears in the final-level cache, and the fourth counter is used to record the number of times the data block corresponding to the first data structure hits in the final-level cache.

13. The device according to claim 12, characterized in that The first determining module includes: A first determining submodule, configured to set the replacement priority of the data block to the highest priority when the first data structure and the second data structure indicate that the data block is accessed by an upper level cache of the last level cache and the access is hit; A second determining submodule, configured to keep the current replacement priority of the data block unchanged when the first data structure and the second data structure indicate that the data block is accessed by an upper level cache of the last level cache and the access does not hit; A third determining submodule, configured to set the replacement priority of the data block to the lowest priority when the first data structure and the second data structure indicate that the data block is prefetched by an upper level cache of the last level cache and the prefetch hits; The fourth determining submodule is used to determine the replacement priority of the data block according to a preset rule when the first data structure and the second data structure indicate that the data block is released by the previous level cache of the last level cache.

14. An electronic device, characterized in that: The electronic device includes a processor, a memory, a communication interface and a communication bus, and the processor, the memory and the communication interface communicate with each other through the communication bus; the memory is used to store executable instructions, and the executable instructions enable the processor to execute the cache replacement method as described in any one of claims 1 to 11.

15. A readable storage medium, characterized in that: When the instructions in the readable storage medium are executed by a processor of an electronic device, the processor is enabled to execute the cache replacement method as claimed in any one of claims 1 to 11.