CN117909141A - Data backup method, device and medium for system power failure - Google Patents

Data backup method, device and medium for system power failure Download PDF

Info

Publication number
CN117909141A
CN117909141A CN202410141655.4A CN202410141655A CN117909141A CN 117909141 A CN117909141 A CN 117909141A CN 202410141655 A CN202410141655 A CN 202410141655A CN 117909141 A CN117909141 A CN 117909141A
Authority
CN
China
Prior art keywords
flash memory
data
backup
address
bad block
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202410141655.4A
Other languages
Chinese (zh)
Inventor
张唯
宁宁
陈佑炳
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shandong Yunhai Guochuang Cloud Computing Equipment Industry Innovation Center Co Ltd
Original Assignee
Shandong Yunhai Guochuang Cloud Computing Equipment Industry Innovation Center Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shandong Yunhai Guochuang Cloud Computing Equipment Industry Innovation Center Co Ltd filed Critical Shandong Yunhai Guochuang Cloud Computing Equipment Industry Innovation Center Co Ltd
Priority to CN202410141655.4A priority Critical patent/CN117909141A/en
Publication of CN117909141A publication Critical patent/CN117909141A/en
Pending legal-status Critical Current

Links

Landscapes

  • Techniques For Improving Reliability Of Storages (AREA)

Abstract

The invention discloses a data backup method, a device and a medium when a system is powered down, which are applied to the technical field of computers. If the computer system is powered down, the power supply unit is used for supplying power to the computer system, acquiring data in a volatile memory of the computer system at the current moment, and then backing up the acquired data to a flash memory, wherein a flash memory page with writing failure possibly occurs in the backup process, and the flash memory page with writing failure needs to be skipped for continuous backup so as to save time; temporary storage of the address of the flash page which fails to be written by using the power-down protection mark is convenient for neglecting invalid flash pages when the data is read subsequently; and adds the current block with flash pages corresponding to the number of flash pages failed to write to keep the block size unchanged. The method does not need address mapping and bad block data migration during backup, but skips the flash memory pages with failed writing, and the method has the beneficial effects of saving the time consumed by bad block management during backup, thereby improving the data backup rate.

Description

