A mapping table reconstruction method and a storage device

By determining the last checkpoint and constructing a linked list of historical physical addresses in the SSD, the accuracy and efficiency issues of mapping table recovery in existing technologies are resolved, achieving efficient and accurate mapping table reconstruction and meeting the rapid fault recovery requirements of high-availability storage systems.

CN120832363BActive Publication Date: 2026-01-02CHENGDU BIWIN STORAGE TECHNOLOGY CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202511342629.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-09-19
Publication Date
2026-01-02
Estimated Expiration
2045-09-19

AI Technical Summary

Technical Problem

Existing SSD firmware mapping table recovery schemes rely on a full disk scan mechanism, which can lead to SN conflicts or misjudgments, affecting the accuracy and efficiency of data recovery and making it difficult to meet the rapid fault recovery requirements of high-availability storage systems.

Method used

By determining the last checkpoint in the storage medium, the target mapping table is determined based on the last checkpoint. The metadata of the data blocks is read sequentially, the data is written to a linked list, and the update link of the logical address is constructed using the historical physical address. This avoids the single dependency of the SN counter and realizes the reconstruction of the mapping table of the local scan and linked list structure.

Benefits of technology

It improves the efficiency and accuracy of mapping table reconstruction, ensures the timeliness of mapping relationships, avoids mapping misjudgments caused by SN flipping or reuse, and meets the rapid fault recovery requirements of high-availability storage systems.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120832363B_ABST
    Figure CN120832363B_ABST
Patent Text Reader

Abstract

The application discloses a mapping table reconstruction method and a storage device. The method comprises the following steps: determining a last checkpoint in a storage medium; determining a target mapping table which needs to be recovered based on the last checkpoint; reading metadata of each data block in the storage medium in sequence according to the last checkpoint, wherein the metadata comprises a logical address of currently written data and a historical physical address corresponding to the logical address at previous writing; determining a target block matched with the target mapping table in the data block according to the logical address; constructing a data writing linked list of the logical address according to the historical physical address of the target block; and reconstructing the target mapping table according to the data writing linked list. The application can ensure accurate reconstruction of the mapping table and improve the reconstruction efficiency of the mapping table.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of storage technology, and in particular to a mapping table reconstruction method and storage device. Background Technology

[0002] In storage systems, data recovery is a critical step in ensuring data reliability and system availability. Since storage media (such as SSDs) and the storage system itself have a certain probability of failure, how to quickly and accurately recover valid data in the event of a failure is one of the core challenges in designing storage solutions.

[0003] Currently, the mapping table recovery scheme widely used in SSD firmware mainly relies on a full disk scan mechanism. This mechanism reconstructs the mapping relationship between logical addresses and physical addresses by reading data blocks on the storage medium and parsing their metadata (such as serial number SN).

[0004] However, existing mechanisms have the following problems: First, full-disk scanning relies on the serial number (SN) information of data blocks for recovery, but in certain scenarios (such as SN counter flipping or reuse), it may lead to SN conflicts or misjudgments, resulting in the recovery of incorrect mapping relationships and affecting the accuracy of data recovery. Second, SN-based recovery mechanisms require repeated cross-validation among multiple data blocks to determine the correct data version and mapping relationship. This process involves a large number of random accesses and redundant comparisons, resulting in excessively long recovery times, making it difficult to meet the rapid fault recovery requirements of high-availability storage systems. Summary of the Invention

[0005] The technical problem to be solved by the present invention is to provide a mapping table reconstruction method and storage device, which can improve the reconstruction efficiency of the mapping table while ensuring accurate reconstruction.

[0006] To solve the above-mentioned technical problems, the present invention adopts the following technical solution:

[0007] A mapping table reconstruction method, comprising:

[0008] Determine the last checkpoint in the storage medium;

[0009] Based on the final checkpoint, determine the target mapping table that requires data recovery;

[0010] Based on the last checkpoint, the metadata of each data block in the storage medium is read sequentially. The metadata includes the logical address of the currently written data and the historical physical address corresponding to the logical address in the previous write.

[0011] Determine the target block in the data block that matches the target mapping table based on the logical address;

[0012] The data for constructing the logical address based on the historical physical address of the target block is written into a linked list;

[0013] The target mapping table is reconstructed by writing the data into a linked list.

[0014] To solve the above-mentioned technical problems, another technical solution adopted by the present invention is as follows:

[0015] A storage device includes a storage chip and a control chip, wherein the storage chip stores a computer program, and the computer program, when executed by the control chip, implements the various steps in the mapping table reconstruction method described above.

