WO2023116346A1 - 异常掉电下Trim数据的恢复方法、系统及固态硬盘 - Google Patents

异常掉电下Trim数据的恢复方法、系统及固态硬盘 Download PDF

Info

Publication number
WO2023116346A1
WO2023116346A1 PCT/CN2022/134511 CN2022134511W WO2023116346A1 WO 2023116346 A1 WO2023116346 A1 WO 2023116346A1 CN 2022134511 W CN2022134511 W CN 2022134511W WO 2023116346 A1 WO2023116346 A1 WO 2023116346A1
Authority
WO
WIPO (PCT)
Prior art keywords
trim
bitmap
data
triml2p
logical address
Prior art date
Application number
PCT/CN2022/134511
Other languages
English (en)
French (fr)
Inventor
郭少敏
韩斌
陈祥
Original Assignee
深圳大普微电子科技有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 深圳大普微电子科技有限公司 filed Critical 深圳大普微电子科技有限公司
Publication of WO2023116346A1 publication Critical patent/WO2023116346A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/14Error detection or correction of the data by redundancy in operation
    • G06F11/1402Saving, restoring, recovering or retrying
    • G06F11/1446Point-in-time backing up or restoration of persistent data
    • G06F11/1448Management of the data involved in backup or backup restore
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/14Error detection or correction of the data by redundancy in operation
    • G06F11/1402Saving, restoring, recovering or retrying
    • G06F11/1446Point-in-time backing up or restoration of persistent data
    • G06F11/1458Management of the backup or restore process

Definitions

  • the invention relates to the field of solid-state hard disks, in particular to a method and system for recovering Trim data under abnormal power failure and solid-state hard disks.
  • SSD Solid State Drives, solid state drive
  • the Trim command is used to tell the SSD which data has become useless data and can be erased internally.
  • the Trim command includes storage locations of useless data, so as to inform the SSD which data becomes useless data.
  • the SSD modifies the Trim bitmap according to the Trim command (Bitmap, the Trim bitmap consists of multiple bits, and each bit of the Trim bitmap is used to represent whether the data corresponding to each logical address of the SSD is useful or not.
  • bit position 1 indicates that the corresponding position data is useless
  • bit position 0 indicates that the corresponding position data is useful
  • each bit of the Trim bitmap defaults to a valid state 0), to show these storages contained in the Trim command through the Trim bitmap The data of the location is useless, waiting for garbage collection.
  • garbage collection is a routine operation.
  • the principle of garbage collection operation is: after the data of the host where the SSD is located is updated, the data originally stored in the data blocks of the SSD will become invalid data, resulting in some data blocks in the SSD containing valid data and invalid data at the same time. After reorganizing the data that is still valid in the data block, rewrite it to a new data block, so as to release the storage space occupied by invalid data, that is, to erase the data block that only contains invalid data.
  • SSD will skip useless data according to the Trim bitmap, so that it is no longer necessary to rewrite these useless data (that is, these useless data are also regarded as invalid data ), which reduces write amplification, saves garbage collection time, and improves the performance of SSD during operation.
  • the L2P table is a mapping table with continuous addresses stored in the SSD memory. It is used to represent the mapping relationship between logical addresses and physical addresses.
  • the host accesses the data on the SSD through the L2P table.
  • Each bit in the Trim bitmap is in one-to-one correspondence with each entry in the L2P table.
  • the SSD encounters trimmed data during garbage collection, it will not move the data.
  • the physical address corresponding to the trimmed data in the L2P table will be changed to invalid, and the trimmed bitmap will be deleted.
  • the bit corresponding to the data is reset to 0 (indicating that the Trim data has been processed).
  • the storage capacity of the L2P table is large (generally speaking, the size of the L2P table is 1/1024 of the capacity of the SSD hard disk, for example, the size of the L2P table of the 1T hard disk is 1G, and the size of the L2P table of the 4T hard disk is 4G).
  • the L2P table cannot be completely flashed to the SSD NAND (non-volatile memory), and some of the physical addresses in the L2P table that have been modified to be invalid may be lost due to abnormal power failure, and the validity of the data represented by the Trim bitmap at this time is not valid. Accurate, eventually leading to the failure to correctly restore the Trim data before the abnormal power failure after the system is powered on, thus affecting the reliability of the SSD.
  • the purpose of the present invention is to provide a recovery method, system and solid-state hard disk for Trim data under abnormal power failure, which can restore all Trim data before the system abnormal power failure, effectively avoiding the loss of Trim data in the process of system abnormal power failure,
  • the reliability of the SSD is improved; in addition, the recovery time of the bitmap recovery method is shorter, so that the power-on recovery time after the abnormal power failure of the system is shorter, and a better user experience is brought to the user.
  • the present invention provides a method for recovering Trim data under abnormal power failure, which is applied to solid-state hard drives, including:
  • the start logical address and data length of useless data are included in the Trim command;
  • Modifying the Trim bitmap based on the Trim command includes:
  • the recovery method of Trim data under the abnormal power failure also includes:
  • the first bit in the Trim bitmap is in a valid state, look up the first physical address corresponding to the first logical address from the L2P table to read from the first physical address Data is returned to the reader.
  • the recovery method of Trim data under the abnormal power failure also includes:
  • the invalid address information is directly returned to the reading end.
  • the recovery method of Trim data under the abnormal power failure also includes:
  • both the Trim bitmap and the third bit in the TrimL2P bitmap are in a valid state, then write the first data into a third physical address newly allocated for the third logical address, and updating the L2P table based on the new mapping relationship between the third logical address and the third physical address.
  • the recovery method of Trim data under the abnormal power failure also includes:
  • the fourth bit in the target bitmap is in an invalid state, then write the second data into the fourth physical address newly allocated for the fourth logical address, and write the fourth bit in the target bitmap Reset the bit to a valid state, record the reset information of the target bitmap into a corresponding bitmap log, and update the L2P based on the new mapping relationship between the fourth logical address and the fourth physical address Table; wherein, the target bitmap is the Trim bitmap or the TrimL2P bitmap.
  • the recovery method of Trim data under the abnormal power failure also includes:
  • the count value of valid data on each data block of the solid-state hard disk is updated according to the change of the L2P table.
  • updating the count value of valid data on each data block of the solid state disk according to the change of the L2P table including:
  • the count value of valid data on the data block corresponding to the last physical address corresponding to the logical address in the new mapping relationship is decremented by 1, and the logical address in the new mapping relationship is The count value of valid data on the data block where the corresponding new physical address is located is increased by 1.
  • the present invention also provides a recovery system for Trim data under abnormal power failure, which is applied to solid-state hard drives, including:
  • the Trim bitmap modification module is used to modify the Trim bitmap based on the Trim command after receiving the Trim command, and record the modification information of the Trim bitmap in the Trim log;
  • a garbage collection module configured to skip garbage collection of the target storage data if it is determined according to the Trim bitmap that the target storage data corresponding to the target logical address of the pre-garbage collection is useless data during the garbage collection process;
  • Trim bitmap reset module configured to reset the bits corresponding to the target logical address in the Trim bitmap to a valid state, and record the reset information of the Trim bitmap into the Trim log ;
  • the power-down recovery module is used to restore the Trim bitmap according to the Trim log during the power-on process after the system is abnormally powered off, and restore the TrimL2P bitmap according to the TrimL2P log, and restore the TrimL2P bitmap according to the TrimL2P bitmap.
  • the figure restores the invalid entry of the L2P table, so as to restore the Trim data before the abnormal power failure of the system.
  • the present invention also provides a solid state hard disk, comprising:
  • the controller is configured to implement the steps of any one of the above methods for recovering Trim data under abnormal power failure when the computer program is executed.
  • the invention provides a method for recovering Trim data under abnormal power failure, which is applied to solid-state hard disks.
  • This application involves two bitmaps, one is the Trim bitmap, and the modification information and reset information of the Trim bitmap are recorded in the Trim log; the other is the TrimL2P bitmap, and the modification information of the TrimL2P bitmap is recorded in the TrimL2P log.
  • the Trim bitmap can be restored through the Trim log, and the trim data that has not been processed before the abnormal power failure of the system can be restored after the Trim bitmap is restored;
  • the TrimL2P can be restored through the TrimL2P log Bitmap, restoring the TrimL2p bitmap also restores the Trim data that has been processed by garbage collection before the system abnormal power failure, and the invalid entries of the L2P table can be restored according to the recovered TrimL2P bitmap, thereby recovering the system abnormal power failure
  • All Trim data beforehand can effectively avoid the loss of Trim data in the process of abnormal power failure of the system, and improve the reliability of SSD.
  • the recovery time of the bitmap recovery method is shorter, so that the power-on recovery time after the abnormal power failure of the system is shorter, and a better user experience is brought to the user.
  • the present invention also provides a Trim data recovery system under abnormal power failure and a solid-state hard disk, which have the same beneficial effect as the above recovery method.
  • Fig. 1 is the flow chart of the recovery method of Trim data under a kind of abnormal power failure that the embodiment of the present invention provides;
  • Fig. 2 is a kind of processing schematic diagram that receives Trim order provided by the embodiment of the present invention
  • Fig. 3 is a kind of processing schematic diagram that reads Trim position provided by the embodiment of the present invention.
  • FIG. 4 is a schematic diagram of a process for writing to the Trim/TrimL2p position provided by an embodiment of the present invention
  • FIG. 5 is a processing principle diagram of a position where garbage collection encounters Trim provided by an embodiment of the present invention
  • Fig. 6 is a processing schematic diagram for recovering Trim data according to a bitmap after power-on after an abnormal power-off provided by an embodiment of the present invention
  • FIG. 7 is a schematic structural diagram of a Trim data recovery system under abnormal power failure provided by an embodiment of the present invention.
  • the core of the present invention is to provide a recovery method, system and solid-state hard drive for Trim data under abnormal power failure, which can restore all Trim data before the system abnormal power failure, effectively avoiding the loss of Trim data in the process of system abnormal power failure,
  • the reliability of the SSD is improved; in addition, the recovery time of the bitmap recovery method is shorter, so that the power-on recovery time after the abnormal power failure of the system is shorter, and a better user experience is brought to the user.
  • FIG. 1 is a flow chart of a method for recovering Trim data under abnormal power failure provided by an embodiment of the present invention.
  • the recovery method of Trim data under abnormal power failure is applied to solid-state hard drives, including:
  • Step S1 After receiving the Trim command, modify the Trim bitmap based on the Trim command, and record the modification information of the Trim bitmap into a Trim log.
  • the solid state disk supports a Trim command, and the Trim command is used to inform the solid state disk which data has become useless data and can be internally erased. Based on this, after the solid state disk receives the Trim command, it can modify the Trim bitmap based on the Trim command (the Trim bitmap is composed of multiple bits, and each bit of the Trim bitmap is used to represent the logical address correspondence of the solid state disk one by one. Whether the data is useful, such as bit position 1 indicates that the corresponding position data is useless, bit position 0 indicates that the corresponding position data is useful, each bit of the Trim bitmap defaults to a valid state of 0), to show the useless corresponding to the Trim command through the Trim bitmap The storage location of the data. Moreover, the solid state disk also records the modification information of the Trim bitmap into the Trim log.
  • Step S2 During the garbage collection process, if it is determined according to the Trim bitmap that the target storage data corresponding to the target logical address of the pre-garbage collection is useless data, skip the garbage collection of the target storage data.
  • garbage collection is a routine operation.
  • the principle of garbage collection operation is: after the data of the host computer where the solid-state drive is located is updated, the data originally stored in the data block of the solid-state drive becomes invalid data, resulting in some data blocks in the solid-state drive containing valid data and invalid data at the same time.
  • the still valid data in these data blocks are rearranged and rewritten into new data blocks, so as to release the storage space occupied by invalid data, that is, to erase the data blocks containing only invalid data.
  • the bit position 1 of the Trim bitmap indicates that the data at the corresponding location is useless, and the bit position 0 indicates that the data at the corresponding location is useful.
  • the process of determining whether the target storage data corresponding to the target logical address of the pre-garbage collection is useless data according to the Trim bitmap includes: Find the target bit corresponding to the target logical address in the Trim bitmap, if the target bit in the Trim bitmap is 1, then determine that the target storage data corresponding to the target logical address is useless data; if the target bit in the Trim bitmap is 0 , it is determined that the target storage data corresponding to the target logical address is not useless data.
  • Step S3 Reset the bit corresponding to the target logical address in the Trim bitmap to a valid state, and record the reset information of the Trim bitmap into the Trim log.
  • the bits corresponding to the target logical address in the Trim bitmap are reset to a valid state (indicating that the Trim data corresponding to the target logical address has been processed), and Record the reset information of the Trim bitmap to the Trim log.
  • Step S4 Modify the target physical address corresponding to the target logical address in the L2P table to an invalid address, and modify the bits corresponding to the target logical address in the TrimL2P bitmap to an invalid state, and record the modification information of the TrimL2P bitmap to TrimL2P log.
  • the solid-state disk while the solid-state disk is processing the garbage collection of the target logical address, it also uses the L2P table (the L2P table is a mapping table with continuous addresses stored in the memory of the solid-state disk, which is used to represent the relationship between the logical address and the physical address. Mapping relationship, the host accesses the data on the SSD through the L2P table) and the target physical address corresponding to the target logical address is modified to an invalid address, so that when the host reads the target logical address in the L2P table, it knows that the corresponding data is invalid .
  • the L2P table is a mapping table with continuous addresses stored in the memory of the solid-state disk, which is used to represent the relationship between the logical address and the physical address. Mapping relationship, the host accesses the data on the SSD through the L2P table) and the target physical address corresponding to the target logical address is modified to an invalid address, so that when the host reads the target logical address in the L2P table, it knows that the corresponding data
  • the solid-state disk will also use the TrimL2P bitmap (TrimL2P bitmap is composed of multiple bits, each bit of the TrimL2P bitmap represents the validity of the physical address corresponding to each logical address of the L2P table, such as bit position 1 means corresponding The address is invalid, the bit position 0 indicates that the corresponding address is valid, each bit of the TrimL2P bitmap defaults to a valid state 0), and the bit corresponding to the target logical address in the TrimL2P bitmap is modified to an invalid state, and the modification information of the TrimL2P bitmap is recorded in the TrimL2P log middle.
  • TrimL2P bitmap is composed of multiple bits, each bit of the TrimL2P bitmap represents the validity of the physical address corresponding to each logical address of the L2P table, such as bit position 1 means corresponding The address is invalid, the bit position 0 indicates that the corresponding address is valid, each bit of the TrimL2P bitmap defaults to a valid state 0), and the bit corresponding to
  • Step S5 During the power-on process after the system is abnormally powered off, restore the Trim bitmap according to the Trim log, and restore the TrimL2P bitmap according to the TrimL2P log, and restore the invalid entry of the L2P table according to the restored TrimL2P bitmap, so as to restore the output Trim data before the system abnormal power failure.
  • the storage capacity of the two is small (generally about 32K), and the Trim logs and TrimL2P logs are updated in chronological order, and will be written to the solid state when a certain size is filled.
  • the Trim log and TrimL2P log can all be flashed to the NAND, and the log data will not be lost.
  • the storage capacity of the L2P table is very large (usually about several G), if the system is abnormally powered off, the L2P table cannot be completely flashed to the NAND, and part of the L2P table is modified to an invalid physical address. It will be lost due to abnormal power failure.
  • Trim bitmap and TrimL2P bitmap the bitmap data of the two will be lost due to abnormal power failure.
  • the L2P table, Trim log, and TrimL2P log can be restored according to the NAND metadata, and then the Trim bitmap can be restored according to the Trim log.
  • the Trim data that has not been processed before the system abnormal power failure is restored, and the TrimL2P bitmap can also be restored according to the TrimL2P log.
  • Restoring the TrimL2p bitmap also restores the Trim data that has been processed by garbage collection before the system abnormal power failure, and then you can According to the restored TrimL2P bitmap, the invalid entries of the L2P table are restored, thus successfully restoring all the Trim data before the abnormal power failure of the system.
  • this application involves two bitmaps, one is a Trim bitmap, and the modification information and reset information of the Trim bitmap are recorded in the Trim log; the other is a TrimL2P bitmap, and the modification information of the TrimL2P bitmap is recorded in the TrimL2P log .
  • the Trim bitmap can be restored through the Trim log
  • the TrimL2P bitmap can be restored through the TrimL2P log
  • the invalid entries of the L2P table can be restored according to the restored TrimL2P bitmap, thereby restoring the output All Trim data before abnormal power failure of the system effectively avoids the loss of Trim data during abnormal power failure of the system and improves the reliability of solid-state drives.
  • the recovery time of the bitmap recovery method used in this application is shorter, so that the recovery time after the system is abnormally powered off is shorter and brings better user experience to the user.
  • the present application can save the table item changes without frequently refreshing the L2P table, thereby having little impact on the performance of the solid-state hard disk during operation and ensuring stable performance.
  • the start logical address and data length of useless data are included in the Trim command;
  • Modify the Trim bitmap based on the Trim command including:
  • the Trim command of the present application includes the starting logical address and data length of the useless data, and after receiving the Trim command, the solid state disk can determine the starting logical address and data length of the useless data in the Trim command. Terminate the logical address, and then modify the bits corresponding to the address range between the start logical address and the end logical address in the Trim bitmap to an invalid state, indicating that the data corresponding to this part of the address range is useless and becomes invalid data.
  • the recovery method of Trim data under abnormal power failure also includes:
  • the first bit in the Trim bitmap is in a valid state, look up the first physical address corresponding to the first logical address from the L2P table, so as to read data from the first physical address and return it to the reading end.
  • the solid-state hard disk when the solid-state hard disk receives the read command containing the first logical address, it first searches for the first bit corresponding to the first logical address in the Trim bitmap, and determines whether the first bit in the Trim bitmap is valid. state; if the first bit in the Trim bitmap is in a valid state, it means that the data corresponding to the first logical address is valid, and then the first physical address corresponding to the first logical address is searched from the L2P table to obtain the first physical address from the first physical address.
  • the read data is returned to the reading end (the host sending the read command); if the first bit in the Trim bitmap is not in a valid state, it means that the data corresponding to the first logical address is invalid, and the address is directly returned to the reading end as invalid Information (indicating that the first logical address corresponds to invalid data).
  • the recovery method of Trim data under abnormal power failure also includes:
  • the invalid address information is directly returned to the reading end.
  • the recovery method of Trim data under abnormal power failure also includes:
  • the Trim bitmap and the TrimL2P bitmap are all in a valid state, then write the first data into the third physical address newly allocated for the third logical address, and based on the third logical address and the third physical address
  • the new mapping relationship updates the L2P table.
  • the solid-state hard disk when it receives the write command including the third logical address and the first data to be written, it searches for the third bit corresponding to the third logical address in the Trim bitmap, and searches for the third bit in the TrimL2P bitmap.
  • the third bit corresponding to the third logical address then judge whether the third bit in the Trim bitmap and the TrimL2P bitmap is in a valid state, if the third bit in the Trim bitmap and the TrimL2P bitmap is in a valid state, Then the Trim bitmap and the TrimL2P bitmap are not processed, a new third physical address is allocated for the third logical address, and the first data to be written is written into the newly allocated third physical address for the third logical address , then update the L2P table based on the new mapping relationship between the third logical address and the third physical address; if the third bit in the Trim bitmap is in an invalid state and the third bit in the TrimL2P bitmap is in a valid state, then the TrimL2P bit The figure is not
  • the 3rd bit in the TrimL2P bitmap is reset to an effective state (representing that valid data has been written at the 3rd logical address), and the reset information of the TrimL2P bitmap is recorded in the TrimL2P log, and then based on the 3rd logical address and the 3rd logical address
  • the new mapping relationship of the three physical addresses updates the L2P table; if the third bit in the Trim bitmap and the TrimL2P bitmap is in an invalid state, a new third physical address is allocated for the third logical address, and the first data is written Into the third physical address newly allocated for the third logical address, simultaneously the third bit in the Trim bitmap and the TrimL2P bitmap is all reset to an effective state (representing that valid data has been written in the third logical address), and Record the reset information of the Trim bitmap into the Trim log, record the reset information of the TrimL2P bitmap into the TrimL2P log, and then update the L2P table based on the new mapping relationship between the third logical address and
  • the recovery method of Trim data under abnormal power failure also includes:
  • the second data is written into the fourth physical address newly allocated for the fourth logical address, the fourth bit in the target bitmap is reset to an effective state, and The reset information of the target bitmap is recorded in the corresponding bitmap log, and the L2P table is updated based on the new mapping relationship between the fourth logical address and the fourth physical address; wherein, the target bitmap is a Trim bitmap or a TrimL2P bitmap.
  • the recovery method of Trim data under abnormal power failure also includes:
  • the count value of valid data on each data block of the solid state disk is updated according to the change of the L2P table.
  • the solid-state hard disk can also update the count value of valid data on each data block of the solid-state hard disk according to the change of the L2P table, so as to accurately know the quantity of valid data on each data block of the solid-state hard disk.
  • updating the count value of valid data on each data block of the solid state disk according to the change situation of the L2P table includes:
  • the count value of valid data on the data block corresponding to the previous physical address corresponding to the logical address in the new mapping relationship is reduced by 1, and the new physical address corresponding to the logical address in the new mapping relationship is located
  • the count value of valid data on the data block is increased by 1.
  • the solid state disk includes multiple data blocks, each data block includes multiple storage units, and one storage unit corresponds to one physical address.
  • the count value of the valid data on the data block where the previous physical address corresponding to the logical address in the new mapping relationship is located is decremented by 1, And add 1 to the count value of valid data on the data block where the new physical address corresponding to the logical address in the new mapping relationship is located.
  • the host sends a Trim command.
  • the start address corresponding to the Trim command is Lma m, and the length is (n-m). Therefore, the address range corresponding to the Trim command is Lma m to Lma(n-1).
  • the address range corresponding to the Trim command is Lma m to Lma(n-1).
  • lma m in the log indicates that the starting position is m
  • n-m means that the length is n-m
  • 1 means that the bit position whose starting position is m and the length is n-m is 1.
  • the bits at position 1 in the Trim/TrimL2p bitmap are all 0, and the L2P table is directly updated, and valid data on each data block is calculated.
  • the bit at position m in the TrimL2P bitmap is 0, and no operation is performed, and the bit at position m in the Trim bitmap is 1, indicating that the data is invalid, and now the host writes at this position Therefore, the bit at position m in the Trim bitmap will be reset to 0, indicating that the data at this position is valid, and the Trim log will be recorded. Finally, the L2P table will be updated and the valid data on each data block will be calculated.
  • the Trim bitmap is found to find that the data on Lma(n-1) is invalid, so there is no need to garbage Lma(n-1) Recycle, reset the bit at position n-1 in the Trim bitmap to 0 (indicating that the Trim data at this position has been processed), record the Trim log, and modify the Lma(n-1) entry of the L2P table to be invalid , so that when the host reads the Lma(n-1) of the L2P table, it knows that the data is invalid.
  • the TrimL2P bitmap also includes the operation of subtracting valid data, which can ensure that the data of the L2P table restored through the TrimL2P bitmap after power-on is consistent with the valid data of all data blocks.
  • the Trim bitmap is restored according to the Trim log
  • the TrimL2P bitmap is restored according to the TrimL2P log
  • the invalid entries of the L2P table are restored according to the TrimL2P bitmap to restore Trim data before abnormal power failure of the system is displayed.
  • the L2P table can be restored according to the NAND metadata (metadata is the data describing the data) after the system is powered on, but since there is no Trim bitmap, when the host reads Lma(m+ 1) When the data between Lma(n-2) and Lma(n-2) is reached, it will be directly read in the L2P table.
  • the data in the L2P table may be valid, but before power off, Lma(m+1) to Lma(n- 2) The data in between is invalid, so you will read wrong data, which is not allowed for enterprise-level SSDs.
  • the location of Lma(n-1) may be valid data in the same way, but in fact Lma(n-1) has been marked as invalid when the garbage is collected before power-off, but because There is no write, and it is impossible to know that the data of Lma(n-1) is invalid through the metadata of NAND, so it is also possible to read wrong data.
  • FIG. 7 is a schematic structural diagram of a Trim data recovery system under abnormal power failure provided by an embodiment of the present invention.
  • the Trim data recovery system under abnormal power failure is applied to solid-state drives, including:
  • Trim bitmap modification module 1 is used to modify the Trim bitmap based on the Trim command after receiving the Trim command, and record the modification information of the Trim bitmap in the Trim log;
  • Garbage collection module 2 is used to skip the garbage collection of the target storage data if it is determined according to the Trim bitmap that the target storage data corresponding to the target logical address of the pre-garbage collection is useless data during the garbage collection process;
  • Trim bitmap reset module 3 for resetting the bits corresponding to the target logical address in the Trim bitmap to an effective state, and recording the reset information of the Trim bitmap in the Trim log;
  • TrimL2P bitmap modification module 4 is used to modify the physical address corresponding to the target logical address in the L2P table to an invalid address, and modify the bits corresponding to the target logical address in the TrimL2P bitmap to an invalid state, and modify the TrimL2P bitmap
  • the modification information of the L2P table is recorded in the TrimL2P log; wherein, each bit of the TrimL2P bitmap represents the validity of the physical address corresponding to each logical address of the L2P table;
  • the power-down recovery module 5 is used to restore the Trim bitmap according to the Trim log, and restore the TrimL2P bitmap according to the TrimL2P log, and restore the invalid table entry of the L2P table according to the TrimL2P bitmap during the power-on process after the system is powered off abnormally, In order to restore the Trim data before the abnormal power failure of the system.
  • the application also provides a solid state hard drive, including:
  • the controller is configured to realize the steps of any one of the above methods for recovering Trim data under abnormal power failure when executing the computer program.

