The present disclosure relates to the communications field, and in particular, to a cache management method and apparatus.
In a development process of computer technologies, an access speed of a main memory is always much slower than a processing speed of a central processing unit (CPU), resulting in that a high speed processing capability of the CPU cannot be fully used, and working efficiency of an entire computer system is affected. To alleviate a conflict that the speed of the CPU does not match that of the main memory, a relatively commonly used method is to use a cache in a memory hierarchy for temporary memory. For example, the cache may be integrated in the CPU such that the CPU obtains data relatively quickly.
At present, a caching mechanism of the cache includes, receiving an access request, allocating a cache line to the access request, reading, from a memory according to an address (where data corresponding to the address is data to be accessed) in the access request based on the principle of spatial locality, the data to be accessed and data of an address adjacent to an address of the data to be accessed, and writing, to the cache line that is allocated to the access request, both the data to be accessed and the data of the address adjacent to the address of the data to be accessed. The data is directly read from the cache line if data that needs to be accessed according to a next access request is already cached in the cache line, or a cache line is allocated to the next access request according to the foregoing caching mechanism, and the data is read from the memory if data that needs to be accessed according to the next access request is not cached in the cache line.
When temporary memory is performed by means of the foregoing method, the following problems exist: enough data of adjacent addresses cannot be cached in a cache line when spatial locality of data to be accessed is relatively high, resulting in that a cache line still needs to be reallocated and data still needs to be read from a memory when a subsequent access request is received. On one hand, a data read speed is affected. On the other hand, in a case in which there are limited cache lines, data in a cache line is frequently replaced, and a service life of the cache line is affected. Data cached in a cache line is probably not to be accessed according to a subsequent access request when spatial locality of data to be accessed is relatively low, causing a waste of a cache line resource, and a waste of memory bandwidth between a memory and a cache.
Embodiments of the present disclosure provide a cache management method and apparatus, which can resolve a problem of how to improve cache resource utilization.
To achieve the foregoing objective, the following technical solutions are used in the embodiments of the present disclosure.
According to a first aspect, an embodiment of the present disclosure provides a cache management method, where multiple cache subunits are disposed in a cache, and each of the cache subunits includes multiple cache lines. A length of the cache line included in each cache subunit is different from a length of a cache line included in another cache subunit. Each of the cache subunit is configured to store data at a corresponding level, the level is a strength level of spatial locality of the data, and a correspondence between the cache subunit and the level includes that the length of the cache line included in the cache subunit is in a positive correlation with strength of spatial locality of the data, and the method includes receiving an access request, determining data that is to be accessed and that needs to be accessed according to the access request, determining a strength level of spatial locality of the data to be accessed, and allocating, according to the strength level of the spatial locality of the data to be accessed, a cache subunit corresponding to the level to the data to be accessed.
With reference to the first aspect, in a first possible implementation manner, determining a strength level of spatial locality of the data to be accessed includes recording addresses of data that is to be accessed and that need to be accessed according to access requests, collecting statistics about access rules of the addresses of the data to be accessed, where the access rules includes a quantity of times or a probability that data of an address adjacent to the addresses is accessed according to another access request, and classifying, into levels according to the quantity of times or the probability that data of the address adjacent to the addresses of the data to be accessed is accessed by another access request, spatial locality of the data to be accessed.
With reference to the first possible implementation manner of the first aspect, in a second possible implementation manner, the method further includes collecting, within a preset time period, statistics about strength levels of spatial locality of data to be accessed, and calculating a first ratio, where the first ratio is used to represent a proportional relationship between or among the data to be accessed having different levels of spatial locality, calculating a second ratio, where the second ratio is used to represent a proportional relationship between or among the cache subunits in the cache that include cache lines having different lengths, and adjusting a quantity of the cache lines in the cache subunit until the difference between the second ratio and the first ratio falls within a range of the preset threshold after the adjustment when a difference between the first ratio and the second ratio is greater than a preset threshold.
With reference to the first aspect, or the first possible implementation manner of the first aspect, or the second possible implementation manner of the first aspect, in a third possible implementation manner, after receiving an access request, and determining the data that is to be accessed and that needs to be accessed according to the access request, the method further includes determining, according to the strength level of the spatial locality of the data to be accessed, a size of data to be temporarily stored, adjusting the length of the cache line in the cache subunit according to the size of the data to be temporarily stored, allocating an adjusted cache line to the data to be temporarily stored, where a length of the adjusted cache line matches the size of the data to be temporarily stored, and establishing and maintaining an index bitmap based on a change in the length of the cache line in the cache subunit, where the index bitmap is used to indicate a tag domain and a data domain that are in the cache line.
With reference to the first aspect, in a fourth possible implementation manner, that the multiple cache subunits are disposed in the cache includes dividing the cache by ways and/or by sets, to determine the multiple cache subunits, and setting the length of the cache line in each cache subunit.
With reference to the third possible implementation manner of the first aspect, in a fifth possible implementation manner, the access request includes a physical address, the physical address is used to identify the data to be accessed, and the physical address includes a tag domain and a set domain that are of the data to be accessed, and the method further includes sending the access request to each of the cache subunits, determining one or more cache lines that correspond to the set domain of the data to be accessed and that are in each of the cache subunits, comparing tag domains of the one or more cache lines with the tag domain of the data to be accessed, and determining a cache line, which has a same tag domain as the data to be accessed, in the one or more cache lines as a cache line in which the data to be accessed is stored.
With reference to the third possible implementation manner of the first aspect, in a sixth possible implementation manner, the access request includes a physical address, the physical address is used to identify the data to be accessed, and the physical address includes a tag domain and a set domain that are of the data to be accessed, and the method further includes maintaining a list for each cache subunit, where the list is used to record a characteristic value of data stored in each cache subunit, determining a characteristic value of the data that is to be accessed and that needs to be accessed according to the access request when the access request is received, determining a cache subunit, which corresponds to a list in which the characteristic value of the data to be accessed is recorded, as a target cache subunit, sending the access request to the target cache subunit, determining one or more cache lines in the target cache subunit that correspond to the set domain of the data to be accessed, comparing tag domains of the one or more cache lines with the tag domain of the data to be accessed, determining a cache line, which has a same tag domain as the data to be accessed, in the one or more cache lines as a cache line in which the data to be accessed is stored.
According to a second aspect, an embodiment of the present disclosure further provides a cache management apparatus, where the apparatus is configured to manage a cache in which multiple cache subunits are disposed, and each of the cache subunits in the cache includes multiple cache lines. A length of the cache line included in each cache subunit is different from a length of a cache line included in another cache subunit. Each of the cache subunits is configured to store data at a corresponding level, the level is a strength level of spatial locality of the data, and a correspondence between the cache subunit and the level includes that the length of the cache line included in the cache subunit is in a positive correlation with strength of spatial locality of the data, and the apparatus includes a receiving unit configured to receive an access request, a first determining unit configured to determine data that is to be accessed and that needs to be accessed according to the access request, a judging unit configured to determine a strength level of spatial locality of the data to be accessed, and an allocation unit configured to allocate, according to the strength level of the spatial locality of the data to be accessed, a cache subunit corresponding to the level to the data to be accessed.
With reference to the second aspect, in a first possible implementation manner, the judging unit includes a statistics collection module configured to record addresses of data that are to be accessed and that need to be accessed according to access requests, and collect statistics about access rules of the addresses of the data to be accessed, where the access rules include a quantity of times or a probability that data of an address adjacent to the addresses is accessed according to another access request, and a classification module configured to classify, into levels according to the quantity of times or the probability that data of the address adjacent to the addresses of the data to be accessed is accessed by another access request, spatial locality of the data to be accessed.
With reference to the first possible implementation manner of the second aspect, in a second possible implementation manner, the apparatus further includes a calculation unit configured to collect, within a preset time period, statistics about strength levels of spatial locality of data to be accessed, and calculate a first ratio, where the first ratio is used to represent a proportional relationship between or among the data to be accessed having different levels of spatial locality, and the calculation unit is further configured to calculate a second ratio, where the second ratio is used to represent a proportional relationship between or among the cache subunits in the cache that include cache lines having different lengths, and a first adjustment unit configured to adjust a quantity of the cache lines in the cache subunit until the difference between the second ratio and the first ratio falls within a range of the preset threshold after the adjustment when a difference between the first ratio and the second ratio that are obtained through calculation by the calculation unit is greater than a preset threshold.
With reference to the second aspect, or the first possible implementation manner of the second aspect, or the second possible implementation manner of the second aspect, in a third possible implementation manner, the apparatus further includes a second determining unit configured to determine, according to the strength level, which is obtained by the judging unit, of the spatial locality of the data to be accessed, a size of data to be temporarily stored, a second adjustment unit configured to adjust the length of the cache line in the cache subunit according to the size, which is determined by the second determining unit, of the data to be temporarily stored, and allocate an adjusted cache line to the data to be temporarily stored, where a length of the adjusted cache line matches the size of the data to be temporarily stored, and an index bitmap processing unit configured to establish and maintain an index bitmap based on a change in the length of the cache line in the cache subunit, where the index bitmap is used to indicate a tag domain and a data domain that are in the cache line.
With reference to the second aspect, in a fourth possible implementation manner, the apparatus further includes a division unit configured to divide the cache by ways and/or by sets, to determine the multiple cache subunits, and set the length of the cache line in each cache subunit.
With reference to the third possible implementation manner of the second aspect, in a fifth possible implementation manner, the access request received by the receiving unit includes a physical address, the physical address is used to identify the data to be accessed, and the physical address includes a tag domain and a set domain that are of the data to be accessed, and the apparatus further includes a sending unit configured to send the access request to each of the cache subunits, and a first search unit configured to determine one or more cache lines that correspond to the set domain of the data to be accessed and that are in each of the cache subunits, compare tag domains of the one or more cache lines with the tag domain of the data to be accessed, and determine a cache line, which has a same tag domain as the data to be accessed, in the one or more cache lines as a cache line in which the data to be accessed is stored.
With reference to the third possible implementation manner of the second aspect, in a sixth possible implementation manner, the access request received by the receiving unit includes a physical address, the physical address is used to identify the data to be accessed, and the physical address includes a tag domain and a set domain that are of the data to be accessed, and the apparatus further includes a list maintenance unit configured to maintain a list for each cache subunit, where the list is used to record a characteristic value of data stored in each cache subunit, a third determining unit configured to determine a characteristic value of the data that is to be accessed and that needs to be accessed according to the access request when the access request is received, a fourth determining unit configured to traverse each list maintained by the list maintenance unit, and determine a cache subunit, which corresponds to a list in which the characteristic value of the data to be accessed is recorded, as a target cache subunit, and a second search unit configured to send the access request to the target cache subunit, determine one or more cache lines in the target cache subunit that correspond to the set domain of the data to be accessed, compare tag domains of the one or more cache lines with the tag domain of the data to be accessed, and determine a cache line, which has a same tag domain as the data to be accessed, in the one or more cache lines as a cache line in which the data to be accessed is stored.
By means of the cache management method and apparatus that are provided in the embodiments, on one hand, a cache line having a relatively large length is allocated to the data to be accessed when spatial locality of data to be accessed is relatively strong. Because a probability that data of an address adjacent to the data to be accessed is accessed is relatively high when the spatial locality of the data to be accessed is relatively strong, and because the cache line allocated to the data to be accessed has a relatively large length, more data of addresses adjacent to the data to be accessed may be cached in the allocated cache line such that in a process of writing the data from a memory to a cache, a quantity of times of read and write in the cache line can be reduced, a delay for accessing the data to be cached can be reduced, and transmission bandwidth between the memory and the cache can be reduced. On the other hand, a cache line having a relatively small length is allocated to the data to be accessed when spatial locality of data to be accessed is relatively weak. Because a probability that data of an address adjacent to the data to be accessed is accessed is relatively low when the spatial locality of the data to be accessed is relatively weak, and because the cache line allocated to the data to be accessed has a relatively small length, data of only a small quantity of addresses adjacent to the data to be accessed is cached in the allocated cache line such that invalid data in the cache line is reduced, and utilization of the cache line is improved.
To describe the technical solutions in the embodiments of the present disclosure or in the prior art more clearly, the following briefly describes the accompanying drawings required for describing the embodiments or the prior art. The accompanying drawings in the following description show merely some embodiments of the present disclosure, and a person of ordinary skill in the art may still derive other drawings from these accompanying drawings without creative efforts.
The following clearly describes the technical solutions in the embodiments of the present disclosure with reference to the accompanying drawings in the embodiments of the present disclosure. The described embodiments are merely some but not all of the embodiments of the present disclosure. All other embodiments obtained by a person of ordinary skill in the art based on the embodiments of the present disclosure shall fall within the protection scope of the present disclosure.
This embodiment provides a cache management method. In this embodiment, multiple cache subunits are disposed in a cache, and each of the cache subunits includes multiple cache lines. A length of the cache line included in each cache subunit is different from a length of a cache line included in another cache subunit. Each of the cache subunits is configured to store data at a corresponding level, the level is a strength level of spatial locality of the data, and a correspondence between the cache subunit and the level includes that the length of the cache line included in the cache subunit is in a positive correlation with strength of spatial locality of the data.
For ease of understanding, this embodiment provides a schematic diagram of an organization manner of cache lines in a cache that have different lengths for reference. As shown in
It should be emphasized that the cache subunits shown in
As shown in
Step 301: Receive an access request, and determine data that is to be accessed and that needs to be accessed according to the access request.
The access request carries a physical address of the data to be accessed, and addressing may be performed in a memory according to the physical address, to determine the data that is to be accessed and that needs to be accessed according to the access request.
Step 302: Determine a strength level of spatial locality of the data to be accessed.
Stronger spatial locality of the data to be accessed indicates a higher probability that data of an address adjacent to the data to be accessed is accessed. Lower spatial locality of the data to be accessed indicates a lower probability that the data of the address adjacent to the data to be accessed is accessed.
Step 303: Allocate, according to the strength level of the spatial locality of the data to be accessed, a cache subunit corresponding to the level to the data to be accessed.
Furthermore, by means of step 303, a cache line having a large length is allocated to data to be accessed that has strong spatial locality, and a cache line having a small length is allocated to data to be accessed that has low spatial locality.
For example, the multiple cache subunits include at least a first cache subunit and a second cache subunit, where a length of a cache line in the first cache subunit is greater than a length of a cache line in the second cache subunit. The access request received by the cache includes at least a first access request and a second access request, where first data to be accessed needs to be accessed according to the first access request, second data to be accessed needs to be accessed according to the second access request, and spatial locality of the first data to be accessed is higher than spatial locality of the second access request. According to step 303, the cache allocates an idle cache line in the first cache subunit to the first access request, and allocates an idle cache line in the second cache subunit to the second access request.
It should be noted that the method provided in this embodiment may be implemented by a function module, where the function module may be integrated in the cache, or the method provided in this embodiment may be implemented by an independent component disposed in a terminal device, but the present disclosure is not limited thereto.
By means of the cache management method provided in this embodiment, on one hand, a cache line having a relatively large length is allocated to the data to be accessed when spatial locality of data to be accessed is relatively strong. Because a probability that data of an address adjacent to the data to be accessed is relatively high when the spatial locality of the data to be accessed is relatively strong, and because the cache line allocated to the data to be accessed has a relatively large length, more data of addresses adjacent to the data to be accessed may be cached in the allocated cache line such that in a process of writing the data from a memory to a cache, a quantity of times of read and write in the cache line can be reduced, a delay for accessing the data to be cached can be reduced, and transmission bandwidth between the memory and the cache can be reduced. On the other hand, a cache line having a relatively small length is allocated to the data to be accessed when spatial locality of data to be accessed is relatively weak. Because a probability that data of an address adjacent to the data to be accessed is relatively low when the spatial locality of the data to be accessed is relatively weak, and because the cache line allocated to the data to be accessed has a relatively small length, data of only a small quantity of addresses adjacent to the data to be accessed is cached in the allocated cache line such that invalid data in the cache line is reduced, and utilization of the cache line is improved.
Based on the embodiment shown in
Step 401: Dispose multiple cache subunits in a cache, where each cache subunit includes multiple cache lines, and a length of the cache line included in each cache subunit is different from a length of a cache line included in another cache subunit.
The cache may be divided by ways, to determine the multiple cache subunits, and the length of the cache line in each cache subunit is set, and/or the cache is divided by sets, to determine the multiple cache subunits, and the length of the cache line in each cache subunit is set.
Step 402: The cache receives an access request, and determines data that is to be accessed and that needs to be accessed according to the access request.
It should be noted that the method provided in this embodiment may be implemented by a function module, where the function module may be integrated in the cache, or the method provided in this embodiment may be implemented by disposing an independent component in a terminal device, but the present disclosure is not limited thereto.
For ease of understanding, this embodiment is described in a form of the function module, that is, a corresponding function module is disposed in the cache, and the function module is configured to manage the cache.
Step 403: The cache determines a strength level of spatial locality of the data to be accessed.
A spatial locality analysis module may be disposed in the cache to determine the strength level of the spatial locality of the data to be accessed. As shown in
Step S1: The data access rule collection module 501 records addresses of data that is to be accessed and that needs to be accessed according to access requests, and collects statistics about access rules of the addresses, which further includes collecting statistics about a quantity of times or a probability that data of an address adjacent to the data that is to be accessed and that needs to be accessed by each access request is accessed according to another access request.
Step S2: The spatial locality prediction module 502 predicts, according to the access rule, the spatial locality of the data to be accessed, which further includes classifying, into levels according to the quantity of times or the probability that data of the address adjacent to the data to be accessed is accessed by another access request, spatial locality of the data to be accessed.
For example, two determining thresholds T1 and T2 may be preset, where T1 is less than T2. It is determined that the spatial locality of the data to be accessed is “low” when the quantity of times or the probability that the data of the address adjacent to the data to be accessed is accessed by the other access request is lower than T1, or it is determined that the spatial locality of the data to be accessed is “medium” when the quantity of times or the probability that the data of the address adjacent to the data to be accessed is accessed by the other access request reaches T1, but does not reach T2, or it is determined that the spatial locality of the data to be accessed is “high” when the quantity of times or the probability that the data of the address adjacent to the data to be accessed is accessed by the other access request reaches T2.
Step 404: The cache allocates a cache line to the access request according to the strength level of the spatial locality of the data to be accessed.
A cache line having a large length is allocated to data to be accessed that has strong spatial locality, and a cache line having a small length is allocated to data to be accessed that has weak spatial locality. For example (with reference to the
By means of the foregoing steps, on one hand, when spatial locality of data to be accessed is relatively high, the data to be accessed and data of an address adjacent to the data to be accessed may be both determined as data to be cached (where higher spatial locality of the data to be accessed indicates larger data that is to be cached and that corresponds to the data to be accessed), and the data to be cached is cached in a pre-allocated cache line. Because the pre-allocated cache line has a relatively large length, in a process of writing, from a memory to a cache, the data to be cached, a quantity of times of read and write in the cache line can be reduced such that a delay for accessing the data to be cached is reduced, and transmission bandwidth between the memory and the cache is reduced. On the other hand, the data to be accessed may be determined as data to be cached (or the data to be accessed and a small quantity of data of addresses adjacent to the data to be accessed are both determined as the data to be cached), and the data to be cached is cached in a pre-allocated cache line allocated in advance when spatial locality of data to be accessed is relatively low. Because the pre-allocated cache line has a relatively small length, invalid data in the cache line can be reduced, and utilization of the cache line can be improved.
In this embodiment, the organization manner of the cache lines in the cache may be fixed, and capacities of the cache subunits 201 to 203 in
Optionally, in an optimized solution, capacities of the cache subunits in the cache may be further changed in real time according to strength levels of spatial locality of data to be accessed that corresponds to multiple access requests received within a preset time period, to further improve utilization of the cache line. Details are shown in
Step 601: Collect, within a preset time period, statistics about strength levels of spatial locality of data to be accessed, and calculate a first ratio, where the first ratio is used to represent a proportional relationship between (or among) the data to be accessed having different levels of spatial locality.
Step 602: Calculate a second ratio, where the second ratio is used to represent a proportional relationship between (or among) cache subunits in a cache that include cache lines having different lengths.
Step 603: Adjust a quantity of cache lines in a cache subunit until the difference between the second ratio and the first ratio falls within a range of the preset threshold after the adjustment when a difference between the first ratio and the second ratio is greater than a preset threshold.
For ease of understanding, the foregoing steps 601 to 603 are illustrated based on the organization manner of cache lines shown in
By means of step 602, it is determined that a proportional relationship between (or among) quantities of the access requests, which are received by the cache within the preset time period, having different spatial locality is access request having “high” spatial locality : access request having “medium” spatial locality : access request having “low” spatial locality=1:2:3.
Based on the foregoing case, a proportion of each cache subunit in the entire cache may be adjusted by means of step 603 such that the proportional relationship between (or among) the capacities of the cache subunits in the cache is changed to: the cache subunit 201 : the cache subunit 202 : the cache subunit 203=1:2:3.
It may be avoided that data having relatively strong (or relatively weak) spatial locality is written to a cache line having a relatively small (or relatively large) length through the foregoing processing such that utilization of the cache line in each cache subunit is further improved.
The method shown in
In another optimized solution, based on the cache management method shown in
Step S1: Determine, according to the strength level of the spatial locality of the data to be accessed, a size of data to be cached.
The data to be accessed and multiple pieces of data of addresses adjacent to the data to be accessed may be both determined as the data to be cached, when the spatial locality of the data to be accessed is relatively strong, or only the data to be accessed may be determined as the data to be cached (or the data to be accessed and a small quantity of data of addresses adjacent to the data to be accessed are determined together as the data to be cached) when the spatial locality of the data to be accessed is relatively weak.
Step S2: Adjust a length of a cache line in the cache subunit according to the size of the data to be cached, and allocate an adjusted cache line to the data to be cached, where a length of the adjusted cache line matches the size of the data to be cached.
Step S3: Establish and maintain an index bitmap based on a change in the length of the cache line in the cache subunit, where the index bitmap is used to indicate a tag domain and a data domain that are in the cache line.
For ease of understanding, this embodiment provides a schematic diagram of an index bitmap, and a cache line corresponding to the index bitmap for reference. For example, as shown in
By means of the foregoing steps S1 to S3, the corresponding cache line can be allocated, according to the size of the data to be cached, to the data to be cached such that a cache line resource can be fully used.
According to the foregoing description, a cache line can be allocated to an access request according to a strength level of spatial locality of data to be accessed. Based on a cache line allocation solution provided in this embodiment, this embodiment further provides a cache line search solution, and details are shown in following steps.
In a solution 1, as shown in
Step 801: A cache receives an access request, and acquires, from the access request, a physical address of data to be accessed.
The access request includes the physical address, the physical address is used to identify the data to be accessed, and the physical address includes a tag domain and a set domain that are of the data to be accessed, where the tag domain is an identifier of the data to be accessed, and the set domain is used to represent a set to which the data to be accessed belongs in the cache.
Step 802: The cache determines one or more cache lines that correspond to a set domain of the data to be accessed and that are in each cache subunits, compares tag domains of the one or more cache lines with a tag domain of the data to be accessed, and determines that a cache line, which has a same tag domain as the data to be accessed, in the one or more cache lines as a cache line in which the data to be accessed is stored.
In a solution 2, as shown in
Step 901: A cache receives an access request, and acquires, from the access request, a physical address of data to be accessed.
The access request includes the physical address, the physical address is used to identify the data to be accessed, and the physical address includes a tag domain and a set domain that are of the data to be accessed, where the tag domain is an identifier of the data to be accessed, and the set domain is used to represent a set to which the data to be accessed belongs in the cache.
Step 902: The cache maintains a list for each cache subunit, where the list is used to record a characteristic value of data stored in each cache subunit.
The characteristic value is used to identify the data stored in the cache subunit, that is, there is a correspondence between the characteristic value and the data. For example, physical addresses of data may be calculated using a hash function, and values obtained through calculation are determined as characteristic values corresponding to the data.
Step 903:The cache determines a characteristic value of the data that is to be accessed and that needs to be accessed according to the access request when receiving the access request.
Step 904: The cache determines a cache subunit, which corresponds to a list in which the characteristic value of the data to be accessed is recorded, as a target cache subunit.
Step 905: The cache sends the access request to the target cache subunit, determines one or more cache lines in the target cache subunit that correspond to a set domain of the data to be accessed, compares tag domains of the one or more cache lines with a tag domain of the data to be accessed, and determines a cache line, which has a same tag domain as the data to be accessed, in the one or more cache lines as a cache line in which the data to be accessed is stored.
A cache line search can be implemented using the methods shown in
It should be noted that the cache management method provided in this embodiment is applicable to different types of caches.
(1) caches having different functions in a same CPU, such as an instruction cache (Icache) 1001 and a data cache (Dcache) 1002;
(2) caches at different layers but in a same CPU, such as an Icache 1001 and an L2 cache 1004;
(3) caches at a same layer but in different CPUs, such as an Icache 1001 and an Icache 1003; and
(4) a private cache and a shared cache in different CPUs, such as an L3 cache 1005 and another cache unit.
The foregoing different types of caches may be configured using same cache lines or different cache lines, and a specific configuration case may be set as required.
This embodiment of the present disclosure provides a cache management apparatus, which may implement a cache management method provided in the present disclosure.
The apparatus provided in this embodiment is configured to manage a cache in which multiple cache subunits are disposed, and each of the cache subunits in the cache includes multiple cache lines. A length of the cache line included in each cache subunit is different from a length of a cache line included in another cache subunit. Each of the cache subunits is configured to store data at a corresponding level, the level is a strength level of spatial locality of the data, and a correspondence between the cache subunit and the level includes that the length of the cache line included in the cache subunit is in a positive correlation with strength of spatial locality of the data.
As shown in
Further, as shown in
As shown in
Based on
It should be noted that for brevity of description, some units and modules added in
Optionally, the cache management apparatus 110 may further include a division unit configured to divide the cache by ways and/or by sets, to determine the multiple cache subunits, and set the length of the cache line in each cache subunit.
In
Based on
Based on
By means of the cache management apparatus provided in this embodiment, on one hand, a cache line having a relatively large length is allocated to the data to be accessed when spatial locality of data to be accessed is relatively strong. Because a probability that data of an address adjacent to the data to be accessed is relatively high when the spatial locality of the data to be accessed is relatively strong, and because the cache line allocated to the data to be accessed has a relatively large length, more data of addresses adjacent to the data to be accessed may be cached in the allocated cache line such that in a process of writing the data from a memory to a cache, a quantity of times of read and write in the cache line can be reduced, a delay for accessing the data to be cached can be reduced, and transmission bandwidth between the memory and the cache can be reduced. On the other hand, a cache line having a relatively small length is allocated to the data to be accessed when spatial locality of data to be accessed is relatively weak. Because a probability that data of an address adjacent to the data to be accessed is relatively low when the spatial locality of the data to be accessed is relatively weak, and because the cache line allocated to the data to be accessed has a relatively small length, data of only a small quantity of addresses adjacent to the data to be accessed is cached in the allocated cache line such that invalid data in the cache line is reduced, and utilization of the cache line is improved.
Based on the foregoing descriptions of the implementation manners, a person skilled in the art may clearly understand that the present disclosure may be implemented by software in addition to necessary universal hardware or by hardware only. In most circumstances, the former is a preferred implementation manner. Based on such an understanding, the technical solutions of the present disclosure essentially or the part contributing to the prior art may be implemented in a form of a software product. The software product is stored in a readable storage medium, such as a floppy disk, a hard disk or an optical disc of a computer, and includes several instructions for instructing a computer device (which may be a personal computer, a server, or a network device) to perform the methods described in the embodiments of the present disclosure.
The foregoing descriptions are merely specific implementation manners of the present disclosure, but are not intended to limit the protection scope of the present disclosure. Any variation or replacement readily figured out by a person skilled in the art within the technical scope disclosed in the present disclosure shall fall within the protection scope of the present disclosure. Therefore, the protection scope of the present disclosure shall be subject to the protection scope of the claims.
Number | Date | Country | Kind |
---|---|---|---|
201410032035.3 | Jan 2014 | CN | national |
This application is a continuation of International Application No. PCT/CN2015/071344, filed on Jan. 22, 2015, which claims priority to Chinese Patent Application No. 201410032035.3, filed on Jan. 23, 2014, both of which are hereby incorporated by reference in their entireties.
Number | Date | Country | |
---|---|---|---|
Parent | PCT/CN2015/071344 | Jan 2015 | US |
Child | 15218826 | US |