Cache replacement method, device, equipment and storage medium

By dividing the cache space into two categories and dynamically adjusting it according to the access frequency, the problem of limited adaptability and scope of application of existing cache replacement algorithms is solved, and more efficient cache management and operation efficiency is achieved.

CN119357087BActive Publication Date: 2025-05-06BEIJING OCEANBASE TECHNOLOGY CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411920577.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-12-24
Publication Date
2025-05-06
Estimated Expiration
2044-12-24

AI Technical Summary

Technical Problem

The existing cache replacement algorithms have limitations in their adaptability and scope of application, making it difficult to effectively support complex data access patterns in high-performance computing environments.

Method used

The cache space is divided into a first main cache area for storing once accessed and a second main cache area for storing many accessed times. By obtaining the total data size of each area, it is determined whether the preset cache element removal threshold is exceeded. If it exceeds, the cold data element is selected from each area for removal processing.

Benefits of technology

The loading and removal of cache elements is realized, avoiding the situation of synchronous detection of cache space satisfaction, and improving the operation efficiency and adaptability of caches.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119357087B_ABST
    Figure CN119357087B_ABST
Patent Text Reader

Abstract

One or more embodiments of the present application provide a cache replacement method, apparatus, device and storage medium, wherein the cache space includes a first main cache area for storing cache elements that have been accessed once and a second main cache area for storing cache elements that have been accessed multiple times; the method includes: obtaining the total data size of the cache elements in the first main cache area, and obtaining the total data size of the cache elements in the second main cache area; determining whether the sum of the total data size of the cache elements in the first main cache area and the total data size of the cache elements in the second main cache area is greater than a preset cache element removal threshold; if the sum of the total data size of the cache elements in the first main cache area and the total data size of the cache elements in the second main cache area is greater than the cache element removal threshold, selecting cold data elements from the first main cache area and the second main cache area, respectively, and performing removal processing on the selected cold data elements.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] One or more embodiments of the present application relate to the field of data storage technology, and in particular, to a cache replacement method, apparatus, device, and storage medium. Background Art

[0002] In computer systems and network environments, cache is widely used as a high-speed memory to improve data access speed and system performance. Cache is located between the processor and the main memory, or even directly integrated into the processor, and is designed to quickly provide the data or instructions required by the CPU or application, thereby reducing processing delays and improving operating efficiency. However, due to the limited physical capacity of the cache, the cache space cannot accommodate all the data that may be needed indefinitely. Therefore, when new data needs to be added to the cache and the cache space is full, some existing data must be selectively removed to free up some cache space. This process is usually called cache replacement.

[0003] With the development of information technology, various applications and services have higher and higher requirements for data access speed. At the same time, different workload characteristics have also brought about complex and diverse data access patterns. In order to meet these challenges and ensure that the cache mechanism can effectively support the high-performance computing environment, a scientific and reasonable strategy is needed to decide which data should be retained in the cache and which data should be removed when necessary. This strategy is usually called a cache replacement algorithm. However, the current cache replacement algorithm still has many limitations, which affects its adaptability and scope of application. Summary of the invention

[0004] One or more embodiments of the present application provide the following technical solutions:

[0005] The present application provides a cache replacement method; wherein the cache space includes a first main cache area for storing cache elements that have been accessed once, and a second main cache area for storing cache elements that have been accessed multiple times; the method includes:

[0006] Obtaining a total data size of cache elements in the first primary cache area, and obtaining a total data size of cache elements in the second primary cache area;

[0007] Determine whether the sum of the total data size of the cache elements in the first primary cache area and the total data size of the cache elements in the second primary cache area is greater than a preset cache element removal threshold;

[0008] If the sum of the total data size of the cache elements in the first main cache area and the total data size of the cache elements in the second main cache area is greater than the cache element removal threshold, cold data elements are selected from the first main cache area and the second main cache area respectively, and removal processing is performed on the selected cold data elements.

[0009] The present application also provides a cache replacement device; wherein the cache space includes a first main cache area for storing cache elements that have been accessed once, and a second main cache area for storing cache elements that have been accessed multiple times; the device includes:

[0010] An acquisition module, which acquires the total data size of the cache elements in the first primary cache area, and acquires the total data size of the cache elements in the second primary cache area;

[0011] A determination module, determining whether the sum of the total data size of the cache elements in the first primary cache area and the total data size of the cache elements in the second primary cache area is greater than a preset cache element removal threshold;

[0012] A removal module, if the sum of the total data size of the cache elements in the first main cache area and the total data size of the cache elements in the second main cache area is greater than the cache element removal threshold, then selects cold data elements from the first main cache area and the second main cache area respectively, and performs removal processing on the selected cold data elements.

[0013] The present application also provides an electronic device, comprising:

[0014] processor;

[0015] a memory for storing processor-executable instructions;

[0016] The processor implements the steps of any of the above methods by running the executable instructions.

[0017] The present application also provides a computer-readable storage medium having computer instructions stored thereon, which implement the steps of any of the above methods when executed by a processor.

[0018] In the above technical solution, the cache space can be divided into a first main cache area for storing cache elements that have been accessed once, and a second main cache area for storing cache elements that have been accessed multiple times, so that when it is determined that the sum of the total data size of the cache elements in the first main cache area and the total data size of the cache elements in the second main cache area is greater than a preset cache element removal threshold, cold data elements can be selected from the first main cache area and the second main cache area respectively, and removal processing can be performed on the selected cold data elements.

