Data caching method and apparatus, and device and non-volatile readable storage medium
By establishing a memory data management structure in the cache area and performing data management based on logical addresses and time deviations, the problem of poor data cache performance in the existing technology is solved, taking into account both the spatial and temporal locality of data, and improving Overall performance of cache space.
Patent Information
- Application Number
- PCT/CN2023/139981
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-03-09
- Filing Date
- 2023-12-19
- Publication Date
- 2024-09-12
AI Technical Summary
Existing data caching technology is difficult to take into account the spatial locality and temporal locality of data, resulting in poor cache space performance and low efficiency in retrieving and prefetching data.
By establishing a memory data management structure in the cache area, and writing and managing data according to logical addresses and time deviations, ensuring the spatial and temporal locality between data, using a combination of multiple cache areas and memory data management structures, Achieve effective organization and storage of data.
It improves the storage performance of cache space, ensures both spatial and temporal locality of data, reduces the number of disk reads and garbage collection pressure, and improves data access efficiency.
Smart Images

Figure CN2023139981_12092024_PF_FP_ABST
Abstract
Description
Data caching method, device, equipment and non-volatile readable storage medium
[0001] CROSS-REFERENCE TO RELATED APPLICATIONS
[0002] This application claims priority to the Chinese patent application filed with the China Patent Office on March 9, 2023, with application number 202310219993.0, and application name “A data caching method, device, equipment and computer-readable storage medium”, all contents of which are incorporated by reference into this application. Technical Field
[0003] The present application relates to the technical field of data storage, and in particular to a data caching method, apparatus, device, and non-volatile readable storage medium. Background Art
[0004] Storage arrays typically use high-performance media as cache to improve performance. When a user application writes data to the storage array, a success message is returned to the user after the data is written to the cache. The storage array then writes the data in the cache to the hard disk for storage at an appropriate time.
[0005] When a user reads data from a storage array, the array will first check the cache to see if the required data exists. If so, it can be directly retrieved and returned. If not, it will need to be read from the hard disk. Because the data is first searched in the cache, the cache will not immediately discard the data after saving it to the hard disk. Instead, it will keep the data for a period of time until certain conditions are met, at which point the cache will discard the data already stored on the hard disk. The cache also has its own prefetching strategy, which reads data that the user may read from the hard disk in advance and places it in the cache. Because user-written data received by the cache must eventually be written to the hard disk, and cache prefetched data is also read from the hard disk, the data organization and management method in the cache should be combined with the data storage method on the hard disk to better play the role of the cache.
[0006] There are two ways to store data on a hard drive. One is overwrite, meaning that once data with the same logical unit number (LUN) and the same logical block address (LBA) is allocated a storage location on the hard drive, it remains unchanged, and is stored in the same location each time it is written. The other is append, meaning that data with the same LUN and the same LBA is not stored in a fixed location on the hard drive. Each time data is written, the storage array allocates a new storage location using log append, rather than overwriting the previously stored location. This method requires garbage collection (GC) to continuously reclaim the space occupied by old data to continuously provide new space.
[0007] Caches generally organize and manage data in two ways. The first method is to organize and manage data by logical space location (LBA). When a write request is received for the same LBA, the new data overwrites the old data, which is called an overwrite. When cached data is written to disk, it is written to the disk according to the logical space location. The second method is to organize and manage data in chronological order. That is, old data will not be overwritten by new data, and all data is organized in a log format according to the time it was received. When data is written to disk, it is written to the disk in chronological order. When storing data in a storage device in an append-write mode, both methods of organizing and managing cached data can be applied, but both have certain problems.
[0008] The first caching method facilitates retrieval of data by LBA in the cache and maintains spatial locality of the data on the hard drive. That is, data at adjacent LBAs is stored adjacently on the hard drive, and data at adjacent LBAs is generally more likely to be accessed simultaneously than other data. This facilitates merging multiple prefetch requests when prefetching data at adjacent LBAs based on spatial locality, reducing the number of disk reads. However, the data stored on the hard drive loses temporal locality. That is, data written by user applications at adjacent times is scattered and stored in different locations on the hard drive because the LBAs are not adjacent.
[0009] The second caching method maintains the temporal locality of the data, that is, data written at adjacent times are stored adjacently on the hard disk. Generally, the probability of data written at adjacent times being accessed again at the same time is greater than that of other data, and the probability of being overwritten at the same time and becoming garbage data is also greater. The ability to pre-fetch data based on temporal locality improves read performance, which is beneficial to garbage collection and write amplification in the storage array. The greater the write amplification, the more data needs to be relocated during garbage collection, which is not good for array performance and hard disk pressure. However, its problems are that it is first inconvenient to retrieve data from the cache, and secondly, the data on the disk has no spatial locality. Because it is stored in an append-write manner, even data at different times in the same spatial location must be stored in the cache, resulting in a waste of cache space. In addition, old, invalid data will also be stored on the disk when it is finally saved, increasing hard disk pressure.
[0010] It can be seen that how to balance the spatial locality and temporal locality of data to improve the storage performance of the cache space is a problem that those skilled in the art need to solve.
[0011] Summary of the Invention
[0012] The purpose of the embodiments of the present application is to provide a data caching method, apparatus, device and non-volatile readable storage medium, which can take into account both the spatial locality and temporal locality of data to improve the performance of the cache space.
[0013] To solve the above technical problems, an embodiment of the present application provides a data caching method, including:
[0014] When a write request is received, a target cache area matching a target logical address carried in the write request is selected from a plurality of cache areas;
[0015] If there is no corresponding memory data management structure in the target cache area, a memory data management structure is established for the target cache area and the application time is marked, and the memory data management structure is mounted to the time queue; the data carried by the write request is written to the memory data management structure;
[0016] If the target cache area has a corresponding memory data management structure, based on the deviation between the application time of the memory data management structure and the current time, the data carried by the write request is written to the target memory data management structure that meets the time deviation requirements.
[0017] Optionally, when the target cache area does not have a corresponding memory data management structure, establishing a memory data management structure for the target cache area and marking the application time includes:
[0018] If the target cache area does not have a corresponding memory data management structure, construct a memory data management structure corresponding to the target cache area according to the logical address range corresponding to the target cache area and the current time;
[0019] Mark the current time as the application time of the memory data management structure.
[0020] Optionally, mounting the memory data management structure to the event queue includes:
[0021] According to the application time of the memory data management structure, the identification information of the memory data management structure is mounted to the time queue in chronological order.
[0022] Optionally, if the target cache area has a corresponding memory data management structure, based on the deviation between the application time of the memory data management structure and the current time, writing the data carried by the write request to the target memory data management structure that meets the time deviation requirement includes:
[0023] If the target cache area has a corresponding memory data management structure, determining whether the time interval between the application time of the memory data management structure and the current time is within a set threshold range;
[0024] When the time interval between the application time of the memory data management structure and the current time is within a set threshold range, the data carried in the write request is stored in the location pointed to by the target logical address in the memory data management structure;
[0025] When the time interval between the application time of the memory data management structure and the current time is not within the set threshold range, a new memory data management structure is established and the application time is marked, and the new memory data management structure is mounted on the time queue; the data carried by the write request is recorded in the new memory data management structure.
[0026] Optionally, when there are multiple memory data management structures corresponding to the target cache area, determining whether the time interval between the application time of the memory data management structure and the current time is within a set threshold range includes:
[0027] Determine whether the time interval between the application time of the latest created memory data management structure and the current time is within the set threshold range.
[0028] Optionally, when the time interval between the application time of the memory data management structure and the current time is within a set threshold range, storing the data carried in the write request in the location pointed to by the target logical address in the memory data management structure includes:
[0029] When the time interval between the application time of the newly established memory data management structure and the current time is within the set threshold range, the data carried by the write request is written to the location pointed to by the target logical address in the newly established memory data management structure.
[0030] Optionally, storing the data carried in the write request to the location pointed to by the target logical address in the memory data management structure includes:
[0031] Determine whether data exists at a target location in a memory data management structure; wherein the target location is the location pointed to by the target logical address;
[0032] If data exists at the target location in the memory data management structure, the data carried in the write request is overwritten and written to the target location;
[0033] When there is no data at the target location in the memory data management structure, the data carried in the write request is written to the target location.
[0034] Optionally, establishing a new memory data management structure and marking the application time includes:
[0035] Construct a new memory data management structure based on the logical address range corresponding to the target cache area and the current time;
[0036] Mark the current time as the application time of the new memory data management structure.
[0037] Optionally, attaching a new memory data management structure to the event queue includes:
[0038] According to the application time of the new memory data management structure, the identification information of the new memory data management structure is mounted to the time queue in chronological order.
[0039] Optionally, after writing the data carried in the write request into the memory data management structure, the following steps are further included:
[0040] Set the write flag for data written to the memory data management structure.
[0041] Optionally, it also includes:
[0042] When the total used space of the plurality of cache areas reaches a set water level threshold, the data with write flags stored in the memory data management structures are stored in the hard disk in an append-write manner.
[0043] Optionally, it also includes:
[0044] When the total used space of multiple cache areas reaches a set water level threshold, a memory data management structure to be processed whose time interval between the application time and the current time exceeds the set time threshold is selected;
[0045] According to the order of the memory data management structure to be processed in the time chain list, the data with the write flag set is stored in the hard disk in an append-write mode.
[0046] Optionally, after storing the data with the write flag set in the hard disk in an append-write manner according to the order of the memory data management structure to be processed in the time chain list, the method further includes:
[0047] The write flag of the data stored in each to-be-processed memory data management structure is adjusted to a read flag.
[0048] Optionally, it also includes:
[0049] According to the set cycle time, the data with the read mark and the memory data management structure to which it belongs are deleted.
[0050] Optionally, it also includes:
[0051] When a data read request is received, querying a matching first memory data management structure according to a logical address carried in the data read request;
[0052] In a case where target data corresponding to the logical address carried in the data read request exists in the first memory data management structure, the target data is read from the first memory data management structure.
[0053] Optionally, it also includes:
[0054] When the target data corresponding to the logical address carried in the data read request does not exist in the matching first memory data management structure, the target data matching the logical address carried in the data read request is read from the hard disk.
[0055] Optionally, it also includes:
[0056] Pre-read the data adjacent to the target data from the hard disk and put the adjacent data into the corresponding memory data management structure.
[0057] The embodiment of the present application further provides a data cache device, comprising a selection unit, a creation unit, a mounting unit, a first writing unit and a second writing unit;
[0058] a selection unit configured to select, upon receiving a write request, a target cache area that matches a target logical address carried in the write request from a plurality of cache areas;
[0059] an establishing unit configured to establish a memory data management structure for the target cache area and mark the application time when the target cache area does not have a corresponding memory data management structure;
[0060] The mounting unit is configured to mount the memory data management structure to the time queue;
[0061] A first writing unit is configured to write data carried in a write request into a memory data management structure;
[0062] The second write unit is configured to write the data carried by the write request into the target memory data management structure that meets the time deviation requirement based on the deviation between the application time of the memory data management structure and the current time when there is a corresponding memory data management structure in the target cache area.
[0063] Optionally, the establishing unit includes a constructing subunit and a marking subunit;
[0064] a construction subunit configured to construct a memory data management structure corresponding to the target cache area according to a logical address range corresponding to the target cache area and a current time when the target cache area does not have a corresponding memory data management structure;
[0065] The marking subunit is set to mark the current time as the application time of the memory data management structure.
[0066] Optionally, the mounting unit is configured to mount the identification information of the memory data management structure to the time queue in chronological order according to the application time of the memory data management structure.
[0067] Optionally, the second writing unit includes a judging subunit, a storing subunit, an establishing subunit, a mounting subunit and a recording subunit;
[0068] The judging subunit is configured to judge whether a time interval between an application time of the memory data management structure and a current time is within a set threshold range when the target cache area has a corresponding memory data management structure;
[0069] The storage subunit is configured to store the data carried in the write request to the location pointed to by the target logical address in the memory data management structure when the time interval between the application time of the memory data management structure and the current time is within a set threshold range;
[0070] An establishing subunit, configured to establish a new memory data management structure and mark the application time when a time interval between an application time of the memory data management structure and a current time is not within a set threshold range;
[0071] The mount subunit is configured to mount the new memory data management structure to the event queue;
[0072] The recording subunit is configured to record the data carried by the write request into the new memory data management structure.
[0073] Optionally, when there are multiple memory data management structures corresponding to the target cache area, the judging subunit is configured to judge whether the time interval between the application time of the most recently established memory data management structure and the current time is within a set threshold range.
[0074] Optionally, the storage subunit is configured to write the data carried by the write request to the location pointed to by the target logical address in the newly established memory data management structure when the time interval between the application time of the newly established memory data management structure and the current time is within a set threshold range.
[0075] Optionally, the storage subunit is configured to determine whether data exists at a target location in the memory data management structure; wherein the target location is a location pointed to by the target logical address;
[0076] If data exists at the target location in the memory data management structure, the data carried in the write request is overwritten and written to the target location;
[0077] When there is no data at the target location in the memory data management structure, the data carried in the write request is written to the target location.
[0078] Optionally, the establishing subunit is configured to construct a new memory data management structure based on a logical address range corresponding to the target cache area and a current time;
[0079] Mark the current time as the application time of the new memory data management structure.
[0080] Optionally, the mounting subunit is configured to mount the identification information of the new memory data management structure to the time queue in chronological order according to the application time of the new memory data management structure.
[0081] Optionally, a setting unit is further included;
[0082] The setting unit is configured to set a write flag for data written into the memory data management structure.
[0083] Optionally, a deposit unit is further included;
[0084] The storing unit is configured to store the data with write flags stored in each memory data management structure into the hard disk in an appended write manner when the total used space of the plurality of cache areas reaches a set water level threshold.
[0085] Optionally, it also includes a time selection unit and an additional writing unit;
[0086] The time selection unit is configured to select a to-be-processed memory data management structure whose time interval between the application time and the current time exceeds the set time threshold when the total used space of the plurality of cache areas reaches the set water level threshold;
[0087] The append writing unit is configured to store the data with the write identifier into the hard disk in an append writing manner according to the order of the memory data management structure to be processed in the time chain list.
[0088] Optionally, an adjustment unit is further included;
[0089] The adjustment unit is configured to adjust the write identifier of the data stored in each to-be-processed memory data management structure to a read identifier.
[0090] Optionally, a deletion unit is further included;
[0091] The deletion unit is configured to delete the data with the read identifier and the memory data management structure to which it belongs according to a set cycle time.
[0092] Optionally, it further includes a query unit and a first reading unit;
[0093] a query unit configured to query a matching first memory data management structure according to a logical address carried in the data read request when receiving the data read request;
[0094] The first reading unit is configured to read target data from the first memory data management structure when target data corresponding to the logical address carried in the data read request exists in the first memory data management structure.
[0095] Optionally, it further includes a second reading unit;
[0096] The second reading unit is configured to read target data matching the logical address carried by the data reading request from the hard disk when the target data corresponding to the logical address carried by the data reading request does not exist in the matching first memory data management structure.
[0097] Optionally, it further includes a pre-reading unit and a putting unit;
[0098] a pre-reading unit configured to pre-read data adjacent to the target data from the hard disk;
[0099] The placing unit is configured to place adjacent data into a corresponding memory data management structure.
[0100] An embodiment of the present application further provides an electronic device, including:
[0101] a memory arranged to store a computer program;
[0102] The processor is configured to execute a computer program to implement the steps of the above data caching method.
[0103] An embodiment of the present application further provides a non-volatile 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 data caching method are implemented.
[0104] As can be seen from the above technical solution, upon receiving a write request, a target cache area matching the target logical address carried by the write request is selected from multiple cache areas. Each cache area has a corresponding logical address range, ensuring that data with partially consecutive logical addresses can be stored in the same cache area, thereby preserving spatial locality between data. A memory data management structure can be viewed as a virtual box encapsulating the cache area, and each memory data management structure has a corresponding application time. If the target cache area does not have a corresponding memory data management structure, it indicates that the target cache area does not store data. In this case, a memory data management structure can be established for the target cache area, marked with the application time, and mounted to a time queue; the data carried by the write request is then written to the memory data management structure. If the target cache area has a corresponding memory data management structure, there may be multiple memory data management structures corresponding to the same cache area. In this case, based on the deviation between the application time of the memory data management structure and the current time, the data carried by the write request can be written to the target memory data management structure that meets the time deviation requirement. In this technical solution, by storing data according to logical addresses, spatial locality between data can be fully preserved. By using the deviation between the application time and current time of the memory data management structure, data can be written to the target memory data management structure that meets the time deviation requirements, fully retaining the temporal locality between data, achieving a balance between spatial locality and temporal locality of data, and greatly improving the storage performance of the cache space. BRIEF DESCRIPTION OF THE DRAWINGS
[0105] In order to more clearly illustrate the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0106] FIG1 is a flow chart of a data caching method provided in an embodiment of the present application;
[0107] FIG2 is a flowchart of a method for writing data into a target memory data management structure provided by an embodiment of the present application;
[0108] FIG3 is a schematic diagram of a memory data management structure constructed according to spatial organization and temporal organization according to an embodiment of the present application;
[0109] FIG4 is a flow chart of a data reading method provided in an embodiment of the present application;
[0110] FIG5 is a schematic structural diagram of a data cache device provided in an embodiment of the present application;
[0111] FIG6 is a structural diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0112] The following will be combined with the accompanying drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0113] The terms "including" and "having," as well as any variations thereof, in the specification and claims of this application and the accompanying drawings, are intended to cover a non-exclusive inclusion. For example, a process, method, system, product, or apparatus comprising a series of steps or elements is not limited to the listed steps or elements and may include steps or elements that are not listed.
[0114] In order to enable those skilled in the art to better understand the present application, the present application is described in detail below in conjunction with the accompanying drawings and optional implementation methods.
[0115] Next, a data caching method provided by an embodiment of the present application is described in detail. FIG1 is a flow chart of a data caching method provided by an embodiment of the present application, the method comprising:
[0116] Si0i: When a write request is received, a target cache area that matches the target logical address carried in the write request is selected from multiple cache areas.
[0117] In embodiments of the present application, the cache space can be divided according to a set granularity to obtain multiple cache areas. The cache space can include multiple data storage objects provided by the storage array to the application server. Each divided cache area has a corresponding logical address range.
[0118] The size of the granularity can be set based on actual needs and is not limited here. For example, it can be set to 8MB.
[0119] The write request carries the data to be cached, the corresponding logical address to be stored, and the data size. To facilitate the distinction between the logical address range corresponding to the cache area, the logical address carried in the write request can be called the target logical address.
[0120] When a write request is received, a cache region that matches the target logical address carried in the write request can be determined based on the logical address ranges corresponding to the multiple cache regions. For ease of distinction, the cache region that matches the target logical address carried in the write request can be referred to as the target cache region.
[0121] S102: If there is no corresponding memory data management structure in the target cache area, a memory data management structure is established for the target cache area, the application time is marked, and the memory data management structure is mounted to the time queue; the data carried by the write request is written into the memory data management structure.
[0122] The memory data management structure can be regarded as a virtual box used to encapsulate the cache area. In order to reflect the time characteristics between data, there can be multiple memory data management structures corresponding to the same cache area. Multiple memory data management structures corresponding to the same cache area can be distinguished based on the application time.
[0123] In an embodiment of the present application, when there is no corresponding memory data management structure for the target cache area, a memory data management structure corresponding to the target cache area can be constructed based on the logical address range corresponding to the target cache area and the current time; and the current time is marked as the application time of the memory data management structure.
[0124] The cache space can include multiple data storage objects. For easy distinction, in actual applications, LUN plus different numbers can be used to represent different data storage objects. For example, two data storage objects can be represented as LUN0 and LUN1 respectively. Different cache areas (EXTENT) can be represented by EXTENT plus different numbers. For example, two cache areas can be represented as EXTENT1, EXTENT2, etc. The different logical address ranges corresponding to each cache area can be represented by "LBA RANGE" plus different numbers. For example, LBA RANGE1 and LBA RANGE2 can be used to represent the respective logical address ranges of the two cache areas. It should be noted that LBA RANGE1 and LBA RANGE2 are only for representing different logical address ranges. In actual implementation, the corresponding actual logical address range will be recorded for each cache area.
[0125] For example, a cache area EXTENT1 divided under LUN0 corresponds to a logical address range of LBA RANGE1. The memory data management structure created at TIME1 can be expressed as LUN0 EXTENT1 (LBA RANGE1) TIME1.
[0126] In an embodiment of the present application, in order to reflect the chronological order of data storage in each memory data management structure, the identification information of the memory data management structure can be mounted to the time queue in chronological order according to the application time of the memory data management structure.
[0127] The identification information of the memory data management structure may be a unique identifier that can be used to distinguish different memory data management structures. In the embodiment of the present application, the form of the identification information is not limited. For example, the identification information may be a combination of the data storage object to which the memory data management structure belongs, the corresponding cache area, and the application time.
[0128] S103: If the target cache area has a corresponding memory data management structure, based on the deviation between the application time of the memory data management structure and the current time, write the data carried by the write request into the target memory data management structure that meets the time deviation requirement.
[0129] Initially, when data needs to be written to a target cache area, a corresponding memory data management structure is created. If new data is written to the target cache area again after a long interval, directly writing the new data to the memory data management structure will cause the data stored in the same memory data management structure to span a wide range of time periods, making it difficult to subsequently read chronologically related data.
[0130] Therefore, in an embodiment of the present application, in order to retain the time characteristics between data to the greatest extent, when the current time deviates significantly from the application time of the memory data management structure, a new memory data management structure can be created for the target cache area and the data can be written into the new memory data management structure.
[0131] As can be seen from the above technical solution, upon receiving a write request, a target cache area matching the target logical address carried by the write request is selected from multiple cache areas. Each cache area has a corresponding logical address range, ensuring that data with partially consecutive logical addresses can be stored in the same cache area, thereby preserving spatial locality between data. A memory data management structure can be viewed as a virtual box encapsulating the cache area, and each memory data management structure has a corresponding application time. If the target cache area does not have a corresponding memory data management structure, it indicates that the target cache area does not store data. In this case, a memory data management structure can be established for the target cache area, marked with the application time, and mounted to a time queue; the data carried by the write request is then written to the memory data management structure. If the target cache area has a corresponding memory data management structure, there may be multiple memory data management structures corresponding to the same cache area. In this case, based on the deviation between the application time of the memory data management structure and the current time, the data carried by the write request can be written to the target memory data management structure that meets the time deviation requirement. In this technical solution, by storing data according to logical addresses, spatial locality between data can be fully preserved. By using the deviation between the application time and current time of the memory data management structure, data can be written to the target memory data management structure that meets the time deviation requirements, fully retaining the temporal locality between data, achieving a balance between spatial locality and temporal locality of data, and greatly improving the storage performance of the cache space.
[0132] FIG2 is a flowchart of a method for writing data into a target memory data management structure according to an embodiment of the present application. The method includes:
[0133] S201: When the target cache area has a corresponding memory data management structure, determine whether the time interval between the application time of the memory data management structure and the current time is within a set threshold range.
[0134] Considering that in actual applications, a target cache area may correspond to multiple memory data management structures, when caching data, it is only necessary to determine whether the time interval between the application time of the most recently established memory data management structure and the current time is within the set threshold range.
[0135] The threshold range can be set based on actual needs, for example, it can be set within 1 minute.
[0136] Whenever a new memory data management structure is created, the time of creating the memory data management structure is used as the application time of the memory data management structure.
[0137] When there is a need for data caching, the time when the write request is received can be used as the current time. When the time interval between the application time of the memory data management structure and the current time is within the set threshold range, it means that the time interval between the data to be written and the data stored in the memory data management structure is short, and S202 can be executed at this time.
[0138] When the time interval between the application time of the memory data management structure and the current time is not within the set threshold range, it means that the time interval between the data to be written and the data stored in the memory data management structure is long. In order to retain the time characteristics between the data, S203 can be executed at this time.
[0139] S202: Storing the data carried in the write request to the location pointed to by the target logical address in the memory data management structure.
[0140] When the time interval between the application time of the newly established memory data management structure and the current time is within the set threshold range, the data carried by the write request can be written to the location pointed to by the target logical address in the newly established memory data management structure.
[0141] Considering that in actual applications, the location where data is to be written may already have data stored, when writing data, it is possible to determine whether the target location in the memory data management structure has data; where the target location is the location pointed to by the target logical address.
[0142] If the target location in the memory data management structure has data, the data carried by the write request can be overwritten and written to the target location. If the target location in the memory data management structure does not have data, the data carried by the write request can be directly written to the target location.
[0143] S203: Create a new memory data management structure and mark the application time, and mount the new memory data management structure to the time queue; record the data carried by the write request into the new memory data management structure.
[0144] In order to facilitate the distinction between different memory data management structures, in actual implementation, a new memory data management structure can be constructed based on the logical address range corresponding to the target cache area and the current time; the current time is marked as the application time of the new memory data management structure.
[0145] After the new memory data management structure is constructed, the identification information of the new memory data management structure may be mounted to the time queue in chronological order according to the application time of the new memory data management structure.
[0146] FIG3 is a schematic diagram of a memory data management structure constructed according to spatial organization and temporal organization, provided by an embodiment of the present application. FIG3 takes two data storage objects, data storage object 0 and data storage object 1, as an example. Data storage object 0 is divided into two cache areas, cache area 1 and cache area 2. Data storage object 1 is also divided into two cache areas, cache area 1 and cache area 2.
[0147] Taking data storage object 0 as an example, cache area 1 corresponds to two memory data management structures. These two memory data management structures correspond to the same cache area and therefore the same logical address range 1. Since the two memory data management structures have different application times, they can be represented by time 0 and time 1. Cache area 2 corresponds to one memory data management structure, which corresponds to logical address range 2 and was applied at time 3.
[0148] Taking data storage object 1 as an example, cache area 1 and cache area 2 each correspond to a memory data management structure. Cache area 1 corresponds to logical address range 3, and cache area 2 corresponds to logical address range 4. For example, if the memory data management structures for these two cache areas were created simultaneously, the application time corresponding to both cache areas would be time 2. The right-hand box in Figure 3 shows a schematic diagram of sorting the memory data management structures by their corresponding application time. In practical applications, the identification information of each memory data management structure can be recorded in a time queue in chronological order of application time.
[0149] In an embodiment of the present application, if a corresponding memory data management structure exists in the target cache area, a determination is made as to whether the time interval between the application time of the memory data management structure and the current time is within a set threshold. The data carried by the write request is stored in the location pointed to by the target logical address in the memory data management structure. A new memory data management structure is established and the application time is marked, and the new memory data management structure is mounted on the time queue; the data carried by the write request is recorded in the new memory data management structure.
[0150] By dividing the cache space into multiple cache areas at a set granularity and configuring different memory data management structures for the same cache space based on time, the memory data management structure has both spatial and temporal attributes. Data within different time ranges is distributed and managed separately within different memory data management structures. Data with the same logical address within the same time range overwrites each other within the same memory data management structure. The memory data management structures of all cache spaces are managed together in chronological order, allowing all cached data to be written to disk in chronological order.
[0151] To help the system understand whether the data stored in the current memory data management structure has been written to disk, a flag can be set for the data. For example, if the data stored in the memory data management structure has been sent to the hard disk for storage, a read flag can be set for the memory data management structure. If the data stored in the memory data management structure has not yet been sent to the hard disk for storage, a write flag can be set for the memory data management structure. A write flag is set for data written to the memory data management structure.
[0152] In the embodiment of the present application, a water level threshold can be set to trigger the data write operation. In actual implementation, when the total used space of multiple cache areas reaches the set water level threshold, the data with write flags stored in each memory data management structure can be written to the hard disk in an append-write manner.
[0153] The value of the water level threshold can be set according to the proportion of the total space of the cache area. For example, if the total space of the cache area is 10G and the proportion is 90%, the water level threshold can be set to 9G.
[0154] In addition to directly storing the data with write flags stored in each memory data management structure to the hard disk in an append-write manner, the storage time of the data in each memory data management structure can also be considered. In actual implementation, when the total used space of multiple cache areas reaches a set water level threshold, the memory data management structure to be processed whose time interval between the application time and the current time exceeds the set time threshold can be selected. Based on the order of the memory data management structures to be processed in the time chain list, the data with write flags set to the hard disk in an append-write manner.
[0155] Considering that in actual applications, data that has just been stored on the hard disk is more likely to be accessed within a short period of time, in order to improve data reading efficiency, the data stored on the hard disk can be retained in the memory data management structure for a period of time. In order to distinguish it from the data newly written into the memory data management structure, the data with write flags can be stored on the hard disk in an append-write manner according to the order of the pending memory data management structures in the time chain list. After that, the write flags of the data stored in each pending memory data management structure can be adjusted to read flags.
[0156] In order to prevent the data written into the hard disk from occupying the memory data management structure for a long time, the data with a read flag and the memory data management structure to which it belongs can be deleted according to a set cycle time.
[0157] By caching the data written to the hard disk in the memory data management structure for a period of time, we can ensure the reading efficiency of the data written to the hard disk when it is called, and also prevent the data written to the hard disk from occupying the cache space of the memory data management structure for a long time.
[0158] FIG4 is a flow chart of a data reading method provided in an embodiment of the present application, the method comprising:
[0159] S401: When a data read request is received, a matching first memory data management structure is searched according to a logical address carried in the data read request.
[0160] A read request carries the logical address and size of the data to be read. Each memory data management structure has a corresponding logical address range. Based on the logical address carried in the read request, a matching memory data management structure can be determined. To distinguish it from other memory data management structures, the memory data management structure that matches the logical address carried in the data read request can be referred to as the first memory data management structure.
[0161] S402: When target data corresponding to the logical address carried in the data read request exists in the first memory data management structure, read the target data from the first memory data management structure.
[0162] When the target data corresponding to the logical address carried by the data read request exists in the first memory data management structure, it means that the data to be read is still stored in the memory data management structure. In order to improve data reading efficiency, the target data can be read directly from the first memory data management structure.
[0163] S403: If target data corresponding to the logical address carried in the data read request does not exist in the matching first memory data management structure, read the target data matching the logical address carried in the data read request from the hard disk.
[0164] When the target data corresponding to the logical address carried by the data read request does not exist in the first memory data management structure, it means that the data to be read no longer exists in the memory data management structure. At this time, the target data matching the logical address carried by the data read request needs to be read from the hard disk.
[0165] Considering that in actual applications, after the current data is read, the probability of reading data that is logically adjacent to the data or time adjacent to the data is very high, in order to improve the data reading efficiency, a data pre-reading operation can be performed.
[0166] In actual implementation, data adjacent to the target data can be pre-read from the hard disk, and the adjacent data can be placed into the corresponding memory data management structure.
[0167] In the embodiment of the present application, since the data is written to the hard disk in the order of the application time of the memory data management structure when it is written to the disk, it is saved adjacently in time order, and the data in a single memory data management structure is spatially adjacent, so when pre-reading data, the data on the hard disk that is adjacent to the read data can be pre-read, that is, the data that is spatially adjacent and temporally adjacent are all pre-read, thereby improving the hit rate of the pre-read data.
[0168] FIG5 is a schematic diagram of the structure of a data cache device provided in an embodiment of the present application, including a selection unit 51, an establishment unit 52, a mounting unit 53, a first writing unit 54 and a second writing unit 55;
[0169] The selection unit 51 is configured to select, when receiving a write request, a target cache area that matches a target logical address carried in the write request from a plurality of cache areas;
[0170] The establishing unit 52 is configured to establish a memory data management structure for the target cache area and mark the application time when the target cache area does not have a corresponding memory data management structure;
[0171] The mounting unit 53 is configured to mount the memory data management structure to the time queue;
[0172] A first writing unit 54 is configured to write the data carried in the write request into the memory data management structure;
[0173] The second writing unit 55 is configured to write the data carried in the write request into the target memory data management structure that meets the time deviation requirement based on the deviation between the application time of the memory data management structure and the current time when there is a corresponding memory data management structure in the target cache area.
[0174] Optionally, the establishing unit includes a constructing subunit and a marking subunit;
[0175] a construction subunit configured to construct a memory data management structure corresponding to the target cache area according to a logical address range corresponding to the target cache area and a current time when the target cache area does not have a corresponding memory data management structure;
[0176] The marking subunit is set to mark the current time as the application time of the memory data management structure.
[0177] Optionally, the mounting unit is configured to mount the identification information of the memory data management structure to the time queue in chronological order according to the application time of the memory data management structure.
[0178] Optionally, the second writing unit includes a judging subunit, a storing subunit, an establishing subunit, a mounting subunit and a recording subunit;
[0179] The judging subunit is configured to judge whether a time interval between an application time of the memory data management structure and a current time is within a set threshold range when the target cache area has a corresponding memory data management structure;
[0180] The storage subunit is configured to store the data carried in the write request to the location pointed to by the target logical address in the memory data management structure when the time interval between the application time of the memory data management structure and the current time is within a set threshold range;
[0181] An establishing subunit, configured to establish a new memory data management structure and mark the application time when a time interval between an application time of the memory data management structure and a current time is not within a set threshold range;
[0182] The mount subunit is configured to mount the new memory data management structure to the event queue;
[0183] The recording subunit is configured to record the data carried by the write request into the new memory data management structure.
[0184] Optionally, when there are multiple memory data management structures corresponding to the target cache area, the judging subunit is configured to judge whether the time interval between the application time of the most recently established memory data management structure and the current time is within a set threshold range.
[0185] Optionally, the storage subunit is configured to write the data carried by the write request to the location pointed to by the target logical address in the newly established memory data management structure when the time interval between the application time of the newly established memory data management structure and the current time is within a set threshold range.
[0186] Optionally, the storage subunit is configured to determine whether data exists at a target location in the memory data management structure; wherein the target location is a location pointed to by the target logical address;
[0187] If data exists at the target location in the memory data management structure, the data carried in the write request is overwritten and written to the target location;
[0188] When there is no data at the target location in the memory data management structure, the data carried in the write request is written to the target location.
[0189] Optionally, the establishing subunit is configured to construct a new memory data management structure based on a logical address range corresponding to the target cache area and a current time;
[0190] Mark the current time as the application time of the new memory data management structure.
[0191] Optionally, the mounting subunit is configured to mount the identification information of the new memory data management structure to the time queue in chronological order according to the application time of the new memory data management structure.
[0192] Optionally, a setting unit is further included;
[0193] The setting unit is configured to set a write flag for data written into the memory data management structure.
[0194] Optionally, a deposit unit is further included;
[0195] The storing unit is configured to store the data with write flags stored in each memory data management structure into the hard disk in an appended write manner when the total used space of the plurality of cache areas reaches a set water level threshold.
[0196] Optionally, it also includes a time selection unit and an additional writing unit;
[0197] The time selection unit is configured to select a to-be-processed memory data management structure whose time interval between the application time and the current time exceeds the set time threshold when the total used space of the plurality of cache areas reaches the set water level threshold;
[0198] The append writing unit is configured to store the data with the write identifier into the hard disk in an append writing manner according to the order of the memory data management structure to be processed in the time chain list.
[0199] Optionally, an adjustment unit is further included;
[0200] The adjustment unit is configured to adjust the write identifier of the data stored in each to-be-processed memory data management structure to a read identifier.
[0201] Optionally, a deletion unit is further included;
[0202] The deletion unit is configured to delete the data with the read identifier and the memory data management structure to which it belongs according to a set cycle time.
[0203] Optionally, it further includes a query unit and a first reading unit;
[0204] a query unit configured to query a matching first memory data management structure according to a logical address carried in the data read request when receiving the data read request;
[0205] The first reading unit is configured to read target data from the first memory data management structure when target data corresponding to the logical address carried in the data read request exists in the first memory data management structure.
[0206] Optionally, it further includes a second reading unit;
[0207] The second reading unit is configured to read target data matching the logical address carried by the data reading request from the hard disk when the target data corresponding to the logical address carried by the data reading request does not exist in the matching first memory data management structure.
[0208] Optionally, it further includes a pre-reading unit and a putting unit;
[0209] a pre-reading unit configured to pre-read data adjacent to the target data from the hard disk;
[0210] The placing unit is configured to place adjacent data into a corresponding memory data management structure.
[0211] For the description of the features in the embodiment corresponding to FIG5 , reference can be made to the relevant descriptions of the embodiments corresponding to FIG1 , FIG2 and FIG4 , and they will not be described one by one here.
[0212] As can be seen from the above technical solution, upon receiving a write request, a target cache area matching the target logical address carried by the write request is selected from multiple cache areas. Each cache area has a corresponding logical address range, ensuring that data with partially consecutive logical addresses can be stored in the same cache area, thereby preserving spatial locality between data. A memory data management structure can be viewed as a virtual box encapsulating the cache area, and each memory data management structure has a corresponding application time. If the target cache area does not have a corresponding memory data management structure, it indicates that the target cache area does not store data. In this case, a memory data management structure can be established for the target cache area, marked with the application time, and mounted to a time queue; the data carried by the write request is then written to the memory data management structure. If the target cache area has a corresponding memory data management structure, there may be multiple memory data management structures corresponding to the same cache area. In this case, based on the deviation between the application time of the memory data management structure and the current time, the data carried by the write request can be written to the target memory data management structure that meets the time deviation requirement. In this technical solution, by storing data according to logical addresses, spatial locality between data can be fully preserved. By calculating the deviation between the application time and the current time of the memory data management structure, data can be written to the target memory data management structure that meets the time deviation requirements, fully preserving the temporal locality between data, achieving a balance between spatial locality and temporal locality of data, and greatly improving the performance of the cache space.
[0213] FIG6 is a structural diagram of an electronic device provided in an embodiment of the present application. As shown in FIG6 , the electronic device includes: a memory 20 configured to store computer programs;
[0214] The processor 21 is configured to implement the steps of the data caching method in the above embodiment when executing a computer program.
[0215] The electronic 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.
[0216] Among them, the processor 21 may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor 21 can be implemented in at least one hardware form of DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), and PLA (Programmable Logic Array). The processor 21 may also include a main processor and a coprocessor. The main processor is a processor configured to process data in the awake state, also known as a CPU (Central Processing Unit); the coprocessor is a low-power processor configured to process data in the standby state. In some embodiments, the processor 21 may be integrated with a GPU (Graphics Processing Unit), and the GPU is configured to be responsible for rendering and drawing the content to be displayed on the display screen. In some embodiments, the processor 21 may also include an AI (Artificial Intelligence) processor, which is configured to process computing operations related to machine learning.
[0217] The memory 20 may include one or more non-volatile readable storage media, which may be non-transitory. The memory 20 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 20 is at least configured to store the following computer program 201, wherein, after the computer program is loaded and executed by the processor 21, it can implement the relevant steps of the data caching method disclosed in any of the aforementioned embodiments. In addition, the resources stored in the memory 20 may also include an operating system 202 and data 203, etc., and the storage method may be temporary storage or permanent storage. Among them, the operating system 202 may include Windows, Unix, Linux, etc. The data 203 may include but is not limited to the logical address corresponding to each cache area, etc.
[0218] In some embodiments, the electronic device may further include a display screen 22 , an input / output interface 23 , a communication interface 24 , a power supply 25 , and a communication bus 26 .
[0219] Those skilled in the art will appreciate that the structure shown in FIG6 does not limit the electronic device and may include more or fewer components than shown in the figure.
[0220] It is understandable that if the data caching 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 non-volatile readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium and executes all or part of the steps of the various embodiments of the present application. 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, etc. Various media that can store program code.
[0221] Based on this, an embodiment of the present application further provides a non-volatile 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 data caching method are implemented.
[0222] The above describes in detail a data caching method, apparatus, device, and non-volatile readable storage medium provided in the embodiments of the present application. The various embodiments in the specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various 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 section.
[0223] Professionals can also 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 above description has generally described the components and steps of each example according to their functions. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0224] The above is a detailed introduction to a data caching method, device, equipment and non-volatile readable storage medium provided by the present application. Optional individual examples are used herein to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea. It should be pointed out that for ordinary technicians in this technical field, without departing from the principles of the present application, several improvements and modifications can be made to the present application, and these improvements and modifications also fall within the scope of protection of the claims of the present application.
Claims
1. A data caching method, characterized in that: include: When a write request is received, selecting a target cache area that matches a target logical address carried by the write request from a plurality of cache areas; In the case that the target cache area has no corresponding memory data management structure, a memory data management structure is established for the target cache area and the application time is marked, and the memory data management structure is mounted to the time queue; Writing the data carried by the write request into the memory data management structure; In the case where the target cache area has a corresponding memory data management structure, based on the deviation between the application time of the memory data management structure and the current time, the data carried by the write request is written into the target memory data management structure that meets the time deviation requirement.
2. The data caching method according to claim 1, characterized in that: In the case where the target cache area has no corresponding memory data management structure, establishing a memory data management structure for the target cache area and marking the application time includes: In the case where the target cache area has no corresponding memory data management structure, constructing a memory data management structure corresponding to the target cache area according to the logical address range corresponding to the target cache area and the current time; The current time is marked as the application time of the memory data management structure.
3. The data caching method according to claim 1, characterized in that: The step of mounting the memory data management structure to the time queue comprises: According to the application time of the memory data management structure, the identification information of the memory data management structure is mounted to the time queue in chronological order.
4. The data caching method according to claim 1, characterized in that: In the case where the target cache area has a corresponding memory data management structure, based on the deviation between the application time of the memory data management structure and the current time, writing the data carried by the write request into the target memory data management structure that meets the time deviation requirement includes: In the case where the target cache area has a corresponding memory data management structure, determining whether the time interval between the application time of the memory data management structure and the current time is within a set threshold range; When the time interval between the application time of the memory data management structure and the current time is within a set threshold range, storing the data carried by the write request to the location pointed to by the target logical address in the memory data management structure; When the time interval between the application time of the memory data management structure and the current time is not within the set threshold range, a new memory data management structure is established and the application time is marked, and the new memory data management structure is mounted to the time queue; the data carried by the write request is recorded in the new memory data management structure.
5. The data caching method according to claim 4, characterized in that: In the case where there are multiple memory data management structures corresponding to the target cache area, the determining whether the time interval between the application time of the memory data management structure and the current time is within a set threshold range includes: Determine whether the time interval between the application time of the latest created memory data management structure and the current time is within a set threshold range.
6. The data caching method according to claim 5, characterized in that: When the time interval between the application time of the memory data management structure and the current time is within a set threshold range, storing the data carried by the write request to the location pointed to by the target logical address in the memory data management structure includes: When the time interval between the application time of the newly established memory data management structure and the current time is within a set threshold range, the data carried by the write request is written to the location pointed to by the target logical address in the newly established memory data management structure.
7. The data caching method according to claim 4, characterized in that: The storing the data carried by the write request to the location pointed to by the target logical address in the memory data management structure comprises: Determine whether there is data at a target location in the memory data management structure; wherein the target location is the location pointed to by the target logical address; If data exists at the target location in the memory data management structure, overwriting the data carried by the write request to the target location; When there is no data at the target location in the memory data management structure, the data carried by the write request is written to the target location.
8. The data caching method according to claim 4, characterized in that: The establishment of a new memory data management structure and marking the application time includes: Constructing a new memory data management structure according to the logical address range corresponding to the target cache area and the current time; The current time is marked as the application time of the new memory data management structure.
9. The data caching method according to claim 4, characterized in that: The step of mounting the new memory data management structure to the time queue comprises: According to the application time of the new memory data management structure, the identification information of the new memory data management structure is mounted to the time queue in chronological order.
10. The data caching method according to claim 1, characterized in that: After writing the data carried by the write request into the memory data management structure, the following further comprises: A write flag is set for data written into the memory data management structure.
11. The data caching method according to claim 10, characterized in that: Also includes: When the total used space amount of the plurality of cache areas reaches a set water level threshold, the data with write flags stored in the memory data management structures are stored in the hard disk in an append-write manner.
12. The data caching method according to claim 10, characterized in that: Also includes: When the total used space of the plurality of cache areas reaches a set water level threshold, selecting a to-be-processed memory data management structure whose time interval between the application time and the current time exceeds the set time threshold; According to the order of the to-be-processed memory data management structure in the time chain list, the data with the write mark is stored in the hard disk in an append-write mode.
13. The data caching method according to claim 12, characterized in that: After storing the data with write identifiers in the hard disk in an append-write manner according to the order of the memory data management structure to be processed in the time chain list, the method further includes: The write identifier of the data stored in each of the to-be-processed memory data management structures is adjusted to a read identifier.
14. The data caching method according to claim 13, characterized in that: Also includes: According to the set cycle time, the data with the read mark and the memory data management structure to which it belongs are deleted.
15. The data caching method according to claim 1, characterized in that: Also includes: When a data read request is received, querying a matching first memory data management structure according to a logical address carried in the data read request; In a case where target data corresponding to the logical address carried by the data read request exists in the first memory data management structure, the target data is read from the first memory data management structure.
16. The data caching method according to claim 15, characterized in that: Also includes: In a case where the target data corresponding to the logical address carried by the data read request does not exist in the matching first memory data management structure, the target data matching the logical address carried by the data read request is read from the hard disk.
17. The data caching method according to claim 16, characterized in that: Also includes: Data adjacent to the target data is pre-read from the hard disk, and the adjacent data is placed into a corresponding memory data management structure.
18. A data cache device, characterized in that: It includes a selection unit, a creation unit, a mounting unit, a first writing unit and a second writing unit; The selection unit is configured to select, when receiving a write request, a target cache area that matches a target logical address carried by the write request from a plurality of cache areas; The establishing unit is configured to establish a memory data management structure for the target cache area and mark the application time when the target cache area has no corresponding memory data management structure; The mounting unit is configured to mount the memory data management structure to a time queue; The first writing unit is configured to write the data carried by the write request into the memory data management structure; The second writing unit is configured to write the data carried by the write request into the target memory data management structure that meets the time deviation requirement based on the deviation between the application time of the memory data management structure and the current time when there is a corresponding memory data management structure in the target cache area.
19. An electronic device, characterized in that: include: a memory arranged to store a computer program; A processor is configured to execute the computer program to implement the steps of the data caching method according to any one of claims 1 to 17.
20. A non-volatile readable storage medium, characterized in that: The non-volatile readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the data caching method according to any one of claims 1 to 17 are implemented.
Citation Information
Patent Citations
Storage data management method, device and equipment and computer readable storage medium
CN110008142A
Data writing method and device
CN111913664A
Data caching method, device and equipment and computer readable storage medium
CN115952110A
Methods and systems for client-side, on-disk caching
US20060010173A1
