A cache management method, device, apparatus and storage medium
Patent Information
- Application Number
- CN202211717772.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-29
- Publication Date
- 2026-10-27
- Estimated Expiration
- 2042-12-29
AI Technical Summary
但是,偶发性的、周期性的批量操作会导致LRU命中率急剧下降,降低了缓存命中率;其次对扫描读模式是没有抵抗性的
[0045]本申请中,对缓存进行分割,得到第一缓存区域和第二缓存区域,并将所述第一缓存区域配置为第一缓存置换方式,将所述第二缓存区域配置为第二缓存置换方式;为所述第一缓存区域添加用于存储从所述第一缓存区域淘汰的数据块的第一淘汰表,并为所述第二缓存区域添加用于存储从所述第二缓存区域淘汰的数据块的第二淘汰表;根据系统对缓存的访问,分别统计访问命中所述第一淘汰表和所述第二淘汰表的命中率,并根据所述命中率调整所述第一缓存区域和所述第二缓存区域的大小。可见,通过分别构建第一缓存置换方式所在第一缓存区域的第一淘汰表,以及第二缓存置换方式所在第二缓存区域的第二淘汰表,第一淘汰表和第二淘汰表的命中率能够表征当前访问的倾向性,即倾向访问最近内容还是访问最频繁内容,再据此调整第一缓存区域和所述第二缓存区域的大小,使较多缓存区域符合当前缓存访问的倾向性,由此实现适应型的缓存空间置换,应于抗扫描、偶发性、周期性等批量业务操作,提升了缓存命中率。
Smart Images

