A frequency-driven cache replacement method
By dividing the memory cache into high-frequency and low-frequency regions and dynamically adjusting the cache entry position according to the access frequency, the problem of untimely identification of cache pollution and hot data in the existing technology is solved, and more efficient cache management and cost control are achieved.
Patent Information
- Application Number
- CN202411285973.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-13
- Publication Date
- 2025-07-11
- Estimated Expiration
- 2044-09-13
AI Technical Summary
The existing LRU and LFU cache elimination algorithms have problems such as cache pollution and untimely identification of hot data in large-capacity storage systems, resulting in inefficient cache efficiency.
The memory cache is divided into high-frequency zones and low-frequency zones, the access frequency is used to distinguish cache entries, and through the data exchange and elimination mechanism, we ensure that hot data is stored in the high-frequency zone and cold data is stored in the low-frequency zone, and a frequency-driven cache elimination method is adopted.
Improve cache hit rate, reduce read request latency, control storage costs, and achieve more efficient cache management.
Smart Images

Figure CN119357088B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of storage systems, and particularly to a cache eviction method based on frequency drive. Background Art
[0002] Large-capacity storage systems are becoming an indispensable part of today's data centers. Large-capacity storage systems can store massive amounts of data. Depending on the storage scale, each cluster of large-capacity storage systems has an expansion of dozens to thousands of nodes, and each node consists of hundreds of disks and several solid-state drive caches. Each node is usually measured in TB (terabyte) or PB (petabyte).
[0003] The memory cache system can provide more effective support for large-capacity storage systems. The most classic cache eviction algorithms are LRU (Least Recently Used eviction algorithm) and LFU (Least Frequently Used eviction algorithm). LRU has a good effect on workloads with strong temporal locality, but sudden large-scale sequential access may cause cache pollution. LFU is suitable for workloads where certain data is frequently accessed and this access frequency is relatively stable, but high-frequency historical data will be retained even if it is not accessed for a long time, resulting in fewer and fewer mobile cache data, which is not conducive to the identification of subsequent hot data. In order to effectively process cache data queries in large-capacity storage systems, we need to endow the memory cache system with an efficient cache eviction method. Summary of the Invention
[0004] To solve the problems existing in the prior art, the present invention provides a cache eviction method based on frequency drive, which divides the memory cache into a high-frequency area and a low-frequency area, and they share the total cache space. Among them, the high-frequency area is at most 1.5 times that of the low-frequency area. The two cache areas are divided by the average access frequency p. When the access frequency of a cache entry is less than or equal to p, it is inserted into the low-frequency area, otherwise it is inserted into the high-frequency area. Secondly, the data in the high-frequency area and the low-frequency area can be exchanged according to the average frequency, which helps to identify hot data. Eventually, global hot data and stage hot data that have been frequently accessed recently will be saved in the high-frequency area as much as possible. Cold data and stage hot data that have not been frequently accessed recently are saved in the low-frequency area. In this way, hot data can be effectively distinguished, and the problems mentioned in the above background art are solved.
[0005] To achieve the above object, the present invention provides the following technical solution: A cache eviction method based on frequency drive, comprising the following steps:
[0006] S1. Initialize cache space information;
[0007] S2. Monitor read requests accessed by users and determine whether the cache entry is hit in the memory cache system;
[0008] S3. If it is judged that the access fails, access the backend storage, read data from the bottom layer, and convert it into a cache entry to insert into the memory cache system. When a cache entry is added to the memory cache, it is first inserted into the low-frequency area, and then it is judged whether the cache space is full;
[0009] S4. If the cache space occupancy rate reaches 100%, indicating that it is full, data needs to be evicted;
[0010] S5. If it is judged that the access is successful, directly access the memory cache system, and find the corresponding cache block *p according to the LBA; when the cache entry is hit, increment its Freq by 1; then judge whether the access frequency Freq of the updated cache entry is greater than the average frequency;
[0011] S6. If the value of Freq after update is greater than or equal to the average frequency, move the cache entry to the head of the high-frequency area; if the value of Freq after update is less than the average frequency, move the cache entry to the head of the low-frequency area;
[0012] S7. After the search is completed, increment the successful query count by 1, and then judge whether the successful query count is greater than the average access frequency threshold p. If it is greater, recalculate the average frequency of the memory cache and update the average frequency; the new average frequency is equal to the total access frequency divided by the total number of cache entries, and reset the successful query count to 0.
[0013] S8. When the next read request arrives, start the next round of cache eviction operation according to steps S1 - S7.
[0014] Preferably, in step S1, assume the total memory size is 128 GB, set the memory cache space size to 25% of the total memory size, i.e., 32 GB; the cache block size is 512 KB; assume the average access frequency threshold p of the cache entry is 65536; set the initial average frequency to 1; set the successful query count to 0.
[0015] Preferably, in step S1, divide the memory cache into a high-frequency area and a low-frequency area, and they share the total cache space; the two cache areas are demarcated by the average access frequency threshold p of the cache entry, where the high-frequency area is 1.5 times that of the low-frequency area.
[0016] Preferably, the cache entry includes 3 fields: LBA represents the logical block number of the underlying storage device; *p represents the cache block address pointer; Freq represents the access frequency of the cache entry.
[0017] Preferably, in step S4, when eliminating data, if the space occupied by the high-frequency area is greater than or equal to 1.5 times the space occupied by the low-frequency area, then eliminate the data that has not been accessed for the longest time in the high-frequency area; if the space occupied by the high-frequency area is less than 1.5 times the space occupied by the low-frequency area, then eliminate the data that has not been accessed for the longest time in the low-frequency area.
[0018] The beneficial effects of the present invention are as follows:
[0019] 1) Faster read request response time: The frequency-driven cache replacement algorithm can more effectively cache hot data and ensure a high cache hit rate. The user's read requests will access the memory more frequently. When a read request hits the memory cache, the latency can be maintained at the ns level, and the throughput is also at the GB / s level. This greatly reduces the response time of the large-capacity storage system.
[0020] 2) More effective cost control: Over time, more and more hot data will accumulate in the memory, but storing hot data that is no longer accessed will result in ineffective cost expenditures. Therefore, the frequency-driven cache replacement algorithm not only ensures that hot data is more likely to be retained compared to cold data but also can continuously eliminate hot data that is no longer accessed. This helps to control costs. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] Figure 1 is a schematic flowchart of the frequency-driven cache replacement method in an embodiment of the present invention;
[0022] Figure 2 is an architecture diagram of the frequency-driven cache replacement method in an embodiment of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0023] The following will clearly and completely describe the technical solutions in the embodiments of the present invention with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all of the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.
[0024] The present invention provides a technical solution: a frequency-driven cache replacement method, as Figure 1 and 2 shown, includes the following implementation steps:
[0025] (1) Initialize the cache space information. The total memory size is 128 GB, and the memory cache space size is set to 25% of the total memory size (32 GB); the cache block size is 512 KB; the initial average frequency is set to 1; the number of successful queries is set to 0; the cache entry average access frequency threshold p = 65536 (32 GB / 512 KB). The memory cache area is divided into a high-frequency area and a low-frequency area, and they share the total cache space; the two cache areas are demarcated by the cache entry average access frequency threshold p, where the high-frequency area is 1.5 times that of the low-frequency area.
[0026] (2) The memory cache system starts to monitor the read requests of user access.
[0027] (3) If the requested cache to be read is not in the memory cache, read the data from the underlying layer and convert it into a cache entry to insert into the memory cache system. The cache entry includes 3 fields: LBA represents the logical block number of the underlying storage device; *p represents the cache block address pointer; Freq represents the frequency of access to the cache entry.
[0028] (4) When a cache entry is added to the memory cache, it is first inserted into the low-frequency area.
[0029] (5) If the cache space occupancy rate reaches 100%, data needs to be evicted.
[0030] (6) If the space occupied by the high-frequency area is greater than or equal to 1.5 times the space occupied by the low-frequency area, evict the data that has not been accessed for the longest time in the high-frequency area.
[0031] (7) If the space occupied by the high-frequency area is less than 1.5 times the space occupied by the low-frequency area, evict the data that has not been accessed for the longest time in the low-frequency area.
[0032] (8) If the requested cache to be read is in the memory cache, directly access the memory cache system. Find the corresponding cache block *p according to the LBA. When the cache entry is hit, increment its Freq by one, and then determine whether the updated cache entry access frequency Freq is greater than the average frequency;
[0033] (9) If the value of Freq after update is greater than or equal to the average frequency, move the cache entry to the head of the high-frequency area.
[0034] (10) If the value of Freq after update is less than the average frequency, move the cache entry to the head of the low-frequency area.
[0035] (11) After the search is completed, increment the number of successful queries by one, and then determine whether the number of successful queries is greater than the average access frequency threshold p;
[0036] (12) If the number of successful queries is greater than or equal to the frequency update threshold, recalculate the average frequency of the memory cache and update the average frequency. The new average frequency is equal to the total access frequency divided by the total number of cache entries, and the number of successful queries is reset to 0.
[0037] (13) After completion, when the next read request arrives, start the next round of cache operations according to steps (1)-(12).
[0038] Thus, the frequency-driven cache eviction method described in the present invention is all completed.
[0039] The terms used in the embodiments of the present invention are only for the purpose of describing specific embodiments and are not intended to limit the present invention. The singular forms "a", "said", and "the" used in the embodiments of the present invention and the appended claims are also intended to include the plural forms unless the context clearly indicates otherwise.
[0040] It should be understood that the term "and / or" used herein is only a description of the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist simultaneously, and B exists alone. In addition, the character " / " in this article generally represents an "or" relationship between the associated objects before and after.
[0041] Depending on the context, the word "if" as used herein can be interpreted as "when" or "while" or "in response to determining" or "in response to detecting". Similarly, depending on the context, the phrase "if determined" or "if detected (stated condition or event)" can be interpreted as "when determined" or "in response to determining" or "when detected (stated condition or event)" or "in response to detecting (stated condition or event)".
[0042] The "first / second" mentioned in the embodiments is only to distinguish similar objects and does not represent a specific order for the objects. It can be understood that the "first / second" can be interchanged in a specific order or sequence when allowed. It should be understood that the objects distinguished by the "first / second" can be interchanged appropriately so that the embodiments described herein can be implemented in an order other than those illustrated or described herein.
[0043] Although the present invention has been described in detail with reference to the foregoing embodiments, for those skilled in the art, they can still modify the technical solutions recorded in the foregoing embodiments, or perform equivalent replacements for some of the technical features. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A cache replacement method based on frequency driving, characterized in that, It includes the following steps: S1. Initialize the cache space information; S2. Monitor the read requests accessed by the user and determine whether the cache entry is hit in the memory cache system; the cache entry includes 3 fields: LBA represents the logical block number of the underlying storage device; *p represents the cache block address pointer; Freq represents the access frequency of the cache entry; S3. If it is determined that it is not hit, access the backend storage, read data from the underlying layer, and convert it into a cache entry to insert into the memory cache system. When a cache entry is added to the memory cache, it is first inserted into the low-frequency area, and then it is determined whether the cache space is full; S4. If the cache space occupancy rate reaches 100%, indicating that it is full, data needs to be evicted; when evicting data, if the space occupied by the high-frequency area is greater than or equal to 1.5 times the space occupied by the low-frequency area, evict the data that has not been accessed for the longest time in the high-frequency area; if the space occupied by the high-frequency area is less than 1.5 times the space occupied by the low-frequency area, evict the data that has not been accessed for the longest time in the low-frequency area; S5. If it is determined that it is hit, directly access the memory cache system and find the corresponding cache block *p according to LBA; when the cache entry is hit, increment its Freq by 1; then determine whether the access frequency Freq of the updated cache entry is greater than the average frequency; S6. If the value of Freq after update is greater than or equal to the average frequency, move the cache entry to the head of the high-frequency area; if the value of Freq after update is less than the average frequency, move the cache entry to the head of the low-frequency area; S7. After the search is completed, increment the successful query count by 1, and then determine whether the successful query count is greater than the average access frequency threshold p. If it is greater, recalculate the average frequency of the memory cache and update the average frequency; the new average frequency is equal to the total access frequency divided by the total number of cache entries, and reset the successful query count to 0; S8. When the next read request arrives, start the next round of cache eviction operation according to steps S1 - S7.
2. The cache eviction method based on frequency driving according to claim 1, wherein: In step S1, assume the total memory size is 128 GB, set the memory cache space size to 25% of the total memory size, that is, 32 GB; the cache block size is 512 KB; assume the average access frequency threshold p of the cache entry is 65536; the initial average frequency is set to 1; the successful query count is set to 0.
3. The cache eviction method based on frequency driving according to claim 1, wherein: In step S1, divide the memory cache into a high-frequency area and a low-frequency area, and they share the total cache space; the two cache areas are demarcated by the average access frequency threshold p of the cache entry, where the high-frequency area is 1.5 times that of the low-frequency area.
Citation Information
Patent Citations
Data storage method and device
CN101794259A
Caching method and device based on two-layer cache structure
CN115563029A