Data backup method, device and medium for system power failure
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a method, an apparatus, and a medium for data backup when a system is powered down.
Background
Volatile memory is commonly used as data cache in computer architecture, and data in the volatile memory may be lost when power failure occurs, so that backup is required. When the system is powered down, the data in the volatile memory is stored in the nonvolatile memory, and the data backup is generally realized by adopting a flash memory, but bad blocks possibly appear in the flash memory, and the bad block management is needed. At present, in the process of data backup, if a write failure error occurs when writing a certain flash page in a certain flash block, the block needs to be marked as a bad block, then address mapping is performed on the bad block, all valid data written in the bad block are migrated to a good block, and then the data is continuously written in the good block.
Because the standby unit is used for supplying power when power is lost, the standby unit stores limited electric energy, and thus unnecessary operations are required to be reduced as much as possible in the standby stage. The above bad block management operation consumes much time and power during the power down protection process of competing seconds.
Therefore, how to reduce the time consumed by bad block management during backup to increase the data backup rate is a problem to be solved by those skilled in the art.
Disclosure of Invention
The invention aims to provide a data backup method, a device and a medium when a system is powered down, so as to solve the problem of low data backup rate caused by long consumed time for bad block management at present.
In order to solve the technical problems, the invention provides a data backup method when a system is powered down, comprising the following steps:
monitoring a power supply state of a power supply of the computer system;
if the computer system is powered down, the standby power unit is used for supplying power to the computer system, and data in a volatile memory of the computer system at the current moment are obtained;
Backing up the acquired data to a flash memory; if the flash memory page with the writing failure exists in the backup process, continuing to backup the flash memory page with the writing failure in a skipping manner; and temporarily storing the address of the flash memory page with the writing failure by using the power-down protection mark, and adding the flash memory page with the current block by the quantity corresponding to the flash memory page with the writing failure.
In another aspect, the power down protection flag includes: a flag head and a flag body; wherein, the mark head is stored in the fixed address of the flash memory;
The marker head at least comprises the following information: the method comprises the steps of marking an identification code, marking creation time, a data address needing to be backed up, a data size needing to be backed up, an address for storing backup data in a flash memory and an address of a marking text;
the logo text at least comprises the following information: the current backed-up data size, the address of the flash memory page with writing failure, the backup completion identification and the address of the flash memory page with reading failure when writing failure.
On the other hand, backing up the acquired data to a flash memory; if the flash memory page with the writing failure exists in the backup process, continuing to backup the flash memory page with the writing failure in a skipping manner; and temporarily storing the address of the flash memory page with the writing failure by using the power-down protection mark, and adding the flash memory page with the current block corresponding to the number of the flash memory pages with the writing failure, further comprises:
if the computer system is powered on again, the mark head of the power-down protection mark is read from the fixed address in the flash memory;
positioning the mark text according to the address of the mark text stored in the mark head;
Reading the mark text according to the positioning result;
determining the flash memory page with the writing failure according to the current backed-up data size and the flash memory page address with the writing failure in the marking body;
positioning the backup data according to the address of the backup data stored in the flash memory stored in the mark head;
Reading the backup data in the flash memory according to the positioning result, and skipping the flash memory page with failed writing in the reading process;
determining an original address for storing the backup data in the volatile memory of the computer system;
And restoring the read backup data in the flash memory to the original address of the volatile memory of the computer system.
On the other hand, after the backup data in the flash memory is read according to the positioning result and the flash memory page with the write failure is skipped in the reading process, the method further comprises:
checking the read backup data through a check code to obtain the number of error bits of the data;
Comparing the number of error bits of the data in the read block with an error threshold;
if the number of error bits in the data in the read block exceeds the error threshold, determining that the corresponding block is a bad block; wherein the threshold is determined from an upper error correction limit of the error correction code.
On the other hand, after determining that the corresponding block is a bad block if the number of error bits in the data in the read block exceeds the error threshold, the method further includes:
judging whether the bad block address determined to be a bad block exists in a current bad block table;
if the bad block address exists in the current bad block table, skipping the corresponding bad block address;
if the bad block address does not exist in the current bad block table, creating a new bad block mapping relation and updating the bad block table;
And carrying bad block data in the bad blocks to the corresponding good blocks according to the newly created bad block mapping relation.
On the other hand, backing up the acquired data to a flash memory; if the flash memory page with the writing failure exists in the backup process, continuing to backup the flash memory page with the writing failure in a skipping manner; and temporarily storing the address of the flash memory page with the writing failure by using the power-down protection mark, and adding the flash memory page with the current block corresponding to the number of the flash memory pages with the writing failure, further comprises:
Triggering a backup data protection program;
sending a write protection instruction to the flash memory; the flash memory enters a write-protection state after receiving the write-protection instruction;
before the bad block data in the bad blocks is carried to the corresponding good blocks according to the newly created bad block mapping relation, the method further comprises:
Triggering a backup data protection release program;
sending a write protection release instruction to the flash memory; and the flash memory releases the write protection state after receiving the write protection release instruction.
On the other hand, the mark head is stored in a first block in the flash memory;
if the computer system is powered on again, reading the flag head of the power-down protection flag from the fixed address in the flash memory includes:
if the computer system is powered on again, the mark head of the power-down protection mark is read from the first block in the flash memory.
In order to solve the technical problem, the present invention further provides a data backup device when the system is powered down, including:
The monitoring module is used for monitoring the power supply state of the power supply of the computer system;
The acquisition module is used for supplying power to the computer system by using the standby power unit if the computer system is powered down, and acquiring data in a volatile memory of the computer system at the current moment;
the backup module is used for backing up the acquired data to the flash memory; if the flash memory page with the writing failure exists in the backup process, continuing to backup the flash memory page with the writing failure in a skipping manner; and temporarily storing the address of the flash memory page with the writing failure by using the power-down protection mark, and adding the flash memory page with the current block by the quantity corresponding to the flash memory page with the writing failure.
On the other hand, the data backup device when the system is powered down further comprises: the reading module is used for reading the mark head of the power-down protection mark from the fixed address in the flash memory if the computer system is powered on again;
the positioning module is used for positioning the mark text according to the address of the mark text stored in the mark head;
the reading module is also used for reading the mark text according to the positioning result;
the determining module is used for determining the flash memory page with the writing failure according to the current backed-up data size and the flash memory page address with the writing failure in the marking body;
the positioning module is further configured to position the backup data according to an address of the backup data stored in the flash memory stored in the flag head;
the reading module is further used for reading the backup data in the flash memory according to the positioning result, and skipping the flash memory page with failed writing in the reading process;
The determining module is further configured to determine an original address in the volatile memory of the computer system, where the original address is used to store the backup data;
and the recovery module is used for recovering the backup data in the read flash memory to the original address of the volatile memory of the computer system.
On the other hand, the data backup device when the system is powered down further comprises: the verification module is used for verifying the read backup data through a verification code to obtain the error bit number of the data after the backup data in the flash memory are read according to the positioning result and the flash memory pages which fail to be written are skipped in the reading process;
the comparison module is used for comparing the error bit number of the data in the read block with an error threshold value;
The determining module is further configured to determine that the corresponding block is a bad block if the number of error bits in the data in the read block exceeds the error threshold; wherein the threshold is determined from an upper error correction limit of the error correction code.
On the other hand, the data backup device when the system is powered down further comprises: the judging module is used for judging whether the bad block address of the determined bad block exists in the current bad block table after determining that the corresponding block is the bad block if the error bit number of the data in the read block exceeds the error threshold value; if the bad block address exists in the current bad block table, skipping the corresponding bad block address; if the bad block address does not exist in the current bad block table, creating a new bad block mapping relation and updating the bad block table;
and the carrying module is used for carrying bad block data in the bad blocks to the corresponding good blocks according to the newly created bad block mapping relation.
On the other hand, the data backup device when the system is powered down further comprises: the triggering module is used for triggering a backup data protection program after the acquired data is backed up to the flash memory;
The sending module is used for sending a write-protection instruction to the flash memory; the flash memory enters a write-protection state after receiving the write-protection instruction;
The triggering module is further configured to trigger a backup data protection cancellation procedure before the bad block data in the bad block is carried to the corresponding good block according to the newly created bad block mapping relationship;
The sending module is also used for sending a write protection releasing instruction to the flash memory; and the flash memory releases the write protection state after receiving the write protection release instruction.
In order to solve the technical problem, the present invention further provides a data backup device when the system is powered down, including: a memory for storing a computer program;
and the processor is used for realizing the data backup method when the system is powered down when executing the computer program.
In order to solve the technical problem, the invention also provides a computer readable storage medium, wherein the computer readable storage medium stores a computer program, and the computer program realizes the steps of the data backup method when the system is powered down when being executed by a processor.
According to the data backup method when the system is powered down, the processor of the computer system can monitor the power supply state of the power supply of the computer system in real time, if the power failure occurs in the computer system, the power supply unit is used for supplying power to the computer system, the data in the volatile memory of the computer system at the current moment are acquired, the data need to be backed up in time, and otherwise, the volatile memory can lose the data. Therefore, the obtained data are backed up to the flash memory, and the flash memory pages with writing failure possibly occur in the backup process, and the flash memory pages with writing failure need to be skipped for continuous backup so as to save time; temporary storage of the address of the flash page which fails to be written by using the power-down protection mark is convenient for neglecting invalid flash pages when the data is read subsequently; and adds the current block with flash pages corresponding to the number of flash pages failed to write to keep the block size unchanged. Compared with the scheme that the address mapping and the data migration of the bad blocks are carried out immediately after the flash memory pages which fail to be written in the data backup are originally carried out, the method does not need to carry out the address mapping and the data migration of the bad blocks in the backup, but skips the flash memory pages which fail to be written first.
In addition, the power-down protection mark for saving power-down information generally comprises a mark head and a mark text, and backup data can be quickly found when the data is recovered through the information contained in the mark head and the mark text. In practical application, the mark head is used for finding the mark text to determine the flash memory page with failed writing, and the mark head is used for finding the backup data to restore the data. After the data is read, the data is checked to obtain the error bit number of the data in the flash memory block, so that the flash memory block which is a bad block is found, and the data loss caused by the continued use of the bad block is avoided. After determining a flash block as a bad block, creating a new bad block mapping relationship to update the bad block table and handling the data to the good block to avoid data loss. After the data backup is completed, an instruction is sent to enable the flash memory to enter a write protection state, so that the original data is prevented from being lost due to misoperation on the backup data, and the write protection state is released during data migration, so that the data migration is normally performed. The mark head is stored in the first block in the flash memory, so that the mark head can be found out quickly to recover data.
The invention also provides a data backup device and a computer readable storage medium when the system is powered down, which correspond to the method, so that the method has the same beneficial effects as the method.
Drawings
For a clearer description of embodiments of the present invention, the drawings that are required to be used in the embodiments will be briefly described, it being apparent that the drawings in the following description are only some embodiments of the present invention, and other drawings may be obtained according to the drawings without inventive effort for those skilled in the art.
FIG. 1 is a diagram illustrating a conventional method for managing bad blocks of a flash memory;
FIG. 2 is a flowchart of a method for backing up data when a system is powered down according to an embodiment of the present invention;
FIG. 3 is a schematic diagram of a method for managing bad blocks of a flash memory based on a power-down protection flag according to an embodiment of the present invention;
FIG. 4 is a schematic flow chart of a power-down data backup according to an embodiment of the present invention;
FIG. 5 is a schematic flow chart of power-on data recovery according to an embodiment of the present invention;
FIG. 6 is a schematic flow chart of a bad block management stage according to an embodiment of the present invention;
FIG. 7 is a block diagram of a data backup device when a system provided by an embodiment of the present invention is powered down;
fig. 8 is a block diagram of a data backup device when a system is powered down according to another embodiment of the present invention.
Detailed Description
The following description of the embodiments of the present invention will be made clearly and completely with reference to the accompanying drawings, in which it is apparent that the embodiments described are only some embodiments of the present invention, but not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by a person of ordinary skill in the art without making any inventive effort are within the scope of the present invention.
The core of the invention is to provide a data backup method, a device and a medium when a system is powered down, so as to solve the problem of low data backup rate caused by the fact that the consumed time of bad block management is long at present.
In order to better understand the aspects of the present invention, the present invention will be described in further detail with reference to the accompanying drawings and detailed description.
Volatile memory, such as random access memory (Random Access Memory, RAM), is commonly used as a data cache in computer systems because data stored in the volatile memory is lost due to power loss, and when power loss occurs, the data stored in the volatile memory is not protected, which may result in data loss. The spare battery unit (Battery Backup Unit, BBU) is a widely applied power-down protection method, namely, when power failure occurs, the spare battery unit is used for supplying power to the system, and the system stores data in the volatile memory into the nonvolatile memory. Because the power storage of the standby power unit is limited, unnecessary operations need to be reduced as much as possible in the standby power stage, so as to save power consumption, save more data as much as possible or reduce the implementation cost of power-down protection. Nand flash memory and Nor flash memory are both nonvolatile memories, and data stored therein is not lost due to power loss. Compared with Nor flash memory, nand flash memory has faster writing and erasing speeds, higher storage density and lower equipment cost, and is more suitable for power failure protection, however, nand flash memory has bad blocks in the factory and use processes, and the bad blocks need to be managed to avoid data loss. FIG. 1 is a diagram illustrating a conventional method for managing bad blocks of a flash memory; as shown in fig. 1, in the conventional bad block management method, data is backed up from other memories to a flash memory, if a write failure error occurs when writing a certain flash page in a certain flash block, the block needs to be marked as a bad block, address mapping is performed on the bad block, and all the written effective data is migrated to the good block, so that the data can be written continuously. While the above bad block management operation consumes much time and power during the power down protection process of competing seconds.
Therefore, in the conventional bad block management method, when a bad block is found, the bad block address needs to be mapped first, and bad block data is migrated to a good block, and then the data writing operation can be continued, so that the data backup rate is directly affected by the above bad block management operation. Aiming at the problem, the embodiment of the invention provides a data backup method when a system is powered down; FIG. 2 is a flowchart of a method for backing up data when a system is powered down according to an embodiment of the present invention; as shown in fig. 2, the method comprises the steps of:
s10: the power supply state of the computer system is monitored.
S11: if the computer system is powered down, the standby power unit is used for supplying power to the computer system, and data in a volatile memory of the computer system at the current moment are obtained.
S12: backing up the acquired data to a flash memory; if the flash memory page with the writing failure exists in the backup process, continuing to backup the flash memory page with the writing failure in a skipping manner; and temporarily storing the address of the flash page with the writing failure by using the power-down protection mark, and increasing the current block by the flash pages corresponding to the flash page with the writing failure.
The embodiment of the invention provides a flash memory bad block management method based on a power-down protection mark, which is characterized in that when a system is powered down, important data in a volatile memory is backed up to Nand flash memory, a flash memory page address which fails to be written is temporarily stored by the power-down protection mark, and the page is skipped to continue backup. After the system is powered on again and data is recovered, the temporary stored page address is used for updating the bad block table, and mapping and data migration of the bad blocks are realized. Compared with the traditional scheme, the method does not need to update the bad block table and migrate the bad block data during backup, saves the time consumed by bad block management during backup, and improves the data backup rate.
FIG. 3 is a schematic diagram of a method for managing bad blocks of a flash memory based on a power-down protection flag according to an embodiment of the present invention; as shown in fig. 3, to realize the functions of recording power-down information and temporarily storing the address of a flash page with write failure, and to facilitate the recovery of data when the system is powered on, the power-down protection flag is divided into two parts: a flag header and a flag body. The mark head consists of various information generated when power failure occurs and is required to be stored in a fixed address of the flash memory, such as a first block of the flash memory; and the latest power-down protection mark can be determined by means of the mark identification code and the mark creation time, and after the system is powered on, mark text and backup data can be quickly found by reading the mark head positioned at a fixed position, so that data recovery is completed. The mark text is used for recording various information generated in the data backup and recovery process. The method comprises the steps of when writing fails, the current backed-up data size, the flash page address, the backup completion identification and the flash address which needs to be marked as a bad block. By reading the mark text, the skipped flash memory pages during backup can be rapidly positioned, whether the backup is completed or not can be confirmed, and data recovery, bad block address mapping and data migration can be performed.
Based on the power-down protection mark, the system power-down protection process can be divided into three sub-processes: a power-down data backup flow, a power-up data recovery flow and a bad block management flow. Compared with the traditional bad block management method for data backup, the optimized power-down data backup flow does not contain the steps of updating bad block tables and migrating bad block data, so that the time consumed by executing the steps in the backup process is saved, and the data backup rate is improved.
The method comprises the following specific processes: when power failure occurs, a power failure protection mark is created; writing important data in the volatile memory into the Nand flash memory according to the bad block mapping table; if the write failure is detected, continuing to backup the flash memory address, recording the flash memory address in the mark body, and repeating the step until all data backup is completed.
When the system is powered on, a power-down protection mark is read; skipping the recorded mark address of the bad block, and recovering the data in the Nand flash memory into the volatile memory; if it is determined that a bad block may be about to occur in the process, the address is recorded in the flag body, and the step is repeated until all data recovery is completed.
If the mark address of the bad block exists in the mark text, updating the bad block table and migrating the bad block data after the data recovery is completed. Firstly, calculating the marked address of a bad block to obtain a bad block address; mapping the bad block address to the good block, and finally sequentially migrating the data stored in the bad block to the good block.
The three parts of the power-down data backup, the power-up data recovery and the bad block management stage are respectively described below. FIG. 4 is a schematic flow chart of a power-down data backup according to an embodiment of the present invention; as shown in fig. 4, the method comprises the following steps: s20: unexpected power failure. S21: a power down protection flag is created. S22: the flag is written into the flash memory. S23: data is carried to the flash memory address. S24: judging whether the flash memory is successfully written; if yes, the process proceeds to step S26, and if no, the process proceeds to step S25. S25: the flash memory address is increased by one page size, and the flag body is updated. S26: judging whether the data address to be backed up is traversed; if yes, the process proceeds to step S27, and if no, the process returns to step S23. S27: the flag text is written into the flash memory. S28: flash write protection.
When the occurrence of unexpected power failure is detected, the identification code of the mark, the creation time of the mark, the data address to be backed up, the data size to be backed up, the data address stored in the flash memory, the address of the mark text and other power failure information are recorded in the mark head, and the mark head is written into the flash memory. The data to be backed up is transferred from the volatile memory to the flash memory, and the executor of the transfer operation may be a central processing unit (Central Processing Unit, CPU), direct memory access (Direct Memory Access, DMA) or a flash memory controller.
If the flash memory fails to write in the data carrying process, judging that a bad block appears, and recording the address of the bad block. The method comprises the following steps: if the flash memory fails to write, recording the current backed-up data size and the flash memory address in the mark text, increasing the flash memory address by one page size, keeping the data address unchanged and keeping the other parameters unchanged, and executing the data handling operation interrupted by the write failure again; similarly, if multiple pages are operated at a time, for example, a flash memory controller with descriptors is used to carry data, and multiple pages are operated with each descriptor, the change mode of the flash memory address can be changed to increase the data size of one operation, and the rest of the contents are unchanged. After all the data addresses are traversed, namely all the data to be backed up are carried into the flash memory, the backup completion identification is recorded in the mark body, and then the mark body is also written into the flash memory. And finally, sending a write-protection instruction to the flash memory to enable the flash memory to enter a write-protection state. In the above steps, the flag head needs to be stored in a fixed position of the flash memory, so that the flag head can be found out quickly after the system is powered on, and the flag text and the backup data can be found out. Correspondingly, the mark text and the backup data can be stored in any position of the flash memory, and the space of the flash memory is fully utilized.
FIG. 5 is a schematic flow chart of power-on data recovery according to an embodiment of the present invention; as shown in fig. 5, the method comprises the following steps: s30: and (5) powering up and initializing. S31: and reading the power-down protection mark. S32: and the flash memory address recorded in the body of the skip mark restores the data from the flash memory to the original data address. S33: judging whether the number of error bits of the read data is close to the upper limit of error correction; if yes, the process proceeds to step S34, and if no, the process proceeds to step S35. S34: the flash address is recorded in the tag body. S35: and judging whether the backup data address is traversed. S36: the data recovery is completed.
And (3) electrifying the system again, reading the mark head stored in the fixed position of the flash memory after the flash memory controller and the flash memory are initialized, and finding and reading the mark text according to the mark head. And skipping the flash page address recorded in the mark text and having failed writing, and sequentially recovering the data from the flash memory to the original data address in the volatile memory until all the data are recovered. The executor of the handling operation may be a CPU, DMA or flash controller. If the number of error bits detected during reading the flash memory in the above step is close to the upper error correction limit of the error correction code, it needs to be marked as a bad block, i.e. the flash memory address is recorded in the flag body for the processing of the subsequent bad block management stage.
FIG. 6 is a schematic flow chart of a bad block management stage according to an embodiment of the present invention; as shown in fig. 6, the method comprises the following steps: s40: and releasing the flash memory write protection. S41: and carrying out masking operation on the marked addresses of the bad blocks of the flash memory to obtain bad block addresses. S42: judging whether the bad block address exists in a bad block table or not; if yes, the process proceeds to step S44, and if no, the process proceeds to step S43. S43: a new bad block mapping relationship is created. S44: judging whether the traversal of the marked address of the bad block of the flash memory is completed or not; if yes, the process proceeds to step S45, and if no, the process returns to step S41. S45: bad block data is handled to good blocks.
And sending a write protection releasing instruction to the flash memory to release the write protection state of the flash memory. And carrying out mask operation on the mark address of the bad block recorded in the mark text to obtain the bad block address. If the bad block address exists in the bad block table, skipping the bad block address; otherwise, a new bad block mapping relationship is created. The method comprises the following steps: if in the row address of some Nand flash memory, [11:0] bit represents page address, [22:12] bit represents block address, [26:24] bit represents LUN address, then the tag address and 0xFFFFF000 do AND operation, and [31:12] bit is fetched to obtain the corresponding bad block address. Setting the obtained bad block address as 0xCE, and the spare good block address as 0xFE, if 0xCE is recorded in the bad block table, skipping the bad block address; if not, a mapping relationship from 0xCE to 0xFE is created and the bad block table is updated. And carrying bad block data in the bad blocks to good blocks according to the new bad block mapping relation, and carrying out all subsequent operations pointing to 0xCE on 0 xFE.
According to the scheme provided by the invention, bad block mapping and bad block data migration operations are not needed during backup, so that the time consumed by bad block management during backup is saved, and the data backup rate is improved. The mark head is stored in a fixed position of the flash memory, and the mark text and the address of the backup data are stored, so that the backup data can be found out quickly after the system is electrified, and the data recovery is completed. Correspondingly, the mark text and the backup data can be stored in any position of the flash memory, and the space of the flash memory is fully utilized. The backup data is recovered preferentially in the power-on stage, then the write protection of the flash memory is released, and the subsequent bad block management operation is performed, so that the safety of the backup data is ensured. The technical key point of the invention is a flash memory bad block management method based on a power-down protection mark. When the system is powered down, the important data in the volatile memory is backed up to the Nand flash memory, the page address of the flash memory which fails to be written is temporarily stored by using the power-down protection mark, and the page is skipped to continue backup. After the system is powered on again and data is recovered, the temporary stored page address is used for updating the bad block table, and mapping and data migration of the bad blocks are realized.
According to the data backup method when the system is powered down, the processor of the computer system can monitor the power supply state of the power supply of the computer system in real time, if the power of the computer system is lost, the power supply unit is used for supplying power to the computer system, the data in the volatile memory of the computer system at the current moment are acquired, the data need to be backed up in time, and otherwise, the volatile memory loses the data. Therefore, the obtained data are backed up to the flash memory, and the flash memory pages with writing failure possibly occur in the backup process, and the flash memory pages with writing failure need to be skipped for continuous backup so as to save time; temporary storage of the address of the flash page which fails to be written by using the power-down protection mark is convenient for neglecting invalid flash pages when the data is read subsequently; and adds the current block with flash pages corresponding to the number of flash pages failed to write to keep the block size unchanged. Compared with the scheme that the address mapping and the data migration of the bad blocks are carried out immediately after the flash memory pages which fail to be written in the data backup are originally carried out, the method does not need to carry out the address mapping and the data migration of the bad blocks in the backup, but skips the flash memory pages which fail to be written first.
In a specific implementation, the power-down protection mark generally comprises a mark head and a mark text; the mark head is stored in a fixed address in the flash memory so as to be convenient for reading. The marker head at least comprises the following information: the method comprises the steps of marking identification codes, marking creation time, data addresses needing to be backed up, data sizes needing to be backed up, addresses for storing backup data in a flash memory and addresses of marking texts. The logo text comprises at least the following information: the method comprises the steps of when writing fails, the current backed-up data size, the writing failed flash page address, the backup completion identification and the reading failed flash page address. By the information contained in the tag head and the tag body in the embodiment, backup data can be quickly found when the data is restored. Wherein the flag may be stored in a first block of the flash memory; if the computer system is powered on again, the tag head of the power-down protection tag is read from the fixed address in the flash memory, and the tag head comprises: if the computer system is powered up again, the flag head of the power-down protection flag is read from the first block in the flash memory. In this embodiment, the flag is stored in the first block of the flash memory, so that the flag can be found out quickly to recover data.
Based on the specific contents of the tag header and the tag text mentioned above, the embodiment of the present application further includes, after backing up the acquired data to the flash memory: if the computer system is powered on again, the mark head of the power-down protection mark is read from the fixed address in the flash memory; locating the mark text according to the address of the mark text stored in the mark head; reading the mark text according to the positioning result; determining a flash memory page with writing failure according to the current backed-up data size and the flash memory page address with writing failure in the mark body; locating the backup data according to the address of the backup data stored in the flash memory stored in the mark head; reading backup data in the flash memory according to the positioning result, and skipping flash memory pages which fail to be written in the reading process; determining an original address for storing backup data in a volatile memory of a computer system; and restoring the read backup data in the flash memory to the original address of the volatile memory of the computer system. In the embodiment, the flag head is used for finding the flag text to determine the flash page with failed writing, and the flag head is used for finding the backup data to restore the data, so that the data can be quickly restored after the system is powered on again.
In order to ensure that defects occurring at the factory and during use do not affect normal function, the locations of the flash memories where defects occur need to be marked, and because the smallest unit erased by Nand flash memories is a block, these flash memory defects are often represented and handled using "bad blocks". Any of the following situations arises, which needs to be considered as bad: the block erase fails, the page write fails or the page read has too many data error bits, approaching the upper error correction limit. The flash memory has some defects when leaving the factory, and some new defects, such as some bit flipping and other problems, can be generated in the using process. To avoid the threat of such defects to data security, bad block tables and error correction codes are often used to protect the data. Error correction codes are typically written into flash memory pages along with the data, and after the error correction codes are operated on, bit errors in the data can be found and corrected to a certain extent. If the bit error of the data exceeds the upper limit of error correction of the error correction code, the error cannot be corrected, and the data is damaged. Based on this, the present embodiment proposes a scheme, in which after the backup data in the flash memory is read according to the positioning result, and after the flash memory page failed to be written is skipped in the reading process, the read backup data is further checked by the check code to obtain the error bit number of the data; comparing the number of error bits of the data in the read block with an error threshold; if the number of error bits in the data in the read block exceeds an error threshold, determining that the corresponding block is a bad block; wherein the threshold is determined from an upper error correction limit of the error correction code. After the data is read, the data is checked to obtain the number of error bits of the data in the flash memory block, so that the flash memory block which is a bad block is found, and the data loss caused by the continued use of the bad block is avoided.
For a segment of continuous flash memory space, if bad blocks appear in the space, in order to ensure that the addresses of the segment of flash memory space are still continuous, the bad blocks can be replaced by reserved spare blocks, the segment of address space is "stitched up", and the mapped good block addresses are actually accessed every time the user tries to access the addresses where the bad blocks are located again. The bad block table is a data structure for recording the mapping relation between the bad block and the good block, and is often stored in a fixed location of the flash memory, such as the first block of the flash memory. The embodiment provides a scheme, after determining that a corresponding block is a bad block if the number of error bits of data in a read block exceeds an error threshold, judging whether a bad block address of the determined bad block exists in a current bad block table; if the bad block address exists in the current bad block table, skipping the corresponding bad block address. If the bad block address does not exist in the current bad block table, creating a new bad block mapping relation and updating the bad block table; and carrying bad block data in the bad blocks to the corresponding good blocks according to the newly created bad block mapping relation. After determining that a flash memory block is a bad block, creating a new bad block mapping relation to update a bad block table and carrying data to the good block, so that data loss can be avoided.
In practical application, after the data backup of power failure is completed, the backup data may be misoperated to cause the original data to be damaged, so in this embodiment, after the acquired data is backed up to the flash memory, the backup data protection program is triggered to send a write protection instruction to the flash memory; the flash memory enters a write protection state after receiving the write protection instruction. Before carrying bad block data in the bad blocks to the corresponding good blocks according to the newly created bad block mapping relation, triggering a backup data protection canceling program to send a write protection canceling instruction to the flash memory; the flash memory releases the write protection state after receiving the write protection release instruction. After the data backup is completed, the embodiment sends the instruction to enable the flash memory to enter a write protection state, so that the original data is prevented from being lost due to misoperation on the backup data, and the write protection state is released during data migration, so that the data migration is normally performed.
The following explains the various terms mentioned in the present invention, the flash page is the minimum read/write unit of Nand flash, the block is the minimum erase unit of Nand flash, and several pages form a block. The LUN is a Nand flash memory unit, a plurality of blocks form a plane, and a plurality of planes form a LUN. Marking address of bad block: in the invention, a flash memory page address with the number of error bits close to the error correction upper limit of an error correction code during reading is called a bad block mark address during reading, and the flash memory page address with writing failure and the bad block mark address during reading are called a mark address of a bad block, which is called the mark address for short.
In the above embodiment, the detailed description is given to the data backup method when the system is powered down, and the invention also provides a corresponding embodiment of the data backup device when the system is powered down. It should be noted that the present invention describes an embodiment of the device portion from two angles, one based on the angle of the functional module and the other based on the angle of the hardware.
Based on the angle of the functional module, this embodiment provides a data backup device when the system is powered down, and fig. 7 is a structural diagram of the data backup device when the system is powered down, as shown in fig. 7, where the device includes:
The monitoring module 10 is used for monitoring the power supply state of the power supply of the computer system;
The acquiring module 11 is configured to supply power to the computer system by using the power backup unit if the computer system is powered down, and acquire data in a volatile memory of the computer system at the current moment;
A backup module 12, configured to backup the acquired data to the flash memory; if the flash memory page with the writing failure exists in the backup process, continuing to backup the flash memory page with the writing failure in a skipping manner; and temporarily storing the address of the flash page with the writing failure by using the power-down protection mark, and increasing the current block by the flash pages corresponding to the flash page with the writing failure.
Since the embodiments of the apparatus portion and the embodiments of the method portion correspond to each other, the embodiments of the apparatus portion are referred to the description of the embodiments of the method portion, and are not repeated herein.
In some embodiments, the data backup device when the system is powered down further comprises: the reading module is used for reading the mark head of the power-down protection mark from the fixed address in the flash memory if the computer system is powered on again;
The positioning module is used for positioning the mark text according to the address of the mark text stored in the mark head;
The reading module is also used for reading the mark text according to the positioning result;
The determining module is used for determining a flash memory page with writing failure according to the current backed-up data size and the flash memory page address with writing failure in the marking body;
The positioning module is also used for positioning the backup data according to the address of the backup data stored in the flash memory stored in the mark head;
the reading module is also used for reading backup data in the flash memory according to the positioning result, and skipping flash memory pages which fail to be written in the reading process;
the determining module is also used for determining the original address used for storing the backup data in the volatile memory of the computer system;
And the recovery module is used for recovering the read backup data in the flash memory to the original address of the volatile memory of the computer system.
In some embodiments, the data backup device when the system is powered down further comprises: the verification module is used for reading backup data in the flash memory according to the positioning result, and after skipping flash memory pages which fail to be written in the reading process, verifying the read backup data through a verification code to obtain the error bit number of the data;
the comparison module is used for comparing the error bit number of the data in the read block with an error threshold value;
the determining module is further used for determining that the corresponding block is a bad block if the number of error bits of the data in the read block exceeds an error threshold; wherein the threshold is determined from an upper error correction limit of the error correction code.
In some embodiments, the data backup device when the system is powered down further comprises: the judging module is used for judging whether the bad block address of the determined bad block exists in the current bad block table after determining that the corresponding block is the bad block if the number of error bits of the data in the read block exceeds an error threshold value; if the bad block address exists in the current bad block table, skipping the corresponding bad block address; if the bad block address does not exist in the current bad block table, creating a new bad block mapping relation and updating the bad block table;
And the carrying module is used for carrying bad block data in the bad blocks to the corresponding good blocks according to the newly created bad block mapping relation.
In some embodiments, the data backup device when the system is powered down further comprises: the triggering module is used for triggering a backup data protection program after the acquired data is backed up to the flash memory;
The sending module is used for sending a write-protection instruction to the flash memory; the flash memory enters a write-protection state after receiving a write-protection instruction;
the triggering module is also used for triggering a backup data protection release program before carrying bad block data in the bad blocks to the corresponding good blocks according to the newly created bad block mapping relation;
The sending module is also used for sending a write protection releasing instruction to the flash memory; the flash memory releases the write protection state after receiving the write protection release instruction.
The data backup device provided by the embodiment corresponds to the method when the system is powered down, so that the data backup device has the same beneficial effects as the method.
Based on the hardware angle, the embodiment provides another data backup device when the system is powered down, fig. 8 is a structural diagram of the data backup device when the system is powered down, which is provided in another embodiment of the present invention, as shown in fig. 8, where the data backup device when the system is powered down includes: a memory 20 for storing a computer program;
a processor 21 for implementing the steps of the data backup method at power down of the system as mentioned in the above embodiments when executing the computer program.
Processor 21 may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor 21 may be implemented in at least one hardware form of a digital signal processor (DIGITAL SIGNAL processor, DSP), field-programmable gate array (field-programmable GATE ARRAY, FPGA), programmable logic array (Programmable Logic Array, PLA). The processor 21 may also include a main processor, which is a processor for processing data in an awake state, also called CPU, and a coprocessor; a coprocessor is a low-power processor for processing data in a standby state. In some embodiments, the processor 21 may be integrated with an image processor (Graphics Processing Unit, GPU) for rendering and rendering of content to be displayed by the display screen. In some embodiments, the processor 21 may also include an artificial intelligence (ARTIFICIAL INTELLIGENCE, AI) processor for processing computing operations related to machine learning.
Memory 20 may include one or more computer-readable storage media, which may be non-transitory. Memory 20 may also include high-speed random access memory, as well as non-volatile memory, such as one or more magnetic disk storage devices, flash memory storage devices. In this embodiment, the memory 20 is at least used for storing a computer program 201, where the computer program, after being loaded and executed by the processor 21, can implement the relevant steps of the data backup method when the system disclosed in any of the foregoing embodiments is powered down. In addition, the resources stored in the memory 20 may further include an operating system 202, data 203, and the like, where the storage manner may be transient storage or permanent storage. Operating system 202 may include Windows, unix, linux, among other things. The data 203 may include, but is not limited to, data related to a data backup method when the system is powered down, and the like.
In some embodiments, the data backup device when the system is powered down may further include a display 22, an input/output interface 23, a communication interface 24, a power supply 25, and a communication bus 26.
Those skilled in the art will appreciate that the structures shown in the figures do not constitute a limitation on the data backup device when the system is powered down and may include more or less components than those shown.
The data backup device for the system power failure provided by the embodiment of the invention comprises a memory and a processor, wherein the processor can realize the following method when executing a program stored in the memory: a data backup method when the system is powered down.
The data backup device provided by the embodiment corresponds to the method when the system is powered down, so that the data backup device has the same beneficial effects as the method.
Finally, the invention also provides a corresponding embodiment of the computer readable storage medium. The computer-readable storage medium has stored thereon a computer program which, when executed by a processor, performs the steps as described in the method embodiments above.
It will be appreciated that the methods of the above embodiments, if implemented in the form of software functional units and sold or used as stand-alone products, may be stored on a computer readable storage medium. Based on such understanding, the technical solution of the present invention may be embodied essentially or in part or all of the technical solution contributing to the prior art, or may be embodied in the form of a software product stored in a storage medium, performing all or part of the steps of the method described in the various embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a read-only memory (ROM), a random access memory (Random Access Memory, RAM), a magnetic disk, or an optical disk, or other various media capable of storing program codes.
The computer readable storage medium provided in the present embodiment corresponds to the above method, and thus has the same advantageous effects as the above method.
The data backup method, the device and the medium for the system power failure provided by the invention are described in detail. In the description, each embodiment is described in a progressive manner, and each embodiment is mainly described by the differences from other embodiments, so that the same similar parts among the embodiments are mutually referred. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant points refer to the description of the method section. It should be noted that it will be apparent to those skilled in the art that the present invention may be modified and practiced without departing from the spirit of the present invention.
It should also be noted that in this specification, relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Moreover, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.

