Non-volatile memory data storage management method, system, and electronic device

CN122777047APending Publication Date: 2026-09-18AUSTEN TECH BEIJING CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202610706805.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-05-21
Publication Date
2026-09-18

AI Technical Summary

Technical Problem

[0004]本发明的目的在于解决非易失性存储器在固定物理区域覆写时因局部损耗严重导致寿命受限,以及在数据写入过程中因突发断电导致参数逻辑不一致与数据损坏的技术问题,提供一种非易失性存储器数据存储管理方法、系统及电子设备

Benefits of technology

[0016]By configuring the physical page pool and page mapping table, and dynamically selecting the free physical storage page with the lowest wear count for writing during data updates, the decoupling of logical addresses and physical addresses and the global balance of erase and write operations are achieved. This avoids premature failure of local storage media due to frequent overwriting and extends the overall lifespan of non-volatile memory. At the same time, by introducing a status marking mechanism, the timing logic of first setting the target physical page to a pending state, then modifying it to a valid state after write verification and mapping relationship update is completed is strictly followed. This ensures absolute consistency of parameter logic under abnormal operating conditions such as sudden power outages, reducing the risk of data corruption and loss.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122777047A_ABST
    Figure CN122777047A_ABST
Patent Text Reader

Abstract

The application discloses a nonvolatile memory data storage management method and system and electronic equipment, and particularly relates to the technical field of nonvolatile memory management. The method comprises the following steps: in response to a data update instruction for a logical page, obtaining update data, and determining an idle physical storage page in a physical page pool with a state marker of an erased state; comparing wear count of each idle physical storage page in a page mapping table, and determining a physical storage page with minimum wear count as a target physical page; writing the update data and an updated version number into the target physical page, and setting a state marker of the target physical page from the erased state to a to-be-effective state; after the write operation on the target physical page is verified, updating a mapping relationship between the logical page and the target physical page in the page mapping table, and wear count of the target physical page; and after the page mapping table is updated, modifying the state marker of the target physical page from the to-be-effective state to an effective state.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of non-volatile memory management technology, and in particular to a non-volatile memory data storage management method, system, and electronic device. Background Technology

[0002] In embedded applications, non-volatile memory is typically used to store critical system parameters and configuration information. Conventional solutions often employ redundancy backup mechanisms based on pre-defined fixed physical regions, performing data rotation and overwriting on specific sectors. However, this management approach often suffers from severe localized wear and tear on the storage medium, limiting the overall lifespan of the memory. Furthermore, if a sudden power outage or other anomaly occurs during data writing, issues such as data read / verification failures, information corruption, or inconsistent parameter logic often arise.

[0003] The information disclosed in this background section is intended only to enhance the understanding of the overall background of the invention and should not be construed as an admission or in any way implying that the information constitutes prior art known to those skilled in the art. Summary of the Invention

[0004] The purpose of this invention is to solve the technical problems of limited lifespan of non-volatile memory due to severe local wear during overwriting of fixed physical areas, and inconsistent parameters and data corruption caused by sudden power outages during data writing. The invention provides a non-volatile memory data storage management method, system, and electronic device.

[0005] The first aspect of the present invention provides a data storage management method for non-volatile memory, wherein the non-volatile memory is pre-configured with a physical page pool and a page mapping table, the physical page pool includes a plurality of physical storage pages, each of the physical storage pages being configured with a status flag; the page mapping table records the mapping relationship between at least three logical pages and the physical storage pages, as well as the wear count and version number of each physical storage page; wherein the method includes: in response to a data update instruction for any of the at least three logical pages, acquiring update data, and determining a free physical storage page in the physical page pool whose status flag is erased; The wear counts of each free physical storage page in the page mapping table are compared, and the physical storage page with the lowest wear count is determined as the target physical page. The updated data and the updated version number are written to the target physical page, and the status flag of the target physical page is changed from erased to pending. After the write operation of the target physical page passes verification, the mapping relationship between the logical pages and the target physical page in the page mapping table, as well as the wear count of the target physical page, are updated. After the page mapping table is updated, the status flag of the target physical page is changed from pending to active.

[0006] In one embodiment of the present invention, the at least three logical pages are specifically a first logical page, a second logical page, and a third logical page. When updating data on the logical pages, the updates are performed sequentially in the order of the first logical page, the second logical page, and the third logical page. The method further includes: obtaining the addresses of the physical storage pages mapped to the first logical page, the second logical page, and the third logical page, and reading the data in each of the physical storage pages; performing validity checks on the data in each of the physical storage pages; comparing the version numbers of the data in each physical storage page that passes the check, and taking the data with the largest version number as the valid data of the logical page.

[0007] In one embodiment of the present invention, the page mapping table is stored in a pre-defined first mapping page and a second mapping page in a non-volatile memory; wherein, after the write operation to the target physical page passes verification, updating the mapping relationship between the logical page and the target physical page in the page mapping table, and the wear count of the target physical page, includes: obtaining the currently valid mapping page and the backup mapping page from the first mapping page and the second mapping page; writing the updated version number, the updated mapping relationship, and the wear count to the backup mapping page; and after the write operation to the backup mapping page passes verification, modifying the global startup flag to point to the backup mapping page.

[0008] In one embodiment of the present invention, the global boot flag occupies an independent minimum write unit.

[0009] In one embodiment of the present invention, the status marker further includes a pending reclamation status; after the page mapping table is updated, the method further includes: modifying the status marker of the old physical page to a pending reclamation status, wherein the old physical page is the physical storage page pointed to by the logical page before the page mapping table is updated.

