Flash memory power failure processing method and system
By performing exclusive partition identification and recovery of user data and management data of flash memory devices, the problem of incomplete data recovery of flash memory devices after power failure is solved, and the function of stable disk-free flash memory devices is realized, improving the precision and flexibility of power failure recovery.
Patent Information
- Application Number
- CN202510178004.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-18
- Publication Date
- 2025-06-20
AI Technical Summary
The data recovery of existing flash memory devices after power failure is incomplete, resulting in disk drop problems. The existing power-down recovery mechanism of simple traversal mapping tables and bad block tables is difficult to meet the requirements of stable usage without disk drops and timeliness.
By performing exclusive partition identification and recovery processing on the cache interval and storage interval of user data and management data, identifying the cache block type that is interrupted by power-down is the management cache block, obtaining the last cached data type, and performing the power-down recovery operation according to this type to ensure that the flash memory device is operating normally under power-up state and does not cause disk drops.
The function of flash memory devices to recover power down and disks is realized, which improves the precision and flexibility of power down and recovery processing, and improves the accuracy of management data processing.
Smart Images

Figure CN120179459A_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the technical field of flash memory, and particularly relates to a flash memory power-off processing method and system. Background Art
[0002] Currently, for the power-off recovery of data in flash memory devices, taking the power-off recovery of the mapping table data of flash memory devices as an example, R & D personnel have developed a snapshot method, a pre-update backup method, and a full-area scan and reconstruction method.
[0003] In practical applications, the disk drop problem caused by incomplete data recovery of flash memory devices after power-off. Relying solely on the current power-off recovery mechanism that simply traverses the mapping table and the bad block table, it is difficult to meet the usage requirements of stable disk non-drop and timeliness during power-off recovery of flash memory devices. Summary of the Invention
[0004] This application provides a flash memory power-off processing method and system, which can perform exclusive partition identification and recovery processing on the key data causing disk drop, thereby realizing the function of non-disk drop during power-off recovery of flash memory devices. Specifically, the device takes the partition management of the cache area and the storage area of user data and management data that can cause disk drop problems as a prerequisite for power-off data recovery. Thus, when the flash memory device identifies that the block type of the cache block interrupted by power-off is the management cache block, it can obtain the data type of the last cached data, and perform a power-off recovery operation according to this data type, so that the flash memory device can operate normally and without disk drop in the powered-on state, which is beneficial to improving the fineness and flexibility of the power-off recovery process of the flash memory device, and improving the accuracy of the flash memory device in processing management data.
[0005] In a first aspect, this application provides a flash memory power-off processing method, which is applied to a flash memory controller of a flash memory device. The flash memory device includes the flash memory controller, a flash memory cache module, and a flash memory storage module. The flash memory cache module includes a user cache block and a management cache block, and the flash memory storage module includes a user storage block and a management storage block; the method includes:
[0006] Detect abnormal power-off, and query the block type of the cache block interrupted during the abnormal power-off; when the block type is the management cache block, obtain the data type of the last cached data in the interrupted management cache block; and perform a power-off recovery operation according to the data type of the last cached data;
[0007] Before performing the power-off recovery operation, the flash memory device is used to write user data into the user cache block; and after the user cache block is full, update the data of the user cache block to the user storage block according to a first mapping table; and update the first mapping table;
[0008] Before performing the power-down recovery operation, the flash memory device is further configured to write management data into the management cache block; and, after the management cache block is full, update the data in the management cache block to the management storage block according to the second mapping table; and, update the second mapping table.
[0009] In a second aspect, the present application provides a flash memory power-down processing system, the flash memory power-down processing system includes a host and a flash memory device, the host is communicatively connected to the flash memory device, the flash memory device includes a flash memory controller, a flash memory cache module and a flash memory storage module, the flash memory cache module includes a user cache block and a management cache block, the flash memory storage module includes a user storage block and a management storage block; wherein,
[0010] The flash memory device is configured to detect an abnormal power-down, query the block type of the cache block interrupted during the power-down; and, when the block type is the management cache block, obtain the data type of the last cached data in the interrupted management cache block; and, perform a power-down recovery operation according to the data type of the last cached data;
[0011] Before the flash memory device performs the power-down recovery operation, it is further configured to write user data into the user cache block; and, after the user cache block is full, update the data in the user cache block to the user storage block according to the first mapping table; and, update the first mapping table;
[0012] Before the flash memory device performs the power-down recovery operation, it is further configured to write management data into the management cache block; and, after the management cache block is full, update the data in the management cache block to the management storage block according to the second mapping table; and, update the second mapping table.
[0013] It can be seen that in the embodiments of the present application, compared with the existing power-down recovery mechanism of the mapping table, the present application performs exclusive partition identification and recovery processing on the key data that causes the disk drop, so as to realize the function of the flash memory device not dropping the disk during power-down recovery. Specifically, the device uses the partition management of the cache area and the storage area of the user data and the management data that can cause the disk drop problem as the prerequisite for the power-down data recovery. Therefore, when the flash memory device identifies that the block type of the cache block interrupted by the power-down is the management cache block, it can obtain the data type of the last cached data, and perform a power-down recovery operation according to the data type so that the flash memory device can operate normally and not drop the disk in the powered-on state, which is beneficial to improving the fineness and flexibility of the flash memory device for power-down recovery processing, and improving the accuracy of the flash memory device for processing management data. Description of the Drawings
[0014] Figure 1 This is a schematic structural diagram of a flash memory device 1 provided by an embodiment of the present application.
[0015] Figure 2 This is a schematic diagram of the processing flow of a flash memory power-off processing method provided by an embodiment of the present application.
[0016] Figure 3 This is a schematic diagram of a flash memory power-off processing system 100 provided by an embodiment of the present application. Detailed implementation manners
[0017] In order to enable those skilled in the art to better understand the solutions of the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present application.
[0018] The terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish different objects, rather than to describe a specific order. In addition, the terms "include" and "have" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not limited to the listed steps or units, but optionally further includes steps or units not listed, or optionally further includes other steps or units inherent to these processes, methods, products or devices.
[0019] Referring to "embodiments" herein means that the specific features, structures or characteristics described in connection with the embodiments can be included in at least one embodiment of the present application. The phrase appears in various places in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment mutually exclusive with other embodiments. Those skilled in the art will explicitly and implicitly understand that the embodiments described herein can be combined with other embodiments.
[0020] The "and / or" in the embodiments of the present application describes the association relationship of associated objects and indicates that three relationships can exist. For example, A and / or B can represent the following three situations: A exists alone; A and B exist simultaneously; B exists alone. Among them, A and B can be singular or plural.
[0021] In the embodiments of the present application, the symbol " / " can represent that the associated objects before and after are in an "or" relationship. In addition, the symbol " / " can also represent a division sign, that is, perform a division operation. For example, A / B can represent A divided by B.
[0022] The "at least one (piece)" or its similar expression in the embodiments of the present application refers to any combination of these items, including any combination of a single item (piece) or multiple items (pieces), meaning one or more, and multiple means two or more. For example, at least one (piece) of a, b, or c can represent the following seven situations: a, b, c, a and b, a and c, b and c, a, b, and c. Each of a, b, and c can be an element or a set containing one or more elements.
[0023] In the embodiments of the present application, "equal to" can be used in combination with "greater than", applicable to the technical solutions adopted when it is greater than, or can be used in combination with "less than", applicable to the technical solutions adopted when it is less than. When "equal to" is used in combination with "greater than", it is not used in combination with "less than"; when "equal to" is used in combination with "less than", it is not used in combination with "greater than".
[0024] First, the basic concepts involved in the present application will be described below.
[0025] The data of a flash memory (NAND flash) consists of dies, blocks, and pages, and the smallest data access unit is a page. Its characteristics are that it must be erased first, then written, and can only be written once per page, and even must be written in the order of the pages. At the same time, the number of erasures is limited. Generally speaking, a triple-level cell (TLC) has 1000 - 3000 times. Considering the writing characteristics, the P / E (program / erase) (or PE) count is used to measure the lifespan of the flash memory.
[0026] Generally, an operating system organizes data in the form of files in a host, and the final organized access unit is a data block, with sizes such as 512 / 4K / 8K / 16K, etc. Data addressing is achieved by numbering the unit blocks of the flash memory device, that is, the logical block address (LBA). To write the data block in the host to the data page of the flash memory, a flash translation layer (FTL) is required. The first thing to do is the addressing and positioning problem of the data block. In the FTL layer, the mapping layer is used to map the logical block address LBA to the physical page address (PPA), so as to address the actually accessed data.
[0027] Meanwhile, flash memory has the characteristics of writing by page and optionally writing in the order of pages. For the rewriting of the same LBA block data, it will be written into different PPAs. Only the data written into the last PPA is valid, and the data in the previous PPA corresponding to this LBA is invalid data, that is, garbage data. When there is a large amount of such garbage data in the flash memory block, if not processed, it will lead to a reduction in the physical blocks of available data. In order to make full use of the flash memory blocks of the flash device, a garbage collection (GC) algorithm is required to process the invalid data to release the flash memory space.
[0028] In principle, writing data to flash memory is to charge the flash memory cells (cells). For example, filling this flash memory cell is 0. When an abnormal power failure occurs while the flash memory cell is being written with data, this flash memory cell will probably not be fully charged. The state of the flash memory cell that is not fully charged will be uncertain, and the data stored in it will be unreliable. If the data written at this time is critical data such as mapping table data, flash memory block information, bad block table data, etc., this unreliable data will bring abnormal situations such as the accurate storage unit of the previously written data cannot be found. From the user's perspective, a disk drop phenomenon will occur.
[0029] Abnormal power failure poses a major challenge to the integrity and reliability of data. Therefore, the functionality of abnormal power failure recovery is very important for flash devices.
[0030] To solve the above problems, the present application provides a flash memory power failure processing method and system, which specifically identify and recover the critical data that causes disk drops, so as to achieve the function of no disk drop during power failure recovery of the flash device. Specifically, the device takes the partition management of the cache area and storage partition of user data and management data that can cause disk drop problems as a prerequisite for power failure data recovery. On the one hand, it can quickly identify the unreliable data during power failure as management data when powering on again. On the other hand, through the design concept of partition management, when the flash device determines the first management storage block to which the unreliable data belongs, it only needs to perform a power failure recovery operation on the management data of this storage partition, reducing unnecessary processing operations for other data and thus improving the processing efficiency of the power failure recovery mechanism.
[0031] The following uses specific embodiments to elaborate in detail on the technical solutions of the present application and how the technical solutions of the present application solve the above technical problems. The embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The following will describe the embodiments of the present application in conjunction with the accompanying drawings.
[0032] Please refer to Figure 1 , Figure 1 which is a schematic structural diagram of a flash device 1 provided by an embodiment of the present application. As Figure 1As shown in the figure, the flash memory device 1 includes the flash memory controller 10, a flash memory cache module 30, and a flash memory storage module 50. The flash memory cache module 30 includes a user cache block 31 and an administrative cache block 32. The flash memory storage module 50 includes a user storage block 51 and an administrative storage block 52. Among them,
[0033] The flash memory device 1 (such as the flash memory controller 10) is configured to write user data into the user cache block 31; and, after the user cache block 31 is full, write the data in the user cache block 31 into the user storage block 51 according to a first mapping table; and update the first mapping table according to the user free blocks in the user storage block 51;
[0034] The flash memory device 1 (such as the flash memory controller 10) is further configured to write administrative data into the administrative cache block 32; and, after the administrative cache block 32 is full, write the data in the administrative cache block 32 into the administrative storage block 52 according to a second mapping table; and update the second mapping table according to the administrative free blocks in the administrative storage block 52, where the administrative data includes critical data that can cause the flash memory device to experience a disk drop in an unreliable state;
[0035] Among them, the administrative data of the flash memory device includes the data of the mapping table and the data of the bad block table. The mapping table is a data table that records the correspondence between the logical block addresses of the file system of the host device and the physical page addresses of the flash memory device, and the host device is communicatively connected to the flash memory device. The bad block table is a data table that records the bad block information in the storage blocks of the flash memory device.
[0036] Among them, the user cache block 31 and the administrative cache block 32 can be set by the flash memory device according to the ratio of the partition sizes and are isolated from each other. The determination of the ratio of the partition sizes can refer to the type, usage characteristics, etc. of the flash memory device.
[0037] Taking a consumer-grade solid-state drive (SSD) as an example, it is mainly targeted at ordinary individual users and is used for daily office work, entertainment, and other applications. Usually, more attention is paid to the read and write speed of user data to improve the user experience. Therefore, the proportion of the user cache block is relatively large. Generally, the ratio of the user cache block to the administrative cache block can be, for example, between 7:3 and 8:2. For example, a 512MB-cache consumer-grade SSD may allocate 350MB - 400MB as the user cache to accelerate the read and write operations of user files, and 100MB - 150MB as the administrative cache to store management information such as wear leveling and garbage collection.
[0038] Taking enterprise - level solid - state drives as an example, enterprise - level applications have extremely high requirements for data reliability, stability, and performance. The management cache needs to undertake more tasks, such as real - time monitoring of the health status of flash chips and performing complex error correction. Therefore, the proportion of the management cache will be relatively high, and the ratio of the user cache to the management cache may be about 6:4. Suppose an enterprise - level SSD is equipped with 2GB of cache. Approximately 1.2GB will be used as the user cache to meet the data read - write requirements of the enterprise business system; while 0.8GB will be used as the management cache to ensure the stable operation of the device under high - intensity workloads.
[0039] Among them, the user storage block 51 and the management storage block 52 can be single - fold or multi - fold of the minimum write unit of the flash device 1, such as a flash page.
[0040] Such as Figure 2 As shown, the schematic diagram of the processing flow of a flash power - off processing method provided by an embodiment of the present application can be applied to the flash controller 10 of the flash device 1 as shown in Figure 1 As shown, the method includes the following steps:
[0041] Step 201, the flash device detects an abnormal power - off and queries the block type of the cache block interrupted during the abnormal power - off.
[0042] In a specific implementation, when the flash device detects that it has recovered from the power - off state to the power - on state, it can query the block type of the cache block interrupted during the power - off state.
[0043] Among them, the status data of the cache block of the flash device can be recorded in the flash log and / or the metadata information set. The status data can include the usage status, and the usage status can include, for example, idle, occupied, written to storage, written to cache, etc.
[0044] In a specific implementation, the flash device can first obtain the cache block in the written - to - storage usage state by querying the flash log or the metadata information set, and then determine the block type according to the partition type of the obtained cache block.
[0045] Step 202, when the block type is the management cache block, the flash device obtains the data type of the last - cached data in the interrupted management cache block;
[0046] Among them, in addition to the aforementioned usage status, the status data of the cache block of the flash memory device may further include the data type identifier of the data cached in each cache block. By querying the data type table according to this data type identifier, the corresponding data type can be obtained. It should be noted that the data in the cache block may be management data to be written into the storage block, such as a newly created address mapping relationship, or data read by the flash memory device from its own storage block and waiting for further processing, such as information about newly scanned bad blocks, etc.
[0047] In a specific implementation, the status data may be recorded in the operation record entry in the record. The operation record entry will record key information related to the data operation, such as the operation timestamp, the data source (i.e., the corresponding cache block number), the target address of the storage block, the status data, the check value of the data, etc. The flash memory device can determine the operation sequence before and after the power-off moment according to the timestamp, clarify the data flow direction and location through the data source and the target address, and the check value of the data can be used to determine whether the data in the operated storage block is complete. The algorithms for calculating the check value include but are not limited to: using cyclic redundancy check CRC, parity check, Hamming code check, etc.
[0048] Step 203, the flash memory device performs a power-off recovery operation according to the data type of the last cached data, so that the flash memory device maintains the working state except for the disk-off in the power-on state.
[0049] Among them, the flash memory device generally creates operation record entries in the order of the time when the data operation occurs and adds them to the operation record entry table. Therefore, the operation record entry in the power-off state is the last operation record entry in the operation record entry table. By querying the data type identifier in the last operation record entry, the data type of the last cached data can be obtained.
[0050] It can be seen that in the embodiment of the present application, compared with the existing power-off recovery mechanism of the mapping table, the present application performs exclusive partition identification and recovery processing on the key data that causes disk-off, so as to realize the function of the flash memory device to recover from power-off without disk-off. Specifically, the device takes the partition management of the cache area and the storage area of the user data and the management data that can cause disk-off problems as the prerequisite for power-off data recovery. Thus, when the flash memory device identifies that the block type of the cache block interrupted by the power-off is the management cache block, it can obtain the data type of the last cached data, and perform a power-off recovery operation according to this data type so that the flash memory device can operate normally and without disk-off in the power-on state, which is beneficial to improving the fineness and flexibility of the flash memory device for power-off recovery processing, and improving the accuracy of the flash memory device for processing management data.
[0051] In a possible example, the management data includes data of a mapping table of the flash memory device. The mapping table is a data table recording the correspondence between the logical block addresses of the file system of the host device and the physical page addresses of the flash memory device. The host device is communicatively connected to the flash memory device. The performing a power-down recovery operation according to the data type of the last cached data includes: when the data type of the last cached data is the data of the mapping table, querying a flash snapshot table according to the first time node of the last cached data, and obtaining a first mapping table snapshot at a second time node with the shortest time interval from the first time node in the flash snapshot table; and scanning the management storage blocks between the second management storage block corresponding to the first mapping table snapshot and the first management storage block to obtain a first mapping relationship; and updating the first mapping table snapshot according to the first mapping relationship to obtain the updated mapping table;
[0052] Performing an erasure operation on a first management storage block associated with the last cached data to obtain an erasure result;
[0053] If the erasure result is an erasure failure, marking the first management storage block as a bad block, and updating the second mapping relationship table and the bad block table of the flash memory device according to the bad block;
[0054] If the erasure result is an erasure success, updating the second mapping relationship table according to the free state of the first management storage block.
[0055] Among them, the operation record entry in the power-down state is the last operation record entry in the operation record entry table. By querying the operation timestamp in the last operation record entry, it is used as the first time node. The operation object block in the last operation record entry can be the first management storage block.
[0056] Among them, the data of the mapping table newly generated between the first time node and the second time node includes at least one of the following: data of newly created mapping relationships, data of modified existing mapping relationships, and data of deleted existing mapping relationships. It should be noted that since the write operation of the first management storage module is not completed, the correspondence data between the physical address of the first management storage block and the logical address corresponding to the first data has not been created, and the above-mentioned newly generated mapping table data does not include this correspondence data.
[0057] It can be seen that in this example, for the case where the address mapping data of the interrupted mapping table in the flash memory device is unreliable, the flash memory device can update to obtain a stable mapping table based on the most recent snapshot of the mapping table data and the newly generated address mapping data during the valid interval period after the snapshot, thereby improving the consistency and stability of maintaining the mapping table when the flash memory device recovers from power failure. In addition, after the flash memory device updates the mapping relationship table, since the first management storage module is occupied due to storing the first data in the unreliable state, the state update of the first management storage module can be further promoted by performing an erase operation, so as to adaptively adjust the state information of the first management storage module in the second mapping relationship table according to the actual erase result to maintain the consistency and stability of subsequent calls of this storage module.
[0058] In a possible example, the management data includes the data of the bad block table of the flash memory device; the method further includes: when the data type of the last cached data is the data of the bad block table, querying the flash memory log to obtain the operation type and the first management storage block as the operation object block in the operation record entry associated with the last cached data; and updating the bad block table and the second mapping relationship table according to the operation type and the first management storage block.
[0059] Among them, the flash memory device can record data operations in chronological order in the flash memory log. When the data in the cache block starts to be written to the storage block, the log will record the start timestamp information of this operation, including the operation type as write, the identifier of the cache block, the address of the target storage block, the data size, etc. Similarly, the data operations before the write operation will also be sequentially recorded as corresponding operation record entries. At the moment of power failure, the flash memory log is not in time to record the status information such as the data size in the state of the completed write operation and will stay in the state of recording that this cache block is being written. For example, the log may record information similar to [timestamp] - start writing the data of cache block A to storage block X, but there is no subsequent record of the data size.
[0060] It can be seen that in this example, for the case where the first data in the unreliable state in the flash memory device is the data of the bad block table, the flash memory device can query the flash memory log to obtain the operation type and the first management storage block as the operation object block in the operation record entry associated with the last cached data, and update the bad block table and the second mapping relationship table according to the operation type and the first management storage block, thereby maintaining the data consistency of the bad block table and the second mapping relationship table, improving the stability and consistency of the system self-check after the flash memory device resumes power supply, and avoiding the occurrence of disk drop problems.
[0061] In a possible example, updating the bad block table and the second mapping relation table according to the operation type and the first management storage block includes: detecting that the operation type is an erase operation; marking the first management storage block as a bad block; and updating the bad block table and the second mapping relation table according to the marked bad block.
[0062] Among them, the operation type in the operation record entry associated with the last cached data is an erase operation. According to the technical principle that the flash memory device first erases and then writes, the operation object block of this erase operation is the management storage block, and the data to be written is the last cached data. Since this erase operation may not be completed instantaneously due to power failure, that is, for the first management storage module, it may be completely erased or partially erased, that is, in an unstable state.
[0063] Among them, updating the bad block table according to the marked bad block includes: creating bad block description information for the first management storage block as a bad block; querying the free space of the bad block table; and writing the bad block description information into the free space to complete the update of the bad block table.
[0064] Among them, updating the second mapping relation table according to the marked bad block includes: querying whether there is second mapping relation data of the first management storage block in the second mapping relation table; if so, marking the storage unit storing the second mapping relation data as a garbage block and waiting for subsequent garbage collection operations to recycle the invalid data; if not, keeping the state of the second mapping relation table.
[0065] It can be seen that in this example, for the case where the operation type in the operation record entry associated with the last cached data of the flash memory device is an erase operation, the first management storage block will be marked as a bad block; and the bad block table and the second mapping relation table will be updated according to the marked bad block, so as to avoid disk drop caused by the first management storage block in an unstable state.
[0066] In a possible example, updating the bad block table and the second mapping relation table according to the operation type and the first management storage block includes: detecting that the operation type is an erase operation; performing an erase operation on the first management storage block to obtain an erase result;
[0067] If the erase result is an erase failure, marking the first management storage block as a bad block; and, updating the bad block table and the second mapping relation table according to the marked bad block;
[0068] If the erase result is an erase success, updating the second mapping relation table according to the free state of the first management storage block.
[0069] Among them, updating the second mapping relationship table according to the free state of the first managed storage block includes: creating second mapping relationship data between the first managed storage block and the management cache block; querying the free space of the second mapping relationship table; writing the second mapping relationship data into the free space, and the update of the second mapping relationship table is completed.
[0070] It can be seen that in this example, for the case where the operation type in the operation record entry associated with the last cached data in the flash memory device is an erase operation, the flash memory device will first check the validity of the first managed storage block through the erase operation, and mark the first managed storage block as a bad block only when the erase fails; update the bad block table and the second mapping relationship table according to the marked bad block, so as to avoid disk drop caused by the first managed storage block in an unstable state, and at the same time be able to update the second mapping relationship table to release the availability of the first managed storage block when the erase is successful.
[0071] In a possible example, the method further includes: detecting that the operation type is a write operation; reclaiming the valid data of the first managed storage block; performing an erase operation on the first managed storage block to obtain an erase result;
[0072] If the erase result is an erase failure, mark the first managed storage block as a bad block; and update the bad block table and the second mapping relationship table according to the marked bad block;
[0073] If the erase result is an erase success, update the second mapping relationship table according to the free state of the first managed storage block.
[0074] Among them, the data of the first managed storage block may include partial data of the last cached data, and this partial data includes a first part of data in a stable state and a second part of data in an unstable state. For example, the first managed storage block includes a first flash page and a second flash page, the first flash page stores the first part of data, and the second flash page stores the second part of data.
[0075] In a specific implementation, the flash memory device can store the first part of data and the second part of data in a new free managed storage block by overall reclaiming the data of the storage block. Subsequently, the flash memory device can read the first part of data from the managed storage block according to the status data such as the data size in the operation entry record for use.
[0076] It can be seen that in this example, for the case where the operation type in the operation record entry associated with the last cached data in the flash memory device is a write operation, the flash memory device can, through the mechanism of first recycling and then erasing, not only preserve the valid data without loss, but also update the first management storage block to a stable state in a timely manner to avoid disk drop caused by inconsistent bad block table data, which is beneficial to improving the flexibility and applicability of the flash memory device in processing flash memory data during power-down recovery operations.
[0077] In a possible example, the method further includes: detecting that the operation type is a read operation; performing a read operation on the first management storage block to obtain a read result;
[0078] If the read result is a read failure, marking the first management storage block as a bad block; and updating the bad block table and the second mapping relationship table according to the marked bad block;
[0079] If the read result is a read success, maintaining the current states of the bad block table and the second mapping relationship table.
[0080] It can be seen that in this example, for the case where the operation type in the operation record entry associated with the last cached data in the flash memory device is a read operation, a read operation is performed again to check the stability of the first management storage block, thereby improving the consistency of data recovery in the power-down scenario of this read operation to avoid disk drop.
[0081] In a possible example, the method further includes: when the block type is the user cache block, obtaining the operation type in the operation record entry associated with the last cached data and the first user storage block that is the operation object block;
[0082] If the operation type is a write operation, marking the first user storage block as a garbage block; performing a data recycling operation on the first user storage block according to the garbage collection policy; and updating the first mapping relationship table according to the user storage block after the data recycling operation;
[0083] If the operation type is not a write operation, maintaining the first mapping relationship table.
[0084] Among them, when power is lost while writing data from the user cache block to the first user storage block, since not all user data of the current user cache block can be written, the first user storage block only stores partial user data, that is, the first data, which is unreliable and invalid data for the flash memory device. Through the data recycling operation, the storage space of the first user storage block can be released in a timely manner, and through the first mapping relationship table update operation, the accuracy and consistency of the dynamic management of the correspondence between the user storage block and the user cache block can be maintained.
[0085] It can be seen that in this example, unreliable user data caused by power failure can be quickly identified through decoupled cache partitions and a pre-marking mechanism, and discarded for this unreliable user data while maintaining the consistency of reliable data in the flash memory device through a garbage collection mechanism. For the flash memory device, different processing strategies are adopted for user data and management data, improving the flexibility of data recovery in the power-on state after power failure, as well as the efficiency and consistency of power-failure data recovery processing for unreliable user data storage partitions.
[0086] In a possible example, if the power-failure state is multiple consecutive power failures, the cache block interrupted by the power-failure state is the cache block interrupted by the first power failure in the multiple consecutive power failures.
[0087] It can be seen that in this example, for the case of multiple consecutive power failures, the flash memory device performs a one-time power-failure recovery process only based on the cache block interrupted by the first power failure in the multiple consecutive power failures, that is, only one power-failure recovery operation is executed, avoiding repeated execution of the power-failure recovery operation from delaying the power-failure recovery duration of the flash memory device and consuming the flash memory device.
[0088] Such as Figure 3 As shown, an embodiment of the present application further provides a flash memory power-failure processing system 100. The flash memory power-failure processing system is a flash memory device 1 and a host 2. The host 2 is communicatively connected to the flash memory device 1. The flash memory device 1 includes a flash memory controller 10, a flash memory cache module 30, and a flash memory storage module 50. The flash memory cache module 30 includes a user cache block 31 and a management cache block 32. The flash memory storage module 50 includes a user storage block 51 and a management storage block 52; wherein,
[0089] The flash memory device 1 is configured to detect an abnormal power failure, query the block type of the cache block interrupted during the abnormal power failure; and, in the case where the block type is the management cache block 32, obtain the data type of the last cached data in the interrupted management cache block 32; and, perform a power-failure recovery operation according to the data type of the last cached data, so that the flash memory device 1 maintains a working state other than disk-off in the power-on state;
[0090] Before the flash memory device 1 performs the power-failure recovery operation, it is further configured to write user data into the user cache block 31; and, after the user cache block 31 is full, write the data in the user cache block 31 into the user storage block 51 according to a first mapping table; and, update the first mapping table according to the user free blocks in the user storage block 51;
[0091] Before the flash memory device 1 performs the power-down recovery operation, it is also used to write management data into the management cache block 32; and, after the management cache block 32 is full, write the data in the management cache block 32 into the management storage block according to the second mapping relationship table; and update the second mapping relationship table according to the management free blocks in the management storage block 32.
[0092] Among them, the management data includes key data that can cause the flash memory device to experience disk dropout in an unreliable state.
[0093] It can be seen that in the embodiments of the present application, compared with the existing power-down recovery mechanism of the mapping table, the present application performs exclusive partition identification and recovery processing on the key data that causes disk dropout, so as to realize the function of the flash memory device not experiencing disk dropout during power-down recovery. Specifically, the device takes the partition management of the cache interval and storage partition of user data and management data that can cause disk dropout problems as a prerequisite for power-down data recovery. On the one hand, it can quickly identify the unreliable data during power-down as management data when powering on again. On the other hand, through the design concept of partition management, when the flash memory device determines the first management storage block to which the unreliable data belongs, it only needs to perform a power-down recovery operation on the management data in this storage partition, reducing unnecessary processing operations for other data and thus improving the processing efficiency of the power-down recovery mechanism.
[0094] It should be noted that for the foregoing method embodiments, for the sake of simple description, they are all expressed as a series of action combinations. However, those skilled in the art should know that the present application is not limited by the described action sequence, because according to the present application, certain steps can be performed in other sequences or simultaneously. Secondly, those skilled in the art should also know that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily essential to the present application.
[0095] In the above embodiments, the descriptions of each embodiment have their own emphases. For the parts not detailed in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0096] In several embodiments provided by the present application, it should be understood that the disclosed device can be implemented in other ways. For example, the device embodiments described above are only illustrative. For example, the above-mentioned unit division is only a logical function division. In actual implementation, there can be other division methods. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point, the displayed or discussed coupling or direct coupling or communication connection to each other can be through some interfaces. The indirect coupling or communication connection of the device or unit can be in an electrical or other form.
[0097] The units described above as separate components may or may not be physically separated. The components shown as units may or may not be physical units, that is, they may be located in one place or distributed over multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0098] In addition, in each embodiment of the present application, the various functional units may be integrated in a processing unit, may exist separately as individual physical units, or two or more units may be integrated in one unit. The above integrated units may be implemented in the form of hardware or in the form of software functional units.
[0099] If the above integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable memory. Based on this understanding, the technical solution of the present application, in essence, or the part that contributes to the prior art, or all or part of this technical solution, can be embodied in the form of a software product. This computer software product is stored in a memory and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the above methods in each embodiment of the present application. The aforementioned memory includes: USB flash drives, read-only memories (ROMs), random access memories (RAMs), external hard drives, magnetic disks, or optical discs and other media that can store program codes.
[0100] Those of ordinary skill in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructing relevant hardware through a program. This program can be stored in a computer-readable memory. The memory may include: flash drives, read-only memories (abbreviated as ROM in English), random access memories (abbreviated as RAM in English), magnetic disks, or optical discs, etc.
[0101] The above has introduced the embodiments of the present application in detail. Specific examples are used in this article to elaborate on the principle and implementation manner of the present application. The description of the above embodiments is only used to help understand the method and its core idea of the present application; at the same time, for those of ordinary skill in the art, according to the idea of the present application, there will be changes in the specific implementation manner and application scope. In summary, the content of this specification should not be construed as a limitation to the present application.
Claims
1. A flash memory power failure processing method, characterized in that: Applied to a flash memory device, the flash memory device includes a flash memory controller, a flash memory cache module and a flash memory storage module, the flash memory cache module includes a user cache block and a management cache block, the flash memory storage module includes a user storage block and a management storage block; the method includes: When an abnormal power failure is detected, query the block type of the cache block interrupted during the abnormal power failure; when the block type is the management cache block, obtain the data type of the last cached data in the interrupted management cache block; and perform a power failure recovery operation according to the data type of the last cached data; Before performing a power-off recovery operation, the flash memory device is used to write user data into the user cache block; and after the user cache block is full, update the user storage block with the data of the user cache block according to a first mapping relationship table; and update the first mapping relationship table; Before performing a power-off recovery operation, the flash memory device is also used to write management data into the management cache block; and after the management cache block is full, update the management storage block with the data of the management cache block according to a second mapping table; and update the second mapping table.
2. The method according to claim 1, characterized in that The management data includes data of a mapping table of the flash memory device, wherein the mapping table is a data table recording a correspondence between a logical block address of a file system of a host device and a physical page address of the flash memory device, and the host device is in communication connection with the flash memory device; The performing a power-off recovery operation according to the data type of the last cached data includes: In a case where the data type of the last cached data is the data of the mapping table, querying the flash memory snapshot table according to the first time node of the last cached data, and obtaining a first mapping table snapshot at a second time node in the flash memory snapshot table that has the shortest interval with the first time node; Scanning a management storage block between a second management storage block corresponding to the first mapping table snapshot and the first management storage block to obtain a first mapping relationship; Update the first mapping table snapshot according to the first mapping relationship to obtain the updated mapping table; Performing an erase operation on a first management storage block associated with the last cached data to obtain an erase result; If the erasing result is an erasure failure, marking the first management storage block as a bad block, and updating the second mapping relationship table and the bad block table of the flash memory device according to the bad block; If the erasing result is that the erasing is successful, the second mapping relationship table is updated according to the idle state of the first management storage block.
3. The method according to claim 2, characterized in that The management data includes data of a bad block table of the flash memory device; the method further includes: In the case where the data type of the last cached data is the data in the bad block table, querying the flash log to obtain the operation type in the operation record entry associated with the last cached data and the first management storage block as the operation object block; The bad block table and the second mapping relationship table are updated according to the operation type and the first management storage block.
4. The method according to claim 3, characterized in that The updating of the bad block table and the second mapping relationship table according to the operation type and the first management storage block includes: Detecting that the operation type is an erase operation; Marking the first management storage block as a bad block; The bad block table and the second mapping relationship table are updated according to the marked bad blocks.
5. The method according to claim 3, characterized in that: The updating of the bad block table and the second mapping relationship table according to the operation type and the first management storage block includes: Detecting that the operation type is an erase operation; Performing an erase operation on the first management storage block to obtain an erase result; If the erasing result is an erasure failure, marking the first management storage block as a bad block; and updating the bad block table and the second mapping relationship table according to the marked bad block; If the erasing result is that the erasing is successful, the second mapping relationship table is updated according to the idle state of the first management storage block.
6. The method according to claim 4 or 5, characterized in that: The method further comprises: Detecting that the operation type is a write operation; Reclaiming valid data in the first management storage block; Performing an erase operation on the first management storage block to obtain an erase result; If the erasing result is an erasure failure, marking the first management storage block as a bad block; and updating the bad block table and the second mapping relationship table according to the marked bad block; If the erasing result is that the erasing is successful, the second mapping relationship table is updated according to the idle state of the first management storage block.
7. The method according to claim 4 or 5, characterized in that: The method further comprises: Detecting that the operation type is a read operation; Performing a read operation on the first management storage block to obtain a read result; If the reading result is a reading failure, marking the first management storage block as a bad block; and updating the bad block table and the second mapping relationship table according to the marked bad block; If the reading result is a successful reading, the current states of the bad block table and the second mapping relationship table are maintained.
8. The method according to any one of claims 1 to 5, characterized in that: The method further comprises: In the case where the block type is the user cache block, obtaining the operation type in the operation record entry associated with the last cached data and the first user storage block as the operation object block; If the operation type is a write operation, marking the first user storage block as a garbage block; and performing a data recovery operation on the first user storage block according to a garbage recovery strategy; and updating the first mapping relationship table according to the user storage block after the data recovery operation; If the operation type is not a write operation, the first mapping relationship table is maintained.
9. The method according to claim 8, characterized in that If the power-off state is multiple consecutive power-offs, the cache block interrupted by the power-off state is the cache block interrupted by the first power-off of the multiple consecutive power-offs.
10. A flash memory power failure processing system, characterized in that: The flash memory power-off processing system comprises a host and a flash memory device, wherein the host is in communication connection with the flash memory device, the flash memory device comprises a flash memory controller, a flash memory cache module and a flash memory storage module, the flash memory cache module comprises a user cache block and a management cache block, and the flash memory storage module comprises a user storage block and a management storage block; wherein, The flash memory device is used to detect an abnormal power failure, query the block type of the cache block interrupted during the power failure; and, when the block type is the management cache block, obtain the data type of the last cached data in the interrupted management cache block; and perform a power failure recovery operation according to the data type of the last cached data; Before the flash memory device performs the power-off recovery operation, the flash memory device is further used to write user data into the user cache block; and after the user cache block is full, update the user storage block with the data of the user cache block according to the first mapping relationship table; and update the first mapping relationship table; Before the flash memory device performs the power-off recovery operation, it is also used to write management data into the management cache block; and after the management cache block is full, update the management storage block with the data of the management cache block according to the second mapping table; and update the second mapping table.