| CPC G06F 12/0802 (2013.01) [G06F 2212/60 (2013.01)] | 6 Claims |

|
1. A method for selecting and replacing a cache line to be replaced, the method being applied to a blocking cache system, the blocking cache system comprising a plurality of cache lines and storing information of states of a usage state binary tree and a blocking state binary tree, the method comprising:
step (1): checking a state of a root node of a usage state binary tree corresponding to the blocking cache system, wherein the usage state binary tree comprises a plurality of nodes, the plurality of nodes forming a plurality of ways in a form of a binary tree, each of the ways corresponding to one cache line of the blocking cache system, and a state of each node of the usage state binary tree is determined according to a replaceable state of a corresponding cache line of the blocking cache system; the blocking state binary tree comprises a plurality of nodes, and the nodes of the blocking state binary tree are mapped in one-to-one correspondence with the nodes of the usage state binary tree, the plurality of nodes of the blocking state binary tree forming a plurality of second ways in a form of a binary tree, each of the second ways corresponds to one cache line of the blocking cache system, and states of the nodes of each of the ways are determined based on the states of the corresponding nodes of the usage state binary tree and the replaceable state of the corresponding cache line;
step (2): taking the root node of the usage state binary tree as a current parent node of the usage state binary tree on a condition that the state of the root node of the usage state binary tree is a first state,
step (3): determining a new current parent node of the usage state binary tree by using the usage state binary tree and the blocking state binary tree, wherein a second method for determining the new current parent node of the usage state binary tree is selected from the following:
taking a left child node of the current parent node of the usage state binary tree as a new current parent node of the usage state binary tree on a condition that a state of the left child node and a right child node of the current parent node of the usage state binary tree is a first substate,
taking the right child node of the current parent node of the usage state binary tree as the new current parent node of the usage state binary tree on a condition that the state of the left and right child nodes of the current parent node of the usage state binary tree is a second substate, and
mapping the current parent node of the usage state binary tree to a corresponding current parent node of a blocking state binary tree corresponding to the blocking cache system on a condition that the state of the left and right child nodes of the current parent node of the usage state binary tree is a third substate, taking a left child node of the current parent node of the blocking state binary tree as a new current parent node of the blocking state binary tree on a condition that a state of the current parent node of the blocking state binary tree is a third state, taking a right child node of the current parent node of the blocking state binary tree as the new current parent node of the blocking state binary tree on a condition that the state of the current parent node of the blocking state binary tree is a fourth state, and mapping the new current parent node of the blocking state binary tree back to the corresponding current parent node of the usage state binary tree, wherein the current parent node of the usage state binary tree corresponding to the new current parent node of the blocking state binary tree is taken as the new current parent node of the usage state binary tree;
repeating the step (3) until there is no child node in the current parent node of the usage state binary tree, and selecting the cache line corresponding to the way that corresponds to the current parent node of the usage state binary tree as the cache line to be replaced in the blocking cache system;
step (4): updating states of the nodes of the usage state binary tree which forms the way corresponding to the selected cache line to be replaced stored in the blocking cache system and updating states of the nodes of the blocking state binary tree corresponding to the selected cache line to be replaced stored in the blocking cache system after the cache line to be replaced in the blocking cache system is selected; and
step (5): determining that a request entering the blocking cache system finds no match in cached data and is sent to the memory, and in response, replacing the cache line to be replaced determined by using the usage state binary tree and the blocking state binary tree with data returned from memory.
|