[0010] In one embodiment of the present invention, the method further includes: in response to a power-on initialization operation, scanning the status flags of each physical storage page in the physical page pool; when there is a physical storage page with a status flag of pending activation, performing an integrity check on the data in the physical storage page, and determining the logical page corresponding to the physical storage page, as well as the physical storage page currently pointed to by the corresponding logical page in the page mapping table; if the check passes, and the version number of the physical storage page in the pending activation state is higher than the version number of the currently pointed-to physical storage page, then updating the mapping relationship of the corresponding logical page in the page mapping table to point to the physical storage page in the pending activation state, modifying its status flag to an effective state, and modifying the status flag of the currently pointed-to physical storage page to a pending reclamation state.

[0011] In one embodiment of the present invention, the method further includes: when the number of physical storage pages in the physical page pool that are marked as erased is lower than a preset threshold, performing an erase operation on the physical storage pages that are marked as pending recycling; and after successful erasure, resetting the status mark of the physical storage page to the erased state.

[0012] In one embodiment of the present invention, the status flag further includes a damaged state; the method further includes: when the erase operation fails, the write operation fails, or the post-write verification fails, modifying the status flag of the physical storage page to a damaged state.

[0013] A second aspect of the present invention provides a non-volatile memory data storage management system, wherein the non-volatile memory is pre-configured with a physical page pool and a page mapping table, the physical page pool includes multiple physical storage pages, each of the physical storage pages being configured with a status flag; the page mapping table records the mapping relationship between at least three logical pages and the physical storage pages, as well as the wear count and version number of each physical storage page; wherein the system includes: a first determining module, configured to, in response to a data update instruction for any of the at least three logical pages, acquire update data and determine free physical storage pages in the physical page pool whose status flag is erased; and a first counting module, configured to compare the wear counts and version numbers of each physical storage page. The wear count of the free physical storage pages in the page mapping table is used to determine the physical storage page with the smallest wear count as the target physical page; a first write module is used to write the updated data and the updated version number into the target physical page, and set the status flag of the target physical page from erased to pending status; a first update module is used to update the mapping relationship between the logical pages and the target physical page in the page mapping table and the wear count of the target physical page after the write operation of the target physical page passes the verification; a first processing module is used to change the status flag of the target physical page from pending status to valid status after the page mapping table is updated.

[0014] A third aspect of the present invention provides an electronic device, characterized in that it includes a non-volatile memory and a processor, the processor being configured to execute the non-volatile memory data storage management method as described in the first aspect.

[0015] Compared with the prior art, the technical effects achieved by the present invention are as follows:

[0016] By configuring the physical page pool and page mapping table, and dynamically selecting the free physical storage page with the lowest wear count for writing during data updates, the decoupling of logical addresses and physical addresses and the global balance of erase and write operations are achieved. This avoids premature failure of local storage media due to frequent overwriting and extends the overall lifespan of non-volatile memory. At the same time, by introducing a status marking mechanism, the timing logic of first setting the target physical page to a pending state, then modifying it to a valid state after write verification and mapping relationship update is completed is strictly followed. This ensures absolute consistency of parameter logic under abnormal operating conditions such as sudden power outages, reducing the risk of data corruption and loss. Attached Figure Description

[0017] Figure 1 This is a flowchart illustrating a non-volatile memory data storage management method according to an embodiment of the present invention; Figure 2 This is a schematic diagram of the framework of a non-volatile memory data storage management system according to an embodiment of the present invention; Figure 3 This is a schematic diagram of the frame of an electronic device according to an embodiment of the present invention. Detailed Implementation

[0018] Unless otherwise expressly stated, throughout the specification and claims, the term "comprising" or its variations such as "including" or "comprises" shall be understood to include the stated elements or components without excluding other elements or other components.

[0019] The technical solution of the present invention is illustrated below through specific embodiments. It should be understood that the one or more steps mentioned in the present invention do not preclude the existence of other methods and steps before or after the combined steps, or that other methods and steps may be inserted between these explicitly mentioned steps. It should also be understood that these examples are for illustrative purposes only and are not intended to limit the scope of the present invention. Unless otherwise stated, the numbering of each method step is only for the purpose of identifying each method step, and not for limiting the order of each method or limiting the scope of the present invention. Changes or adjustments to their relative relationships, without substantial changes to the technical content, can also be considered as within the scope of the present invention.

[0020] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions in the embodiments of this invention will be clearly and completely described below in conjunction with specific application scenarios. This embodiment uses the internal Flash memory of a microcontroller (MCU), which is common in the field of industrial control, as a typical representative of non-volatile memory for illustration. However, those skilled in the art will understand that the method of this invention is also applicable to EEPROM or other non-volatile storage media with similar physical characteristics.

[0021] One embodiment of the present invention relates to a non-volatile memory data storage management method. Before introducing the method, it is necessary to pre-configure the underlying management architecture in the non-volatile memory.

[0022] Specific sectors in the non-volatile memory are divided into physical page pools. Each physical page pool consists of a predetermined number (or more) of physical storage pages. In this embodiment, a physical storage page is the smallest unit for erasing and writing. To achieve fine-grained state management, a fixed metadata area is reserved in the header of each physical storage page for configuring a status flag. This status flag can reflect the current physical lifecycle stage of the physical storage page through specific magic words, such as erased, pending activation, valid, pending reclamation, or damaged.