[0019] By adopting the above method, the loading of cache elements and the removal of cache elements can be decoupled, that is, it is not necessary to detect whether the cache space is full when loading data into the cache to form a cache element, but it is possible to asynchronously detect whether the cache space is full, and when the cache space is full, selectively remove certain cache elements from the first main cache area and the second main cache area to release part of the cache space. In other words, when loading a new cache element into the cache, it is not necessary to synchronously remove the cache element, but it is possible to asynchronously remove the cache element, thereby improving the operating efficiency of the cache. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] The following is a description of the accompanying drawings required for describing the exemplary embodiments, wherein:

[0021] Figure 1 It is a schematic diagram of a cache space shown in an exemplary embodiment of the present application.

[0022] Figure 2 It is a flowchart of a cache replacement method shown in an exemplary embodiment of the present application.

[0023] Figure 3 It is a schematic diagram of cache space management information shown in an exemplary embodiment of the present application.

[0024] Figure 4 It is a structural schematic diagram of a device shown in an exemplary embodiment of the present application.

[0025] Figure 5 It is a block diagram of a cache replacement device shown in an exemplary embodiment of the present application. DETAILED DESCRIPTION

[0026] Here, exemplary embodiments will be described in detail, and examples thereof are shown in the accompanying drawings. When the following description relates to the accompanying drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with one or more embodiments of the present application. On the contrary, they are only examples consistent with some aspects of one or more embodiments of the present application.

[0027] It should be noted that in other embodiments, the steps of the corresponding method are not necessarily performed in the order shown and described in this application. In some other embodiments, the steps included in the method may be more or less than those described in this application. In addition, a single step described in this application may be decomposed into multiple steps for description in other embodiments; and multiple steps described in this application may also be combined into a single step for description in other embodiments.

[0028] A cache replacement algorithm is a strategy that determines which existing data should be removed to free up some cache space in a computer system's cache when the cache space is full and new data needs to be inserted. The cache replacement algorithm aims to minimize cache misses (i.e., the accessed data is not in the cache) to improve performance and efficiency.

[0029] Common cache replacement algorithms include the First In First Out (FIFO) algorithm, the Least Recently Used (LRU) algorithm, the Least Frequently Used (LFU) algorithm, and the Adaptive Replacement Cache (ARC) algorithm.

[0030] Among them, the FIFO algorithm is one of the simplest replacement algorithms. It selects the oldest data item for replacement based on time order. The disadvantage is that it does not consider the access frequency of the cache item or the possibility of being accessed again in the future.

[0031] The LRU algorithm removes the items that have not been used the longest. It assumes that past behavior can reflect future usage patterns, that is, data that has not been accessed recently is unlikely to be accessed in the future. Specifically, the LRU algorithm records the time t that has elapsed since the last access for each data. When a data needs to be removed, the data with the largest t value among all the current data is selected for removal.

[0032] The LFU algorithm tracks the number of times each cache item is accessed and removes the least accessed data item. It assumes that data that is rarely accessed is less likely to be accessed in the future. Specifically, the LFU algorithm records an access count c for each data item. When a data item needs to be removed, the data item with the smallest c value among all the current data items is selected for removal.

[0033] The ARC algorithm is an adaptive cache algorithm that can dynamically adjust the cache size and replacement strategy based on the cache access pattern and cache data characteristics.

[0034] However, the common cache replacement algorithms currently still have many limitations, which affect their adaptability and scope of application.

[0035] One or more embodiments of the present application provide a technical solution for cache replacement, in which the cache space can be divided into a first main cache area for storing cache elements that have been accessed once, and a second main cache area for storing cache elements that have been accessed multiple times, so that when it is determined that the sum of the total data size of the cache elements in the first main cache area and the total data size of the cache elements in the second main cache area is greater than a preset cache element removal threshold, cold data elements can be selected from the first main cache area and the second main cache area, respectively, and removal processing can be performed on the selected cold data elements.

[0036] By adopting the above method, the loading of cache elements and the removal of cache elements can be decoupled, that is, it is not necessary to detect whether the cache space is full when loading data into the cache to form a cache element, but it is possible to asynchronously detect whether the cache space is full, and when the cache space is full, selectively remove certain cache elements from the first main cache area and the second main cache area to release part of the cache space. In other words, when loading a new cache element into the cache, it is not necessary to synchronously remove the cache element, but it is possible to asynchronously remove the cache element, thereby improving the operating efficiency of the cache.

[0037] Please refer to Figure 1 , Figure 1 is a schematic diagram of a cache space shown in an exemplary embodiment of the present application. Figure 2 , Figure 2 It is a flowchart of a cache replacement method shown in an exemplary embodiment of the present application.

[0038] like Figure 1 As shown, in this embodiment, the cache space may include two main cache areas, respectively referred to as the first main cache area (also referred to as the T1 area) and the second main cache area (also referred to as the T2 area). The first main cache area may be used to store cache elements that have been accessed once, and the second main cache area may be used to store cache elements that have been accessed multiple times. That is, the cache strategy of the first main cache area is similar to the LRU strategy, in which the stored data is usually the most recently accessed data, and the cache strategy of the second main cache area is similar to the LFU strategy, in which the stored data is the most frequently accessed data.

[0039] Specifically, if a data access request misses the cache, the data requested to be accessed needs to be loaded into the cache, and the data can be added to the first main cache area for storage. Subsequently, if a data access request hits the data in the first main cache area, the data can be transferred from the first main cache area to the second main cache area for storage. It can be seen that the first main cache area stores data that has only been accessed once, while the second main cache area stores data that has been accessed multiple times (twice or more).

