Cache data processing method, cache, cache application system and electronic equipment
By considering the cost of data acquisition in the cache replacement algorithm, determining the retention weight of data, and prioritizing the retention of data with higher data acquisition, the problem of frequent replacement and removal of data in the prior art has been solved, and the problem of data with higher data acquisition is frequently replaced and removed, which has improved Data processing performance of cache application systems.
Patent Information
- Application Number
- CN202411463737.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-18
- Publication Date
- 2025-02-25
AI Technical Summary
The existing cache replacement algorithm fails to effectively consider the cost of data acquisition, resulting in data with higher data acquisition cost being replaced and removed, increasing the cost of subsequent acquisition and reducing the overall data processing performance of the cache application system.
A cache replacement algorithm that considers the cost of data acquisition is adopted. By determining the retention weight of data, it is preferred to retain data with higher data acquisition cost, reducing the frequency of data with higher data acquisition cost being replaced and removed.
It effectively reduces the high cost of data acquisition and data being replaced and removed and needs to be reacquisition, and improves the overall data processing performance of the cache application system.
Smart Images

Figure CN119513033A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of computer technology, and specifically to a cache data processing method, a cache, a cache application system, and an electronic device. Background Art
[0002] As an intermediate storage device, cache can be used to temporarily store data that needs to be frequently accessed or recently accessed to improve data access efficiency. Since the cache space is limited, when the cache is full, the old data in the cache needs to be replaced to make room for new data. At this time, a cache replacement algorithm is needed to determine the data to be retained in the cache and the data to be replaced by the cache. Therefore, how to optimize the cache replacement algorithm to improve data processing performance has become a technical problem that technicians in this field need to solve urgently. Summary of the invention
[0003] In view of this, embodiments of the present application provide a cache data processing method, cache, cache application system and electronic device, which utilize a cache replacement algorithm that takes data acquisition costs into consideration to perform cache data processing, thereby improving data processing performance.
[0004] To achieve the above objectives, the embodiments of the present application provide the following technical solutions.
[0005] In a first aspect, an embodiment of the present application provides a cache data processing method, which is applied to a cache, and the method includes:
[0006] Obtaining a data access request, where the data access request is used to request target data;
[0007] Determine the data acquisition cost of the target data;
[0008] Determine the retention weight of the target data at least according to the data acquisition cost of the target data; wherein the retention weight of any data in the cache is determined at least according to the data acquisition cost of the data, and the retention weight of the data represents the priority of the data in the cache, which is used by the cache replacement algorithm to determine the replacement data;
[0009] storing the target data in a cache and indicating a retention weight of the target data; and outputting the target data in response to the data access request.
[0010] In a second aspect, an embodiment of the present application provides a cache, including: a cache control logic; the cache control logic is configured to execute the cache data processing method as described in the first aspect above.
[0011] In a third aspect, an embodiment of the present application provides a cache application system, including an upstream module, a cache, and a cache data source; wherein the cache is the cache as described in the second aspect above.
[0012] In a fourth aspect, an embodiment of the present application provides an electronic device, including a chip, wherein the chip includes the cache as described in the second aspect above.
[0013] In the data processing method of the cache provided in the embodiment of the present application, the cache replacement algorithm can use the retention weight of the data to determine the replacement data, the retention weight of the data indicates the priority of the data to be retained in the cache, and the retention weight of the data is determined at least according to the data acquisition cost of the data; thus, after the cache obtains the data access request for the target data, it can determine the data acquisition cost of the target data; at least according to the data acquisition cost of the target data, determine the retention weight of the target data; then, save the target data in the cache and indicate the retention weight of the target data, so as to provide a basis for the implementation of the cache replacement algorithm; at the same time, the embodiment of the present application can output the target data in response to the data access request. It can be seen that the embodiment of the present application provides a cache replacement algorithm that takes the data acquisition cost into consideration, which can realize the use of data with a lower data acquisition cost as replacement data, and retain data with a higher data acquisition cost in the cache, thereby reducing the higher data acquisition cost caused by the need to obtain data with a higher data acquisition cost again after being replaced and removed, thereby improving the overall data processing performance of the cache application system. BRIEF DESCRIPTION OF THE DRAWINGS
[0014] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.
[0015] Figure 1 The following is an example diagram of a cache application system.
[0016] Figure 2 A flowchart of a cached data processing method provided in an embodiment of the present application.
[0017] Figure 3 This is an example diagram of the format of data items provided in an embodiment of the present application.
[0018] Figure 4 Another flow chart of the cache data processing method provided in an embodiment of the present application.
[0019] Figure 5 This is an application example diagram provided for an embodiment of the present application.
[0020] Figure 6 An example diagram of the cache provided in an embodiment of the present application. DETAILED DESCRIPTION
[0021] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0022] Cache is widely used in many scenarios such as chips and communication networks. In specific scenarios where cache is used, cache can temporarily store data that is frequently accessed or recently accessed by upstream modules to improve the data access efficiency of upstream modules. As an example, Figure 1 The example diagram of the cache application system is shown as an example. The cache application system can be regarded as a computer system or a communication network system that applies a cache mechanism, such as a chip that applies a cache mechanism, a communication network that applies a cache mechanism, etc. Figure 1 As shown, the cache application system may include: an upstream module 110 , a cache 120 , and a cache data source 130 .
[0023] The upstream module 110 is a physical device that accesses data from the cache 120. The upstream module relies on data access to execute the functions of the upstream module. For example, the upstream module needs to access data from the cache to complete computing tasks, process applications, and other functions.
[0024] For example, taking the chip scenario as an example, the upstream modules of the cache are, for example, processor cores, such as CPU (Central Processing Unit) or GPU (Graphics Processing Unit) and other processor cores. For example, taking the communication network scenario as an example, the upstream modules of the cache are, for example, user devices, etc.; wherein user devices are electronic devices used by users such as smart phones, tablet computers, desktop computers, etc., which request video streams, web pages, application data and other data through the network.
[0025] The cache 120 is an intermediate storage device for storing data, and its purpose is to reduce the data access time of the upstream module, improve the data access efficiency, etc. For example, the cache can save the data frequently accessed or recently accessed by the upstream module to reduce the process of requesting data from the more remote cache data source 130.
[0026] For example, in the chip scenario, the cache can be an on-chip cache (i.e., on-chip cache), such as different levels of cache such as L1, L2, L3, etc. inside the CPU or GPU; that is, the on-chip cache is embedded in the processor chip and is located between the processor and the memory to reduce the data access latency between the processor and the memory. For example, in the communication network scenario, the cache can be an edge cache, i.e., a node located at the edge of the communication network. For example, the edge cache can be an edge server located between the user and the data center in the communication network. The edge server can store and provide data that users frequently access to reduce the need to access the data center.
[0027] The cache data source 130 is a physical device that provides data to the cache, that is, the source of cache data. For example, taking the chip scenario as an example, the cache data source can be, for example, a memory. For example, taking the communication network scenario as an example, the cache data source can be an ISP (Internet Service Provider) data center, which can store a large amount of network content, such as web pages, videos, pictures, software, etc.
[0028] exist Figure 1 In the example architecture, the upstream module interacts with the cache and sends data access requests to the cache to request the data required by the upstream module; if the data is already stored in the cache (i.e., cache hit), the cache can feed the data back to the upstream module, thereby improving the data access speed of the upstream module; if the data is not stored in the cache (i.e., cache miss), the cache needs to request data from a more distant cache data source and feed it back to the upstream module.
[0029] In the case of a cache miss, the new data requested by the cache from the cache data source needs to be loaded into the cache. At this time, if the cache is full (that is, the cache has no free storage space to save the new data), the cache replacement algorithm needs to be used to determine the old data that needs to be replaced from the cache to make room for the new data. In other words, the cache relies on the cache data source to fill and update the data stored in the cache (for example, when the cache misses, the cache will request and save data from the cache data source), and the cache relies on the cache replacement algorithm to optimize the data stored in the cache.
[0030] It can be seen that the cache replacement algorithm is a data replacement strategy of the cache, which is used to determine the data that the cache needs to retain and the data that the cache needs to replace when the cache is full (the data that the cache needs to replace can be understood as the data that the cache needs to be kicked out and removed).
[0031] One goal of cache replacement algorithms is to maximize the cache hit rate, that is, to enable upstream modules to directly obtain data from the cache as much as possible, thereby reducing access to cache data sources and improving data access efficiency. Cache replacement algorithms based on cache hit rate include LRU (Least Recently Used) algorithm and LFU (Least Frequently Used) algorithm.
[0032] Among them, the LRU algorithm assumes that data that has not been accessed recently is unlikely to be accessed in the future. Therefore, when the data in the cache needs to be replaced, the LRU algorithm will eliminate the data that has not been accessed for the longest time.
[0033] The LFU algorithm assumes that data that was frequently accessed in the past may also be frequently accessed in the future, thereby eliminating the data with the lowest access frequency in the cache; for example, the LFU algorithm tracks the access frequency of each data in the cache, and when data in the cache needs to be replaced, selects the data with the lowest access frequency for replacement.
[0034] However, the cache replacement algorithm based on cache hit rate may have the problem of low overall data processing performance of the cache application system. Specifically, the cache replacement algorithm based on cache hit rate mainly focuses on the cache hit rate, but does not consider the data acquisition cost of the cache, which may result in the replacement data being data with a high data acquisition cost, so that the cache needs to pay a high data acquisition cost to obtain the data from the cache data source again in the future, which affects the overall data processing performance of the cache application system.
[0035] For example, the LRU algorithm or LFU algorithm replaces data in the cache based on the access frequency of the data or the time when it was most recently used, without considering the cost of the cache to obtain data (such as latency, power consumption, bandwidth, etc.). This may result in the data replaced by cache replacement algorithms such as the LRU algorithm or the LFU algorithm being data that is infrequently accessed but has a higher data acquisition cost. In this case, although the access frequency of the replaced data is lower, the cost of obtaining the data again from the cache data source may be higher than the cost of keeping the data in the cache, thereby reducing the overall data processing performance of the cache application system.
[0036] For example, assuming that the number of cache hits of data D1 in the cache is lower than the number of cache hits of data D2, then according to the cache replacement algorithm based on cache hit rate, such as the LRU algorithm or the LFU algorithm, data D1 is replaced out of the cache and data D2 is retained in the cache; however, if the data acquisition cost of data D1 is higher than the data acquisition cost of data D2, then from the perspective of the overall data processing performance of the cache application system, the decision of the cache replacement algorithm based on cache hit rate to replace data D1 out of the cache may become unreasonable; that is, if the cache needs to obtain data D1 from the cache data source again later, the cache needs to pay a higher cost to obtain data D1 than the cost of keeping data D1 in the cache, resulting in lower overall data processing performance of the cache application system.
[0037] Based on this, the embodiment of the present application provides a cache replacement algorithm that takes into account the data acquisition cost to perform cached data processing, thereby improving the overall data processing performance. As an optional implementation, Figure 2 A flowchart of a cache data processing method provided in an embodiment of the present application is exemplarily shown. The method can be executed by the cache. Figure 2 The method flow may include the following steps.
[0038] In step S210, a data access request is obtained, where the data access request is used to request target data.
[0039] In an optional implementation, the upstream module of the cache may send a data access request to the cache based on data access requirements to request target data. For example, when executing a computing task or an application, the upstream module of the cache may request the cache for target data required to execute the computing task or the application, thereby sending a data access request to the cache to request the target data.
[0040] In an optional implementation, based on the data storage situation of the cache, the cache may process data access requests in the following situations:
[0041] The cache is not full and the target data is not stored in the cache (i.e., the cache is not full and the cache misses). At this time, the cache can load the target data from the cache data source into the cache for storage, and output the stored target data to the upstream module to respond to the data access request. Since the cache still has storage space to store the target data, there is no need to replace or remove the data from the cache, so this situation does not trigger the cache replacement algorithm.
[0042] The cache is not full and the target data is stored in the cache (i.e., the cache is not full and the cache hits). At this time, the cache can output the target data stored in the cache to the upstream module to respond to the data access request. Since there is free storage space in the cache and the cache has already stored the target data, there is no need to replace and remove the data from the cache. Therefore, this situation may not trigger the cache replacement algorithm.
[0043] The cache is full and the target data is not stored in the cache (i.e., the cache is full and the cache misses). At this time, the cache can load the target data from the cache data source into the cache for storage. At the same time, since the cache is full, it is necessary to trigger the cache replacement algorithm to replace and remove the data from the cache to make room for storing the target data in the cache. Therefore, after storing the target data, the cache can output the target data to the upstream module to respond to the data access request.
[0044] The cache is full and the target data is stored in the cache (i.e., the cache is full and the cache hits). At this time, the cache can output the target data stored in the cache to the upstream module in response to the data access request. Although there is no free storage space in the cache, the cache has already stored the target data, and there is no need to replace and remove data from the cache to make room for the target data. Therefore, this situation may not trigger the cache replacement algorithm.
[0045] Regardless of the above situation, based on the cache replacement algorithm that considers the data acquisition cost in the embodiment of the present application, the embodiment of the present application needs to determine the data acquisition cost of the target data requested by the data access request, so as to provide a basis for the implementation of the cache replacement algorithm.
[0046] In step S211 , the data acquisition cost of the target data is determined.
[0047] Different from cache replacement algorithms such as LRU and LFU based on cache hit rate, the cache replacement algorithm provided in the embodiment of the present application takes into account the data acquisition cost of the data. It should be noted that the data acquisition cost of the data can represent a cost index consumed by the cache to acquire the data. Since the cost index of the cache to acquire different data may be different, the data acquisition cost of different data may be different. In an optional implementation, the data acquisition cost of the data can be determined by the cost index consumed by the cache to acquire the data. The cost index consumed by the cache to acquire the data can be a single-dimensional cost index or a multi-dimensional cost index.
[0048] In an optional implementation example, the cost indicator consumed by the cache to obtain data may include but is not limited to at least one of the following: the time cost, resource cost, economic cost, etc. consumed by the cache to obtain data. Among them, the time cost consumed by the cache to obtain data mainly refers to the latency of the cache to obtain data, such as the time delay from the cache requesting data from the cache data source to the cache obtaining data feedback from the cache data source. The resource cost consumed by the cache to obtain data refers to the system resources consumed by the cache to obtain data, including but not limited to power consumption, bandwidth, etc. The economic cost consumed by the cache to obtain data refers to the direct and indirect expenses incurred by the cache to obtain data.
[0049] As an example, the cost indicator consumed by cache acquisition of data may include at least one of the following:
[0050] The latency of cache acquiring data is the time delay from when the cache requests data from the cache data source to when the cache obtains the data fed back by the cache data source. For example, in a communication network scenario, the latency can be measured in ms (milliseconds), and in a chip scenario, the latency can be measured in ns (nanoseconds).
[0051] The power consumption of caching data, the energy consumption involved in caching data, for example, the energy consumed to find data from the cache data source;
[0052] The bandwidth used to obtain data from the cache. The bandwidth resources used or occupied by obtaining data from the cache, etc.
[0053] It should be noted that, based on the specific type and architecture of the cache application system, the form of the cost indicator of cache data acquisition consumption may be different, that is, the cost indicator of cache data acquisition consumption may be adapted to the specific cache application system. For example, the specific type and architecture of the cache application system may determine the form of the cost indicator of cache data acquisition consumption.
[0054] As an optional implementation, for any data, the embodiment of the present application can determine the data acquisition cost of the cache to obtain the data based on the cost index consumed by the cache to obtain the data (a single-dimensional cost index or a multi-dimensional cost index).
[0055] In an optional implementation, taking the cost indicator of a single dimension consumed by the cache to obtain data as an example, the data acquisition cost can be defined as the cost indicator of this single dimension, that is, the cost indicator of this single dimension can be directly used as the data acquisition cost. For example, taking the cost indicator of a single dimension of latency as an example, the data acquisition cost of the cache to obtain data can be defined as the latency of the cache to obtain data; for another example, taking the cost indicator of a single dimension of power consumption as an example, the data acquisition cost of the cache to obtain data can be defined as the power consumption consumed by the cache to obtain data.
[0056] In an optional implementation, taking the multi-dimensional cost indicators of cache data acquisition consumption as an example, the multi-dimensional cost indicators of cache data acquisition consumption can be comprehensively used to obtain the data acquisition cost of cache data acquisition, that is, when using multi-dimensional cost indicators, the data acquisition cost of cache data acquisition can be determined by comprehensively using the multi-dimensional cost indicators of cache data acquisition consumption.
[0057] Optionally, the product of the multi-dimensional cost indicators consumed by the cache to obtain data can be used as the data acquisition cost of the cache to obtain data, so that for any data, the multi-dimensional cost indicators consumed by the cache to obtain data can be multiplied, and the multiplication result (i.e., the product) is used as the data acquisition cost of the cache to obtain data. For example, taking the cost indicators of latency and bandwidth as an example, for any data, the latency of the cache to obtain data can be multiplied by the bandwidth used by the cache to obtain data, so as to obtain the data acquisition cost of the cache to obtain data. For example, let the data acquisition cost of the data be P, the latency of the cache to obtain data be A, and the bandwidth used be B, then P = A × B.
[0058] Optionally, the weighted sum of the multi-dimensional cost indicators consumed by the cache to obtain data can be used as the data acquisition cost of the cache to obtain data, so that the preset weights can be set for the cost indicators of each dimension to indicate the importance of the cost indicators of each dimension to the data acquisition cost. The preset weights corresponding to the cost indicators of different dimensions can be set according to the actual situation, and the embodiments of the present application are not limited; and then for any data, the multi-dimensional cost indicators consumed by the cache to obtain data and the preset weights corresponding to the cost indicators of each dimension can be weighted summed, and the weighted summation result can be used as the data acquisition cost of the cache to obtain data. For example, for any data, the cost indicators of each dimension of the cache to obtain data are multiplied by the corresponding preset weights, and the sum of each product result can be obtained to obtain the data acquisition cost of the cache to obtain data. For example, taking latency and bandwidth as an example, preset weights can be assigned to latency and bandwidth respectively to indicate the importance of latency to the data acquisition cost and the importance of bandwidth to the data acquisition cost; thus, for any data, the latency of the cache to obtain data can be multiplied by the preset weight corresponding to the latency, and the bandwidth used by the cache to obtain data can be multiplied by the preset weight corresponding to the bandwidth, and then the two multiplication results are summed to obtain the data acquisition cost of the cache to obtain data.
[0059] It should be further explained that the data acquisition cost can be flexibly defined. For example, the data acquisition cost can be flexibly defined according to the actual application scenario of the cache, including but not limited to defining a specific single-dimensional cost indicator for the data acquisition cost, a multi-dimensional cost indicator, and a method of obtaining the data acquisition cost by comprehensively analyzing the multi-dimensional cost indicators.
[0060] In an optional implementation, the cache can manage the data stored in the cache through a cache management data structure, and the cache management data structure can be regarded as a logical data structure for implementing cache management; wherein the cache management data structure can include data items of data, and one data in the cache corresponds to one data item, for example, the data content and tag information of one data can be organized into one data item. In the mapping with the hardware storage unit (such as a cache line) of the cache, a data item of the cache management data structure can map one or more hardware storage units of the cache (for example, one data item maps one or more cache lines), and the number of hardware storage units mapped by one data item (such as the number of cache lines) can depend on the data size and cache configuration, and the embodiments of the present application are not limited thereto.
[0061] For example, the cache management data structure may be, for example, a cache linked list, which may be a cache management data structure in the form of a linked list, which may include multiple linked list nodes, and one linked list node may correspond to one data item of the cache management data structure. In other possible examples, the embodiments of the present application may also support the cache management data structure in the form of a hash table, rather than being limited to a linked list.
[0062] In an optional implementation of an embodiment of the present application, data can be organized as data items in a cache management data structure. For example, the data content and tag information of a data can be organized into a data item in the cache management data structure (such as a linked list node in a cache linked list), thereby realizing the physical storage of data in the cache through mapping the data item of the data with the hardware storage unit (such as a cache line).
[0063] As an optional implementation, the data item of the data (e.g., the linked list node of the data in the cache linked list) can record the cost index consumed by the cache to obtain the data. Furthermore, when determining the data acquisition cost of any data, the cost index consumed by the cache to obtain the data can be obtained from the data item of the data, and the data acquisition cost of the data can be determined based on the obtained cost index consumed by the cache to obtain the data.
[0064] In an optional implementation example, the cost indicator consumed by the cache to obtain data can be recorded in the additional tag information of the data item, that is, the additional tag information of the data item can be used to set the cost indicator consumed by the cache to obtain data. It should be noted that tag information (Tag Information) can be tag information of the data, which is divided into basic tag information and additional tag information; basic tag information can be used as tag information to determine the location of data, and is used to verify whether the access request hits in the cache; additional tag information can be tag information used for cache control and optimization. The embodiment of the present application can set the cost indicator consumed by the cache to obtain data in the additional tag information of the data item.
[0065] In an optional implementation, for the target data requested by the data access request, the embodiment of the present application may record a cost indicator consumed by the cache to obtain the target data in the data item of the target data (for example, in the additional tag information of the data item of the target data, record the cost indicator consumed by the cache to obtain the target data). Thus, when determining the data acquisition cost of the target data, the cost indicator consumed by the cache to obtain the target data may be obtained from the data item of the target data (for example, from the additional tag information of the data item of the target data, obtain the cost indicator consumed by the cache to obtain the target data); then, the data acquisition cost of the target data is determined based on the obtained cost indicator consumed by the cache to obtain the target data. The method for determining the data acquisition cost based on the cost indicator (a single-dimensional cost indicator or a multi-dimensional cost indicator) can refer to the description of the corresponding part of the previous text and will not be expanded here.
[0066] In the optional implementation example, taking the single-dimensional cost indicator of latency as an example, Figure 3 The format of the data item provided in the embodiment of the present application is exemplarily shown. The data item can map the cache line of the cache, such as Figure 3 As shown, the content in the data item may include stored data, basic tag information, and additional tag information, wherein the additional tag information records a delay (i.e., the delay for the cache to obtain data). In this example, when it is necessary to determine the data acquisition cost of any data, the delay for the cache to obtain the data can be obtained from the additional tag information of the data item of the data, and then the obtained delay for the cache to obtain the data is used as the data acquisition cost of the data. It should be noted that this example is only illustrated with a single-dimensional cost indicator of delay. Based on actual conditions, the embodiments of the present application may record other forms of single-dimensional cost indicators in the data item (such as power consumption or bandwidth for caching data), or record multi-dimensional cost indicators. The embodiments of the present application are not limited to this.
[0067] In step S212, the retention weight of the target data is determined based at least on the data acquisition cost of the target data; wherein, for any data in the cache, the retention weight of the data is determined based at least on the data acquisition cost of the data, and the retention weight of the data represents the priority of retaining the data in the cache, which is used by the cache replacement algorithm to determine the replacement data.
[0068] In an optional implementation, the retention weight of data can express the priority of retaining data in the cache. For example, the higher the retention weight of data, the higher the priority of retaining data in the cache, and the less likely it is to be replaced and removed from the cache; the lower the retention weight of data, the lower the priority of retaining data in the cache, and the more likely it is to be replaced and removed from the cache. In the optional implementation example, the retention weight of data is negatively correlated with the probability of data becoming replacement data, that is, the higher the retention weight of data, the lower the probability of data becoming replacement data, and correspondingly, the lower the probability of data being replaced and removed from the cache; and the lower the retention weight of data, the higher the probability of data becoming replacement data, and correspondingly, the higher the probability of data being replaced and removed from the cache. For ease of explanation, data replaced and removed from the cache is referred to as replacement data.
[0069] Since the retention weight of the data is determined at least according to the data acquisition cost, by using data with lower retention weight as replacement data, it is possible to use data with lower data acquisition cost as replacement data and retain data with higher data acquisition cost in the cache, thereby reducing the higher data acquisition cost caused by the need to acquire data with higher data acquisition cost again after being replaced and removed, thereby improving the overall data processing performance of the cache application system.
[0070] In an optional implementation, the embodiment of the present application can directly use the data acquisition cost of the data as the retention weight of the data. For example, if the retention weight of the data is W and the data acquisition cost of the data is P, then W=P. Accordingly, an optional implementation of step S212 can be to use the data acquisition cost of the target data as the retention weight of the target data.
[0071] In a further optional implementation, the cache replacement algorithm provided by the embodiment of the present application may also consider the use value of the data in addition to the data acquisition cost. The use value of the data may reflect the probability that the data is used by the upstream module, and the use value of the data may be updated at least with the use of the data. Furthermore, in the case where the retention weight of the data is determined based on the data acquisition cost and the use value of the data, the embodiment of the present application may implement the update of the retention weight of the data based on the use value of the data that is updated at least with the use of the data.
[0072] In an optional implementation, the use value of the data can be recorded in the data item of the data. For example, when the data is accessed by an upstream module, the embodiment of the present application can set the use value of the data in the data item of the data, and the use value of the data is updated with the usage of the data to update the retention weight of the data. Thus, when it is necessary to determine the retention weight of the data, the embodiment of the present application can obtain the cost index of the cache acquisition data consumption and the use value of the data from the data item of the data; then, determine the data acquisition cost of the data based on the obtained cost index of the cache acquisition data consumption; determine the retention weight of the data based on the data acquisition cost of the data and the obtained data use value. In an optional implementation example, the embodiment of the present application can set the use value of the data in the additional tag information of the data item.
[0073] In an optional implementation, for the target data requested by the data access request, after obtaining the data access request, the embodiment of the present application can set the use value of the target data in the data item of the target data (for example, in the additional tag information of the data item of the target data, the use value of the target data is set), and the use value of the target data is updated with the use of the target data to update the retention weight of the target data. Thus, the embodiment of the present application can obtain the cost index consumed by the cache to obtain the target data and the use value of the target data from the data item of the target data; then, according to the obtained cost index consumed by the cache to obtain the target data, determine the data acquisition cost of the target data; according to the data acquisition cost of the target data and the obtained use value of the target data, determine the retention weight of the target data.
[0074] In a further optional implementation, the use value of data may include the access frequency of the data, that is, the cache replacement algorithm provided in the embodiment of the present application may consider the access frequency of the data in addition to the cost of data acquisition. The access frequency of data may represent the number of times the data is accessed in the cache, such as the number of times the data is accessed by the upstream module in the cache; for example, the access frequency of data newly entering the cache may be set to a preset initial access frequency (the preset initial access frequency is, for example, 1), then in the process of storing the data in the cache, each time the data is accessed, the access frequency of the data increases by 1.
[0075] In an optional implementation, the retention weight of the data can be determined based on at least the data acquisition cost of the data and the access frequency of the data; for example, for any data, the embodiment of the present application can comprehensively consider the data acquisition cost of the data and the access frequency of the data to obtain a comprehensive result of the data, thereby determining the retention weight of the data based on at least the comprehensive result of the data.
[0076] In an optional implementation example, the embodiment of the present application can multiply the data acquisition cost of the data by the access frequency of the data to obtain the retention weight of the data. For example, if the access frequency of the data is F, the retention weight of the data can be expressed as: W = F × P.
[0077] In other possible implementation examples, the embodiments of the present application may also set preset weights for the data acquisition cost and the access frequency, respectively, to indicate the importance of the data acquisition cost and the access frequency for retaining the weight, that is, the preset weight of the data acquisition cost indicates the importance of the data acquisition cost for retaining the weight, and the preset weight of the access frequency indicates the importance of the access frequency for retaining the weight. The preset weights corresponding to the data acquisition cost and the access frequency may be set according to actual conditions, and the embodiments of the present application do not set any limitation; for example, in the case where the impact of the data acquisition cost takes precedence over the access frequency, the preset weight corresponding to the data acquisition cost may be set higher than the preset weight corresponding to the access frequency.
[0078] Thus, the retention weight of the data may be the result of weighted summation of the data acquisition cost, the access frequency and the corresponding preset weight of the data. For example, for any data, the data acquisition cost of the data may be multiplied by the preset weight corresponding to the data acquisition cost, the access frequency of the data may be multiplied by the preset weight corresponding to the access frequency, and the multiplication results may be summed to obtain the retention weight of the data.
[0079] It should be noted that the above-mentioned method of comprehensively considering the data acquisition cost and access frequency to obtain the retention weight is only an optional implementation method. When the cache replacement algorithm comprehensively considers the data acquisition cost and access frequency of the data, any method of comprehensively considering the data acquisition cost and access frequency that can reflect the impact of the data acquisition cost and access frequency on the retention weight can be used as the method of comprehensively considering the data acquisition cost and access frequency to obtain the retention weight in the embodiment of the present application.
[0080] It should be further explained that, when the cache replacement algorithm comprehensively considers the data acquisition cost and access frequency of the data, the goal of the cache replacement algorithm is to further keep the data with high data acquisition cost and frequent access in the cache while considering the data acquisition cost, and to give priority to removing the data with low data acquisition cost and low access frequency from the cache; that is, while considering the data acquisition cost, the cache hit rate is further taken into account, thereby improving the overall data processing performance of the cache application system.
[0081] In an optional implementation, based on the use value of the data being recorded in the data item of the data, the embodiment of the present application can record the access frequency of the data in the data item of the data (for example, setting the access frequency of the data in the additional tag information of the data item), and the access frequency of the data is updated with the number of times the data is accessed in the cache. Figure 3 As shown, the additional tag information of the data item records the access frequency of the data, and the access frequency of the data in the data item is updated with the number of times the data is accessed in the cache to achieve the retention weight of the updated data.
[0082] Accordingly, for the target data requested by the data access request, the embodiment of the present application can set the access frequency of the target data in the data item of the target data after obtaining the data access request. In an optional implementation, based on the data access request, setting the access frequency of the target data in the data item of the target data can be specifically divided into the following cases.
[0083] Case 1: after obtaining the data access request, if it is determined that the cache is full and the target data is not stored in the cache, the access frequency of the target data is set to a preset initial access frequency in the data item of the target data, for example, the access frequency of the target data recorded in the data item of the target data is set to 1;
[0084] When the cache is full and the target data is not stored in the cache, the embodiment of the present application needs to load the target data from the cache data source into the cache, and the access frequency of the target data needs to be reset, so that the access frequency of the target data can be set to a preset initial access frequency (for example, 1) based on the data access request to access the target data.
[0085] Case 2: after obtaining the data access request, if it is determined that the cache is full and the target data is already stored in the cache, then one access is added according to the target data, and the access frequency of the target data recorded in the data item of the target data is updated, for example, the access frequency of the target data recorded in the data item of the target data is increased by 1;
[0086] When the cache is full and the target data has been stored in the cache, the data item of the target data has recorded the access frequency of the target data. Based on the data access request for access to the target data, the access frequency of the target data recorded in the data item of the target data can be increased by 1, thereby updating the access frequency of the target data recorded in the data item of the target data.
[0087] Case three, after obtaining the data access request, if it is determined that the cache is not full, the access frequency of the target data is set to the preset initial access frequency in the data item of the target data, for example, the access frequency of the target data recorded in the data item of the target data is set to 1.
[0088] It should be noted that, when the cache is not full, the target data may or may not be stored in the cache. If the cache is not full and the target data is not stored in the cache, the target data needs to be loaded from the cache data source to the cache, and the access frequency of the target data needs to be reset, so that the access frequency of the target data can be set to a preset initial access frequency (such as 1) based on the data access request to access the target data.
[0089] If the cache is not full and the target data has been stored in the cache, the embodiment of the present application adjusts the access frequency of the target data whose data item has been recorded to the preset initial access frequency (for example, 1); that is, when the cache is not full and the target data has been stored in the cache, although the target data item has the access frequency of the recorded target data, the access frequency of the recorded target data will be adjusted to the preset initial access frequency (for example, 1). This is because the calculation of the retention weight requires the comprehensive consideration of the access frequency and the data acquisition cost, and the value of the access frequency is not lower than the preset initial access frequency (for example, not lower than 1), so in the process of comprehensive consideration of the access frequency and the data acquisition cost, the access frequency is an expansion factor of the retention weight; for example, taking the data acquisition cost of the data multiplied by the access frequency as an example, the access frequency of the data is the multiplier factor of the data acquisition cost, so the greater the access frequency of the data, the greater the result after comprehensive consideration of the data acquisition cost and the access frequency, and it increases exponentially. At the same time, the goal of the cache replacement algorithm is to further try to retain data with high data acquisition cost and frequent access in the cache, and to remove data with low data acquisition cost and low access frequency from the cache in priority, taking into account the data acquisition cost; and if the cache is not full and the target data is already stored in the cache (the storage resources of the cache are not tight at this time), the recorded access frequency of the data item of the target data is still increased by 1, then based on the access frequency as an expansion factor of the retention weight (such as a multiplier factor of the data acquisition cost), it may cause data with low data acquisition cost but high access frequency to have a higher retention weight and be retained in the cache, while data with high data acquisition cost but low access frequency has a lower retention weight and is kicked out of the cache, making it impossible for the cache replacement algorithm to retain data with high data acquisition cost in the cache; therefore, in the embodiment of the present application, when the cache is not full and the target data is already stored in the cache, the access frequency of the target data recorded in the data item of the target data is adjusted to the preset initial access frequency, thereby recalibrating the retention weight of the target data stored in the cache, so that when the cache replacement algorithm is subsequently triggered, the new data entering the cache can have a fair opportunity to compete with the old data stored in the cache for the storage location, and achieve the goal of the cache replacement algorithm.
[0090] From the above example, it can be seen that for any data, the access frequency of the data can be updated with the number of accesses to the data when the cache is full and the data is stored in the cache (i.e., the cache is satisfied and the cache hits). Of course, the embodiments of the present application may not be limited to the above example. For example, when the cache is not full and the target data is stored in the cache, the access frequency of the target data recorded in the data item of the target data may be reduced, and the access frequency of the target data after the reduction is not less than the preset initial access frequency (e.g., not less than 1), and is not limited to setting the access frequency of the target data recorded to the preset initial access frequency.
[0091] As an optional implementation, for the target data requested by the data access request, the embodiment of the present application can obtain the cost index consumed by the cache to obtain the target data and the access frequency of the target data from the data item of the target data; determine the data acquisition cost of the target data based on the obtained cost index consumed by the cache to obtain the target data; comprehensively consider the data acquisition cost of the target data and the access frequency of the obtained target data to obtain a comprehensive result of the target data; determine the retention weight of the target data at least based on the comprehensive result of the target data. The relevant content of comprehensively considering the data acquisition cost and the access frequency to determine the retention weight can refer to the description of the corresponding part of the previous text, which will not be expanded here.
[0092] In a further optional implementation, the use value of data may also include the dynamic age of data, that is, the cache replacement algorithm provided in the embodiment of the present application may consider the dynamic age of data in addition to the data acquisition cost and access frequency. The dynamic age of data may at least indicate the use value corresponding to the storage time of data in the cache; in an optional implementation, the dynamic age of data is negatively correlated (such as an inverse relationship) with the storage time of data in the cache, that is, the longer the storage time of data in the cache, the smaller the dynamic age of data; for example, for each set time that data is stored in the cache, the dynamic age of data is reduced by a set unit value.
[0093] In the case where the cache replacement algorithm considers the data acquisition cost, access frequency and dynamic age of the data, the retention weight of the data can be determined based on the data acquisition cost, access frequency and dynamic age of the data. For example, for any data, the embodiment of the present application can superimpose the comprehensive result of the data acquisition cost and access frequency of the data with the dynamic age of the data to obtain the retention weight of the data. In an optional implementation, the method of combining the data acquisition cost and access frequency of the data can refer to the description of the corresponding part of the previous text, which will not be repeated here.
[0094] In an optional implementation example, for any data, the embodiment of the present application can add the comprehensive result of the data acquisition cost and the access frequency of the data (hereinafter referred to as the comprehensive result of the data) to the dynamic age of the data to obtain the retention weight of the data. For example, assuming that the dynamic age of the data is L, the retention weight of the data can be expressed as: W = L + F × P.
[0095] It should be noted that adding the comprehensive result of the data to the dynamic age of the data is only an optional implementation of superimposing the comprehensive result of the data with the dynamic age of the data. The embodiment of the present application can also support other possible ways of superimposing the comprehensive result of the data with the dynamic age of the data, such as multiplying the dynamic age of the data by a preset weight assigned to the dynamic age, and then adding it to the comprehensive result of the data to obtain the retention weight of the data.
[0096] It should be further explained that, when the cache replacement algorithm considers the data acquisition cost, access frequency and dynamic age of the data, the goal of the cache replacement algorithm is to balance the cache hit efficiency and data acquisition cost as much as possible while considering the data acquisition cost, so as to retain data with usable value within the limited cache space; thereby, when considering the data acquisition cost of the data, the overall data processing performance of the cache application system is further comprehensively considered from the perspective of multi-dimensional indicators such as data acquisition cost, access frequency and dynamic age, so as to improve the overall data processing performance of the cache application system.
[0097] In an optional implementation, based on the use value of the data being recorded in the data item of the data, the embodiment of the present application can record the dynamic age of the data in the data item of the data (for example, setting the dynamic age of the data in the additional tag information of the data item), and the dynamic age of the data is updated at least with the storage time of the data in the cache and is negatively correlated, so as to update the retention weight of the data. Figure 3 As shown, the additional tag information of the data item records the dynamic age of the data, and the dynamic age of the data recorded in the data item is updated as the data is saved in the cache to achieve the retention weight of the updated data.
[0098] Accordingly, for the target data requested by the data access request, after obtaining the data access request, the embodiment of the present application can set the dynamic age of the target data in the data item of the target data, and the dynamic age of the target data is updated at least with the storage time of the target data in the cache, so as to update the retention weight of the target data. In an optional implementation, based on the data access request, setting the dynamic age of the target data in the data item of the target data can be specifically divided into the following cases.
[0099] Case 1: after obtaining a data access request, if it is determined that the cache is full and the target data is not stored in the cache, the dynamic age of the target data is set in the data item of the target data as the retention weight of the current replacement data, wherein the current replacement data is the data that is replaced and removed from the cache due to the storage of the target data;
[0100] If the cache is full and the target data is not stored in the cache, the target data needs to be loaded from the cache data source into the cache, and the cache replacement algorithm is used to determine the current replacement data and remove the current replacement data from the cache to make room for the target data. At this time, the current replacement data is the replacement data corresponding to the target data (that is, the current replacement data is replaced and removed from the cache due to the storage of the target data), so that the dynamic age of the target data can be set to the retention weight of the current replacement data, that is, the target data can inherit the retention weight of the current replacement data through the dynamic age; further, on the basis of the dynamic age of the target data being set to the retention weight of the current replacement data, the dynamic age of the target data can at least decrease with the retention time of the target data in the cache.
[0101] Case 2: After obtaining a data access request, if it is determined that the cache is full and the target data is stored in the cache, the dynamic age of the target data is set in the data item of the target data as: the dynamic age of the recorded target data, and the superposition result of the retention weight of the last replacement data; for example, the dynamic age of the recorded target data is added to the retention weight of the last replacement data; wherein the last replacement data is the data removed by the last replacement in the cache;
[0102] If the cache is full and the target data is stored in the cache, the data item of the target data has recorded the dynamic age of the target data. Since the target data is accessed by the data access request (i.e., the target data has use value), and the storage space of the cache is currently full, the use value of the target data can be improved by setting the dynamic age of the target data, thereby reducing the probability of the target data with use value being kicked out in the future. Based on this, in the embodiment of the present application, when the cache is full and the target data is stored in the cache, the dynamic age of the target data can be inherited on the basis of the record, and then the retention weight of the last replacement data can be inherited. For example, the dynamic age of the target data recorded in the data item of the target data is added to the retention weight of the last replacement data, thereby improving the use value of the target data. It should be noted that when the cache is full and the target data is stored in the cache, the cache replacement algorithm does not trigger execution, so there is no current replacement data in the cache. The last replacement data can be regarded as the replacement data determined by the cache using the cache replacement algorithm last time (i.e., the most recently determined replacement data), that is, the data removed from the cache replacement last time (i.e., the most recently removed from the cache replacement data).
[0103] Case three, after obtaining the data access request, if it is determined that the cache is not full, the dynamic age of the target data is set to a preset initial dynamic age (the preset initial dynamic age is, for example, 0) in the data item of the target data.
[0104] It should be noted that, when the cache is not full, the target data may or may not be stored in the cache. If the cache is not full and the target data is not stored in the cache, the target data needs to be loaded from the cache data source to the cache, and since the cache still has storage space for the target data, the cache replacement algorithm is not triggered, so the target data does not have corresponding current replacement data, and the dynamic age of the target data can be set to a preset initial dynamic age (such as 0).
[0105] If the cache is not full and the target data has been stored in the cache, the embodiment of the present application adjusts the dynamic age of the target data recorded in the data item of the target data to a preset initial dynamic age (e.g., 0). That is, when the cache is not full and the target data has been stored in the cache, although the dynamic age of the target data recorded in the data item of the target data exists, the dynamic age of the target data recorded will be adjusted to the preset initial dynamic age (e.g., 0).
[0106] It should be further explained that the dynamic age of the data is negatively correlated with the storage time of the data in the cache (for example, an inverse relationship). For example, the dynamic age of the data decreases with the storage time. Therefore, the dynamic age of the data may be a positive value (for example, when inheriting the retention weight of the current replacement data or the retention weight of the previous replacement data), or it may be a negative value (for example, the dynamic age of the data gradually decreases to a value less than 0 with the passage of storage time); at the same time, the dynamic age of the data is a superposition factor in the calculation of the retention weight, so when the superimposed dynamic age is a positive value, the corresponding retention weight result increases, and when the superimposed dynamic age is a negative value, the corresponding retention weight result decreases. Based on this, the embodiments of the present application can adjust the dynamic age of the target data recorded in the data item of the target data to the preset initial dynamic age when the cache is not full and the target data has been stored in the cache, thereby avoiding the situation where data that has been stored in the cache for a long time but is still accessed has a smaller retention weight due to the negative value of the dynamic age; that is, when the cache is not full and the target data has been stored in the cache, the embodiments of the present application adjust the dynamic age of the target data recorded in the data item of the target data to the preset initial dynamic age, and the retention weight of the target data stored in the cache can be recalibrated to avoid the situation where data that has a high data acquisition cost and is still accessed has a smaller retention weight due to the long storage time, thereby achieving the goal of the cache replacement algorithm.
[0107] As an optional implementation, for the target data requested by the data access request, the embodiment of the present application can obtain the cost index consumed by the cache to obtain the target data, the access frequency of the target data, and the dynamic age of the target data from the data item of the target data; determine the data acquisition cost of the target data based on the obtained cost index consumed by the cache to obtain the target data; comprehensively consider the data acquisition cost of the target data and the access frequency of the obtained target data to obtain the comprehensive result of the target data; and then superimpose the comprehensive result of the target data with the dynamic age of the obtained target data to obtain the retention weight of the target data. The relevant optional implementation content can refer to the description of the corresponding part of the previous text, which will not be expanded here.
[0108] In step S213, the target data is saved in the cache and the retention weight of the target data is indicated; and the target data is output in response to the data access request.
[0109] After determining the retention weight of the target data, an embodiment of the present application can save the target data in the cache and indicate the retention weight of the target data, so that when a subsequent cache replacement algorithm is triggered, replacement data can be determined based on the retention weight of the data (including the target data) saved in the cache.
[0110] As an optional implementation, the embodiment of the present application can save the target data in the cache and indicate the retention weight of the target data when the cache replacement algorithm is triggered or when the cache replacement algorithm is not triggered. The situations of triggering and not triggering the cache replacement algorithm can refer to the description of the corresponding part above.
[0111] Taking the case of triggering a cache replacement algorithm as an example, after obtaining a data access request, if it is determined that the cache is full and the target data is not stored in the cache (i.e., the cache is full and the cache misses), the cache obtains the target data from the cache data source and triggers the cache replacement algorithm; further, the embodiment of the present application can determine the current replacement data and remove the current replacement data from the cache to make room for storing the target data in the cache.
[0112] In an optional implementation, after obtaining a data access request, if the cache replacement algorithm is triggered (i.e., it is determined that the cache is full and the target data is not stored in the cache), the embodiment of the present application can determine the current replacement data of the cache based on the retention weight of the data stored in the cache and remove the current replacement data from the cache so as to save the target data in the cache.
[0113] In a further optional implementation, the embodiment of the present application can use the data with the lowest retention weight stored in the cache as the current replacement data and remove the current replacement data from the cache. That is, for the data stored in the cache, the data with the lowest retention weight has the lowest priority to be retained in the cache and can be used as the current replacement data and removed from the cache.
[0114] In other optional implementations, the embodiments of the present application may not be limited to using the data with the lowest retention weight as the current replacement data, as long as the retention weight of the current replacement data is lower than the data stored in the cache; for example, the data with the second lowest retention weight may be used as the current replacement data, any random data with a retention weight lower than a preset retention weight threshold may be used as the current replacement data, any random data with a retention weight lower than the average retention weight of the stored data may be used as the current replacement data, etc.
[0115] In an optional implementation, the storage location of the data item of the data in the cache management data structure may indicate the retention weight of the data. Accordingly, the embodiment of the present application may store the target data in the cache according to the retention weight of the target data, wherein the storage location of the data item of the target data in the cache management data structure indicates the retention weight of the target data, so as to store the target data in the cache and indicate the retention weight of the target data.
[0116] In a further optional implementation, the embodiment of the present application can determine the order of the data items in the cache management data structure according to the order of the retention weights of the data stored in the data items, so as to indicate the retention weight of the data through the storage position of the data items of the data; that is, the data items are sorted according to the order of the retention weights of the stored data, so that the storage position of the data items of the data in the cache management data structure can indicate the retention weight of the data. Accordingly, the embodiment of the present application can determine the order of the data items of the target data in the cache management data structure according to the retention weight of the target data, and insert the data items of the target data at the position corresponding to the determined order.
[0117] In an optional implementation example, the cache may sort the data items in descending order of the retention weights of the data stored in the data items (i.e., in order from large to small); that is, the data items are sorted in descending order of the retention weights of the stored data. Thus, the retention weights of the data stored in the data items closer to the front are greater, and the retention weights of the data stored in the data items closer to the back are smaller. Furthermore, when the cache replacement algorithm is triggered, the data stored in the last data item of the cache management data structure may be used as the current replacement data and the last data item may be removed, and accordingly, the data of the corresponding mapped cache line in the cache is removed; that is, at this time, the data stored in the last data item is the data with the lowest retention weight, and is used as the replacement data determined by the cache replacement algorithm.
[0118] In an optional implementation example, the cache may sort the data items in ascending order of the retention weights of the data stored in the data items (i.e., in order from small to large); that is, the data items are sorted in ascending order of the retention weights of the stored data. Thus, the retention weights of the data stored in the data items closer to the front are smaller, and the retention weights of the data stored in the data items closer to the back are larger. Furthermore, when the cache replacement algorithm is triggered, the data stored in the head data item of the cache management data structure may be used as the current replacement data and the head data item may be removed, and accordingly, the data of the corresponding mapped cache line in the cache is removed; that is, at this time, the data stored in the head data item is the data with the lowest retention weight, and is used as the replacement data determined by the cache replacement algorithm.
[0119] As an example, the data item may be a linked list node of a cache linked list, and is mapped to a cache line in the cache. Thus, the linked list nodes in the cache linked list may be sorted in order from large to small, or from small to large, according to the retention weight of the stored data. For example, the sorting of the linked list nodes in the cache linked list may be determined according to the descending order of the retention weight of the data stored in the linked list nodes (i.e., the order from large to small), so that when the cache replacement algorithm is triggered, the data corresponding to the last linked list node of the cache linked list may be used as replacement data, and then the last linked list node of the cache linked list is removed, and accordingly, the data of the cache line corresponding to the mapping in the cache is removed. For another example, the sorting of the linked list nodes in the cache linked list may be determined according to the ascending order of the retention weight of the data stored in the linked list nodes (i.e., the order from small to large), so that when the cache replacement algorithm is triggered, the data corresponding to the first linked list node of the cache linked list may be used as replacement data, and then the first linked list node of the cache linked list is removed, and accordingly, the data of the cache line corresponding to the mapping in the cache is removed.
[0120] In order to keep the data items in the cache management data structure sorted in the order of the retention weights of the stored data, the embodiments of the present application can adjust the sorting of the data items in the cache management data structure according to the updated retention weights of the data when the retention weights of any data are updated; that is, if the retention weights of any data in the cache are updated, the data items of the data can be re-determined in the sorting position according to the updated retention weights of the data, so that the data items in the cache management data structure can be kept sorted in the order of the retention weights of the stored data. Based on the description of the corresponding part of the previous text, the update of the retention weight of the data may be the update of the access frequency recorded in the data items of the data, the dynamic age update, etc., and the relevant content can refer to the previous description and will not be expanded here.
[0121] In other possible implementations, the embodiments of the present application may also record the retention weight of each data in the cache to indicate the retention weight of the data; for example, the embodiments of the present application may save the target data in the cache and record the retention weight of the target data to indicate the retention weight of the target data when the target data is saved in the cache. As an optional implementation, record information may be set in the cache, so that the retention weight of each data is recorded through the record information; further, the embodiments of the present application may, when triggering the cache replacement algorithm, use the data with the lowest retention weight as the current replacement data based on the retention weight of each data recorded in the record information, and remove the data item corresponding to the data with the lowest retention weight, and accordingly, the corresponding mapped cache line in the cache is removed. In an optional implementation example, the embodiments of the present application may record the retention weight of the data in the data item of the data; accordingly, the embodiments of the present application may record the retention weight of the target data in the data item of the target data in the cache management data structure.
[0122] Furthermore, after the target data is saved in the cache, the embodiment of the present application can feed back the target data to the upstream module (ie, output the target data to the upstream module) in response to the data access request.
[0123] In the data processing method of the cache provided in the embodiment of the present application, the cache replacement algorithm can use the retention weight of the data to determine the replacement data, the retention weight of the data indicates the priority of the data to be retained in the cache, and the retention weight of the data is determined at least according to the data acquisition cost of the data; thus, after the cache obtains the data access request for the target data, it can determine the data acquisition cost of the target data; at least according to the data acquisition cost of the target data, determine the retention weight of the target data; then, save the target data in the cache and indicate the retention weight of the target data, so as to provide a basis for the implementation of the cache replacement algorithm; at the same time, the embodiment of the present application can output the target data in response to the data access request. It can be seen that the embodiment of the present application provides a cache replacement algorithm that takes the data acquisition cost into consideration, which can realize the use of data with a lower data acquisition cost as replacement data, and retain data with a higher data acquisition cost in the cache, thereby reducing the higher data acquisition cost caused by the need to obtain data with a higher data acquisition cost again after being replaced and removed, thereby improving the overall data processing performance of the cache application system.
[0124] In the optional implementation example, Figure 4 Another flowchart of the cache data processing method provided in an embodiment of the present application is exemplarily shown. The method can be executed by the cache. Figure 4 The method flow may include the following steps.
[0125] In step S410, a data access request sent by an upstream module is obtained, where the data access request is used to request target data.
[0126] In step S411, determine whether the cache is full, if not, execute step S412, if so, execute step S413.
[0127] Whether the cache is full indicates whether the cache has free storage space, that is, whether the storage space of the cache has been completely filled with data.
[0128] In step S412, the dynamic age of the target data is set to the preset initial dynamic age, and the access frequency is set to the preset initial access frequency in the data item of the target data.
[0129] For example, the dynamic age L of the target data can be set to 0 and the access frequency F to 1 in the data item of the target data; further, the data item of the target data also records the cost index consumed by the cache to obtain the target data, such as latency. Optionally, the dynamic age, access frequency, and cost index (such as latency) can be recorded in the additional tag information of the data item. After executing step S412, step S416 can be entered.
[0130] In step S413, it is determined whether the target data is in the cache, if not, step S414 is executed, and if so, step S415 is executed.
[0131] As an optional implementation, the data may have an identifier, and the cache may determine whether the target data requested by the data access request has been stored in the cache by using the identifier of the stored data. Optionally, the identifier of the data may be recorded in the basic tag information of the data item.
[0132] In an optional implementation, the data access request may carry an identifier of the target data, so that the cache can query the identifier of the stored data to see whether it matches the identifier of the target data carried by the data access request, so as to determine whether the target data is in the cache. That is, if the identifier carried by the data access request is an identifier of data already stored in the cache, then the target data requested by the data access request is already stored in the cache, i.e., a cache hit; if the identifier carried by the data access request is not an identifier of data already stored in the cache, then the target data requested by the data access request is not stored in the cache, i.e., a cache miss.
[0133] It should be noted that the data identifier may be in different forms based on different application scenarios of the cache. For example, in a chip that applies a cache mechanism, the data identifier may be the memory address of the data. For another example, in a communication network that applies a cache mechanism, the data identifier may be the data's URL (Uniform Resource Locator), file name, or other network resource identifier.
[0134] In step S414, the data stored in the last data item is used as the current replacement data, and the last data item is removed; and the dynamic age of the target data is set in the data item of the target data as the retention weight of the current replacement data and the access frequency is set to the preset initial access frequency.
[0135] In an optional implementation, if the cache is full and the target data is not in the cache, the target data is obtained from the cache data source to the cache, and the cache replacement algorithm is triggered; in an optional implementation example, the data items in the cache management data structure based on the cache are sorted in descending order of the retention weight of the stored data, and the cache replacement algorithm can use the data stored in the last data item in the cache management data structure as the current replacement data and remove the last data item; at the same time, the target data obtained from the cache data source is organized in the form of data items, and the dynamic age L of the target data is set to the retention weight of the current replacement data and the access frequency F is set to 1 in the data item of the target data; further, the data item of the target data also records the cost indicators consumed by the cache to obtain the target data, such as latency, etc. After executing step S414, step S416 can be entered.
[0136] In step S415, in the data item of the target data, the dynamic age of the target data is set to: the dynamic age of the recorded target data plus the retention weight of the last replaced data; and, in the data item of the target data, the access frequency of the recorded target data is updated according to an increase in the access to the target data.
[0137] In an optional implementation, if the cache is full and the target data is already in the cache, the dynamic age L of the target data can be set in the data item of the target data as: the dynamic age of the recorded target data plus the retention weight of the last replaced data; and the access frequency F of the target data can be set in the data item of the target data as: the access frequency of the recorded target data plus 1 (that is, the access frequency of the recorded target data is updated according to the increase of one access to the target data); further, the data item of the target data also records the cost indicators consumed by the cache to obtain the target data, such as latency.
[0138] In step S416, the retention weight of the target data is determined according to the cost index of the target data consumed by the cache, the access frequency of the target data, and the dynamic age of the target data recorded in the data item of the target data.
[0139] In an optional implementation, the cost index consumed by the cache to obtain the target data, the access frequency of the target data, and the dynamic age of the target data can be obtained from the data item of the target data (for example, the additional tag information of the data item of the target data), and then the retention weight of the target data can be calculated. Based on the cost index, access frequency and dynamic age, the method of determining the retention weight can refer to the description of the corresponding part of the previous text, such as the retention weight is expressed as W = L + F × P, and the embodiments of this application will not be expanded here.
[0140] In step S417, the data items of the target data are inserted into the cache management data structure of the cache according to the retention weight of the target data, wherein the data items in the cache management data structure are sorted in descending order of the retention weight of the stored data; and the target data are fed back to the upstream module.
[0141] In an application example, Figure 5 An example diagram of an application provided by an embodiment of the present application is shown, taking the latency of obtaining data from the cache as the cost of obtaining data as an example, such as Figure 5 As shown, due to the different distances between the cache and different cache data sources, the propagation delays between the cache and different cache data sources are different, which affects the latency of the cache obtaining data from different cache data sources. For example, the latency of the cache obtaining data from cache data source 3 is greater than the latency of obtaining data from cache data source 2, and greater than the latency of obtaining data from cache data source 1. In other words, based on the different distances between the cache and cache data sources 1, 2, and 3, the latency of the cache obtaining data from cache data sources 1, 2, and 3 is, from large to small, the latency of obtaining data from cache data source 3, the latency of obtaining data from cache data source 2, and the latency of obtaining data from cache data source 1.
[0142] For example, in a communication network, the cache may be an edge cache, and different cache data sources represent data centers of different ISPs, and the latency from the edge cache to data centers of different ISPs is different. For another example, in a chip, the cache may be an on-chip cache (such as an L1 cache or an L2 cache, etc.), and different cache data sources represent memories on different DIEs (such as a wafer), so that the latency from the core of the processor corresponding to the on-chip cache to different DIEs is different.
[0143] exist Figure 5Based on the example, taking the data D1 of cache data source 1 and the data D3 of cache data source 3 in the cache as an example, assuming that the access frequency of data D1 is high, since the cache is close to cache data source 1, if the cache replacement algorithm chooses to remove data D1 between data D1 and data D3, the cache can subsequently reacquire data D1 with a lower delay. Assume that the delay for the cache to obtain data D1 is T1; further, assuming that the access frequency of data D3 is low, but since the cache is far from cache data source 3, if the cache replacement algorithm chooses to remove data D3 between data D1 and data D3, the cache needs to reacquire data D3 with a longer delay later. Assuming that the delay for the cache to obtain data D3 is T3, T3 is greater than T1.
[0144] Based on the cache replacement algorithm that considers the data acquisition cost in the embodiment of the present application (the cache replacement algorithm can also further consider the use value of data such as access frequency and dynamic age), if the calculated retention weight of data D3 is greater than the retention weight of data D1, then the cache replacement algorithm in the embodiment of the present application can choose to remove D1 from data D1 and data D3; if the calculated retention weight of data D1 is greater than the retention weight of data D3, then the cache replacement algorithm in the embodiment of the present application can choose to remove D3 from data D1 and data D3. Therefore, based on the calculated retention weight of data D1 and the retention weight of data D3, the embodiment of the present application has the situation of frequently re-acquiring data D1 with a lower latency, and the situation of occasionally re-acquiring data D3 with a higher latency (corresponding to a higher data acquisition cost). Therefore, within a certain time window, the embodiment of the present application can reduce the overall data acquisition cost of the system. For example, after the cache has been running for a period of time, the total delay of the cache in acquiring data from the cache data source can be minimized, thereby improving the overall data processing performance of the system.
[0145] In a further optional implementation, the embodiment of the present application also provides a cache, and the relevant content of the cache described below can refer to the description of the corresponding part of the previous text, that is, the content described below can be referenced to the content described in the previous text.
[0146] As an optional implementation, Figure 6 An example diagram of a cache provided by an embodiment of the present application is shown as follows: Figure 6 As shown, the cache may include cache control logic 610; wherein the cache control logic may be configured to execute the cache data processing method provided in the embodiment of the present application, and the relevant contents of the cache data processing method provided in the embodiment of the present application may refer to the previous description.
[0147] In an alternative implementation, cache control logic can be used to:
[0148] Obtaining a data access request, where the data access request is used to request target data;
[0149] Determine the data acquisition cost of the target data;
[0150] Determine the retention weight of the target data at least according to the data acquisition cost of the target data; wherein the retention weight of any data in the cache is determined at least according to the data acquisition cost of the data, and the retention weight of the data represents the priority of the data in the cache, which is used by the cache replacement algorithm to determine the replacement data;
[0151] storing the target data in a cache and indicating a retention weight of the target data; and outputting the target data in response to the data access request.
[0152] For the relevant functional contents of the cache control logic, please refer to the description of the corresponding part in the previous text.
[0153] In an optional implementation, the cache control logic may be a core component of cache management, responsible for executing cache-related control operations and management policies. For example, the cache control logic may be implemented by hardware, for example, the cache control logic may be embedded in a cache controller, so that the function of the cache control logic may be implemented as the function of the cache controller.
[0154] Further integration Figure 6 As shown, the cache may also include a cache management data structure 620, which includes multiple data items 621, one data item corresponding to one data; for example, the cache management data structure may be a cache linked list, which includes multiple linked list nodes. The data items of the data (such as the additional tag information of the data items) are recorded as follows:
[0155] The cost indicator of cache data acquisition is used to determine the data acquisition cost;
[0156] The use value of the data, which is updated at least as the data is used, so as to update the retention weight of the data;
[0157] Among them, the retention weight of the data is determined according to the data acquisition cost and usage value.
[0158] In an optional implementation, the use value of the data includes the access frequency of the data and the dynamic age of the data; the access frequency of the data is updated at least with the number of times the data is accessed in the cache, so as to update the retention weight of the data; the dynamic age of the data at least indicates the use value corresponding to the retention time of the data in the cache, and the dynamic age of the data is updated at least with the retention time of the data in the cache and is negatively correlated, so as to update the retention weight of the data.
[0159] In an optional implementation, the retention weight of the data may be: a comprehensive result of the data acquisition cost and the access frequency of the data, superimposed with the dynamic age of the data.
[0160] In an optional implementation, the multiple data items in the cache management data structure of the cache may be sorted in order of the retention weights of the stored data.
[0161] In a further optional implementation, the embodiment of the present application further provides a cache application system, combined with Figure 1 As shown, the cache application system may include an upstream module, a cache, and a cache data source; wherein the cache is a cache as provided in the embodiment of the present application, for example Figure 6 Cache for samples.
[0162] In an optional implementation, the cache application system may be a chip, and accordingly, the upstream module may be a processor core, the cache may be an on-chip cache, and the cache data source may be a memory. In an optional implementation, the cache application system may be a communication network system, and accordingly, the upstream module may be a user device, the cache may be an edge cache, and the cache data source may be a data center of an Internet service provider.
[0163] In a further optional implementation, the embodiment of the present application further provides an electronic device (such as a terminal device or a server device), which may include a chip, such as a SOC (System on Chip), and the chip may include a cache provided by the embodiment of the present application, such as Figure 6 Cache for samples.
[0164] The above describes multiple implementation schemes provided by the embodiments of the present application. The various optional methods introduced in each implementation scheme can be combined and cross-referenced with each other without conflict, thereby extending a variety of possible implementation schemes, which can all be considered as implementation schemes disclosed and open in the embodiments of the present application.
[0165] Although the embodiments of the present application are disclosed above, the present application is not limited thereto. Any person skilled in the art may make various changes and modifications without departing from the spirit and scope of the present application. Therefore, the scope of protection of the present application shall be subject to the scope defined by the claims.
Claims
1. A cached data processing method, characterized in that: Applied to caching, the method comprises: Obtaining a data access request, where the data access request is used to request target data; Determine the data acquisition cost of the target data; Determine the retention weight of the target data at least according to the data acquisition cost of the target data; wherein the retention weight of any data in the cache is determined at least according to the data acquisition cost of the data, and the retention weight of the data represents the priority of the data in the cache, which is used by the cache replacement algorithm to determine the replacement data; storing the target data in a cache and indicating a retention weight of the target data; and outputting the target data in response to the data access request.
2. The method according to claim 1, characterized in that: The data acquisition cost of the data is determined according to the cost index consumed by the cache to acquire the data; wherein the cache manages the data stored in the cache through a cache management data structure, the cache management data structure includes data items of the data, and the data items of the data record the cost index consumed by the cache to acquire the data; The data acquisition cost of determining the target data includes: Obtaining a cost indicator consumed by cache acquisition of target data from a data item of the target data; The data acquisition cost of the target data is determined according to the cost indicator consumed by obtaining the target data from the cache.
3. The method according to claim 2, characterized in that The retention weight of the data is also determined according to the use value of the data; and the data item of the data records the use value of the data, and the use value of the data is updated at least according to the use of the data, so as to update the retention weight of the data; The method further comprises: After obtaining the data access request, setting the use value of the target data in the data item of the target data, and the use value of the target data is updated along with the use of the target data, so as to update the retention weight of the target data; Determining the retention weight of the target data at least according to the data acquisition cost of the target data includes: Obtaining the use value of the target data from the data item of the target data; The retention weight of the target data is determined based on the data acquisition cost of the target data and the usage value of the obtained target data.
4. The method according to claim 3, characterized in that The use value of the data includes the access frequency of the data, wherein the retention weight of the data is determined at least based on the comprehensive result of the access frequency of the data and the cost of obtaining the data; and the data item of the data records the access frequency of the data, and the access frequency of the data is updated at least with the number of times the data is accessed in the cache, so as to update the retention weight of the data.
5. The method according to claim 4, characterized in that After obtaining the data access request, setting the use value of the target data in the data item of the target data includes: After obtaining the data access request, if it is determined that the cache is full and the target data is not stored in the cache, setting the access frequency of the target data to a preset initial access frequency in the data item of the target data; or, After obtaining the data access request, if it is determined that the cache is full and the target data is already stored in the cache, an access is added according to the target data, and the access frequency of the target data recorded in the data item of the target data is updated; or, After obtaining the data access request, if it is determined that the cache is not full, the access frequency of the target data is set to a preset initial access frequency in the data item of the target data.
6. The method according to claim 5, characterized in that The obtaining the use value of the target data from the data item of the target data comprises: obtaining the access frequency of the target data from the data item of the target data; Determining the retention weight of the target data according to the data acquisition cost of the target data and the use value of the acquired target data includes: The data acquisition cost of the target data and the access frequency of the obtained target data are combined to obtain a comprehensive result of the target data; At least based on the comprehensive results of the target data, the retention weight of the target data is determined.
7. The method according to claim 6, characterized in that The use value of the data also includes the dynamic age of the data, and the dynamic age of the data at least indicates the use value corresponding to the storage time of the data in the cache; wherein the retention weight of the data is: the result of the combined result of the data acquisition cost and the access frequency of the data, and the result after the dynamic age of the data is superimposed; Furthermore, the data item of the data records the dynamic age of the data, and the dynamic age of the data is updated at least with the retention time of the data in the cache and is negatively correlated, so as to be used for updating the retention weight of the data.
8. The method according to claim 7, characterized in that After obtaining the data access request, setting the use value of the target data in the data item of the target data further includes: After obtaining the data access request, if it is determined that the cache is full and the target data is not stored in the cache, then the dynamic age of the target data is set in the data item of the target data as the retention weight of the current replacement data, wherein the current replacement data is the data that is replaced and removed from the cache due to the storage of the target data; or, After obtaining a data access request, if it is determined that the cache is full and the target data is stored in the cache, the dynamic age of the target data is set in the data item of the target data as: the dynamic age of the recorded target data, and the superposition result of the retention weight of the last replacement data; wherein the last replacement data is the data removed by the last replacement in the cache; or, After obtaining the data access request, if it is determined that the cache is not full, the dynamic age of the target data is set to a preset initial dynamic age in the data item of the target data; The dynamic age of the target data set by the data item of the target data is updated at least with the storage time of the target data in the cache, so as to be used for updating the retention weight of the target data.
9. The method according to claim 8, characterized in that The obtaining the use value of the target data from the data item of the target data also includes: Obtaining the dynamic age of the target data from the data item of the target data; Determining the retention weight of the target data at least according to the comprehensive result of the target data includes: The comprehensive result of the target data is superimposed with the obtained dynamic age of the target data to obtain the retention weight of the target data.
10. The method according to claim 1, characterized in that Also includes: After obtaining a data access request, if it is determined that the cache is full and the target data is not stored in the cache, the cache replacement algorithm is triggered to determine the current replacement data of the cache and remove the current replacement data from the cache based on the retention weight of the data stored in the cache, so as to save the target data in the cache.
11. The method according to claim 10, characterized in that The retention weight of the data is negatively correlated with the probability of the data becoming replacement data; determining the current replacement data of the cache and removing the current replacement data from the cache according to the retention weight of the data stored in the cache includes: The data with the lowest retention weight stored in the cache is used as the current replacement data and the current replacement data is removed from the cache.
12. The method according to any one of claims 2 to 9, characterized in that: The storing of the target data in the cache and indicating the retention weight of the target data comprises: The target data is stored in the cache according to the retention weight of the target data; wherein the storage position of the data item of the target data in the cache management data structure indicates the retention weight of the target data.
13. The method according to claim 12, characterized in that The storing the target data in the cache according to the retention weight of the target data includes: According to the retention weight of the target data, the order of the data items of the target data in the cache management data structure is determined, and the data items of the target data are inserted at the position corresponding to the determined order; wherein the data items are sorted in the order of the retention weight of the stored data.
14. The method according to claim 13, characterized in that Also includes: If the retention weight of any data stored in the cache is updated, the order of the data items in the cache management data structure is adjusted according to the updated retention weight of the data to keep the data items sorted in order of the retention weight of the stored data.
15. The method of claim 14, wherein the data items are sorted in descending order of the retention weight of the stored data, wherein: The data stored in the last data item has the lowest retention weight and is used as the replacement data determined by the cache replacement algorithm; Alternatively, the data items are sorted in ascending order of the retention weights of the stored data, wherein the data stored in the first data item has the lowest retention weight and is used as the replacement data determined by the cache replacement algorithm.
16. The method according to any one of claims 2 to 9, characterized in that: The cost indicator consumed by the cache to obtain data includes at least one of the following: The latency of caching data; The power consumption of cache to retrieve data; The bandwidth used to obtain data from the cache.
17. A cache, characterized in that: include: Cache control logic; The cache control logic is configured to execute the cache data processing method according to any one of claims 1-16.
18. The cache according to claim 17, characterized in that: Also includes: A cache management data structure; the cache management data structure includes data items of data; The data item records are: The cost indicator of cache data acquisition is used to determine the data acquisition cost; The use value of the data, which is updated at least as the data is used, so as to update the retention weight of the data; Among them, the retention weight of the data is determined according to the data acquisition cost and usage value.
19. The cache according to claim 18, characterized in that: The use value of the data includes the access frequency of the data and the dynamic age of the data; the access frequency of the data is updated at least with the number of times the data is accessed in the cache, so as to update the retention weight of the data; The dynamic age of the data at least indicates the use value corresponding to the storage time of the data in the cache. The dynamic age of the data is at least updated with the storage time of the data in the cache and is negatively correlated, so as to be used to update the retention weight of the data; The retention weight of the data is: the comprehensive result of the data acquisition cost and the access frequency of the data, superimposed with the dynamic age of the data.
20. The cache according to any one of claims 18 to 19, characterized in that: The data items are sorted in order of the retention weights of the stored data.
21. A cache application system, characterized in that: It includes an upstream module, a cache, and a cache data source; wherein the cache is a cache as described in any one of claims 17-20.
22. The cache application system according to claim 21, characterized in that: The cache application system is a chip, the upstream module is a processor core, the cache is an on-chip cache, and the cache data source is a memory; Alternatively, the cache application system is a communication network system, the upstream module is a user device, the cache is an edge cache, and the cache data source is a data center of an Internet service provider.
23. An electronic device, characterized in that: Comprising a chip, wherein the chip comprises a cache as described in any one of claims 17-20.