[0023] In one example, when the system first powers on or formats non-volatile memory data, the processor MCU logically partitions the internal Flash memory. A contiguous physical space within the Flash memory is designated as a parameter storage area, containing several physical memory pages that form a physical page pool. The size of a single physical memory page is typically aligned with the MCU's smallest Flash erase unit, such as 1KB or 2KB. Several bytes are reserved at the beginning or end of each physical memory page for storing page management metadata, including at least a status flag field and fields for storing the version number and checksum.

[0024] Corresponding to the underlying physical space, the system abstracts at least three logical pages at the logical layer to store the same system parameters, thus constructing a three-page redundancy fault-tolerant mechanism. To establish a dynamic link between the logical and physical layers, a dedicated area is allocated in the non-volatile memory to store the page mapping table. The page mapping table is a data structure that records at least: the physical storage page addresses currently mapped to each of the multiple logical pages defined by the system; and the cumulative wear count of each physical storage page in the physical page pool. The mapping table itself also includes a version number and a checksum field to ensure the integrity of the mapping table itself.

[0025] In this embodiment, three logical pages are defined, denoted as logical page A, logical page B, and logical page C, respectively, to store the same parameter data in a redundant round-robin manner. The page mapping table maintains the physical addresses corresponding to logical page A, logical page B, and logical page C, respectively, as well as the wear count of each physical storage page in the physical page pool. In a preferred embodiment, the total number of physical pages in the physical page pool is greater than three to provide alternatives for dynamic mapping and wear leveling.

[0026] One embodiment of the present invention relates to a method for managing data storage in non-volatile memory, such as... Figure 1As shown, the method may specifically include the following steps: S101, in response to a data update instruction for any one of at least three logical pages, obtain update data and determine the free physical storage pages in the physical page pool whose status is marked as erased; In this embodiment, the updated data can be calibration parameters collected and processed by the sensor, or configuration information sent by the user through the communication interface.

[0027] The status flag field of each physical storage page in the physical page pool is traversed to filter out all physical storage pages whose current status is erased. In this embodiment, the status flag field uses specific hexadecimal encoding to represent different statuses. For example, the erased status corresponds to the default value of 0xFF after the physical storage page is erased at the factory, the pending activation status corresponds to 0xA5, the valid status corresponds to 0x5A, the pending recycling status corresponds to 0x3C, and the damaged status corresponds to 0x00. After identifying all physical storage pages in the erased state, all physical storage pages in the erased state are used as candidate pages.

[0028] S102, compare the wear counts of each free physical storage page in the page mapping table, and determine the physical storage page with the smallest wear count as the target physical page; In this embodiment, the wear count is an accumulated value, which is incremented by one each time the physical storage page is erased and the page mapping table is updated.

[0029] By querying the wear count of each candidate physical storage page in the page mapping table, the wear count values ​​of each candidate physical storage page are compared one by one, and the physical storage page with the smallest wear count is selected as the target physical storage page for this write operation. If multiple physical storage pages have the same smallest wear count, one can be selected according to physical address order or other predetermined strategies.

[0030] This selection mechanism ensures that the number of erases and writes of all physical storage pages in the physical page pool is balanced, preventing individual physical storage pages from reaching their lifespan limit prematurely due to concentrated use.

[0031] S103, write the updated data and the updated version number to the target physical page, and change the status flag of the target physical page from the erased state to the pending state; After identifying the target physical page, an erase operation is first performed on the target physical page to ensure that all storage units in the physical page are restored to their initial state. After the erase is complete, the received updated data is assembled according to a predetermined data structure.

[0032] In this embodiment, the parameter structure includes an incremented version number field (the updated version number), an array of actual parameter data to be stored (updated data), and a checksum field calculated based on the version number and parameter data. The checksum algorithm can adopt the CRC-16 / CCITT standard, and the calculation range covers all bytes of the version number and parameter data. The checksum itself is stored in the last two bytes of the physical storage page.

[0033] After assembly, the complete parameter structure data is written to the target physical page. After the write operation, the data is not immediately considered effective; instead, the status flag of the target physical page is changed from erased to pending activation. In the pending activation state, the data physically exists in the Flash memory, but the page mapping table has not yet been updated, and logically, the system still considers the data in the old physical page as valid.

[0034] S104, after the write operation to the target physical page passes the verification, update the mapping relationship between logical pages and target physical pages in the page mapping table, as well as the wear count of the target physical page. In this step, a readback operation is performed on the data just written to the target physical page. The readback data is recalculated using the same algorithm, and the checksum is compared with the checksum attached during the write operation. If they match, the write verification is considered successful, and the data is complete and correct on the physical medium. If the verification fails, it indicates that there is a physical defect or abnormal interference in this write operation. The status flag of the target physical page is directly changed to a damaged state, and the process returns to the free page selection step to retry writing to another target physical page.

[0035] Subsequently, after the write operation to the target physical page is read back and verified, and confirmed to be successful, the page mapping table stored in the non-volatile memory is updated. Specific operations include, but are not limited to, pointing the corresponding logical page index to the new address of the target physical page and synchronously incrementing the wear count of the page recorded in the mapping table. Because the page mapping table itself employs a dual-backup power-loss protection mechanism, changes to the mapping relationship can be safely persisted in memory.

[0036] S105, after the page mapping table is updated, change the status flag of the target physical page from pending to effective to effective.

[0037] Once the physical update of the page mapping table is completely completed, the status of the target physical page is officially changed from pending to active. At this point, the data in the target physical page becomes the currently active data for that logical page.