[0040] By dynamically dividing the cache space into different areas, the cache strategy can be dynamically adjusted according to the cache access pattern. Specifically, the sizes of two of the main cache areas can be dynamically adjusted by monitoring and responding to changes in the cache access pattern, thereby optimizing cache performance. If a data access request hits data stored in the first main cache area, the size of the first main cache area can be increased. Similarly, if a data access request hits data stored in the second main cache area, the size of the second main cache area can be increased. In this way, dynamic adjustment of the sizes of the first main cache area and the second main cache area is achieved.

[0041] It should be noted that a cache element is a basic unit of data in a cache, which is a logical unit with a specific meaning and a set of possible values. A cache element in this application may be data loaded into the cache each time.

[0042] like Figure 2 As shown, the cache replacement method may include the following steps:

[0043] Step 202: Obtain the total data size of the cache elements in the first primary cache area, and obtain the total data size of the cache elements in the second primary cache area.

[0044] Generally, when the cache space is full, if a new data page needs to be loaded into the cache, some data pages need to be removed from the first main cache area and / or the second main cache area to release part of the cache space before the data page can be loaded into the cache. That is, when a new data page is loaded into the cache, the operation of releasing the cache space needs to be performed synchronously. Although this can ensure that there is enough cache space to write the data page each time it is loaded, the efficiency is very low.

[0045] Based on the above, in this embodiment, the loading of cache elements can be decoupled from the removal of cache elements, that is, there is no need to detect whether the cache space is full when loading data into the cache to form cache elements, and when the cache space is full, some cache elements are removed from the first main cache area and / or the second main cache area to release part of the cache space. In other words, when loading new cache elements into the cache, there is no need to synchronously execute the operation of releasing the cache space; loading cache elements into the cache and removing the cache elements to release part of the cache space can be performed asynchronously.

[0046] In the above case, the total data size of all cache elements stored in the above-mentioned first main cache area can be obtained, and the total data size of all cache elements stored in the above-mentioned second main cache area can be obtained to determine whether it is necessary to remove the cache elements in the two main cache areas based on the total data size of the cache elements in the two main cache areas.

[0047] In practical applications, the total data size of the cache elements in the above two main cache areas can be obtained in real time, or the total data size of the cache elements in the above two main cache areas can be obtained regularly according to a certain time period. This application does not impose any special restrictions on this.

[0048] Step 204: Determine whether the sum of the total data size of the cache elements in the first primary cache area and the total data size of the cache elements in the second primary cache area is greater than a preset cache element removal threshold.

[0049] In this embodiment, when the total data size of the cache elements in the above-mentioned two main cache areas is obtained, it can be determined whether the sum of the total data size of the cache elements in the above-mentioned first main cache area and the total data size of the cache elements in the above-mentioned second main cache area is greater than the preset cache element removal threshold.

[0050] Step 206: If the sum of the total data size of the cache elements in the first main cache area and the total data size of the cache elements in the second main cache area is greater than the cache element removal threshold, cold data elements are selected from the first main cache area and the second main cache area respectively, and removal processing is performed on the selected cold data elements.

[0051] In this embodiment, if the sum of the total data size of the cache elements in the first main cache area and the total data size of the cache elements in the second main cache area is greater than the cache element removal threshold, it can be considered that the cache element removal condition is met, so that the cache elements in these two main cache areas can be removed.

[0052] If the sum of the total data size of the cache elements in the first main cache area and the total data size of the cache elements in the second main cache area is greater than the cache element removal threshold, it can be considered that the cache element removal condition has not been met and there is no need to remove the cache elements in these two main cache areas.

[0053] When performing removal processing on the cache elements in the two main cache areas, cold data elements may be selected from the first main cache area and the second main cache area respectively, and removal processing may be performed on the selected cold data elements.

[0054] In some embodiments, when selecting cold data elements from the first main cache area and the second main cache area, respectively, the removal data size corresponding to the first main cache area can be determined based on the area size of the first main cache area, and the removal data size corresponding to the second main cache area can be determined. Subsequently, cold data elements can be selected from the first main cache area for removal processing according to the removal data size corresponding to the first main cache area, and cold data elements can be selected from the second main cache area for removal processing according to the removal data size corresponding to the second main cache area.

[0055] Assuming that the size of the cache space is C, the size of the first main cache area can be expressed as C*m (0≤m≤1). In practical applications, m can be limited to a real number greater than 0, for example, the value range of m can be 0.2≤m≤1, so that the size of the first main cache area can be prevented from being adjusted to 0, thereby causing the first main cache area to be cleared. According to the size of the first main cache area, a parameter p can be determined, which represents the ratio between the size of the first main cache area and the size of the second main cache area, so that according to the p value, the size of the removed data corresponding to the first main cache area can be determined, and the size of the removed data corresponding to the second main cache area can be determined; for example, assuming that the cache element removal threshold is C0, the total data size of the cache elements in the first main cache area is CT1, and the total data size of the cache elements in the second main cache area is CT2, then the size of the removed data corresponding to the first main cache area can be expressed as not less than (CT1+CT2-C0)*p, and the size of the removed data corresponding to the second main cache area can be expressed as not less than (CT1+CT2-C0)*(1-p).

