A data writing method, device, apparatus and storage medium
By differentiating between hot and cold data in the solid-state drive and performing wear leveling based on operation records, the lifespan and performance issues caused by frequent garbage collection in SSDs are resolved, resulting in improved performance and extended lifespan.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- SICHUAN YUNHAI XINKE MICROELECTRONICS TECH CO LTD
- Filing Date
- 2026-04-14
- Publication Date
- 2026-05-29
AI Technical Summary
In existing technologies, solid-state drives (SSDs) suffer from frequent garbage collection and increased write amplification due to the fact that NAND flash memory does not support overwrite, which affects lifespan and performance.
By distinguishing between cold and hot data, cold data is stored in older physical blocks and hot data is stored in younger physical blocks. FMD metadata records the operation type and number of operations for partitioning and writing, thus achieving wear leveling.
It improves the performance and lifespan of solid-state drives, reduces the frequent migration of cold data, and enhances the effectiveness of garbage collection.
Smart Images

Figure CN122111345A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of data writing, and in particular to a data writing method, apparatus, device, and storage medium. Background Technology
[0002] Because NAND flash memory in SSDs (Solid State Disks or Solid State Drives) does not support overwrite operations, but only erases before writing, overwrite operations on the host machine will write to new physical pages in the NAND. The old data becomes garbage data on that physical block, leading to insufficient user space on the SSD. Therefore, a garbage collection (GC) process is needed to move the valid data from the physical block and then erase the physical block to obtain a new physical block that can be written to. Moving valid data to the new physical block can lead to further garbage collection if hot data is quickly overwritten. This frequent migration of truly cold data increases write amplification, significantly impacting the lifespan and performance of the SSD. Therefore, distinguishing between hot and cold data and storing them separately—with cold data on older physical blocks and hot data on younger physical blocks—to maintain wear level is crucial.
[0003] Currently, existing technologies move all data to a single physical block during garbage collection. However, some or all of the moved data may be hot data, which is easily overwritten and becomes garbage again. This results in frequent migration of garbage collection data, which has a significant impact on the lifespan and performance of SSDs.
[0004] In conclusion, improving SSD performance and extending SSD lifespan are pressing issues that need to be addressed. Summary of the Invention
[0005] In view of this, the purpose of this invention is to provide a data writing method, apparatus, device, and storage medium that can improve SSD performance and extend SSD lifespan. The specific solution is as follows: Firstly, this application provides a data writing method, including: Determine the current operation record corresponding to the data to be written, and update the FMD metadata of the data to be written using the current operation record to obtain the target data to be written; wherein, the current operation record includes the current operation type and the current operation count; The hard disk free physical blocks are divided according to the number of erases of the physical blocks to obtain the divided hard disk free physical blocks. Then, the hard disk working physical blocks corresponding to each divided hard disk free physical block are determined based on the number of erases of each divided hard disk free physical block. Determine the current operation type corresponding to the target data to be written, and determine whether the current operation count corresponding to the current operation type is greater than a preset filtering coefficient; Based on the target determination result, the target data to be written is written into the corresponding working physical block of the hard disk in the partitioned free physical block of the hard disk.
[0006] Optionally, determining the current operation record corresponding to the data to be written, and updating the FMD metadata of the data to be written using the current operation record to obtain the target data to be written, includes: If the current operation type of the data to be written is an IO data type, then determine whether the data to be written meets the preset new data conditions; If it is determined that the data to be written meets the preset new data conditions, then the first preset number of operations is determined as the current number of operations on the data to be written, and then the FMD metadata of the data to be written is updated according to the current operation type and the current number of operations to obtain the target data to be written.
[0007] Optionally, the process of determining the current operation record corresponding to the data to be written, and updating the FMD metadata of the data to be written using the current operation record to obtain the target data to be written, further includes: If it is determined that the data to be written does not meet the preset new data conditions, and the historical operation type in the historical operation record corresponding to the data to be written is a garbage collection data type, then the current operation type of the data to be written is determined to be the IO data type, and the first preset operation number is determined to be the current operation number of the data to be written. Then, the FMD metadata of the data to be written is updated based on the current operation type and the current operation number to obtain the target data to be written. If it is determined that the data to be written does not meet the preset new data conditions, and the historical operation type of the historical operation record corresponding to the data to be written is an IO data type, then the current operation count of the data to be written is increased by a first preset number to obtain a new current operation count of the data to be written, and then the FMD metadata of the data to be written is updated based on the new current operation count to obtain the target data to be written.
[0008] Optionally, determining the current operation record corresponding to the data to be written, and updating the FMD metadata of the data to be written using the current operation record to obtain the target data to be written, includes: If the current operation type of the data to be written is a garbage collection data type, and the historical operation type of the historical operation record of the data to be written is an IO data type, then the current operation type of the data to be written is determined to be the garbage collection data type, the second preset operation number is determined to be the current operation number of the data to be written, and then the FMD metadata of the data to be written is updated based on the current operation type and the current operation number to obtain the target data to be written. If the current operation type of the data to be written is a garbage collection data type, and the historical operation type of the historical operation record of the data to be written is a garbage collection data type, then the historical operation count of the historical operation record of the data to be written is increased by a second preset number to obtain the current operation count, and then the FMD metadata of the data to be written is updated based on the current operation count to obtain the target data to be written.
[0009] Optionally, the step of dividing the hard disk free physical blocks according to the number of erases of physical blocks to obtain the divided hard disk free physical blocks includes: The hard disk free physical blocks whose number of erasures is less than the first preset threshold value are determined as the first partitioned hard disk free physical blocks; The hard disk free physical blocks whose number of erases is greater than or equal to the first preset quantile value and less than the median of the number of erases are determined as the second partitioned hard disk free physical blocks; The hard disk free physical blocks whose erase count is greater than or equal to the median of the erase count and less than the second preset quantile value are determined as the hard disk free physical blocks after the third partition; The hard disk free physical blocks whose number of erases is greater than or equal to the second preset grading line value are determined as the hard disk free physical blocks after the fourth partition.
[0010] Optionally, determining the working physical block of the hard disk corresponding to each of the partitioned free physical blocks based on the number of erases of each partitioned free physical block includes: Determine whether there are any physical blocks in the free physical blocks of the hard disk after each partition that meet the preset minimum number of erase counts condition; If it exists, then the physical block that meets the preset minimum number of erases condition from the partitioned free physical blocks of the hard disk is determined as the working physical block of the hard disk.
[0011] Optionally, the step of writing the target data to be written into the corresponding working physical block of the hard disk in the partitioned free physical block of the hard disk according to the target determination result includes: If the target determination result indicates that the current operation type corresponding to the target data to be written is an IO data type, and the corresponding current operation count is greater than or equal to the first preset screening coefficient, then the target data to be written is determined to meet the preset hot data condition, and then the target data to be written that meets the preset hot data condition is written to the hard disk working physical block corresponding to the first partitioned hard disk free physical block. If the target determination result indicates that the current operation type corresponding to the target data to be written is an IO data type, and the corresponding current operation count is less than the first preset screening coefficient, then the target data to be written is determined to meet the preset micro-hot data condition, and then the target data to be written that meets the preset micro-hot data condition is written into the hard disk working physical block corresponding to the second partitioned hard disk free physical block; If the target determination result indicates that the current operation type corresponding to the target data to be written is a garbage collection data type, and the corresponding current operation count is less than the second preset screening coefficient, then the target data to be written is determined to meet the preset micro-cold data condition, and then the target data to be written that meets the preset micro-cold data condition is written to the hard disk working physical block corresponding to the third partitioned hard disk free physical block. If the target determination result indicates that the current operation type corresponding to the target data to be written is a garbage collection data type, and the corresponding current operation count is greater than or equal to the second preset screening coefficient, then the target data to be written is determined to meet the preset cold data condition, and then the target data to be written that meets the preset cold data condition is written to the hard disk working physical block corresponding to the fourth partitioned hard disk free physical block.
[0012] Secondly, this application provides a data writing device, comprising: The target data to be written acquisition module is used to determine the current operation record corresponding to the data to be written, and update the FMD metadata of the data to be written using the current operation record to obtain the target data to be written; wherein, the current operation record includes the current operation type and the current operation count; The hard disk working physical block determination module is used to divide the hard disk free physical blocks according to the number of erases of the physical blocks to obtain the divided hard disk free physical blocks, and then determine the hard disk working physical block corresponding to each of the divided hard disk free physical blocks based on the number of erases of each of the divided hard disk free physical blocks. The current operation count determination module is used to determine the current operation type corresponding to the target data to be written, and to determine whether the current operation count corresponding to the current operation type is greater than a preset filtering coefficient; The target data to be written module is used to write the target data to be written into the corresponding working physical block of the hard disk in the partitioned free physical block of the hard disk according to the target determination result obtained by the judgment.
[0013] Thirdly, this application provides an electronic device, comprising: Memory, used to store computer programs; A processor is used to execute the computer program to implement the data writing method as described above.
[0014] Fourthly, this application provides a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, it implements the data writing method described above.
[0015] In summary, this application first determines the current operation record corresponding to the data to be written, and uses the current operation record to update the FMD (Flash Meta Data) metadata of the data to be written to obtain the target data to be written. The current operation record includes the current operation type and the current number of operations. The free physical blocks of the hard disk are divided according to the number of erases of the physical blocks to obtain the divided free physical blocks. Then, based on the number of erases of each divided free physical block, the corresponding working physical block of the hard disk is determined. The current operation type corresponding to the target data to be written is determined, and it is determined whether the current number of operations corresponding to the current operation type is greater than a preset filtering coefficient. Based on the obtained target determination result, the target data to be written is written to the corresponding working physical block of the divided free physical blocks. As can be seen, after the current operation record corresponding to the data to be written is determined, this current operation record is written to the FMD metadata of the data to be written, thereby obtaining the target data to be written. Then, the free physical blocks of the hard disk are divided according to the number of erases of the physical blocks, and the resulting division is the divided free physical blocks of the hard disk. Then, based on the erase counts of each of the partitioned free physical blocks, the corresponding working physical block of each partitioned free physical block is further determined. Next, the current operation type corresponding to the target data to be written is determined, and it is judged whether the current operation count under this current operation type is greater than a preset filtering coefficient, thus obtaining a target determination result. Finally, according to this target determination result, the target data to be written is written to the corresponding working physical block of the partitioned free physical block, thereby completing the data writing operation. In this way, by linearly weighting the data record operation type and corresponding operation count for each data point, the degree of hot / cold data is identified through weights, and during host I / O writes and garbage collection data migration, data is written to physical blocks of different ages according to its hot / coldness, improving the effectiveness of garbage collection, promoting wear leveling, improving SSD performance, and extending SSD lifespan. Attached Figure Description
[0016] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.
[0017] Figure 1 This is a flowchart of a data writing method disclosed in this invention; Figure 2 This is a schematic diagram of a specific IO data sector format disclosed in this invention; Figure 3 This is a specific FMD storage diagram disclosed in this invention; Figure 4 This is a schematic diagram illustrating a specific method for filtering and separating hot and cold data disclosed in this invention; Figure 5 This is a schematic diagram of a data writing device disclosed in this invention; Figure 6 This is a structural diagram of an electronic device disclosed in this invention. Detailed Implementation
[0018] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0019] Currently, because the NAND flash memory in SSDs (Solid State Disks or Solid State Drives) does not support overwrite operations, but only erases before writing, overwrite operations on the host machine will write to new physical pages in the NAND. The old data becomes garbage data on that physical block, leading to insufficient user space on the SSD. Therefore, a garbage collection (GC) process is needed to move the valid data from the physical block and then erase the physical block to obtain a new physical block that can be written to. Moving valid data to the new physical block can lead to further garbage collection if hot data is quickly overwritten. This frequent migration of truly cold data increases write amplification, significantly impacting the lifespan and performance of the SSD. Therefore, distinguishing between hot and cold data and storing them separately—with cold data on older physical blocks and hot data on younger physical blocks—to maintain wear level is crucial. Existing technologies move all data to a single physical block during garbage collection. However, some or all of this moved data may be frequently accessed (hot) data, making it susceptible to overwriting and reverting to garbage. This leads to frequent migration of garbage collection data, significantly impacting SSD lifespan and performance. To address these issues, this application discloses a data writing method, apparatus, device, and storage medium that can improve SSD performance and extend its lifespan.
[0020] See Figure 1 As shown, an embodiment of the present invention discloses a data writing method, which may include: Step S11: Determine the current operation record corresponding to the data to be written, and update the FMD metadata of the data to be written using the current operation record to obtain the target data to be written; wherein, the current operation record includes the current operation type and the current operation count.
[0021] In this embodiment, the first step is to obtain the data to be written to the SSD. Different SSDs have different sector formats, i.e., the format for writing to NAND FLASH. For example, each IO data has a sector format like... Figure 2 The diagram shows 4K of raw data, a total of 80 bytes of reserved bytes, and metadata bytes. FMD stands for Flash Meta Data, which is stored in the FMD of the IO data before it is written to the NAND flash. Figure 3 The first four bytes shown record the operation. The data content can include the first byte as the operation type. For example, 0 represents the IO operation type and 1 represents the GC operation type. The other three bytes record the number of operations.
[0022] In one specific implementation, if the current operation type of the data to be written is an IO data type, it is determined whether the data to be written meets the preset new data conditions. If it is determined that the data to be written meets the preset new data conditions, the first preset operation count is determined as the current operation count of the data to be written. Then, the FMD metadata of the data to be written is updated according to the current operation type and the current operation count to obtain the target data to be written. Specifically, since this operation is host IO data being written to the SSD, the operation type is an IO data type, and the first byte of the FMD can be set to 0. Since there are no previous historical operation records, this is the first time the IO data is written to the SSD, so the current operation count is set to 1. Finally, this operation record can be represented as IO:1. After writing IO:1 to the FMD of the data to be written, the target data to be written is obtained.
[0023] Additionally, if the current operation type of the data to be written is an IO data type, and it is determined that the data to be written does not meet the preset new data conditions, and the historical operation type in the historical operation record corresponding to the data to be written is a garbage collection data type, then the current operation type of the data to be written is determined to be an IO data type, and the first preset operation count is determined to be the current operation count of the data to be written. Then, the FMD metadata of the data to be written is updated based on the current operation type and the current operation count to obtain the target data to be written. If it is determined that the data to be written does not meet the preset new data conditions, and the historical operation type of the historical operation record corresponding to the data to be written is an IO data type, then the current operation count of the data to be written is increased by the first preset count to obtain the new current operation count of the data to be written. Then, the FMD metadata of the data to be written is updated based on the new current operation count to obtain the target data to be written. Specifically, if this operation involves writing IO data sent by the host to the SSD, the operation type of the data to be written is IO data type. Since there are historical operation records in the FMD metadata of the data to be written, the historical operation records in the FMD of the data to be written are read first. If the historical operation record in the FMD of the data to be written is IO:X, a weighted operation is performed, and a first preset operation count is added to the historical operation count. That is, IO:X+1 is written to the FMD of the data to be written and then written to disk. If the historical operation record in the FMD of the data to be written is GC:X, the first preset operation count is determined as the current operation count, and the current operation type is determined as IO data type. That is, IO:1 is written to the FMD of the data to be written to obtain the target data to be written.
[0024] In another specific implementation, if the current operation type of the data to be written is a garbage-collected data type, and the historical operation type of the historical operation record of the data to be written is an IO data type, then the current operation type of the data to be written is determined to be a garbage-collected data type, the second preset number of operations is determined to be the current number of operations of the data to be written, and then the FMD metadata of the data to be written is updated based on the current operation type and the current number of operations to obtain the target data to be written; if the current operation type of the data to be written is a garbage-collected data type, and the historical operation type of the historical operation record of the data to be written is a garbage-collected data type, then the historical operation number of the historical operation record of the data to be written is increased by the second preset number to obtain the current number of operations, and then the FMD metadata of the data to be written is updated based on the current number of operations to obtain the target data to be written. Specifically, when garbage collection (GC) moves data, it first obtains the File Deposit Count (FMD) of the data to be written. If the historical operation record in the FMD of the data to be written is IO:X, the second preset number of operations is determined as the current number of operations on the data to be written, and the current operation type of the data to be written is determined as the garbage collection data type. That is, GC:1 is written to the FMD of the data to be written and then written to disk. If the historical operation record in the FMD is GC:X, the second preset number is added to the historical operation count for weighting. That is, the current operation record of the data to be written is determined as GC:X+1, and then written to the FMD of the data to be written to obtain the target data to be written.
[0025] Step S12: Divide the free physical blocks of the hard disk according to the number of erases of the physical blocks to obtain the divided free physical blocks of the hard disk. Then, determine the working physical blocks of the hard disk corresponding to each of the divided free physical blocks of the hard disk based on the number of erases of each of the divided free physical blocks of the hard disk.
[0026] In this embodiment, a physical block whose number of erases is less than a first preset quantile value is determined as a first partitioned free physical block; a physical block whose number of erases is greater than or equal to the first preset quantile value and less than the median number of erases is determined as a second partitioned free physical block; a physical block whose number of erases is greater than or equal to the median number of erases and less than the second preset quantile value is determined as a third partitioned free physical block; and a physical block whose number of erases is greater than or equal to the second preset quantile value is determined as a fourth partitioned free physical block. Specifically, based on the Program / Erase Cycle (PEC) of the hard drive's physical blocks, the free physical blocks are divided into four equal parts. Free physical blocks with a PEC less than the first preset quantile are called "childhood free physical blocks," i.e., the free physical blocks after the first division. Free physical blocks with a PEC between the first preset quantile and the median of the erase count are called "youthful free physical blocks," i.e., the free physical blocks after the second division. Free physical blocks with a PEC between the median of the erase count and the second preset quantile are called "middle-aged free physical blocks," i.e., the free physical blocks after the third division. Free physical blocks with a PEC greater than the second preset quantile are called "old-age free physical blocks," i.e., the free physical blocks after the fourth division. Furthermore, depending on the different requirements for hot and cold data, the blocks can be divided into eight or sixteen equal parts, etc.
[0027] In this embodiment, after obtaining the partitioned free physical blocks of the hard disk, it is determined whether there are physical blocks in each partitioned free physical block whose erase count meets the preset minimum erase count condition. If so, the physical block that meets the preset minimum erase count condition is determined as the working physical block of the hard disk. Specifically, when it is necessary to select working physical blocks for each age group, the working physical blocks corresponding to the four partitioned free physical blocks are determined according to the PEC, namely the working physical blocks corresponding to the free physical blocks for children, youth, middle-aged, and elderly respectively. Except when determining the working physical block corresponding to the free physical block for the elderly, which requires finding the cold data stored with the most erase counts in the elderly free physical block, the other free physical blocks are all determined as the working physical blocks of the hard disk with the smallest PEC in their area.
[0028] Step S13: Determine the current operation type corresponding to the target data to be written, and determine whether the current operation count corresponding to the current operation type is greater than the preset filtering coefficient.
[0029] In this embodiment, after determining the working physical block of the hard disk corresponding to the free physical block of the hard disk after partitioning, the target data to be written needs to be stored in the working physical block of the hard disk corresponding to the free physical block of the hard disk after partitioning. First, the current operation type corresponding to the target data to be written can be determined. If the target data to be written is an IO data type, the current operation count is judged according to the current operation record to see if it is greater than the preset filtering coefficient. According to the target judgment result, the target data to be written can be determined to be slightly hot data or hot data. For example, if the current operation type corresponding to the target data to be written is an IO data type and the current operation count is greater than 4, then the target data to be written is hot data.
[0030] Step S14: Based on the target determination result obtained from the judgment, write the target data to be written into the corresponding working physical block of the hard disk in the partitioned free physical block of the hard disk.
[0031] In this embodiment, after obtaining the target determination result, if the obtained target determination result indicates that the current operation type corresponding to the target data to be written is an IO data type, and the corresponding current operation count is greater than or equal to the first preset screening coefficient, then the target data to be written is determined to meet the preset hot data condition, and then the target data to be written that meets the preset hot data condition is written to the hard disk working physical block corresponding to the first partitioned hard disk free physical block; if the obtained target determination result indicates that the current operation type corresponding to the target data to be written is an IO data type, and the corresponding current operation count is less than the first preset screening coefficient, then the target data to be written is determined to meet the preset micro-hot data condition, and then the target data to be written that meets the preset micro-hot data condition is written to the hard disk working physical block corresponding to the second partitioned hard disk free physical block. The target data to be written is determined to meet the preset cold data condition. If the target determination result indicates that the current operation type corresponding to the target data to be written is a garbage collection data type, and the corresponding current operation count is less than the second preset screening coefficient, then the target data to be written meets the preset cold data condition. The target data meeting the preset cold data condition is then written to the hard drive working physical block corresponding to the third partitioned free physical block. If the target determination result indicates that the current operation type corresponding to the target data to be written is a garbage collection data type, and the corresponding current operation count is greater than or equal to the second preset screening coefficient, then the target data to be written meets the preset cold data condition. The target data meeting the preset cold data condition is then written to the hard drive working physical block corresponding to the fourth partitioned free physical block. Specifically, for example... Figure 4 As shown, based on the obtained target determination result, the target data to be written is stored in the corresponding working physical block of the hard disk after partitioning the free physical block of the hard disk.
[0032] In one specific implementation, when the target determination result of the data to be written is IO:1-3, IO:1 means that this logical address LBA is either being written to for the first time, or the data was previously moved by GC and is now being overwritten. IO:2-3 indicates overwriting IO data without undergoing garbage collection, suggesting that the data to be written is hot data prone to overwriting. However, a small number of overwrites are not enough to definitively conclude that the data is hot. Therefore, the data to be written is classified as slightly hot data, and a PBA (Physics Block Address) is allocated from the young working physical block for the data to be written and written to disk. Additionally, if the young free physical block has no available physical address to allocate, another physical block is selected from the young free physical blocks as the new working physical block. Slightly hot data is not frequently overwritten, and the speed at which young free physical blocks transition to middle-aged free physical blocks is slower than that of child free physical blocks transitioning to young free physical blocks, which is beneficial for wear leveling.
[0033] In another specific implementation, the target determination result for the data to be written is IO: ≥4, meaning that the data to be written has overwritten the IO data at least three times without undergoing GC data migration. This indicates that the data to be written is frequently updated hot data, and the IO data overwriting is sufficient. Therefore, the data to be written is identified as hot data, and a PBA is allocated from the child working physical block for the data to be written and written to disk. If there is no physical address available for allocation on the hard disk working physical block of the child free physical block, another physical block is selected from the child free physical block as the new hard disk working physical block. The child free physical block has fewer erase and write cycles, and storing hot data is beneficial for wear leveling.
[0034] In the third specific implementation, the target determination result of the data to be written is GC:1-3, which means that the data to be written was moved during the GC process without undergoing IO overwrite. This indicates that the data to be written is cold data that is not easily overwritten by IO. However, a few GC moves are not enough to make a definitive conclusion, so the data to be written is identified as slightly cold data. A PBA is allocated from the middle-aged working physical block to the data to be written for disk writing. If the working physical block of the middle-aged free physical block has no physical address to allocate, another physical block is selected from the middle-aged free physical blocks as the new working physical block. Storing slightly cold data on the corresponding middle-aged free physical block can slow down the rate at which the middle-aged free physical block becomes an old free physical block, and at the same time separate it from cold data. This can avoid the need for cold data to be moved again after slightly cold data is overwritten, thus improving the effectiveness of GC moving and avoiding frequent migrations.
[0035] In the fourth specific implementation, the target determination result of the data to be written is GC:≥4, meaning that the data to be written has been moved at least three times in the GC process without undergoing IO overwrite. This indicates that the data to be written is cold data that will basically not be updated. The number of GC moves is sufficient, so the data to be written is identified as cold data. A PBA is allocated from the old working physical block to the data to be written for disk writing. If there is no physical address available for allocation in the hard disk working physical block of the old free physical block, another physical block is selected from the old free physical blocks as the new hard disk working physical block. Storing cold data in the old free physical block prevents the old free physical block from being erased and written, which is beneficial for wear leveling and extends the life of the SSD.
[0036] As described above, in this embodiment, after the current operation record corresponding to the data to be written is determined, this current operation record is written to the FMD metadata of the data to be written, thereby obtaining the target data to be written. Next, the free physical blocks of the hard disk are divided according to the number of erases of the physical blocks, resulting in the divided free physical blocks of the hard disk. Then, based on the number of erases of each of these divided free physical blocks, the working physical block of the hard disk corresponding to each divided free physical block is further determined. Subsequently, the current operation type corresponding to the target data to be written is determined, and it is judged whether the number of current operations under this current operation type is greater than a preset filtering coefficient, thereby obtaining a target determination result. Finally, according to this target determination result, the target data to be written is written to the working physical block of the hard disk in the corresponding divided free physical blocks of the hard disk, thereby completing the data writing operation. This approach linearly weights the data record operation type and corresponding number of operations for each data point, identifying the degree of hot / cold data based on these weights. During host I / O writes and garbage collection data migration, data is written to physical blocks of different ages according to its hot / coldness, improving the effectiveness of garbage collection, promoting wear leveling, enhancing SSD performance, and extending SSD lifespan. It also facilitates interaction between different data ranges, aiming to maintain a balance between young and middle-aged free physical blocks, gradually increasing write operations, allowing more write operations to be performed on young free physical blocks containing hot data, and ceasing write operations on old free physical blocks containing cold data.
[0037] As can be seen from the previous embodiment, this application discloses a data writing method that can filter and separate hot and cold data, thereby improving SSD performance and extending SSD lifespan. The specific data writing method will be described in detail below.
[0038] This application first obtains the data to be written to the SSD. Based on the historical operation records of the data to be written, it determines the current operation record corresponding to the data to be written, and then obtains the target data to be written based on the determined current operation record. Next, the free physical blocks of the hard drive are divided into four equal parts according to the Physical Block Configuration (PEC) of the hard drive's physical blocks. Free physical blocks with a PEC less than the first preset quantile are designated as "childhood free physical blocks," free physical blocks with a PEC between the first preset quantile and the median number of erases are designated as "youth free physical blocks," free physical blocks with a PEC between the median number of erases and the second preset quantile are designated as "middle-aged free physical blocks," and free physical blocks with a PEC greater than the second preset quantile are designated as "old-age free physical blocks." After obtaining the divided free physical blocks, the working physical blocks corresponding to the four divided free physical blocks are determined based on the PEC. After determining the working physical block of the hard drive corresponding to the free physical block after partitioning, the current operation type corresponding to the target data to be written is determined. If the target data to be written is an I / O data type, the current operation count is judged based on the current operation record to see if it exceeds a preset filtering coefficient, thus obtaining the corresponding target determination result. After obtaining the target determination result, it can be determined whether the target data to be written is cold or hot data, so that the target data to be written can be stored in the corresponding working physical block of the hard drive corresponding to the free physical block after partitioning. By storing I / O data and data migration operation records in the metadata area, the coldness or hotness of the data can be filtered out. Then, based on the characteristics of different coldness or hotness levels, the physical block to store the corresponding data should be selected for flushing, realizing dynamic wear leveling, reducing the frequent migration of cold data, improving SSD performance, and extending SSD lifespan.
[0039] See Figure 5 As shown, an embodiment of the present invention discloses a data writing device, which may include: The target data to be written acquisition module 11 is used to determine the current operation record corresponding to the data to be written, and update the FMD metadata of the data to be written using the current operation record to obtain the target data to be written; wherein, the current operation record includes the current operation type and the current operation count; The hard disk working physical block determination module 12 is used to divide the hard disk free physical blocks according to the number of erases of the physical blocks to obtain the divided hard disk free physical blocks, and then determine the hard disk working physical block corresponding to each of the divided hard disk free physical blocks based on the number of erases of each of the divided hard disk free physical blocks. The current operation count determination module 13 is used to determine the current operation type corresponding to the target data to be written, and to determine whether the current operation count corresponding to the current operation type is greater than a preset filtering coefficient; The target data to be written module 14 is used to write the target data to be written into the corresponding working physical block of the hard disk in the partitioned free physical block of the hard disk according to the target determination result obtained by the judgment.
[0040] As described above, this application first determines the current operation record corresponding to the data to be written. This current operation record is then written into the FMD metadata of the data to be written, thus obtaining the target data to be written. Next, the free physical blocks of the hard disk are divided according to the number of erases on the physical blocks. The resulting division is the partitioned free physical blocks of the hard disk. Then, based on the erase counts of each of these partitioned free physical blocks, the working physical block of the hard disk corresponding to each partitioned free physical block is further determined. Subsequently, the current operation type corresponding to the target data to be written is determined, and it is judged whether the current operation count under this current operation type is greater than a preset filtering coefficient, thus obtaining a target determination result. Finally, based on this target determination result, the target data to be written is written into the working physical block of the hard disk within the corresponding partitioned free physical blocks of the hard disk, thereby completing the data writing operation. In this way, by linearly weighting the data record operation type and the corresponding number of operations for each data, the degree of hot and cold data is identified through the weights, and the data is written to physical blocks of different ages according to its hotness or coldness during host IO write and garbage collection data migration, the effectiveness of garbage collection is improved, wear leveling is promoted, the performance of SSD is improved and the life of SSD is extended.
[0041] In one specific embodiment, the target data to be written acquisition module 11 may specifically include: A preset new data condition judgment unit is used to determine whether the data to be written meets the preset new data condition if the current operation type of the data to be written is an IO data type. The first target data to be written acquisition unit is used to determine the first preset number of operations as the current number of operations of the data to be written if it is determined that the data to be written meets the preset new data conditions, and then update the FMD metadata of the data to be written according to the current operation type and the current number of operations to obtain the target data to be written.
[0042] In one specific embodiment, the data writing device may further include: The second target data to be written acquisition unit is used to determine the current operation type of the data to be written as the IO data type and the first preset operation number as the current operation number of the data to be written if it is determined that the data to be written does not meet the preset new data conditions and the historical operation type in the historical operation record corresponding to the data to be written is the garbage collection data type. Then, it updates the FMD metadata of the data to be written based on the current operation type and the current operation number to obtain the target data to be written. The third target data to be written acquisition unit is used to, if it is determined that the data to be written does not meet the preset new data conditions, and the historical operation type of the historical operation record corresponding to the data to be written is IO data type, then increase the current operation count of the data to be written by a first preset number to obtain a new current operation count of the data to be written, and then update the FMD metadata of the data to be written based on the new current operation count to obtain the target data to be written.
[0043] In one specific embodiment, the target data to be written acquisition module 11 may specifically include: The fourth target data to be written acquisition unit is used to determine the current operation type of the data to be written as the garbage collection data type if the current operation type of the data to be written is the garbage collection data type and the historical operation type of the historical operation record of the data to be written is the IO data type, and determine the second preset operation number as the current operation number of the data to be written, and then update the FMD metadata of the data to be written based on the current operation type and the current operation number to obtain the target data to be written; The fifth target data to be written acquisition unit is used to, if the current operation type of the data to be written is garbage collection data type and the historical operation type of the historical operation record of the data to be written is garbage collection data type, then increase the historical operation count of the historical operation record of the data to be written by a second preset number to obtain the current operation count, and then update the FMD metadata of the data to be written based on the current operation count to obtain the target data to be written.
[0044] In one specific embodiment, the hard disk working physical block determination module 12 may specifically include: The first partitioned hard disk free physical block determination unit is used to determine the hard disk free physical blocks whose erase count is less than the first preset threshold value as the first partitioned hard disk free physical blocks. The second partitioned hard disk free physical block unit is used to determine the hard disk free physical blocks whose number of erases is greater than or equal to the first preset quantile value and less than the median of the number of erases as the second partitioned hard disk free physical blocks; The third partitioned hard disk free physical block unit is used to determine the hard disk free physical blocks whose erase count is greater than or equal to the median of the erase count and less than the second preset quantile value as the third partitioned hard disk free physical blocks; The fourth partitioned hard disk free physical block unit is used to determine the hard disk free physical blocks whose erase count is greater than or equal to the second preset quantile value as the fourth partitioned hard disk free physical blocks.
[0045] In one specific embodiment, the hard disk working physical block determination module 12 may specifically include: The physical block determination unit is used to determine whether there are any physical blocks in the free physical blocks of the hard disk after the partitioning that meet the preset minimum number of erase counts condition. The hard disk working physical block determination unit is used to determine, if it exists, a physical block that meets the preset minimum number of erases condition from the free physical blocks of the partitioned hard disk as the hard disk working physical block.
[0046] In one specific embodiment, the target data to be written writing module 14 may specifically include: The first target data to be written unit is used to determine that the target data to be written meets the preset hot data condition if the target determination result indicates that the current operation type corresponding to the target data to be written is an IO data type and the corresponding current operation number is greater than or equal to the first preset filtering coefficient. Then, the target data to be written that meets the preset hot data condition is written to the hard disk working physical block corresponding to the first partitioned hard disk free physical block. The second target data to be written unit is used to determine that the target data to be written meets the preset micro-hot data condition if the target determination result indicates that the current operation type corresponding to the target data to be written is IO data type and the corresponding current operation number is less than the first preset screening coefficient. Then, the target data to be written that meets the preset micro-hot data condition is written to the hard disk working physical block corresponding to the second partitioned hard disk free physical block. The third target data to be written unit is used to determine that the target data to be written meets the preset micro-cold data condition if the target determination result indicates that the current operation type corresponding to the target data to be written is a garbage collection data type and the corresponding current operation number is less than the second preset screening coefficient. Then, the target data to be written that meets the preset micro-cold data condition is written to the hard disk working physical block corresponding to the third partitioned hard disk free physical block. The fourth target data to be written unit is used to determine that the target data to be written meets the preset cold data condition if the target determination result indicates that the current operation type corresponding to the target data to be written is a garbage collection data type and the corresponding current operation number is greater than or equal to the second preset screening coefficient. Then, the target data to be written that meets the preset cold data condition is written to the hard disk working physical block corresponding to the fourth partitioned hard disk free physical block.
[0047] Furthermore, embodiments of this application also disclose an electronic device, Figure 6 This is a structural diagram of an electronic device 20 according to an exemplary embodiment. The content of the diagram should not be construed as limiting the scope of this application.
[0048] Figure 6 This is a schematic diagram of the structure of an electronic device 20 provided in an embodiment of this application. Specifically, the electronic device 20 may include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. The memory 22 stores a computer program, which is loaded and executed by the processor 21 to implement the relevant steps in the data writing method disclosed in any of the foregoing embodiments. Furthermore, the electronic device 20 in this embodiment may specifically be an electronic computer.
[0049] In this embodiment, the power supply 23 is used to provide operating voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and external devices, and the communication protocol it follows can be any communication protocol applicable to the technical solution of this application, and is not specifically limited here; the input / output interface 25 is used to acquire external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs, and is not specifically limited here.
[0050] In addition, the memory 22, as a carrier for resource storage, can be a read-only memory, random access memory, disk or optical disk, etc. The resources stored thereon can include operating system 221, computer program 222, etc., and the storage method can be temporary storage or permanent storage.
[0051] The operating system 221 is used to manage and control the various hardware devices on the electronic device 20 and the computer program 222, which may be Windows Server, Netware, Unix, Linux, etc. In addition to including a computer program capable of performing the data writing method executed by the electronic device 20 as disclosed in any of the foregoing embodiments, the computer program 222 may further include a computer program capable of performing other specific tasks.
[0052] Furthermore, this application also discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, it implements the aforementioned disclosed data writing method. The specific steps of this method can be found in the corresponding content disclosed in the foregoing embodiments, and will not be repeated here.
[0053] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatus disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple; relevant parts can be referred to in the method section.
[0054] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art 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.
[0055] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein can be implemented directly by hardware, a software module executed by a processor, or a combination of both. The software module can be located in random access memory (RAM), main memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the art.
[0056] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0057] The technical solutions provided in this application have been described in detail above. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the methods and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.
Claims
1. A data writing method, characterized in that, include: Determine the current operation record corresponding to the data to be written, and update the FMD metadata of the data to be written using the current operation record to obtain the target data to be written; wherein, the current operation record includes the current operation type and the current operation count; The hard disk free physical blocks are divided according to the number of erases of the physical blocks to obtain the divided hard disk free physical blocks. Then, the hard disk working physical blocks corresponding to each divided hard disk free physical block are determined based on the number of erases of each divided hard disk free physical block. Determine the current operation type corresponding to the target data to be written, and determine whether the current operation count corresponding to the current operation type is greater than a preset filtering coefficient; Based on the target determination result, the target data to be written is written into the corresponding working physical block of the hard disk in the partitioned free physical block of the hard disk.
2. The data writing method according to claim 1, characterized in that, The step of determining the current operation record corresponding to the data to be written, and updating the FMD metadata of the data to be written using the current operation record to obtain the target data to be written, includes: If the current operation type of the data to be written is an IO data type, then determine whether the data to be written meets the preset new data conditions; If it is determined that the data to be written meets the preset new data conditions, then the first preset number of operations is determined as the current number of operations on the data to be written, and then the FMD metadata of the data to be written is updated according to the current operation type and the current number of operations to obtain the target data to be written.
3. The data writing method according to claim 2, characterized in that, The process of determining the current operation record corresponding to the data to be written, and updating the FMD metadata of the data to be written using the current operation record to obtain the target data to be written, further includes: If it is determined that the data to be written does not meet the preset new data conditions, and the historical operation type in the historical operation record corresponding to the data to be written is a garbage collection data type, then the current operation type of the data to be written is determined to be the IO data type, and the first preset operation number is determined to be the current operation number of the data to be written. Then, the FMD metadata of the data to be written is updated based on the current operation type and the current operation number to obtain the target data to be written. If it is determined that the data to be written does not meet the preset new data conditions, and the historical operation type of the historical operation record corresponding to the data to be written is an IO data type, then the current operation count of the data to be written is increased by a first preset number to obtain a new current operation count of the data to be written, and then the FMD metadata of the data to be written is updated based on the new current operation count to obtain the target data to be written.
4. The data writing method according to claim 1, characterized in that, The step of determining the current operation record corresponding to the data to be written, and updating the FMD metadata of the data to be written using the current operation record to obtain the target data to be written, includes: If the current operation type of the data to be written is a garbage collection data type, and the historical operation type of the historical operation record of the data to be written is an IO data type, then the current operation type of the data to be written is determined to be the garbage collection data type, the second preset operation number is determined to be the current operation number of the data to be written, and then the FMD metadata of the data to be written is updated based on the current operation type and the current operation number to obtain the target data to be written. If the current operation type of the data to be written is a garbage collection data type, and the historical operation type of the historical operation record of the data to be written is a garbage collection data type, then the historical operation count of the historical operation record of the data to be written is increased by a second preset number to obtain the current operation count, and then the FMD metadata of the data to be written is updated based on the current operation count to obtain the target data to be written.
5. The data writing method according to any one of claims 1 to 4, characterized in that, The process of dividing the hard disk's free physical blocks according to the number of erase cycles to obtain the divided free physical blocks includes: The hard disk free physical blocks whose number of erasures is less than the first preset threshold value are determined as the first partitioned hard disk free physical blocks; The hard disk free physical blocks whose number of erases is greater than or equal to the first preset quantile value and less than the median of the number of erases are determined as the second partitioned hard disk free physical blocks; The hard disk free physical blocks whose erase count is greater than or equal to the median of the erase count and less than the second preset quantile value are determined as the hard disk free physical blocks after the third partition; The hard disk free physical blocks whose number of erases is greater than or equal to the second preset grading line value are determined as the hard disk free physical blocks after the fourth partition.
6. The data writing method according to claim 5, characterized in that, The determination of the working physical block corresponding to each of the partitioned free physical blocks of the hard disk based on the number of erases of each partitioned free physical block includes: Determine whether there are any physical blocks in the free physical blocks of the hard disk after each partition that meet the preset minimum number of erase counts condition; If it exists, then the physical block that meets the preset minimum number of erases condition from the partitioned free physical blocks of the hard disk is determined as the working physical block of the hard disk.
7. The data writing method according to claim 6, characterized in that, The step of writing the target data to be written into the corresponding working physical block of the hard disk in the partitioned free physical block of the hard disk according to the target determination result includes: If the target determination result indicates that the current operation type corresponding to the target data to be written is an IO data type, and the corresponding current operation count is greater than or equal to the first preset screening coefficient, then the target data to be written is determined to meet the preset hot data condition, and then the target data to be written that meets the preset hot data condition is written to the hard disk working physical block corresponding to the first partitioned hard disk free physical block. If the target determination result indicates that the current operation type corresponding to the target data to be written is an IO data type, and the corresponding current operation count is less than the first preset screening coefficient, then the target data to be written is determined to meet the preset micro-hot data condition, and then the target data to be written that meets the preset micro-hot data condition is written into the hard disk working physical block corresponding to the second partitioned hard disk free physical block; If the target determination result indicates that the current operation type corresponding to the target data to be written is a garbage collection data type, and the corresponding current operation count is less than the second preset screening coefficient, then the target data to be written is determined to meet the preset micro-cold data condition, and then the target data to be written that meets the preset micro-cold data condition is written to the hard disk working physical block corresponding to the third partitioned hard disk free physical block. If the target determination result indicates that the current operation type corresponding to the target data to be written is a garbage collection data type, and the corresponding current operation count is greater than or equal to the second preset screening coefficient, then the target data to be written is determined to meet the preset cold data condition, and then the target data to be written that meets the preset cold data condition is written to the hard disk working physical block corresponding to the fourth partitioned hard disk free physical block.
8. A data writing device, characterized in that, include: The target data to be written acquisition module is used to determine the current operation record corresponding to the data to be written, and update the FMD metadata of the data to be written using the current operation record to obtain the target data to be written; wherein, the current operation record includes the current operation type and the current operation count; The hard disk working physical block determination module is used to divide the hard disk free physical blocks according to the number of erases of the physical blocks to obtain the divided hard disk free physical blocks, and then determine the hard disk working physical block corresponding to each of the divided hard disk free physical blocks based on the number of erases of each of the divided hard disk free physical blocks. The current operation count determination module is used to determine the current operation type corresponding to the target data to be written, and to determine whether the current operation count corresponding to the current operation type is greater than a preset filtering coefficient; The target data to be written module is used to write the target data to be written into the corresponding working physical block of the hard disk in the partitioned free physical block of the hard disk according to the target determination result obtained by the judgment.
9. An electronic device, characterized in that, include: Memory, used to store computer programs; A processor for executing the computer program to implement the data writing method as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, Used to store a computer program; wherein, when the computer program is executed by a processor, it implements the data writing method as described in any one of claims 1 to 7.