[0038] Through the embodiments of this application, a physical page pool and page mapping table are configured, and the free physical storage page with the lowest wear count is dynamically selected for writing during data updates. This achieves decoupling of logical addresses and physical addresses and global balancing of erase and write operations, avoiding premature failure of local storage media due to frequent overwriting and extending the overall lifespan of non-volatile memory. At the same time, by introducing a status marking mechanism, the timing logic of first setting the target physical page to a pending state, then modifying it to a valid state after write verification and mapping relationship update is completed is strictly followed. This ensures absolute consistency of parameter logic under abnormal operating conditions such as sudden power outages, reducing the risk of data corruption and loss.

[0039] Optionally, in this embodiment, the at least three logical pages are specifically a first logical page, a second logical page, and a third logical page. The first logical page, the second logical page, and the third logical page can be, for example, three independent logical units with the same data structure that are pre-divided in the memory of the electronic device, and they correspond to different physical addressing spaces in the physical page pool through a page mapping table.

[0040] When updating data on logical pages, the updates are performed sequentially in the order of the first logical page, the second logical page, and the third logical page. Specifically, when the processor receives an update instruction for stored data, it does not simultaneously cover all redundant areas, but updates sequentially in the order of the first logical page, the second logical page, and the third logical page. By staggering the timing of write operations, it is ensured that in the event of any abnormal write operation (such as a sudden power outage), at least two complete historical version backups are always maintained in the physical medium.

[0041] This embodiment may further include the following steps: S201, obtain the addresses of the physical storage pages mapped to the first logical page, the second logical page, and the third logical page respectively, and read the data in each physical storage page; Specifically, the aforementioned page mapping table is first accessed via the memory bus, and the addresses of the physical memory pages currently mapped to the three logical pages are obtained through index retrieval. Subsequently, the processor drives the memory controller to read the complete data from each physical memory page from the corresponding physical bias address in the non-volatile memory.

[0042] S202, Perform validity checks on the data in each physical storage page; After obtaining the addresses of the three physical storage pages, read operations are performed on each physical storage page sequentially. The data structure stored in each physical storage page includes a version number field, a parameter data array, and a checksum field.

[0043] The complete content of the physical page is read, and the checksum of the version number and parameter data is recalculated using the 16-bit Cyclic Redundancy Check (CRC-16 / CCITT) algorithm. The calculated result is compared with the checksum stored in the physical storage page. If they match, the data in the physical storage page is considered valid; otherwise, the data in the physical storage page is considered corrupted, excluded from the candidate range, and the status flag of the physical storage page is changed to corrupted.

[0044] S203: Compare the version numbers of the data in each physical storage page that has passed the verification, and take the data with the largest version number as the valid data of the logical page.

[0045] Subsequently, the version numbers of the data in each physical storage page that passed verification are compared. The version number can be, for example, a sequence number that accumulates with each successful update, or a specific identifier containing timestamp information. The processor uses an internal logical comparator to determine the numerical values ​​of the version numbers of the live backups, and identifies the data with the largest version number as the latest valid data for that logical page.

[0046] In a preferred embodiment, the determined valid data is loaded into a runtime cache. The runtime cache may be, for example, processor-integrated static random access memory (SRAM), externally extended synchronous dynamic random access memory (SDRAM), or a high-speed data buffer.

[0047] This joint processing mechanism, which couples physical verification and version adjudication in a multi-page redundant environment, can effectively shield the impact of single-point physical damage or residual data after power failure on upper-layer services.

[0048] Optionally, in this embodiment, in order to prevent global addressing failure due to abnormal power loss during the time window for updating the mapping relationship, the page mapping table is stored in a preset first mapping page and second mapping page in non-volatile memory; for example, it can be two data sectors or erase blocks with completely independent physical boundaries in the underlying flash memory medium. The first mapping page and the second mapping page are redundant to each other in the system architecture, forming a dual backup update mechanism.

[0049] The data structure definition of the page mapping table includes the following fields: (a) the physical address corresponding to logical page A, the physical address corresponding to logical page B, and the physical address corresponding to logical page C; (b) an array of wear counts for each physical storage page in the physical page pool, the array length of which is equal to the total number of physical storage pages in the physical page pool, and each array element is an unsigned integer value that records the cumulative number of erases since the corresponding physical storage page was put into use; (c) the version number of the mapping table itself, used to determine the age during dual backup rotation; and (d) the cyclic redundancy check (CRC) checksum of the mapping table itself, covering all the above fields.

[0050] During system initialization, the currently valid mapping page is determined by reading the global startup flag. The global startup flag is a byte variable stored at a fixed address in Flash. If its value is the first preset code, it points to the first mapping page; if it is the second preset code, it points to the second mapping page. The mapping table data in the valid mapping page is read, and after verification, it is loaded into RAM as the current runtime mapping table.

[0051] Specifically, step S104 may include the following steps: S301, obtain the currently valid mapping page and the backup mapping page from the first mapping page and the second mapping page; Specifically, after the write operation to the aforementioned target physical page passes verification, the crucial step of updating the page mapping table begins. The global startup flag is read to determine which mapping page is currently valid, thus determining that the target for this write operation should be another mapping page, i.e., the backup mapping page. For example, if the valid mapping page is the first mapping page, then the second mapping page is the backup mapping page; if the valid mapping page is the second mapping page, then the first mapping page is the backup mapping page.