[0056] like Figure 1As shown, in some embodiments, the cache space may further include an auxiliary cache area (i.e., a ghost cache area), referred to as a first auxiliary cache area (also referred to as a B1 area or a T1 ghost area). The first auxiliary cache area may be used to store cache elements removed from the first primary cache area. Data removed from the first auxiliary cache area means that the data is removed from the cache.

[0057] It should be noted that the auxiliary cache area can be used to track the removed data so that better replacement decisions can be made when the same data is accessed again. For example, if a data access request hits the data stored in the auxiliary cache area multiple times, it means that the data may be hot data and should be re-added to the main cache area. In addition, the size of the main cache area can be dynamically adjusted according to the access to the data in the auxiliary cache area. Specifically, if a data access request hits the data stored in the first auxiliary cache area, the size of the first main cache area can be increased, which is equivalent to reducing the size of the second main cache area.

[0058] In the above case, the cold data elements are selected from the first main cache area for removal, that is, the cold data elements are selected from the first main cache area and transferred from the first main cache area to the first auxiliary cache area.

[0059] Since not only the main cache area has a capacity limit, but also the auxiliary cache area has a capacity limit, the total data size of all cache elements stored in the first auxiliary cache area can be obtained, and it is determined whether the sum of the total data size of the cache elements in the first main cache area and the total data size of the cache elements in the first auxiliary cache area is greater than the preset cache element removal threshold. The cache element removal threshold can be the same as or different from the aforementioned cache element removal threshold, and this application does not impose any special restrictions on this.

[0060] If the sum of the total data size of the cache elements in the above-mentioned first main cache area and the total data size of the cache elements in the above-mentioned first auxiliary cache area is greater than the above-mentioned cache element removal threshold, it can be considered that the cache element removal condition is met. In this case, the cache elements in the first auxiliary cache area can be removed.

[0061] If the sum of the total data size of the cache elements in the first main cache area and the total data size of the cache elements in the first auxiliary cache area is greater than the cache element removal threshold, it can be considered that the cache element removal condition has not been met and there is no need to remove the cache elements in the first auxiliary cache area.

[0062] When performing the removal process on the cache elements in the first auxiliary cache area, cold data elements may be selected from the first auxiliary cache area, and the selected cold data elements may be removed from the first auxiliary cache area.

[0063] It should be noted that the total data size of the cold data elements that need to be removed from the first auxiliary cache area, that is, the total data size of the cold data elements selected from the first auxiliary cache area, may be no less than the sum of the total data size of the cache elements in the first main cache area and the total data size of the cache elements in the first auxiliary cache area, and the difference between the cache element removal threshold. For example, assuming that the cache element removal threshold is C0, the total data size of the cache elements in the first main cache area is CT1, and the total data size of the cache elements in the first auxiliary cache area is CB1, then the total data size of the cold data elements selected from the first auxiliary cache area can be expressed as no less than (CT1+CB1-C0).

[0064] like Figure 1 As shown, in some embodiments, the cache space may further include an auxiliary cache area (i.e., a ghost cache area), referred to as a second auxiliary cache area (also referred to as a B2 area or a T2 ghost area). The second auxiliary cache area may be used to store cache elements removed from the second primary cache area. Data removed from the second auxiliary cache area means that the data is removed from the cache.

[0065] It should be noted that the auxiliary cache area can be used to track the removed data so that a better replacement decision can be made when the same data is accessed again. In addition, the size of the main cache area can be dynamically adjusted according to the access to the data in the auxiliary cache area. Specifically, if a data access request hits the data stored in the second auxiliary cache area, the size of the first main cache area can be reduced, which is equivalent to increasing the size of the second main cache area.

[0066] In the above case, the cold data elements are selected from the second main cache area for removal, that is, the cold data elements are selected from the second main cache area and transferred from the second main cache area to the second auxiliary cache area.

[0067] Since not only the main cache area has a capacity limit, but also the auxiliary cache area has a capacity limit, the total data size of all cache elements stored in the second auxiliary cache area can be obtained, and it is determined whether the sum of the total data size of the cache elements in the second main cache area and the total data size of the cache elements in the second auxiliary cache area is greater than the preset cache element removal threshold. The cache element removal threshold can be the same as or different from the aforementioned cache element removal threshold, and this application does not impose any special restrictions on this.

[0068] If the sum of the total data size of the cache elements in the above-mentioned second main cache area and the total data size of the cache elements in the above-mentioned second auxiliary cache area is greater than the above-mentioned cache element removal threshold, it can be considered that the cache element removal condition is met. In this case, the cache elements in the second auxiliary cache area can be removed.

[0069] If the sum of the total data size of the cache elements in the above-mentioned second main cache area and the total data size of the cache elements in the above-mentioned second auxiliary cache area is greater than the above-mentioned cache element removal threshold, it can be considered that the cache element removal condition has not been met and there is no need to remove the cache elements in the second auxiliary cache area.

[0070] When performing the removal process on the cache elements in the second auxiliary cache area, cold data elements may be selected from the second auxiliary cache area, and the selected cold data elements may be removed from the second auxiliary cache area.

[0071] It should be noted that the total data size of the cold data elements that need to be removed from the second auxiliary cache area, that is, the total data size of the cold data elements selected from the second auxiliary cache area, may be no less than the sum of the total data size of the cache elements in the second main cache area and the total data size of the cache elements in the second auxiliary cache area, and the difference between the cache element removal threshold. For example, assuming that the cache element removal threshold is C0, the total data size of the cache elements in the first main cache area is CT2, and the total data size of the cache elements in the first auxiliary cache area is CB2, then the total data size of the cold data elements selected from the first auxiliary cache area can be expressed as no less than (CT2+CB2-C0).

