Data recovery method and flash memory controller thereof
By identifying and copying potentially corrupted page data to temporary blocks in the flash memory controller and optimizing the mapping table loading, the problem of low data recovery efficiency caused by asynchronous power failures is solved, achieving more efficient data recovery.
Patent Information
- Application Number
- CN202610731079.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Priority Date
- 2025-05-27
- Filing Date
- 2026-05-26
- Publication Date
- 2026-11-27
AI Technical Summary
Data inconsistency and corruption caused by asynchronous power failures in flash memory, especially during unmapping, result in low data recovery efficiency in existing technologies, which is particularly severe when using RAID mechanisms.
By identifying potentially corrupted pages, their data is copied to a temporary block, and a mapping table is created in RAM. The data is then copied back to the source block. At the same time, the loading method of the mapping table is optimized to reduce the frequent unloading and loading of RAM, thereby improving data recovery efficiency.
It improves the efficiency of the data recovery process, reduces the frequent use of RAM space, and enhances the overall efficiency of data recovery, especially in RAID groups, significantly shortening processing time.
Smart Images

Figure CN123178165A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to flash memory, and more particularly to a flash memory data recovery method and a flash memory controller thereof. Background Technology
[0002] Asynchronous power loss (APL), also known as sudden power-off (SPO), can cause significant problems for flash memory, especially during asynchronous operations such as data unmapping. Unmapping is the process of breaking the mapping between logical and physical addresses. If a power failure occurs during this process (e.g., a USB hard drive being suddenly unplugged), the system often remains in an inconsistent data mapping state. This can result in unused data still being marked as valid, or conversely, data becoming unusable due to incomplete updates, leading to data loss.
[0003] When write operations are detected to be affected by asynchronous power outages, a data recovery operation must be performed after power is restored to rebuild the data in the flash memory, ensuring its integrity and minimizing damage. The source block of the flash memory that may contain corrupted pages needs to be identified. The potentially corrupted page data in this source block is copied to a new block in the flash memory as a temporary workspace. During the data read process, error correction processing, such as error correction codes (ECC), is performed to correct errors caused by various reasons. After the data is corrected and restored, it is copied back to the source block, achieving the data recovery result.
[0004] Because the unmapping process can also be affected by asynchronous power outages, the physical-to-logical (P2L) and logical-to-physical (L2P) mapping tables may not perfectly match. For example, the P2L mapping table might show a value for a logical block address (LBA), but the corresponding physical block address (PBA) in the L2P mapping table might be invalid or altered. This is because the unmapping operation was just before the sudden power outage, marking the corresponding PBA in the L2P mapping table as invalid, or new data was written to the LBA, thus changing the corresponding PBA. Therefore, during the process of copying potentially corrupted block data to the temporary working area, the flash controller must check the validity of the page data for each potentially corrupted page using both the P2L and L2P mapping tables. Only pages with valid data are restored and copied to the temporary working area.
[0005] However, due to the capacity limitations of the random access memory (RAM) within the flash memory controller, the L2P mapping table required above must be unloaded from RAM to free up sufficient RAM space for copying page data to a temporary workspace. Then, when the validity of the next page data needs to be determined, the flash memory controller needs to load the L2P mapping table from flash memory back into RAM. This frequent loading of the L2P mapping table consumes a significant amount of time. This is especially true when the flash memory uses a redundant array of independent disks (RAID) mechanism; in the event of asynchronous power loss, the entire RAID group must be considered potentially damaged. The increased number of potentially damaged pages exacerbates the aforementioned time-consuming problem. Therefore, an innovative mechanism is needed to improve the processing efficiency of the data recovery process. Summary of the Invention
[0006] Therefore, one of the objectives of this invention is to provide a data recovery method and its flash memory controller to improve the above-mentioned problems.
[0007] According to an embodiment of the present invention, a data recovery method is disclosed, applied to a flash memory controller, the method comprising the following steps: (a) identifying a potentially corrupted first page in a first block of a flash memory; (b) copying or moving the data of the first page in the first block to a second page in a second block of the flash memory; (c) copying or moving the data of the second page to a third page in the first block of the flash memory; and (d) determining whether the data of the third page is valid based on an entity-to-logic mapping table and a logic-to-entity mapping table.
[0008] According to an embodiment of the present invention, a flash memory controller is disclosed, configured to perform the above-described method. The method is stored in the read-only memory of the flash memory controller in the form of code. The processing unit of the flash memory controller executes the code to complete the operations disclosed in this invention. Attached Figure Description
[0009] Figure 1 This is a block diagram of an electronic device according to an embodiment of the present invention.
[0010] Figure 2 This is a flowchart of a data recovery method according to an embodiment of the present invention.
[0011] Figure 3 This is a schematic diagram illustrating the execution process of a data recovery method according to an embodiment of the present invention. Detailed Implementation Exemplary embodiments of this application will now be described more fully with reference to the accompanying drawings. However, these exemplary embodiments can be implemented in many forms and should not be construed as limited to the examples set forth herein. Rather, these embodiments are provided to make this application more comprehensive and complete, and to fully convey the concept of the exemplary embodiments to those skilled in the art. The accompanying drawings are merely illustrative of this application and are not necessarily drawn to scale.
[0012] Please refer to Figure 1 This is a block diagram of an electronic device according to an embodiment of the present invention. The electronic device 10 includes a host device 110 and a storage device 100, and is suitable for integration into various electronic products, including but not limited to smartphones, tablet computers, wearable devices, personal computers (such as desktop and laptop computers), camera equipment (such as digital cameras or camcorders), game consoles, car navigation systems, printers, scanners, or server systems. Examples of the storage device 100 include, but are not limited to: portable storage devices (such as memory cards conforming to SD / MMC, CF, MS, XD, or UFS standards), solid-state drives (SSDs), and various embedded storage devices (such as embedded storage devices conforming to UFS or eMMC standards).
[0013] Storage device 100 includes a flash memory controller 130 and a flash memory 150. The flash memory controller 130 includes a host interface 131, a processing unit 134, a read-only memory (ROM) 135, a random access memory (RAM) 136, and a flash memory interface 139. A bus 132 serves as a communication link connecting the host interface 131, processing unit 134, ROM 135, RAM 136, and flash memory interface 139, for transmitting data, addresses, control signals, etc. Host device 110 communicates with flash memory controller 130 via host interface 131 according to a standard such as eMMC (embedded MultiMedia Card). Flash memory controller 130 communicates with flash memory 150 via flash memory interface 139. Processing unit 134 is responsible for executing code stored in ROM 135, receiving eMMC commands via host interface 131, and executing these commands according to the present invention. RAM 136 can be static random access memory (SRAM) or dynamic random access memory (DRAM) as internal storage space for flash memory controller 130.
[0014] Please refer to Figure 2 This is a flowchart of a data recovery method according to an embodiment of the present invention. Figure 3 This is a schematic diagram illustrating the execution process of this method. This method is... Figure 1 The flash memory controller 130 in the middle performs the operation in conjunction with Figure 3 The execution steps are explained below.
[0015] Step S11: Identify at least one potentially corrupted page in a block of the flash memory. Since there are usually more than one potentially corrupted page, the following description assumes multiple potentially corrupted pages. However, this invention can operate and function even when only one potentially corrupted page exists. When a power outage occurs, the data in a block can be affected in many ways. For example, pages currently being written to are the most vulnerable. NAND flash memory programming is performed page-by-page, with multiple word lines sharing the same set of physical circuitry. A sudden power outage will result in incomplete page writing, affecting not only the pages on the word line being written to but also adjacent word lines due to program disturbance, potentially corrupting the data on those word lines. Furthermore, when the flash memory uses a Redundant Array of Independent Disks (RAID) mechanism, the entire RAID group must be considered potentially corrupted during a sudden power outage. How to identify potentially corrupted pages can be handled using existing technology and will not be described in detail here.
[0016] For ease of description, the flash memory block that is identified as potentially corrupted is called the source block. For example... Figure 3For example, block #20 is the source block. Figure 3 In this context, multiple potentially corrupted pages 301 constitute a continuous range of pages, for example, from page #10 to page #7000.
[0017] Step S12: Copy or move the data of the plurality of potentially corrupted pages 301 in the source block to the random access memory. According to an embodiment of the present invention, regardless of the actual validity of the data of the plurality of potentially corrupted pages, the flash memory controller 130 copies or moves it to the RAM 136.
[0018] Step S13: Move the data from the multiple pages in the random access memory to multiple pages of a temporary block in the flash memory. The flash memory controller 130 identifies an available block in the flash memory 150 as a temporary block #T. The flash memory controller 130 moves the page data stored in RAM 136 in step S12 to multiple pages of the temporary block #T.
[0019] According to one embodiment of the present invention, when the flash memory controller 130 reads data from the plurality of potentially corrupted pages 301 in the source block, it can perform data recovery processing. The flash memory controller 130 can execute an error correction code mechanism, such as a low-density parity check code, to detect and correct erroneous data, restore the data, and then write it back to the temporary block #T.
[0020] It is important to note that after the data of the multiple pages stored in RAM 136 is moved to the temporary block #T, all the data in those pages in RAM 136 can be unloaded, thereby freeing up the used RAM space. This is crucial because the capacity of RAM 136 in the flash controller 130 is limited, for example, only 1MB. The RAM space used for completed tasks must be released to ensure sufficient space for subsequent operations by the flash controller 130. Understandably, to achieve the same effect, releasing only a portion of the multiple pages in RAM 136 is also feasible.
[0021] Through steps S12-S13, the flash memory controller 130 copies or moves potentially corrupted page data from the source block to temporary block #T. When the number of potentially corrupted pages is too large, these potentially corrupted pages can be divided into batches, and steps S12-S13 can be performed on each batch of potentially corrupted pages separately, ultimately achieving the goal of copying or moving all potentially corrupted page data to temporary block #T.
[0022] Step S14: Copy or move the data of the multiple pages 302 in the temporary block #T to the random access memory 136.
[0023] Step S15: Move the data from the multiple pages in the random access memory to multiple pages 303 of the source block, where these multiple pages 303 are different from the potentially corrupted page 301 in step S11. Since multiple pages 301 are potentially corrupted, the data from multiple pages 302 in temporary block #T will be copied or moved to other available pages in source block #20, such as pages #7001 to #13991 after multiple pages 301.
[0024] Through steps S14-S15, the flash memory controller 130 copies or moves the data of multiple pages 302 of temporary block #T to multiple pages 303 of source block #20. When the number of pages 302 of temporary block #T is too large, these pages can be processed in batches, and steps S14-S15 can be performed on each batch of pages separately, ultimately achieving the goal of copying or moving all the data of multiple pages 302 of temporary block #T back to source block #20.
[0025] Step S16: Establish an entity-to-logical mapping table and load the logical-to-entity mapping table from flash memory into random access memory. Based on the metadata of each page in block #20, which records the logical block address and timestamp corresponding to that page, a P2L mapping table associated with the source block #20 can be established and stored in RAM 136. An L2P mapping table is also loaded from flash memory 150 into RAM 136. Since the complete L2P mapping table is quite large, the flash memory controller 130 will only load partial, relevant L2P mapping tables into RAM 136. Note that the L2P mapping table may be corrupted due to asynchronous power failure. Existing asynchronous power failure recovery mechanisms include rebuilding the L2P mapping table; details are not described here. In this step, the L2P mapping table is the restored L2P mapping table.
[0026] For easier explanation, please refer to Figure 3For example, multiple potentially corrupted pages 301 are detected in source block #20, for example, from page #10 to page #7000. After steps S12-S13, pages #10 to #7000 in source block #20 are copied or moved to temporary block #T, for example, from page #20 to page #7010, where page #PT in temporary block #T corresponds to page #PS in source block #20. Then, after steps S14-S15, pages #20 to #7010 in temporary block #T are copied or moved back to source block #20, for example, from page #7001 to page #13991, where page #PT in temporary block #T corresponds to page #PS' in source block #20. The entity block address of page #PS' in source block #20 is 20:PS' (meaning block address: page address). Based on the metadata of each page in block #20, a P2L mapping table 311 associated with the source block #20 can be established.
[0027] Step S17: Based on the P2L mapping table and L2P mapping table, determine whether the data in each page of multiple pages 303 of source block #20 is valid. Please refer to... Figure 3 Taking page #PS' from multiple pages 303 of source block #20 as an example, based on the page address of page #PS', a corresponding logical block address 351 with a value of 30000038 can be retrieved from the P2L mapping table. Please note that Figure 3 The logical block address value is an example for ease of explanation; the actual logical block address value can be as long as, for example, 28 bits. Based on this logical block address 351, a corresponding entity block address 352 can be retrieved from the L2P mapping table 312. Figure 3 For example, based on logical block address 351, whose value is 30000038, the corresponding entity block address 352 retrieved from the L2P mapping table has a value of 20:PS, which points to source block #20. When the value of entity block address 352 points to source block #20, entity block address 352 is determined to be valid; when entity block address 352 is valid, then page #PS' and its stored data are further determined to be valid.
[0028] Because a sudden power outage may occur during the unmapping process, a mismatch may arise between the contents of the P2L mapping table and the L2P mapping table. Therefore, as in the previous example, the flash memory controller 130 must use the L2P mapping table to check whether the physical block address 352 corresponding to the logical block address 351 is valid. When the physical block address 352 points to the same physical block as page #PS', the physical block address 352 is determined to be valid. On the other hand, if the physical block address 352 is 0, it indicates that the logical block address 351 has been unmapped and marked as invalid, or if the block pointed to by the physical block address 352 is not the source block #20, then page #PS' and its stored data are determined to be invalid. Please refer to the example below. Figure 3 In the example of source block #20 page #10, according to step S13, the data of source block #20 page #10 is copied or moved to temporary block #T page #20, and further copied or moved to source block #20 page #7001. The logical block address obtained by searching the P2L mapping table with page #7001 is 30000031. The entity block address obtained by searching the L2P mapping table is 0, which is an invalid entity block address. This means that the logical block address 30000031 has been unmapped. Therefore, page #7001 is determined to be invalid.
[0029] Please note that the entire L2P mapping table in flash memory 150 is typically quite large, especially in high-capacity electronic devices. In step S16, the L2P mapping table loaded into RAM 136 refers to a subset of logical block addresses 351 contained within the entire L2P mapping table. More specifically, when it is necessary to check the validity of a first logical block address associated with page #P1, the flash memory controller 130 needs to load a first L2P sub-mapping table, which is a subset of the entire L2P mapping table containing the first logical block address. When processing another page #P2 and checking the validity of a second logical block address associated with page #P2, if the second logical block address is not within the range of the first L2P mapping table, the flash memory controller 130 needs to load a second L2P sub-mapping table, which is a subset of the entire L2P mapping table containing the second logical block address.
[0030] For example, the sizes of RAM 136, the P2L mapping table, and the L2P mapping table are 1M bits, 27K bits, and 16K bits, respectively. In the event of an asynchronous power failure, the 6912 pages covered by the RAID group used by the device are considered potentially corrupted. Each page is 4K bits in size, therefore the amount of data potentially corrupted is... Bit groups. Traditional techniques require loading the L2P mapping table and copying source block data to a temporary block in each iteration. Limited by RAM, the loaded L2P mapping table must be unloaded to allow sufficient RAM for data copying. In the next iteration, the RAM space occupied by the copied data is released before loading the required L2P mapping table for that round. Thus... Data and The limitation of only 1MB of RAM for L2P mapping tables to be used interactively leads to the need for traditional technologies to frequently unload and upload L2P mapping tables, reducing overall efficiency.
[0031] In contrast, this invention uses RAM space for the process of copying or moving source block data to a temporary block, and then copying or moving temporary block data back to the source block. After completion, this data is unloaded from RAM space. Therefore, RAM 136 has ample available space for the flash controller 130 to execute step S17 to determine the validity of the data. In this invention, the available space in RAM 136 in step S17 is sufficient to accommodate multiple L2P mapping tables, significantly reducing the frequent unloading and loading of L2P mapping tables, thus improving the operational efficiency of step S17.
[0032] According to the present invention, the restored data of the source block should be the same as the result obtained by conventional techniques, except that the operating efficiency is significantly improved. According to the present invention, the copying of the source block data to a temporary block is processed through an iterative loop, during which the RAM 136 space is dedicated to data copying without involving L2P mapping tables. Then, after releasing the RAM 136 space used for copying the data, another iterative loop is used to check the validity of each page. At this point, the RAM 136 has sufficient space to load the required multiple L2P mapping tables, thus significantly improving the efficiency of determining whether each page has been unmapped. In this way, the present invention effectively solves the problem caused by the limited RAM 136 space and significantly improves operating efficiency.
[0033] Embodiments of the present invention further include a flash memory controller 130 configured to execute the data recovery method described above. In practice, the method implementation code is stored in the ROM 135 of the flash memory controller 130. The processing unit 134 of the flash memory controller 130 executes this code to perform the data recovery method disclosed in this invention.
[0034] The above are merely specific embodiments of this application, but the scope of protection of this application is not limited thereto. Those skilled in the art, within the technical scope disclosed in this application, can easily conceive of variations or substitutions, all of which should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A data recovery method applied to a flash memory controller, characterized in that, The method includes the following steps: (a) Identify a potentially corrupted first page in a first block of a flash memory; (b) Copy or move the data of the first page in the first block to a second page in a second block of the flash memory; (c) Copying or moving the data of the second page to a third page of the first block in the flash memory; and (d) Determine whether the data on the third page is valid based on an entity-to-logical mapping table and a first logical-to-entity mapping table.
2. The data recovery method as described in claim 1, characterized in that, Step (b) includes: The data of the first page is copied or moved to a random access memory; and The data on the first page of the random access memory is moved to the second page.
3. The data recovery method as described in claim 2, characterized in that, Step (c) includes: Copy or move the data of the second page to the random access memory; and The data on the second page of the random access memory is moved to the third page.
4. The data recovery method as described in claim 1, characterized in that, The entity-to-logical mapping table is generated from the metadata corresponding to the data on the second page, and the first logical-to-entity mapping table is taken from the flash memory.
5. The data recovery method as described in claim 1, characterized in that, In step (d), based on the third page, a logical block address is obtained by retrieving the entity-to-logical mapping table; based on the logical block address, an entity block address is obtained by retrieving the first logical-to-entity mapping table; when the entity block address is valid, the data on the third page is determined to be valid.
6. The data recovery method as described in claim 5, characterized in that, When the entity block address points to the first block, the entity block address is determined to be valid.
7. The data recovery method as described in claim 1, characterized in that, The first logical-to-entity mapping table is a part of a second logical-to-entity mapping table stored in the flash memory.
8. The data recovery method as described in claim 1, characterized in that, In step (b), data recovery processing is performed on the data of the first page before copying or moving the data of the first page to the second page.
9. A flash memory controller for accessing a flash memory, characterized in that, The flash controller includes: A read-only memory used to store a piece of code; A random access memory; and A processing unit, configured to execute this code, performs the following steps: (a) Identify a potentially corrupted first page in a first block of the flash memory; (b) Copy or move the data of the first page in the first block to a second page in a second block of the flash memory; (c) Copying or moving the data of the second page to a third page of the first block in the flash memory; and (d) Determine whether the data on the third page is valid based on an entity-to-logical mapping table and a first logical-to-entity mapping table.
10. The flash memory controller as claimed in claim 9, characterized in that, Step (b) includes: Copy or move the data of the first page to the random access memory; and The data from the first page in the random access memory is moved to the second page.
11. The flash memory controller as claimed in claim 10, characterized in that, Step (c) includes: Copy or move the data of the second page to the random access memory; and The data on the second page of the random access memory is moved to the third page.
12. The flash memory controller as claimed in claim 9, characterized in that, The entity-to-logical mapping table is generated from the metadata corresponding to the data on the second page, and the first logical-to-entity mapping table is taken from the flash memory.
13. The flash memory controller as claimed in claim 9, characterized in that, In step (d), based on the third page, a logical block address is obtained by retrieving the entity-to-logical mapping table; based on the logical block address, an entity block address is obtained by retrieving the first logical-to-entity mapping table; when the entity block address is valid, the data on the third page is determined to be valid.
14. The flash memory controller as claimed in claim 13, characterized in that, When the entity block address points to the first block, the entity block address is determined to be valid.
15. The flash memory controller as claimed in claim 9, characterized in that, The first logical-to-entity mapping table is a part of a second logical-to-entity mapping table stored in the flash memory.
16. The flash memory controller as claimed in claim 9, characterized in that, In step (b), data recovery processing is performed on the data of the first page before copying or moving the data of the first page to the second page.