[0052] Based on the current runtime mapping table in RAM, the version number field of the mapping table is incremented by one. The mapping relationships of the logical pages involved in this parameter update are updated to point to the addresses of the target physical pages, and the wear count corresponding to the target physical page is incremented by one. The mapping relationships of other unchanged logical pages and the wear counts of the remaining physical storage pages remain unchanged.

[0053] S302, write the updated version number, updated mapping relationship and wear count to the backup mapping page; The incremented version number, the updated mapping relationship (i.e., the address information of the logical page pointing to the new target physical page), and the latest wear count of the target physical page are used as the updated mapping table content. The CRC checksum of this updated mapping table content is recalculated, and the new checksum is filled into the checksum field. At this point, the mapping table data to be written is ready. A programming operation is initiated to the Flash controller to write the complete mapping table data structure to the backup mapping page.

[0054] S303, after the write operation to the backup mapping page passes verification, modifies the global startup flag to point to the backup mapping page.

[0055] After the write operation is complete, a readback verification is performed on the backup mapping page. During the readback, the complete mapping table data is read back from the backup mapping page, the CRC checksum is recalculated using the same algorithm, and compared with the read-back checksum field. If the comparison matches, the mapping table is considered successfully written; if the comparison does not match, the mapping page is considered to have a possible physical defect, the entire physical storage unit containing the mapping page is marked as damaged, and an attempt is made to reallocate another free physical storage page as a backup mapping page, repeating the above write process.

[0056] After the write operation to the backup mapping page passes verification, the global startup flag is modified, changing its value from pointing to the original valid mapping page to pointing to the backup mapping page. Once this global startup flag modification is complete, the backup mapping page logically becomes the new valid mapping page, and the original valid mapping page reverts to a backup role, awaiting overwriting during the next mapping table update.

[0057] Optionally, in this embodiment, the global boot flag is configured to occupy an independent minimum write unit in the physical space allocation of the non-volatile memory. The minimum write unit may be, for example, the minimum bus programming data width defined by the underlying flash memory controller hardware architecture, such as a single byte (1 Byte) in EEPROM, a double word (8 Bytes) in Nor Flash, or a single page of a specific NAND Flash.

[0058] It should be noted that if an unexpected power outage occurs at the moment the system modifies the global startup flag, since this operation either executes completely or not at all, the global startup flag read during the next power-on initialization will explicitly point to a complete mapping page that was solidified and verified before the power outage. Specifically, if the power outage occurs before the physical transition of the flag is completed, the original valid mapping page's pointing relationship will be maintained. Any incomplete writes in the backup mapping page will be discarded by the logic layer during the next power-on scan because they cannot pass the integrity check, and the system will automatically roll back to the stable addressing state before the update. Conversely, if the power outage occurs after the flag transition is completed, the system will directly identify the new valid mapping page after power-on, thus achieving a seamless and smooth switching of the addressing relationship.

[0059] Based on the aforementioned isolated layout of the underlying physical space, when the processor performs a logical switching action of the mapped page pointer, it directly issues a single programming instruction to the address where the independent smallest write unit is located, effectively avoiding the problem of adjacent data being damaged in the event of a sudden power outage during the writing process due to sharing erase and write sectors with other parameters.

[0060] Optionally, in this embodiment, the status flag also includes a pending reclamation status; after the page mapping table is updated, it also includes, but is not limited to: modifying the status flag of the old physical page to a pending reclamation status, wherein the old physical page is the physical storage page pointed to by the logical page before the page mapping table is updated.

[0061] In this embodiment, the status marker also includes a pending reclamation state. The pending reclamation state can be, for example, a status byte in the header of a physical storage page programmed with a specific characteristic value (such as 0x3C), which logically indicates that the data carried in the physical storage page has become invalid due to a logical update, but has not yet been physically erased and is in an intermediate transitional stage awaiting unified processing by the reclamation system.

[0062] In this embodiment, the old physical page is defined as the physical storage page pointed to by the logical page before the current page mapping table update operation. In the timing logic of off-site updates, once the new data has been securely stored in the target physical page and the addressing pointer of the mapping table has been successfully switched to the new page, the data in the original physical page (i.e., the old physical page) loses its addressing reference and becomes logically dirty data.

[0063] By issuing programming instructions to the status flag area of ​​the old physical page, its status is changed from valid to pending reclamation. This status indicates that the data stored in the physical storage page is no longer the latest valid version referenced by any current logical page, and the physical space it occupies can be reclaimed and reused. However, before being reclaimed, the physical storage page has not been erased, and its historical data is still retained at the physical level.

[0064] Once an old physical page is marked as pending reclaim, it is considered unusable space in the system. During subsequent parameter update processes, when traversing the physical page pool and filtering for erased physical storage pages, pages in the pending reclaim state are not identified as free pages and do not participate in wear count comparisons or target page selection. Only in subsequent garbage collection processes, after a pending physical storage page is erased and its status is reset to erased, will it return to the pool of free physical storage pages.

[0065] Optionally, in this embodiment, the above method may further include the following steps: S401, in response to the power-on initialization operation, scans the status flags of each physical memory page in the physical page pool; In real-world applications, a system may experience an unexpected power outage at any time, including during parameter updates. If the power outage occurs before the page mapping table update is complete, a physical storage page will remain in the system with a pending status but no corresponding pointer in the mapping table.

