Data writing method and device, electronic equipment and computer readable storage medium
By selecting the write target storage segment according to the data heat level in the all-flash system, the problem of write amplification during garbage collection is solved, the service life of the flash disk is extended, and the system performance and stability are improved.
Patent Information
- Application Number
- CN202410833829.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-25
- Publication Date
- 2024-10-25
- Estimated Expiration
- 2044-06-25
AI Technical Summary
In an all-flash system, the garbage collection process is accompanied by the migration of valid data, resulting in write amplification, which increases the number of write operations on the flash disk, reduces the speed and service life of the flash memory, and reduces system stability.
By determining the heat level of the data when a data write request is detected, and writing the data to the matching storage segment, the free segment information recorded in the shared pool is used to select the target storage segment to reduce write amplification.
It effectively reduces the amount of valid data during garbage data recycling, reduces the write amplification phenomenon, extends the service life of the flash disk, and improves the writing performance and stability of the system.
Smart Images

Figure CN118838541A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of storage technology, and in particular to a data writing method, device, electronic device and computer-readable storage medium. Background Art
[0002] With the continuous development of storage technology, compared with traditional disks, flash memory-based solid-state drives (referred to as flash drives) are widely used in storage systems due to their advantages in performance, reliability, space utilization, etc.; here, the storage system that uses flash drives as storage media can be called an all-flash system.
[0003] In an all-flash system, garbage collection of junk data is required to improve the space utilization of the system. However, since the garbage collection process is often accompanied by the migration of valid data, it will lead to write amplification. The so-called write amplification phenomenon refers to the fact that the actual amount of data written by the system to the flash disk is much greater than the amount of data written by other electronic devices to the system. Write amplification will increase the number of write operations to the flash disk, causing problems such as reduced flash speed, shortened service life, and reduced stability. Based on this, how to reduce write amplification is a technical problem that needs to be solved urgently. Summary of the invention
[0004] In view of this, the present application provides a data writing method, device, electronic device and computer-readable storage medium to reduce write amplification.
[0005] The present application provides a data writing method, which is applied to a storage device; the storage device provides X flash disks as memory of an external designated device connected to the storage device, where X is greater than 1; each flash disk includes Y storage blocks, where Y is greater than 1; each storage block of the X flash disks is grouped into Z storage segments, where Z is greater than 1; in an initialization state, information of the Z storage segments is recorded in a shared pool configured by the storage device; the method includes:
[0006] When a data write request sent by an external designated device is detected, the data write request at least indicates the data to be written and a first storage location identifier corresponding to the storage location where the data is to be written; determining a first data heat level matched by the first storage location identifier; the first data heat level is used to indicate a data update frequency at the storage location corresponding to the first storage location identifier;
[0007] If there is no at least one storage segment matching the first data heat level in the currently used storage segments, based on the information of the free storage segments recorded in the shared pool, a free storage segment is selected as the first target storage segment matching the first data heat level, and the data is written to the first target storage segment; if there is a first target storage segment matching the first data heat level in the currently used storage segments and the free storage space is sufficient to accommodate the data, the data is written to the free storage space in the first target storage segment.
[0008] The embodiment of the present application also provides a data writing device, which is configured in a storage device; the storage device provides X flash disks as memory of an external designated device connected to the storage device, X is greater than 1; each flash disk includes Y storage blocks, Y is greater than 1; each storage block of the X flash disks is grouped into Z storage segments, Z is greater than 1; in an initialized state, the storage device is configured with a shared pool that records information of the Z storage segments; the device includes:
[0009] A determination module, for, when a data write request sent by an external designated device is detected, the data write request at least indicates the data to be written and a first storage location identifier corresponding to the storage location to which the data is to be written; determining a first data heat level matched by the first storage location identifier; the first data heat level is used to indicate a data update frequency at the storage location corresponding to the first storage location identifier;
[0010] A writing module is used to select a free storage segment as a first target storage segment matching the first data heat level based on the information of the free storage segments recorded in the shared pool if there is no at least one storage segment matching the first data heat level in the currently used storage segments, and write the data to the first target storage segment; if there is a first target storage segment matching the first data heat level and the free storage space is sufficient to accommodate the data in the currently used storage segments, the data is written to the free storage space in the first target storage segment.
[0011] The present application also provides an electronic device, the electronic device comprising:
[0012] Processor; and
[0013] A memory, in which computer program instructions are stored, and when the computer program instructions are executed by a processor, the processor executes the steps of the above method.
[0014] An embodiment of the present application further provides a computer-readable storage medium, on which computer program instructions are stored. When the computer program instructions are executed by a processor, the processor executes the steps in the above method.
[0015] It can be seen from the above technical solution that in this embodiment, when a data write request sent by an external designated device is detected, the data heat level that matches the storage location identifier corresponding to the data to be written is first determined. The data heat level indicates the data update frequency at the storage location corresponding to the data to be written. Then, the target storage segment to be written is determined for the data according to the determined data heat level for data writing. In this way, part or all of the data in the same storage segment can become invalid and become garbage data at approximately the same time, thereby effectively reducing the amount of valid data in the storage segment during subsequent garbage data recovery, thereby reducing write amplification. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] The accompanying drawings, which are incorporated in the specification and constitute a part of this application, illustrate embodiments consistent with the application and, together with the description, serve to explain the principles of the application.
[0017] Figure 1 A schematic diagram of the SSD disk garbage collection principle provided in an embodiment of the present application.
[0018] Figure 2 A flow chart of the method provided in an embodiment of the present application.
[0019] Figure 3 A schematic diagram of the implementation of cold and hot data discrimination provided in an embodiment of the present application.
[0020] Figure 4 A schematic diagram of an array provided in an embodiment of the present application.
[0021] Figure 5 A schematic diagram of array weight configuration provided in an embodiment of the present application.
[0022] Figure 6 A schematic diagram of the implementation of garbage collection provided in an embodiment of the present application.
[0023] Figure 7 This is a diagram of the device structure provided in an embodiment of the present application.
[0024] Figure 8 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0025] To facilitate understanding of the present solution, before describing the present solution, the technical problems existing in the existing storage system involved in the embodiments of the present application are described first:
[0026] In an all-flash system, garbage collection is mainly involved at two levels. The first level is a single SSD disk (i.e., flash disk) as a storage medium, and the second level is the entire all-flash system. Here, garbage collection refers to a mechanism for reclaiming invalid data space; in a storage system, a large amount of invalid data is generated due to the dynamic writing and deletion of data, and the space occupied by these invalid data cannot be released immediately. The main purpose of garbage collection is to identify and recycle these invalid data, thereby improving the space utilization of the storage system.
[0027] The following is a description of garbage collection at the SSD disk level:
[0028] The reason why SSD disks need garbage collection is related to their internal working principle. SSD disks use flash memory to store data, and their internal storage units are usually composed of data pages (Page) and storage blocks (Block). For example, the size of a data page (also called a page) is usually 4KB, and a block usually contains a fixed number of pages (such as generally an integer power of 2), and the size of a block usually ranges from hundreds of KB to thousands of KB.
[0029] The smallest write unit of an SSD is a page. However, due to the nature of flash memory particles, if data needs to be updated after being written, it cannot be updated locally (i.e., in-place update). The original data must be erased before new data can be written. Also due to the nature of flash memory particles, the erase operation needs to be performed in blocks, and compared with reading and writing, the erase operation is particularly time-consuming (milliseconds; in contrast, the time taken to read and write a page is 10 microseconds). The inconsistency between the granularity of the data write unit and the data erase unit, as well as the fact that the erase operation is too slow, are the two reasons why data cannot be updated in place and the updated data needs to be written to a new location.
[0030] See also Figure 1 As shown, a storage block 100 includes multiple data pages 101; data A, B, and C are first written to three pages in a certain block, and this block is called Block X (i.e., storage block X). Then, data D, E, and F are written to this Block X; and data A, B, and C are updated to A', B', and C'. At this time, because the flash memory cannot be updated locally, A', B', and C' need to be written to a new page in Block X (if there is no free space in Block X ( Figure 1In the above example, free means free Page, which can be considered as free space in Block), so it needs to be written to the free space of other Blocks, so the original data A, B, C become garbage data, and the Pages they occupy cannot be used. In order to reuse the Pages occupied by the garbage data, it is necessary to find a free Block Y (i.e. storage block Y), copy the valid data in Block X (i.e. including data D, E, F and data A′, B′, C′) to Block Y, and then erase Block X as a whole. In this way, the space occupied by the garbage data A, B, C is recycled.
[0031] It should be noted that the garbage collection process of the SSD disk is transparent to the upper-layer applications (i.e., the applications on the electronic devices deployed with the all-flash system). In other words, from the perspective of the application or OS, the logical location of the updated data is the file offset or the logical block address (Logical Block Addressing, LBA), but the SSD disk remaps the logical address (such as LBA) and the physical address of the SSD disk through an address mapping layer (FTL) in the disk, which the upper layer cannot perceive. Here, LBA is a way to identify the data storage location on the disk.
[0032] The following describes the all-flash system level:
[0033] From the perspective of an all-flash system, there are two types of write strategies: in-place write and log-write. In the in-place write method, from the perspective of the all-flash system, data is written directly to its original location. When existing data needs to be updated or modified, in-place write will write directly to the original location, overwriting the original data. From the perspective of the SSD disk, it may receive a large amount of random input / output (IO).
[0034] The log writing method is to write new data sequentially to the log. When existing data needs to be updated, the new data is appended to the log sequentially, while the original written data remains unchanged. The data in the log is written sequentially, which can achieve higher write performance for intensive small IO write scenarios. At this time, the updated data will become garbage data, and garbage collection is required to reuse the space it occupies. From the perspective of the SSD disk, its data is written sequentially.
[0035] Whether it is a disk (HDD) or an SSD, the sequential write performance is much higher than the random write performance. Moreover, if garbage collection is done well at the system level, in theory, it is not necessary to do garbage collection at the SSD level. At this time, the OP space of the SSD disk (that is, the over-configured space, which generally accounts for more than 10% of the overall capacity of a single SSD disk and cannot be directly used by users) can be greatly reduced, thereby improving storage utilization. Therefore, all-flash systems based on log writing are widely used.
[0036] It can be seen that garbage collection is a universal requirement, whether in a single SSD or in an all-flash system based on log writing. Because the garbage collection process is accompanied by the migration of valid data, it will inevitably lead to write amplification. From a system perspective, the actual amount of writes to the SSD by the all-flash system is much greater than the amount of data written by the host application to the all-flash system. Write amplification will have an adverse effect on the SSD because it increases the number of write operations to the flash chip, which will lead to problems such as reduced flash speed, shortened service life, and reduced stability. Therefore, how to reduce write amplification from the system level has become a technical problem that needs to be solved urgently.
[0037] In this embodiment, for the convenience of management and implementation, the use space of the SSD disk as the storage medium can be further grouped. For example, a number of consecutive fixed numbers of Blocks can be grouped into a storage segment (a segment can be called a Segment, Section or Zone, etc., and is called a Segment in this embodiment). In this way, an SSD disk will contain several Segments. In order to give full play to the performance of the all-flash system, the data writing rules meet the following requirements: the all-flash system is implemented based on the log-write method; the all-flash system is implemented based on the log-write method; the all-flash system can write to multiple segments concurrently; for each segment, data is written sequentially, and the remaining free segments are written after it is full; garbage collection is performed in segments.
[0038] Under the above requirements, it can be seen that the all-flash system is initially full of free segments, and as data is written, the free segments gradually decrease. At the same time, data updates will cause the garbage data in the segments to gradually increase. At a certain point, the all-flash system needs to perform garbage collection to obtain free segments. At this time, in order to obtain the minimum write amplification, the following two problems will exist:
[0039] 1) How to lay out the user's written data in the segment (because data can be written to multiple data segments concurrently);
[0040] 2) What strategy should be adopted when performing garbage collection (for example, which segments to collect garbage for; how to rearrange the data for valid data in the garbage segments, etc.)
[0041] In this embodiment, a concept is first introduced, the data life cycle. The so-called data life cycle refers to the time that data exists before being updated. After the data is updated, the previously written data becomes garbage data. Therefore, when a piece of data is updated multiple times, except for the last written data in the all-flash system, all the previous data becomes garbage data. For the first question above, if you look at it from a bird's eye view, when writing data, data with the same life cycle or approximately the same life cycle should be put into the same segment. In this way, the data of the entire segment will become garbage data in almost the same time; at this time, recycling this segment does not require any effective data movement, and the entire segment can be directly erased, and the write amplification is optimized. But in fact, there is no bird's eye view, so the future life cycle of a piece of data can only be estimated based on its previous update frequency. For example, if a piece of data has a data whose corresponding storage location is frequently updated, it can be considered that the data will still have a greater probability of being updated in the future. This data can be called hot data; relatively speaking, if a piece of data is not updated for a long time, this data can be called cold data. It should be noted that, in addition to considering the average number of data updates in the past period of time, the life cycle of the predicted data also needs to consider the recency information of the data update (recency refers to the time interval between the last update time of the data at the storage location and the current time). For example, the data at the two storage locations A and B have been updated 10 times in the past 3 minutes, but the data update at the A storage location all occurred in the first minute; and the data update at the B storage location occurred in the third minute. At this time, the frequency of data updates at the two storage locations A and B is the same, but the recency of the B storage location is greater, which means that the data at the B storage location is more likely to continue to be updated in the short future, that is, the data at the B storage location is hotter. Therefore, in this embodiment, when writing data, it is necessary to separate the hot and cold data and put them in different segments so that the data in the segment will become garbage data at approximately the same time, thereby reducing write amplification. Then, how to identify hot and cold data becomes a problem. The above storage location can be understood as the storage location (such as a logical address, etc.) to which the data carried in the data write request is to be written.
[0042] In summary, from the perspective of reducing system write amplification, the garbage collection problem of the all-flash system can be abstracted into the following two problems:
[0043] 1) The problem of identifying hot and cold data (putting hot and cold data into different segments after identification);
[0044] 2) During garbage collection, there is the issue of selecting the recycling segment and how to layout the valid data in the garbage segment.
[0045] To solve the above technical problems, the embodiment of the present application provides a data writing method. In order to enable those skilled in the art to better understand the technical solution provided by the embodiment of the present application, and to make the above-mentioned purposes, features and advantages of the embodiment of the present application more obvious and easy to understand, the technical solution in the embodiment of the present application is further described in detail below with reference to the accompanying drawings.
[0046] See also Figure 2 , Figure 2 A flow chart of a method provided for an embodiment of the present application. The method is applied to a storage device; the storage device provides X flash disks as memory of an external designated device connected to the storage device, X is greater than 1; each flash disk includes Y storage blocks, Y is greater than 1; each storage block of the X flash disks is grouped into Z storage segments, Z is greater than 1; in the initialization state, the storage device is configured with a shared pool that records information of the Z storage segments. As an embodiment, the storage device refers to a device such as a database server, and the external designated device refers to an electronic device corresponding to a client, which is not specifically limited in this embodiment.
[0047] like Figure 2 As shown, the process may include the following steps:
[0048] Step 201, when a data write request sent by an external designated device is detected, the data write request at least indicates the data to be written and a first storage location identifier corresponding to the storage location where the data is to be written, and determines a first data heat level matched by the first storage location identifier.
[0049] In this embodiment, when a data write request sent by an external designated device is detected, a first data heat level matching the first storage location identifier indicated by the data write request is determined. Here, the first data heat level is used to indicate the data update frequency at the storage location corresponding to the first storage location identifier.
[0050] In this embodiment, the first storage location identifier refers to the location identifier corresponding to the storage location where the data to be written is to be written. For example, the first storage location identifier can be the LBA address where the data to be written is to be written. This embodiment does not specifically limit this.
[0051] As an embodiment, K arrays are pre-configured based on actual needs, and any array includes multiple element positions; any used element position in the K arrays is used to record the number of data updates at the storage position corresponding to the storage position identifier that matches the used element position. Based on this, the first data heat level that determines the first storage position identifier matches in this step 201 can be implemented as follows: first determine whether the array currently in use meets the following conditions: the number of element positions that have been used is less than the set number, and / or the timing duration of the timer corresponding to the array currently in use does not reach the set timing duration. If so, find the element position that matches the first storage position identifier from the array currently in use, increase the value at the element position by the set value (that is, it can be considered to update the number of data updates recorded at the element position), and determine the first data heat level that matches the first storage position identifier based on the value at the element position that matches the first storage position identifier in each array; here, the set value can be 1. Otherwise, initialize the next array and use it as the array currently in use, and return to the step of determining whether the array currently in use meets the conditions.
[0052] In this embodiment, any array needs to be initialized before being used as the array currently in use to perform the step of determining whether the array currently in use meets the conditions. Here, the initialization may include: initializing the values of each element position in the array to the set element value (such as 0), initializing the used element position record corresponding to the array to 0, and starting the timer corresponding to the array, etc., which is not specifically limited in this embodiment.
[0053] As for how to find the element position that matches the first storage position identifier from the array currently being used, and how to determine the first data heat level that matches the first storage position identifier based on the numerical value at the element position that matches the first storage position identifier in each array, the following will give examples and will not be elaborated here.
[0054] Step 202: If there is no at least one storage segment matching the first data heat level in the currently used storage segments, based on the information of the free storage segments recorded in the shared pool, a free storage segment is selected as the first target storage segment matching the first data heat level, and the data is written to the first target storage segment; if there is a first target storage segment matching the first data heat level in the currently used storage segments and the free storage space is sufficient to accommodate the data, the data is written to the free storage space in the first target storage segment.
[0055] In this embodiment, the segment description information corresponding to any used storage segment at least includes the data heat level that matches the storage segment, that is, the data heat level that matches the storage location identifier of each data in any used storage segment is the same. Based on this, in this step 202, first check whether there is at least one storage segment that matches the first data heat level in the currently used storage segment; if not, then based on the information of the free storage segments recorded in the shared pool, select a free storage segment as the first target storage segment that matches the first data heat level, and write the data to the first target storage segment; if there is a first target storage segment that matches the first data heat level and has enough free storage space to accommodate the data in the currently used storage segment, then write the data to the free storage space in the first target storage segment.
[0056] As an embodiment, the above-mentioned selection of a free storage segment as the first target storage segment matching the first data heat level based on the information of the free storage segments recorded in the shared pool can be specifically implemented as follows: based on the information of the free storage segments recorded in the shared pool, a free storage segment is randomly selected from the shared pool as the first target storage segment matching the first data heat level, and the first data heat level matching the storage segment is added to the segment description information of the first target storage segment. Based on this, after selecting a free storage segment as the first target storage segment matching the first data heat level based on the information of the free storage segments recorded in the shared pool, the information of the first target storage segment is deleted from the recorded shared pool information.
[0057] So far, completed Figure 2 The process shown.
[0058] pass Figure 2 It can be seen from the shown process that this embodiment, when detecting a data write request sent by an external designated device, first determines the data heat level that matches the storage location identifier corresponding to the data to be written, and the data heat level indicates the data update frequency at the storage location corresponding to the data to be written. Then, according to the determined data heat level, the target storage segment to be written is determined for the data to write the data. In this way, part or all of the data in the same storage segment can be invalidated at approximately the same time to become garbage data, thereby effectively reducing the amount of valid data in the storage segment during subsequent garbage data recovery, thereby reducing write amplification.
[0059] The following describes how to determine the first data heat level that matches the first storage location identifier based on the value at the element position that matches the first storage location identifier in each array:
[0060] As an embodiment, the above-mentioned determination of the target data heat level matching the storage location identifier based on the numerical value at the element position matching the first storage location identifier in each array may be implemented in a variety of ways. For example, first find the element position matching the first storage location identifier from the configured K arrays; then, determine the first data heat level based on the weights corresponding to each array and the numerical value at the element position matching the first storage location identifier in each array.
[0061] In this embodiment, as an embodiment, each of the configured K arrays corresponds to a hash function; here, in order to avoid hash collision problems, the hash functions corresponding to each array are different. Based on this, the above-mentioned finding the element position matching the first storage position identifier from the configured K arrays can be specifically implemented as follows: for each array, the first storage position identifier is substituted into the hash function corresponding to the array to obtain a hash result; based on the hash result, the element position corresponding to the hash result is found in the array.
[0062] Optionally, the above-mentioned finding the element position corresponding to the hash result in the array based on the hash result may be specifically implemented as: taking the hash result as the element position subscript, and finding the element position corresponding to the hash result in the array.
[0063] Correspondingly, how to find the element position matching the first storage position identifier from the array currently being used in the above step 101 is similar to the specific implementation method of finding the element position matching the first storage position identifier from the configured K arrays mentioned above, and will not be repeated here.
[0064] As an embodiment, multiple data heat levels are preconfigured, and each data heat level corresponds to a heat value range. Based on this, there are many specific implementation methods for determining the first data heat level based on the weights corresponding to each array and the values at the element positions in each array that match the first storage location identifier. For example, first determine the heat value that matches the first storage location identifier based on the weights corresponding to each array and the values at the element positions in each array that match the first storage location identifier; based on the heat value range corresponding to each configured data heat level, determine the data heat level that matches the heat value from at least one configured data heat level as the first data heat level. Here, the heat value indicates the probability that the data to be written in the data request at the storage position corresponding to the first storage location identifier will be frequently updated in the future. The higher the heat value, the higher the probability that the corresponding data will be frequently updated in the future.
[0065] Optionally, the weight value corresponding to each array changes dynamically, and the weight value corresponding to each array depends on the array currently being used, the arrangement order of each array, and the pre-configured weight rule. As for how to determine the weight of each array used when determining the first data heat level using the weight of each array, an example will be described below, which will not be repeated here.
[0066] The following describes the garbage collection of used memory segments:
[0067] As an embodiment, when it is determined based on the recorded shared pool information that the number of free storage segments is less than a set threshold, at least one storage segment that needs to be garbage collected is determined from the currently used storage segments, and when the storage segment still stores valid data, valid data is migrated to other storage segments and garbage data stored in the storage segment is garbage collected, and then the storage segment is treated as a free storage segment and added to the shared pool, and the information of the storage segment is added to the recorded shared pool information. Here, the threshold can be set based on actual needs, such as 3, 4 or 5.
[0068] In this embodiment, there are many specific implementation methods for determining at least one storage segment that needs to be garbage collected from the currently used storage segments. For example, as an embodiment, the first P storage segments with the largest amount of garbage data are selected from the currently used storage segments as the storage segments that need to be garbage collected, and P is greater than or equal to 1.
[0069] As another embodiment, for each storage segment in the currently used storage segments, first determine the recycling reference value corresponding to the storage segment based on the data update frequency recorded in the segment description information of the storage segment and the valid data occupancy rate corresponding to the storage segment; wherein the data update frequency refers to the data update frequency at the storage location where the specified data is written, and the specified data is any data in the storage segment; then, select the first Q storage segments with the largest recycling reference values from the currently used storage segments as the storage segments that need to perform garbage data recycling, where Q is greater than or equal to 1.
[0070] Optionally, as an embodiment, the above-mentioned recovery reference value corresponding to the storage segment is determined based on the data update frequency recorded in the segment description information of the storage segment and the valid data occupancy rate corresponding to the storage segment. In specific implementation, for example, the recovery reference value corresponding to the storage segment can be calculated by the following formula: Recovery reference value = (1-U)*(1 / f), wherein U represents the valid data occupancy rate, U = the number of valid data in the storage segment / the number of all data in the storage segment; f represents the recorded data update frequency.
[0071] Optionally, for any array that has been used, the array description information of the array that has been used at least includes the timer timing duration when the array was most recently used. There are many specific ways to determine the above-mentioned recorded data update frequency, for example, first find the element position that matches the storage position identifier corresponding to the specified data in each configured array, and then determine the ratio between the sum of the values at the found element positions and the sum of the timer timing durations corresponding to each array as the recorded data update frequency.
[0072] As an embodiment, the above execution of valid data migration to other storage segments can be implemented in many ways. For example, for each valid data, first find the element position that matches the second position identifier from the configured K arrays based on the second position identifier corresponding to the storage location where the valid data is written; any array contains multiple element positions. Here, how to find the element position that matches the second position identifier from the configured K arrays is similar to how to find the element position that matches the first storage position identifier from the configured K arrays, and will not be repeated here.
[0073] Then, the second data heat level that matches the second storage location identifier is determined based on the weights corresponding to each array and the values at the element positions in each array that match the second storage location identifier; the second data heat level is used to indicate the data update frequency at the storage location corresponding to the second storage location identifier. Here, how to determine the second data heat level that matches the second storage location identifier is similar to how to determine the first data heat level based on the weights corresponding to each array and the values at the element positions in each array that match the first storage location identifier, and will not be repeated here.
[0074] Finally, if there is no at least one storage segment matching the second data heat level in the currently used storage segments, a free storage segment is selected as a second target storage segment matching the second data heat level based on the information of the free storage segments recorded in the shared pool, and the valid data is written to the second target storage segment; if there is a second target storage segment matching the second data heat level in the currently used storage segments and the free storage space can accommodate the valid data, the valid data is written to the free storage space in the second target storage segment.
[0075] In order to facilitate understanding of the specific implementation process of the above method, it is described below through a specific embodiment.
[0076] This embodiment provides a method for garbage data recovery in an all-flash memory system. The method mainly involves the following contents:
[0077] 1) Identify hot and cold data for write IO with less computation and memory overhead;
[0078] 2) Hot and cold data can be classified into multiple levels according to heat (used to put data with similar life cycles into the same segment);
[0079] 3) The discrimination of hot and cold data can capture both frequency and recency information;
[0080] 4) During garbage collection, the valid data in the recycled garbage segment is again identified as hot and cold data, and the corresponding data layout is made based on the identification results.
[0081] This embodiment optimizes data writing and garbage collection of the all-flash memory system, reduces system write amplification, increases the service life and writing performance of the SSD disk, and improves system stability.
[0082] The following is an example of describing the cold and hot data discrimination method of this embodiment:
[0083] See also Figure 3 As shown, the method comprises the following steps:
[0084] Step 301, after receiving the write IO from the user end, extract the LBA address carried in the write IO;
[0085] Step 302: Based on the LBA address of the write IO, the data heat level of the write IO is determined to obtain a determination result;
[0086] Step 302: Based on the determination result, the data to be written corresponding to the write IO is written into the Segment of the corresponding heat.
[0087] It should be noted that the all-flash system can configure the level of cold and hot data (which can be recorded as data heat level), such as simply configuring it into two levels of cold and hot; three levels of cold, warm, and hot; or any L levels, where L is a positive integer greater than or equal to 2. After the all-flash system is pre-configured with parameter L, for each Segment, the data stored on it must have the same data heat level. The data on each Segment is written sequentially. At any time, each Segment must be in one of the four states of "idle", "in use", "full of data", and "garbage collection in progress". Among them, the "idle" state means that there is no data in the Segment; "in use" means that the Segment is being used; "full of data" means that the storage space in the Segment has been filled, that is, there is no free storage space; "garbage collection in progress" means that the Segment is recycling garbage data.
[0088] The following describes the determination of data heat level (i.e. the above-mentioned determination of hot and cold data):
[0089] See also Figure 4 As shown, the system allocates K ordered arrays, namely C1, C2, C3, ..., C K Identify. Each array contains M (M is an integer power of 2) element positions, and each element position contains N bits (N can be taken as log2M) of space. The K and M values can be flexibly configured based on actual needs. Initially, the values at each element position of each array are initialized to 0. At the same time, a hash function is configured for each array, and the hash functions of different arrays are different.
[0090] In this embodiment, when a write IO arrives, it is first recorded in an array, then its heat value is calculated, and the data heat level matching the write IO is determined according to the pre-configured data heat level, so that the data to be written corresponding to the write IO is written to the Segment that matches the data heat level.
[0091] In general, the number of write IOs is recorded in K arrays according to the relative write time. Each array records no more than D (D < M) write IOs, and the D value is configurable. At the same time, the IO time interval (i.e., the timer timing duration) recorded by each array is required to not exceed T, and the T value is configurable. S After completing the recording, start using the next array C S+1 Record and proceed in sequence. K After completing the recording, use C1 to start recording in a loop, and so on. In order to achieve the attenuation effect and avoid cumulative overlap, it is necessary to ensure that when a new array count starts, the new array is reinitialized. In addition, the K hash functions selected by the system satisfy the value range of Hash (LBA) that falls exactly within the range of 0-(M-1). It should be noted that the two parameters P and T are set here mainly to ensure that different load conditions can be adaptive. Under intensive IO load, the writing of an array does not need to wait until the timer T times out, and reaches the threshold P first, so as to start counting with the next array; while for light IO load, an array may not reach the threshold P, but reach the timer timeout first, so as to start counting with the next array. This ensures the adaptive effect of multi-level classification of data heat under different loads.
[0092] The following is an example description of the data writing process:
[0093] Step 1, array initialization:
[0094] 1.1, Initialize the current record array C S is 0;
[0095] 1.2, start the timer (period is T);
[0096] 1.3, Initialize the single-array LBA address counter D = 0 (D represents the number of used element positions in the array).
[0097] Step 2, For the write IO with LBA address LBA X;
[0098] 2.1, D = D + 1;
[0099] 2.2, Determine whether the update count corresponding to this LBA X can be recorded in the current C S If not, enter the next array C S+1 and perform the above array initialization process on C S+1 ; Otherwise, execute 2.3;
[0100] 2.3, Calculate Hash(X) through the hash function specified by the current array. Assume its value is V, then increment the element value at the element position of position V in C S by 1;
[0101] 2.4, Calculate the heat value of the current IO, and determine the matching data heat level based on the heat value of this IO, so as to write the data to be written into the segment matching this data heat level;
[0102] Step 3, Wait for a new write IO and transfer to the above Step 2.
[0103] In this embodiment, the method for determining whether the update count corresponding to an LBA can be recorded in the current C S is as follows:
[0104] If the following two conditions are met simultaneously, it is determined to be recordable; otherwise, it is determined to be non-recordable:
[0105] Condition 1: D < M (the number of LBAs recorded in a single array does not exceed D to control the number of hash conflicts);
[0106] Condition 2: The timer T does not time out.
[0107] The following describes the calculation of the heat value corresponding to the IO:
[0108] C1, C2, C3,..., C K record the number of LBAs of each write IO in the recent period. The following explains how to calculate the heat value corresponding to a write IO. In this embodiment, when calculating the heat value, both the number of times it appears and its recency need to be considered. Since the array records both frequency and recency information, the final heat value only needs to take the weighted sum of the frequency values of each array.
[0109] The weight value is set for each array. The currently used array has the highest weight. The closer the array is to the currently used array, the higher the corresponding weight of the array. Figure 5 As shown in the figure, assuming that the array currently being used is C3, then C3 has the highest weight, and the weights are Figure 5 The weight of each array changes dynamically as the current array changes. There are multiple ways to select the weight that decreases from the current array. For example, define the current array weight as 2. K , the next array is defined as 2 K-1 , and so on, the minimum weight array weight is defined as 2. For another example, the current array weight is defined as 1, the minimum weight array weight is defined as 0.1, and the intermediate arrays are decreased according to a fixed step size (in this example, the step size is 0.9 / (K-1)), etc., which is not specifically limited in this embodiment.
[0110] For example, assume that at a certain moment, the current record array (i.e., the array currently being used) is C S , then the frequency value of LBA X is C S The array subscript is Hash S The values of the element positions corresponding to LBA X in other arrays are similar and will not be described here. The frequency values of LBA X in each array are F1, F2, ..., F K , the corresponding array weights are W1, W2, ..., W K , then the heat value corresponding to this LBAX is
[0111] It should be noted that the above frequency values and array weight values are dynamically changing.
[0112] The following describes the classification of data heat levels:
[0113] After calculating the IO heat, the IO data needs to be written to the corresponding Segment. As described above, assuming that the system setting divides the data heat level into L levels, let's remember these levels as H1, H2, ..., H L The higher the level, the higher the popularity. Each level can be set with a corresponding threshold, and the thresholds of adjacent levels change continuously but have no intersection. For example, the H1 level range can be set to [0, V1], and the H L The level threshold is set to [V L , +∞), for the intermediate level, evenly divided (V L -V1). LThe values of V1 and V2 can be set based on actual needs. Of course, other methods can also be used, such as dividing the levels according to the distribution of heat values, which will not be described in detail here.
[0114] The following is a description of the garbage collection method:
[0115] See also Figure 6 As shown, the method comprises the following steps:
[0116] Step 601, when it is detected that the number of current free storage segments is less than a set threshold, garbage collection is started;
[0117] Step 602, selecting at least one segment that needs to be garbage collected based on the garbage collection segment selection strategy;
[0118] Step 603: for each Segment, determine the data heat level of the valid data contained in the Segment to obtain a determination result;
[0119] Step 604: Based on the determination result, migrate the valid data to a Segment that matches the data heat level corresponding to the valid data.
[0120] The following describes the data layout method for valid data during garbage collection:
[0121] As described above, the IO data written into the system is written into different segments according to its estimated heat (that is, predicted life cycle). From a probabilistic point of view, it is reasonable to expect that most of the data, or even all of the data in the same segment, will become garbage data at a similar time, and thus be garbage collected by the system at a certain moment. However, from a probabilistic point of view, there must be some segments where the actual life cycle of some data does not match the system's prediction. When the system performs garbage collection on this segment, some data may still be valid data. At this time, it is necessary to copy this data from the segment and write it to the idle segment. At this time, the valid data to be copied can be regarded as ordinary write IO, and the aforementioned IO heat calculation and data layout method can be used to classify these valid data and write them into the segment. The specific effective data migration process can be found in the above description, which will not be repeated here.
[0122] The following describes the garbage collection strategy selection:
[0123] The garbage collection selection strategy is the system's selection of which segments to perform garbage collection. This embodiment provides two strategies, namely the greedy algorithm and the benefit-cost algorithm.
[0124] The greedy algorithm traverses all segments in the system and then selects P segments (the P value can be pre-set in the system) with the largest amount of garbage data for recycling.
[0125] The benefit-cost algorithm comprehensively considers the amount of garbage in the Segment and the life cycle of the Segment. In this embodiment, because the data contained in each Segment has a similar life cycle, its value is assumed to be T' (the T' value can be recorded as the metadata of the Segment when the data is written, that is, T' is the above 1 / f); at the same time, it is assumed that the effective data occupancy rate of the Segment is U (0≤U≤1, a dynamically changing value). The benefit cost number of each Segment is defined as (1-U)*T'. At this point, the benefit cost values of all Segments can be calculated, and Q (Q value can be pre-set in the system) Segments with the largest values are selected for garbage collection. This is done to take into account that hot data segments will become garbage data in a shorter time. Compared with cold data segments, recycling cold data segments at the same U value will bring greater benefits (lower write amplification values).
[0126] As an embodiment, due to the use of a hash function method for LBA addresses, hash conflicts may occur. The final result of the hash conflict may lead to a misjudgment of the heat of a certain write IO; however, a small number of misjudgments is not a big problem, because the heat value is originally a predicted value, which itself has a probabilistic attribute. This embodiment provides a method for reducing hash conflicts as follows:
[0127] Control the upper limit of the number of element positions used in each array, that is, the D value. For example, D = M / 2 can be set to exchange space for conflict probability; and / or,
[0128] Set different hash functions for different arrays to avoid the accumulation of conflict effects. That is, even if the hash values of two different IOs conflict in one array, the probability that these two IOs conflict in other arrays is very small.
[0129] At this point, the description of the method provided in the embodiment of the present application is completed. The following is a description of the device provided in the embodiment of the present application:
[0130] As an embodiment, this embodiment also provides a data writing device. Figure 7 , Figure 7 This is a schematic diagram of the device structure provided in the embodiment of the present application. Figure 7As shown, the apparatus 700 is configured in a storage device; the storage device provides X flash disks as memory of an external designated device connected to the storage device, X is greater than 1; each flash disk includes Y storage blocks, Y is greater than 1; each storage block of the X flash disks is grouped into Z storage segments, Z is greater than 1; in an initial state, the storage device is configured with a shared pool that records information of Z storage segments; the apparatus 700 includes:
[0131] Determine module 701, for, when a data write request sent by an external designated device is detected, the data write request at least indicates the data to be written and the first storage location identifier corresponding to the storage location to which the data is to be written; determine a first data heat level matched by the first storage location identifier; the first data heat level is used to indicate the data update frequency at the storage location corresponding to the first storage location identifier;
[0132] The write module 702 is used to select a free storage segment as a first target storage segment matching the first data heat level based on the information of the free storage segments recorded in the shared pool if there is no at least one storage segment matching the first data heat level in the currently used storage segments, and write the data to the first target storage segment; if there is a first target storage segment matching the first data heat level in the currently used storage segments and the free storage space is sufficient to accommodate the data, the data is written to the free storage space in the first target storage segment.
[0133] As an embodiment, the storage device is pre-configured with K arrays, each array comprising a plurality of element positions; each used element position in each array is used to record the number of data updates at the storage position corresponding to the storage position identifier matching the used element position;
[0134] The determination module 701 is specifically used for:
[0135] Determine whether the array currently in use meets the following conditions: the number of element positions that have been used is less than the set number, and / or the timing duration of the timer corresponding to the array currently in use has not reached the set timing duration;
[0136] If yes, find the element position that matches the first storage position identifier from the array currently being used, increase the value at the element position by the set value, and determine the first data heat level that matches the first storage position identifier based on the value at the element position that matches the first storage position identifier in each array;
[0137] Otherwise, initialize the next array and use it as the array currently in use, and return to the step of determining whether the array currently in use meets the conditions.
[0138] As an embodiment, determining the target data heat level matching the storage location identifier according to the value at the element position matching the first storage location identifier in each array includes:
[0139] Find the element position that matches the first storage position identifier from the configured K arrays; determine the first data heat level according to the weight corresponding to each array and the value at the element position that matches the first storage position identifier in each array.
[0140] As an embodiment, each of the K arrays corresponds to a hash function;
[0141] Finding the element position matching the first storage location identifier from the configured K arrays includes:
[0142] For each array, the first storage location identifier is substituted into the hash function corresponding to the array to obtain a hash result; based on the hash result, the element position corresponding to the hash result is found in the array.
[0143] As an embodiment, based on the information of the free storage segments recorded in the shared pool, selecting a free storage segment as the first target storage segment matching the first data heat level further includes: deleting the information of the first target storage segment from the recorded shared pool information;
[0144] The device further comprises:
[0145] The recycling module is used to determine at least one storage segment that needs to be garbage collected from the currently used storage segments when it is determined that the number of free storage segments is less than a set threshold based on the recorded shared pool information, migrate valid data to other storage segments when the storage segment still stores valid data and perform garbage collection on the garbage data stored in the storage segment, then treat the storage segment as a free storage segment and add it to the shared pool, and add the information of the storage segment to the recorded shared pool information.
[0146] As an embodiment, determining at least one storage segment that needs to be garbage collected from the currently used storage segments includes:
[0147] Select the first P storage segments with the largest amount of garbage data from the currently used storage segments as the storage segments that need to be garbage collected, where P is greater than or equal to 1; or
[0148] For each storage segment in the currently used storage segments, determine the recycling reference value corresponding to the storage segment according to the data update frequency recorded in the segment description information of the storage segment and the valid data occupancy rate corresponding to the storage segment; the data update frequency refers to the data update frequency at the storage location where the specified data is written, and the specified data is any data in the storage segment; and select the first Q storage segments with the largest recycling reference values from the currently used storage segments as the storage segments that need to perform garbage data recycling, where Q is greater than or equal to 1.
[0149] As an embodiment, performing migration of valid data to other storage segments includes:
[0150] For each valid data, based on the second position identifier corresponding to the storage location where the valid data is written, find the element position matching the second position identifier from the configured K arrays; any array contains multiple element positions; according to the weights corresponding to each array and the values at the element positions matching the second storage position identifier in each array, determine the second data heat level matching the second storage position identifier; the second data heat level is used to indicate the data update frequency at the storage location corresponding to the second storage position identifier;
[0151] If there is no at least one storage segment matching the second data heat level in the currently used storage segments, then based on the information of the free storage segments recorded in the shared pool, a free storage segment is selected as the second target storage segment matching the second data heat level, and the valid data is written to the second target storage segment; if there is a second target storage segment matching the second data heat level in the currently used storage segments and the free storage space can accommodate the valid data, the valid data is written to the free storage space in the second target storage segment.
[0152] So far, completed Figure 7 Structural description of the device shown.
[0153] The implementation process of the functions and effects of each unit in the above-mentioned device is specifically described in the implementation process of the corresponding steps in the above-mentioned method, and will not be repeated here.
[0154] For the device embodiment, since it basically corresponds to the method embodiment, the relevant parts can refer to the partial description of the method embodiment. The device embodiment described above is only schematic, wherein the modules described as separate components may or may not be physically separated, and the components displayed as modules may or may not be physical modules, that is, they may be located in one place, or they may be distributed on multiple network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the present application scheme. A person of ordinary skill in the art can understand and implement it without paying creative labor.
[0155] See also Figure 8 , is a schematic diagram of the hardware structure of an electronic device provided by an exemplary embodiment of the present application. The electronic device may include a processor 801, a communication interface 802, a memory 803 and a communication bus 804. The processor 801, the communication interface 802 and the memory 803 communicate with each other through the communication bus 804. Among them, the memory 803 stores computer program instructions; the processor 801 can execute the steps of the method described in the above embodiment by executing the computer program instructions stored in the memory 803. The electronic device may also include other hardware according to the actual function of the electronic device, which will not be described in detail.
[0156] Correspondingly, an embodiment of the present application further provides a computer-readable storage medium, on which a number of computer program instructions are stored. When the computer program instructions are executed by a processor, the method disclosed in the above example of the present application can be implemented.
[0157] Exemplarily, the computer-readable storage medium may be any electronic, magnetic, optical or other physical storage device that may contain or store information, such as executable instructions, data, etc. For example, the computer-readable storage medium may be: RAM (Radom Access Memory), volatile memory, non-volatile memory, flash memory, storage drive (such as hard disk drive), solid state drive, any type of storage disk (such as optical disk, DVD, etc.), or similar storage medium, or a combination thereof. The processor and memory may be supplemented by or incorporated into a dedicated logic circuit.
[0158] The above are only preferred embodiments of the present application and are not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application should be included in the scope of protection of the present application.
Claims
1. A data writing method, characterized in that: The method is applied to a storage device; the storage device provides X flash disks as memory of an external designated device connected to the storage device, X is greater than 1; each flash disk includes Y storage blocks, Y is greater than 1; each storage block of the X flash disks is grouped into Z storage segments, Z is greater than 1; in an initialization state, the storage device is configured with a shared pool that records information of the Z storage segments; the method includes: When a data write request sent by the external designated device is detected, the data write request at least indicates the data to be written and a first storage location identifier corresponding to the storage location to which the data is to be written; a first data heat level matched by the first storage location identifier is determined; the first data heat level is used to indicate a data update frequency at the storage location corresponding to the first storage location identifier; If there is no at least one storage segment matching the first data heat level in the currently used storage segments, based on the information of the free storage segments recorded in the shared pool, a free storage segment is selected as the first target storage segment matching the first data heat level, and the data is written to the first target storage segment; if there is a first target storage segment matching the first data heat level in the currently used storage segments and the free storage space is sufficient to accommodate the data, the data is written to the free storage space in the first target storage segment.
2. The method according to claim 1, characterized in that: The storage device is pre-configured with K arrays, each array comprising a plurality of element positions; each used element position in each array is used to record the number of data updates at the storage position corresponding to the storage position identifier matching the used element position; Determining the first data heat level that matches the first storage location identifier includes: Determine whether the array currently in use meets the following conditions: the number of element positions that have been used is less than a set number, and / or the timing duration of the timer corresponding to the array currently in use does not reach the set timing duration; If yes, find the element position that matches the first storage position identifier from the array currently being used, increase the value at the element position by a set value, and determine the first data heat level that matches the first storage position identifier based on the value at the element position that matches the first storage position identifier in each array; Otherwise, the next array is initialized and used as the array currently in use, and the process returns to the step of determining whether the array currently in use satisfies the condition.
3. The method according to claim 2, characterized in that The step of determining the target data heat level matching the storage location identifier according to the value at the element position matching the first storage location identifier in each array includes: Find the element position that matches the first storage location identifier from the configured K arrays; determine the first data heat level based on the weight corresponding to each array and the value at the element position in each array that matches the first storage location identifier.
4. The method according to claim 3, characterized in that Each of the K arrays corresponds to a hash function; The step of finding the element position matching the first storage position identifier from the configured K arrays includes: For each array, the first storage location identifier is substituted into the hash function corresponding to the array to obtain a hash result; based on the hash result, an element position corresponding to the hash result is found in the array.
5. The method according to claim 1, characterized in that The selecting a free storage segment as a first target storage segment matching the first data heat level based on the information of the free storage segments recorded in the shared pool further comprises: deleting the information of the first target storage segment from the recorded shared pool information; The method further comprises: When it is determined based on the recorded shared pool information that the number of free storage segments is less than a set threshold, at least one storage segment that needs to be garbage collected is determined from the currently used storage segments, and when the storage segment still stores valid data, valid data is migrated to other storage segments and garbage collection is performed on the garbage data stored in the storage segment. Thereafter, the storage segment is treated as a free storage segment and added to the shared pool, and the information of the storage segment is added to the recorded shared pool information.
6. The method according to claim 5, characterized in that The step of determining at least one storage segment that needs to be garbage collected from the currently used storage segments includes: Select the first P storage segments with the largest amount of garbage data from the currently used storage segments as the storage segments that need to be garbage collected, where P is greater than or equal to 1; or For each storage segment in the currently used storage segments, determine the recycling reference value corresponding to the storage segment according to the data update frequency recorded in the segment description information of the storage segment and the valid data occupancy rate corresponding to the storage segment; the data update frequency refers to the data update frequency at the storage location where the specified data is written, and the specified data is any data in the storage segment; and select the first Q storage segments with the largest recycling reference values from the currently used storage segments as the storage segments that need to perform garbage data recycling, Q is greater than or equal to 1.
7. The method according to claim 5, characterized in that Performing effective data migration to other storage segments includes: For each valid data, based on the second position identifier corresponding to the storage location where the valid data is written, find the element position matching the second position identifier from the configured K arrays; any array contains multiple element positions; according to the weights corresponding to each array and the values at the element positions matching the second storage position identifier in each array, determine the second data heat level matching the second storage position identifier; the second data heat level is used to indicate the data update frequency at the storage location corresponding to the second storage position identifier; If there is no at least one storage segment matching the second data heat level in the currently used storage segments, based on the information of the free storage segments recorded in the shared pool, a free storage segment is selected as the second target storage segment matching the second data heat level, and the valid data is written to the second target storage segment; if there is a second target storage segment matching the second data heat level in the currently used storage segments and the free storage space can accommodate the valid data, the valid data is written to the free storage space in the second target storage segment.
8. A data writing device, characterized in that: The device is configured on a storage device; the storage device provides X flash disks as memory of an external designated device connected to the storage device, X is greater than 1; each flash disk includes Y storage blocks, Y is greater than 1; each storage block of the X flash disks is grouped into Z storage segments, Z is greater than 1; in an initialization state, the storage device is configured with a shared pool that records information of the Z storage segments; the device includes: A determination module, for, when detecting a data write request sent by the external designated device, the data write request at least indicates the data to be written and a first storage location identifier corresponding to the storage location to which the data is to be written; determining a first data heat level matched by the first storage location identifier; the first data heat level is used to indicate a data update frequency at the storage location corresponding to the first storage location identifier; A writing module is used to select a free storage segment as a first target storage segment matching the first data heat level based on the information of the free storage segments recorded in the shared pool if there is no at least one storage segment matching the first data heat level in the currently used storage segments, and write the data to the first target storage segment; if there is a first target storage segment matching the first data heat level and the free storage space is sufficient to accommodate the data in the currently used storage segments, then the data is written to the free storage space in the first target storage segment.
9. An electronic device, characterized in that: The electronic device includes: Processor; and A memory, wherein computer program instructions are stored in the memory, and when the computer program instructions are executed by the processor, the processor is caused to perform the steps in any one of the methods of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer program instructions, which, when executed by a processor, enable the processor to perform the steps of any one of the methods of claims 1 to 7.
Citation Information
Patent Citations
Wiping and writing management method and system for non-volatile flash memory
CN104156317A
Method and device for reducing LSM Tree writing amplification
CN104915145A
Data storage method and device, computer equipment and storage medium
CN112181303A
Method for writing data into solid state disk, garbage collection method and device
CN113010091A
Formatting method and device of disk array, equipment and medium
CN116339643A
Cited By
Data storage method, device and equipment, readable storage medium and program product
CN119415039A