[0016] The beneficial effects of this invention are as follows: determining the last checkpoint enables the location of the latest valid system status information in the storage medium, reducing redundant scanning range; determining the target mapping table based on the last checkpoint directly locks the mapping relationship that needs to be restored; sequentially reading data block metadata according to the last checkpoint reduces redundant comparisons caused by cross-validation, improving the efficiency of mapping table reconstruction. By matching target blocks with logical addresses, data blocks related to the target mapping table are accurately filtered, irrelevant data interference is eliminated, local scanning is achieved, and the efficiency of mapping table reconstruction is improved; furthermore, a data writing linked list is constructed based on historical physical addresses to restore the update link of different physical addresses corresponding to a logical address. The latest valid data version is tracked through the linked list structure, eliminating the single dependence on the SN counter and avoiding mapping misjudgments caused by SN flipping or reuse, ensuring the accuracy of mapping table reconstruction; finally, the target mapping table is reconstructed according to the data writing linked list, ensuring the timeliness and accuracy of the mapping relationship. Attached Figure Description

[0017] Figure 1 This is a flowchart of a mapping table reconstruction method according to the present invention;

[0018] Figure 2 This is a schematic diagram illustrating the arrangement of a data block sequence for recovery according to the present invention;

[0019] Figure 3 This is a schematic diagram of metadata for a data block according to the present invention;

[0020] Figure 4 This is a schematic diagram illustrating how data is written to a linked list according to the present invention.

[0021] Figure 5 This is a schematic diagram of a data block storage according to the present invention;

[0022] Figure 6 This is a schematic diagram illustrating the arrangement of a data table for reverse reconstruction according to the present invention;

[0023] Figure 7 This is a schematic diagram of the structure of a storage device according to the present invention;

[0024] Label Explanation:

[0025] 100. Storage device; 101. Storage chip; 102. Control chip. Detailed Implementation

[0026] To explain in detail the technical content, objectives, and effects of the present invention, the following description is provided in conjunction with the embodiments and accompanying drawings.

[0027] An embodiment of the present invention provides a mapping table reconstruction method, comprising:

[0028] Determine the last checkpoint in the storage medium;

[0029] Based on the final checkpoint, determine the target mapping table that requires data recovery;

[0030] Based on the last checkpoint, the metadata of each data block in the storage medium is read sequentially. The metadata includes the logical address of the currently written data and the historical physical address corresponding to the logical address in the previous write.

[0031] Determine the target block in the data block that matches the target mapping table based on the logical address;

[0032] The data for constructing the logical address based on the historical physical address of the target block is written into a linked list;

[0033] The target mapping table is reconstructed by writing the data into a linked list.

[0034] As described above, the beneficial effects of this invention are as follows: determining the last checkpoint enables the location of the latest valid system status information in the storage medium, reducing redundant scanning range; determining the target mapping table based on the last checkpoint directly locks the mapping relationship that needs to be restored; sequentially reading data block metadata according to the last checkpoint reduces redundant comparisons caused by cross-validation, improving the efficiency of mapping table reconstruction. By matching target blocks with logical addresses, data blocks related to the target mapping table are accurately filtered, irrelevant data interference is eliminated, local scanning is achieved, and the efficiency of mapping table reconstruction is improved; furthermore, a data writing linked list is constructed based on historical physical addresses to restore the update link of different physical addresses corresponding to a logical address. The latest valid data version is tracked through the linked list structure, eliminating the single dependence on the SN counter and avoiding mapping misjudgments caused by SN flipping or reuse, ensuring the accuracy of mapping table reconstruction; finally, the target mapping table is reconstructed according to the data writing linked list, ensuring the timeliness and accuracy of the mapping relationship.

[0035] Furthermore, it also includes:

[0036] When each piece of data to be written is written to a data block, the historical physical address corresponding to the logical address of the data to be written in the previous write is written into the data block to obtain the metadata.

[0037] As described above, by recording the previous physical address written to the logical address, i.e. the historical physical address, a chain structure of data updates is formed, which enables the system to trace back all historical physical storage locations corresponding to the logical address, avoiding version misjudgment problems that may be caused by relying solely on the serial number (SN).

[0038] Furthermore, determining the last checkpoint in the storage medium includes:

[0039] Obtain the index number of each physical block in the storage medium;

[0040] The metadata of each physical block is read sequentially according to the index number;

[0041] The latest system block is determined in the physical block based on the metadata;

[0042] The latest system page is found in the latest system block using a binary search method;

[0043] The final checkpoint is determined based on the latest system page.

[0044] As described above, the physical blocks are first traversed by index number to avoid the efficiency loss caused by random scanning. Physical blocks are then filtered based on metadata, using both block type and allocation sequence number to filter out system blocks, ensuring the integrity of system status data. A binary search method is used to quickly locate the latest system page within each system block, and an ordered retrieval mechanism replaces full disk traversal, reducing block scan time and thus improving the efficiency of mapping table reconstruction. Finally, the last checkpoint is extracted based on the latest system page, providing a reliable baseline timestamp for subsequent mapping table recovery.

[0045] Furthermore, the metadata also includes block type and allocation sequence number;

[0046] Determining the latest system block in the physical block based on the metadata includes:

[0047] Locate the physical block whose block type is system identifier to obtain the system block;

[0048] The allocation sequence numbers of the system blocks are compared, and the system block with the largest allocation sequence number is determined as the latest system block.