[0072] In some embodiments, the size of the main cache area can also be dynamically adjusted according to the access to the data in the auxiliary cache area. Specifically, when the cache elements in the first auxiliary cache area are accessed, that is, when a data access request hits the data stored in the first auxiliary cache area, the area size of the first main cache area can be increased. Correspondingly, when the cache elements in the second auxiliary cache area are accessed, that is, when a data access request hits the data stored in the second auxiliary cache area, the area size of the first main cache area can be reduced.

[0073] Generally, a linked list can be maintained for each cache area to manage all data stored in the cache area. Specifically, the position of the data in the linked list can reflect the "hotness" of the data. Generally, the data corresponding to the tail of the linked list can be considered as cold data, while the data corresponding to the head of the linked list can be considered as hot data.

[0074] In practical applications, cold data refers to data that is not frequently accessed and may only need to be queried occasionally or used for long-term archiving and backup purposes; hot data refers to data that is frequently accessed, read, or written. Therefore, when removing data from the cache, the cold data in the cache is usually removed. In this case, when a data page needs to be removed from the first primary cache area, a data page is usually removed from the tail of the linked list in the first primary cache area and the data page is inserted into the head of the linked list in the first auxiliary cache area.

[0075] However, in some embodiments, a linked list may no longer be used to manage all cache elements stored in the cache area, and it is no longer necessary to determine whether the data is cold data or hot data based on the position of the data in the linked list. Instead, element metadata corresponding to each cache element in the cache space may be maintained. For a cache element, the element metadata corresponding to the cache element may include time information when the cache element was most recently accessed.

[0076] In the above case, when selecting cold data elements from any one of the first primary cache area, the second primary cache area, the first auxiliary cache area, and the second auxiliary cache area, the cold data elements can be selected from the cache area based on the time information in the element metadata corresponding to each cache element in the cache area. The cold data elements are cache elements whose most recently accessed time is far from the current time.

[0077] For example, the time information may specifically be a timestamp. In this case, the cache elements in the cache area may be sorted according to the timestamps in the element metadata corresponding to the cache elements, and multiple cold data elements with the smallest timestamps may be selected according to the sorting result, so that the total data size of the multiple cold data elements is smaller than the difference between the sum of the total data size of the cache elements in the first primary cache area and the total data size of the cache elements in the first auxiliary cache area and the cache element removal threshold.

[0078] In some embodiments, in order to improve query efficiency, a map class container may be used to manage all cache elements stored in a cache area, that is, element metadata corresponding to each cache element in the cache space may be maintained in a map class container.

[0079] A map container generally refers to a collection of key-value pairs, where each key is unique. In this application, the key in a key-value pair can be a unique identifier of a cache element, and the value can be the element metadata corresponding to the cache element.

[0080] It should be noted that the above map class containers are usually maintained in memory rather than in cache. A map class container corresponding to a cache area usually does not contain the specific content of the cache elements in the cache area, but only contains the unique identifier of the cache element, and uses the unique identifier of the cache element to represent the cache element itself. Through the unique identifier of the cache element, the storage location of the cache element in the cache can also be located, so that the specific content of the cache element can be found.

[0081] In some embodiments, in order to avoid traversing all cache elements stored in the cache area to select a specific number of cold data elements whose most recently accessed time is farthest from the current time, when selecting cold data elements from the cache area based on the above-mentioned time information in the element metadata corresponding to each cache element in the cache area, an excess of candidate cache elements can be randomly selected from the cache area. The total data size of the cold data elements selected from the cache area should not be less than the total data size of the cold data elements that need to be removed from the cache area. Therefore, the excess of candidate cache elements means that the total data size of these candidate cache elements is greater than or even much greater than the total data size of the cold data elements that need to be removed from the cache area.

[0082] Subsequently, cold data elements may be selected from the candidate cache elements based on the time information in the element metadata corresponding to each candidate cache element.

[0083] Usually, each time data is loaded into the cache or removed from the cache, it is necessary to use pages as units, where the data size of the data page is fixed to ensure that for each cache area, the total size of the data stored in the cache area can be obtained by counting the number of data pages in the cache area.

[0084] However, in some embodiments, the region metadata corresponding to the first primary cache region, the second primary cache region, the first auxiliary cache region, and the second auxiliary cache region may be maintained respectively. For a cache region, the region metadata corresponding to the cache region may include the total data size of the cache elements in the cache region.

[0085] In the above case, when obtaining the total data size of the cache elements in a cache area, the total data size in the area metadata corresponding to the cache area can be directly obtained as the total data size of the cache elements in the cache area.

[0086] In this way, since the regional metadata containing the total data size of the cache elements therein is maintained for each cache area, the total data size of the cache elements in the cache area can be directly obtained through the regional metadata, and there is no need to obtain the total data size of the cache elements in the cache area by counting the number of data pages in the cache area. Therefore, each time data is loaded into the cache, or data in the cache is removed, the cache elements can be loaded into the cache, or the cache elements in the cache can be removed, no longer in units of data pages with fixed data size, but in units of cache elements. The data size of the cache element can be any value, and the data size of the cache element is variable.

[0087] Please refer to Figure 3 , Figure 3 It is a schematic diagram of cache space management information shown in an exemplary embodiment of the present application.