Claims (10)

1. The data backup method when the system is powered down is characterized by comprising the following steps:
monitoring a power supply state of a power supply of the computer system;
if the computer system is powered down, the standby power unit is used for supplying power to the computer system, and data in a volatile memory of the computer system at the current moment are obtained;
Backing up the acquired data to a flash memory; if the flash memory page with the writing failure exists in the backup process, continuing to backup the flash memory page with the writing failure in a skipping manner; and temporarily storing the address of the flash memory page with the writing failure by using the power-down protection mark, and adding the flash memory page with the current block by the quantity corresponding to the flash memory page with the writing failure.
2. The method for backing up data when a system is powered down according to claim 1, wherein the power-down protection flag comprises: a flag head and a flag body; wherein, the mark head is stored in the fixed address of the flash memory;
The marker head at least comprises the following information: the method comprises the steps of marking an identification code, marking creation time, a data address needing to be backed up, a data size needing to be backed up, an address for storing backup data in a flash memory and an address of a marking text;
the logo text at least comprises the following information: the current backed-up data size, the address of the flash memory page with writing failure, the backup completion identification and the address of the flash memory page with reading failure when writing failure.
3. The method for backing up data when the system is powered down according to claim 2, wherein the acquired data is backed up to a flash memory; if the flash memory page with the writing failure exists in the backup process, continuing to backup the flash memory page with the writing failure in a skipping manner; and temporarily storing the address of the flash memory page with the writing failure by using the power-down protection mark, and adding the flash memory page with the current block corresponding to the number of the flash memory pages with the writing failure, further comprises:
if the computer system is powered on again, the mark head of the power-down protection mark is read from the fixed address in the flash memory;
positioning the mark text according to the address of the mark text stored in the mark head;
Reading the mark text according to the positioning result;
determining the flash memory page with the writing failure according to the current backed-up data size and the flash memory page address with the writing failure in the marking body;
positioning the backup data according to the address of the backup data stored in the flash memory stored in the mark head;
Reading the backup data in the flash memory according to the positioning result, and skipping the flash memory page with failed writing in the reading process;
determining an original address for storing the backup data in the volatile memory of the computer system;
And restoring the read backup data in the flash memory to the original address of the volatile memory of the computer system.
4. The method for backing up data when power is turned off in the system according to claim 3, further comprising, after said reading the backup data in the flash memory according to the positioning result and skipping the flash memory page that fails to be written during the reading process:
checking the read backup data through a check code to obtain the number of error bits of the data;
Comparing the number of error bits of the data in the read block with an error threshold;
if the number of error bits in the data in the read block exceeds the error threshold, determining that the corresponding block is a bad block; wherein the threshold is determined from an upper error correction limit of the error correction code.
5. The method for backing up data when power is down of the system according to claim 4, wherein after determining that the corresponding block is a bad block if the number of error bits of the data in the read block exceeds the error threshold, further comprising:
judging whether the bad block address determined to be a bad block exists in a current bad block table;
if the bad block address exists in the current bad block table, skipping the corresponding bad block address;
if the bad block address does not exist in the current bad block table, creating a new bad block mapping relation and updating the bad block table;
And carrying bad block data in the bad blocks to the corresponding good blocks according to the newly created bad block mapping relation.
6. The method for backing up data when power is turned off in the system according to claim 5, wherein the acquired data is backed up to a flash memory; if the flash memory page with the writing failure exists in the backup process, continuing to backup the flash memory page with the writing failure in a skipping manner; and temporarily storing the address of the flash memory page with the writing failure by using the power-down protection mark, and adding the flash memory page with the current block corresponding to the number of the flash memory pages with the writing failure, further comprises:
Triggering a backup data protection program;
sending a write protection instruction to the flash memory; the flash memory enters a write-protection state after receiving the write-protection instruction;
before the bad block data in the bad blocks is carried to the corresponding good blocks according to the newly created bad block mapping relation, the method further comprises:
Triggering a backup data protection release program;
sending a write protection release instruction to the flash memory; and the flash memory releases the write protection state after receiving the write protection release instruction.
7. The method for backing up data when the system is powered down according to claim 3, wherein the flag is stored in a first block in the flash memory;
if the computer system is powered on again, reading the flag head of the power-down protection flag from the fixed address in the flash memory includes:
if the computer system is powered on again, the mark head of the power-down protection mark is read from the first block in the flash memory.
8. A data backup device when a system is powered down, comprising:
The monitoring module is used for monitoring the power supply state of the power supply of the computer system;
The acquisition module is used for supplying power to the computer system by using the standby power unit if the computer system is powered down, and acquiring data in a volatile memory of the computer system at the current moment;
the backup module is used for backing up the acquired data to the flash memory; if the flash memory page with the writing failure exists in the backup process, continuing to backup the flash memory page with the writing failure in a skipping manner; and temporarily storing the address of the flash memory page with the writing failure by using the power-down protection mark, and adding the flash memory page with the current block by the quantity corresponding to the flash memory page with the writing failure.
9. The data backup device when the system is powered down is characterized by comprising a memory for storing a computer program;
A processor for implementing the steps of the data backup method at power down of the system according to any one of claims 1 to 7 when executing the computer program.
10. A computer readable storage medium, characterized in that the computer readable storage medium has stored thereon a computer program which, when executed by a processor, implements the steps of the data backup method at power down of the system according to any of claims 1 to 7.
CN202410141655.4A 2024-01-31 2024-01-31 Data backup method, device and medium for system power failure Pending CN117909141A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202410141655.4A CN117909141A (en) 2024-01-31 2024-01-31 Data backup method, device and medium for system power failure

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202410141655.4A CN117909141A (en) 2024-01-31 2024-01-31 Data backup method, device and medium for system power failure