Abstract

一种异常掉电下Trim数据的恢复方法、系统及固态硬盘。本申请涉及两个位图,一个是Trim位图,Trim位图的修改信息和重置信息记录到Trim日志中;另一个是TrimL2P位图,TrimL2P位图的修改信息记录到TrimL2P日志中。则在系统异常掉电后上电的过程中,可通过Trim日志恢复Trim位图,通过TrimL2P日志恢复TrimL2P位图,且根据恢复出的TrimL2P位图可恢复L2P表的无效表项,从而有效避免了系统异常掉电过程中Trim数据的丢失,提升了SSD的可靠性。另外,采用位图恢复方式的恢复时间较短,从而使得系统异常掉电后上电恢复的时间较短,给用户带来较好的使用体验。

Description

异常掉电下Trim数据的恢复方法、系统及固态硬盘
本申请要求于2021年12月20日提交中国专利局、申请号为202111562876.1、发明名称为“异常掉电下Trim数据的恢复方法、系统及固态硬盘”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本发明涉及固态硬盘领域,特别是涉及一种异常掉电下Trim数据的恢复方法、系统及固态硬盘。
背景技术
SSD(Solid State Drives,固态硬盘)支持Trim命令,Trim命令用于告知SSD哪些数据已变为无用数据,可以被内部擦除。具体地,Trim命令中包含无用数据的存储位置,以告知SSD具体哪些数据变为无用数据。SSD在接收到Trim命令后,根据Trim命令修改Trim位图(Bitmap,Trim位图由多个比特位组成,Trim位图的各比特位用于一一表征SSD的各逻辑地址对应的数据是否有用,具体地,比特位置1表示对应位置数据无用,比特位置0表示对应位置数据有用,Trim位图的各比特位默认为有效状态0),以通过Trim位图标示出Trim命令中包含的这些存储位置的数据无用,等待垃圾回收时使用。
在SSD中,垃圾回收是一种常规操作。垃圾回收操作的原理为:SSD所在主机的数据更新后,原来在SSD的数据块中存储的数据便成为无效数据,导致SSD中有的数据块同时包含有效数据和无效数据,需要将这些数据块内仍然有效的数据整理后重新写入到新的数据块,以便释放掉无效数据所占用的存储空间,即擦除只包含无效数据的数据块。而在将有效数据重新写入到新的数据块的过程中,SSD会根据Trim位图跳过无用数据,从而不再用重新写入这些无用的数据(即这些无用数据也被当作无效数据),减小了写放大,同时也节省了垃圾回收时间,提高了SSD在运行过程中的性能。
L2P表是存于SSD内存中的一张地址连续的映射表,用于表示逻辑地址与物理地址之间的映射关系,主机通过L2P表访问SSD上的数据。Trim位图中的各比特位与L2P表的各表项一一对应。SSD在垃圾回收过程中遇到被Trim掉的数据时,不会产生数据搬移,此时会将L2P表中被Trim掉的数据对应的物理地址修改为无效,同时将Trim位图中被Trim掉的数据对应的比特位重新置0(表示此Trim数据已被处理完成)。但是,L2P表的存储量很大(一般来说,L2P表的大小为SSD硬盘容量的1/1024,例如1T硬盘L2P表大小为1G,4T硬盘L2P表为4G),如果系统异常掉电,L2P表不能全部下刷至SSD NAND(非易失性存储器)中,L2P表中部分修改为无效的物理地址可能就会因为异常掉电丢失,而Trim位图此时表示的数据有效性也不准确,最终导致系统上电后无法正确恢复出异常掉电前的Trim数据,从而影响SSD的可靠性。
因此,如何提供一种解决上述技术问题的方案是本领域的技术人员目前需要解决的问题。
发明内容
本发明的目的是提供一种异常掉电下Trim数据的恢复方法、系统及固态硬盘,可恢复出系统异常掉电前所有的Trim数据,有效避免了系统异常掉电过程中Trim数据的丢失,提升了SSD的可靠性;另外,采用位图恢复方式的恢复时间较短,从而使得系统异常掉电后上电恢复的时间较短,给用户带来较好的使用体验。
为解决上述技术问题,本发明提供了一种异常掉电下Trim数据的恢复方法,应用于固态硬盘,包括:
在接收到Trim命令后,基于所述Trim命令修改Trim位图,并将所述Trim位图的修改信息记录到Trim日志中;
在垃圾回收过程中,若根据所述Trim位图判定出预垃圾回收的目标逻辑地址对应的目标存储数据为无用数据,则跳过所述目标存储数据的垃圾回收;
将所述Trim位图中与所述目标逻辑地址对应的比特位重置为有效状态,并将所述Trim位图的重置信息记录到所述Trim日志中;
将L2P表中与所述目标逻辑地址对应的目标物理地址修改为无效地址,并将TrimL2P位图中与所述目标逻辑地址对应的比特位修改为无效状态,且将所述TrimL2P位图的修改信息记录到TrimL2P日志中;
在系统异常掉电后上电的过程中,根据所述Trim日志恢复所述Trim位图,并根据所述TrimL2P日志恢复所述TrimL2P位图,且根据恢复的所述TrimL2P位图恢复所述L2P表的无效表项,以恢复出系统异常掉电前的Trim数据。
可选地,所述Trim命令中包含无用数据的起始逻辑地址和数据长度;
基于所述Trim命令修改所述Trim位图,包括:
根据所述起始逻辑地址和所述数据长度确定所述无用数据的终止逻辑地址;
将所述Trim位图中与所述起始逻辑地址和所述终止逻辑地址之间的地址范围对应的比特位均修改为无效状态。
可选地,所述异常掉电下Trim数据的恢复方法还包括:
在接收到包含第一逻辑地址的读取指令时,查找所述Trim位图中与所述第一逻辑地址对应的第一比特位;
若所述Trim位图中所述第一比特位处于有效状态,则从所述L2P表中查找与所述第一逻辑地址对应的第一物理地址,以从所述第一物理地址中读取数据返回给读取端。
可选地,所述异常掉电下Trim数据的恢复方法还包括:
在接收到包含第二逻辑地址的读取指令时,查找所述Trim位图中与所述第二逻辑地址对应的第二比特位;
若所述Trim位图中所述第二比特位处于无效状态,则直接向读取端返回地址无效信息。
可选地,所述异常掉电下Trim数据的恢复方法还包括:
在接收到包含第三逻辑地址和待写入的第一数据的写入指令时,分别查找所述Trim位图和所述TrimL2P位图中与所述第三逻辑地址对应的第三比特位;
若所述Trim位图和所述TrimL2P位图中所述第三比特位均处于有效状态,则将所述第一数据写入为所述第三逻辑地址新分配的第三物理地址中,并基于所述第三逻辑地址与所述第三物理地址的新映射关系更新所述L2P表。
可选地,所述异常掉电下Trim数据的恢复方法还包括:
在接收到包含第四逻辑地址和待写入的第二数据的写入指令时,分别查找所述Trim位图和所述TrimL2P位图中与所述第四逻辑地址对应的第四比特位;
若目标位图中所述第四比特位处于无效状态,则将所述第二数据写入为所述第四逻辑地址新分配的第四物理地址,将所述目标位图中所述第四比特位重置为有效状态,并将所述目标位图的重置信息记录到相应位图日志中,且基于所述第四逻辑地址与所述第四物理地址的新映射关系更新所述L2P表;其中,所述目标位图为所述Trim位图或所述TrimL2P位图。
可选地,所述异常掉电下Trim数据的恢复方法还包括:
在所述L2P表更改后,根据所述L2P表的更改情况更新所述固态硬盘的各数据块上有效数据的计数值。
可选地,根据所述L2P表的更改情况更新所述固态硬盘的各数据块上有效数据的计数值,包括:
在将所述L2P表中所述目标物理地址修改为无效地址后,将所述目标物理地址所在的数据块上有效数据的计数值减1;
在基于新映射关系更新所述L2P表后,将所述新映射关系中逻辑地址对应的上一个物理地址所在的数据块上有效数据的计数值减1,并将所述新映射关系中逻辑地址对应的新物理地址所在的数据块上有效数据的计数值加1。
为解决上述技术问题,本发明还提供了一种异常掉电下Trim数据的恢复系统,应用于固态硬盘,包括:
Trim位图修改模块,用于在接收到Trim命令后,基于所述Trim命令修改Trim位图,并将所述Trim位图的修改信息记录到Trim日志中;
垃圾回收模块,用于在垃圾回收过程中,若根据所述Trim位图判定出预垃圾回收的目标逻辑地址对应的目标存储数据为无用数据,则跳过所述目标存储数据的垃圾回收;
Trim位图重置模块,用于将所述Trim位图中与所述目标逻辑地址对应的比特位重置为有效状态,并将所述Trim位图的重置信息记录到所述Trim日志中;
TrimL2P位图修改模块,用于将L2P表中与所述目标逻辑地址对应的物理地址修改为无效地址,并将TrimL2P位图中与所述目标逻辑地址对应的比特位修改为无效状态,且将所述TrimL2P位图的修改信息记录到TrimL2P日志中;
掉电恢复模块,用于在系统异常掉电后上电的过程中,根据所述Trim日志恢复所述Trim位图,并根据所述TrimL2P日志恢复所述TrimL2P位图,且根据所述TrimL2P位图恢复所述L2P表的无效表项,以恢复出系统异常掉电前的Trim数据。
为解决上述技术问题,本发明还提供了一种固态硬盘,包括:
存储器,用于存储计算机程序;
控制器,用于在执行所述计算机程序时实现上述任一种异常掉电下Trim数据的恢复方法的步骤。
本发明提供了一种异常掉电下Trim数据的恢复方法,应用于固态硬盘。本申请涉及两个位图,一个是Trim位图,Trim位图的修改信息和重置信息记录到Trim日志中;另一个是TrimL2P位图,TrimL2P位图的修改信息记录到TrimL2P日志中。则在系统异常掉电后上电的过程中,可通过Trim日志恢复Trim位图,恢复了Trim位图也就恢复了系统异常掉电前还未处理完的Trim数据;可通过TrimL2P日志恢复TrimL2P位图,恢复了TrimL2p位图也就恢复了系统异常掉电前垃圾回收已处理完的Trim数据,且根据恢复出的TrimL2P位图可恢复L2P表的无效表项,从而恢复出系统异常掉电前所有的Trim数据,有效避免了系统异常掉电过程中Trim数据 的丢失,提升了SSD的可靠性。另外,采用位图恢复方式的恢复时间较短,从而使得系统异常掉电后上电恢复的时间较短,给用户带来较好的使用体验。
本发明还提供了一种异常掉电下Trim数据的恢复系统及固态硬盘,与上述恢复方法具有相同的有益效果。
附图说明
为了更清楚地说明本发明实施例中的技术方案,下面将对现有技术和实施例中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。
图1为本发明实施例提供的一种异常掉电下Trim数据的恢复方法的流程图;
图2为本发明实施例提供的一种接收到Trim命令的处理原理图;
图3为本发明实施例提供的一种读到Trim位置的处理原理图;
图4为本发明实施例提供的一种写到Trim/TrimL2p位置的处理原理图;
图5为本发明实施例提供的一种垃圾回收遇到Trim的位置的处理原理图;
图6为本发明实施例提供的一种异常掉电后上电根据位图恢复Trim数据的处理原理图;
图7为本发明实施例提供的一种异常掉电下Trim数据的恢复系统的结构示意图。
具体实施方式
本发明的核心是提供一种异常掉电下Trim数据的恢复方法、系统及固态硬盘,可恢复出系统异常掉电前所有的Trim数据,有效避免了系统异常 掉电过程中Trim数据的丢失,提升了SSD的可靠性;另外,采用位图恢复方式的恢复时间较短,从而使得系统异常掉电后上电恢复的时间较短,给用户带来较好的使用体验。
为使本发明实施例的目的、技术方案和优点更加清楚,下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。
请参照图1,图1为本发明实施例提供的一种异常掉电下Trim数据的恢复方法的流程图。
该异常掉电下Trim数据的恢复方法应用于固态硬盘,包括:
步骤S1:在接收到Trim命令后,基于Trim命令修改Trim位图,并将Trim位图的修改信息记录到Trim日志中。
具体地,固态硬盘支持Trim命令,Trim命令用于告知固态硬盘哪些数据已变为无用数据,可以被内部擦除。基于此,固态硬盘在接收到Trim命令后,可基于Trim命令修改Trim位图(Trim位图由多个比特位组成,Trim位图的各比特位用于一一表征固态硬盘的各逻辑地址对应的数据是否有用,如比特位置1表示对应位置数据无用,比特位置0表示对应位置数据有用,Trim位图的各比特位默认为有效状态0),以通过Trim位图标示出Trim命令对应的无用数据的存储位置。而且,固态硬盘还将Trim位图的修改信息记录到Trim日志中。
步骤S2:在垃圾回收过程中,若根据Trim位图判定出预垃圾回收的目标逻辑地址对应的目标存储数据为无用数据,则跳过目标存储数据的垃圾回收。
具体地,在固态硬盘中,垃圾回收是一种常规操作。垃圾回收操作的原理为:固态硬盘所在主机的数据更新后,原来在固态硬盘的数据块中存储的数据便成为无效数据,导致固态硬盘中有的数据块同时包含有效数据和无效数据,需要将这些数据块内仍然有效的数据整理后重新写入到新的 数据块,以便释放掉无效数据所占用的存储空间,即擦除只包含无效数据的数据块。
固态硬盘在将有效数据重新写入到新的数据块的过程中,根据Trim位图判定预垃圾回收的目标逻辑地址对应的目标存储数据是否为无用数据,若目标存储数据不为无用数据,则将目标存储数据重新写入到新的数据块中;若目标存储数据为无用数据,则跳过目标存储数据的垃圾回收,从而不再用重新写入无用数据(即无用数据也被当作无效数据),减小了写放大,同时也节省了垃圾回收时间,提高了固态硬盘在运行过程中的性能。
比如,Trim位图的比特位置1表示对应位置数据无用,比特位置0表示对应位置数据有用,则根据Trim位图判定预垃圾回收的目标逻辑地址对应的目标存储数据是否为无用数据的过程包括:查找Trim位图中与目标逻辑地址对应的目标比特位,若Trim位图中目标比特位为1,则确定目标逻辑地址对应的目标存储数据为无用数据;若Trim位图中目标比特位为0,则确定目标逻辑地址对应的目标存储数据不为无用数据。
步骤S3:将Trim位图中与目标逻辑地址对应的比特位重置为有效状态,并将Trim位图的重置信息记录到Trim日志中。
具体地,固态硬盘在处理目标逻辑地址的垃圾回收的同时,将Trim位图中与目标逻辑地址对应的比特位重置为有效状态(表示目标逻辑地址对应的Trim数据已被处理完成),并将Trim位图的重置信息记录到Trim日志中。
步骤S4:将L2P表中与目标逻辑地址对应的目标物理地址修改为无效地址,并将TrimL2P位图中与目标逻辑地址对应的比特位修改为无效状态,且将TrimL2P位图的修改信息记录到TrimL2P日志中。
具体地,固态硬盘在处理目标逻辑地址的垃圾回收的同时,还将L2P表(L2P表是存于固态硬盘内存中的一张地址连续的映射表,用于表示逻辑地址与物理地址之间的映射关系,主机通过L2P表访问固态硬盘上的数据)中与目标逻辑地址对应的目标物理地址修改为无效地址,这样当主机读到L2P表中目标逻辑地址时便知道其对应的数据是无效的。此外,固态硬盘还将TrimL2P位图(TrimL2P位图由多个比特位组成,TrimL2P位图 的各比特位一一表征L2P表的各逻辑地址对应的物理地址的有效性,如比特位置1表示对应地址无效,比特位置0表示对应地址有效,TrimL2P位图的各比特位默认为有效状态0)中与目标逻辑地址对应的比特位修改为无效状态,并将TrimL2P位图的修改信息记录到TrimL2P日志中。
步骤S5:在系统异常掉电后上电的过程中,根据Trim日志恢复Trim位图,并根据TrimL2P日志恢复TrimL2P位图,且根据恢复的TrimL2P位图恢复L2P表的无效表项,以恢复出系统异常掉电前的Trim数据。
具体地,对于Trim日志和TrimL2P日志来说,二者的存储量较小(一般是32K左右),Trim日志和TrimL2P日志是按照时间先后顺序更新的,写满一定的大小就会刷写到固态硬盘的NAND中,即使系统异常掉电,由于二者的存储量较小,Trim日志和TrimL2P日志也能全部下刷至NAND中,日志数据不会丢失。对于L2P表来说,L2P表的存储量很大(一般是几个G左右),如果系统异常掉电,L2P表不能全部下刷至NAND中,L2P表中部分修改为无效的物理地址可能就会因为异常掉电丢失。对于Trim位图和TrimL2P位图来说,二者的位图数据会因为异常掉电丢失。
基于此,固态硬盘在系统异常掉电后上电的过程中,可根据NAND的元数据恢复L2P表、Trim日志及TrimL2P日志,而后可根据Trim日志恢复Trim位图,恢复了Trim位图也就恢复了系统异常掉电前还未处理完的Trim数据,还可根据TrimL2P日志恢复TrimL2P位图,恢复了TrimL2p位图也就恢复了系统异常掉电前垃圾回收已处理完的Trim数据,然后可根据恢复的TrimL2P位图恢复L2P表的无效表项,从而成功恢复出系统异常掉电前所有的Trim数据。
可见,本申请涉及两个位图,一个是Trim位图,Trim位图的修改信息和重置信息记录到Trim日志中;另一个是TrimL2P位图,TrimL2P位图的修改信息记录到TrimL2P日志中。则在系统异常掉电后上电的过程中,可通过Trim日志恢复Trim位图,通过TrimL2P日志恢复TrimL2P位图,且根据恢复出的TrimL2P位图可恢复L2P表的无效表项,从而恢复出系统异常掉电前所有的Trim数据,有效避免了系统异常掉电过程中Trim数据的丢失,提升了固态硬盘的可靠性。而且,本申请采用位图恢复方式的恢 复时间较短,从而使得系统异常掉电后上电恢复的时间较短,给用户带来较好的使用体验。另外,本申请在设置TrimL2P位图的基础上,不必频繁下刷L2P表也能保存表项变化,从而对固态硬盘运行时的性能影响较小,保证性能的平稳。
在上述实施例的基础上:
作为一种可选的实施例,Trim命令中包含无用数据的起始逻辑地址和数据长度;
基于Trim命令修改Trim位图,包括:
根据起始逻辑地址和数据长度确定无用数据的终止逻辑地址;
将Trim位图中与起始逻辑地址和终止逻辑地址之间的地址范围对应的比特位均修改为无效状态。
具体地,本申请的Trim命令中包含无用数据的起始逻辑地址和数据长度,则固态硬盘在接收到Trim命令后,可根据Trim命令中无用数据的起始逻辑地址和数据长度确定无用数据的终止逻辑地址,然后将Trim位图中与起始逻辑地址和终止逻辑地址之间的地址范围对应的比特位均修改为无效状态,表示这部分地址范围对应的数据已无用,成为无效数据。
作为一种可选的实施例,异常掉电下Trim数据的恢复方法还包括:
在接收到包含第一逻辑地址的读取指令时,查找Trim位图中与第一逻辑地址对应的第一比特位;
若Trim位图中第一比特位处于有效状态,则从L2P表中查找与第一逻辑地址对应的第一物理地址,以从第一物理地址中读取数据返回给读取端。
进一步地,固态硬盘在接收到包含第一逻辑地址的读取指令时,先查找Trim位图中与第一逻辑地址对应的第一比特位,并判断Trim位图中第一比特位是否处于有效状态;若Trim位图中第一比特位处于有效状态,说明第一逻辑地址对应的数据有效,则从L2P表中查找与第一逻辑地址对应的第一物理地址,以从第一物理地址中读取数据返回给读取端(发送读取指令的主机);若Trim位图中第一比特位未处于有效状态,说明第一逻辑 地址对应的数据无效,则直接向读取端返回地址无效信息(表示第一逻辑地址对应的是无效数据)。
作为一种可选的实施例,异常掉电下Trim数据的恢复方法还包括:
在接收到包含第二逻辑地址的读取指令时,查找Trim位图中与第二逻辑地址对应的第二比特位;
若Trim位图中第二比特位处于无效状态,则直接向读取端返回地址无效信息。
本实施例与上述读取实施例的原理类似,本申请在此不再赘述。
作为一种可选的实施例,异常掉电下Trim数据的恢复方法还包括:
在接收到包含第三逻辑地址和待写入的第一数据的写入指令时,分别查找Trim位图和TrimL2P位图中与第三逻辑地址对应的第三比特位;
若Trim位图和TrimL2P位图中第三比特位均处于有效状态,则将第一数据写入为第三逻辑地址新分配的第三物理地址中,并基于第三逻辑地址与第三物理地址的新映射关系更新L2P表。
进一步地,固态硬盘在接收到包含第三逻辑地址和待写入的第一数据的写入指令时,查找Trim位图中与第三逻辑地址对应的第三比特位,并查找TrimL2P位图中与第三逻辑地址对应的第三比特位,然后判断Trim位图和TrimL2P位图中第三比特位是否均处于有效状态,若Trim位图和TrimL2P位图中第三比特位均处于有效状态,则对Trim位图和TrimL2P位图不做处理,为第三逻辑地址分配一个新的第三物理地址,并将待写入的第一数据写入为第三逻辑地址新分配的第三物理地址中,然后基于第三逻辑地址与第三物理地址的新映射关系更新L2P表;若Trim位图中第三比特位处于无效状态、TrimL2P位图中第三比特位处于有效状态,则对TrimL2P位图不做处理,为第三逻辑地址分配一个新的第三物理地址,并将待写入的第一数据写入为第三逻辑地址新分配的第三物理地址中,同时将Trim位图中第三比特位重置为有效状态(表示在第三逻辑地址写入了有效数据),并将Trim位图的重置信息记录到Trim日志中,然后基于第三逻辑地址与第三物理地址的新映射关系更新L2P表;若TrimL2P位图中第三比特位处于无效状态、Trim位图中第三比特位处于有效状态,则对Trim 位图不做处理,为第三逻辑地址分配一个新的第三物理地址,并将待写入的第一数据写入为第三逻辑地址新分配的第三物理地址中,同时将
TrimL2P位图中第三比特位重置为有效状态(表示在第三逻辑地址写入了有效数据),并将TrimL2P位图的重置信息记录到TrimL2P日志中,然后基于第三逻辑地址与第三物理地址的新映射关系更新L2P表;若Trim位图和TrimL2P位图中第三比特位均处于无效状态,则为第三逻辑地址分配一个新的第三物理地址,并将第一数据写入为第三逻辑地址新分配的第三物理地址中,同时将Trim位图和TrimL2P位图中第三比特位均重置为有效状态(表示在第三逻辑地址写入了有效数据),并将Trim位图的重置信息记录到Trim日志中、将TrimL2P位图的重置信息记录到TrimL2P日志中,然后基于第三逻辑地址与第三物理地址的新映射关系更新L2P表。主机来读的时候便能根据L2P表读到新的位置的有效数据。
作为一种可选的实施例,异常掉电下Trim数据的恢复方法还包括:
在接收到包含第四逻辑地址和待写入的第二数据的写入指令时,分别查找Trim位图和TrimL2P位图中与第四逻辑地址对应的第四比特位;
若目标位图中第四比特位处于无效状态,则将第二数据写入为第四逻辑地址新分配的第四物理地址,将目标位图中第四比特位重置为有效状态,并将目标位图的重置信息记录到相应位图日志中,且基于第四逻辑地址与第四物理地址的新映射关系更新L2P表;其中,目标位图为Trim位图或TrimL2P位图。
本实施例与上述写入实施例的原理类似,本申请在此不再赘述。
作为一种可选的实施例,异常掉电下Trim数据的恢复方法还包括:
在L2P表更改后,根据L2P表的更改情况更新固态硬盘的各数据块上有效数据的计数值。
进一步地,固态硬盘在L2P表更改后,还可根据L2P表的更改情况更新固态硬盘的各数据块上有效数据的计数值,以准确了解固态硬盘的各数据块上有效数据的数量。
作为一种可选的实施例,根据L2P表的更改情况更新固态硬盘的各数据块上有效数据的计数值,包括:
在将L2P表中目标物理地址修改为无效地址后,将目标物理地址所在的数据块上有效数据的计数值减1;
在基于新映射关系更新L2P表后,将新映射关系中逻辑地址对应的上一个物理地址所在的数据块上有效数据的计数值减1,并将新映射关系中逻辑地址对应的新物理地址所在的数据块上有效数据的计数值加1。
具体地,固态硬盘中包含多个数据块,每个数据块中包含多个存储单元,一个存储单元对应一个物理地址。固态硬盘更改L2P表有两种情况:1)将L2P表中一个目标物理地址修改为无效地址,此情况下该目标物理地址所在的数据块上便少了一个有效数据,则将该目标物理地址所在的数据块上有效数据的计数值减1;2)基于新映射关系更新L2P表,此情况下新映射关系中逻辑地址对应的上一个物理地址所在的数据块上便少了一个有效数据,新映射关系中逻辑地址对应的新物理地址所在的数据块上便多了一个有效数据,则将新映射关系中逻辑地址对应的上一个物理地址所在的数据块上有效数据的计数值减1,并将新映射关系中逻辑地址对应的新物理地址所在的数据块上有效数据的计数值加1。
综上,给出具体实施例进一步解释说明:
如图2所示,主机发送Trim命令,Trim命令对应的起始地址是Lma m,长度为(n-m),因此Trim命令对应的地址范围是Lma m到Lma(n-1),此时只需要将trim位图的m到n-1位置的比特位置为1即可,表示这部分的数据被Trim掉了,是无效的数据;并且,记录Trim日志,日志中lma m表示起始位置为m,n-m表示长度为n-m,1表示将起始位置为m长度为n-m的比特位置1。
如图3所示,当主机读到Lma1时,查找到Trim位图中1位置的比特位为0,说明该位置数据有效,便会去L2P表查找Lma1对应的物理位置,以从此物理位置读取数据返回给主机。当主机读到Lma m时,查找到Trim位图中m位置的比特位为1,说明该位置数据无效,因此直接返回地址无效信息给主机,表示这个位置无有效数据。
如图4所示,当主机写Lma1时,在Trim/TrimL2p位图中1位置的比特位均为0,直接更新L2P表,并计算每个数据块上有效数据。当主机写 Lma m时,在TrimL2P位图中m位置的比特位为0,不进行任何操作,在Trim位图中m位置的比特位为1,表明该数据无效,现在主机在该位置写入了有效数据,因此会将Trim位图中m位置的比特位重置为0,表示该位置数据有效,并记录Trim日志,最后更新L2P表,并计算每个数据块上有效数据。
如图5所示,当要对Lma(n-1)做垃圾回收时,查找Trim位图发现Lma(n-1)上的数据是无效的,因此不需要对Lma(n-1)做垃圾回收,将Trim位图中n-1位置的比特位重置为0(表示已处理过这个位置的Trim数据),并记录Trim日志,修改L2P表的Lma(n-1)的表项为无效,这样当主机读到L2P表的Lma(n-1)时便知道数据是无效的,此时需要将TrimL2P位图中n-1位置的比特位置为1,并记录TrimL2P日志,表示n-1的位置是垃圾回收的时候遇到Trim数据而更改了L2P表,通过TrimL2P位图记录的方式,防止频繁下刷L2P表,减小了系统性能的波动。需要说明的是,在垃圾回收遇到Trim数据时,将Trim位图的对应比特位由1置为0时会将对应数据块的有效数据减掉,并将TrimL2P位图的对应比特位置为1,因此TrimL2P位图也包含了减掉有效数据这一操作,能够保证上电后通过TrimL2P位图恢复的L2P表的数据与所有数据块的有效数据保持一致性。
如图6所示,在系统异常掉电后上电的过程中,根据Trim日志恢复Trim位图,并根据TrimL2P日志恢复TrimL2P位图,且根据TrimL2P位图恢复L2P表的无效表项,以恢复出系统异常掉电前的Trim数据。
需要说明的是,如果没有Trim位图,系统上电后可根据NAND的元数据(元数据为描述数据的数据)恢复出L2P表,但是由于没有Trim位图,当主机读到Lma(m+1)到Lma(n-2)之间的数据时,就会直接去L2P表中读,L2P表中的数据可能是有效的,但是在掉电前Lma(m+1)到Lma(n-2)之间的数据是无效的,因此就会读到错误的数据,对于企业级SSD来说是不允许的。
如果没有TrimL2P位图,同理读到Lma(n-1)的位置可能是有效数据,但实际上Lma(n-1)在掉电之前垃圾回收的时候就已经被标记为无效了,但 是因为没有产生写,无法通过NAND的元数据知道Lma(n-1)的数据是无效的,因此也可能会读到错误的数据。
请参照图7,图7为本发明实施例提供的一种异常掉电下Trim数据的恢复系统的结构示意图。
该异常掉电下Trim数据的恢复系统应用于固态硬盘,包括:
Trim位图修改模块1,用于在接收到Trim命令后,基于Trim命令修改Trim位图,并将Trim位图的修改信息记录到Trim日志中;
垃圾回收模块2,用于在垃圾回收过程中,若根据Trim位图判定出预垃圾回收的目标逻辑地址对应的目标存储数据为无用数据,则跳过目标存储数据的垃圾回收;
Trim位图重置模块3,用于将Trim位图中与目标逻辑地址对应的比特位重置为有效状态,并将Trim位图的重置信息记录到Trim日志中;
TrimL2P位图修改模块4,用于将L2P表中与目标逻辑地址对应的物理地址修改为无效地址,并将TrimL2P位图中与目标逻辑地址对应的比特位修改为无效状态,且将TrimL2P位图的修改信息记录到TrimL2P日志中;其中,TrimL2P位图的各比特位一一表征L2P表的各逻辑地址对应的物理地址的有效性;
掉电恢复模块5,用于在系统异常掉电后上电的过程中,根据Trim日志恢复Trim位图,并根据TrimL2P日志恢复TrimL2P位图,且根据TrimL2P位图恢复L2P表的无效表项,以恢复出系统异常掉电前的Trim数据。
本申请提供的恢复系统的介绍请参考上述恢复方法的实施例,本申请在此不再赘述。
本申请还提供了一种固态硬盘,包括:
存储器,用于存储计算机程序;
控制器,用于在执行计算机程序时实现上述任一种异常掉电下Trim数据的恢复方法的步骤。
本申请提供的固态硬盘的介绍请参考上述恢复方法的实施例,本申请 在此不再赘述。
还需要说明的是,在本说明书中,诸如第一和第二等之类的关系术语仅仅用来将一个实体或者操作与另一个实体或操作区分开来,而不一定要求或者暗示这些实体或操作之间存在任何这种实际的关系或者顺序。而且,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者设备不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、物品或者设备所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括所述要素的过程、方法、物品或者设备中还存在另外的相同要素。
对所公开的实施例的上述说明,使本领域专业技术人员能够实现或使用本发明。对这些实施例的多种修改对本领域的专业技术人员来说将是显而易见的,本文中所定义的一般原理可以在不脱离本发明的精神或范围的情况下,在其他实施例中实现。因此,本发明将不会被限制于本文所示的这些实施例,而是要符合与本文所公开的原理和新颖特点相一致的最宽的范围。

Claims (10)

  1. 一种异常掉电下Trim数据的恢复方法,其特征在于,应用于固态硬盘,包括:
    在接收到Trim命令后,基于所述Trim命令修改Trim位图,并将所述Trim位图的修改信息记录到Trim日志中;
    在垃圾回收过程中,若根据所述Trim位图判定出预垃圾回收的目标逻辑地址对应的目标存储数据为无用数据,则跳过所述目标存储数据的垃圾回收;
    将所述Trim位图中与所述目标逻辑地址对应的比特位重置为有效状态,并将所述Trim位图的重置信息记录到所述Trim日志中;
    将L2P表中与所述目标逻辑地址对应的目标物理地址修改为无效地址,并将TrimL2P位图中与所述目标逻辑地址对应的比特位修改为无效状态,且将所述TrimL2P位图的修改信息记录到TrimL2P日志中;
    在系统异常掉电后上电的过程中,根据所述Trim日志恢复所述Trim位图,并根据所述TrimL2P日志恢复所述TrimL2P位图,且根据恢复的所述TrimL2P位图恢复所述L2P表的无效表项,以恢复出系统异常掉电前的Trim数据。
  2. 如权利要求1所述的异常掉电下Trim数据的恢复方法,其特征在于,所述Trim命令中包含无用数据的起始逻辑地址和数据长度;
    基于所述Trim命令修改所述Trim位图,包括:
    根据所述起始逻辑地址和所述数据长度确定所述无用数据的终止逻辑地址;
    将所述Trim位图中与所述起始逻辑地址和所述终止逻辑地址之间的地址范围对应的比特位均修改为无效状态。
  3. 如权利要求1所述的异常掉电下Trim数据的恢复方法,其特征在于,所述异常掉电下Trim数据的恢复方法还包括:
    在接收到包含第一逻辑地址的读取指令时,查找所述Trim位图中与所述第一逻辑地址对应的第一比特位;
    若所述Trim位图中所述第一比特位处于有效状态,则从所述L2P表中查找与所述第一逻辑地址对应的第一物理地址,以从所述第一物理地址中读取数据返回给读取端。
  4. 如权利要求3所述的异常掉电下Trim数据的恢复方法,其特征在于,所述异常掉电下Trim数据的恢复方法还包括:
    在接收到包含第二逻辑地址的读取指令时,查找所述Trim位图中与所述第二逻辑地址对应的第二比特位;
    若所述Trim位图中所述第二比特位处于无效状态,则直接向读取端返回地址无效信息。
  5. 如权利要求1-4任一项所述的异常掉电下Trim数据的恢复方法,其特征在于,所述异常掉电下Trim数据的恢复方法还包括:
    在接收到包含第三逻辑地址和待写入的第一数据的写入指令时,分别查找所述Trim位图和所述TrimL2P位图中与所述第三逻辑地址对应的第三比特位;
    若所述Trim位图和所述TrimL2P位图中所述第三比特位均处于有效状态,则将所述第一数据写入为所述第三逻辑地址新分配的第三物理地址中,并基于所述第三逻辑地址与所述第三物理地址的新映射关系更新所述L2P表。
  6. 如权利要求5所述的异常掉电下Trim数据的恢复方法,其特征在于,所述异常掉电下Trim数据的恢复方法还包括:
    在接收到包含第四逻辑地址和待写入的第二数据的写入指令时,分别查找所述Trim位图和所述TrimL2P位图中与所述第四逻辑地址对应的第四比特位;
    若目标位图中所述第四比特位处于无效状态,则将所述第二数据写入为所述第四逻辑地址新分配的第四物理地址,将所述目标位图中所述第四比特位重置为有效状态,并将所述目标位图的重置信息记录到相应位图日志中,且基于所述第四逻辑地址与所述第四物理地址的新映射关系更新所述L2P表;其中,所述目标位图为所述Trim位图或所述TrimL2P位图。
  7. 如权利要求6所述的异常掉电下Trim数据的恢复方法,其特征在于,所述异常掉电下Trim数据的恢复方法还包括:
    在所述L2P表更改后,根据所述L2P表的更改情况更新所述固态硬盘的各数据块上有效数据的计数值。
  8. 如权利要求7所述的异常掉电下Trim数据的恢复方法,其特征在于,根据所述L2P表的更改情况更新所述固态硬盘的各数据块上有效数据的计数值,包括:
    在将所述L2P表中所述目标物理地址修改为无效地址后,将所述目标物理地址所在的数据块上有效数据的计数值减1;
    在基于新映射关系更新所述L2P表后,将所述新映射关系中逻辑地址对应的上一个物理地址所在的数据块上有效数据的计数值减1,并将所述新映射关系中逻辑地址对应的新物理地址所在的数据块上有效数据的计数值加1。
  9. 一种异常掉电下Trim数据的恢复系统,其特征在于,应用于固态硬盘,包括:
    Trim位图修改模块,用于在接收到Trim命令后,基于所述Trim命令修改Trim位图,并将所述Trim位图的修改信息记录到Trim日志中;
    垃圾回收模块,用于在垃圾回收过程中,若根据所述Trim位图判定出预垃圾回收的目标逻辑地址对应的目标存储数据为无用数据,则跳过所述目标存储数据的垃圾回收;
    Trim位图重置模块,用于将所述Trim位图中与所述目标逻辑地址对应的比特位重置为有效状态,并将所述Trim位图的重置信息记录到所述Trim日志中;
    TrimL2P位图修改模块,用于将L2P表中与所述目标逻辑地址对应的物理地址修改为无效地址,并将TrimL2P位图中与所述目标逻辑地址对应的比特位修改为无效状态,且将所述TrimL2P位图的修改信息记录到TrimL2P日志中;
    掉电恢复模块,用于在系统异常掉电后上电的过程中,根据所述Trim日志恢复所述Trim位图,并根据所述TrimL2P日志恢复所述TrimL2P位 图,且根据所述TrimL2P位图恢复所述L2P表的无效表项,以恢复出系统异常掉电前的Trim数据。
  10. 一种固态硬盘,其特征在于,包括:
    存储器,用于存储计算机程序;
    控制器,用于在执行所述计算机程序时实现如权利要求1-8任一项所述的异常掉电下Trim数据的恢复方法的步骤。
PCT/CN2022/134511 2021-12-20 2022-11-25 异常掉电下Trim数据的恢复方法、系统及固态硬盘 WO2023116346A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202111562876.1 2021-12-20
CN202111562876.1A CN114237984A (zh) 2021-12-20 2021-12-20 异常掉电下Trim数据的恢复方法、系统及固态硬盘

Publications (1)

Publication Number Publication Date
WO2023116346A1 true WO2023116346A1 (zh) 2023-06-29

Family

ID=80759275

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/134511 WO2023116346A1 (zh) 2021-12-20 2022-11-25 异常掉电下Trim数据的恢复方法、系统及固态硬盘

Country Status (2)

Country Link
CN (1) CN114237984A (zh)
WO (1) WO2023116346A1 (zh)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117112310A (zh) * 2023-10-18 2023-11-24 苏州元脑智能科技有限公司 后台任务进度保存和恢复方法、装置、设备及存储介质
CN117149091A (zh) * 2023-10-23 2023-12-01 四川云海芯科微电子科技有限公司 一种固态硬盘数据保存方法及相关装置

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114237984A (zh) * 2021-12-20 2022-03-25 深圳大普微电子科技有限公司 异常掉电下Trim数据的恢复方法、系统及固态硬盘
CN117539692B (zh) * 2024-01-09 2024-03-15 武汉麓谷科技有限公司 一种zns固态硬盘数据集管理命令实现方法

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20190034287A1 (en) * 2017-07-26 2019-01-31 Epostar Electronics (Bvi) Corporation Data backup method, data recovery method and storage controller
US20190324904A1 (en) * 2018-04-24 2019-10-24 Phison Electronics Corp. Trim command recording method, memory control circuit unit and memory storage device
CN110568998A (zh) * 2019-09-16 2019-12-13 深圳忆联信息系统有限公司 基于固态硬盘的Trim命令实现方法、装置和计算机设备
US20200081830A1 (en) * 2018-09-11 2020-03-12 Toshiba Memory Corporation Enhanced trim command support for solid state drives
CN111737162A (zh) * 2020-06-10 2020-10-02 广州市大黄蜂信息科技有限公司 一种快速恢复数据的固态硬盘使用方法及计算机可读存储介质
CN114237984A (zh) * 2021-12-20 2022-03-25 深圳大普微电子科技有限公司 异常掉电下Trim数据的恢复方法、系统及固态硬盘

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20190034287A1 (en) * 2017-07-26 2019-01-31 Epostar Electronics (Bvi) Corporation Data backup method, data recovery method and storage controller
US20190324904A1 (en) * 2018-04-24 2019-10-24 Phison Electronics Corp. Trim command recording method, memory control circuit unit and memory storage device
US20200081830A1 (en) * 2018-09-11 2020-03-12 Toshiba Memory Corporation Enhanced trim command support for solid state drives
CN110568998A (zh) * 2019-09-16 2019-12-13 深圳忆联信息系统有限公司 基于固态硬盘的Trim命令实现方法、装置和计算机设备
CN111737162A (zh) * 2020-06-10 2020-10-02 广州市大黄蜂信息科技有限公司 一种快速恢复数据的固态硬盘使用方法及计算机可读存储介质
CN114237984A (zh) * 2021-12-20 2022-03-25 深圳大普微电子科技有限公司 异常掉电下Trim数据的恢复方法、系统及固态硬盘

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117112310A (zh) * 2023-10-18 2023-11-24 苏州元脑智能科技有限公司 后台任务进度保存和恢复方法、装置、设备及存储介质
CN117112310B (zh) * 2023-10-18 2024-02-20 苏州元脑智能科技有限公司 后台任务进度保存和恢复方法、装置、设备及存储介质
CN117149091A (zh) * 2023-10-23 2023-12-01 四川云海芯科微电子科技有限公司 一种固态硬盘数据保存方法及相关装置

Also Published As

Publication number Publication date
CN114237984A (zh) 2022-03-25

Similar Documents

Publication Publication Date Title
WO2023116346A1 (zh) 异常掉电下Trim数据的恢复方法、系统及固态硬盘
US11068391B2 (en) Mapping table updating method for data storage device
US8312204B2 (en) System and method for wear leveling in a data storage device
US10776153B2 (en) Information processing device and system capable of preventing loss of user data
US7911840B2 (en) Logged-based flash memory system and logged-based method for recovering a flash memory system
KR101473344B1 (ko) 플래시 메모리를 스토리지로 사용하는 장치 및 그 동작방법
US7191306B2 (en) Flash memory, and flash memory access method and apparatus
JP4536785B2 (ja) 情報処理装置、該情報処理装置で行われるデータ記憶を制御する制御部およびデータ記憶の制御方法
US20080177937A1 (en) Storage apparatus, computer system, and method for managing storage apparatus
US8296503B2 (en) Data updating and recovering methods for a non-volatile memory array
JP2013061799A (ja) 記憶装置、記憶装置の制御方法およびコントローラ
KR20080037283A (ko) 플래시 메모리 장치를 포함하는 시스템 및 그것의 데이터복구 방법
CN110674056B (zh) 一种垃圾回收方法及装置
JP2004303238A (ja) フラッシュメモリアクセス装置及び方法
CN108874574B (zh) 一种垃圾回收处理方法及相关装置
US20170010810A1 (en) Method and Apparatus for Providing Wear Leveling to Non-Volatile Memory with Limited Program Cycles Using Flash Translation Layer
TW202209333A (zh) 記憶裝置、快閃記憶體控制器及其存取方法
EP2264602A1 (en) Memory device for managing the recovery of a non volatile memory
JP2020191055A (ja) 瞬断からの回復処理方法及び装置、並びにコンピュータ読み取り可能な記憶媒体
KR20200120113A (ko) 메모리 시스템 및 그것의 동작방법
US20200097215A1 (en) Adaptive solid state device management based on data expiration time
CN112035065B (zh) 一种数据写入方法、装置、设备及计算机可读存储介质
CN111758086B (zh) 用于ssd的映射表的刷新方法
CN110286850B (zh) 固态硬盘元数据的写入方法、恢复方法及固态硬盘
US11436105B2 (en) Data processing method and memory controller utilizing the same

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 22909661

Country of ref document: EP

Kind code of ref document: A1