[0049] As described above, by using the system identifier as the block type as the filtering condition, dedicated storage units belonging to system information are filtered out from physical blocks, effectively eliminating interference from data blocks and mapping blocks and narrowing the search range. Based on this, by comparing the allocation sequence numbers carried by the system blocks, a version judgment criterion based on the write order is established to ensure that the latest system blocks are obtained, avoiding the recovery of invalid data in older system blocks and guaranteeing the accuracy of data recovery.

[0050] Furthermore, the final checkpoint stores multiple array structures with the index number of each physical block as the index value;

[0051] Also includes:

[0052] Each time the physical block is allocated, the allocation sequence number of the physical block is stored in an array structure with the index number of the physical block as the index value.

[0053] As described above, directly mapping the allocation sequence number to the physical block index number through an array structure can effectively reduce the complexity of querying block allocation records and avoid the performance overhead of traditional linked lists or traversal methods.

[0054] Furthermore, the target mapping table for determining the data recovery needs based on the last checkpoint includes:

[0055] Locate the physical block whose block type is a mapping identifier to obtain the mapping block;

[0056] Read the allocation sequence number of the mapping block from the last checkpoint;

[0057] Compare the allocation sequence numbers of the mapping blocks and determine the latest mapping block based on the comparison result;

[0058] Read the latest mapping table from the latest mapping block;

[0059] Scan the latest mapping table to determine the target mapping table for which data recovery is required.

[0060] As described above, the filtering mechanism based on the block type as the mapping identifier quickly filters out all physical blocks containing mapping information in the storage medium. By extracting the allocation sequence number of the mapping block from the last checkpoint, a version comparison mechanism based on the sequence number size is established to determine the latest mapping block. After obtaining the latest mapping block, its latest mapping table is read, and a scanning filtering mechanism is used to identify the specific target mapping table that needs to be recovered from the global mapping table. This preserves the integrity of all mapping data while achieving precise control over the recovery scope for fault scenarios.

[0061] Furthermore, sequentially reading the metadata of each data block in the storage medium according to the last checkpoint includes:

[0062] Locate the physical block whose block type is data identifier to obtain the data block;

[0063] Read the allocation sequence number of the data block from the last checkpoint;

[0064] The data blocks are arranged in order from the largest to the smallest allocation sequence number to obtain the recovered data block sequence;

[0065] The metadata of the data blocks is read sequentially based on the order of the recovered data block sequence.

[0066] As described above, by filtering data blocks whose block type is "data identifier," it is ensured that only valid data carriers are processed, avoiding interference from invalid blocks in the recovery process. The allocation sequence numbers of all allocated data blocks are extracted from the last checkpoint. By arranging the data blocks in reverse order of their allocation sequence numbers (from newest to earliest written), a reverse-order recovery data block sequence is formed. Finally, metadata is read sequentially based on this sequence. This ensures the timeline continuity of data versions and reduces the random access operations required by traditional cross-validation through linear reading, thereby improving both recovery accuracy and efficiency.

[0067] Further, determining the target block in the data block that matches the target mapping table based on the logical address includes:

[0068] Compare whether the logical address is consistent with the target logical address that needs to be mapped and restored in the target mapping table. If they are consistent, then determine the data block containing the logical address as the target block.

[0069] As described above, comparing the logical address with the target logical address to be recovered in the target mapping table can filter out irrelevant data blocks, retaining only the target block related to the logical address. This mechanism avoids the redundant process of relying on sequence number cross-validation in traditional methods, and directly locks the physical block to be recovered through address matching. This avoids the risk of misjudgment caused by sequence number conflicts and reduces the range of data block traversal.

[0070] Further, constructing the logical address data writing linked list based on the historical physical address of the target block includes:

[0071] Read the old physical address mapped to the target logical address from the last checkpoint;

[0072] The historical physical address of the target block is used as the next node pointed to by the target physical address of the target block, and the historical physical address is compared with the old physical address to see if they are consistent.

[0073] If so, the historical physical address is used as the termination node to obtain data and write it into the linked list;

[0074] Otherwise, return to the previous state and use the historical physical address of the target block as the next node pointed to by the target physical address of the target block.

[0075] As described above, by reading the old physical address from the last checkpoint as a reference and linking historical physical addresses as nodes in a linked list, consistency verification is performed in real time with the old physical address. If they match, the linked list construction is immediately terminated, forming a definite physical address chain; if they do not match, the historical address is continuously traced back to continue forming the physical address chain. This step-by-step verification mechanism based on physical addresses avoids redundant comparisons caused by full scans and avoids mapping misjudgments caused by SN flips or reuse, significantly improving recovery efficiency while ensuring recovery accuracy.

[0076] Further, reconstructing the target mapping table by writing the data into the linked list includes:

[0077] The data is written to the first physical address of the first node in the linked list and mapped to the target logical address to obtain the target mapping table.

[0078] As described above, the data writing linked list is a chain structure built based on historical physical addresses. Its nodes are arranged in the order of data writing, with the first node representing the latest valid data version. By utilizing the inherent time-series characteristics of linked lists, the system can quickly locate the latest physical address corresponding to the logical address, fundamentally avoiding version misjudgment problems that may be caused by SN conflicts, and avoiding the redundant operations of traversing multiple data blocks or repeatedly verifying SN information in traditional solutions.