[0088] like Figure 3 As shown, for any one of the first main cache area, the second main cache area, the first auxiliary cache area and the second auxiliary cache area, a map class container can be used to maintain element metadata corresponding to each cache element in the cache space. In the map class container, the key in the key-value pair can be a unique identifier of the cache element, and the value can be the element metadata corresponding to the cache element; at the same time, the corresponding area metadata can be maintained for the cache space.

[0089] Furthermore, in some embodiments, a cache element to be loaded (referred to as a target cache element) can be obtained, so that based on the regional metadata corresponding to the above-mentioned first main cache area, it can be determined whether the remaining available size of the first main cache area is not less than the data size of the target cache element. If so, the target cache element can be loaded into the first main cache area for storage, and based on the data size of the target cache element, the regional metadata corresponding to the first main cache area can be updated.

[0090] It should be noted that, although when loading the above-mentioned target cache element, it will be checked whether the remaining available size of the above-mentioned first main cache area is not less than the data size of the target cache element, but if the remaining available size of the first main cache area is less than the data size of the target cache element, the operation of releasing the cache space can be performed asynchronously, and instead, the target cache element can be attempted to be loaded after the asynchronous operation of releasing the cache space is completed.

[0091] In the above technical solution, the cache space can be divided into a first main cache area for storing cache elements that have been accessed once, and a second main cache area for storing cache elements that have been accessed multiple times, so that when it is determined that the sum of the total data size of the cache elements in the first main cache area and the total data size of the cache elements in the second main cache area is greater than a preset cache element removal threshold, cold data elements can be selected from the first main cache area and the second main cache area respectively, and removal processing can be performed on the selected cold data elements.

[0092] By adopting the above method, the loading of cache elements and the removal of cache elements can be decoupled, that is, it is not necessary to detect whether the cache space is full when loading data into the cache to form a cache element, but it is possible to asynchronously detect whether the cache space is full, and when the cache space is full, selectively remove certain cache elements from the first main cache area and the second main cache area to release part of the cache space. In other words, when loading a new cache element into the cache, it is not necessary to synchronously remove the cache element, but it is possible to asynchronously remove the cache element, thereby improving the operating efficiency of the cache.

[0093] Corresponding to the aforementioned method embodiments, the present application also provides device embodiments.

[0094] Please refer to Figure 4 , Figure 4It is a structural diagram of a device shown in an exemplary embodiment of the present application. At the hardware level, the device includes a processor 402, an internal bus 404, a network interface 406, a memory 408 and a non-volatile memory 410, and of course may also include other required hardware. One or more embodiments of the present application can be implemented based on software, such as the processor 402 reading the corresponding computer program from the non-volatile memory 410 into the memory 408 and then running it. Of course, in addition to the software implementation, one or more embodiments of the present application do not exclude other implementations, such as logic devices or a combination of software and hardware, etc., that is to say, the execution subject of the following processing flow is not limited to each logic module, but can also be hardware or logic devices.

[0095] Please refer to Figure 5 , Figure 5 It is a block diagram of a cache replacement device shown in an exemplary embodiment of the present application.

[0096] The cache replacement device can be applied to Figure 4 The device shown in the figure is used to implement the technical solution of the present application. The cache space includes a first main cache area for storing cache elements that have been accessed once, and a second main cache area for storing cache elements that have been accessed multiple times; the device includes:

[0097] An acquisition module 502 is configured to acquire a total data size of cache elements in the first primary cache area and acquire a total data size of cache elements in the second primary cache area;

[0098] The determination module 504 determines whether the sum of the total data size of the cache elements in the first primary cache area and the total data size of the cache elements in the second primary cache area is greater than a preset cache element removal threshold;

[0099] The removal module 506 selects cold data elements from the first main cache area and the second main cache area respectively, and performs removal processing on the selected cold data elements if the sum of the total data size of the cache elements in the first main cache area and the total data size of the cache elements in the second main cache area is greater than the cache element removal threshold.

[0100] In some embodiments, the cache space further includes a first auxiliary cache area for storing cache elements removed from the first primary cache area;

[0101] The cold data elements selected from the first primary cache area are removed, including:

[0102] transferring the selected cold data elements from the first primary cache area to the first auxiliary cache area;

[0103] The device is also used for:

[0104] Obtaining a total data size of cache elements in the first auxiliary cache area;

[0105] Determine whether the sum of the total data size of the cache elements in the first primary cache area and the total data size of the cache elements in the first auxiliary cache area is greater than a preset cache element removal threshold;

[0106] If the sum of the total data size of the cache elements in the first primary cache area and the total data size of the cache elements in the first auxiliary cache area is greater than the cache element removal threshold, a cold data element is selected from the first auxiliary cache area and the selected cold data element is removed from the first auxiliary cache area.

[0107] In some embodiments, the cache space further includes a second auxiliary cache area for storing cache elements removed from the second primary cache area;

[0108] The cold data elements selected from the second primary cache area are removed, including:

[0109] transferring the selected cold data elements from the second primary cache area to the second auxiliary cache area;

[0110] The device is also used for:

[0111] Obtaining a total data size of cache elements in the second auxiliary cache area;

[0112] Determine whether the sum of the total data size of the cache elements in the second primary cache area and the total data size of the cache elements in the second auxiliary cache area is greater than a preset cache element removal threshold;

[0113] If the sum of the total data size of the cache elements in the second primary cache area and the total data size of the cache elements in the second auxiliary cache area is greater than the cache element removal threshold, a cold data element is selected from the second auxiliary cache area and the selected cold data element is removed from the second auxiliary cache area.