[0066] Specifically, in response to the power-on initialization operation, the processor traverses the metadata area reserved at the head or tail of each physical storage page in the physical page pool and reads its status flag field. The power-on initialization operation can be, for example, the loading stage of the underlying bootloader executed after a cold start or warm reset of the electronic device. During this stage, the processor traverses the metadata area of ​​the entire physical page pool to search for any physical storage pages marked as pending activation. Based on the aforementioned update timing, if such physical storage pages exist, it indicates that a power outage occurred during the previous data update process after data was written but before the mapping table pointer switch.

[0067] S402, when there is a physical storage page whose status is marked as pending, perform an integrity check on the data in the physical storage page, and determine the logical page corresponding to the physical storage page, as well as the physical storage page currently pointed to by the corresponding logical page in the page mapping table; In this embodiment, when a physical storage page marked as pending activation is identified during the scan, the data verification and reallocation actions corresponding to that physical storage page are performed. Specifically, firstly, an integrity check, such as a CRC check, is performed on the data in the physical storage page to confirm whether the physical storage page has completed full physical-level programming at the moment of power failure. Subsequently, the header information of the physical storage page is parsed to determine the logical page corresponding to the physical storage page, and the current page mapping table is queried to determine the physical storage page currently pointed to by the corresponding logical page.

[0068] S403, if the verification passes and the version number of the physical storage page in the pending state is higher than the version number of the currently pointed-to physical storage page, then update the mapping relationship of the corresponding logical page in the page mapping table to point to the physical storage page in the pending state, modify its status mark to the valid state, and modify the status mark of the currently pointed-to physical storage page to the pending reclamation state.

[0069] Specifically, if the version number of the physical storage page awaiting activation is lower than or equal to the version number of the old physical page, it indicates that in the write operation before the abnormal power outage, the version number carried by the updated data did not exceed the version number of the old data, or the data in the page awaiting activation is residual data left over from an earlier anomaly. In this case, the data in the physical storage page awaiting activation is not legitimate to replace the data in the old physical page. The status flag of the physical storage page awaiting activation is directly changed to a pending reclamation state, causing it to enter the reclamation queue and be erased and reused in the subsequent garbage collection process. The mapping relationship and status of the old physical page remain unchanged.

[0070] If the verification passes, and the version number of the physical storage page in the pending state is higher than the version number of the old physical page, it indicates that the physical storage page in the pending state carries newer and more complete data. In this case, the mapping relationship of the corresponding logical page in the page mapping table is updated to point to the physical storage page in the pending state, and its status is officially changed from pending state to effective state.

[0071] Finally, the status of the old physical page is changed to pending reclamation, and any old associations between the pending physical storage page and the original mapping are canceled, so that it is removed from the role of a valid data carrier and enters the reclamation queue.

[0072] Optionally, in this embodiment, the above method may further include the following steps: S501, when the number of physical storage pages marked as erased in the physical page pool is lower than a preset threshold, the physical storage pages marked as pending reclamation are erased. In practical applications, the processor of the non-volatile memory continuously monitors the physical page pool. When the number of physical storage pages marked as erased in the physical page pool falls below a preset threshold, a garbage collection mechanism is initiated. This preset threshold could be, for example, 10% of the total capacity of the physical page pool or a fixed number of free pages. By quickly scanning the status markers of each physical storage page, all pages marked as awaiting reclaiming are identified; the data carried by these pages is logically invalid.

[0073] When the number of erased physical storage pages detected is still within a preset threshold, it indicates that there are sufficient idle resources in the system, and the garbage collection process is not in a hurry to be executed. Physical pages in the pending collection state continue to maintain their current state, waiting for the system to become idle.

[0074] Next, an erase operation is performed on the selected physical memory pages marked as awaiting reclamation. Specifically, the processor drives the erase control logic of the non-volatile memory controller to apply a high-voltage erase pulse to the control gate of the corresponding physical block, causing the electrons in the memory cell to discharge, thereby restoring the data of the entire physical memory page to a logic initial state of all "1s".

[0075] S502, after successful erasure, resets the status flag of the physical storage page to the erased state.

[0076] After the erase operation is completed, a success check is performed on the physical storage page. This check typically involves reading the entire content of the physical storage page and verifying that each storage cell has been restored to its default erased state. If the check passes, the status flag of the physical storage page is reset from pending reclamation to erased. This physical storage page then re-enters the free candidate set of the physical storage page pool and can be identified as a free physical storage page in subsequent parameter update processes, participating in wear count comparisons and target physical storage page selection.

[0077] If an erase operation on a physical storage page in a pending reclaim state fails verification, it indicates that the physical storage page may be physically damaged and cannot be erased normally. The status of the physical storage page is then changed from pending reclaim to damaged, and the page is logically removed from the manageable physical page pool.

[0078] Optionally, in this embodiment, the status flag also includes a damaged state; the above method may also include, but is not limited to: when the erase operation fails, the write operation fails, or the post-write verification fails, the status flag of the physical storage page is modified to a damaged state.

[0079] In this embodiment, the damaged state can be achieved, for example, by writing a feature word (such as 0x00) representing "permanent failure" to a specific storage bit in the header of the physical storage page. This logically indicates that the physical storage page no longer has reliable charge retention or logical programming capabilities and should be permanently removed by the scheduling algorithm.

[0080] Specifically, during the data management operations performed on the physical storage page, the processor monitors for abnormal states reported by the hardware in real time. These operations include, but are not limited to, erasing, writing, and post-write readback verification. If, during any of these actions, a timeout signal or current anomaly flag is received from the storage controller, or if the XOR comparison result between the readback data and the original data is inconsistent (i.e., verification fails), then it is determined that the physical storage page has suffered irreversible physical damage. This physical damage may, for example, be oxide layer breakdown of the flash memory cell or open word / bit line circuitry.