[0079] Furthermore, before mapping the physical address of the first node in the linked list to the target logical address to obtain the target mapping table, the process further includes:

[0080] The data is written to the first target block located at the first physical address in the linked list;

[0081] Read the allocation sequence number of the first target block from the last checkpoint;

[0082] The forward scan range is determined based on the allocation sequence number of the first target block and the number of flushed cache blocks;

[0083] Scan all data blocks whose allocation sequence numbers are within the forward scan range to determine whether there is a historical physical address within the forward scan range that is the same as the first physical address;

[0084] If so, then the historical physical address within the forward scan range is determined to be a valid data block of the first physical address, and the actual physical address of the valid data block is mapped to the target logical address to obtain a target mapping table;

[0085] Otherwise, the data is written to the first physical address of the first node in the linked list and mapped to the target logical address to obtain the target mapping table.

[0086] As described above, a forward scan is used to verify the validity of the first node in the linked list where data is written. In some scenarios, there may be two physical addresses corresponding to the same logical address. One physical address was written earlier but its block allocation sequence number is later, while the other physical address was written later but its block allocation sequence number is earlier. In these scenarios, since the metadata of data blocks is read according to the allocation sequence number, the physical address with the later write sequence might not be read, leading to an older data version being mistakenly identified as the latest. Therefore, the forward scan range is determined based on the correlation between the allocation sequence number and the number of cached blocks. A rescan of the physical block region where newly written data may exist ensures that the finally selected physical address is indeed the latest valid version corresponding to the logical address, thereby improving the accuracy of the mapping table recovery.

[0087] Another embodiment of the present invention provides a storage device including a storage chip and a control chip, wherein the storage chip stores a computer program, and when the computer program is executed by the control chip, it implements the various steps in the above-described mapping table reconstruction method.

[0088] As described above, the beneficial effects of this invention are as follows: determining the last checkpoint enables the location of the latest valid system status information in the storage medium, reducing redundant scanning range; determining the target mapping table based on the last checkpoint directly locks the mapping relationship that needs to be restored; sequentially reading data block metadata according to the last checkpoint reduces redundant comparisons caused by cross-validation, improving the efficiency of mapping table reconstruction. By matching target blocks with logical addresses, data blocks related to the target mapping table are accurately filtered, irrelevant data interference is eliminated, local scanning is achieved, and the efficiency of mapping table reconstruction is improved; furthermore, a data writing linked list is constructed based on historical physical addresses to restore the update link of different physical addresses corresponding to a logical address. The latest valid data version is tracked through the linked list structure, eliminating the single dependence on the SN counter and avoiding mapping misjudgments caused by SN flipping or reuse, ensuring the accuracy of mapping table reconstruction; finally, the target mapping table is reconstructed according to the data writing linked list, ensuring the timeliness and accuracy of the mapping relationship.

[0089] The mapping table reconstruction method and storage device described above are applicable to scenarios requiring rapid data recovery. Specifically, the actual location (physical address, PBA) of data on the storage medium is a specific page or block on the flash memory chip, while the logical location (logical address, LBA) seen by the operating system or file system is the logical block address in the read / write request issued by the file system. Due to the characteristics of flash memory, the physical block address corresponding to the logical block address changes dynamically. Therefore, the storage medium needs to maintain a mapping table (L2P table) from logical address to physical address, recording the PBA currently corresponding to each LBA. When the system suddenly loses power or the SSD fails, this mapping table may be lost or corrupted. At this time, the data itself is usually still stored in the flash memory, but the file system cannot find the data and considers the data lost. Therefore, the core task of data recovery is to rebuild the L2P mapping table and re-establish the correspondence between LBA and PBA, thereby allowing the file system to recover the data.

[0090] The mapping table reconstruction method and storage device provided by this invention can improve the reconstruction efficiency of mapping tables while ensuring accurate reconstruction. The following detailed embodiments illustrate this:

[0091] Please refer to Figures 1 to 6 Embodiment 1 of the present invention is as follows:

[0092] A mapping table reconstruction method, specifically including:

[0093] S1. Determine the last checkpoint in the storage medium.

[0094] The last checkpoint stores multiple array structures indexed by the index number of each physical block. Each time a physical block is allocated, its allocation sequence number is stored in an array structure indexed by the physical block's index number. It's important to note that a checkpoint is a periodically saved snapshot of metadata in the storage medium, recording the current FTL (Flash Translation Layer) mapping table. When the storage medium experiences a sudden power outage or crash, the last checkpoint is used to restore the operational state before the power outage.