[0114] In some embodiments, selecting cold data elements from the first primary cache area and the second primary cache area respectively includes:

[0115] Based on the area size of the first primary cache area, determining a removed data size corresponding to the first primary cache area, and determining a removed data size corresponding to the second primary cache area;

[0116] A cold data element is selected from the first primary cache area according to a removed data size corresponding to the first primary cache area, and a cold data element is selected from the second primary cache area according to a removed data size corresponding to the second primary cache area.

[0117] In some embodiments, the device is further used to:

[0118] When a cache element in the first auxiliary cache area is accessed, increasing the area size of the first primary cache area;

[0119] When cache elements in the second auxiliary cache area are accessed, the area size of the first primary cache area is reduced.

[0120] In some embodiments, element metadata corresponding to each cache element in the cache space is maintained; the element metadata includes time information when the cache element was most recently accessed;

[0121] Select cold data elements from the cache area, including:

[0122] Based on the time information in the element metadata corresponding to each cache element in the cache area, a cold data element is selected from the cache area.

[0123] In some embodiments, selecting the cold data elements from the cache area based on the time information in the element metadata corresponding to each cache element in the cache area includes:

[0124] Randomly select candidate cache elements from the cache area, and select cold data elements from the candidate cache elements based on the time information in the element metadata corresponding to each candidate cache element; wherein the total data size of the candidate cache elements is greater than the total data size of the cold data elements.

[0125] In some embodiments, element metadata corresponding to each cache element in the cache space is maintained in a map-type container.

[0126] In some embodiments, region metadata corresponding to the first primary cache region, the second primary cache region, the first auxiliary cache region, and the second auxiliary cache region are maintained respectively; the region metadata includes a total data size of cache elements in the cache region;

[0127] Get the total data size of the cache elements in the cache area, including:

[0128] The total data size in the area metadata corresponding to the cache area is obtained as the total data size of the cache elements in the cache area.

[0129] In some embodiments, the device is further used to:

[0130] Get the target cache element to be loaded;

[0131] determining, based on region metadata corresponding to the first primary cache region, whether a remaining available size of the first primary cache region is not less than a data size of the target cache element;

[0132] If the remaining available size of the first primary cache area is not less than the data size of the target cache element, the target cache element is loaded into the first primary cache area for storage, and based on the data size of the target cache element, the area metadata corresponding to the first primary cache area is updated.

[0133] For the device embodiment, it basically corresponds to the method embodiment, so the relevant parts can refer to the partial description of the method embodiment. The device embodiment described above is only schematic, wherein the modules described as separate components may or may not be physically separated, and the components displayed as modules may or may not be physical modules, that is, they may be located in one place, or they may be distributed on multiple network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the technical solution of the present application.

[0134] The systems, devices, modules or units described in the above embodiments may be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer, which may be in the form of a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email transceiver, a game console, a tablet computer, a wearable device or a combination of any of these devices.

[0135] In a typical configuration, a computer includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.

[0136] Memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. Memory is an example of a computer-readable medium.

[0137] Computer readable media include permanent and non-permanent, removable and non-removable media that can store information by any method or technology. Information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, disk storage, quantum memory, graphene-based storage media or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined in this article, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.

[0138] It should be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of further restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.

[0139] The above specific embodiments of the present application are described. Other embodiments are within the scope of the present application. In some cases, the actions or steps recorded in the present application can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the process depicted in the accompanying drawings does not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0140] The terms used in one or more embodiments of the present application are only for the purpose of describing specific embodiments, and are not intended to limit one or more embodiments of the present application. The singular forms of "a", "said" and "the" are also intended to include plural forms, unless the context clearly indicates other meanings. The term "and / or" refers to and includes any or all possible combinations of one or more associated listed items.

[0141] The description of the terms "one embodiment", "some embodiments", "example", "specific example" or "an implementation method" etc. used in one or more embodiments of the present application means that the specific features or characteristics described in conjunction with the embodiment are included in at least one embodiment of the present application. The schematic description of these terms is not necessarily for the same embodiment. Moreover, the specific features or characteristics described can be combined in a suitable manner in one or more embodiments of the present application. In addition, different embodiments and specific features or characteristics in different embodiments can be combined without contradicting each other.

[0142] It should be understood that, although the terms first, second, third, etc. may be used to describe various information in one or more embodiments of the present application, these information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of one or more embodiments of the present application, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determination".

[0143] The above description is merely a preferred embodiment of one or more embodiments of the present application and is not intended to limit one or more embodiments of the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of one or more embodiments of the present application shall be included in the scope of protection of one or more embodiments of the present application.

[0144] The user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.

Claims