[0081] After determining that the above-mentioned anomaly has occurred, the processor executes the damage marking step, which modifies the status of the physical memory page to a damaged state. Based on the above principle, once a physical memory page is marked as damaged, its wear count will be frozen in the page mapping table, and the processor will automatically ignore this address space when subsequently executing the free memory page filtering process described in step S101 above.

[0082] Another embodiment of the present invention relates to a non-volatile memory data storage management system, wherein the non-volatile memory is pre-configured with a physical page pool and a page mapping table, the physical page pool includes multiple physical storage pages, each of the physical storage pages is configured with a status flag; the page mapping table records the mapping relationship between at least three logical pages and the physical storage pages, as well as the wear count and version number of each physical storage page.

[0083] like Figure 2 As shown, the system may specifically include: The first determining module 20 is configured to, in response to a data update instruction for any one of the at least three logical pages, acquire update data and determine the free physical storage pages in the physical page pool whose status is marked as erased. The first counting module 21 is used to compare the wear counts of each free physical storage page in the page mapping table and determine the physical storage page with the smallest wear count as the target physical page. The first writing module 22 is used to write the updated data and the updated version number into the target physical page, and to set the status flag of the target physical page from the erased state to the pending state. The first update module 23 is used to update the mapping relationship between the logical page and the target physical page in the page mapping table and the wear count of the target physical page after the write operation of the target physical page passes the verification. The first processing module 24 is used to change the status flag of the target physical page from pending to effective to effective after the page mapping table is updated.

[0084] Optionally, in this embodiment, the at least three logical pages are specifically a first logical page, a second logical page, and a third logical page. When updating data on the logical pages, the updates are performed sequentially in the order of the first logical page, the second logical page, and the third logical page. The system also includes: The first acquisition module is used to acquire the addresses of the physical storage pages mapped to the first logical page, the second logical page, and the third logical page, and to read the data in each of the physical storage pages; The first verification module is used to perform validity verification on the data in each of the physical storage pages; The second processing module is used to compare the version numbers of the data in each physical storage page that has passed the verification, and to take the data with the largest version number as the valid data of the logical page.

[0085] Optionally, in this embodiment, the page mapping table is stored in a preset first mapping page and second mapping page in non-volatile memory; wherein, the first update module 23 includes: The first acquisition submodule is used to acquire the currently valid mapping page in the first mapping page and the second mapping page, as well as the backup mapping page; The first write submodule is used to write the updated version number, the updated mapping relationship, and the wear count into the backup mapping page; The first processing submodule is used to modify the global startup flag to point to the backup mapping page after the write operation to the backup mapping page passes the verification.

[0086] Optionally, in this embodiment, the global startup flag occupies an independent minimum write unit.

[0087] Optionally, in this embodiment, the status marker further includes a pending recycling status; the system also includes: The second processing module is used to modify the status flag of the old physical page to a pending reclamation state after the page mapping table is updated, wherein the old physical page is the physical storage page pointed to by the logical page before the page mapping table is updated.

[0088] Optionally, in this embodiment, the system further includes: The first scanning module is used to scan the status flags of each physical storage page in the physical page pool in response to the power-on initialization operation; The second determining module is used to perform an integrity check on the data in a physical storage page when there is a physical storage page whose status is marked as pending, and to determine the logical page corresponding to the physical storage page, as well as the physical storage page currently pointed to by the corresponding logical page in the page mapping table. The third processing module is used to update the mapping relationship of the corresponding logical page in the page mapping table to point to the physical storage page in the pending state if the verification passes and the version number of the physical storage page to be effective is higher than the version number of the currently pointed-to physical storage page, modify its status mark to effective, and modify the status mark of the currently pointed-to physical storage page to be reclaimed.

[0089] Optionally, in this embodiment, the system further includes: The first erasure module is used to perform an erasure operation on physical storage pages marked as pending reclamation when the number of physical storage pages in the physical page pool that are marked as erased is lower than a preset threshold. The fourth processing module is used to reset the status flag of the physical storage page to the erased state after successful erasure.

[0090] Optionally, in this embodiment, the status marker further includes a damaged status; the system also includes The fifth processing module is used to modify the status flag of a physical storage page to a damaged state when an erase operation fails, a write operation fails, or a post-write verification fails.

[0091] Another embodiment of the present invention relates to an electronic device, such as Figure 3 As shown, it includes: at least one processor 301; and a memory 302 communicatively connected to the at least one processor 301; wherein the memory 302 stores instructions executable by the at least one processor 301, the instructions being executed by the at least one processor 301 to enable the at least one processor 301 to perform the non-volatile memory data storage management method in the above embodiments.

[0092] The memory and processor are connected via a bus, which can include any number of interconnecting buses and bridges, connecting various circuits of one or more processors and memories. The bus can also connect various other circuits, such as peripheral devices, voltage regulators, and power management circuits, which are well known in the art and will not be described further herein. The bus interface provides an interface between the bus and the transceiver. The transceiver can be a single element or multiple elements, such as multiple receivers and transmitters, providing a unit for communicating with various other devices over a transmission medium. Data processed by the processor is transmitted over the wireless medium via an antenna, which further receives data and transmits it to the processor.

[0093] The processor manages the bus and general processing, and also provides various functions, including timing, peripheral interfaces, voltage regulation, power management, and other control functions. Memory is used to store data used by the processor during operation.