[0095] In a specific application scenario, the firmware defines the following array structure: DWORD g_blockAllocSN[BLOCK_NUM]. The number of the above array structure is the total number of physical blocks. For example, if the storage medium contains 729 physical blocks, the number of array structures is 729. The firmware maintains the allocation sequence number (hereinafter referred to as SN) of the physical blocks. Each time any physical block is allocated, the SN is incremented and assigned to the above array structure. The index value BLOCK_NUM is the index number of the allocated physical block (hereinafter referred to as ID). Based on this, if the SN allocated to the physical block with ID 1 is N+1, then the array structure g_blockAllocSN[1] in the firmware is N+1.

[0096] Specifically, step S1 includes:

[0097] S11. Obtain the index number of each physical block in the storage medium.

[0098] S12. Read the metadata of each physical block sequentially according to the index number.

[0099] In some embodiments, the metadata of each page in the physical block is read sequentially in ascending order of the physical block index number BLOCK_NUM.

[0100] S13. Determine the latest system block in the physical blocks based on the metadata. The metadata includes the block type and allocation sequence number.

[0101] Specifically, step S13 includes:

[0102] S131. Locate the physical block whose block type is system identifier to obtain the system block.

[0103] S132. Compare the allocation sequence numbers of the system blocks and determine the system block with the largest allocation sequence number as the latest system block.

[0104] It should be noted that physical blocks include bootblk (card activation block), sysblk (system block), L2Pblk (mapping block), and datablk (data block). Bootblk stores card activation information, sysblk stores system information, L2Pblk stores mapping information, and datablk stores data information. Specifically, the type of physical block and the order in which physical blocks are allocated and used are determined by reading the metadata within the physical blocks. The information of the final checkpoint is stored in the sysblk, and a maximum of two sysblks can exist in the firmware at any given time.

[0105] S14. Use a binary search method to find the latest system page in the latest system block.

[0106] In some embodiments, the system page with the largest page number that can correctly read back data in the latest system block is the latest system page. For example, in the latest system block, the system page with page number 200 (page200) can be correctly read back data by binary search, but the system page with page number 201 (page201) cannot be correctly read back data. Therefore, page200 is the latest system page found in the latest system block.

[0107] S15. Determine the final checkpoint based on the latest system page. Specifically, the data stored in the latest system page is the final checkpoint.

[0108] S2. Determine the target mapping table that needs to be recovered based on the last checkpoint.

[0109] Specifically, step S2 includes:

[0110] S21. Locate the physical block whose block type is mapping identifier to obtain the mapping block.

[0111] S22. Read the allocation sequence number of the mapping block from the last checkpoint.

[0112] S23. Compare the size of the allocation sequence number of the mapping block and determine the latest mapping block based on the comparison result.

[0113] Specifically, if the allocation sequence number is incremented according to the allocation order, then the allocation sequence number of the latest mapped block is the largest.

[0114] S24. Read the latest mapping table from the latest mapping block.

[0115] The mapping page with the largest page number that can be correctly read back from the latest mapping block is the latest mapping page, and the data stored in the latest mapping page is the latest mapping table.

[0116] S25. Scan the latest mapping table to determine the target mapping table for which data recovery is required.

[0117] It should be noted that the target mapping tables described in this application are all L2P (Logical-to-Physical) mapping tables.

[0118] S3. Read the metadata of each data block in the storage medium in sequence according to the last checkpoint. The metadata includes the logical address of the currently written data and the historical physical address corresponding to the logical address when it was written last time.

[0119] Specifically, when each piece of data to be written is written to a data block, the historical physical address corresponding to the logical address of the data to be written at the time of the previous write is written into the data block to obtain metadata. Metadata includes the logical address (LAA) of the data being written, the historical physical address corresponding to the logical address at the time of the previous write (Pre_FAA), the block type, and the block allocation sequence number. The historical physical address (Pre_FAA) includes the physical block (Pre_block) and physical page (Pre_page) where the logical address was located at the time of the previous write.

[0120] Specifically, step S3 includes:

[0121] S31. Locate the physical block whose block type is data identifier to obtain the data block.

[0122] S32. Read the allocation sequence number of the data block from the last checkpoint.

[0123] S33. Arrange the data blocks in order from the largest to the smallest allocation sequence number to obtain the recovered data block sequence.

[0124] S34. Read the metadata of the data blocks sequentially based on the order of the recovered data block sequence.

[0125] In a specific application scenario, the index numbers of the data blocks are 34, 25, 56, and 321, respectively. The array structure stored in the final checkpoint includes: g_blockAllocSN

[34] =70, g_blockAllocSN

[25] =69, g_blockAllocSN

[56] =68, and g_blockAllocSN

[321] =67. Therefore, the recovered data block sequence obtained by arranging the above four data blocks is: block_34, block_25, block_56, and block_321. Figure 2 As shown, without considering SN flipping, the order of recovering the data block sequence is from the newly allocated data block to the old allocated data block.

[0126] S4. Determine the target block in the data block that matches the target mapping table based on the logical address.

[0127] Specifically, step S4 includes:

[0128] S41. Compare whether the logical address is consistent with the target logical address that needs to be mapped and restored in the target mapping table. If so, determine that the data block containing the logical address is the target block.