1. A cache replacement method; wherein: The cache space includes a first main cache area for storing cache elements that have been accessed once, a second main cache area for storing cache elements that have been accessed multiple times, a first auxiliary cache area for storing cache elements removed from the first main cache area, and a second auxiliary cache area for storing cache elements removed from the second main cache area; the method includes: Respectively obtain the total data size of cache elements in the first primary cache area, the second primary cache area, the first auxiliary cache area, and the second auxiliary cache area; Determine whether the sum of the total data size of the cache elements in the first primary cache area and the total data size of the cache elements in the second primary cache area is greater than a preset cache element removal threshold; If the sum of the total data size of the cache elements in the first primary cache area and the total data size of the cache elements in the second primary cache area is greater than the cache element removal threshold, select cold data elements from the first primary cache area and transfer the selected cold data elements from the first primary cache area to the first auxiliary cache area, and select cold data elements from the second primary cache area and transfer the selected cold data elements from the second primary cache area to the second auxiliary cache area; Determine whether the sum of the total data size of the cache elements in the first primary cache area and the total data size of the cache elements in the first auxiliary cache area is greater than a preset cache element removal threshold; If the sum of the total data size of the cache elements in the first primary cache area and the total data size of the cache elements in the first auxiliary cache area is greater than the cache element removal threshold, select a cold data element from the first auxiliary cache area, and remove the selected cold data element from the first auxiliary cache area; Determine whether the sum of the total data size of the cache elements in the second primary cache area and the total data size of the cache elements in the second auxiliary cache area is greater than a preset cache element removal threshold; If the sum of the total data size of the cache elements in the second primary cache area and the total data size of the cache elements in the second auxiliary cache area is greater than the cache element removal threshold, a cold data element is selected from the second auxiliary cache area and the selected cold data element is removed from the second auxiliary cache area.

2. The method according to claim 1, wherein selecting cold data elements from the first primary cache area and the second primary cache area respectively comprises: Based on the area size of the first primary cache area, determining a removed data size corresponding to the first primary cache area, and determining a removed data size corresponding to the second primary cache area; A cold data element is selected from the first primary cache area according to a removed data size corresponding to the first primary cache area, and a cold data element is selected from the second primary cache area according to a removed data size corresponding to the second primary cache area.

3. The method according to claim 2, further comprising: When a cache element in the first auxiliary cache area is accessed, increasing the area size of the first primary cache area; When cache elements in the second auxiliary cache area are accessed, the area size of the first primary cache area is reduced.

4. According to the method of claim 1, element metadata corresponding to each cache element in the cache space is maintained; the element metadata includes time information when the cache element was most recently accessed; Select cold data elements from the cache area, including: Based on the time information in the element metadata corresponding to each cache element in the cache area, a cold data element is selected from the cache area.

5. The method according to claim 4, wherein the step of selecting cold data elements from the cache area based on the time information in the element metadata corresponding to each cache element in the cache area comprises: Randomly select candidate cache elements from the cache area, and select cold data elements from the candidate cache elements based on the time information in the element metadata corresponding to each candidate cache element; wherein the total data size of the candidate cache elements is greater than the total data size of the cold data elements.

6. According to the method of claim 4, the element metadata corresponding to each cache element in the cache space is maintained in a map class container.

7. The method according to claim 1, maintaining corresponding regional metadata for the first primary cache area, the second primary cache area, the first auxiliary cache area, and the second auxiliary cache area; The region metadata includes the total data size of the cache elements in the cache region; Get the total data size of the cache elements in the cache area, including: The total data size in the area metadata corresponding to the cache area is obtained as the total data size of the cache elements in the cache area.

8. The method according to claim 7, further comprising: Get the target cache element to be loaded; determining, based on region metadata corresponding to the first primary cache region, whether a remaining available size of the first primary cache region is not less than a data size of the target cache element; If the remaining available size of the first primary cache area is not less than the data size of the target cache element, the target cache element is loaded into the first primary cache area for storage, and based on the data size of the target cache element, the area metadata corresponding to the first primary cache area is updated.

9. A cache replacement device; wherein: The cache space includes a first primary cache area for storing cache elements that have been accessed once, a second primary cache area for storing cache elements that have been accessed multiple times, a first auxiliary cache area for storing cache elements removed from the first primary cache area, and a second auxiliary cache area for storing cache elements removed from the second primary cache area; The device comprises: an acquisition module, for respectively acquiring a total size of data of cache elements in the first primary cache area, the second primary cache area, the first auxiliary cache area, and the second auxiliary cache area; A determination module, determining whether the sum of the total data size of the cache elements in the first primary cache area and the total data size of the cache elements in the second primary cache area is greater than a preset cache element removal threshold; a removal module, which selects cold data elements from the first main cache area and transfers the selected cold data elements from the first main cache area to the first auxiliary cache area, and selects cold data elements from the second main cache area and transfers the selected cold data elements from the second main cache area to the second auxiliary cache area if the sum of the total data size of the cache elements in the first main cache area and the total data size of the cache elements in the second main cache area is greater than the cache element removal threshold; Determine whether the sum of the total data size of the cache elements in the first primary cache area and the total data size of the cache elements in the first auxiliary cache area is greater than a preset cache element removal threshold; If the sum of the total data size of the cache elements in the first primary cache area and the total data size of the cache elements in the first auxiliary cache area is greater than the cache element removal threshold, select a cold data element from the first auxiliary cache area, and remove the selected cold data element from the first auxiliary cache area; Determine whether the sum of the total data size of the cache elements in the second primary cache area and the total data size of the cache elements in the second auxiliary cache area is greater than a preset cache element removal threshold; If the sum of the total data size of the cache elements in the second primary cache area and the total data size of the cache elements in the second auxiliary cache area is greater than the cache element removal threshold, a cold data element is selected from the second auxiliary cache area and the selected cold data element is removed from the second auxiliary cache area.

10. An electronic device, comprising: processor; a memory for storing processor-executable instructions; The processor implements the method according to any one of claims 1 to 8 by running the executable instructions.

11. A computer-readable storage medium having computer instructions stored thereon, wherein the instructions are executed by a processor to implement the method according to any one of claims 1 to 8.

Citation Information

Patent Citations

  • Method, device for managing cache and computer program product

    CN110737394A

  • Cache data expelling method and device, electronic equipment and storage medium

    CN118747056A