Caching method, device and equipment and computer readable storage medium
Through filtering conditions, the disk data is filtered and written to the read cache. Combined with the dynamic deletion mechanism, the problem of low read request cache hit rate in the existing technology is solved, and more efficient cache utilization and performance improvement is achieved.
Patent Information
- Application Number
- CN202411944075.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-26
- Publication Date
- 2025-03-14
AI Technical Summary
In the prior art, the cache hit rate of read requests is low and the caching effect cannot be better played.
The data on the disk is filtered through filtering conditions, and the filtered data is written into the read cache; the filtering conditions include at least one of the data drop time, access frequency and read request data volume; calculate the cache share of the cache memory occupied by the cache, and determine whether the cache share reaches the startup threshold; if it is reached, the deletion mechanism of dynamic speed adjustment will be triggered to delete the data in the read cache.
Filtering data on disk through filtering conditions can reduce the amount of data written by the read cache and ensure cache efficiency; when triggering the deletion mechanism, the dynamic deletion speed can not only minimize the impact of deletion on read requests under smaller cache pressure, but also ensure that read requests do not cause cache exhaustion under greater pressure, affecting overall performance.
Smart Images

Figure CN119620956A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of cache, and in particular to a cache method, device, equipment and computer-readable storage medium. Background Art
[0002] The existing cache design is that after the data in the write cache is written to the disk, it will be directly used as the read cache data and written into the read cache. And each time after responding to a read request, the data is also written into the read cache, but due to the limited cache space, data deletion is required. The existing data deletion mechanism is the FIFO (First In First Out) algorithm, which has certain limitations and reduces the cache hit rate and performance of user read requests.
[0003] Therefore, how to improve the cache hit rate of read requests and better play the role of cache is a technical problem that needs to be solved urgently. Summary of the invention
[0004] In view of this, an object of the present invention is to provide a cache method, apparatus, device and computer-readable storage medium, which solves the problem in the prior art that the cache hit rate of read requests is low and the cache function cannot be better exerted.
[0005] In order to solve the above technical problems, the present invention provides a caching method, comprising:
[0006] Filter the data in the disk according to the filtering conditions, and write the filtered data into the read cache; the filtering conditions include at least one of the data disk placement time, access frequency and read request data volume;
[0007] Calculate the cache ratio of the memory occupied by the cache and determine whether the cache ratio reaches the startup threshold;
[0008] If it is reached, the deletion mechanism of dynamic speed adjustment is triggered to delete the data in the read cache.
[0009] On the one hand, when the filtering condition is the time when the data is written to the disk, the data in the disk is filtered according to the filtering condition, and the filtered data is written to the read cache, including:
[0010] When the data in the write cache is written to the disk, the data's writing time and last access time are obtained;
[0011] Calculate the time difference between the disk drop time and the last access time;
[0012] The data corresponding to the time difference less than the preset time threshold is written into the read cache.
[0013] On the one hand, when the filtering condition is the access frequency, the data in the disk is filtered according to the filtering condition, and the filtered data is written into the read cache, including:
[0014] Get the access frequency of data in each area of the disk;
[0015] Write the data in the disk whose access frequency is greater than or equal to the preset access frequency threshold into the read cache.
[0016] On the one hand, when the filtering condition is the amount of read request data, the data in the disk is filtered according to the filtering condition, and the filtered data is written to the read cache, including:
[0017] When a read request is received, determining whether the amount of data in the read request is greater than or equal to a preset threshold;
[0018] If the amount of data in the read request is greater than a preset threshold, determine whether the read request is a random read;
[0019] If the read request is a random read, the data corresponding to the read request in the disk is written into the read cache.
[0020] On the one hand, if it is reached, the deletion mechanism of dynamic speed adjustment is triggered to delete the data in the read cache, including:
[0021] If the cache ratio reaches the startup threshold, determining whether the cache ratio reaches the speed adjustment threshold; the speed adjustment threshold is greater than the startup threshold;
[0022] If the cache ratio reaches the speed adjustment threshold, the deletion speed of the data in the read cache is increased and deleted until the cache ratio is lower than the speed adjustment threshold, and the currently set deletion speed is used as the maximum deletion speed;
[0023] If the cache ratio does not reach the speed adjustment threshold, the actual deletion speed of the data in the read cache is calculated based on the current cache ratio through the maximum deletion speed and the minimum deletion speed, and the data is deleted; the minimum deletion speed is the speed after the deletion speed is reduced when the cache ratio does not reach the start threshold.
[0024] On the one hand, before deleting the data in the read cache, the following steps are also included:
[0025] Get the deletion priority of data in the read cache;
[0026] The data in the read cache is deleted according to the deletion priority.
[0027] On the one hand, the deletion priority of data in the read cache is obtained, including:
[0028] Using the data written in the read cache by triggering the pre-read function as the first data;
[0029] Using the cache hit data in the first data as the second data;
[0030] Setting the deletion priority of the second data to the highest;
[0031] The data in the read cache that is hit by the cache multiple times within a period of time is used as the third data;
[0032] The deletion priority of the third data is set to the lowest.
[0033] The present invention also provides a cache device, comprising:
[0034] A data screening module is used to screen the data in the disk according to the screening conditions and write the screened data into the read cache; the screening conditions include at least one of the data storage time, access frequency and read request data volume;
[0035] The cache ratio calculation module is used to calculate the cache ratio of the memory occupied by the cache and determine whether the cache ratio reaches the startup threshold;
[0036] The data deletion module is used to trigger the deletion mechanism of dynamic speed adjustment to delete the data in the read cache if the limit is reached.
[0037] The present invention also provides a cache device, comprising:
[0038] Memory for storing computer programs;
[0039] A processor is used to implement the above-mentioned cache method when executing a computer program.
[0040] The present invention also provides a computer-readable storage medium, in which computer-executable instructions are stored. When the computer-executable instructions are loaded and executed by a processor, the above-mentioned cache method is implemented.
[0041] The present invention also provides a computer program product, comprising a computer program / instruction, which implements the steps of the above-mentioned cache method when executed by a processor.
[0042] It can be seen from the above technical solution that the present invention filters the data in the disk according to the screening conditions, and writes the filtered data into the read cache; the screening conditions include at least one of the data falling time, access frequency and read request data volume; calculate the cache ratio of the cache to the memory, and determine whether the cache ratio reaches the startup threshold; if reached, trigger the deletion mechanism with dynamic speed adjustment to delete the data in the read cache. The beneficial effect of the present invention is that by filtering the data in the disk according to the screening conditions, the amount of data written to the read cache can be reduced, and the cache efficiency can be guaranteed; and when the deletion mechanism is triggered, the dynamic deletion speed can be used to ensure that the impact of deletion on the read request can be minimized under a small cache pressure, and that the read request under a large pressure will not cause the cache to be exhausted and affect the overall performance.
[0043] In addition, the present invention also provides a cache device, equipment and computer-readable storage medium, which also have the above-mentioned beneficial effects. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.
[0045] Figure 1 A flowchart of a deletion method provided by the prior art;
[0046] Figure 2 A flowchart of a caching method provided by an embodiment of the present invention;
[0047] Figure 3 An example diagram of a deletion mechanism flow for dynamic speed adjustment provided by an embodiment of the present invention;
[0048] Figure 4 A schematic diagram of the structure of a cache device provided by an embodiment of the present invention;
[0049] Figure 5 A schematic diagram of the structure of a cache device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0050] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0051] In the design of centralized storage programs, the data that users need to write to disk will be temporarily stored in memory according to certain rules. This part of the memory used to temporarily store user data is called write cache, or WCA (write cache). At the same time, part of the data that users read from disk is also temporarily stored in memory. This part of the memory used to temporarily store data is called read cache, or RCA (read cache). RCA is to ensure that users can directly read this part of data from the read cache in memory when they access this part of data next time, instead of reading it from disk. This process is called cache hit. Cache hit will improve the efficiency of reading data and improve the overall performance of centralized storage systems. In addition, under certain conditions, read operations will trigger pre-reading, and part of the data in the disk will be read into the read cache in advance. Subsequent read requests will directly hit this part of the pre-read data, achieving the effect of pre-read hit, which can also improve the efficiency of system data reading. After the data in the write cache is stored on the disk, it will also be converted into read cache data to cope with the scenario of read-after-write, and improve the cache efficiency in this scenario. In short, the original intention of designing the read cache is to allow as many read requests as possible to read directly from the memory level, and try to avoid reading data directly from the disk. However, the cache comes from the memory, so the space is limited. It is necessary to continuously delete the read cache data with low access priority to save more read cache data with high access priority. This process is called the demote mechanism of the cache, that is, the deletion mechanism in this embodiment.
[0052] The existing cache design is that after the data in the write cache is written to the disk, it will be directly used as the read cache data and written to the read cache; and each time after responding to a read request, the data will also be written to the read cache. This writing method has the problem of writing data with low access probability into the read cache, which loses the cache function and reduces cache hits. For the read cache deletion mechanism, a FIFO algorithm is currently used, such as Figure 1As shown. When the proportion of cache data occupying memory reaches the preset threshold, a timer will be used to trigger cache deletion. The deletion process will delete the read cache data with a fixed amount of data each time. After the execution is completed, the processor time slice is released and the next deletion is determined based on whether the cache usage exceeds the threshold of the proportion of cache memory occupied. The cache is queued again for processor execution. The FIFO algorithm is performed at a certain size, resulting in an inability to balance the read pressure: when the read pressure is small, the deletion process occupies more processor time slices, affecting other performance; and when the read pressure is high, it cannot be guaranteed that the deletion mechanism can delete the read cache data in time.
[0053] In order to solve the above problems, the present invention provides a caching method. Figure 2 , Figure 2 A flowchart of a caching method provided by an embodiment of the present invention. The method may include:
[0054] S101: Filter the data in the disk according to the filtering condition, and write the filtered data into the read cache; the filtering condition includes at least one of the data disk placement time, access frequency and read request data volume.
[0055] The execution subject in this embodiment is the cache module. According to the current cache design, the amount of deleted data cannot be changed, and the deletion mechanism will have an intractable contradiction. From the perspective of cache performance, it is hoped that as little data as possible is deleted to eliminate the impact of the deletion process on performance and improve system performance; however, from the perspective of the deletion mechanism, the improvement of performance will cause more data to be written into the read cache, so more deletion operations are required to maintain the proportion of the cache in the memory. Under the current cache design, because the data must be finally stored in the read cache, the amount of deleted data is proportional to the performance. In this case, the above contradiction cannot be resolved. Therefore, it is necessary to determine whether the data needs to be written into the read cache. By screening conditions, the amount of data written into the read cache can be reduced while ensuring the cache efficiency. This embodiment can start from one aspect or from multiple aspects at the same time to reduce the amount of data written into the read cache. For example, the processing of write cache data after it falls on the disk, the processing of pre-read data, and the processing of read data, that is, any one or several of the data falling time, access frequency, and read request data volume, or other aspects. Among them, the read request data volume refers to the amount of data covered by a read operation.
[0056] Furthermore, when the screening condition is the time when the data is written to the disk, the data in the disk is screened according to the screening condition, and the screened data is written into the read cache, which may specifically include the following steps:
[0057] Step 21: When the data in the write cache is written to the disk, the writing time and the last access time of the data are obtained;
[0058] Step 22: Calculate the time difference between the disk download time and the last access time;
[0059] Step 23: Write the data corresponding to the time difference being less than the preset time threshold into the read cache.
[0060] In the existing read cache design, the data in the write cache (referring to the data that has been written to the write cache but not yet written to the disk) will be directly converted into the read cache data after it is written to the disk. Since it is impossible to control the writing time of the data in the write cache, it may take a long time after the write request is processed to trigger the writing to the disk. At this time, the possibility of users accessing this part of the data is already very low, which makes the design of directly converting the write cache to the read cache after it is written to the disk not well matched with the original design intention of the read cache. In addition, since it is impossible to control the writing time of the write data (referring to the data stored in the write cache), it is also possible that the user views and accesses the data in the write cache before the data is completely written to the disk. In other words, when the data is written to the write cache, the user views and accesses the written data in a short period of time, then the possibility of users accessing this part of the data is already very low. Therefore, the processing of the data after the write cache is written to the disk in this embodiment mainly includes screening the data according to the time when the data is written to the disk, removing the above-mentioned data with low access possibility, and writing the data with higher access possibility as read cache data into the read cache.
[0061] Specifically, this embodiment calculates the time difference between the time when the data is placed on the disk and the time when it was last accessed, and compares the time difference with a preset time threshold. If the time difference is greater than or equal to the preset time threshold, it does not need to be written into the read cache; otherwise, it is written into the read cache as read cache data. If the data is read in the write cache, the last access time refers to the time when the data was last read; if the data is not read in the write cache, the last access time refers to the time when the data was written into the write cache.
[0062] Furthermore, when the screening condition is the access frequency, the data in the disk is screened according to the screening condition, and the screened data is written into the read cache, which may specifically include the following steps:
[0063] Step 31: Obtain the access frequency of data in each area of the disk;
[0064] Step 32: Write data in the disk whose access frequency is greater than or equal to a preset access frequency threshold into the read cache.
[0065] It should be noted that the triggering of the pre-reading function is determined based on heat and access validity. Among them, heat refers to the frequency of input / output (IO) operations received by a specific area (such as a sector on a disk or a block in memory) within a period of time. Access validity refers to the probability that the data actually read will be used or hit in subsequent operations after the pre-reading function is triggered. For a read request, if the heat condition is not met in the judgment process of whether the pre-reading function is triggered, it means that the probability of the statistical area where the data corresponding to the read request is accessed is very low. In this case, the probability of the data corresponding to the read request being accessed here will also be very low. Therefore, for a read request that meets this condition, the corresponding data will no longer be written into the read cache. Specifically, according to the pre-reading principle, this embodiment can know that the area with a high access frequency in the disk has a higher probability of being hit. Therefore, by monitoring the access frequency of the data in each area of the disk, the data in the area with higher heat can be written into the read cache as read cache data.
[0066] Furthermore, when the screening condition is the amount of read request data, the data in the disk is screened according to the screening condition, and the screened data is written into the read cache, which may specifically include the following steps:
[0067] Step 41: When a read request is received, determining whether the amount of data in the read request is greater than or equal to a preset threshold;
[0068] Step 42: If the read request data volume is greater than a preset threshold, determine whether the read request is a random read;
[0069] Step 43: If the read request is a random read, the data corresponding to the read request in the disk is written into the read cache.
[0070] The current cache design is to write all the data corresponding to the read request into the read cache, but the read IO model is divided into random read and sequential read, and the actual user business is often a combination of these two businesses. According to past experience, read requests are divided into large blocks and small blocks according to their size. Here, a configurable threshold can be set as the boundary (preset threshold). Read requests less than the preset threshold are considered small block reads, and vice versa. In actual business, small block reads are mainly random reads, because small block sequential reads can improve performance through large block sequential reads, but it does not rule out the possibility of small block sequential reads in some applications; large block reads are more sequential reads, because random business in actual applications often reads a small amount of data each time, but in small, scattered blocks.
[0071] Based on the above rules, if it is a small block sequential read, the subsequent access will hit the pre-read data, and the data that triggered the pre-read will not be accessed again; if it is a small block random read, the probability of accessing the data next time is also very low, so there is no need to write it to the read cache. Therefore, for small block reads, it is no longer necessary to write its data to the read cache. That is, for small block reads, whether it is sequential reads or random reads, the data corresponding to the read request will not be written to the cache. For large block sequential reads, if the pre-read hits, the corresponding data should also be deleted from the read cache as soon as possible; for large block random reads, there may be a situation where the user reads a large block of data at a time but accesses a small block each time. At this time, the data corresponding to such a read request needs to be written to the read cache for the next access. Therefore, for large block read requests, when the pre-read function is triggered, it means that the large block read request is a sequential read, and this part of the data will no longer be written to the read cache; when the pre-read function is not triggered, it means that the large block read request is a random read, and the data corresponding to the read request will be written to the read cache.
[0072] S102: Calculate the cache ratio of the memory occupied by the cache, and determine whether the cache ratio reaches a startup threshold.
[0073] The startup threshold of this embodiment is the critical value of whether to start the deletion mechanism of dynamic speed adjustment, and the user can set it according to the situation. The startup threshold can be set to 80%, which can ensure that there is enough cache in the memory to save data and improve the cache hit rate. In this embodiment, the cache includes a read cache and a write cache, and the cache ratio of the memory occupied by the cache, that is, the ratio of the memory occupied by the sum of the read cache and the write cache is the cache ratio.
[0074] S103: If the limit is reached, a deletion mechanism for dynamically adjusting the speed is triggered to delete the data in the read cache.
[0075] When the cache ratio reaches the startup threshold, the speed dynamic adjustment deletion mechanism is triggered to dynamically delete the data in the read cache at the set deletion speed. The deletion mechanism in this embodiment can be understood as an elimination mechanism to eliminate the data in the read cache.
[0076] Furthermore, if the above condition is reached, a deletion mechanism of dynamic speed adjustment is triggered to delete the data in the read cache, which may specifically include the following steps:
[0077] Step 51: If the cache ratio reaches the startup threshold, determine whether the cache ratio reaches the speed adjustment threshold; the speed adjustment threshold is greater than the startup threshold;
[0078] Step 52: If the cache ratio reaches the speed adjustment threshold, the deletion speed of the data in the read cache is increased and deleted until the cache ratio is lower than the speed adjustment threshold, and the currently set deletion speed is used as the maximum deletion speed;
[0079] Step 53: If the cache ratio does not reach the speed adjustment threshold, the actual deletion speed of the data in the read cache is calculated based on the current cache ratio through the maximum deletion speed and the minimum deletion speed, and the data is deleted; the minimum deletion speed is the speed after the deletion speed is reduced when the cache ratio does not reach the startup threshold.
[0080] The current cache deletion mechanism is performed at a fixed speed, so the existing deletion mechanism will have an approximately equal impact on the read pressure, and in some cases will cause cache exhaustion, affecting the overall performance of the system. Based on this consideration, this embodiment adopts an intelligent dynamic deletion speed. For details, please refer to Figure 3 , Figure 3 An example diagram of a deletion mechanism process with dynamic speed adjustment provided by an embodiment of the present invention. When the cache ratio reaches the startup threshold, the deletion process is triggered and the data in the read cache is deleted. If the cache ratio does not reach the startup threshold, the deletion process is not triggered. In the deletion mechanism process with dynamic speed adjustment, if the cache ratio reaches the speed adjustment threshold, the demote (elimination, i.e., deletion in this embodiment) speed is increased until the cache ratio is lower than the speed adjustment threshold. At this time, the demote speed of this time is recorded as the maximum demote speed; if the cache ratio is between the startup threshold and the speed adjustment threshold, the minimum demote speed and the middle value of the maximum demote speed can be selected to set the demote speed, thereby realizing intelligent adjustment of the demote speed. In the deletion mechanism process with dynamic speed adjustment, the cache ratio may not reach the startup threshold. At this time, it is necessary to stop the deletion and reduce the deletion speed until the cache ratio exceeds the startup threshold. It is recorded as the minimum deletion speed, but the deletion is not performed. Such intelligent dynamic adjustment of the deletion speed can not only ensure that the impact of demo on the read request can be minimized under less pressure, but also ensure that the read request under greater pressure will not cause the cache to be exhausted and affect the overall performance. The speed adjustment threshold can be 90%, which is the middle value between the start threshold (80%) and 100%. This ensures that the cache hit rate is affected as little as possible while adjusting the cache as quickly as possible to avoid affecting the memory.
[0081] Furthermore, before deleting the data in the read cache, the following steps may also be included:
[0082] Step 61: Obtain the deletion priority of the data in the read cache;
[0083] Step 62: Delete the data in the read cache according to the deletion priority.
[0084] In this embodiment, when deleting, data also needs to be deleted according to the deletion priority, that is, data with a higher deletion priority is deleted first according to the intelligent deletion speed.
[0085] Furthermore, the above-mentioned obtaining the deletion priority of the data in the read cache may specifically include the following steps:
[0086] Step 71: using the data written into the read cache by triggering the pre-read function as the first data;
[0087] Step 72: Using the cache hit data in the first data as the second data;
[0088] Step 73: setting the deletion priority of the second data to the highest;
[0089] Step 74: taking data in the read cache that is cache hit multiple times within a period of time as third data;
[0090] Step 75: Set the deletion priority of the third data to the lowest.
[0091] The traditional FIFO algorithm maintains a linked list of access times for cached data, places the most recently accessed data at the end of the linked list, and starts deleting from the beginning, in order to implement a design that determines the deletion priority of cached data based on the order in which read requests arrive. For processing after a read cache hit, the current design implementation does not change the position of the cached data in the FIFO linked list, and therefore does not change its demote priority. In this way, if this part of data is requested again after a read request, its deletion priority cannot be updated, resulting in some repeatedly accessed data such as metadata (data that records information such as data location) still being deleted from the read cache.
[0092] In response to the above problems, the deletion priority of the data in the read cache in this embodiment is not sorted according to the order of access, and the deletion priority of the data in this embodiment can be changed. It can be understood that the successful hit of the pre-read data is often triggered by the sequential read model. Under the sequential read model, the probability of accessing the pre-read data again after the pre-read hit is very low. Therefore, after each pre-read hit, the hit part of the data can be placed at the highest deletion priority to ensure that this part of the read data with a low access probability can be deleted first. That is, if the read request does not trigger the pre-read function due to low heat, or successfully hits the pre-read data, it should be ensured that the data corresponding to the read request is no longer stored in the read cache. However, for metadata with higher access heat, its deletion priority is set to the lowest to ensure that it will not be deleted.
[0093] Furthermore, the above-mentioned deleting of the data in the read cache may specifically include the following steps:
[0094] Step 81: Sort and arrange the data in the read cache in sequence according to the order of access time of the data in the read cache to obtain a data deletion linked list;
[0095] Step 82: When data in the data deletion linked list is accessed again, the accessed data is placed at the end of the data deletion linked list;
[0096] Step 83: Start deleting from the head of the data deletion linked list.
[0097] Based on the problem that the deletion order in the existing data deletion linked list cannot be changed, this embodiment updates the data in the data deletion linked list according to the latest access time of the data by counting the data access time. That is, when the data is accessed once, it is sorted from front to back based on the order of access time to obtain the data deletion linked list; when the data in the data deletion linked list is accessed again, the deletion order of the data in the data deletion linked list is updated according to the time of the second access. In this way, it can ensure that the frequently accessed data is always placed at the end of the data deletion linked list and deleted last.
[0098] The cache method provided by the embodiment of the present invention is applied, and the data in the disk is filtered according to the filtering conditions, and the filtered data is written into the read cache; the filtering conditions include at least one of the data falling time, access frequency and read request data volume; the cache ratio of the cache memory is calculated, and it is determined whether the cache ratio reaches the startup threshold; if it reaches, the deletion mechanism of dynamic speed adjustment is triggered to delete the data in the read cache. The beneficial effect of this method is that the data in the disk is filtered by the filtering conditions, which can reduce the amount of data written to the read cache and ensure the cache efficiency; and when the deletion mechanism is triggered, the dynamic deletion speed can be used to ensure that the impact of deletion on the read request can be minimized under a small cache pressure, and the read request under a large pressure will not cause the cache to be exhausted and affect the overall performance; and the data that hits the read cache multiple times may be metadata or hot data, and it is highly likely that the data will be accessed again in a short time, so the deletion priority of this part of the data is set to the lowest to ensure that this part of the data will not be deleted in a short time; effectively improve the effectiveness of the read cache and reduce the impact of the deletion mechanism on performance. The original intention of the design of the read cache is to increase the probability of user read requests hitting the cache by storing some data with a high probability of subsequent user access in the memory, thereby improving the read performance. The present invention can better meet the original intention of the read cache design and better play the buffering role played by RCA.
[0099] The following is an introduction to a cache device provided in an embodiment of the present invention. The cache device described below and the cache method described above can be referenced to each other.
[0100] Please refer to Figure 4 , Figure 4 A schematic diagram of a cache device provided in an embodiment of the present invention may include:
[0101] The data screening module 100 is used to screen the data in the disk according to the screening conditions and write the screened data into the read cache; the screening conditions include at least one of the data storage time, access frequency and read request data volume;
[0102] The cache ratio calculation module 200 is used to calculate the cache ratio of the memory occupied by the cache and determine whether the cache ratio reaches the startup threshold;
[0103] The data deletion module 300 is used to trigger a deletion mechanism with dynamic speed adjustment to delete the data in the read cache if the limit is reached.
[0104] Based on the above embodiment, the data screening module 100 may include:
[0105] A time acquisition unit, used to acquire the disk placement time and the last access time of the data when the data in the write cache is placed on the disk;
[0106] A calculation unit, used to calculate the time difference between the disk placement time and the last access time;
[0107] The first writing unit is used to write data corresponding to a time difference less than a preset time threshold into the read cache.
[0108] Based on the above embodiment, the data screening module 100 may include:
[0109] An access frequency acquisition unit, used to acquire the access frequency of data in each area of the disk;
[0110] The second writing unit is used to write data in the disk whose access frequency is greater than or equal to a preset access frequency threshold into the read cache.
[0111] Based on the above embodiment, the data screening module 100 may include:
[0112] A first judgment unit, configured to judge whether the amount of data in the read request is greater than or equal to a preset threshold when a read request is received;
[0113] A second judgment unit, used to judge whether the read request is a random read if the read request data amount is greater than a preset threshold;
[0114] The third writing unit is configured to write data corresponding to the read request in the disk into the read cache if the read request is a random read.
[0115] Based on the above embodiment, the data deletion module 300 may include:
[0116] A judgment unit, for judging whether the cache ratio reaches a speed adjustment threshold if the cache ratio reaches a startup threshold; the speed adjustment threshold is greater than the startup threshold;
[0117] A first deleting unit is used to increase the deleting speed of the data in the read cache and delete it if the cache ratio reaches the speed adjustment threshold, until the cache ratio is lower than the speed adjustment threshold, and the currently set deleting speed is used as the maximum deleting speed;
[0118] The second deletion unit is used to calculate the actual deletion speed of the data in the read cache and delete it according to the current cache ratio through the maximum deletion speed and the minimum deletion speed if the cache ratio does not reach the speed adjustment threshold; the minimum deletion speed is the speed after the deletion speed is reduced when the cache ratio does not reach the start threshold.
[0119] Based on the above embodiment, the cache device may further include:
[0120] A deletion priority acquisition module is used to obtain the deletion priority of data in the read cache;
[0121] The deletion module is used to delete the data in the read cache according to the deletion priority.
[0122] Based on the above embodiment, the deletion priority acquisition module may include:
[0123] a first data determining unit, which uses the data written in the read cache by triggering the pre-read function as the first data;
[0124] A second data determining unit, configured to use cache hit data in the first data as second data;
[0125] A highest priority setting unit, used to set the deletion priority of the second data to the highest;
[0126] A third data determination unit, configured to use data in the read cache that is cache hit multiple times within a period of time as third data;
[0127] The lowest priority setting unit is used to set the deletion priority of the third data to the lowest.
[0128] It should be noted that the order of the modules and units in the above cache device can be changed without affecting the logic.
[0129] The cache device provided by the embodiment of the present invention is applied, through a data screening module, used to screen the data in the disk according to the screening conditions, and write the screened data into the read cache; the screening conditions include at least one of the data drop time, access frequency and read request data volume; a cache ratio calculation module, used to calculate the cache ratio of the cache occupied by the memory, and determine whether the cache ratio reaches the startup threshold; a data deletion module, used to trigger the deletion mechanism of dynamic speed adjustment if it reaches, and delete the data in the read cache. The beneficial effect of the device is that: by screening the data in the disk through the screening conditions, the amount of data written to the read cache can be reduced, and the cache efficiency can be guaranteed; and when the deletion mechanism is triggered, the dynamic deletion speed can be used to ensure that the impact of deletion on the read request can be minimized under a small cache pressure, and the read request under a large pressure will not cause the cache to be exhausted and affect the overall performance; and the data that hits the read cache multiple times may be metadata or hot data, and it is highly likely that the data will be accessed again in a short time, so the deletion priority of this part of the data is set to the lowest to ensure that this part of the data will not be deleted in a short time; effectively improve the effectiveness of the read cache and reduce the impact of the deletion mechanism on performance. The original intention of the design of the read cache is to increase the probability of user read requests hitting the cache by storing some data with a high probability of subsequent user access in the memory, thereby improving the read performance. The present invention can better meet the original intention of the read cache design and better play the buffering role played by RCA.
[0130] Figure 5 A schematic diagram of a cache device provided by an embodiment of the present invention is shown in FIG. Figure 5 As shown, the cache device includes:
[0131] A memory 60, for storing computer programs;
[0132] The processor 61 is used to implement the steps of the cache method in the above embodiment when executing a computer program.
[0133] The cache device provided in this embodiment may include but is not limited to a smart phone, a tablet computer, a laptop computer, or a desktop computer.
[0134] Among them, the processor 61 may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor 61 can be implemented in at least one hardware form of digital signal processing (DSP), field-programmable gate array (FPGA), and programmable logic array (PLA). The processor 61 may also include a main processor and a coprocessor. The main processor is a processor for processing data in the awake state, also known as a central processing unit (CPU); the coprocessor is a low-power processor for processing data in the standby state. In some embodiments, the processor 61 may be integrated with a graphics processing unit (GPU), and the GPU is responsible for rendering and drawing the content to be displayed on the display screen. In some embodiments, the processor 61 may also include an artificial intelligence (AI) processor, which is used to process computing operations related to machine learning.
[0135] The memory 60 may include one or more computer-readable storage media, which may be non-transitory. The memory 60 may also include a high-speed random access memory, and a non-volatile memory, such as one or more disk storage devices, flash memory storage devices. In this embodiment, the memory 60 is at least used to store the following computer program 601, wherein, after the computer program is loaded and executed by the processor 61, it can implement the relevant steps of the cache method disclosed in any of the aforementioned embodiments. In addition, the resources stored in the memory 60 may also include an operating system 602 and data 603, etc., and the storage method may be short-term storage or permanent storage. Among them, the operating system 602 may include Windows, Unix, Linux, etc. Data 603 may include, but is not limited to, data of the cache method, etc.
[0136] In some embodiments, the cache device may further include a display screen 62 , an input / output interface 63 , a communication interface 64 , a power supply 65 , and a communication bus 66 .
[0137] Those skilled in the art will understand that Figure 5 The structure shown in the figure does not constitute a limitation on the cache device, and may include more or fewer components than those shown in the figure.
[0138] It is understandable that if the cache method in the above embodiment is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the current technology or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium and executes all or part of the steps of the methods of each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), electrically erasable programmable ROM, register, hard disk, removable disk, CD-ROM, magnetic disk or optical disk and other media that can store program code.
[0139] Based on this, an embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the above-mentioned cache method are implemented.
[0140] A computer program product provided in an embodiment of the present application is introduced below. The computer program product described below can be cross-referenced with other embodiments described in this document.
[0141] A computer program product comprises a computer program / instruction, wherein the computer program / instruction implements the steps of the aforementioned disclosed cache method when executed by a processor.
[0142] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part.
[0143] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.
[0144] Finally, it should be noted that, in this article, relationships such as first and second, etc. are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprises" or any other variations are intended to cover non-exclusive inclusion, so that a process, method, article or device that includes 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, article or device.
[0145] The above is a detailed introduction to a caching method, device, equipment and computer-readable storage medium provided by the present invention. Specific examples are used in this article to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea; at the same time, for general technical personnel in this field, according to the idea of the present invention, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.
Claims
1. A caching method, characterized in that: include: Filter the data in the disk according to the filtering conditions, and write the filtered data into the read cache; The screening condition includes at least one of the data disk storage time, access frequency and read request data volume; Calculate the cache ratio of the memory occupied by the cache, and determine whether the cache ratio reaches the startup threshold; If it is reached, a deletion mechanism of dynamic speed adjustment is triggered to delete the data in the read cache.
2. The caching method according to claim 1, characterized in that: When the screening condition is the time when the data is written to the disk, the data in the disk is screened according to the screening condition, and the screened data is written to the read cache, including: When the data in the write cache is written to the disk, the writing time and the last access time of the data are obtained; Calculate the time difference between the disk placement time and the last access time; The data corresponding to the time difference being less than a preset time threshold is written into the read cache.
3. The caching method according to claim 1, characterized in that: When the screening condition is the access frequency, the data in the disk is screened according to the screening condition, and the screened data is written into the read cache, including: Obtaining the access frequency of data in each area of the disk; The data in the disk whose access frequency is greater than or equal to a preset access frequency threshold is written into the read cache.
4. The caching method according to claim 1, characterized in that: When the screening condition is the amount of read request data, the data in the disk is screened according to the screening condition, and the screened data is written into the read cache, including: When a read request is received, determining whether the amount of data in the read request is greater than or equal to a preset threshold; If the read request data amount is greater than the preset threshold, determining whether the read request is a random read; If the read request is a random read, the data corresponding to the read request in the disk is written into the read cache.
5. The caching method according to claim 1, characterized in that: If it is reached, the deletion mechanism of the dynamic speed adjustment is triggered to delete the data in the read cache, including: If the cache ratio reaches the startup threshold, determining whether the cache ratio reaches the speed adjustment threshold; the speed adjustment threshold is greater than the startup threshold; If the cache ratio reaches the speed adjustment threshold, the deletion speed of the data in the read cache is increased and deleted until the cache ratio is lower than the speed adjustment threshold, and the currently set deletion speed is used as the maximum deletion speed; If the cache ratio does not reach the speed adjustment threshold, the actual deletion speed of the data in the read cache is calculated based on the current cache ratio through the maximum deletion speed and the minimum deletion speed, and the data is deleted; the minimum deletion speed is the speed after the deletion speed is reduced when the cache ratio does not reach the start threshold.
6. The caching method according to claim 1, characterized in that: Before deleting the data in the read cache, the method further includes: Obtaining a deletion priority of data in the read cache; The data in the read cache is deleted according to the deletion priority.
7. The caching method according to claim 6, characterized in that: Obtaining the deletion priority of the data in the read cache includes: using the data written in the read cache by triggering the pre-read function as the first data; Using the cache hit data in the first data as the second data; Setting the deletion priority of the second data to the highest; Using data in the read cache that is cache hit multiple times within a period of time as third data; The deletion priority of the third data is set to the lowest.
8. A cache device, characterized in that: include: A data filtering module is used to filter the data in the disk according to the filtering conditions and write the filtered data into the read cache; The screening condition includes at least one of the data disk storage time, access frequency and read request data volume; A cache ratio calculation module is used to calculate the cache ratio of the memory occupied by the cache and determine whether the cache ratio reaches the startup threshold; The data deletion module is used to trigger a deletion mechanism with dynamic speed adjustment to delete the data in the read cache if the limit is reached.
9. A cache device, characterized in that: include: Memory for storing computer programs; A processor, configured to implement the caching method according to any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, and when the computer-executable instructions are loaded and executed by a processor, the caching method according to any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Background disk writing flow control method and device, electronic equipment and storage medium
CN108763107A
A cache reading method for distributed storage and a device thereof
CN108984130A
Method, device and equipment for eliminating cache data on disk block
CN110825652A
Information device equipped with cache memories, apparatus and program using the same device
US20120054421A1
Data caching method and apparatus
US20210133103A1
Cited By
Data read-write request processing method, electronic equipment, storage medium and program product
CN120233958A
Data reading and writing request processing method, electronic device, storage medium and program product
CN120233958B
Screening method and device, equipment and storage medium
CN120540716A
Screening method, apparatus, device, storage medium
CN120540716B
Cache performance verification method, electronic equipment and storage medium
CN121050960A