Cache line replacement method and apparatus
By dividing the cache into multiple data block partitions and managing them using a binary tree structure, the problem of inconsistent cache line hits is solved, achieving balanced replacement of cache lines and efficient hit testing, thus improving the stability and efficiency of the cache.
Patent Information
- Application Number
- CN202311634767.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-11-30
- Publication Date
- 2026-01-27
- Estimated Expiration
- 2043-11-30
AI Technical Summary
In existing technologies, the way cache lines are managed leads to inconsistent cache line hit counts, frequent replacement of some cache line data, resulting in unstable program execution and long hit test times.
The cache is divided into multiple data block partitions, and each data block partition is set with a corresponding management organization structure. A binary tree structure and node information are used to replace cache lines. The PLRU algorithm is used to find replaceable cache lines, and the management organization structure is used to achieve balanced replacement of cache lines.
While increasing cache storage capacity, the time required for hit testing was reduced, and balanced replacement of cache lines was achieved, improving the efficiency and stability of cache line replacement.
Smart Images

Figure CN117349198B_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of memory management technology, and in particular to a cache line replacement method and apparatus. Background Technology
[0002] A Graphics Processing Unit (GPU), also known as a display core, visual processor, or display chip, is a microprocessor specifically designed for performing image and graphics-related computations in personal computers, workstations, game consoles, and some mobile devices (such as tablets and smartphones). Data related to GPU computations can be stored in on-chip or off-chip memory. External Global Memory (GRAM), located far from the GPU core, suffers from slow access speeds. To address this, an on-chip cache is typically added within the processor core. This cache pre-loads read and write data, allowing the GPU to quickly access the cache without retrieving it from external GRAM. The cache consists of multiple cache lines, accessed via line addresses. However, current cache management methods suffer from inconsistent cache line hit counts and frequent data replacement in some cache lines, issues that require further resolution. Summary of the Invention
[0003] In view of this, the present disclosure proposes a cache line replacement method and apparatus.
[0004] According to one aspect of this disclosure, a cache line replacement method is provided for replacing and searching cache lines in a data block partition. The data block partition includes at least one data block, each data block includes multiple cache lines, and each data block partition has a corresponding management organization structure. The management organization structure includes a binary tree structure corresponding to the data block partition and node information for each node in the binary tree structure. The node information includes: processing status, a left partition counter, and a right partition counter. The method includes:
[0005] Upon receiving a replacement request, the root node in the binary tree structure corresponding to the data block partition is determined as the first target node, and the node information of the target node is obtained.
[0006] If the target node is a non-leaf node, the child node of the target node in the replacement direction indicated by the current processing state of the target node is determined as the next target node and the target counter of the target node corresponding to the replacement direction is updated until the determined target node is a leaf node. Then, the data block to be queried is determined based on the leaf node.
[0007] The PLRU algorithm is used to find replaceable cache lines in the data block to be searched;
[0008] The search results are generated based on the data block ID of the data block to be searched and the cache line ID of the replaceable cache line;
[0009] The target counter is the left partition counter and the right partition counter of the target node, which are counters corresponding to the replacement direction indicated by the processing state of the target node. The replacement direction indicated by the processing state of each node is the left branch or the right branch of the node.
[0010] In one possible implementation, determining the data block to be queried based on the leaf nodes includes:
[0011] The data block corresponding to the replacement direction indicated by the processing status of the leaf node is determined as the data block to be queried; or
[0012] The data block corresponding to the leaf node is identified as the data block to be queried.
[0013] In one possible implementation, the node information further includes left partition weights and right partition weights, and the method further includes:
[0014] If the value of the target counter is a preset value, reset the target counter to the initial value and change the replacement direction indicated by the processing state of the target node;
[0015] Wherein, the initial value corresponds to the partition weight of the branch direction where the target counter is located, and the preset value is 0; or, the initial value is 0, and the preset value corresponds to the partition weight of the branch direction where the target counter is located; the partition weight of the branch direction where the left partition counter is located is the left partition weight, and the partition weight of the branch direction where the right partition counter is located is the right partition weight.
[0016] In one possible implementation, the method further includes:
[0017] If the target counter of the target node is determined to be invalid and / or the partition weight of the target node corresponding to the replacement direction indicated by the processing state is 0, the target node is determined to be a leaf node;
[0018] Wherein, the partition weight of the target node corresponding to the replacement direction indicated by the processing state is either the left partition weight or the right partition weight.
[0019] In one possible implementation, the node information further includes a left pointer and a right pointer, and the method further includes:
[0020] The next target node is found based on the target pointer corresponding to the replacement direction indicated by the current processing status of the target node;
[0021] Wherein, if the replacement direction indicated by the current processing state of the target node is the left branch, then the target pointer is the left pointer; if the replacement direction indicated by the current processing state of the target node is the right branch, then the target pointer is the right pointer.
[0022] In one possible implementation, the node information of the leaf node further includes: a right address index and a left address index.
[0023] Specifically, determining the data block corresponding to the replacement direction indicated by the processing state of the leaf node as the data block to be queried includes: determining the data block pointed to by the target address index corresponding to the replacement direction indicated by the processing state of the leaf node as the data block to be queried.
[0024] Wherein, if the replacement direction indicated by the current processing state of the target node is the left branch, then the target address index is the left address index; if the replacement direction indicated by the current processing state of the target node is the right branch, then the target address index is the right address index.
[0025] In one possible implementation, the node information further includes: a left valid index identifier and a right valid index identifier, determining the data block pointed to by the address index corresponding to the replacement direction indicated by the processing state of the leaf node as the data block to be queried, including:
[0026] If the valid index identifier corresponding to the replacement direction indicated by the processing state of the leaf node is valid, the data block pointed to by the address index corresponding to the replacement direction indicated by the processing state of the leaf node is determined as the data block to be queried.
[0027] Wherein, if the replacement direction indicated by the current processing state of the target node is the left branch, then the address index pointing to the data block to be queried is the left valid index identifier; if the replacement direction indicated by the current processing state of the target node is the right branch, then the address index pointing to the data block to be queried is the right valid index identifier.
[0028] In one possible implementation, the node information of the leaf node further includes one of the right address index and the left address index.
[0029] Specifically, determining the data block corresponding to the leaf node as the data block to be queried includes: determining the data block pointed to by the address index existing in the node information of the leaf node as the data block to be queried.
[0030] In one possible implementation, the node information of the leaf node further includes one of a left valid index identifier and a right valid index identifier.
[0031] Specifically, determining the data block corresponding to the leaf node as the data block to be queried includes:
[0032] If the left or right valid index identifier in the node information of the leaf node is valid, the data block pointed to by the address index in the node information of the leaf node is determined as the data block to be queried.
[0033] In one possible implementation, the left partition weight and right partition weight of each node are related to the number of data blocks on the left side of the node's left branch and the number of data blocks on the right side of the node's right branch.
[0034] When the number of nodes on the left and right sides of a node is not zero, the values of the left partition weight and the right partition weight of the node are determined according to the simplest integer ratio of the number of nodes on the left and the number of nodes on the right.
[0035] When the number of nodes to the left and / or the number of nodes to the right are zero, the values of the left partition weight and the right partition weight of the node are set to the number of nodes to the left and the number of nodes to the right, respectively.
[0036] In one possible implementation, the method further includes:
[0037] In response to the reconstruction request, the number of data blocks in the data block partition and the number of cache lines in each data block are set according to the configuration information, and the data block ID and cache line ID of each data block are set.
[0038] Based on the number of data blocks in the data block partition, a binary tree structure corresponding to the data block partition is created, and the node information of each node in the binary tree structure is determined to complete the management organization structure configuration of the data block partition.
[0039] In one possible implementation, each of the data blocks includes There are n cache lines, where n is a positive integer.
[0040] According to another aspect of this disclosure, a cache line replacement apparatus is provided for replacing and searching cache lines in a data block partition. The data block partition includes at least one data block, each data block includes multiple cache lines, and each data block partition has a corresponding management organization structure. The management organization structure includes a binary tree structure corresponding to the data block partition and node information for each node in the binary tree structure. The node information includes: processing status, a left partition counter, and a right partition counter. The apparatus includes:
[0041] The replacement request receiving module is used to determine the root node in the binary tree structure corresponding to the data block partition as the first target node and obtain the node information of the target node when a replacement request is received.
[0042] The data block to be checked module is used to determine the child node of the target node in the replacement direction indicated by the current processing state of the target node as the next target node and update the target counter of the target node corresponding to the replacement direction, when the target node is a non-leaf node, until the determined target node is a leaf node, and then determine the data block to be checked based on the leaf node.
[0043] The cache line replacement module is used to find replaceable cache lines in the data block to be searched using the PLRU algorithm.
[0044] The search result generation module is used to generate search results based on the data block ID of the data block to be searched and the cache line ID of the replaceable cache line;
[0045] The target counter is the left partition counter and the right partition counter of the target node, which are counters corresponding to the replacement direction indicated by the processing state of the target node. The replacement direction indicated by the processing state of each node is the left branch or the right branch of the node.
[0046] In one possible implementation, the data block determination module includes:
[0047] The first determining submodule is used to determine the data block corresponding to the replacement direction indicated by the processing state of the leaf node as the data block to be searched; or
[0048] The second determination submodule is used to determine the data block corresponding to the leaf node as the data block to be queried.
[0049] In one possible implementation, the node information further includes left partition weights and right partition weights, and the device further includes:
[0050] The reset update module is used to reset the target counter to an initial value and change the replacement direction indicated by the processing state of the target node when the value of the target counter is a preset value.
[0051] Wherein, the initial value corresponds to the partition weight of the branch direction where the target counter is located, and the preset value is 0; or, the initial value is 0, and the preset value corresponds to the partition weight of the branch direction where the target counter is located; the partition weight of the branch direction where the left partition counter is located is the left partition weight, and the partition weight of the branch direction where the right partition counter is located is the right partition weight.
[0052] In one possible implementation, the device further includes:
[0053] The leaf node determination module is used to determine the target node as a leaf node when the target counter of the target node is determined to be invalid and / or the partition weight of the target node corresponding to the replacement direction indicated by the processing state is 0.
[0054] Wherein, the partition weight of the target node corresponding to the replacement direction indicated by the processing state is either the left partition weight or the right partition weight.
[0055] In one possible implementation, the node information further includes a left pointer and a right pointer, and the device further includes:
[0056] The target node search module is used to find the next target node according to the target pointer corresponding to the replacement direction indicated by the current processing state of the target node;
[0057] Wherein, if the replacement direction indicated by the current processing state of the target node is the left branch, then the target pointer is the left pointer; if the replacement direction indicated by the current processing state of the target node is the right branch, then the target pointer is the right pointer.
[0058] In one possible implementation, the node information of the leaf node further includes: a right address index and a left address index.
[0059] Specifically, determining the data block corresponding to the replacement direction indicated by the processing state of the leaf node as the data block to be queried includes: determining the data block pointed to by the target address index corresponding to the replacement direction indicated by the processing state of the leaf node as the data block to be queried.
[0060] Wherein, if the replacement direction indicated by the current processing state of the target node is the left branch, then the target address index is the left address index; if the replacement direction indicated by the current processing state of the target node is the right branch, then the target address index is the right address index.
[0061] In one possible implementation, the node information further includes: a left valid index identifier and a right valid index identifier, determining the data block pointed to by the address index corresponding to the replacement direction indicated by the processing state of the leaf node as the data block to be queried, including:
[0062] If the valid index identifier corresponding to the replacement direction indicated by the processing state of the leaf node is valid, the data block pointed to by the address index corresponding to the replacement direction indicated by the processing state of the leaf node is determined as the data block to be queried.
[0063] Wherein, if the replacement direction indicated by the current processing state of the target node is the left branch, then the address index pointing to the data block to be queried is the left valid index identifier; if the replacement direction indicated by the current processing state of the target node is the right branch, then the address index pointing to the data block to be queried is the right valid index identifier.
[0064] In one possible implementation, the node information of the leaf node further includes one of the right address index and the left address index.
[0065] Specifically, determining the data block corresponding to the leaf node as the data block to be queried includes: determining the data block pointed to by the address index existing in the node information of the leaf node as the data block to be queried.
[0066] In one possible implementation, the node information of the leaf node further includes one of a left valid index identifier and a right valid index identifier.
[0067] Specifically, determining the data block corresponding to the leaf node as the data block to be queried includes:
[0068] If the left or right valid index identifier in the node information of the leaf node is valid, the data block pointed to by the address index in the node information of the leaf node is determined as the data block to be queried.
[0069] In one possible implementation, the left partition weight and right partition weight of each node are related to the number of data blocks on the left side of the node's left branch and the number of data blocks on the right side of the node's right branch.
[0070] When the number of nodes on the left and right sides of a node is not zero, the values of the left partition weight and the right partition weight of the node are determined according to the simplest integer ratio of the number of nodes on the left and the number of nodes on the right.
[0071] When the number of nodes to the left and / or the number of nodes to the right are zero, the values of the left partition weight and the right partition weight of the node are set to the number of nodes to the left and the number of nodes to the right, respectively.
[0072] In one possible implementation, the device further includes:
[0073] The configuration module is used to respond to a reconstruction request by setting the number of data blocks in the data block partition and the number of cache lines in each data block according to the configuration information, and setting the data block ID and cache line ID of each data block; creating a binary tree structure corresponding to the data block partition according to the number of data blocks in the data block partition, and determining the node information of each node in the binary tree structure, thereby completing the management organization structure configuration of the data block partition.
[0074] In one possible implementation, each of the data blocks includes There are n cache lines, where n is a positive integer.
[0075] According to another aspect of this disclosure, a cache line replacement apparatus is provided, comprising: a processor; a memory for storing processor-executable instructions; wherein the processor is configured to implement the above method when executing instructions stored in the memory.
[0076] According to another aspect of this disclosure, a non-volatile computer-readable storage medium is provided that stores computer program instructions thereon, wherein the computer program instructions, when executed by a processor, implement the above-described method.
[0077] According to another aspect of this disclosure, a computer program product is provided, including computer-readable code, or a non-volatile computer-readable storage medium carrying computer-readable code, wherein when the computer-readable code is run in a processor of an electronic device, the processor in the electronic device performs the above-described method.
[0078] This disclosure provides a cache line replacement method and apparatus. The cache is divided into multiple data block partitions, each containing at least one data block. Each data block includes multiple cache lines, and a corresponding management organization structure is set for each data block partition. Cache line replacement is then performed based on this management organization structure. This increases cache storage capacity while reducing the time required for hit tests, and simultaneously achieves balanced cache line replacement.
[0079] Other features and aspects of this disclosure will become clear from the following detailed description of exemplary embodiments with reference to the accompanying drawings. Attached Figure Description
[0080] The accompanying drawings, which are included in and form part of this specification, illustrate exemplary embodiments, features, and aspects of this disclosure together with the specification and serve to explain the principles of this disclosure.
[0081] Figure 1 This diagram illustrates cache line replacement based on a full binary tree in related technologies.
[0082] Figure 2 This diagram illustrates a non-full binary tree structure corresponding to a cache line in related technologies.
[0083] Figure 3 This diagram illustrates cache allocation in a cache line replacement method according to an embodiment of the present disclosure.
[0084] Figure 4This diagram illustrates a binary tree structure corresponding to a data block partition in an example of a cache line replacement method according to an embodiment of the present disclosure.
[0085] Figure 5 This diagram illustrates node information of a binary tree structure in a cache line replacement method according to an embodiment of the present disclosure.
[0086] Figure 6 This diagram illustrates the binary tree structure corresponding to the data block partition in Example 2 of a cache line replacement method according to an embodiment of this disclosure.
[0087] Figure 7 This diagram illustrates a binary tree structure in the management organization of a block grouping, representing an example of a cache line replacement method according to an embodiment of the present disclosure.
[0088] Figure 8 A flowchart illustrating the replacement step in a cache line replacement method according to an embodiment of the present disclosure is shown.
[0089] Figure 9 A block diagram of a cache line replacement apparatus according to an embodiment of the present disclosure is shown.
[0090] Figure 10 This is a block diagram illustrating an apparatus 1900 for cache line replacement according to an exemplary embodiment. Detailed Implementation
[0091] Various exemplary embodiments, features, and aspects of this disclosure will now be described in detail with reference to the accompanying drawings. The same reference numerals in the drawings denote elements that have the same or similar functions. Although various aspects of the embodiments are shown in the drawings, they are not necessarily drawn to scale unless specifically indicated otherwise.
[0092] The term “exemplary” as used herein means “serving as an example, embodiment, or illustration.” Any embodiment illustrated herein as “exemplary” is not necessarily to be construed as superior to or better than other embodiments.
[0093] Furthermore, to better illustrate this disclosure, numerous specific details are set forth in the following detailed description. Those skilled in the art will understand that this disclosure can be practiced without certain specific details. In some instances, methods, means, components, and circuits well known to those skilled in the art have not been described in detail in order to highlight the main points of this disclosure.
[0094] A cache is a buffer located between main memory (also known as RAM) and processors such as GPUs and CPUs, used to store data from main memory. Based on speed, caches can be categorized into Level 1 cache (L1 Cache), Level 2 cache (L2 Cache), and Level 3 cache (L3 Cache), with speed decreasing in that order.
[0095] In related technologies, access to cached lines in the cache is implemented as follows: After determining the line address of the cached line to be accessed, a Hit / Miss Test is performed. If a hit occurs, the cached line can be accessed directly; if a miss occurs, a replacement algorithm (such as the Pseudo Least Recently Used (PLRU) algorithm) is used to select the least recently used cached line for replacement, and access is then performed after the replacement is complete. During this process, Tag RAM (Tag Random Access Memory) is used to store and manage information such as the tag, valid bit, dirty mask, and context ID for each cached line.
[0096] When a cache miss occurs, the PLRU algorithm selects the cache line to be replaced and obtains its cache line ID. Then, it checks the Tag Ram to see if the dirty mask of that cache line is dirty. If it is dirty, the data from that cache line is stored in the corresponding location in the next level cache before accessing the cache line again. If it is not dirty, the data stored in the cache line is directly replaced with new data, or the cache line is read after it has stored the data returned by the request, and the information corresponding to that cache line stored in the Tag Ram is updated. The PLRU algorithm is simple and fast, and is suitable for applications such as... Figure 1 The full binary tree structure shown can achieve balanced replacement management. However, the PLRU algorithm has limitations; it requires a certain number of cache lines in the cache. (where n is an integer) is required to guarantee that the hit rate of each cache line is the same. However, in some cases, especially in some configurable storage environments, the number of cache lines in the cache is often not... The resulting binary tree structure is unbalanced, with one side having more lines than the other. For example, if the number of cache lines in the cache is as follows... Figure 2 The three cache lines shown form a non-full binary tree structure. When the PLRU algorithm is used for replacement, the rightmost leaf node has a 50% hit rate, while the two leftmost leaf nodes each have a 25% hit rate. This clearly cannot guarantee that all cache lines are hit equally, and it also leads to some cache lines being frequently replaced, causing program instability. Furthermore, when performing a Hit / Miss Test on a tag, the access wait time for n cache lines is consistently n / 2. This means that the more cache lines there are, the more comparisons are performed, and the slower the lookup and replacement speed becomes.
[0097] To address the aforementioned technical problems, this disclosure provides a cache line replacement method and apparatus. The cache is divided into multiple data block partitions, each containing at least one data block. Each data block includes multiple cache lines, and a corresponding management organization structure is set for each data block partition. Cache line replacement is then performed based on this management organization structure. This increases cache storage capacity while reducing the time required for hit tests, and simultaneously achieves balanced cache line replacement.
[0098] The cache line replacement method provided in this disclosure is used for... Figure 3 The storage area 2 shown is replaced. Storage area 2 may include multiple data block partitions (also called DB areas or DB partitions) 30, and each data block partition 30 includes multiple data blocks 301. Each data block 301 includes... There are n (a positive integer) cache lines. Figure 3 The cache settings are only shown schematically. Those skilled in the art can set the number of data block partitions in the cache, the number of data blocks in the data block partitions, and the number of cache lines contained in the data blocks according to actual needs. This disclosure does not impose any restrictions on these settings. The storage area 2 can be a cache, such as a level 1 cache (L1 cache), a level 2 cache (L2 cache), a level 3 cache (L3 cache), etc. This disclosure does not impose any restrictions on these settings.
[0099] The cache line replacement method provided in this disclosure includes an "initialization configuration step" and a "replacement step", which are explained below.
[0100] In this embodiment, the "initialization configuration step" completes the management organization structure configuration for each of the data block partitions 30. The "initialization configuration step" may include an allocation step and a structure creation step.
[0101] In the "allocation step," in response to a reconstruction request (which can be initiated by the user or generated after detecting that preset conditions are met, such as detecting program startup), the data block partition 30 is configured for use based on configuration information. This configuration information may indicate some or all of the following: the currently available storage capacity of the data block partition 30 (or the number of currently available cache lines), the number of data blocks in the data block partition, and the size of each data block. Configuring the data block partition 30 for use may include: configuring data blocks for each data block partition based on the number of blocks corresponding to each data block partition; and configuring cache lines for each data block based on the number of lines corresponding to each data block. In some embodiments, the configuration information in this "allocation step" originates from the configuration information of storage region 2. The configuration information of storage region 2 may also indicate the number of currently available bankgroups in storage region 2, the size of each bankgroup, and which data block partitions are set in each bankgroup.
[0102] In this embodiment, configuring data blocks for each data block partition according to the number of blocks corresponding to each data block partition may include: allocating data blocks (DB) to each data block partition according to the number of blocks corresponding to each data block partition; and determining the data block ID (DB id) of each data block DB. Specifically, configuring cache lines for each data block according to the number of rows corresponding to each data block includes: allocating cache lines to each data block DB, and determining the cache line ID (cacheline id) and cache line tag (cacheline tag) of each cache line.
[0103] In the "Structure Creation Step," a binary tree structure corresponding to each data block partition 30 is created based on the number of data blocks 301 in the data block partition 30, and the node information of each node in the binary tree structure is determined, thus completing the management organization structure configuration of the data block partition 30. Then, the binary tree structure and the node information of each node are stored. In some embodiments, the binary tree structure and the node information of each node can be stored in a corresponding memory, such as a corresponding buffer.
[0104] In this embodiment, the level and number of nodes in the binary tree structure corresponding to each data block partition are related to the number of data blocks in that partition. Each leaf node in the binary tree structure can correspond to at most one or two data blocks in that partition. Depending on the maximum number of data blocks a leaf node can correspond to, there are two different implementations of the binary tree structure.
[0105] Example 1: If a leaf node can correspond to a maximum of 2 data blocks. For example... Figure 4 , Figure 5As shown, in this example, data block partition 1 includes 6 data blocks, and the corresponding binary tree has 3 levels and 5 nodes, including 3 leaf nodes. Each leaf node corresponds to two data blocks. Each node has its own node information.
[0106] Example 2: If a leaf node can correspond to a maximum of 1 data block. For example... Figure 6 As shown, in this example, data block partition 1 includes 6 data blocks, and the corresponding binary tree has 4 levels and 11 nodes, of which there are 6 leaf nodes, and each leaf node corresponds to one data block. Each node has its own node information.
[0107] In some embodiments, node information includes some or all of the following: ProcessingStatus (S), Left Partition weight (LW), Left Partition counter (LC), Left Pointer (LP), Left VldIdx_flag (LVF), Left Address Index (LAI), Right Partition weight (RW), Right Partition counter (RC), Right Pointer (RP), Right VldIdx_flag (RVF), and Right Address Index (RAI).
[0108] The processing status S indicates the current processing status of the corresponding data blocks in the left and right branches of the node, indicating the replacement direction. The replacement direction indicated by the processing status of each node is either the left or right branch of that node. In some embodiments, the processing status can indicate whether the cache line of the data block in the left branch or the cache line of the data block in the right branch of the node can be replaced. Different processing status flags can be set to represent different replacement directions. For example, "0" can be set to indicate that the processing status S is replacing the left branch, and "1" can be set to indicate that the processing status S is replacing the right branch. In Example 1, the node information of each node has a processing status set. In Example 2, only the node information of non-leaf nodes has a processing status set; the node information of leaf nodes does not contain a processing status or the processing status bit is invalid.
[0109] The left partition weight LW represents the weight of the left branch of the node. The left partition weight LW is related to the number of data blocks in the left branch of the node (i.e., the number on the left) and the number of data blocks in both the left and right branches of the node (i.e., the number on the right). The right partition weight RW represents the weight of the right branch of the node. The right partition weight RW is related to the number of data blocks in the right branch of the node and the number of data blocks in both the left and right branches of the node. Left partition weight LW : Right partition weight RW = Number of data blocks in the left branch of the node LN : Number of data blocks in the right branch of the node RN. In some examples, it can be determined based on... The simplest integer ratio determines LW and RW. Figure 4 , Figure 5 , Figure 6 For example, the root node shown is... Then the LW and RW of the root node can be set to 2 and 1, respectively. In Example 1, if the LN and / or RN of the leaf node are 0, then the LW and RW of the node are set to LN and RN, respectively. In Example 2, the LW and RW of the leaf node are both set to 0, or they can be set to other specific values that indicate that the node is a leaf node; this disclosure does not impose any restrictions on this.
[0110] The left partition counter LC is used for counting. The value of the left partition counter LC is continuously updated based on the usage of data blocks in the left branch of the node. In some embodiments, the initial value and the preset value for ending the count can be set according to the meaning represented by the left partition counter LC. If the current value of the left partition counter LC corresponds to the proportion of unused data blocks remaining in the left branch of the node (i.e., LC / LW = number of unused data blocks on the left side of the node / total number of data blocks on the left side of the node), then the initial value of the left partition counter LC is equal to the left partition weight LW, and the minimum value is 0 (i.e., the preset value is 0). For example, if the initial value of the left partition counter LC of a node is LW, and the current processing state of the node is processing the left node (e.g., set to 0) and the left partition weight LW is greater than 0, then the data flows to the left branch, and the value of the left partition counter LC is decremented by 1; until the value of the left partition counter LC is 0, then it is reset to the left partition weight LW, and the processing state of the node needs to be changed to processing the right node (e.g., set to 1). Alternatively, if the current value of the left partition counter LC corresponds to the proportion of data blocks that have been replaced in the left branch of the node (that is, LC / LW = the number of data blocks that have been replaced in the left branch of the node / the total number of data blocks in the left branch of the node), then the initial value of the left partition counter LC is equal to 0, and the maximum value is the left partition weight LW (that is, the default value is the left partition weight LW).
[0111] The right partition counter RC is used for counting. The value of the right partition counter RC is continuously updated based on the usage of data blocks in the right branch of the node. In some embodiments, the initial value and the preset value for ending the count can be set according to the meaning represented by the right partition counter RC. If the current value of the right partition counter RC corresponds to the proportion of unused data blocks remaining in the right branch of the node (i.e., RC / RW = number of unused data blocks on the right side of the node / total number of data blocks on the right side of the node), then the initial value of the right partition counter RC is equal to the right partition weight RW, and the minimum value is 0 (i.e., the preset value is 0). For example, if the initial value of the right partition counter RC of a node is RW, and the current processing state of the node is processing the right node (e.g., set to 0) and the right partition weight value is greater than 0, data flows to the right branch, and the value of the right partition counter RC is decremented by 1. Until the value of the right partition counter RC is 0, it is reset to the right partition weight RW, and the processing state of the node needs to be changed to processing the right node (e.g., set to 1). Alternatively, if there is a corresponding relationship between the current value of the right partition counter RC and the proportion of data blocks that have been replaced in the right branch of the node (that is, RC / RW = the number of data blocks that have been replaced in the right branch of the node / the total number of data blocks in the right branch of the node), then the initial value of the right partition counter RC is equal to 0 and the maximum value is the right partition weight RW (that is, the default value is the right partition weight RW).
[0112] In Example 2, the node information of the leaf node does not include the left partition counter LC and the right partition counter RC, or the left partition counter LC and the right partition counter RC in the node information of the leaf node are invalid.
[0113] The Left Address Index (LAI) points to the corresponding data block. The Left Valid Index Flag (LVF) indicates whether the LAI is valid (e.g., 1 for valid, 0 for invalid). In Example 1, if the current node's left partition weight (LW) is 0 and the LVF is valid, then the node is a leaf node and its LAI points to a data block corresponding to that leaf node. If the current node's left partition weight (LW) is non-zero and / or the LVF is invalid, then the node is a non-leaf node and its LAI is invalid. In Example 2, if the current node's left partition weight (LW) is 0 and the LVF is valid, then the node is a leaf node and its LAI points to a data block corresponding to that leaf node. If the current node's left partition weight (LW) is non-zero and / or the LVF is invalid, then the node is a non-leaf node and its LAI is invalid.
[0114] The left pointer LP points to the position of the child node to the left of the current node. This is represented by hardwired connections in hardware, such as... Figure 5 The left pointer LP is represented by the arrow pointing to the left node in the diagram. The node information of non-leaf nodes includes the left pointer LP, while the node information of leaf nodes does not include the left pointer LP, or the left pointer LP bit in the node information is invalid.
[0115] The right address index (RAI) points to the corresponding data block. The right valid index flag (RVF) indicates whether the right address index RAI is valid (e.g., 1 for valid, 0 for invalid). In Example 1, if the current node's right partition weight (RW) is 0 and the right valid index flag (RVF) is valid, then the node is a leaf node and its right address index RAI points to a data block corresponding to that leaf node. If the current node's right partition weight (RW) is non-zero and / or the right valid index flag (RVF) is invalid, then the node is a non-leaf node and its right address index RAI is invalid. In Example 2, if the current node's right partition weight (RW) is 0 and the right valid index flag (RVF) is valid, then the node is a leaf node and its right address index RAI points to a data block corresponding to that leaf node. If the current node's right partition weight (RW) is non-zero and / or the right valid index flag (RVF) is invalid, then the node is a non-leaf node and its right address index RAI is invalid. In Example 2, the node information of the leaf node is only "Right Address Index RAI, Right Valid Index Identifier RVF" or "Left Valid Index Identifier LVF, Left Address Index LAI".
[0116] The right pointer RP indicates the position of the child node to the right of the current node. This is represented in hardware using hardwired connections, such as... Figure 5 The right pointer RP is represented by the arrow pointing to the right node in the diagram. The node information of non-leaf nodes includes the right pointer RP, while the node information of leaf nodes does not include the right pointer RP, or the right pointer RP bit in the node information is invalid.
[0117] For example, assuming the management organizational structure is set up according to the method described in "Example 1" above, in a certain example, storage area 2 that needs to be configured is an L1 Data Cache. This L1 Data Cache is allocated into 4 block groups and supports dynamic size configuration, where the size of each data block is 8KB. The different configuration states of the L1 Data Cache are shown in Table 1 below, and the L1 Data Cache has corresponding configuration information under different configuration states.
[0118] Table 1 L1 Data Cache Configuration Status Table
[0119]
[0120] Based on Table 1, the L1 Data Cache has six different configuration states: 32KB, 64KB, 96KB, 128KB, 160KB, and 192KB. These are divided into four block groups, each containing six data block partitions. The number of blocks in each data block partition is 1, 2, 3, 4, 5, and 6, respectively. The "Initialization Configuration Steps" can be used to create configurations for each block group. Figure 7 The diagram shows multiple binary tree structures, each corresponding to a different data block partition.
[0121] For data block partitions with different numbers of blocks, the left partition weight (LW) and right partition weight (RW) of the corresponding binary tree structure nodes can be set differently. For example, as shown in Table 2 below, for the root node of a three-level binary tree with 6 data blocks, the ratio of the number of data blocks in its left and right branches... In this case, the LW and RW of the root node can be set to 4 and 2 respectively, while to simplify the replacement search process, the LW and RW of the root node can be set to 2 and 1 respectively. Similarly, for a binary tree with a two-level structure and four data blocks, the LW and RW of the root node can be set to 2 and 2 respectively, while to simplify the replacement search process, the LW and RW of the root node can be set to 1 and 1 respectively.
[0122] Table 2. Root Node Weight Diagram
[0123]
[0124] In this way, by setting up the above management organization structure (binary tree structure and its node information), during the replacement process, the binary tree structure corresponding to the data block partition makes the replacement probability between each data block the same. Furthermore, by using the PLRU algorithm to perform replacement search for the cache line in each data block, the replacement probability between cache lines in the same data block can be made the same. In this way, the cache lines in each data block partition can have the same replacement probability as a whole.
[0125] In this embodiment, the "replacement step" may include: upon receiving a replacement request, determining the root node in the binary tree structure corresponding to the data block partition as the first target node and obtaining the node information of the target node; if the target node is a non-leaf node, determining the child nodes of the target node in the replacement direction indicated by the current processing state of the target node as the next target node and updating the target counter of the target node corresponding to the replacement direction, until the determined target node is a leaf node. Specifically, if the target node is determined to be a leaf node, the data block to be searched is determined based on the leaf node; the PLRU algorithm is used to find replaceable cache lines in the data block to be searched; and a search result is generated based on the data block ID of the data block to be searched and the cache line ID of the replaceable cache lines. In this way, during the replacement process, first finding the data block to be searched narrows the cache line search range, and then finding replaceable cache lines from the data block to be searched improves the efficiency of cache line replacement and avoids searching line by line.
[0126] Due to differences in management organizational structure, the replacement procedures also differ to some extent. The following is a combination of... Figure 8 The "replacement steps" based on the "management organizational structure provided in Example 1 above" are explained.
[0127] like Figure 8 As shown, the "replacement step" is a step of replacing and searching cached lines based on the "management organizational structure provided in Example 1 above". The "replacement step" may include steps S201-S213.
[0128] like Figure 8 As shown, in step S201, a replacement request is received, and the root node of the binary tree structure corresponding to the data block partition it controls is determined as the first target node.
[0129] like Figure 8 As shown, in step S202, after the target node is determined, the node information of the target node is obtained.
[0130] like Figure 8 As shown, in step S203, after obtaining the node information of the target node, the left or right branch of the target node is determined as the replacement direction according to the indication of the processing state S in the node information of the target node. For example, if "0" represents the left branch and "1" represents the right branch, then when the processing state S is 0, the replacement direction is the left branch of the target node; when the processing state is 1, the replacement direction is the right branch of the target node.
[0131] like Figure 8As shown, in step S204, after determining the replacement direction, the weight corresponding to that replacement direction is determined (i.e., the left partition weight LW or right partition weight RW of the target node). For example, if the replacement direction is the left branch of the target node, the weight corresponding to the replacement direction is the left partition weight LW; if the replacement direction is the right branch of the target node, the weight corresponding to the replacement direction is the right partition weight RW. If the weight corresponding to the replacement direction is 0 and / or the corresponding target counter is invalid, then step S205 continues. If the weight corresponding to the replacement direction is not 0 and the target counter is valid, then step S209 continues. The target counter is the counter in the left partition counter or right partition counter that corresponds to the replacement direction.
[0132] like Figure 8 As shown, in step S205, the valid index identifier corresponding to the replacement direction is determined (i.e., the left valid index identifier LVF or the right valid index identifier RVF of the target node), and it is further determined whether the valid index identifier corresponding to the replacement direction is valid. For example, if the replacement direction is the left branch of the target node, then the valid index identifier corresponding to the replacement direction is the left valid index identifier LVF; if the replacement direction is the right branch of the target node, then the valid index identifier corresponding to the replacement direction is the right valid index identifier RVF. If the valid index identifier corresponding to the replacement direction is valid, then step S207 is executed. If the valid index identifier corresponding to the replacement direction is invalid, then step S206 is executed. Wherein, if... Figure 8 As shown, in step S206, if the valid index identifier corresponding to the replacement direction is invalid, it can be determined that none of the data blocks in the replacement direction of the target node meet the search conditions. The replacement request is discarded, the search is stopped, a replacement failure exception is generated and reported to the exception register so that the exception can be processed in the future.
[0133] like Figure 8 As shown, in step S207, if the valid index identifier corresponding to the replacement direction is valid, the current target node can be determined to be a leaf node. Then, the right address index RAI or left address index LAI of the leaf node corresponding to the replacement direction is determined as the target address index. For example, if the replacement direction is the left branch of the target node, the valid index identifier corresponding to the replacement direction is the left valid index identifier LVF. If the left valid index identifier LVF is valid, the left address index LAI can be determined as the target address index.
[0134] like Figure 8As shown, in step S208, after determining the target address index, the corresponding data block to be searched is further determined based on the target address index, and then the PLRU algorithm is used to find cache lines in the data block to be searched that can be used as replacements. If a cache line that can be used as a replacement can be found, then the cache line is used as a replaceable cache line, and thus a search result is generated.
[0135] like Figure 8 As shown, in step S209, the current value of the target counter (i.e., the left partition counter LC or the right partition counter RC of the target node) corresponding to the replacement direction is determined. If the current value of the target counter is a preset value (e.g., 0), then step S211 is executed. If the current value of the target counter is not a preset value, then step S210 is executed. In some embodiments, the value of the target counter can be updated first, and then it can be determined whether the current value of the target counter is a preset value. If the current value of the target counter is a preset value (e.g., 0), then step S211 is executed; if it is not a preset value, then step S212 is executed. This disclosure does not limit this.
[0136] like Figure 8 As shown, in step S210, the value of the target counter is updated, and then step S212 is executed. Specifically, if the initial value of the target counter (i.e., the left partition counter LC or right partition counter RC of the target node) is the left partition weight LW or right partition weight RW of the target node, and the preset value is 0, then "updating the value of the target counter" can be done by decrementing the value of the target counter by 1. If the initial value of the target counter (i.e., the left partition counter LC or right partition counter RC of the target node) is 0, and the preset value is the left partition weight LW or right partition weight RW of the target node, then "updating the value of the target counter" can be done by incrementing the value of the target counter by 1.
[0137] like Figure 8As shown, in step S211, the value of the target counter is reset, and the processing state S of the target node is changed. Then, step S212 is executed. Wherein, if the initial value of the target counter of the target node is the left partition weight LW or the right partition weight RW of the target node, and the preset value is 0, then "resetting the value of the target counter" can be to reset the value of the target counter to the left partition weight LW or the right partition weight RW. If the initial value of the target counter of the target node is 0, and the preset value is the left partition weight LW or the right partition weight RW of the target node, then "resetting the value of the target counter" can be to reset the value of the target counter to 0. Wherein, "changing the processing state S of the target node" can be: if the processing state S of the target node indicates a left branch replacement direction, then modify the processing state S of the target node to indicate a right branch replacement direction, for example, changing the processing state S from "0" to "1". Alternatively, if the processing status S of the target node indicates that the replacement direction is the right branch, then change the processing status S of the target node to indicate that the replacement direction is the left branch. For example, change the processing status S from "1" to "0".
[0138] like Figure 8 As shown, in step S212, the stored node information of the target node is updated. Updating the stored node information of the target node may include: replacing the value of the target counter from the original value to the current value, updating the processing status S of the target node; or, replacing the value of the target counter from the original value to the current value. This ensures that the stored node information of each node always corresponds to the access status of the data block, and ensures the balance of cache line replacement.
[0139] like Figure 8 As shown, in step S213, a target pointer indicating the next target node is determined. This target pointer can be a pointer corresponding to the replacement direction of the target node, which can be a left pointer LP or a right pointer RP. For example, if the replacement direction is the left branch of the target node, then the target pointer corresponding to the replacement direction is the left pointer LP. Then, step S202 is executed to further determine the storage address of the node information of the next target node based on the target pointer, and then obtain the node information of the next target node based on the storage address.
[0140] The execution order of steps S212 and S213 can be as follows: Figure 8 As shown, step S212 can also be executed after or simultaneously with step S213, and this disclosure does not limit this.
[0141] In this embodiment, if the "replacement step" is a cache line replacement lookup step based on the "management organizational structure provided in Example 2 above", then the "replacement step" based on the "management organizational structure provided in Example 2" and... Figure 8The replacement steps shown differ only in some steps; for simplicity, only the differing steps are explained. Specifically, because leaf nodes and data blocks in the "management organizational structure provided in Example 2" correspond one-to-one, the "replacement steps" based on the "management organizational structure provided in Example 2" are different from... Figure 8 The difference in the replacement steps shown is:
[0142] After step S206, if the target node is determined to be a leaf node, the left address index or right address index stored in the target node is directly determined as the target address index, and then step S208 is executed.
[0143] To illustrate the implementation of the "replacement step" clearly, a simple example is provided below. In this example, the replacement direction indicated by the processing status is left-to-right.
[0144] Assuming the "replacement step" is as follows: Figure 4 The organizational structure shown is based on "the management structure provided in Example 1" or as follows Figure 6 The cache line replacement lookup shown is based on the "management organization structure provided in Example 2". If the left partition weight and right partition weight of the root node are 4 and 2 respectively, and the left partition weight and right partition weight of the left child node of the root node are both 2, then the data block to be searched will be determined in a cyclical order of "data block DB_a, data block DB_b, data block DB_c, data block DB_d, data block DB_e, data block DB_f, data block DB_a..."
[0145] Assuming the "replacement step" is as follows: Figure 4 The organizational structure shown is based on "the management structure provided in Example 1" or as follows Figure 6 The cache line replacement lookup shown is based on the "management organization structure provided in Example 2". If the left partition weight and right partition weight of the root node are 2 and 1 respectively, and the left partition weight and right partition weight of the left child node of the root node are both 1, then the data block to be searched will be determined in a cyclical order of "data block DB_a, data block DB_c, data block DB_e, data block DB_b, data block DB_d, data block DB_f, data block DB_a..."
[0146] like Figure 9 As shown, this disclosure also provides a cache line replacement device for performing a replacement lookup of cache lines in a data block partition. The data block partition includes at least one data block, each data block includes multiple cache lines, and each data block partition has a corresponding management organization structure. The management organization structure includes a binary tree structure corresponding to the data block partition and node information for each node in the binary tree structure. The node information includes: processing status, a left partition counter, and a right partition counter. The device includes:
[0147] The replacement request receiving module 41 is used to determine the root node in the binary tree structure corresponding to the data block partition as the first target node and obtain the node information of the target node when a replacement request is received.
[0148] The data block determination module 42 is used to determine the child node of the target node in the replacement direction indicated by the current processing state of the target node as the next target node and update the target counter of the target node corresponding to the replacement direction when the target node is a non-leaf node, until the determined target node is a leaf node, and then determine the data block to be checked based on the leaf node.
[0149] The cache line replacement module 43 is used to find replaceable cache lines in the data block to be searched using the PLRU algorithm;
[0150] The search result generation module 44 is used to generate search results based on the data block ID of the data block to be searched and the cache line ID of the replaceable cache line;
[0151] The target counter is the left partition counter and the right partition counter of the target node, which are counters corresponding to the replacement direction indicated by the processing state of the target node. The replacement direction indicated by the processing state of each node is the left branch or the right branch of the node.
[0152] In one possible implementation, the data block determination module includes:
[0153] The first determining submodule is used to determine the data block corresponding to the replacement direction indicated by the processing state of the leaf node as the data block to be searched; or
[0154] The second determination submodule is used to determine the data block corresponding to the leaf node as the data block to be queried.
[0155] In one possible implementation, the node information further includes left partition weights and right partition weights, and the device further includes:
[0156] The reset update module is used to reset the target counter to an initial value and change the replacement direction indicated by the processing state of the target node when the value of the target counter is a preset value.
[0157] Wherein, the initial value corresponds to the partition weight of the branch direction where the target counter is located, and the preset value is 0; or, the initial value is 0, and the preset value corresponds to the partition weight of the branch direction where the target counter is located; the partition weight of the branch direction where the left partition counter is located is the left partition weight, and the partition weight of the branch direction where the right partition counter is located is the right partition weight.
[0158] In one possible implementation, the device further includes:
[0159] The leaf node determination module is used to determine the target node as a leaf node when the target counter of the target node is determined to be invalid and / or the partition weight of the target node corresponding to the replacement direction indicated by the processing state is 0.
[0160] Wherein, the partition weight of the target node corresponding to the replacement direction indicated by the processing state is either the left partition weight or the right partition weight.
[0161] In one possible implementation, the node information further includes a left pointer and a right pointer, and the device further includes:
[0162] The target node search module is used to find the next target node according to the target pointer corresponding to the replacement direction indicated by the current processing state of the target node;
[0163] Wherein, if the replacement direction indicated by the current processing state of the target node is the left branch, then the target pointer is the left pointer; if the replacement direction indicated by the current processing state of the target node is the right branch, then the target pointer is the right pointer.
[0164] In one possible implementation, the node information of the leaf node further includes: a right address index and a left address index.
[0165] Specifically, determining the data block corresponding to the replacement direction indicated by the processing state of the leaf node as the data block to be queried includes: determining the data block pointed to by the target address index corresponding to the replacement direction indicated by the processing state of the leaf node as the data block to be queried.
[0166] Wherein, if the replacement direction indicated by the current processing state of the target node is the left branch, then the target address index is the left address index; if the replacement direction indicated by the current processing state of the target node is the right branch, then the target address index is the right address index.
[0167] In one possible implementation, the node information further includes: a left valid index identifier and a right valid index identifier, determining the data block pointed to by the address index corresponding to the replacement direction indicated by the processing state of the leaf node as the data block to be queried, including:
[0168] If the valid index identifier corresponding to the replacement direction indicated by the processing state of the leaf node is valid, the data block pointed to by the address index corresponding to the replacement direction indicated by the processing state of the leaf node is determined as the data block to be queried.
[0169] Wherein, if the replacement direction indicated by the current processing state of the target node is the left branch, then the address index pointing to the data block to be queried is the left valid index identifier; if the replacement direction indicated by the current processing state of the target node is the right branch, then the address index pointing to the data block to be queried is the right valid index identifier.
[0170] In one possible implementation, the node information of the leaf node further includes one of a right address index and a left address index, wherein determining the data block corresponding to the leaf node as the data block to be queried includes: determining the data block pointed to by the address index existing in the node information of the leaf node as the data block to be queried.
[0171] In one possible implementation, the node information of the leaf node further includes one of a left valid index identifier and a right valid index identifier.
[0172] Specifically, determining the data block corresponding to the leaf node as the data block to be queried includes:
[0173] If the left or right valid index identifier in the node information of the leaf node is valid, the data block pointed to by the address index in the node information of the leaf node is determined as the data block to be queried.
[0174] In one possible implementation, the left partition weight and right partition weight of each node are related to the number of data blocks on the left side of the node's left branch and the number of data blocks on the right side of the node's right branch.
[0175] When the number of nodes on the left and right sides of a node is not zero, the values of the left partition weight and the right partition weight of the node are determined according to the simplest integer ratio of the number of nodes on the left and the number of nodes on the right.
[0176] When the number of nodes to the left and / or the number of nodes to the right are zero, the values of the left partition weight and the right partition weight of the node are set to the number of nodes to the left and the number of nodes to the right, respectively.
[0177] In one possible implementation, the device further includes:
[0178] The configuration module is used to respond to a reconstruction request by setting the number of data blocks in the data block partition and the number of cache lines in each data block according to the configuration information, and setting the data block ID and cache line ID of each data block; creating a binary tree structure corresponding to the data block partition according to the number of data blocks in the data block partition, and determining the node information of each node in the binary tree structure, thereby completing the management organization structure configuration of the data block partition.
[0179] In one possible implementation, each of the data blocks includes There are n cache lines, where n is a positive integer.
[0180] In some embodiments, the functions or modules of the apparatus provided in this disclosure can be used to perform the methods described in the above method embodiments. The specific implementation and related beneficial effects can be referred to the description of the above method embodiments, and will not be repeated here for the sake of brevity.
[0181] It should be noted that although the cache line replacement method and apparatus have been described above as examples, those skilled in the art will understand that this disclosure is not limited thereto. In fact, users can flexibly set each step and module according to their personal preferences and / or actual application scenarios, as long as it conforms to the technical solution of this disclosure.
[0182] This disclosure also proposes a computer-readable storage medium storing computer program instructions that, when executed by a processor, implement the above-described method. The computer-readable storage medium can be volatile or non-volatile.
[0183] This disclosure also proposes an electronic device, including: a processor; and a memory for storing processor-executable instructions; wherein the processor is configured to implement the above method when executing the instructions stored in the memory.
[0184] This disclosure also provides a computer program product, including computer-readable code, or a non-volatile computer-readable storage medium carrying computer-readable code, wherein when the computer-readable code is run in a processor of an electronic device, the processor in the electronic device performs the above-described method.
[0185] Figure 10 This is a block diagram illustrating an apparatus 1900 for cache line replacement according to an exemplary embodiment. For example, apparatus 1900 may be provided as a server or terminal device. (Refer to...) Figure 10 The apparatus 1900 includes a processing component 1922, which further includes one or more processors, and memory resources represented by memory 1932 for storing instructions, such as application programs, that can be executed by the processing component 1922. The application programs stored in memory 1932 may include one or more modules, each corresponding to a set of instructions. Furthermore, the processing component 1922 is configured to execute instructions to perform the methods described above.
[0186] Device 1900 may also include a power supply component 1926 configured to perform power management of device 1900, a wired or wireless network interface 1950 configured to connect device 1900 to a network, and an input / output interface 1958 (I / O interface). Device 1900 can operate on an operating system, such as Windows Server, stored in memory 1932. TM macOS X TM Unix TM Linux TM FreeBSD TM Or similar.
[0187] In an exemplary embodiment, a non-volatile computer-readable storage medium is also provided, such as a memory 1932 including computer program instructions that can be executed by a processing component 1922 of the device 1900 to perform the above-described method.
[0188] This disclosure can be a system, method, and / or computer program product. A computer program product may include a computer-readable storage medium having computer-readable program instructions loaded thereon for causing a processor to implement various aspects of this disclosure.
[0189] Computer-readable storage media can be tangible devices capable of holding and storing instructions for use by an instruction execution device. Computer-readable storage media can be, for example—but not limited to—electrical storage devices, magnetic storage devices, optical storage devices, electromagnetic storage devices, semiconductor storage devices, or any suitable combination of the foregoing. More specific examples (a non-exhaustive list) of computer-readable storage media include: portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), static random access memory (SRAM), portable compact disc read-only memory (CD-ROM), digital multifunction disc (DVD), memory sticks, floppy disks, mechanical encoding devices, such as punch cards or recessed protrusions storing instructions thereon, and any suitable combination of the foregoing. The computer-readable storage media used herein are not to be construed as transient signals themselves, such as radio waves or other freely propagating electromagnetic waves, electromagnetic waves propagating through waveguides or other transmission media (e.g., light pulses through fiber optic cables), or electrical signals transmitted through wires.
[0190] The computer-readable program instructions described herein can be downloaded from computer-readable storage media to various computing / processing devices, or downloaded via a network, such as the Internet, local area network, wide area network, and / or wireless network, to an external computer or external storage device. The network may include copper transmission cables, fiber optic transmission, wireless transmission, routers, firewalls, switches, gateway computers, and / or edge servers. A network adapter card or network interface in each computing / processing device receives the computer-readable program instructions from the network and forwards them to the computer-readable storage media in the respective computing / processing device.
[0191] Computer program instructions used to perform the operations of this disclosure may be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-dependent instructions, microcode, firmware instructions, status setting data, or source code or object code written in any combination of one or more programming languages, including object-oriented programming languages such as Smalltalk, C++, etc., and conventional procedural programming languages such as the "C" language or similar programming languages. The computer-readable program instructions may execute entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer via any type of network—including a local area network (LAN) or a wide area network (WAN)—or may be connected to an external computer (e.g., via the Internet using an Internet service provider). In some embodiments, electronic circuitry, such as programmable logic circuitry, field-programmable gate arrays (FPGAs), or programmable logic arrays (PLAs), is personalized by utilizing the status information of the computer-readable program instructions to implement various aspects of this disclosure.
[0192] Various aspects of this disclosure are described herein with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this disclosure. It should be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer-readable program instructions.
[0193] These computer-readable program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing apparatus to produce a machine such that, when executed by the processor of the computer or other programmable data processing apparatus, they create means for implementing the functions / actions specified in one or more blocks of the flowchart and / or block diagram. These computer-readable program instructions can also be stored in a computer-readable storage medium that causes a computer, programmable data processing apparatus, and / or other device to operate in a particular manner; thus, the computer-readable medium storing the instructions comprises an article of manufacture that includes instructions for implementing aspects of the functions / actions specified in one or more blocks of the flowchart and / or block diagram.
[0194] Computer-readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other device to cause a series of operational steps to be performed on the computer, other programmable data processing apparatus, or other device to produce a computer-implemented process, thereby causing the instructions executed on the computer, other programmable data processing apparatus, or other device to perform the functions / actions specified in one or more boxes of a flowchart and / or block diagram.
[0195] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of the present disclosure. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of an instruction containing one or more executable instructions for implementing a specified logical function. In some alternative implementations, the functions marked in the blocks may occur in a different order than those shown in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, may be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.
[0196] The various embodiments of this disclosure have been described above. These descriptions are exemplary and not exhaustive, nor are they limited to the disclosed embodiments. Many modifications and variations will be apparent to those skilled in the art without departing from the scope and spirit of the described embodiments. The terminology used herein is chosen to best explain the principles, practical application, or technical improvements to the embodiments in the market, or to enable others skilled in the art to understand the embodiments disclosed herein.
Claims
1. A cache line replacement method, characterized in that, This is used to perform a replacement lookup of cached lines in a data block partition, wherein the data block partition includes at least one data block, and each data block includes... There are n cache lines, where n is a positive integer; each data block partition has a corresponding management organization structure, which includes a binary tree structure corresponding to the data block partition and node information of each node in the binary tree structure. The node information includes processing status, left partition counter, and right partition counter. The method includes: Upon receiving a replacement request, the root node in the binary tree structure corresponding to the data block partition is determined as the first target node, and the node information of the target node is obtained. If the target node is a non-leaf node, the child node of the target node in the replacement direction indicated by the current processing state of the target node is determined as the next target node and the target counter of the target node corresponding to the replacement direction is updated until the determined target node is a leaf node. Then, the data block to be queried is determined based on the leaf node. The PLRU algorithm is used to find replaceable cache lines in the data block to be searched; The search results are generated based on the data block ID of the data block to be searched and the cache line ID of the replaceable cache line; Wherein, the target counter is the left partition counter and the right partition counter of the target node that corresponds to the replacement direction indicated by the processing state of the target node, and the replacement direction indicated by the processing state of each node is the left branch or the right branch of the node. The process of determining the data block to be checked based on the leaf node includes: when the number of data blocks corresponding to the leaf node in the binary tree structure is determined to be 2, the data block corresponding to the replacement direction indicated by the processing state of the leaf node is determined as the data block to be checked. Wherein, if the node information of the leaf node also includes a right address index and a left address index, determining the data block corresponding to the replacement direction indicated by the processing state of the leaf node as the data block to be queried includes: determining the data block pointed to by the target address index corresponding to the replacement direction indicated by the processing state of the leaf node as the data block to be queried; wherein, if the replacement direction indicated by the current processing state of the target node is a left branch, then the target address index is the left address index; if the replacement direction indicated by the current processing state of the target node is a right branch, then the target address index is the right address index; The method further includes: In response to the reconstruction request, the number of data blocks in the data block partition and the number of cache lines in each data block are set according to the configuration information, and the data block ID and cache line ID of each data block are set. Based on the number of data blocks in the data block partition, a binary tree structure corresponding to the data block partition is created, and the node information of each node in the binary tree structure is determined to complete the management organization structure configuration of the data block partition.
2. The method according to claim 1, characterized in that, The node information also includes left partition weights and right partition weights, and the method further includes: If the value of the target counter is a preset value, reset the target counter to the initial value and change the replacement direction indicated by the processing state of the target node; Wherein, the initial value corresponds to the partition weight of the branch direction where the target counter is located, and the preset value is 0; or, the initial value is 0, and the preset value corresponds to the partition weight of the branch direction where the target counter is located; the partition weight of the branch direction where the left partition counter is located is the left partition weight, and the partition weight of the branch direction where the right partition counter is located is the right partition weight.
3. The method according to claim 2, characterized in that, The method further includes: If the target counter of the target node is determined to be invalid and / or the partition weight of the target node corresponding to the replacement direction indicated by the processing state is 0, the target node is determined to be a leaf node; Wherein, the partition weight of the target node corresponding to the replacement direction indicated by the processing state is either the left partition weight or the right partition weight.
4. The method according to claim 1, characterized in that, The node information also includes a left pointer and a right pointer, and the method further includes: The next target node is found based on the target pointer corresponding to the replacement direction indicated by the current processing status of the target node; Wherein, if the replacement direction indicated by the current processing state of the target node is the left branch, then the target pointer is the left pointer; if the replacement direction indicated by the current processing state of the target node is the right branch, then the target pointer is the right pointer.
5. The method according to claim 1, characterized in that, The node information also includes: a left valid index identifier and a right valid index identifier, determining the data block pointed to by the address index corresponding to the replacement direction indicated by the processing status of the leaf node as the data block to be queried, including: If the valid index identifier corresponding to the replacement direction indicated by the processing state of the leaf node is valid, the data block pointed to by the address index corresponding to the replacement direction indicated by the processing state of the leaf node is determined as the data block to be queried. Wherein, if the replacement direction indicated by the current processing state of the target node is the left branch, then the address index pointing to the data block to be queried is the left valid index identifier; if the replacement direction indicated by the current processing state of the target node is the right branch, then the address index pointing to the data block to be queried is the right valid index identifier.
6. The method according to claim 1, characterized in that, The method of determining the data block to be queried based on the leaf node further includes: when it is determined that the number of data blocks corresponding to the leaf node in the binary tree structure is 1, the data block corresponding to the leaf node is determined as the data block to be queried. If the node information of the leaf node also includes one of the right address index and the left address index, then determining the data block corresponding to the leaf node as the data block to be queried includes: determining the data block pointed to by the address index existing in the node information of the leaf node as the data block to be queried.
7. The method according to claim 6, characterized in that, The node information of the leaf node also includes one of the left valid index identifier and the right valid index identifier. Specifically, determining the data block corresponding to the leaf node as the data block to be queried includes: If the left valid index identifier or the right valid index identifier in the node information of the leaf node is valid, the data block pointed to by the address index in the node information of the leaf node is determined as the data block to be queried.
8. The method according to claim 2, characterized in that, The left partition weight and right partition weight of each node are related to the number of data blocks on the left side of the node's left branch and the number of data blocks on the right side of the node's right branch. When the number of nodes on the left and right sides of a node is not zero, the values of the left partition weight and the right partition weight of the node are determined according to the simplest integer ratio of the number of nodes on the left and the number of nodes on the right. When the number of nodes to the left and / or the number of nodes to the right are zero, the values of the left partition weight and the right partition weight of the node are set to the number of nodes to the left and the number of nodes to the right, respectively.
9. A cache line replacement device, characterized in that, This is used to perform a replacement lookup of cached lines in a data block partition, wherein the data block partition includes at least one data block, and each data block includes... There are 1 cache line, where n is a positive integer; each data block partition has a corresponding management organization structure, which includes a binary tree structure corresponding to the data block partition and node information of each node in the binary tree structure. The node information includes: processing status, left partition counter, and right partition counter. The device includes: The replacement request receiving module is used to determine the root node in the binary tree structure corresponding to the data block partition as the first target node and obtain the node information of the target node when a replacement request is received. The data block to be checked module is used to determine the child node of the target node in the replacement direction indicated by the current processing state of the target node as the next target node and update the target counter of the target node corresponding to the replacement direction, when the target node is a non-leaf node, until the determined target node is a leaf node, and then determine the data block to be checked based on the leaf node. The cache line replacement module is used to find replaceable cache lines in the data block to be searched using the PLRU algorithm. The search result generation module is used to generate search results based on the data block ID of the data block to be searched and the cache line ID of the replaceable cache line; Wherein, the target counter is the left partition counter and the right partition counter of the target node that corresponds to the replacement direction indicated by the processing state of the target node, and the replacement direction indicated by the processing state of each node is the left branch or the right branch of the node. The data block determination module includes: a first determination submodule, used to determine the data block corresponding to the replacement direction indicated by the processing state of the leaf node as the data block to be checked when the number of data blocks corresponding to the leaf nodes in the binary tree structure is determined to be 2. Wherein, if the node information of the leaf node also includes a right address index and a left address index, determining the data block corresponding to the replacement direction indicated by the processing state of the leaf node as the data block to be queried includes: determining the data block pointed to by the target address index corresponding to the replacement direction indicated by the processing state of the leaf node as the data block to be queried; wherein, if the replacement direction indicated by the current processing state of the target node is a left branch, then the target address index is the left address index; if the replacement direction indicated by the current processing state of the target node is a right branch, then the target address index is the right address index; The device further includes: The configuration module is used to respond to a reconstruction request by setting the number of data blocks in the data block partition and the number of cache lines in each data block according to the configuration information, and setting the data block ID and cache line ID of each data block; based on the number of data blocks in the data block partition, creating a binary tree structure corresponding to the data block partition, and determining the node information of each node in the binary tree structure, thereby completing the management organization structure configuration of the data block partition.
10. The apparatus according to claim 9, characterized in that, The node information also includes left partition weight and right partition weight, and the device further includes: The reset update module is used to reset the target counter to an initial value and change the replacement direction indicated by the processing state of the target node when the value of the target counter is a preset value. Wherein, the initial value corresponds to the partition weight of the branch direction where the target counter is located, and the preset value is 0; or, the initial value is 0, and the preset value corresponds to the partition weight of the branch direction where the target counter is located; the partition weight of the branch direction where the left partition counter is located is the left partition weight, and the partition weight of the branch direction where the right partition counter is located is the right partition weight.
11. The apparatus according to claim 10, characterized in that, The device further includes: The leaf node determination module is used to determine the target node as a leaf node when the target counter of the target node is determined to be invalid and / or the partition weight of the target node corresponding to the replacement direction indicated by the processing state is 0. Wherein, the partition weight of the target node corresponding to the replacement direction indicated by the processing state is either the left partition weight or the right partition weight.
12. The apparatus according to claim 9, characterized in that, The node information also includes a left pointer and a right pointer, and the device further includes: The target node search module is used to find the next target node according to the target pointer corresponding to the replacement direction indicated by the current processing state of the target node; Wherein, if the replacement direction indicated by the current processing state of the target node is the left branch, then the target pointer is the left pointer; if the replacement direction indicated by the current processing state of the target node is the right branch, then the target pointer is the right pointer.
13. The apparatus according to claim 9, characterized in that, The node information also includes: a left valid index identifier and a right valid index identifier, determining the data block pointed to by the address index corresponding to the replacement direction indicated by the processing status of the leaf node as the data block to be queried, including: If the valid index identifier corresponding to the replacement direction indicated by the processing state of the leaf node is valid, the data block pointed to by the address index corresponding to the replacement direction indicated by the processing state of the leaf node is determined as the data block to be queried. Wherein, if the replacement direction indicated by the current processing state of the target node is the left branch, then the address index pointing to the data block to be queried is the left valid index identifier; if the replacement direction indicated by the current processing state of the target node is the right branch, then the address index pointing to the data block to be queried is the right valid index identifier.
14. The apparatus according to claim 9, characterized in that, The data block determination module further includes: a second determination submodule, used to determine the data block corresponding to the leaf node as the data block to be checked when the number of data blocks corresponding to the leaf nodes in the binary tree structure is determined to be 1. If the node information of the leaf node also includes one of the right address index and the left address index, then determining the data block corresponding to the leaf node as the data block to be queried includes: determining the data block pointed to by the address index existing in the node information of the leaf node as the data block to be queried.
15. The apparatus according to claim 14, characterized in that, The node information of the leaf node also includes one of the left valid index identifier and the right valid index identifier. Specifically, determining the data block corresponding to the leaf node as the data block to be queried includes: If the left valid index identifier or the right valid index identifier in the node information of the leaf node is valid, the data block pointed to by the address index in the node information of the leaf node is determined as the data block to be queried.
16. The apparatus according to claim 10, characterized in that, The left partition weight and right partition weight of each node are related to the number of data blocks on the left side of the node's left branch and the number of data blocks on the right side of the node's right branch. When the number of nodes on the left and right sides of a node is not zero, the values of the left partition weight and the right partition weight of the node are determined according to the simplest integer ratio of the number of nodes on the left and the number of nodes on the right. When the number of nodes to the left and / or the number of nodes to the right are zero, the values of the left partition weight and the right partition weight of the node are set to the number of nodes to the left and the number of nodes to the right, respectively.
17. A cache line replacement device, characterized in that, include: processor; Memory used to store processor-executable instructions; The processor is configured to implement the method of any one of claims 1 to 8 when executing instructions stored in the memory.
18. A non-volatile computer-readable storage medium storing computer program instructions thereon, characterized in that, When the computer program instructions are executed by the processor, they implement the method described in any one of claims 1 to 8.
Citation Information
Patent Citations
Cache replacement method and device
CN112363958A