[0094] Another embodiment of the present invention relates to a computer-readable storage medium storing a computer program. When executed by a processor, the computer program implements the method embodiments described above.

[0095] That is, those skilled in the art will understand that all or part of the steps in the methods of the above embodiments can be implemented by a program instructing related hardware. This program is stored in a storage medium and includes several instructions to cause a device (which may be a microcontroller, chip, etc.) or processor to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0096] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0097] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0098] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and not to limit it. Although the present invention has been described in detail with reference to the above embodiments, those skilled in the art should understand that modifications or equivalent substitutions can still be made to the specific implementation of the present invention. Any modifications or equivalent substitutions that do not depart from the spirit and scope of the present invention should be covered within the scope of protection of the claims of the present invention.

Claims

1. A method for managing data storage in a non-volatile memory, characterized in that, The non-volatile memory is pre-configured with a physical page pool and a page mapping table. The physical page pool includes multiple physical storage pages, each of which is configured with a status flag. The page mapping table records the mapping relationship between at least three logical pages and the physical storage pages, as well as the wear count and version number of each physical storage page. The method includes: In response to a data update instruction for any one of the at least three logical pages, update data is obtained, and free physical storage pages in the physical page pool that are marked as erased are identified. Compare the wear counts of each free physical storage page in the page mapping table, and determine the physical storage page with the smallest wear count as the target physical page; Write the updated data and the updated version number into the target physical page, and change the status flag of the target physical page from erased to pending effect; After the write operation to the target physical page passes the verification, the mapping relationship between the logical page and the target physical page in the page mapping table, as well as the wear count of the target physical page, are updated. After the page mapping table is updated, the status flag of the target physical page is changed from pending to active to active.

2. The method according to claim 1, characterized in that, The at least three logical pages are specifically a first logical page, a second logical page, and a third logical page. When updating data on the logical pages, the updates are performed sequentially in the order of the first logical page, the second logical page, and the third logical page. The method further includes: Obtain the addresses of the physical storage pages mapped to the first logical page, the second logical page, and the third logical page, and read the data in each of the physical storage pages; Perform validity checks on the data in each of the aforementioned physical storage pages; Compare the version numbers of the data in each physical storage page that has passed the verification, and take the data with the largest version number as the valid data of the logical page.

3. The method according to claim 1, characterized in that, The page mapping table is stored in a pre-defined first mapping page and a second mapping page in non-volatile memory; wherein... After the write operation to the target physical page passes verification, the mapping relationship between the logical page and the target physical page in the page mapping table, and the wear count of the target physical page are updated, including: Obtain the currently valid mapping page from the first mapping page and the second mapping page, as well as the backup mapping page; Write the updated version number, the updated mapping relationship, and the wear count into the backup mapping page; After the write operation to the backup mapping page passes verification, the global startup flag is modified to point to the backup mapping page.

4. The method according to claim 3, characterized in that, The global startup flag occupies an independent minimum write unit.

5. The method according to claim 1, characterized in that, The status marker also includes a pending recycling status; after the page mapping table is updated, the process further includes: The status flag of the old physical page is changed to a pending reclamation state, wherein the old physical page is the physical storage page that the logical page points to before the page mapping table is updated.

6. The method according to claim 5, characterized in that, The method further includes: In response to the power-on initialization operation, the status flags of each physical memory page in the physical page pool are scanned; When there is a physical storage page whose status is marked as pending, perform an integrity check on the data in the physical storage page, and determine the logical page corresponding to the physical storage page, as well as the physical storage page currently pointed to by the corresponding logical page in the page mapping table; If the verification passes, and the version number of the physical storage page in the pending state is higher than the version number of the currently pointed-to physical storage page, then the mapping relationship of the corresponding logical page in the page mapping table is updated to point to the physical storage page in the pending state, its status mark is modified to valid, and the status mark of the currently pointed-to physical storage page is modified to pending reclamation.

7. The method according to claim 5, characterized in that, The method further includes: When the number of physical storage pages marked as erased in the physical page pool is detected to be lower than a preset threshold, an erase operation is performed on the physical storage pages marked as pending reclamation. After a successful erase, the status flag of the physical storage page is reset to the erased state.

8. The method according to claim 1, characterized in that, The status marker also includes a damaged status; the method further includes: If an erase operation, write operation, or post-write verification fails, the status flag of the physical storage page is changed to corrupted.

9. A non-volatile memory data storage management system, characterized in that, The non-volatile memory is pre-configured with a physical page pool and a page mapping table. The physical page pool includes multiple physical storage pages, each of which is configured with a status flag. The page mapping table records the mapping relationship between at least three logical pages and the physical storage pages, as well as the wear count and version number of each physical storage page. The system includes: The first determining module is configured to, in response to a data update instruction for any one of the at least three logical pages, acquire update data and determine the free physical storage pages in the physical page pool whose status is marked as erased. The first counting module is used to compare the wear counts of each free physical storage page in the page mapping table and determine the physical storage page with the smallest wear count as the target physical page. The first writing module is used to write the updated data and the updated version number into the target physical page, and to set the status flag of the target physical page from the erased state to the pending state. The first update module is used to update the mapping relationship between the logical page and the target physical page in the page mapping table, and the wear count of the target physical page, after the write operation of the target physical page passes the verification. The first processing module is used to change the status flag of the target physical page from pending to effective to effective after the page mapping table is updated.

10. An electronic device, characterized in that, It includes a non-volatile memory and a processor, the processor being configured to perform the non-volatile memory data storage management method as described in any one of claims 1 to 8.