[0129] In some embodiments, as shown in Table 1, the mapping storage structure of the target mapping table includes block-level mapping (BLKL2P) and page-level mapping (PAGEL2P). If the mapping storage structure for data recovery is page-level mapping (PAGEL2P), then in step S34, it is necessary to scan the metadata of each data page in the data block, compare the logical address of each data page in the data block with the target logical address for mapping recovery in the target mapping table. If they are consistent, then the target page (T_page) containing the logical address is determined in the data block (datablk), and the physical page (Pre_page) where the logical address of T_page was last written is taken as the next node pointed to by the target physical address of T_page. The Pre_page is compared with the old physical page (Old_page) of the last checkpoint. If they are consistent, the Pre_page is used as the terminating node to obtain data and write it into the linked list to realize PAGEL2P recovery. If the mapped storage structure for which data recovery is required is block-level mapping (BLKL2P), then PAGEL2P data recovery needs to be performed first. At the same time, the target block (T_blk) where each T_page is located and the physical page (Pre_block) where each Pre_page is located are determined. The mapping pointer of T_blk is pointed to the PAGEL2P corresponding to its T_page, and the mapping pointer of Pre_block is pointed to the PAGEL2P corresponding to its Pre_page, so as to realize BLKL2P recovery.

[0130] Table 1 Target Mapping Table

[0131]

[0132] Specifically, step S34 involves sequentially scanning each data page of the data block to read the metadata of each data page, and then determining whether it is a target page based on the metadata of each data page. During the scanning process, once a target page containing a logical address is identified, the scanning of the next data page in the data block is stopped. At this point, the historical physical address recorded by the target page can be directly identified as the target page, and so on, all target pages in the data block can be identified without scanning and comparing every data page in the data block.

[0133] S5. Construct logical address data based on the historical physical address of the target block and write it into the linked list.

[0134] Specifically, step S5 includes:

[0135] S51. Read the old physical address mapped to the logical address from the last checkpoint.

[0136] Specifically, the old physical address mapped to the logical address recorded in the last checkpoint is the physical address of the last time logical address data was written, as recorded in the last checkpoint.

[0137] S52. Use the historical physical address of the target block as the next node pointed to by the target physical address of the target block, and compare whether the historical physical address is consistent with the old physical address.

[0138] The target physical address of the target block refers to the actual physical address of the target block on the storage medium.

[0139] S53. If so, the historical physical address is used as the terminating node to obtain the data and write it into the linked list.

[0140] S54. Otherwise, return to the previous step and use the historical physical address of the target block as the next node pointed to by the target physical address of the target block.

[0141] S6. Reconstruct the target mapping table by writing the data into the linked list.

[0142] Specifically, step S6 includes:

[0143] S61. The data is written to the first physical address of the first node in the linked list and mapped to the target logical address to obtain the target mapping table.

[0144] In a specific application scenario, if the target logical address that needs to be mapped and restored in the current target mapping table is LAA10, and the data block in the storage medium containing LAA10-related data is as follows: Figure 3 As shown. Here, Data area represents the region where the data block is used to store data, LAA represents the logical address of the data block, Pre-Phy block represents the physical block in the historical physical address, Pre-Phy page represents the physical page in the historical physical address, block type represents the block type, SN represents the allocation sequence number, and oxff indicates that the data is empty. The final checkpoint records the mapping relationship of data blocks with allocation sequence numbers preceding data block1. Based on... Figure 3 Data obtained from the storage medium is written into a linked list, such as... Figure 4 As shown, the data is written to the linked list specifically at physical address 0.<block1,page1000> Pointing to physical address 1<block1,page2> Physical address 1<block1,page2> Pointing to physical address 2<block1,page1> Physical address 2<block1,page1> Pointing to physical address 3<block0,page1000> Among them, physical address 3<block0,page1000> This is the old physical address mapped to the target logical address in the last checkpoint.

[0145] Prior to step S61, the method further includes:

[0146] S601. Determine the first target block where the first physical address of the data is located in the linked list.

[0147] S602. Read the allocation sequence number of the first target block from the last checkpoint.

[0148] S603. Determine the forward scan range based on the allocation sequence number of the first target block and the number of flushed cache blocks.

[0149] S604. Scan all data blocks whose allocation sequence number is within the forward scan range to determine whether there is a historical physical address with the same first physical address within the forward scan range.

[0150] S605. If so, then determine the valid data blocks whose historical physical addresses are the first physical addresses within the forward scan range, and map the actual physical addresses of the valid data blocks to the target logical addresses to obtain the target mapping table.

[0151] S606. Otherwise, the data is written to the first physical address of the first node in the linked list and mapped to the target logical address to obtain the target mapping table.

