A storage device and a control method thereof
By designing backup modules and reconstruction modules in storage devices, and utilizing specific storage blocks in flash chips to store and rebuild backup data, the problems of poor performance and data loss in existing storage devices during reconstruction are solved, achieving more efficient and Reliable storage and reconstruction process.
Patent Information
- Application Number
- CN202411506125.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-28
- Publication Date
- 2025-02-07
- Estimated Expiration
- 2044-10-28
AI Technical Summary
During the reconstruction process of existing storage devices, the amount of backup data is directly related to the long time, resulting in poor performance and may lead to data loss in the event of power failure.
A storage device is designed, including a backup module, a flash memory chip, a normal power-down reconstruction module and an abnormal power-down reconstruction module. By dividing table blocks, backup blocks and register blocks in the flash memory chip, address mapping information of host data, backup data and reconstruction identification data are stored. When the device receives a power-down command or abnormal power-down, it uses this information to quickly rebuild the backup data.
Improves the storage reliability and reconstruction efficiency of storage devices, reduces scanning area, avoids data loss, and improves performance.
Smart Images

Figure CN119025051B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of storage technology, and in particular to a storage device and a control method thereof. Background Art
[0002] Backup is the basis of disaster recovery. It refers to the process of copying all or part of the data set from the hard disk or array of the application host to other storage media to prevent data loss due to system operation errors or system failures. When a storage device fails and data is lost, the lost data can be restored by reconstruction. Among them, the reconstruction of the storage device is the process of copying all the data on the failed disk to the replacement disk based on the backup file when a disk fails. The reconstruction algorithm is one of the key algorithms of the storage device. During reconstruction, the more data that needs to be backed up, the longer the reconstruction time. For storage devices, the length of backup and reconstruction is directly related to the performance of the storage device. Summary of the invention
[0003] An object of the present invention is to provide a storage device and a control method thereof, which can improve the storage reliability of the storage device.
[0004] In order to solve the above technical problems, the present invention is achieved through the following technical solutions:
[0005] The present invention provides a storage device, comprising:
[0006] A backup module uses the copy data of the host data as backup data;
[0007] A flash memory chip, wherein some storage blocks in the flash memory chip are divided into a table block, a backup block and a register block, the backup block stores the backup data, the table block stores address mapping information of the host data and backup information of the backup data, and the register block stores reconstruction identification data;
[0008] a normal power-off reconstruction module, which scans the backup blocks according to the backup information and rebuilds the backup information when the storage device receives a power-off instruction from the host computer; and
[0009] An abnormal power failure reconstruction module is used to scan the backup block according to the reconstruction identification data and rebuild the backup information when the storage device loses power abnormally.
[0010] In one embodiment of the present invention, the backup information includes address mapping information of the host data, the physical address of the backup block, the physical address of the backup page and the type of the backup block, wherein the backup page is the storage page where the backup data is located, and the type of the backup block includes user data block and garbage collection block.
[0011] In an embodiment of the present invention, the reconstruction identification data includes a physical address of the backup block and a physical address of the backup page.
[0012] In one embodiment of the present invention, the reconstruction identification data includes a power-off flag, which is set to a first flag by default. When the storage device receives a power-off instruction, the power-off flag is set to a second flag. After the storage device is powered on again, the power-off flag is initialized to the first flag.
[0013] In one embodiment of the present invention, the reconstruction identification data includes a single reliable write flag, which defaults to a first flag. When the storage device receives a reliable write instruction from a host computer, the single reliable write flag is set to a second flag. After the single reliable write instruction is completed, the single reliable write flag is initialized to the first flag.
[0014] In one embodiment of the present invention, the storage device includes a cache chip. When the cache chip is enabled, if the single reliable write flag is set, the backup module copies the written host data as the backup data. When the cache chip is disabled, the backup module copies the written host data as the backup data.
[0015] In one embodiment of the present invention, before the storage device enters an idle state or before the storage device receives a power-off instruction, the latest data of the table block is stored in the cache chip, wherein the latest data of the table block includes address mapping information of the newly written host data and backup information of the newly written backup data.
[0016] In one embodiment of the present invention, the storage device includes a device identification register, which is electrically connected to the flash memory chip. Before the storage device receives a power-off instruction or before the storage device enters an idle state, the latest data of the register block is stored in the device identification register, wherein after power is restored, the parameter data of the device identification register is initialized and the parameter data is read from the register block.
[0017] In one embodiment of the present invention, a mapping relationship update flag is stored in the register block. In the reconstruction scanning process of the storage device, when the physical address of the host data in the address mapping table and in the backup information is consistent, or the host data and the backup data are the same, the mapping relationship update flag is set to the second flag, and the physical address of the host data in the address mapping table is updated to the physical address of the backup data, wherein the mapping relationship update flag defaults to the first flag.
[0018] The present invention provides a method for controlling a storage device, comprising the following steps:
[0019] When writing host data to the storage device, using the copy data of the host data as backup data;
[0020] Acquire backup information of the backup data, and store the backup information in a backup block of the storage device;
[0021] Acquire reconstruction identification data of the storage device, and store the reconstruction identification data in a register block of the storage device;
[0022] When the storage device receives a power-off instruction from the host computer, scanning the backup block according to the backup information and rebuilding the backup information; and
[0023] When the storage device loses power abnormally, the backup blocks are scanned according to the reconstruction identification data to reconstruct the backup information.
[0024] As described above, the present invention provides a storage device and a control method thereof, which can avoid resource occupation caused by backing up each host data when the storage device stores data, improve the storage efficiency and life of the storage device, and avoid data loss caused by not backing up data, thereby improving the storage accuracy and stability of the storage device. The storage device and the control method thereof provided by the present invention can greatly reduce the scanning area and improve the reconstruction efficiency of the storage device when the storage device loses power abnormally or normally, and the reconstruction data will not be lost. Therefore, the present invention takes into account the accuracy and efficiency of backup and reconstruction, and comprehensively improves the performance of the storage device.
[0025] Of course, any product implementing the present invention does not necessarily need to achieve all of the advantages described above at the same time. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for describing the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative work.
[0027] Figure 1 FIG. 4 is a schematic diagram of the structure of a storage device in an embodiment of the present invention.
[0028] Figure 2 FIG. 4 is a schematic diagram of the structure of a flash memory chip in an embodiment of the present invention.
[0029] Figure 3 Schematic diagram of the structure of a table block in one embodiment of the present invention.
[0030] Figure 4 Schematic diagram of the structure of a backup block in one embodiment of the present invention.
[0031] Figure 5 FIG. 4 is a schematic diagram of the structure of a register block in an embodiment of the present invention.
[0032] Figure 6 Schematic diagram of the storage structure of the cache write mode identifier CACHE_EN in one embodiment of the present invention.
[0033] Figure 7 The flowchart of the control method of the storage device in one embodiment of the present invention.
[0034] Figure 8 Flow chart of the backup information reconstruction process S3 in a normal power failure in one embodiment of the present invention.
[0035] Fig. 9 Flow chart of the backup information reconstruction process S4 in the event of abnormal power failure in one embodiment of the present invention.
[0036] Fig.10 FIG. 1 is a schematic diagram of the structure of the control firmware in one embodiment of the present invention.
[0037] In the figure: 100, storage device; 200, main controller; 210, processor; 220, control firmware; 221, backup module; 222, normal power-off reconstruction module; 223, abnormal power-off reconstruction module; 224, parameter update module; 230, device identification register; 300, cache chip; 400, flash memory chip; 410, flash memory plane; 420, storage block; 421, table block; 422, backup block; 423, register block; 4231, backup block information; 4232, backup page information; 4233, single reliable write flag; 4234, power-off flag; 430, storage page; CACHE_EN, cache write mode flag. DETAILED DESCRIPTION
[0038] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0039] See also Figure 1As shown, the storage device 100 provided by the present invention uses flash memory as a storage medium, specifically, uses NAND flash memory as a storage medium, such as SM flash card, CF card, Multi Media Card (MMC), Secure Digital Card (SD card), memory stick and micro hard disk, etc. The storage device 100 is electrically connected to the host computer to receive instructions and data from the host computer. When the host computer writes data to the storage device 100, the data required to be backed up by the host computer is backed up according to the instructions of the host computer. The present invention does not limit the type of data to be backed up. The host computer writes the host data into the storage device 100, and after the host data is written, the host data is backed up. Specifically, the host data is copied as backup data and stored in the flash memory chip 400. After normal power failure or abnormal power failure, the backup data and its related information are rebuilt according to the backup data and the backup information related to the backup data.
[0040] See also Figure 1 and Figure 2 As shown, in one embodiment of the present invention, the storage device 100 includes a main controller 200, a cache chip 300 and a flash memory chip 400. The main controller 200 is electrically connected to the cache chip 300 and the flash memory chip 400, and the cache chip 300 is electrically connected to the flash memory chip 400. The main controller 200 includes a processor 210 and a control firmware 220, and the processor 210 calls the control firmware 220 to implement the control method of the storage device 100 provided by the present invention. In the present invention, the flash memory chip 400 includes a plurality of flash memory planes 410 (planes), the flash memory planes 410 include a plurality of storage blocks 420, and the storage blocks 420 include a plurality of storage pages 430. The storage blocks 420 are physical blocks (blocks) of the flash memory chip 400, and the storage pages 430 are physical pages (pages) of the flash memory chip 400.
[0041] See also Figures 1 to 4As shown, in one embodiment of the present invention, host data and backup data can be written into the flash memory chip 400 in any mode of a single-layer storage unit SLC, a multi-layer storage unit MLC, a three-layer storage unit TLC, and a four-layer storage unit QLC. Among them, a single-layer storage unit can store, for example, 1-bit data, a multi-layer storage unit can store, for example, 2-bit data, a three-layer storage unit can store, for example, 3-bit data, and a four-layer storage unit can store, for example, 4-bit data. The data stored in the single-layer storage unit is stable data. If the multi-layer storage unit, the three-layer storage unit, and the four-layer storage unit are not fully stored, the data storage structure in the corresponding storage unit is unstable. Therefore, in some embodiments of the present invention, according to whether the cache chip 300 is enabled or not, after the backup data is written into the flash memory chip 400, the supplementary data can continue to be written to the backup block 422 until the backup block 422 reaches a stable state. The supplementary data is invalid data.
[0042] See also Figures 1 to 5 As shown, in one embodiment of the present invention, the storage block 420 includes a table block 421, a backup block 422 and a register block 423. The backup data of the host data is stored in the backup block 422. Specifically, in the process of backing up the host data, the host data is copied to obtain the backup data, and the backup data is stored in the backup block 422, and the backup information of the backup data is stored in the cache chip 300 or in the flash chip 400. When the storage device 100 loses power, the backup data can be retrieved from the backup block 422 to the storage block 420, and the backup information of the backup data can be restored, thereby completing the data reconstruction of the backup data. When the host data cannot be read out normally and cannot be restored, the host data can be restored according to the backup data. In this embodiment, the backup block 422 is any storage block 420 or a storage block 420 with a fixed number.
[0043] See also Figures 1 to 5As shown, in one embodiment of the present invention, in the backup process of host data, the backup information of the backup data is obtained, and the backup information is stored in the table block 421. The table block 421 is a preset storage block 420 for storing table information. The table block 421 includes multiple address pages and multiple backup pages, such as address pages d1~dn, such as backup pages d1~dm. Wherein m corresponds to the number of pages of the storage page 430 contained in a word line WL. The present invention does not limit the value of n. The backup page is used to store the backup information of the backup data, and the address page is used to store the multi-level address mapping table of the host data. In this embodiment, the backup information includes the address mapping information of the host data, the physical address of the backup block 422 and the physical address of the storage page 430 in the backup block 422, and the type of the storage block 420 where the backup data is located. The address mapping information of the host data refers to the mapping relationship between the logical address and the physical address of the host data. The physical address of the backup block 422 is the physical address of the storage block 420 where the current backup data is located. The physical address of the storage page 430 in the backup block 422 refers to the physical address of the storage page 430 where the current backup data is located. For example, a storage page 430 can store 16KB of data, and the space occupied by a mapping relationship is 4KB, then the addresses of the storage pages 430 of at most 4 mapping relationships are consistent. The type of the storage block 420 where the backup data is located is a user block or a garbage collection block. The user block is a storage block 420 that stores host data. The garbage collection block is a target block in the garbage collection process (Garbage Collection, GC). It should be noted here that the garbage collection process includes a source block and a target block, the source block is a user block to be transferred data, and the target block is a user block to receive the transferred data. In this embodiment, the space occupied by the backup information is the number of pages of the storage page 430 contained in a word line WL. For example, a word line WL includes 12 storage pages 430, the size of a storage page 430 is, for example, 16KB, and for example, the space occupied by a mapping relationship is 4KB, then 4×12 mapping relationships can be stored in the backup page.
[0044] See also Figure 1 , Figure 2 and Figure 5As shown, in one embodiment of the present invention, the main controller 200 includes a device identification register 230. In this embodiment, the width of the device identification register 230 is 128 bits wide. The storage information in the device identification register 230 includes information used by the e-MMC protocol device identification in the device identification stage. It should be noted that each individual flash memory chip 400 or input / output device has a unique identification number. And each type of storage device 100 has a unique identification number. In this implementation, the storage information in the device identification register 230 includes part of the backup information and the instruction flag. And it should be noted that the backup information and the instruction flag in the present invention only occupy part of the fields of the device identification register 230, and the present invention occupies the fields that are not defined in the protocol. In this embodiment, before power failure occurs, the data in the device identification register 230 is transferred to the register block 423. After power is restored, the storage data in the register block 423 is restored to the device identification register 230, so that the processor 210 executes the corresponding control process of the control firmware 220 according to the parameter data in the device identification register 230. In this embodiment, the register block 423 stores backup block information 4231, backup page information 4232, a single reliable write flag 4233 and a power-off flag 4234. Among them, the backup block information 4231 is the physical address of the storage block 420 storing the backup data. The backup page information 4232 stores the physical address of the storage page 430 of the backup data. The single reliable write flag 4233 is used to identify whether the host computer has issued a single reliable write instruction. The power-off flag 4234 is used to identify whether the current power-off process is normal. When the storage device 100 issues a reliable write instruction, the single reliable write flag 4233 is set, for example, to a high level potential 1. Specifically, after the host computer issues a power-off instruction, the power-off flag 4234 is set, for example, to a high level potential 1. Among them, after power is turned on again, the single reliable write flag 4233 and the power-off flag 4234 are cleared, where clearing is, for example, set to a low level potential 0. In this embodiment, the low level potential 0 state is the default initial state of the single reliable write flag 4233 and the power-off flag 4234 .
[0045] See also Figure 1 , Figure 2 and Figure 5As shown, in one embodiment of the present invention, the storage device 100 has a cache-on write mode and a cache-off write mode. In the cache-on write mode, the host data is stored in the cache chip 300. The cache chip 300 has a capacity threshold. When the written host data reaches the capacity threshold, the host data is transferred to the flash memory chip 400. For example, the capacity threshold is 32KB. In the case of writing 4KB host data, the 4KB host data is stored in the cache chip 300. When writing 38KB host data, when it reaches 32KB, the first 32KB host data is transferred to the flash memory chip 400, and the remaining 6KB host data is stored in the cache chip 300. In the cache-off write mode, the host data is directly written into the flash memory chip 400. In the present invention, the relevant table information of the host data is stored in the cache chip 300. According to the flushing condition set by the present invention, when the flushing condition is met, the host data and the relevant table information of the host data are transferred to the flash memory chip 400. In this embodiment, in the cache-off write mode, all host data are backed up. In the cache write mode, if the host computer does not issue a specific instruction, the host data may not be backed up. The specific instruction is, for example, a reliable write instruction. In this embodiment, a byte may be reserved in the register block 423 and the device identification register 230 for identifying the cache write mode. Figure 7 As shown, Bit7 to Bit1 are reserved positions, and Bit0 is used to store the cache write mode identifier CACHE_EN. When CACHE_EN is 0, the storage device 100 is in the cache closed write mode. When CACHE_EN is 1, the storage device 100 is in the cache open write mode. In this embodiment, the reserved field (cid rsv) status in the device identification register 230 can be used to confirm whether the current host computer has issued a single reliable write instruction.
[0046] See also Figure 1 and Figure 7 As shown, in one embodiment of the present invention, the control method of the storage device 100 provided by the present invention can be used to obtain backup information and rebuild the backup information after power failure. Among them, the control method of the storage device 100 includes a backup data establishment process S1, a backup information acquisition process S2, a normal power failure backup information reconstruction process S3 and an abnormal power failure backup information reconstruction process S4. Among them, the backup information acquisition process S2 is performed after the backup data establishment process S1, and the backup information reconstruction process S3 and the abnormal power failure backup information reconstruction process S4 are performed after the backup information acquisition process S2. Among them, at the same time, the storage device 100 selectively executes the backup information reconstruction process S3 and the abnormal power failure backup information reconstruction process S4. Specifically, the storage device 100 can identify whether the process before the power failure is a normal power failure based on whether the power failure instruction of the upper computer is received before the power failure.
[0047] See also Figure 1 and Figure 2 , Figure 4 and Figure 5 ,as well as Figure 7 As shown, in one embodiment of the present invention, in the backup data establishment process S1, the write mode of the storage device 100 is identified according to the state of the cache write mode identifier CACHE_EN. When the cache write mode identifier CACHE_EN is the first identifier, the storage device 100 is in the cache closed write mode. In this embodiment, the first identifier is a low level identifier, such as 0. In the cache closed write mode, all the written host data are backed up. Specifically, after the host computer writes the host data, any storage block 420 is obtained as a backup block 422. Then the host data is copied, and the copied host data is stored in the backup block 422. Among them, the copied host data is the backup data. When the cache write mode identifier CACHE_EN is the second identifier, the storage device 100 is in the cache open write mode. In this embodiment, the second identifier is a high level identifier, such as 1. In the cache open write mode, if the host computer issues a reliable write instruction, the written host data is backed up under a single reliable write instruction. If the host computer does not issue a reliable write instruction, the host data is not backed up. In this embodiment, when the host computer issues a reliable write instruction, the single reliable write flag 4233 is set, for example, to a high level potential 1. When the host computer issues an instruction other than a reliable write instruction, the single reliable write flag 4233 is cleared, for example, to a low level potential 0.
[0048] See also Figure 1 and Figure 2 , Figure 4 and Figure 5 ,as well as Figure 7As shown, in one embodiment of the present invention, in the backup information acquisition process S2, after the backup data is stored in the backup block 422, the backup information of the backup data is acquired. The acquired backup information is stored in the cache chip 300. In the present invention, when editing the host data, an address mapping table is generated according to the address mapping information of the host data, wherein the address mapping table stores the mapping relationship between the physical address and the logical address of the host data. The generated address mapping table is stored in the cache chip 300. And the address mapping table of the host data is written into the backup information of the table block 421. In this embodiment, when the storage device 100 receives a power-off instruction, and when the storage device 100 is in an idle state, the backup information and the address mapping table are transferred to the flash memory chip 400 together. Specifically, the backup information is transferred to the backup page of the table block 421, and the address mapping table is transferred to the address page of the table block 421. In the process of normal power-off of the storage device 100, the host computer sends a power-off instruction to the processor 210. When the storage device 100 completes the instruction of the host computer and does not receive a new instruction of the host computer within a preset time, the storage device 100 enters an idle state.
[0049] See also Figure 1 and Figure 2 , Figure 4 and Figure 5 ,as well as Figure 7 and Figure 8 As shown, in one embodiment of the present invention, in the backup information reconstruction process S3 of normal power failure or the backup information reconstruction process S4 of abnormal power failure, after power-on, the data in the device identification register 230 is initialized, and the values of each field are restored to the default values. Then the data of the register block 423 is read into the device identification register 230. According to whether the power-off flag 4234 is set, it is judged whether the power-off state before power-on is normal power failure. If the power-off flag 4234 is set, it means that the power-off process before power-on is normal power failure. Therefore, the present invention only needs to scan the register block 423 to quickly know whether the power-off process before power-on is normal power failure or abnormal power failure, avoiding multiple scanning and comparison, and the efficiency is extremely high. If the power-off flag 4234 is cleared, it means that the power-off process before power-on is abnormal power failure. In this embodiment, the backup information reconstruction process S3 of normal power failure includes steps S31 to S38.
[0050] Step S31: determine whether the storage device 100 is in cache write mode before power failure.
[0051] Step S32: If the storage device 100 is in the cache write mode, then determine whether the single reliable write flag 4233 is set.
[0052] Step S33 : if the storage device 100 is in the cache-off write mode, or the storage device 100 is in the cache-on write mode and the single reliable write flag 4233 is set, the backup information and the address mapping table are read from the table block 421 .
[0053] Step S34: read the physical address of the host data from the address mapping table as the first physical address.
[0054] Step S35: Set the physical address of the host data in the backup information as the second physical address.
[0055] Step S36: Determine whether the first physical address and the second physical address are the same.
[0056] Step S37: When the first physical address and the second physical address are the same, a mapping relationship update flag is set, and the physical address of the host data is updated to the physical address of the backup data.
[0057] Step S38: When the first physical address and the second physical address are different, clear the mapping relationship update flag.
[0058] See also Figure 1 and Figure 2 , Figure 4 and Figure 5 ,as well as Figure 7 and Figure 8As shown, in one embodiment of the present invention, in step S31, when the cache write mode identifier CACHE_EN is the second identifier, step S32 is executed. When the cache write mode identifier CACHE_EN is the first identifier, step S33 is executed. In step S32, the single reliable write flag 4233 is set, and step S33 is executed. In step S32, if the single reliable write flag 4233 is not set, the normal power-off backup information reconstruction process S3 is directly terminated. In step S33, the backup information and the address mapping table are read from the table block 421, and then step S34 is executed. The backup information and the address mapping table both record the address mapping information of the host data. According to the logical address of the current host data, the physical address of the current host data can be obtained from the backup information and the address mapping table respectively. In step S34, the physical address in the address mapping table is used as the first physical address. In step S35, the physical address of the host data is found from the backup information as the second physical address. In step S36, the first physical address and the second physical address are compared. In step S37 and step S38, the mapping relationship update flag is stored in the device identification register 230, and before power failure or when the storage device 100 is idle, the data in the device identification register 230 is transferred to the register block 423. When the mapping relationship update flag is set, for example, to a high level 1, the address mapping information of the host data needs to be updated, specifically, the physical address of the current host data is updated from the first physical address to the physical address of the backup data.
[0059] See also Figure 1 and Figure 2 , Figure 4 and Figure 5 ,as well as Figure 7 and Figure 8As shown, in one embodiment of the present invention, when executing a reliable write instruction, the host data is written to the flash memory chip 400 in the XLC mode, and the backup data is written to the flash memory chip 400 in the SLC mode, so the backup data is stable. In step S36, after power is turned on again, if the first physical address and the second physical address are consistent, it means that the current host data has not undergone data update after the backup, and the current backup data is available. Therefore, after power is turned on again, the mapping relationship update flag is set. The physical address of the host data in the address mapping table is updated to the physical address of the backup data. For example, the logical address of the host data is L1. The first physical address of the host data is P1, and the second physical address is also P1. At this time, the physical address of the backup data in the backup information is P2, then after the mapping relationship update flag is set, the mapping relationship L1 to P1 in the address mapping table is updated to the mapping relationship L1 to P2. At this time, the host data is stored in the SLC mode at the physical address P2, and the stability is good. The original host data at the first physical address P1 is invalidated. Specifically, the host data originally stored at the first physical address becomes invalid data, and the invalid data can be recycled in the subsequent garbage collection process. In step S36, if the first physical address and the second physical address are different, it means that the current host data has undergone an editing process after the backup. Therefore, in the current backup information, the data at the first physical address and the data at the second physical address are different, and the mapping relationship update flag is cleared, for example, set to a high level 0, and the normal power-off backup information reconstruction process S3 is terminated. For example, the logical address of the host data is L1. The first physical address of the host data is P3, and the second physical address is P1. At this time, the address mapping table of the host data is not updated. In the present invention, while trying not to scan the flash memory chip 400, not only can the information reconstruction of the host data and the backup data be realized, and the storage stability of the host data be improved, but also the older data can be prevented from overwriting the newer data during reconstruction, thereby improving the accuracy of reconstruction.
[0060] See also Figure 1 and Figure 2 , Figure 4 and Figure 5 ,as well as Figure 7 and Fig. 9 As shown, in one embodiment of the present invention, when the power-off flag 4234 is not set, for example, at a low level 0, the power-off process before power-on is an abnormal power-off, and the backup information reconstruction process S4 of the abnormal power-off is executed. The backup information reconstruction process S4 of the abnormal power-off includes steps S41 to S45.
[0061] Step S41: determine whether the storage device 100 is in cache write mode before power failure.
[0062] Step S42: If the storage device 100 is in the cache write mode, then determine whether the single reliable write flag 4233 is set.
[0063] Step S43 : If the storage device 100 is in the cache-off write mode, or the storage device 100 is in the cache-on write mode and the single reliable write flag 4233 is set, scan multiple storage pages 430 of the backup block 422 .
[0064] Step S44 , obtaining the backup information of the scanned backup data, and updating the backup information to the cache chip 300 .
[0065] Step S45: according to the consistency between the host data and the backup data, set or clear the mapping relationship update flag.
[0066] See also Figure 1 and Figure 2 , Figure 4 and Figure 5 ,as well as Figure 7 and Fig. 9 As shown, in one embodiment of the present invention, in step S41, when the cache write mode identifier CACHE_EN is the second identifier, step S42 is executed. When the cache write mode identifier CACHE_EN is the first identifier, step S43 is executed. In step S42, the single reliable write flag 4233 is set, and step S43 is executed. In step S42, if the single reliable write flag 4233 is not set, the backup information reconstruction process S4 of abnormal power failure is directly terminated. In step S43, the latest multiple storage pages 430 in the backup block 422 are scanned, and the number of pages scanned is the number of storage pages 430 contained in the word line WL. For example, if there are 12 storage pages 430 on the word line WL, then in step S43, the 12 most recently written storage pages 430 in the backup block 422 are scanned. In step S44 , the backup information of the backup data is acquired according to the backup data scanned in step S43 , wherein the backup information includes the physical address of the backup block 422 , the physical address of the backup page, and the type of the backup block 422 .
[0067] See also Figure 1 and Figure 2 , Figure 4 and Figure 5 ,as well as Figure 7 and Fig. 9As shown, in one embodiment of the present invention, in step S45, the updating of the mapping relationship update flag is the same as that in the backup information reconstruction process S3 of normal power failure. In step S45, after the backup information is reconstructed, the logical address of the backup data can be obtained from the backup information, and the logical address of the backup data is also the logical address of the host data, for example, L1. The address mapping table is read from the table block 421. According to the logical address L1, the address mapping information of the host data is read from the address mapping table, so as to obtain the physical address of the host data and use it as the first physical address. In this embodiment, the backup data and the host data of the first physical address are scanned. If the host data and the backup data are consistent, it is considered that the host data has not been updated after the backup, and the mapping relationship update flag is set, and the physical address of the host data in the address mapping table is updated to the physical address of the backup data. For example, the physical address of the host data L1 is P1, and the physical address of the backup data L1 is P2, then the address mapping relationship of the host data L1 is updated from L1 to P1 to L1 to P2. At this time, the original backup information is invalidated, and the host data of P1 becomes invalid data. The host data of P1 can be recycled in the subsequent garbage collection process. If the host data and the backup data are inconsistent, the host data has been updated after the backup, so the physical address has been changed. At this time, the host data is the latest data, so the address mapping table is not updated, and the mapping relationship update flag is cleared.
[0068] See also Figure 1 and Figure 2 , Figure 4 and Figure 5 ,as well as Figures 7 to 9 As shown, in one embodiment of the present invention, in the backup information reconstruction process S3 of normal power failure and the backup information reconstruction process S4 of abnormal power failure, after the backup information is reconstructed, the type of the backup block 422 is marked as a garbage collection block, and the garbage collection priority of the backup block 422 is set to the highest priority. When the garbage collection conditions are met, the backup block 422 is garbage collected first to ensure the stability of the backup data.
[0069] See also Figure 1 and Figure 2 , Figure 4 and Figure 5 ,as well as Figures 7 to 9As shown, in one embodiment of the present invention, after each update of the information in the flash memory chip 400, the data in the device identification register 230 is immediately updated to the register block 423. The update content includes the backup block information 4231, the backup page information 4232 and the power-off flag 4234. In the cache-enabled write mode, if the host computer issues a single reliable write instruction, the data in the device identification register 230 is updated, and the update content is the backup block information 4231, the backup page information 4232 and the single reliable write flag 4233. In the cache-enabled write mode, if the host computer issues a single reliable write instruction and multiple storage pages 430 have been written, specifically, the number of storage pages 430 written is the number of storage pages 430 contained in the word line WL, and the data in the device identification register 230 is updated. The update content is to clear the single reliable write flag 4233. The backup information may be updated or not. If the backup block information 4231 and the backup page information 4232 are updated, the contents of the backup block information 4231 and the backup page information 4232 are cleared to facilitate entering the backup information record of the next unstable storage unit. In this embodiment, the storage unit refers to a word line WL. And the unstable storage unit is an unfilled word line WL. In this embodiment, after the write mode of the storage device 100 is switched, for example, the write mode is switched from the cache-on write mode to the cache-off write mode, the state of the cache write mode identifier CACHE_EN is updated, and the updated cache write mode identifier CACHE_EN data is updated to the register block 423.
[0070] The control firmware 220 provided by the present invention includes a backup module 221, a normal power failure reconstruction module 222, an abnormal power failure reconstruction module 223 and a parameter update module 224, wherein the backup module 221 is used to generate backup data and backup information of the backup data according to the control method of the storage device 100 when the host data is written. Specifically, the backup module 221 is used to execute the backup data establishment process S1 and the backup information acquisition process S2. The normal power failure reconstruction module 222 is used to execute the backup information reconstruction process S3 of normal power failure. The abnormal power failure reconstruction module 223 is used to execute the backup information reconstruction process S4 of abnormal power failure. The parameter update module 224 is used to update the parameter data in the device identification register 230 and the register block 423 according to the control method of the storage device 100.
[0071] The embodiments of the present invention disclosed above are only used to help illustrate the present invention. The embodiments do not describe all the details in detail, nor do they limit the invention to the specific embodiments described. Obviously, many modifications and changes can be made according to the content of this specification. This specification selects and specifically describes these embodiments in order to better explain the principles and practical applications of the present invention, so that those skilled in the art can understand and use the present invention well. The present invention is limited only by the claims and their full scope and equivalents.
Claims
1. A storage device, characterized in that: include: A backup module uses the copy data of the host data as backup data; A flash memory chip, wherein some storage blocks in the flash memory chip are divided into a table block, a backup block and a register block, the backup block stores the backup data, the table block stores address mapping information of the host data and backup information of the backup data, and the register block stores reconstruction identification data; A normal power-off reconstruction module, when the storage device receives a power-off instruction from the host computer, the normal power-off reconstruction module scans the backup block according to the backup information and rebuilds the backup information, wherein the backup information includes address mapping information of the host data, the physical address of the backup block, the physical address of the backup page and the type of the backup block, wherein the backup page is a storage page where the backup data is located, and the types of the backup blocks include user data blocks and garbage collection blocks; as well as An abnormal power-off reconstruction module, when the storage device abnormally powers off, the abnormal power-off reconstruction module scans the backup block according to the reconstruction identification data and reconstructs the backup information, wherein the reconstruction identification data includes the physical address of the backup block, the physical address of the backup page and a single reliable write flag, the single reliable write flag defaults to the first flag, when the storage device receives a reliable write instruction from the host computer, the single reliable write flag is set to the second flag, and after the single reliable write instruction is completed, the single reliable write flag is initialized to the first flag.
2. A storage device according to claim 1, characterized in that: The reconstruction identification data includes a power-off flag, which is set to a first flag by default. When the storage device receives a power-off instruction, the power-off flag is set to a second flag. After the storage device is powered on again, the power-off flag is initialized to the first flag.
3. A storage device according to claim 1, characterized in that: The storage device includes a cache chip. When the cache chip is enabled, if the single reliable write flag is set, the backup module copies the written host data as the backup data. When the cache chip is disabled, the backup module copies the written host data as the backup data.
4. A storage device according to claim 3, characterized in that: Before the storage device enters an idle state or before the storage device receives a power-off instruction, the latest data of the table block is stored in the cache chip, wherein the latest data of the table block includes address mapping information of the newly written host data and backup information of the newly written backup data.
5. A storage device according to claim 1, characterized in that: The storage device includes a device identification register, which is electrically connected to the flash memory chip. Before the storage device receives a power-off instruction or before the storage device enters an idle state, the latest data of the register block is stored in the device identification register, wherein after power is restored, the parameter data of the device identification register is initialized and the parameter data is read from the register block.
6. A storage device according to claim 1, characterized in that: A mapping relationship update flag is stored in the register block. In the reconstruction scanning process of the storage device, when the physical address of the host data in the address mapping table and in the backup information is consistent, or the host data and the backup data are the same, the mapping relationship update flag is set to the second flag, and the physical address of the host data in the address mapping table is updated to the physical address of the backup data, wherein the mapping relationship update flag defaults to the first flag.
7. A method for controlling a storage device, characterized in that: The following steps are involved: When writing host data to the storage device, using the copy data of the host data as backup data; Acquire backup information of the backup data, and store the backup information in a backup block of the storage device; Acquire reconstruction identification data of the storage device, and store the reconstruction identification data in a register block of the storage device; When the storage device receives a power-off instruction from the host computer, the backup block is scanned according to the backup information to rebuild the backup information, wherein the backup information includes address mapping information of the host data, the physical address of the backup block, the physical address of the backup page and the type of the backup block, wherein the backup page is a storage page where the backup data is located, and the types of the backup blocks include user data blocks and garbage collection blocks; as well as When the storage device loses power abnormally, the backup block is scanned according to the reconstruction identification data to reconstruct the backup information, wherein the reconstruction identification data includes the physical address of the backup block, the physical address of the backup page and a single reliable write flag, the single reliable write flag defaults to the first flag, when the storage device receives a reliable write instruction from the host computer, the single reliable write flag is set to the second flag, and after the single reliable write instruction is completed, the single reliable write flag is initialized to the first flag.
Citation Information
Patent Citations
Data brown-out protection method for NOR flash memory
CN102737715A
Data recovery method and device for solid state disk and electronic equipment
CN117389798A