Figure CN116185904B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and in particular to a cache management method, apparatus, device, and storage medium. Background Technology
[0002] Currently, there is a significant performance gap between solid-state drives (SSDs) and hard disk drives (HDDs) in storage media, with access efficiency increasing sequentially. However, the price of these devices also rises accordingly. For this reason, modern computers always strike a balance between cost-effectiveness and performance. Since storage media with higher access efficiency are more expensive, these media are finite resources. To process an infinite amount of data within these limited resources, the concept of data replacement was introduced. Ideally, data that won't be accessed again in the near future would be replaced from the cache. However, since the future is unpredictable, replacement can only be performed by analyzing patterns in past data access patterns.
[0003] In existing technologies, LFU (Least Frequently Used) cache replacement is employed. This algorithm evicts data based on its access frequency. The system records the access frequency of all data within a certain period, and when the cache is full, it prioritizes evicting the data with the fewest accesses. The core idea is that if data has been accessed infrequently recently, it is unlikely to be accessed again in the future. This is clearly a reasonable algorithm, as the least used page so far is likely to be the least accessed page in the future. Each cached data item has a reference count, and all data is sorted by reference count. Data with the same reference count are sorted by time. However, LFU suffers from a cache invalidation problem: frequent, infrequent operations make it difficult to invalidate the cache, reducing the cache hit rate.
[0004] Existing technologies also employ LRU (Least Recently Used) cache replacement, which is an algorithm based on the least recently used data access history to execute the eviction policy. LRU first evicts the page that has not been used for the longest time. This algorithm uses the page that has not been accessed for the longest time recently as the page to be replaced. Unlike LFU, LRU does not focus on the number of times cached data has been accessed; it only focuses on the access time of the data. The core idea is that if data has not been accessed in a recent period, the probability of it being accessed in the future is also very small. However, occasional, periodic batch operations can cause the LRU hit rate to drop sharply, reducing the cache hit rate; secondly, it is not resistant to scan-read patterns. Summary of the Invention
[0005] In view of this, the purpose of this invention is to provide a cache management method, apparatus, device, and medium that can improve cache hit rate. The specific solution is as follows:
[0006] Firstly, this application discloses a cache management method, including:
[0007] The cache is divided into a first cache region and a second cache region. The first cache region is configured with a first cache replacement method, and the second cache region is configured with a second cache replacement method.
[0008] Add a first eligibility table to the first cache area to store data blocks evicted from the first cache area, and add a second eligibility table to the second cache area to store data blocks evicted from the second cache area;
[0009] Based on the system's access to the cache, the hit rate of accessing the first eviction table and the second eviction table is calculated respectively, and the size of the first cache area and the second cache area is adjusted according to the hit rate.
[0010] Optionally, adjusting the size of the first cache region and the second cache region according to the hit rate includes:
[0011] If the hit rate of the first eviction table is greater than the hit rate of the second eviction table, then the first cache area is expanded and the second cache area is reduced.
[0012] If the hit rate of the second eviction table is greater than the hit rate of the first eviction table, then the second cache area is expanded and the first cache area is reduced.
[0013] Optionally, expanding the first cache region and shrinking the second cache region includes:
[0014] Determine a preset adjustment unit, where the preset adjustment unit is the target number of data blocks;
[0015] According to the preset adjustment unit, the size of the first cache area is increased by decreasing the size of the second cache area;
[0016] The expansion of the second cache region and the reduction of the first cache region include:
[0017] According to the preset adjustment unit, the size of the first cache area is reduced and the size of the second cache area is increased.
[0018] Optionally, after dividing the cache to obtain a first cache region and a second cache region, the method further includes:
[0019] Determine the position of the dividing line between the first cache region and the second cache region;
[0020] Accordingly, expanding the first cache region and shrinking the second cache region includes:
[0021] The position of the dividing line is adjusted with the second cache area as the direction, so as to expand the first cache area and shrink the second cache area;
[0022] Accordingly, expanding the second cache region and shrinking the first cache region includes:
[0023] The position of the dividing line is adjusted with the first cache area as the direction, so as to expand the second cache area and shrink the first cache area.
[0024] Optionally, the step of dividing the cache to obtain a first cache region and a second cache region bounded by a dividing line includes:
[0025] The cache is divided into two equal parts, a first cache region and a second cache region of the same size, bounded by a dividing line; the cache is in units of fixed-size data blocks.
[0026] Optionally, the first cache area is used to store the data block written for the first time; the second cache area is used to store the data block that has been hit multiple times.
[0027] Accordingly, the cache management method further includes:
[0028] When the target data block in the first cache area is hit again, the target data block is moved to the second cache area.
[0029] Optionally, adding a first elapsed table to the first cache area for storing data blocks elapsed from the first cache area, and adding a second elapsed table to the second cache area for storing data blocks elapsed from the second cache area, includes:
[0030] The first and second elimination tables are constructed based on Bloom filters;
[0031] The first and second elimination tables are divided into regions to obtain multiple table intervals corresponding to each elimination table. This allows the eliminated data blocks to be written sequentially into each table interval. After a table interval is full, the table interval with the earliest written data is cleared according to the writing order.
[0032] Optionally, the statistical access hit rate of the first and second elimination tables includes:
[0033] Determine the Bloom filter data layout corresponding to the first or second elimination table; the Bloom filter data layout method includes partitioning storage by column table or partitioning storage by row table.
[0034] Calculate the target hash value corresponding to each target cache accessed by the current system according to the hash set;
[0035] If the Bloom filter stores the hash values of the eliminated data blocks according to the column-based table partitioning, then determine all target rows in the Bloom filter data layout that the target hash value hits, and obtain the target table based on the target rows;
[0036] The target table is queried by column, and the elimination data block is determined based on the column query results to determine whether it matches the first elimination table or the second elimination table.
[0037] Secondly, this application discloses a cache management device, comprising:
[0038] The segmentation module is used to segment the cache to obtain a first cache region and a second cache region, and configure the first cache region as a first cache replacement method and the second cache region as a second cache replacement method;
[0039] The eligibility table addition module is used to add a first eligibility table to the first cache area for storing data blocks eligible from the first cache area, and to add a second eligibility table to the second cache area for storing data blocks eligible from the second cache area;
[0040] The region adjustment module is used to calculate the hit rate of access to the first eviction table and the second eviction table based on the records of the system access cache, and adjust the size of the first cache region and the second cache region according to the hit rate.
[0041] Thirdly, this application discloses an electronic device, including:
[0042] Memory, used to store computer programs;
[0043] A processor for executing the computer program to implement the aforementioned cache management method.
[0044] Fourthly, this application discloses a computer-readable storage medium for storing a computer program; wherein the computer program implements the aforementioned cache management method when executed by a processor.
[0045] In this application, the cache is divided into a first cache region and a second cache region. The first cache region is configured with a first cache replacement method, and the second cache region is configured with a second cache replacement method. A first eligibility table is added to the first cache region to store data blocks evicted from the first cache region, and a second eligibility table is added to the second cache region to store data blocks evicted from the second cache region. Based on system access to the cache, the hit rate of access hitting the first eligibility table and the second eligibility table is calculated respectively, and the size of the first cache region and the second cache region is adjusted according to the hit rate. It can be seen that by constructing the first eligibility table in the first cache region where the first cache replacement method is used, and the second eligibility table in the second cache region where the second cache replacement method is used, the hit rate of the first eligibility table and the second eligibility table can represent the current access tendency, i.e., whether the access is more recent or the most frequently accessed content. Based on this, the size of the first cache region and the second cache region are adjusted so that more cache regions conform to the current cache access tendency, thereby achieving adaptive cache space replacement. This is suitable for batch business operations such as anti-scanning, sporadic, and periodic operations, and improves the cache hit rate. Attached Figure Description
[0046] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.
[0047] Figure 1 A flowchart of a cache management method provided in this application;
[0048] Figure 2 A schematic diagram of a specific cache segmentation structure provided in this application;
[0049] Figure 3 A flowchart illustrating a specific method for constructing an elimination table is provided in this application;
[0050] Figure 4 A flowchart illustrating a specific method for filling out an elimination table data is provided in this application;
[0051] Figure 5 A flowchart of a specific elimination table hit determination method provided in this application;
[0052] Figure 6 A schematic diagram of a specific Bloom filter data layout structure is provided for this application;
[0053] Figure 7A schematic diagram of a cache management device provided in this application;
[0054] Figure 8 This application provides a structural diagram of an electronic device. Detailed Implementation
[0055] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0056] In existing technologies, LFU (Least Recently Used) cache replacement is employed. However, LFU suffers from the problem of difficulty in cache invalidation, meaning that frequent, isolated operations make it difficult to invalidate the cache, thus reducing the cache hit rate. LRU (Least Recently Used) cache replacement is also used, but sporadic, periodic batch operations can cause a sharp drop in the LRU hit rate, and it is not resistant to scan-read patterns, further reducing the cache hit rate. To overcome these technical problems, this application proposes a cache management method that can improve the cache hit rate.
[0057] This application discloses a cache management method, see [link to relevant documentation]. Figure 1 As shown, the method may include the following steps:
[0058] Step S11: Divide the cache to obtain a first cache region and a second cache region, and configure the first cache region as the first cache replacement method and the second cache region as the second cache replacement method.
[0059] In this embodiment, the cache region is divided into two parts by segmentation. The first part is replaced using a first cache replacement method, and the other part is replaced using a second cache replacement method. The first cache replacement method can be an LRU cache replacement method, and the second cache replacement method can be an LFU cache replacement method. That is, one part is replaced according to the LRU algorithm, and the other part is replaced according to the LFU algorithm. A cache is a high-speed memory with a faster access speed than general random access memory (RAM). Unlike main memory, it typically doesn't use DRAM (Dynamic Random Access Memory) technology, but rather the more expensive but faster SRAM (Static Random-Access Memory) technology. Cache configuration is one of the important factors for achieving high performance in all modern computer systems.
[0060] In this embodiment, the step of dividing the cache to obtain a first cache region and a second cache region bounded by a dividing line can include: dividing the cache evenly to obtain a first cache region and a second cache region of the same size bounded by the dividing line; the cache is based on fixed-size data blocks. That is, the entire cache space is divided into several blocks according to a fixed block size. The smallest unit in the cache is a block, so the cache is divided in blocks. Since the cache access tendency is unknown at this time, the initial division can be an even division, that is, the size of the first cache region is the same as the size of the second cache region. The first cache region corresponds to a cache table defined as an LRU table, used to record access records of the first cache region, and the second cache region corresponds to a cache table defined as an LFU table, used to record access records of the second cache region.
[0061] In this embodiment, the first cache area is used to store the data block written for the first time; the second cache area is used to store data blocks that have been hit multiple times; correspondingly, the cache management method may further include: when a target data block in the first cache area is hit again, moving the target data block to the second cache area. It is understood that since the first cache area is configured with a first cache replacement method, which is based on data access time and does not focus on frequency, the data that is cache-missed for the first time will be placed in the LRU table; if the cache-hit occurs in the LRU table and is not found in the LFU table, then the relevant content will be placed in the LFU table.
[0062] Step S12: Add a first evictory table to the first cache area for storing data blocks evicted from the first cache area, and add a second evictory table to the second cache area for storing data blocks evicted from the second cache area.
[0063] In this embodiment, a first evictation table is added to the first cache area to store data blocks evicted from the first cache area, and a second evictation table is added to the second cache area to store data blocks evicted from the second cache area. That is, the first cache area corresponds to one first evictation table, and the information of data blocks evicted from the first cache area is stored in the first evictation table. Similarly, the second cache area corresponds to one second evictation table, and the information of data blocks evicted from the second cache area is stored in the second evictation table. The first and second evictation tables can be linked lists.
[0064] For example Figure 2 As shown, the entire cache space corresponds to two parts: an LRU table and an LFU table. Initially, it is assumed that the LRU table and LFU table each occupy half, and p is the split position between the two regions. Each of LRU and LFU has an eviction table, namely the first eviction table (LRUGhost table) and the second eviction table (LFU Ghost table). Specifically, the first and second eviction tables can be Ghost shadow lists. The first and second eviction tables store data in the form of keys, namely the file I / O offset, size, and file_no. For example, if the evicted data block comes from the LRU table, the key corresponding to that unit will be placed in the first eviction table corresponding to the LRU table.
[0065] Additionally, when the cache area is full, during cache replacement and data block eviction, data blocks can be evicted based on their popularity value from low to high. In this embodiment, the LRU table and LFU table can each use sets divided by popularity level. If there are 0-255 sequences, there are 256 popularity values. For example, sequence [0-127] is the LRU table, and sequence [128-255] is the LFU table. The first data written enters the LRU table, and the sequence set [0-127] is filled sequentially from sequence 0 (0(N / 128), 1(N / 128)...127(N / 128)). If a second hit occurs, the data block is moved from the LRU table to the LFU table (starting from sequence 128). If a third or more hit occurs, the data block is moved sequentially towards the end of the LFU table to increase its popularity value; that is, the higher the access frequency, the higher the popularity value. During eviction, data blocks are selected sequentially from the lowest-hotness values in both the LRU and LFU tables, moving towards the highest-hotness values. The LFU table is handled similarly. The number of blocks selected from each of the LFU and LRU tables is determined by the P-value, ensuring that neither the first nor the second cache region, currently partitioned based on the P-value, has an actual data volume exceeding its cache capacity after the appropriate number of data blocks are evicted.
[0066] Step S13: Based on the system's access to the cache, calculate the hit rate of accessing the first eviction table and the second eviction table respectively, and adjust the size of the first cache area and the second cache area according to the hit rate.
[0067] In this embodiment, based on the system's access to the cache, the hit rate of accessing the first and second eviction tables is calculated respectively. Then, the size of the first and second cache areas is adjusted according to the hit rate. That is, by calculating the hit rate of the first and second eviction tables, the current system's cache access tendency can be determined, that is, whether it tends to access the most recent content or the most frequently accessed content. The access method with a higher hit rate is the cache access tendency.
[0068] In this embodiment, adjusting the size of the first cache region and the second cache region according to the hit rate may include: if the hit rate of the first eligibility table is greater than the hit rate of the second eligibility table, then expanding the first cache region and shrinking the second cache region; if the hit rate of the second eligibility table is greater than the hit rate of the first eligibility table, then expanding the second cache region and shrinking the first cache region. It is understood that the hit rate can characterize the cache access tendency. If the hit rate of the first eligibility table is greater than the hit rate of the second eligibility table, it can be considered that the system tends to access the most recent content. However, since the first cache region does not have enough space to store data, access may hit data blocks eligible from the first cache region in the first eligibility table. Therefore, it is necessary to appropriately expand the first cache region so that more caches can be replaced according to the LRU algorithm. The same applies when the hit rate of the second eligibility table is greater than the hit rate of the first eligibility table, thus improving the cache hit rate.
[0069] In this embodiment, expanding the first cache area and shrinking the second cache area may include: determining a preset adjustment unit, where the preset adjustment unit is a target number of data blocks; and increasing the size of the first cache area by decreasing the size of the second cache area according to the preset adjustment unit. Expanding the second cache area and shrinking the first cache area includes: increasing the size of the second cache area by decreasing the size of the first cache area according to the preset adjustment unit. That is, a data block in the cache is used as the unit; therefore, when adjusting the size of the two cache areas, the size of each adjustment can be set to a preset adjustment unit, specifically, the preset adjustment unit can be a data block of the target data.
[0070] In this embodiment, after dividing the cache to obtain a first cache region and a second cache region, the process may further include: determining the position of the dividing line between the first cache region and the second cache region; correspondingly, expanding the first cache region and shrinking the second cache region includes: adjusting the position of the dividing line with the second cache region as the direction to expand the first cache region and shrink the second cache region; correspondingly, expanding the second cache region and shrinking the first cache region includes: adjusting the position of the dividing line with the first cache region as the direction to expand the second cache region and shrink the first cache region. For example Figure 2 As shown, if the hit rate of the first replacement table is greater than the hit rate of the second replacement table, the value of p is decreased by 1 so that the position of the dividing line moves to the left. If the hit rate of the second replacement table is greater than the hit rate of the first replacement table, the value of p is increased by 1 so that the position of the dividing line moves to the right. Thus, the size of the first and second cache regions can be adjusted by adjusting the value of p.
[0071] Therefore, by combining the first cache replacement method and the second cache replacement method and dynamically adjusting them, when the system tends to access the most recent content, it will hit the LRU Ghost table more often, which will increase the space of the first cache area; when the system tends to access the most frequently accessed content, it will hit the LFU Ghost table more often, which will increase the space of the second cache area.
[0072] As can be seen from the above, this embodiment divides the cache into a first cache region and a second cache region. The first cache region is configured with a first cache replacement method, and the second cache region is configured with a second cache replacement method. A first eligibility table is added to the first cache region to store data blocks evicted from the first cache region, and a second eligibility table is added to the second cache region to store data blocks evicted from the second cache region. Based on system access to the cache, the hit rate of access hitting the first eligibility table and the second eligibility table is calculated respectively, and the size of the first cache region and the second cache region is adjusted according to the hit rate. It can be seen that by constructing the first eligibility table in the first cache region where the first cache replacement method is used, and the second eligibility table in the second cache region where the second cache replacement method is used, the hit rate of the first eligibility table and the second eligibility table can represent the current access tendency, that is, whether it is more likely to access recent content or most frequently accessed content. Based on this, the size of the first cache region and the second cache region are adjusted so that more cache regions conform to the current cache access tendency, thereby realizing adaptive cache space replacement, which is suitable for batch business operations such as anti-scanning, occasional, and periodic operations, and improves the cache hit rate.
[0073] This application discloses a specific method for constructing an elimination table. See [link to relevant documentation]. Figure 3 As shown, the method may include the following steps:
[0074] Step S21: Construct the first elimination table and the second elimination table based on the Bloom filter.
[0075] Step S22: Divide the first elimination table and the second elimination table into regions to obtain multiple table intervals corresponding to each elimination table, so that the eliminated data blocks are written to each table interval in order, and after the table interval is full, the table interval with the earliest written data is cleared according to the writing order.
[0076] Understandably, in existing technologies, using traditional linked lists to store data sequentially is convenient for storage, but it has high complexity and long search time, and consumes a lot of memory resources. In this embodiment, to greatly optimize memory usage, a Bloom filter is used as the eviction table. A Bloom filter is a long binary vector and a series of random mapping functions. A Bloom filter can be used to check whether an element is in a set.
[0077] In this embodiment, when using a Bloom filter for data storage, the Bloom filter serves as the index for the first and second eviction tables, each with its own independent Bloom filter interval. In existing technologies, Bloom filters cannot delete elements, and the order of data insertion is unknown. In this embodiment, to create an LRU effect for data insertion and deletion, the given space used for the Bloom filter is divided into multiple Bloom filter intervals, each hashed with a fixed number of data. Each Bloom filter interval independently calculates its data distribution, filling all intervals sequentially. When new data arrives after an interval is full, the earliest filled interval is removed according to the LRU principle; that is, the earliest filled Bloom filter interval is cleared to 0. The following is an example. Figure 4 It is the data filling process of the elimination table. After the first round of hashing, the hash value is stored in the first interval, and after the second round of hashing, the hash value is stored in the second interval.
[0078] Accordingly, this application discloses a specific method for determining the hit rate of an elimination table, see [link to relevant documentation]. Figure 5 As shown, the method may include the following steps:
[0079] Step S31: Determine the Bloom filter data layout corresponding to the first elimination table or the second elimination table; the Bloom filter data layout method includes storing the data in columns as tables or storing the data in rows as tables.
[0080] Step S32: Calculate the target hash value corresponding to each target cache accessed by the current system according to the hash set.
[0081] Step S33: If the Bloom filter stores the hash values of the eliminated data blocks according to the column-based table partitioning, then determine all target rows that the target hash value hits in the Bloom filter data layout, and obtain the target table based on the target rows.
[0082] Step S34: Query the target table by column, and determine whether the eliminated data block matches the first elimination table or the second elimination table based on the column query results.
[0083] According to the principle of Bloom filters, using a hash table (also called a hash table) data structure, an element can be mapped to a point in a bit array using a hash function. Therefore, checking if this point is 1 indicates whether the element exists in the set. In this implementation, hash values are stored by area. Therefore, it's first necessary to determine whether to use row-based or column-based areas. After determining this, to determine if the target cache exists, it needs to be hashed. That is, the target cache is initially stored using a hash value, and the same data using the same hash function will yield the same hash value. Furthermore, multiple hash functions are typically used to calculate multiple hash values. Therefore, by recalculating the target hash value and determining its possible position in the Bloom filter data layout, a query is performed at that position to check if the element already exists. If it does, a hit is considered.
[0084] For example Figure 6 As shown, the Bloom filter data layout uses columns as table partitions for storage, divided into 64 partitions. Because the hash key values are the same, the relative positions of the hash values from each hash function in different partitions are also the same. For example... Figure 6 The entire BloomFilter interval is divided vertically into equal parts, with each column serving as a BloomFilter Bit array and each row representing the storage location of a specific hash value. To check if data exists, it's sufficient to find the row corresponding to the hash(key) value, assemble these rows into a target table, and then perform a bitwise AND operation on each column of the target table; a non-zero value indicates a match.
[0085] like Figure 6When a key is initially written, if the hash set contains 5 hash functions, after 5 hashes, assuming it falls into the fifth column and the hash value corresponds to rows 2, 6, 10, 14, and 18, then when checking if the key exists again, it is hashed 5 more times, and the hash value will again correspond to rows 2, 6, 10, 14, and 18. Therefore, these rows are retrieved, and a bitwise AND operation is performed on the 5 identifiers in each column. If the result in the fifth column is non-zero, the data is considered to exist. If no non-zero result is found after traversing all 64 columns, the data is considered not to exist. During data filling and deletion, the 64 regions are managed using an LRU (Least Recently Used) approach. After each region is filled with a fixed amount of data, the next region is filled, and this process is repeated for all 64 regions. When all 64 regions are full, the first region is deleted using an LRU approach. Furthermore, deletion is a relatively time-consuming operation, especially when deleting non-contiguous column addresses. Therefore, the corresponding deletion operation can be performed in a dedicated thread or a worker thread other than the query thread. As can be seen, the Bloom filter reduces memory usage while maintaining the cache replacement algorithm; and data deletion is achieved through partitioned storage.
[0086] Bloom filters have a certain error rate. Factors affecting the error rate include: the amount of data inserted into the Bloom filter (n), the length of the Bloom filter array (m), and the number of hash functions (k), where n and m are related by thread. For example, assuming each block occupies 4 bytes of memory, then m / n = 32, k = 22 (32 * 0.69), and the error rate f = 0.000, which is negligible. Based on this, to reduce the number of hashes, when the hash function k_hash is selected as 5, the error rate is 0.000063; when k_hash is 3, the error rate is 0.000717 (0.7‰). Therefore, it is preferable to use 3 hash functions in the hash set.
[0087] As can be seen from the above, in this embodiment, a first replacement table and a second replacement table are constructed based on a Bloom filter; the first replacement table and the second replacement table are divided into regions to obtain multiple table intervals corresponding to each replacement table, so that the replaced data blocks are written sequentially to each table interval, and after the table interval is full, the table interval with the earliest written data is cleared according to the writing order; the Bloom filter data layout corresponding to the first replacement table or the second replacement table is determined; the Bloom filter data layout method includes column-based table partitioning storage or row-based table partitioning storage; each target hash value corresponding to the target cache accessed by the current system is calculated according to the hash set; if the Bloom filter stores the hash value of the replaced data block according to column-based table partitioning, all target rows hit by the target hash value in the Bloom filter data layout are determined, and a target table is obtained based on the target rows; the target table is queried by column, and it is determined whether the replaced data block hits the first replacement table or the second replacement table according to the column query results. By using a Bloom filter, memory resource consumption is reduced while ensuring the cache replacement algorithm; and data deletion function is implemented through partitioned storage.
[0088] Accordingly, embodiments of this application also disclose a cache management device, see [link to relevant documentation]. Figure 7 As shown, the device includes:
[0089] The segmentation module 11 is used to segment the cache to obtain a first cache region and a second cache region, and configure the first cache region as a first cache replacement method and the second cache region as a second cache replacement method;
[0090] The eviction table addition module 12 is used to add a first eviction table to the first cache area for storing data blocks evicted from the first cache area, and to add a second eviction table to the second cache area for storing data blocks evicted from the second cache area;
[0091] The region adjustment module 13 is used to calculate the hit rate of accessing the first eviction table and the second eviction table based on the records of the system access cache, and adjust the size of the first cache region and the second cache region according to the hit rate.
[0092] As can be seen from the above, this embodiment divides the cache into a first cache region and a second cache region. The first cache region is configured with a first cache replacement method, and the second cache region is configured with a second cache replacement method. A first eligibility table is added to the first cache region to store data blocks evicted from the first cache region, and a second eligibility table is added to the second cache region to store data blocks evicted from the second cache region. Based on system access to the cache, the hit rate of access hitting the first eligibility table and the second eligibility table is calculated respectively, and the size of the first cache region and the second cache region is adjusted according to the hit rate. It can be seen that by constructing the first eligibility table in the first cache region where the first cache replacement method is used, and the second eligibility table in the second cache region where the second cache replacement method is used, the hit rate of the first eligibility table and the second eligibility table can represent the current access tendency, that is, whether it is more likely to access recent content or most frequently accessed content. Based on this, the size of the first cache region and the second cache region are adjusted so that more cache regions conform to the current cache access tendency, thereby realizing adaptive cache space replacement, which is suitable for batch business operations such as anti-scanning, occasional, and periodic operations, and improves the cache hit rate.
[0093] In some specific embodiments, the region adjustment module 13 may specifically include:
[0094] The first adjustment unit is used to expand the first cache area and shrink the second cache area if the hit rate of the first evictory table is greater than the hit rate of the second evictory table.
[0095] The second adjustment unit is used to expand the second cache area and shrink the first cache area if the hit rate of the second replacement table is greater than the hit rate of the first replacement table.
[0096] In some specific embodiments, the first adjustment unit may specifically include:
[0097] A preset adjustment unit is used to determine a preset adjustment unit, wherein the preset adjustment unit is a target number of data blocks;
[0098] An adjustment unit is used to adjust the size of the first cache region by decreasing the size of the second cache region according to the preset adjustment unit.
[0099] In some specific embodiments, the second adjustment unit may specifically include:
[0100] The adjustment unit is used to adjust the size of the first cache area and the size of the second cache area by decreasing the size of the first cache area and increasing the size of the second cache area according to the preset adjustment unit.
[0101] In some specific embodiments, the cache management device may specifically include:
[0102] A dividing line position determination unit is used to determine the position of the dividing line between the first cache region and the second cache region;
[0103] Accordingly, the first adjustment unit may specifically include:
[0104] The first dividing line adjustment unit is used to adjust the position of the dividing line with the second buffer area as the direction, so as to expand the first buffer area and shrink the second buffer area;
[0105] Accordingly, the second adjustment unit may specifically include:
[0106] The second dividing line adjustment unit is used to adjust the position of the dividing line with the first cache area as the direction, so as to expand the second cache area and shrink the first cache area.
[0107] In some specific embodiments, the segmentation module 11 may specifically include:
[0108] An average partitioning unit is used to partition the cache equally to obtain a first cache region and a second cache region of the same size, bounded by a partition line; the cache is in units of fixed-size data blocks.
[0109] In some specific embodiments, the first cache area is used to store the data block written for the first time; the second cache area is used to store the data block that is hit multiple times.
[0110] Correspondingly, the cache management device further includes:
[0111] A data block moving unit is used to move the target data block to the second cache area when the target data block in the first cache area is hit again.
[0112] In some specific embodiments, the elimination table addition module 12 may specifically include:
[0113] A linked list construction unit is used to construct the first elimination table and the second elimination table based on a Bloom filter;
[0114] The interval partitioning unit is used to partition the first elimination table and the second elimination table into multiple table intervals corresponding to each elimination table, so that the eliminated data blocks are written to each table interval in order, and after the table interval is full, the table interval with the earliest written data is cleared according to the writing order.
[0115] In some specific embodiments, the region adjustment module 13 may specifically include:
[0116] A data layout determination unit is used to determine the Bloom filter data layout corresponding to the first elimination table or the second elimination table; the Bloom filter data layout method includes partitioning storage by column table or partitioning storage by row table.
[0117] The hash calculation unit is used to calculate the hash value of each target cache accessed by the current system according to the hash set.
[0118] The target table determination unit is used to determine all target rows in the Bloom filter data layout that the target hash value hits if the Bloom filter stores the hash values of the eliminated data blocks according to the column-based table partitioning; and to obtain a target table based on the target rows.
[0119] The judgment unit is used to query the target table by column and determine whether the eliminated data block matches the first elimination table or the second elimination table based on the column query results.
[0120] Furthermore, this application also discloses an electronic device, see [link to relevant documentation]. Figure 8 As shown, the content in the figure should not be considered as any limitation on the scope of use of this application.
[0121] Figure 8 This is a schematic diagram of the structure of an electronic device 20 provided in an embodiment of this application. The electronic device 20 may specifically include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. The memory 22 stores a computer program, which is loaded and executed by the processor 21 to implement the relevant steps in the cache management method disclosed in any of the foregoing embodiments.
[0122] In this embodiment, the power supply 23 is used to provide operating voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and external devices, and the communication protocol it follows can be any communication protocol applicable to the technical solution of this application, and is not specifically limited here; the input / output interface 25 is used to acquire external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs, and is not specifically limited here.
[0123] In addition, the memory 22, as a carrier for resource storage, can be a read-only memory, random access memory, disk or optical disk, etc. The resources stored thereon include operating system 221, computer program 222 and data 223 including hit rate, etc. The storage method can be temporary storage or permanent storage.
[0124] The operating system 221 manages and controls the various hardware devices on the electronic device 20 and the computer program 222 to enable the processor 21 to perform calculations and processing on the massive amounts of data 223 in the memory 22. The operating system 221 can be Windows Server, Netware, Unix, Linux, etc. In addition to including a computer program capable of performing the cache management method executed by the electronic device 20 as disclosed in any of the foregoing embodiments, the computer program 222 may further include computer programs capable of performing other specific tasks.
[0125] Furthermore, this application also discloses a computer storage medium storing computer-executable instructions. When the computer-executable instructions are loaded and executed by a processor, they implement the cache management method steps disclosed in any of the foregoing embodiments.
[0126] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatus disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple; relevant parts can be referred to in the method section.
[0127] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein can be implemented directly by hardware, a software module executed by a processor, or a combination of both. The software module can be located in random access memory (RAM), main memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the art.
[0128] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0129] The cache management method, apparatus, device, and medium provided by the present invention have been described in detail above. Specific examples have been used to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only for the purpose of helping to understand the method and core ideas of the present invention. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of the present invention. Therefore, the content of this specification should not be construed as a limitation of the present invention.
Claims
1. A cache management method, characterized in that, include: The cache is divided into a first cache region and a second cache region. The first cache region is configured with a first cache replacement method, and the second cache region is configured with a second cache replacement method. Add a first eligibility table to the first cache area to store data blocks evicted from the first cache area, and add a second eligibility table to the second cache area to store data blocks evicted from the second cache area; Based on the system's access to the cache, the hit rate of accessing the first eviction table and the second eviction table is calculated respectively, and the size of the first cache area and the second cache area is adjusted according to the hit rate; The step of adjusting the size of the first cache region and the second cache region according to the hit rate includes: If the hit rate of the first eviction table is greater than the hit rate of the second eviction table, then the first cache area is expanded and the second cache area is reduced. If the hit rate of the second eviction table is greater than the hit rate of the first eviction table, then the second cache area is expanded and the first cache area is reduced. The step of adding a first eligibility table to the first cache area to store data blocks evicted from the first cache area, and adding a second eligibility table to the second cache area to store data blocks evicted from the second cache area, includes: The first and second elimination tables are constructed based on Bloom filters; The first and second elimination tables are divided into regions to obtain multiple table intervals corresponding to each elimination table. This allows the eliminated data blocks to be written sequentially into each table interval. After a table interval is full, the table interval with the earliest written data is cleared according to the writing order.
2. The cache management method according to claim 1, characterized in that, Expanding the first cache region and shrinking the second cache region includes: Determine a preset adjustment unit, where the preset adjustment unit is the target number of data blocks; According to the preset adjustment unit, the size of the first cache area is increased by decreasing the size of the second cache area; The expansion of the second cache region and the reduction of the first cache region include: According to the preset adjustment unit, the size of the first cache area is reduced and the size of the second cache area is increased.
3. The cache management method according to claim 1, characterized in that, After dividing the cache to obtain a first cache region and a second cache region, the process further includes: Determine the position of the dividing line between the first cache region and the second cache region; Accordingly, expanding the first cache region and shrinking the second cache region includes: The position of the dividing line is adjusted with the second cache area as the direction, so as to expand the first cache area and shrink the second cache area; Accordingly, expanding the second cache region and shrinking the first cache region includes: The position of the dividing line is adjusted with the first cache area as the direction, so as to expand the second cache area and shrink the first cache area.
4. The cache management method according to claim 1, characterized in that, The process of segmenting the cache to obtain a first cache region and a second cache region bounded by a dividing line includes: The cache is divided into two equal parts, a first cache region and a second cache region of the same size, bounded by a dividing line; the cache is in units of fixed-size data blocks.
5. The cache management method according to claim 1, characterized in that, The first cache area is used to store the first data block written; The second cache area is used to store data blocks that have been hit multiple times; Accordingly, the cache management method further includes: When the target data block in the first cache area is hit again, the target data block is moved to the second cache area.
6. The cache management method according to claim 1, characterized in that, The statistical access hit rate of the first and second elimination tables includes: Determine the Bloom filter data layout corresponding to the first or second elimination table; the Bloom filter data layout method includes partitioning storage by column table or partitioning storage by row table. Calculate the target hash value corresponding to each target cache accessed by the current system according to the hash set; If the Bloom filter stores the hash values of the eliminated data blocks according to the column-based table partitioning, then determine all target rows in the Bloom filter data layout that the target hash value hits, and obtain the target table based on the target rows; The target table is queried by column, and the elimination data block is determined based on the column query results to determine whether it matches the first elimination table or the second elimination table.
7. A cache management device, characterized in that, include: The segmentation module is used to segment the cache to obtain a first cache region and a second cache region, and configure the first cache region as a first cache replacement method and the second cache region as a second cache replacement method; The eligibility table addition module is used to add a first eligibility table to the first cache area for storing data blocks eligible from the first cache area, and to add a second eligibility table to the second cache area for storing data blocks eligible from the second cache area; The region adjustment module is used to calculate the hit rate of access to the first eviction table and the second eviction table based on the records of the system access cache, and adjust the size of the first cache region and the second cache region according to the hit rate. The domain adjustment module includes: The first adjustment unit is used to expand the first cache area and shrink the second cache area if the hit rate of the first evictory table is greater than the hit rate of the second evictory table. The second adjustment unit is used to expand the second cache area and shrink the first cache area if the hit rate of the second replacement table is greater than the hit rate of the first replacement table. The elimination table addition module includes: A linked list construction unit is used to construct the first elimination table and the second elimination table based on a Bloom filter; The interval partitioning unit is used to partition the first elimination table and the second elimination table into multiple table intervals corresponding to each elimination table, so that the eliminated data blocks are written to each table interval in order, and after the table interval is full, the table interval with the earliest written data is cleared according to the writing order.
8. An electronic device, characterized in that, include: Memory, used to store computer programs; A processor for executing the computer program to implement the cache management method as described in any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that, Used for storing computer programs; wherein the computer programs, when executed by a processor, implement the cache management method as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Data caching method and device
CN108763110A