[0152] In a specific application scenario, such as Figure 5As shown, the storage medium includes four data blocks: blockA, blockB, blockC, and blockD. Each data block includes data pages p1-p63. The allocation sequence number of blockA is N+1, the allocation sequence number of blockB is N+2, the allocation sequence number of blockC is N+3, and the allocation sequence number of blockD is N+4. Therefore, based on step S3 above, the recovered data block sequence is blockA->blockB->blockC->blockD. The write timing of the target logical address LAA10 in the storage medium is sequentially the same as that of physical address 1.<blockB,page1> Physical address 2<blockA,page37> Physical address 3<blockA,page53> Physical address 4<blockB,page17> Physical address 5<blockC,page28> Physical address 6<blockD,page9> Physical address 7<blockC,page60> According to this write timing, the historical physical address of physical address 7 is physical address 6, the historical physical address of physical address 6 is physical address 5, and so on. Among them, physical address 1 is the physical address where LAA10 was initially written; physical address 3 is the old physical address mapped to LAA10 determined based on the last checkpoint; physical address 6 is the physical address mapped to the first LAA10 found during the forward scan based on the data block allocation sequence number; physical address 7...<blockC,page60> The latest physical address written to LAA10, which is the target mapping that ultimately needs to be restored.

[0153] In the specific application scenario described above, the data obtained from steps S4-S5 is written to the linked list at physical address 6.<blockD,page10> -Physical address 5<blockC,page28> -Physical address 4<blockB,page17> -Physical address 3<blockA,page53> -Physical address 2<blockA,page37> -Physical address 1<blockB,page1> At this point, the first physical address where data is written to the linked list is physical address 6. Based on the allocation sequence number SN+4 and the number of cache blocks flushed (1), the forward scan range is determined to be SN+3. Therefore, each data page in block C is scanned, and at this time, physical address 7...<blockC,page60> The recorded historical physical address is consistent with physical address 6, therefore physical address 7 is...<blockC,page60> The target mapping is obtained by mapping to the target logical address LAA10. This process is repeated to restore the mapping of all target logical addresses, resulting in the target mapping table.

[0154] In an optional implementation, in step 3, the metadata of the data blocks can be read sequentially in reverse order of the recovered data block sequence. Without considering SN flipping, the reverse order of the recovered data block sequence is from the old allocated data block to the newly allocated data block. At this time, there is no need to establish a data write linked list; the physical address of the data page can be determined to be mapped to the target logical address using the following method. For example... Figure 6 As shown, the method includes: Step a, scanning the next data block. Step b, determining whether the current data block is empty; if so, exiting the scan; otherwise, proceeding to step c. Step c, scanning the current data page of the current data block. Step d, determining whether the current data page is marked as skipped; if so, proceeding to step e; otherwise, proceeding to step f. Step e, scanning the next data page of the current data block and proceeding to step g. Step f, obtaining the historical physical address of the current data page and comparing whether the allocation time of the historical physical address is later than the allocation time of the current data page; if so, proceeding to step h; otherwise, proceeding to step i. Step g, determining whether each data page of the current data block has been scanned completely; if so, scanning the next data block; otherwise, proceeding to step c. Step h, mapping the physical address of the data page to the target logical address to restore the target mapping table, and proceeding to step e. Step i, marking the data page corresponding to the historical physical address as skipped. Based on this, it can be seen that the mapping table reconstruction method of this application can support the out-of-order recovery mechanism of the allocation sequence number.

[0155] Please refer to Figure 7 Embodiment two of the present invention is as follows:

[0156] A storage device 100 includes a storage chip 101 and a control chip 102. The storage chip 101 stores a computer program, which, when executed by the control chip 102, implements the various steps in the mapping table reconstruction method of Embodiment 1 described above.

[0157] In summary, this invention provides a mapping table reconstruction method and storage device. Through a combination of the last checkpoint and a linked list of historical physical addresses, the mapping table recovery process is simplified from full-disk scanning and cross-validation to partial scanning and linked list backtracking without relying on easily flipped allocation sequence numbers. First, a binary search method is used to quickly locate the last checkpoint. Then, using the allocation sequence number stored in the last checkpoint, the metadata of the data blocks is read in reverse order. Only target blocks with matching logical addresses are written to a linked list layer by layer according to their historical physical addresses, with the first node representing the latest version. This, combined with forward scanning, eliminates misjudgments caused by misaligned allocation and write sequences, thereby reducing the scanning range from the entire disk to a minimum. Version judgment is transformed from easily conflicting SN comparison to linked backtracking based on physical addresses. This significantly reduces redundant I / O, improves reconstruction speed, and completely avoids mapping errors caused by SN flips or duplications, ensuring that the recovery result is completely consistent with the latest valid data, thus balancing efficiency, accuracy, and reliability.

[0158] In the embodiments provided in this application, it should be understood that the disclosed methods, apparatus, computer-readable storage media, and storage devices can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative. For instance, the division of modules is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple components or modules may be combined or integrated into another device, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection of devices, components, or modules may be electrical, mechanical, or other forms.

[0159] The components described as separate parts may or may not be physically separate. The components shown as components may or may not be physical modules; that is, they may be located in one place or distributed across multiple network modules. Some or all of the components can be selected to achieve the purpose of this embodiment according to actual needs.