Publications (1)

Publication Number Publication Date
CN117909141A true CN117909141A (en) 2024-04-19

Family

ID=90687716

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202410141655.4A Pending CN117909141A (en) 2024-01-31 2024-01-31 Data backup method, device and medium for system power failure

Country Status (1)

Country Link
CN (1) CN117909141A (en)

Similar Documents

Publication Publication Date Title
US10552311B2 (en) Recovery for non-volatile memory after power loss
US6795890B1 (en) Data storage method, and data processing device using an erasure block buffer and write buffer for writing and erasing data in memory
EP3022740B1 (en) Erase management in memory systems
CN102043727B (en) Method and device for recovering solid-state hard disc mapping table
JP2002351685A (en) Data updating method and controller for nonvolatile memory
US20150331624A1 (en) Host-controlled flash translation layer snapshot
US7441085B2 (en) Memory control method for restoring data in a cache memory
CN110895514A (en) Mapping table updating method
KR20150017672A (en) Torn write mitigation
TWI633428B (en) Data storage device and methods for processing data in the data storage device
CN107239411B (en) Memory management method and system for vehicle-mounted controller
TW201411343A (en) Data storage device and control method for flash memory
GB2507961A (en) Back-up and restoration of data between volatile and flash memory
WO2023206968A1 (en) Data storage method and system, and computer readable storage medium
US20070277028A1 (en) Method and system for recovery from reprogramming failures in nonvolatile memory
US7257030B2 (en) Operating a storage component
CN113220221A (en) Memory controller and data processing method
CN117909141A (en) Data backup method, device and medium for system power failure
KR100654344B1 (en) Memory device using flash memory and error correction method the same
CN116027973A (en) Data writing method and device based on flash memory
CN112269531B (en) Source roll capacity reduction method, device, equipment and medium
CN114327292A (en) File management method, system, electronic device and storage medium
US7849279B2 (en) Method for the secure updating data areas in non volatile memory, device to perform such a method
JP5050508B2 (en) Storage device, storage device program, and storage processing method
JP2005056144A (en) Electronic apparatus loaded with flash memory, its memory data managing method, and program

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination