Method, System and Solid State Drive for Recovering Trim Data under Abnormal Power Failure
By recording the modification information of the Trim bitmap and TrimL2P bitmap in the solid state hard disk, the Trim data loss problem caused by abnormal power failure is solved, and reliable data recovery and performance improvement is achieved.
Patent Information
- Application Number
- CN202111562876.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-20
- Publication Date
- 2025-07-25
- Estimated Expiration
- 2041-12-20
AI Technical Summary
When the SSD is abnormally powered down, Trim data loss leads to a decrease in reliability, and the data cannot be recovered correctly, affecting system performance and user experience.
By modifying the Trim bitmap after receiving the Trim command and recording it into the Trim log, skipping useless data during garbage collection, modifying the L2P table and recording it into the TrimL2P bitmap log, and restoring the Trim bitmap and TrimL2P bitmap after the system powers down to restore the invalid table entries of the L2P table.
It effectively avoids Trim data loss, improves the reliability of the solid-state drive, and shortens the power-on recovery time after abnormal power-down of the system, providing a good user experience.
Smart Images

Figure CN114237984B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of solid state drives, and particularly to a method and system for recovering Trim data under abnormal power-off and a solid state drive. Background Art
[0002] SSD (Solid State Drives) supports the Trim command. The Trim command is used to inform the SSD which data has become useless data and can be internally erased. Specifically, the Trim command contains the storage locations of the useless data to inform the SSD which specific data has become useless. After receiving the Trim command, the SSD modifies the Trim 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. Specifically, when the bit is set to 1, it indicates that the data at the corresponding position is useless, and when the bit is set to 0, it indicates that the data at the corresponding position is useful. Each bit of the Trim bitmap defaults to the valid state 0) to indicate through the Trim bitmap that the data at these storage locations included in the Trim command is useless and waits to be used during garbage collection.
[0003] In an SSD, garbage collection is a routine operation. The principle of the garbage collection operation is as follows: After the data of the host where the SSD is located is updated, the data originally stored in the data blocks of the SSD becomes invalid data, resulting in some data blocks in the SSD containing both valid data and invalid data. It is necessary to reorganize the still valid data in these data blocks and rewrite it into new data blocks to release the storage space occupied by the invalid data, that is, erase the data blocks containing only invalid data. During the process of rewriting the valid data into new data blocks, the SSD will skip the useless data according to the Trim bitmap, so that these useless data do not need to be rewritten again (that is, these useless data are also regarded as invalid data), reducing the write amplification, saving the garbage collection time at the same time, and improving the performance of the SSD during operation.
[0004] The L2P table is a continuously - addressed mapping table stored in the SSD memory, which 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 corresponds one - to - one with each entry in the L2P table. When the SSD encounters data that has been Trimmed during the garbage collection process, no data migration will occur. At this time, the physical address corresponding to the Trimmed data in the L2P table will be modified to invalid, and at the same time, the bit corresponding to the Trimmed data in the Trim bitmap will be reset to 0 again (indicating that this Trimmed data has been processed). However, the storage capacity of the L2P table is very large (generally, the size of the L2P table is 1 / 1024 of the SSD hard - disk capacity. For example, the L2P table size of a 1T hard - disk is 1G, and the L2P table of a 4T hard - disk is 4G). If the system loses power abnormally, the entire L2P table cannot be flushed to the SSD NAND (non - volatile memory). Some physical addresses modified to invalid in the L2P table may be lost due to abnormal power - off, and the data validity represented by the Trim bitmap is also inaccurate at this time. Eventually, the system cannot correctly recover the Trim data before the abnormal power - off after power - on, thus affecting the reliability of the SSD.
[0005] Therefore, how to provide a solution to the above - mentioned technical problems is an issue that those skilled in the art need to solve currently. Summary of the Invention
[0006] The object of the present invention is to provide a method, a system, and a solid - state drive for recovering Trim data under abnormal power - off, which can recover all Trim data before the system abnormally loses power, effectively avoiding the loss of Trim data during the abnormal power - off of the system, and improving the reliability of the SSD. In addition, the recovery time using the bitmap recovery method is shorter, so that the power - on recovery time after the system abnormally loses power is shorter, bringing a better user experience.
[0007] To solve the above - mentioned technical problems, the present invention provides a method for recovering Trim data under abnormal power - off, which is applied to a solid - state drive and includes:
[0008] After receiving a Trim command, modify the Trim bitmap based on the Trim command, and record the modification information of the Trim bitmap into the Trim log;
[0009] During the garbage collection process, if it is determined according to the Trim bitmap that the target stored data corresponding to the target logical address to be pre - garbage - collected is useless data, skip the garbage collection of the target stored data;
[0010] 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;
[0011] Modify the target physical address corresponding to the target logical address in the L2P table to an invalid address, modify the bit corresponding to the target logical address in the TrimL2P bitmap to an invalid state, and record the modification information of the TrimL2P bitmap in the TrimL2P log;
[0012] During the power-on process after a system abnormal power-off, restore the Trim bitmap according to the Trim log, restore the TrimL2P bitmap according to the TrimL2P log, and restore the invalid entries of the L2P table according to the restored TrimL2P bitmap to restore the Trim data before the system abnormal power-off.
[0013] Optionally, the Trim command includes the starting logical address and data length of the useless data;
[0014] Modifying the Trim bitmap based on the Trim command includes:
[0015] Determine the ending logical address of the useless data according to the starting logical address and the data length;
[0016] Modify all the bits in the Trim bitmap corresponding to the address range between the starting logical address and the ending logical address to an invalid state.
[0017] Optionally, the method for restoring Trim data under abnormal power-off further includes:
[0018] When receiving a read instruction containing a first logical address, look up the first bit corresponding to the first logical address in the Trim bitmap;
[0019] If the first bit in the Trim bitmap is in a valid state, look up the first physical address corresponding to the first logical address in the L2P table to read data from the first physical address and return it to the reading end.
[0020] Optionally, the method for restoring Trim data under abnormal power-off further includes:
[0021] When receiving a read instruction containing a second logical address, look up the second bit corresponding to the second logical address in the Trim bitmap;
[0022] If the second bit in the Trim bitmap is in an invalid state, directly return address invalid information to the reading end.
[0023] Optionally, the method for restoring Trim data under abnormal power-off further includes:
[0024] When receiving a write instruction including a third logical address and first data to be written, respectively look up a third bit corresponding to the third logical address in the Trim bitmap and the TrimL2P bitmap;
[0025] If the third bits in the Trim bitmap and the TrimL2P bitmap are both in an effective state, write the first data into a third physical address newly allocated for the third logical address, and update the L2P table based on the new mapping relationship between the third logical address and the third physical address.
[0026] Optionally, the method for recovering Trim data under abnormal power-off further includes:
[0027] When receiving a write instruction including a fourth logical address and second data to be written, respectively look up a fourth bit corresponding to the fourth logical address in the Trim bitmap and the TrimL2P bitmap;
[0028] If the fourth bit in the target bitmap is in an invalid state, write the second data into a fourth physical address newly allocated for the fourth logical address, reset the fourth bit in the target bitmap to an effective state, record the reset information of the target bitmap in a corresponding bitmap log, and update the L2P table based on the new mapping relationship between the fourth logical address and the fourth physical address; wherein, the target bitmap is the Trim bitmap or the TrimL2P bitmap.
[0029] Optionally, the method for recovering Trim data under abnormal power-off further includes:
[0030] After the L2P table is changed, update the count value of valid data on each data block of the solid-state drive according to the change situation of the L2P table.
[0031] Optionally, updating the count value of valid data on each data block of the solid-state drive according to the change situation of the L2P table includes:
[0032] After modifying the target physical address in the L2P table to an invalid address, subtract 1 from the count value of valid data on the data block where the target physical address is located;
[0033] After updating the L2P table based on the new mapping relationship, subtract 1 from the count value of valid data on the data block where the previous physical address corresponding to the logical address in the new mapping relationship is located, 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.
[0034] To solve the above technical problems, the present invention also provides a Trim data recovery system under abnormal power failure, which is applied to a solid-state drive and includes:
[0035] A Trim bitmap modification module, configured to modify the Trim bitmap based on the Trim command after receiving the Trim command, and record the modification information of the Trim bitmap into the Trim log;
[0036] A garbage collection module, configured to skip the garbage collection of the target stored data if it is determined according to the Trim bitmap that the target stored data corresponding to the target logical address to be pre-garbage collected is useless data during the garbage collection process;
[0037] A Trim bitmap reset module, configured to 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;
[0038] A TrimL2P bitmap modification module, configured to modify the physical address corresponding to the target logical address in the L2P table to an invalid address, modify the bit corresponding to the target logical address in the TrimL2P bitmap to an invalid state, and record the modification information of the TrimL2P bitmap into the TrimL2P log;
[0039] A power failure recovery module, configured to recover the Trim bitmap according to the Trim log, recover the TrimL2P bitmap according to the TrimL2P log, and recover the invalid entries of the L2P table according to the TrimL2P bitmap during the process of powering on after the system has an abnormal power failure, so as to recover the Trim data before the system has an abnormal power failure.
[0040] To solve the above technical problems, the present invention also provides a solid-state drive, including:
[0041] A memory, configured to store a computer program;
[0042] A controller, configured to implement the steps of any one of the above Trim data recovery methods when executing the computer program.
[0043] The present invention provides a method for recovering Trim data under abnormal power-off, which is applied to a solid-state drive. 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. Then, during the power-on process after the system abnormally powers off, the Trim bitmap can be restored through the Trim log. Restoring the Trim bitmap also restores the Trim data that was not processed before the system abnormally powered off. The TrimL2P bitmap can be restored through the TrimL2P log. Restoring the TrimL2P bitmap also restores the Trim data that has been processed by garbage collection before the system abnormally powers off. And based on the restored TrimL2P bitmap, the invalid entries of the L2P table can be restored, thereby restoring all the Trim data before the system abnormally powers off, effectively avoiding the loss of Trim data during the system abnormal power-off process and improving the reliability of the SSD. In addition, the recovery time using the bitmap recovery method is short, so that the power-on recovery time after the system abnormally powers off is short, bringing a good user experience.
[0044] The present invention also provides a system for recovering Trim data under abnormal power-off and a solid-state drive, which have the same beneficial effects as the above recovery method. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following will briefly introduce the drawings required for use in the prior art and the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other drawings can be obtained based on these drawings.
[0046] Figure 1 It is a flowchart of a method for recovering Trim data under abnormal power-off provided by an embodiment of the present invention;
[0047] Figure 2 It is a schematic diagram of the processing principle of receiving a Trim command provided by an embodiment of the present invention;
[0048] Figure 3 It is a schematic diagram of the processing principle of reading to the Trim position provided by an embodiment of the present invention;
[0049] Figure 4 It is a schematic diagram of the processing principle of writing to the Trim / TrimL2p position provided by an embodiment of the present invention;
[0050] Figure 5 It is a schematic diagram of the processing principle of the position where garbage collection encounters Trim provided by an embodiment of the present invention;
[0051] Figure 6 It is a schematic diagram of the processing principle for restoring Trim data according to a bitmap after power-on following abnormal power-off provided by an embodiment of the present invention;
[0052] Figure 7 It is a schematic structural diagram of a system for restoring Trim data under abnormal power-off provided by an embodiment of the present invention. Detailed implementation manners
[0053] The core of the present invention is to provide a method, a system, and a solid-state drive for restoring Trim data under abnormal power-off, which can restore all Trim data before the system abnormally powers off, effectively avoid the loss of Trim data during the abnormal power-off of the system, and improve the reliability of the SSD; in addition, the recovery time using the bitmap recovery method is relatively short, so that the power-on recovery time after the system abnormally powers off is relatively short, bringing a good user experience.
[0054] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention. Apparently, the described embodiments are some, but not all, of the embodiments of the present invention. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.
[0055] Please refer to Figure 1 , Figure 1 It is a flowchart of a method for restoring Trim data under abnormal power-off provided by an embodiment of the present invention.
[0056] The method for restoring Trim data under abnormal power-off is applied to a solid-state drive and includes:
[0057] Step S1: After receiving a Trim command, modify the Trim bitmap based on the Trim command, and record the modification information of the Trim bitmap in the Trim log.
[0058] Specifically, the solid-state drive supports the Trim command, which is used to inform the solid-state drive which data has become useless data and can be internally erased. Based on this, after receiving the Trim command, the solid-state drive can modify the Trim bitmap according to the Trim command (the Trim bitmap consists of multiple bits, and each bit of the Trim bitmap is used to represent one by one whether the data corresponding to each logical address of the solid-state drive is useful. For example, if the bit is set to 1, it means the data at the corresponding position is useless, and if the bit is set to 0, it means the data at the corresponding position is useful. Each bit of the Trim bitmap defaults to the valid state 0), so as to indicate the storage location of the useless data corresponding to the Trim command through the Trim bitmap. Moreover, the solid-state drive also records the modification information of the Trim bitmap into the Trim log.
[0059] Step S2: During the garbage collection process, if it is determined according to the Trim bitmap that the target stored data corresponding to the target logical address to be pre-garbage collected is useless data, then skip the garbage collection of the target stored data.
[0060] Specifically, in a solid-state drive, garbage collection is a routine operation. The principle of the garbage collection operation is as follows: After the data of the host 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 both valid data and invalid data. It is necessary to organize the still valid data in these data blocks and rewrite it into a new data block in order to release the storage space occupied by the invalid data, that is, erase the data block that only contains invalid data.
[0061] During the process of rewriting the valid data into a new data block, the solid-state drive determines whether the target stored data corresponding to the target logical address to be pre-garbage collected is useless data according to the Trim bitmap. If the target stored data is not useless data, then rewrite the target stored data into the new data block; if the target stored data is useless data, then skip the garbage collection of the target stored data, so that there is no need to rewrite the useless data again (that is, the useless data is also regarded as invalid data), reducing the write amplification, saving the garbage collection time at the same time, and improving the performance of the solid-state drive during operation.
[0062] For example, if the bit of the Trim bitmap is set to 1, it means the data at the corresponding position is useless, and if the bit is set to 0, it means the data at the corresponding position is useful. Then the process of determining whether the target stored data corresponding to the target logical address to be pre-garbage collected is useless data according to the Trim bitmap includes: searching for 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 stored data corresponding to the target logical address is useless data; if the target bit in the Trim bitmap is 0, then determine that the target stored data corresponding to the target logical address is not useless data.
[0063] Step S3: Reset the bit corresponding to the target logical address in the Trim bitmap to the valid state, and record the reset information of the Trim bitmap in the Trim log.
[0064] Specifically, while the solid-state drive processes the garbage collection of the target logical address, it resets the bit corresponding to the target logical address in the Trim bitmap to the valid state (indicating that the Trim data corresponding to the target logical address has been processed), and records the reset information of the Trim bitmap in the Trim log.
[0065] Step S4: Modify the target physical address corresponding to the target logical address in the L2P table to an invalid address, modify the bit corresponding to the target logical address in the TrimL2P bitmap to the invalid state, and record the modification information of the TrimL2P bitmap in the TrimL2P log.
[0066] Specifically, while the solid-state drive processes the garbage collection of the target logical address, it also modifies the target physical address corresponding to the target logical address in the L2P table (the L2P table is a continuously addressed mapping table stored in the memory of the solid-state drive, used to represent the mapping relationship between the logical address and the physical address, and the host accesses the data on the solid-state drive through the L2P table) 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. In addition, the solid-state drive also modifies the bit corresponding to the target logical address in the TrimL2P bitmap (the TrimL2P bitmap consists of multiple bits, and each bit of the TrimL2P bitmap represents the validity of the physical address corresponding to each logical address of the L2P table one by one. For example, when the bit is set to 1, it means the corresponding address is invalid, and when the bit is set to 0, it means the corresponding address is valid, and each bit of the TrimL2P bitmap is default to the valid state 0) to the invalid state, and records the modification information of the TrimL2P bitmap in the TrimL2P log.
[0067] Step S5: During the power-on process after a system abnormal power-off, restore the Trim bitmap according to the Trim log, restore the TrimL2P bitmap according to the TrimL2P log, and restore the invalid entries of the L2P table according to the restored TrimL2P bitmap to restore the Trim data before the system abnormal power-off.
[0068] Specifically, for the Trim log and the TrimL2P log, their storage capacities are relatively small (generally around 32K). The Trim log and the TrimL2P log are updated in chronological order. Once they are filled to a certain size, they will be flushed to the NAND of the solid-state drive. Even if the system experiences an abnormal power failure, due to their small storage capacities, the Trim log and the TrimL2P log can be fully flushed to the NAND, and the log data will not be lost. For the L2P table, its storage capacity is very large (generally several G). If the system experiences an abnormal power failure, the L2P table cannot be fully flushed to the NAND, and some physical addresses that have been modified to invalid in the L2P table may be lost due to the abnormal power failure. For the Trim bitmap and the TrimL2P bitmap, their bitmap data will be lost due to an abnormal power failure.
[0069] Based on this, during the power-on process after the system of the solid-state drive experiences an abnormal power failure, the L2P table, the Trim log, and the TrimL2P log can be restored according to the metadata of the NAND. Then, the Trim bitmap can be restored according to the Trim log. Restoring the Trim bitmap also restores the Trim data that was not processed before the system's abnormal power failure. The TrimL2P bitmap can 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's abnormal power failure. Then, the invalid entries of the L2P table can be restored according to the restored TrimL2P bitmap, thereby successfully restoring all the Trim data before the system's abnormal power failure.
[0070] It can be seen that 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. Then, during the power-on process after the system experiences an abnormal power failure, the Trim bitmap can be restored through the Trim log, the TrimL2P bitmap can be restored through the TrimL2P log, and the invalid entries of the L2P table can be restored according to the restored TrimL2P bitmap, thereby restoring all the Trim data before the system's abnormal power failure, effectively avoiding the loss of Trim data during the system's abnormal power failure and improving the reliability of the solid-state drive. Moreover, the recovery time of the bitmap recovery method adopted in this application is relatively short, so that the power-on recovery time after the system's abnormal power failure is relatively short, bringing a good user experience. In addition, based on the setting of the TrimL2P bitmap in this application, it is not necessary to frequently flush the L2P table to save the changes of the table entries, thus having a relatively small impact on the performance of the solid-state drive during operation and ensuring the stability of the performance.
[0071] Based on the above embodiments:
[0072] As an alternative embodiment, the starting logical address and data length of the useless data are included in the Trim command;
[0073] Modify the Trim bitmap based on the Trim command, including:
[0074] Determine the ending logical address of the useless data according to the starting logical address and data length;
[0075] Modify all the bit positions in the Trim bitmap corresponding to the address range between the starting logical address and the ending logical address to the invalid state.
[0076] Specifically, since the starting logical address and data length of the useless data are included in the Trim command of the present application, after receiving the Trim command, the solid-state drive can determine the ending logical address of the useless data according to the starting logical address and data length of the useless data in the Trim command, and then modify all the bit positions in the Trim bitmap corresponding to the address range between the starting logical address and the ending logical address to the invalid state, indicating that the data corresponding to this part of the address range is no longer useful and becomes invalid data.
[0077] As an alternative embodiment, the method for recovering Trim data under abnormal power-off further includes:
[0078] When receiving a read instruction containing a first logical address, look up the first bit position in the Trim bitmap corresponding to the first logical address;
[0079] If the first bit position in the Trim bitmap is in the valid state, look up the first physical address corresponding to the first logical address in the L2P table to read the data from the first physical address and return it to the reading end.
[0080] Furthermore, when the solid-state drive receives a read instruction containing a first logical address, it first looks up the first bit position in the Trim bitmap corresponding to the first logical address and determines whether the first bit position in the Trim bitmap is in the valid state; if the first bit position in the Trim bitmap is in the valid state, it indicates that the data corresponding to the first logical address is valid, and then it looks up the first physical address corresponding to the first logical address in the L2P table to read the data from the first physical address and return it to the reading end (the host that sends the read instruction); if the first bit position in the Trim bitmap is not in the valid state, it indicates that the data corresponding to the first logical address is invalid, and then it directly returns an address invalid message to the reading end (indicating that the data corresponding to the first logical address is invalid data).
[0081] As an alternative embodiment, the method for recovering Trim data under abnormal power-off further includes:
[0082] When receiving a read instruction containing a second logical address, look up the second bit corresponding to the second logical address in the Trim bitmap;
[0083] If the second bit in the Trim bitmap is in an invalid state, directly return address invalid information to the reading end.
[0084] The principle of this embodiment is similar to that of the above read embodiment, and will not be elaborated herein in this application.
[0085] As an optional embodiment, the method for recovering Trim data under abnormal power failure further includes:
[0086] When receiving a write instruction containing a third logical address and first data to be written, look up the third bit corresponding to the third logical address in the Trim bitmap and the TrimL2P bitmap respectively;
[0087] If the third bits in both the Trim bitmap and the TrimL2P bitmap are in a valid state, write the first data into the third physical address newly allocated for the third logical address, and update the L2P table based on the new mapping relationship between the third logical address and the third physical address.
[0088] Further, when the solid-state drive receives a write instruction including a third logical address and first data to be written, it looks up the third bit corresponding to the third logical address in the Trim bitmap and the third bit corresponding to the third logical address in the TrimL2P bitmap, and then determines whether the third bits in the Trim bitmap and the TrimL2P bitmap are both in the valid state. If the third bits in the Trim bitmap and the TrimL2P bitmap are both in the valid state, no processing is performed on the Trim bitmap and the TrimL2P bitmap, 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, and then the L2P table is updated 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 the invalid state and the third bit in the TrimL2P bitmap is in the valid state, no processing is performed on the TrimL2P bitmap, 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. At the same time, the third bit in the Trim bitmap is reset to the valid state (indicating that valid data has been written at the third logical address), and the reset information of the Trim bitmap is recorded in the Trim log, and then the L2P table is updated based on the new mapping relationship between the third logical address and the third physical address; if the third bit in the TrimL2P bitmap is in the invalid state and the third bit in the Trim bitmap is in the valid state, no processing is performed on the Trim bitmap, 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. At the same time, the third bit in the TrimL2P bitmap is reset to the valid state (indicating that valid data has been written at the third logical address), and the reset information of the TrimL2P bitmap is recorded in the TrimL2P log, and then the L2P table is updated based on the new mapping relationship between the third logical address and the third physical address; if the third bits in the Trim bitmap and the TrimL2P bitmap are both in the invalid state, a new third physical address is allocated for the third logical address, and the first data is written into the newly allocated third physical address for the third logical address. At the same time, the third bits in the Trim bitmap and the TrimL2P bitmap are both reset to the valid state (indicating that valid data has been written at the third logical address), and the reset information of the Trim bitmap is recorded in the Trim log and the reset information of the TrimL2P bitmap is recorded in the TrimL2P log, and then the L2P table is updated based on the new mapping relationship between the third logical address and the third physical address. When the host reads, it can read the valid data at the new position according to the L2P table.
[0089] As an optional embodiment, the method for recovering Trim data under abnormal power-off further includes:
[0090] When receiving a write instruction including a fourth logical address and second data to be written, respectively look up the fourth bit corresponding to the fourth logical address in the Trim bitmap and the TrimL2P bitmap;
[0091] If the fourth bit in the target bitmap is in an invalid state, write the second data to the fourth physical address newly allocated for the fourth logical address, reset the fourth bit in the target bitmap to a valid state, record the reset information of the target bitmap in the corresponding bitmap log, and update the L2P table based on the new mapping relationship between the fourth logical address and the fourth physical address; wherein, the target bitmap is the Trim bitmap or the TrimL2P bitmap.
[0092] The principle of this embodiment is similar to that of the above write embodiment, and will not be elaborated herein.
[0093] As an optional embodiment, the method for recovering Trim data under abnormal power-off further includes:
[0094] After the L2P table is changed, update the count value of the valid data on each data block of the solid-state drive according to the change situation of the L2P table.
[0095] Further, after the L2P table of the solid-state drive is changed, it can also update the count value of the valid data on each data block of the solid-state drive according to the change situation of the L2P table, so as to accurately know the quantity of the valid data on each data block of the solid-state drive.
[0096] As an optional embodiment, updating the count value of the valid data on each data block of the solid-state drive according to the change situation of the L2P table includes:
[0097] After modifying the target physical address in the L2P table to an invalid address, subtract 1 from the count value of the valid data on the data block where the target physical address is located;
[0098] After updating the L2P table based on the new mapping relationship, subtract 1 from 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, and add 1 to the count value of the valid data on the data block where the new physical address corresponding to the logical address in the new mapping relationship is located.
[0099] Specifically, a solid-state drive contains multiple data blocks, each data block contains multiple storage units, and one storage unit corresponds to one physical address. There are two cases where the solid-state drive changes the L2P table: 1) Modify a target physical address in the L2P table to an invalid address. In this case, there is one less valid data on the data block where the target physical address is located, so the count value of the valid data on the data block where the target physical address is located is decreased by 1; 2) Update the L2P table based on the new mapping relationship. In this case, there is one less valid data on the data block where the previous physical address corresponding to the logical address in the new mapping relationship is located, and there is one more valid data on the data block where the new physical address corresponding to the logical address in the new mapping relationship is located. Therefore, 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 decreased by 1, and the count value of the valid data on the data block where the new physical address corresponding to the logical address in the new mapping relationship is located is increased by 1.
[0100] In summary, specific embodiments are given for further explanation:
[0101] As Figure 2 shown, the host sends a Trim command. The starting 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 from Lma m to Lma(n - 1). At this time, only the bits at positions m to n - 1 of the trim bitmap need to be set to 1, indicating that the data in this part has been Trimmed and is invalid data; and, record the Trim log. In the log, lma m represents the starting position as m, n - m represents the length as n - m, and 1 represents setting the bits at positions from m with a length of n - m to 1.
[0102] As Figure 3 shown, when the host reads Lma1, it finds that the bit at position 1 in the Trim bitmap is 0, indicating that the data at this position is valid. Then it will look up the physical location corresponding to Lma1 in the L2P table to read the data from this physical location and return it to the host. When the host reads Lma m, it finds that the bit at position m in the Trim bitmap is 1, indicating that the data at this position is invalid. Therefore, it directly returns an address invalid message to the host, indicating that there is no valid data at this position.
[0103] As Figure 4As shown, when the host writes Lma1, the bits at the 1 position in the Trim / TrimL2p bitmap are all 0. The L2P table is directly updated, and the valid data on each data block is calculated. When the host writes Lma m, the bit at the m position in the TrimL2P bitmap is 0, and no operation is performed. The bit at the m position in the Trim bitmap is 1, indicating that the data is invalid. Now that the host has written valid data at this position, the bit at the m position 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 is updated, and the valid data on each data block is calculated.
[0104] As Figure 5 shown, when garbage collection is to be performed on Lma(n - 1), it is found by looking up the Trim bitmap that the data on Lma(n - 1) is invalid. Therefore, there is no need to perform garbage collection on Lma(n - 1). The bit at the n - 1 position in the Trim bitmap is reset to 0 (indicating that the Trim data at this position has been processed), and the Trim log is recorded. The entry of Lma(n - 1) in the L2P table is modified to invalid. In this way, when the host reads Lma(n - 1) in the L2P table, it knows that the data is invalid. At this time, the bit at the n - 1 position in the TrimL2P bitmap needs to be set to 1, and the TrimL2P log is recorded, indicating that the position of n - 1 is where the L2P table was changed when encountering Trim data during garbage collection. By recording in the TrimL2P bitmap, frequent flushing of the L2P table is prevented, and the system performance fluctuation is reduced. It should be noted that when garbage collection encounters Trim data, when the corresponding bit in the Trim bitmap is set from 1 to 0, the valid data of the corresponding data block will be subtracted, and the corresponding bit in the TrimL2P bitmap will be set to 1. Therefore, the TrimL2P bitmap also includes the operation of subtracting valid data, which can ensure that the data in the L2P table restored through the TrimL2P bitmap after power-on is consistent with the valid data of all data blocks.
[0105] As Figure 6 shown, during the power-on process after the system abnormally loses power, the Trim bitmap is restored according to the Trim log, the TrimL2P bitmap is restored according to the TrimL2P log, and the invalid entries in the L2P table are restored according to the TrimL2P bitmap to restore the Trim data before the system abnormally lost power.
[0106] It should be noted that if there is no Trim bitmap, the system can restore the L2P table according to the NAND metadata (metadata is data that describes data) after power-on. However, due to the absence of the Trim bitmap, when the host reads the data between Lma(m + 1) and Lma(n - 2), it will directly read from the L2P table. The data in the L2P table may be valid, but the data between Lma(m + 1) and Lma(n - 2) was invalid before power-off. Therefore, incorrect data will be read, which is not allowed for enterprise-level SSDs.
[0107] Similarly, if there is no Trim L2P bitmap, the data read at the position of Lma(n - 1) may be valid data, but in fact, Lma(n - 1) was marked as invalid during garbage collection before power-off. However, since no write occurred, it is impossible to know through the NAND metadata that the data of Lma(n - 1) is invalid. Therefore, incorrect data may also be read.
[0108] Please refer to Figure 7 , Figure 7 which is a schematic structural diagram of a Trim data recovery system under abnormal power-off provided by an embodiment of the present invention.
[0109] The Trim data recovery system under abnormal power-off is applied to a solid-state drive and includes:
[0110] A Trim bitmap modification module 1, configured to modify the Trim bitmap based on a Trim command after receiving the Trim command, and record the modification information of the Trim bitmap into a Trim log;
[0111] A garbage collection module 2, configured to skip the garbage collection of target stored data if it is determined according to the Trim bitmap that the target stored data corresponding to the target logical address to be pre-garbage collected is useless data during the garbage collection process;
[0112] A Trim bitmap reset module 3, configured to 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 a Trim log;
[0113] A Trim L2P bitmap modification module 4, configured to modify the physical address corresponding to the target logical address in the L2P table to an invalid address, modify the bit corresponding to the target logical address in the Trim L2P bitmap to an invalid state, and record the modification information of the Trim L2P bitmap into a Trim L2P log; wherein, each bit of the Trim L2P bitmap represents the validity of the physical address corresponding to each logical address of the L2P table one by one;
[0114] The power-down recovery module 5 is used to restore the Trim bitmap according to the Trim log, restore the TrimL2P bitmap according to the TrimL2P log, and restore the invalid entries of the L2P table according to the TrimL2P bitmap during the power-on process after the system abnormally powers down, so as to restore the Trim data before the system abnormally powers down.
[0115] For the introduction of the recovery system provided in this application, please refer to the embodiments of the above recovery method, and this application will not elaborate here.
[0116] This application also provides a solid-state drive, including:
[0117] A memory for storing computer programs;
[0118] A controller for implementing the steps of any of the above Trim data recovery methods under abnormal power-down when executing the computer program.
[0119] For the introduction of the solid-state drive provided in this application, please refer to the embodiments of the above recovery method, and this application will not elaborate here.
[0120] It should also be noted that in this specification, relational terms such as first and second are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the term "comprising", "including" or any other variation thereof is intended to cover a non-exclusive inclusion, so that a process, method, article or device including a series of elements not only includes those elements, but also includes other elements not expressly listed, or also includes elements inherent to such process, method, article or device. Without further limitation, an element defined by the statement "including a..." does not exclude the existence of additional identical elements in the process, method, article or device including the said element.
[0121] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present invention. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A method for recovering Trim data under abnormal power failure, characterized in that, Applied to a solid-state drive, including: After receiving a Trim command, modify the Trim bitmap based on the Trim command, and record the modification information of the Trim bitmap into the Trim log; During the garbage collection process, if it is determined according to the Trim bitmap that the target stored data corresponding to the target logical address to be pre-garbage collected is useless data, then skip the garbage collection of the target stored data; 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; Modify the target physical address corresponding to the target logical address in the L2P table to an invalid address, modify the bit corresponding to the target logical address in the TrimL2P bitmap to an invalid state, and record the modification information of the TrimL2P bitmap into the TrimL2P log; During the power-on process after a system abnormal power-off, restore the Trim bitmap according to the Trim log, restore the TrimL2P bitmap according to the TrimL2P log, and restore the invalid entries of the L2P table according to the restored TrimL2P bitmap to restore the Trim data before the system abnormal power-off.
2. The method for restoring Trim data under abnormal power failure according to claim 1, wherein The Trim command contains the starting logical address and data length of the useless data; Modifying the Trim bitmap based on the Trim command includes: Determine the ending logical address of the useless data according to the starting logical address and the data length; Modify all the bits corresponding to the address range between the starting logical address and the ending logical address in the Trim bitmap to an invalid state.
3. The method for restoring Trim data under abnormal power-off as described in claim 1, wherein The method for restoring Trim data under abnormal power-off further includes: When receiving a read instruction containing a first logical address, look up the first bit corresponding to the first logical address in the Trim bitmap; If the first bit in the Trim bitmap is in a valid state, look up the first physical address corresponding to the first logical address in the L2P table to read the data from the first physical address and return it to the reading end.
4. The method for recovering Trim data under abnormal power failure according to claim 3, characterized in that The method for restoring Trim data under abnormal power-off further includes: When receiving a read instruction containing a second logical address, look up the second bit corresponding to the second logical address in the Trim bitmap; If the second bit in the Trim bitmap is in an invalid state, directly return address invalid information to the reading end.
5. The method for recovering Trim data under abnormal power-off according to any one of claims 1-4, characterized in that, The method for restoring Trim data under abnormal power-off further includes: When receiving a write instruction containing a third logical address and a first data to be written, look up the third bit corresponding to the third logical address in the Trim bitmap and the TrimL2P bitmap respectively; If the third bits in the Trim bitmap and the TrimL2P bitmap are both in a valid state, write the first data into the third physical address newly allocated for the third logical address, and update the L2P table based on the new mapping relationship between the third logical address and the third physical address.
6. The method for recovering Trim data under abnormal power failure according to claim 5, wherein, The method for recovering Trim data under abnormal power-off further includes: When receiving a write instruction including a fourth logical address and second data to be written, respectively search for a fourth bit corresponding to the fourth logical address in the Trim bitmap and the TrimL2P bitmap; If the fourth bit in the target bitmap is in an invalid state, write the second data to a fourth physical address newly allocated for the fourth logical address, reset the fourth bit in the target bitmap to an effective state, record the reset information of the target bitmap in a corresponding bitmap log, and update the L2P table based on the new mapping relationship between the fourth logical address and the fourth physical address; wherein, the target bitmap is the Trim bitmap or the TrimL2P bitmap.
7. The method for restoring Trim data under abnormal power failure as described in claim 6, characterized in that, The method for recovering Trim data under abnormal power-off further includes: After the L2P table is changed, update the count value of valid data on each data block of the solid-state drive according to the change situation of the L2P table.
8. The method for restoring Trim data under abnormal power-off according to claim 7, characterized in that Updating the count value of valid data on each data block of the solid-state drive according to the change situation of the L2P table includes: After modifying the target physical address in the L2P table to an invalid address, decrement the count value of valid data on the data block where the target physical address is located by 1; After updating the L2P table based on the new mapping relationship, decrement the count value of valid data on the data block where the previous physical address corresponding to the logical address in the new mapping relationship is located by 1, and increment 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 by 1.
9. An abnormal power failure Trim data recovery system, characterized in that Applied to a solid-state drive, it includes: A Trim bitmap modification module, configured 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 stored data if it is determined according to the Trim bitmap that the target stored data corresponding to the target logical address to be pre-garbage collected is useless data during the garbage collection process; A Trim bitmap reset module, configured to reset the bit corresponding to the target logical address in the Trim bitmap to an effective state, and record the reset information of the Trim bitmap in the Trim log; A TrimL2P bitmap modification module, configured to modify the target physical address corresponding to the target logical address in the L2P table to an invalid address, modify the bit corresponding to the target logical address in the TrimL2P bitmap to an invalid state, and record the modification information of the TrimL2P bitmap in the TrimL2P log; A power-off recovery module, configured to recover the Trim bitmap according to the Trim log, recover the TrimL2P bitmap according to the TrimL2P log, and recover the invalid entries of the L2P table according to the recovered TrimL2P bitmap during the power-on process after system abnormal power-off, so as to recover the Trim data before system abnormal power-off.
10. A solid-state drive, characterized in that, It includes: A memory for storing a computer program; A controller for implementing the steps of the method for recovering Trim data under abnormal power failure according to any one of claims 1-8 when executing the computer program.
Citation Information
Patent Citations
Solid state disk using method capable of rapidly recovering data and computer readable storage medium
CN111737162A
Data backup method, data recovery method and storage controller
US20190034287A1