[0160] Furthermore, the functional modules in the various embodiments of the present invention can be integrated into one processing module, or each component can exist physically separately, or two or more modules can be integrated into one module. The integrated modules described above can be implemented in hardware or as software functional modules.

[0161] If the integrated module is implemented as a software functional module and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0162] It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that the present invention is not limited to the described order of actions, because according to the present invention, some steps can be performed in other orders or simultaneously. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are preferred embodiments, and the actions and modules involved are not necessarily essential to the present invention.

[0163] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments.

[0164] The above description is merely an embodiment of the present invention and does not limit the patent scope of the present invention. Any equivalent modifications made based on the content of the present invention specification and drawings, or direct or indirect applications in related technical fields, are similarly included within the patent protection scope of the present invention.

Claims

1. A mapping table reconstruction method characterized by, The method comprises the following steps: determining a last checkpoint in a storage medium; determining a target mapping table requiring data recovery based on the last checkpoint; reading metadata of each data block in the storage medium in sequence according to the last checkpoint, wherein the metadata comprises a logical address of currently written data and a historical physical address corresponding to the logical address at a previous writing time; comparing the logical address with a target logical address requiring mapping recovery in the target mapping table, and if they are consistent, determining that a data block containing the logical address is a target block; reading an old physical address mapped to the target logical address from the last checkpoint; taking the historical physical address of the target block as a next node pointed to by a target physical address of the target block, and comparing the historical physical address with the old physical address; if they are consistent, taking the historical physical address as a terminal node to obtain a data writing chain table; otherwise, returning to take the historical physical address of the target block as the next node pointed to by the target physical address of the target block; mapping a first physical address of a first node in the data writing chain table to the target logical address to obtain a target mapping table.

2. The mapping table reconstruction method of claim 1, wherein, The method further comprises the following steps: when writing data into a data block, writing a historical physical address corresponding to a logical address of the data at a previous writing time into the data block to obtain the metadata.

3. The mapping table reconstruction method of claim 1, wherein, The step of determining the last checkpoint in the storage medium comprises the following steps: obtaining an index number of each physical block in the storage medium; reading metadata of each physical block in sequence according to the index number; determining a latest system block in the physical block according to the metadata; finding a latest system page in the latest system block by dichotomy; determining the last checkpoint based on the latest system page.

4. The mapping table reconstruction method of claim 3, wherein, The metadata further comprises a block type and an allocation sequence number; the step of determining the latest system block in the physical block according to the metadata comprises the following steps: finding a physical block with the block type being a system identifier to obtain a system block; comparing sizes of allocation sequence numbers of the system blocks, and determining a system block with the largest allocation sequence number as the latest system block.

5. The mapping table reconstruction method of claim 4, wherein, The last checkpoint stores a plurality of array structures with index numbers of respective physical blocks as index values; The method further comprises the following steps: when allocating the physical block, storing an allocation sequence number of the physical block in an array structure with the index number of the physical block as an index value.

6. The mapping table reconstruction method of claim 4, wherein, The step of determining the target mapping table requiring data recovery based on the last checkpoint comprises the following steps: finding a physical block with the block type being a mapping identifier to obtain a mapping block; reading an allocation sequence number of the mapping block from the last checkpoint; comparing sizes of allocation sequence numbers of the mapping blocks, and determining a latest mapping block according to a comparison result; reading a latest mapping table from the latest mapping block; scanning the latest mapping table to determine a target mapping table requiring data recovery.

7. The mapping table reconstruction method of claim 4, wherein, The step of reading the metadata of each data block in the storage medium in sequence according to the last checkpoint comprises the following steps: finding a physical block with the block type being a data identifier to obtain a data block; reading an allocation sequence number of the data block from the last checkpoint; arranging the data blocks in an order from the largest allocation sequence number to the smallest allocation sequence number to obtain a recovered data block sequence; reading the metadata of the data blocks in sequence based on the order of the recovered data block sequence.

8. The mapping table reconstruction method of claim 1, wherein, Before mapping the first physical address of the first node in the data write chain table to the target logical address to obtain a target mapping table, the method further comprises: determining a first target block in which the first physical address is located in the data write chain table; reading an allocation sequence number of the first target block from the last checkpoint; determining a forward scanning range based on the allocation sequence number of the first target block and the number of the flushed cache blocks; scanning all data blocks with allocation sequence numbers within the forward scanning range to determine whether there is a historical physical address identical to the first physical address within the forward scanning range; if yes, determining that the historical physical address within the forward scanning range is a valid data block of the first physical address, and mapping an actual physical address of the valid data block to the target logical address to obtain a target mapping table; otherwise, mapping the first physical address of the first node in the data write chain table to the target logical address to obtain a target mapping table.

9. A storage device comprising a storage chip and a control chip, the storage chip storing a computer program, characterized in that, The computer program, when executed by the control chip, implements each step in the mapping table reconstruction method according to any one of claims 1 to 8.

Citation Information

Patent Citations

  • Method and equipment for eliminating repeated data writing of pre-writing log in solid-state disk

    CN112764685A

  • Mapping table reconstruction method and data storage device

    CN115563026A