A file system-based flash memory real-time monitoring and life prediction method
By constructing a dynamic wear coefficient table based on real-time monitoring of the file system and a sliding window algorithm, the problem of evaluation bias in the life prediction of Flash storage devices is solved, and high-precision life prediction and fault handling are achieved, which is suitable for embedded devices and other scenarios.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-07
- Publication Date
- 2026-03-24
AI Technical Summary
Existing methods for predicting the lifespan of flash storage devices fail to fully consider file update frequency and directory structure changes, leading to biases in health status assessment. Furthermore, existing algorithms have high computational resource requirements, which cannot meet the lightweight and real-time requirements of embedded systems.
By using a file system-based real-time monitoring method, Flash physical parameters and operation records are collected to construct a dynamic wear coefficient table. Combined with a sliding window algorithm and an intelligent weight iteration mechanism, full lifecycle management of Flash storage is achieved, including real-time erase statistics, bad block event recording, file and directory update frequency statistics, dynamic wear coefficient calculation, and remaining lifespan prediction.
It enables fine-grained management of Flash storage devices, improves the accuracy and real-time performance of lifetime prediction, reduces computing resource consumption, is suitable for resource-constrained scenarios such as embedded devices, and is compatible with multiple operating systems and flash memory chips.
Smart Images

Figure CN121070740B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of flash memory technology, and in particular to a method for real-time monitoring and lifetime prediction of flash storage based on a file system. Background Technology
[0002] Flash memory, with its advantages of high speed and low power consumption, is widely used in power equipment such as distribution terminals. As critical nodes in the distribution network, these terminals need to reliably store critical information such as power metering data, fault recordings, operation logs, and equipment status for extended periods. Storage reliability directly affects the accuracy of power grid dispatching decisions, the continuity of power supply, and the timeliness of fault location, serving as a core support for ensuring the safe operation of the distribution network. However, Flash memory cells have inherent physical limitations: each storage block has a limited number of erase cycles. With repeated erase and write operations, the storage cell gradually wears down, eventually producing bad blocks or even failing entirely. Therefore, real-time health monitoring and accurate prediction of the remaining lifespan of Flash memory are key technologies for ensuring stable equipment operation and preventing data loss.
[0003] Currently, most Flash life testing technologies still focus on the number of times blocks are erased and written, but ignore the indirect impact of file update frequency and directory structure changes on the wear and tear of storage units, resulting in biased health status assessments. Even though some prediction algorithms have emerged, these algorithms usually rely on large machine learning models, which require a lot of computing resources and cannot meet the lightweight and real-time requirements of embedded system devices. Summary of the Invention
[0004] This invention addresses the reliability requirements of power distribution terminal storage and discloses a method for real-time monitoring and lifespan prediction of Flash storage based on a file system. This method enables full lifecycle management of Flash storage and can at least solve one of the technical problems in the background art.
[0005] To achieve the above objectives, the present invention adopts the following technical solution:
[0006] A method for real-time monitoring and lifetime prediction of flash storage based on a file system includes the following steps:
[0007] S100 Initialization Information Acquisition: Obtain Flash physical parameters through the file system driver interface, including the physical size of each block, the total number of blocks, the maximum number of erases per block (Em), and the factory bad block mark, and register corresponding erase update and file operation record callback functions;
[0008] S101 Real-time Erasure Statistics: During system operation, the callback registered through S100 records the operated block, file, and corresponding timestamp, and updates the log buffer, etc., every time an erasure or file operation is performed; a low-priority software timer is created with a default trigger period of 300 seconds (configurable), and the cumulative number of erasures and the maximum / minimum erase block information are updated in the timer interrupt;
[0009] S102, Bad Block Event Recording: When a new bad block is detected, the fault timestamp is recorded, and the operation records before the fault (including the number of writes, the number of erases, and the file handles involved) and the operation status of the Flash before the fault are extracted from the dedicated log buffer and stored in the non-volatile memory area of the MCU in the form of file appending.
[0010] S103. File and directory update frequency statistics: Calculate the frequency of file updates (writes, deletions) per unit time (Fi); at the same time, calculate the number of file creations, deletions, renamings, and subdirectory changes for each directory per unit time to obtain the directory update frequency (Di).
[0011] S200. Construct a dynamic wear coefficient table, including the following sub-steps:
[0012] S201. Data Preprocessing: An integer linear mapping strategy is adopted, scaling the number of erases (Ei) proportionally and truncating the file update frequency (Fi) and directory update frequency (Di). The results are uniformly rounded and mapped to the 0-100 range, as shown in the formula:
[0013]
[0014] in: : The normalized value of the number of erases for the i-th block, ranging from 0 to 100; The number of times the i-th block is erased; : Maximum nominal number of erase cycles per unit; : Normalized value of file update frequency; : The update frequency of the i-th file; : Normalized value of directory update frequency; The update frequency of the i-th directory per unit of time;
[0015] S202, Dynamic Weight Allocation: Weight coefficients are determined using a lookup table method, with the industrial control scenario employing... Power distribution scenarios adopt Embedded scenarios adopt ;
[0016] Where α, β, and γ are the weights of the number of erases, file update frequency, and directory update frequency, respectively, and α + β + γ = 100%. The weight combination can be dynamically switched via API interface during system startup or operation, with a switching response time ≤ 2 milliseconds. Simultaneously, an intelligent weight iteration mechanism is adopted, automatically calculating the contribution ratio of wear factors to the faulty block each time a new bad block event occurs. The specific formula is as follows:
[0017]
[0018] In the formula: B is the number of bad blocks caused by sudden failure, B total This is the total number of bad blocks;
[0019] S203 Wear Coefficient Calculation: Calculate the dynamic wear coefficient of each block according to the formula. The calculation process uses 16-bit integer multiplication and accumulation operation. The result is rounded and stored. The calculation time for a single block is ≤20 microseconds. The remainder is the execution time of the rest of the code.
[0020]
[0021] In the formula: : The current dynamic wear coefficient of the i-th block;
[0022] S300, Lifetime dynamic prediction based on sliding window, includes the following sub-steps:
[0023] S301. Sliding window initialization: The window size is a power of 2 (N=32). A circular buffer is used to store the wear coefficient (Wi), the erase count increment (ΔEi), and the time interval (Δti, unit: seconds) of the most recent 64 erase operations.
[0024] S302. Trend feature extraction: Calculate the mean wear coefficient (μW), variance (σW), wipe frequency slope (k), and current decay factor (λ) within the window.
[0025] Calculate the mean wear coefficient (μW) within the window:
[0026]
[0027] In the formula: : The current dynamic wear coefficient of the i-th block; N is the window size;
[0028] Calculate the variance of the wear coefficient (σW) within the window:
[0029]
[0030] In the formula: : The current dynamic wear coefficient of the i-th block, μW: the average wear coefficient within the window;
[0031] Calculate the slope (k) of the erasure frequency trend:
[0032] Using the timestamps (ti, in seconds, relative to the window's start time) of each erase within the window as the x-axis and the erase count increment (ΔEi) as the y-axis, the least squares method is used to fit the straight line y=kx+b, and the formula for calculating the slope k is:
[0033]
[0034] Where: N: window size; ti: timestamp of each erase; Increment of erase count;
[0035] Calculate the attenuation factor (λ):
[0036] The durability curve is dynamically adjusted according to the Flash specification. The initial value for new equipment is 1.0, and it linearly decreases to 0.8 when the maximum number of erases Ec≥0.5Em.
[0037]
[0038] Where: Ec: current maximum number of erases, Em: maximum number of erases;
[0039] S303. Dynamic lifetime prediction: Estimate the remaining lifetime according to the following formula;
[0040]
[0041] Where L: Remaining lifetime (percentage); λ: Attenuation factor; fb: Baseline erase frequency (unit: times / 300 seconds); k: Erasure frequency trend slope;
[0042] S400, fault location and strategy optimization, including the following sub-steps:
[0043] S401. Fault Cause Judgment: Combining the cumulative erase count (Ei) corresponding to the physical address of the bad block, the erase frequency per unit time before the fault, and the read FLASH status, the fault type is determined by a preset threshold: If Ei ≥ 0.9 × Em and the erase frequency ≥ 1.5 times the base frequency, it is determined to be wear and aging; if the erase frequency ≤ 1.5 times the base frequency, it is classified as natural aging; if Ei < 0.9 × Em but there are more than 3 consecutive ECC or FLASH status abnormal errors, it is determined to be a sudden fault; the rest are unknown errors, and a log is printed to remind the user.
[0044] S402, file migration strategy for wear and natural aging: Extract files associated with bad blocks from the pre-failure operation log recorded in S102, and at the same time, traverse and filter the free blocks with the lowest current wear from the dynamic wear coefficient table, and migrate files in batches of 4 pages. Release the requested memory resources after the migration is completed and the synchronization is completed.
[0045] S403, Similar block marking strategy for sudden failures: Obtain the erase / write frequency and the time interval between the last 5 erases of the faulty block from the statistical data of S101, and traverse all non-bad blocks to calculate the above characteristic parameters of each block. Compare them with the faulty block. When the erase / write deviation rate and the time interval deviation rate are both <20%, it is judged as a "similar risk block" and write restrictions are added.
[0046] S404, Update Flash Prediction: After the bad block is introduced, the prediction interface is called to recalculate the Flash storage lifetime;
[0047] Furthermore, the triggering period of the timed task in step S101 of the present invention can be adjusted through the system configuration interface, with a default period of 300 seconds, and the statistical information is automatically synchronized to the non-volatile storage area.
[0048] Furthermore, the "appending to a file" method described in step S102 of this invention is a circular overwrite writing method, which can write up to 1024 bad block information.
[0049] Furthermore, the dedicated log buffer mentioned in step 102 of the present invention has a size of 5KB and stores the most recent 512 operation records. Each record includes: timestamp (4 bytes, Unix format), physical block address (2 bytes), file handle index (2 bytes), operation type (1 byte, 0x01=erase, 0x02=write, 0x04=delete), and operation status (1 byte, recording the status read by Flash).
[0050] Furthermore, the automatic calculation of the wear factor contribution ratio of the faulty block in step S202 of the present invention is achieved by automatically calling the update callback function after the bad block is identified through the initial registration of the update callback function to update the weight.
[0051] Furthermore, the weight table in step S202 of the present invention is stored in a fixed file, which supports offline modification via a host computer, and no system restart is required after modification;
[0052] Furthermore, in step S302 of this invention, the least squares fitting method only retains the calculation of linear terms and omits higher-order terms to reduce the computational complexity of the system.
[0053] Furthermore, the file migration in step S402 of the present invention adopts a checksum verification mechanism. The original block space is only released when the checksum of the file data before and after migration is consistent, so as to ensure data integrity.
[0054] Furthermore, the time data such as time consumption and CPU time occupied mentioned in this invention are all obtained by testing with a 72MHz MCU main frequency;
[0055] Furthermore, the method described in this invention is applicable to embedded devices, power distribution, and industrial control scenarios, is compatible with Nor / NandFlash chips, supports bare metal, RTOS, and Linux operating systems, and has a core algorithm code size of <32KB.
[0056] In summary, the file system-based real-time monitoring and lifetime prediction method for Flash storage disclosed in this invention achieves refined management of the entire Flash lifecycle. This method first acquires Flash physical parameters through initialization information collection, and constructs a multi-dimensional real-time status dataset by combining real-time erase statistics, bad block statistics, and file and directory update frequency statistics. Through data preprocessing, dynamic weight allocation, and wear coefficient calculation, a dynamic wear coefficient table is generated. Then, based on the sliding window algorithm, feature values are extracted by combining historical data and current trends, and the remaining lifetime is estimated with high accuracy by dynamically adjusting the prediction model. Finally, fault location and subsequent operation optimization are completed through fault type judgment, file migration strategies, and similar risk block marking. The entire process is based on lightweight algorithms, and through real-time statistics and dynamic adjustment mechanisms, it achieves closed-loop management of the entire chain from status monitoring to lifetime prediction and fault handling. It is compatible with mainstream Nor / NandFlash chips and adapts to various operating systems such as bare metal, RTOS, and Linux, and can be widely applied to diverse scenarios such as embedded devices, power distribution, and industrial control.
[0057] Compared with the prior art, the advantages of this invention are as follows:
[0058] 1. This invention breaks through the traditional single evaluation mode that only uses the number of erases. It incorporates the number of block erases, file update frequency, directory update frequency, etc. into the wear assessment system and constructs a dynamic wear coefficient table, which can more comprehensively reflect the actual health status of the storage unit and solve the evaluation bias problem caused by ignoring indirect wear factors in the prior art.
[0059] 2. This invention employs a sliding window optimization algorithm that combines historical erase / write records with current trends. By dynamically adjusting the window size and correcting the decay factor, it achieves high-precision estimation of remaining lifetime. Simultaneously, the intelligent weight iteration mechanism can continuously optimize the model based on bad block feedback, further improving prediction accuracy and meeting the stringent requirements for lifetime prediction in different scenarios.
[0060] 3. This invention significantly reduces system resource consumption through designs such as replacing division with shift operations, reducing computational load with 16-bit integer operations, low-priority scheduling of timed tasks, and a core algorithm code size of <32KB. It does not rely on large machine learning models and can be directly applied to resource-constrained scenarios such as embedded devices, balancing real-time performance and efficiency. It is also compatible with mainstream Nor / NandFlash flash memory and adaptable to various operating systems including bare metal, RTOS, and Linux, enhancing the technology's versatility and practicality. Attached Figure Description
[0061] Figure 1 This is a flowchart of the present invention. Detailed Implementation
[0062] The solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of the present invention, and not all of them. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0063] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to specific embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention.
[0064] like Figure 1 As shown in the figure, this invention discloses a method for real-time monitoring and lifetime prediction of FLASH storage based on a file system, including the following steps:
[0065] S100: Register the memory device, obtain its physical parameter information, collect the number of block erases, file update frequency and directory update frequency in real time, and record the operation log at the same time, thereby constructing a multi-dimensional data set to provide basic data support for the health status assessment and life prediction of the memory.
[0066] S200, based on the multi-dimensional data set in S100, constructs a dynamic wear coefficient table through dynamic weight allocation and integer linear mapping strategy to accurately quantify the real-time health status of each storage unit;
[0067] S300, combined with the dynamic wear coefficient table constructed by S200 and the multi-dimensional data set in S100, uses the sliding window method to extract wear trend features, dynamically adjusts the life prediction model, and achieves accurate calculation of remaining life.
[0068] S400: Based on the operation log recorded in S100 and the dynamic wear coefficient table constructed in S200, the faulty file and related write and erase information are located by analyzing the file operation records before the bad block appears. Based on the fault type, file migration or risk blocks are marked to optimize subsequent file operation behavior.
[0069] The following is a detailed explanation:
[0070] S100, Initialization Information Collection
[0071] Register flash memory information through the MTD device driver (File System Abstraction Layer Standardized Access Interface), obtain the initial core parameters of the flash memory, store the parameters in a structure, and register corresponding callback functions for erase / update and file operation records; specifically including,
[0072] S101, Real-time Erasure Statistics
[0073] During system operation, the callback registered through S100 records the operated block, file, and corresponding timestamp, and updates the log buffer, etc., every time an erase or file operation is performed; a low-priority software timer is created with a default trigger period of 300 seconds (configurable), and the cumulative number of erases and the maximum / minimum erase block information are updated in the timer interrupt;
[0074] S102, Bad Block Event Log
[0075] When the Flash erase / write operation fails or (NandECC error ≥ 3 times, Nor programming verification fails), the bad block detection process is triggered. The bad block detection interface checks whether it is a new bad block. If the result is true, the bad block is marked and the fault-related block operation record, corresponding file and timestamp are filtered out from the dedicated log ring buffer and written to the non-volatile storage area of the MCU. CRC16 is used to verify the data integrity.
[0076] S103. Statistics on File and Directory Update Frequency
[0077] The system uses a 300-second statistical period by default, covering all mounted file systems. It monitors file write and deletion operations, as well as file creation, deletion, renaming, and subdirectory changes in directories. By embedding registered callbacks in the file system API to record the number of operations, it ultimately obtains the corresponding block file update frequency Fi and directory update frequency Di.
[0078]
[0079] In the formula: Wi is the number of write operations, Di is the number of delete operations, Ci is the number of directory creations, Ri is the number of renamings, and Mi is the number of subdirectory changes;
[0080] S200, Constructing a dynamic wear coefficient table
[0081] S201, Data Preprocessing
[0082] An integer linear mapping strategy is adopted, which scales the number of erases (Ei) proportionally and truncates the file update frequency (Fi) and directory update frequency (Di) directly, uniformly rounding the results to the 0-100 range. This method uses integer operations instead of floating-point operations, significantly reducing CPU resource consumption and improving the operating efficiency of the embedded platform. The formula is as follows:
[0083]
[0084] in: : The normalized value of the number of erases for the i-th block, ranging from 0 to 100; The number of times the i-th block is erased; : Maximum nominal number of erase cycles per unit; : Normalized value of file update frequency; : The update frequency of the i-th file; : Normalized value of directory update frequency; The update frequency of the i-th directory per unit of time;
[0085] S202, Dynamic Weight Allocation
[0086] The weighting coefficients are determined using a lookup table method; in industrial control scenarios, the following method is adopted. Power distribution scenarios adopt Embedded scenarios adopt ;
[0087] Where α, β, and γ are the weights of the number of erases, file update frequency, and directory update frequency, respectively, and α + β + γ = 100%. The weight combination can be dynamically switched via API interface during system startup or operation, with a switching response time ≤ 2 milliseconds. Simultaneously, an intelligent weight iteration mechanism is adopted, automatically calculating the contribution ratio of wear factors to the faulty block each time a new bad block event occurs. The specific formula is as follows:
[0088]
[0089] In the formula: B is the number of bad blocks caused by high-frequency erasure, B total This is the total number of bad blocks;
[0090] S203, Wear Coefficient Calculation
[0091] The dynamic wear coefficient of each block is calculated according to the formula. The calculation process uses 16-bit integer multiplication and accumulation operation. The result is rounded and stored. The calculation time for a single block is ≤20 microseconds, which meets the requirements of high-frequency erase and write recording. The remaining time is the execution time of the rest of the code.
[0092]
[0093] In the formula: : The current dynamic wear coefficient of the i-th block;
[0094] S300, dynamic lifetime prediction based on sliding window;
[0095] S301, Sliding window initialization
[0096] Using a window size that is a power of 2 (N=32), a circular buffer is used to store the wear coefficient (Wi), erase count increment (ΔEi), and time interval (Δti, in seconds) of the most recent 64 erase operations.
[0097] S302, Trend Feature Extraction
[0098] Calculate the mean wear coefficient (μW), variance (σW), erase frequency slope (k), and current attenuation factor (λ) within the window;
[0099] Calculate the mean wear coefficient (μW) within the window:
[0100]
[0101] In the formula: : The current dynamic wear coefficient of the i-th block; N is the window size;
[0102] Calculate the variance of the wear coefficient (σW) within the window:
[0103]
[0104] In the formula: : The current dynamic wear coefficient of the i-th block, μW: the average wear coefficient within the window;
[0105] Calculate the slope (k) of the erasure frequency trend:
[0106] Using the timestamps (ti, in seconds, relative to the window's start time) of each erase within the window as the x-axis and the erase count increment (ΔEi) as the y-axis, the least squares method is used to fit the straight line y=kx+b, and the formula for calculating the slope k is:
[0107]
[0108] Where: N: window size; ti: timestamp of each erase; The number of erasures increments; the least squares fitting method omits higher-order terms, which greatly reduces the computational burden while ensuring the ability to capture trends;
[0109] Calculate the attenuation factor (λ):
[0110] The durability curve is dynamically adjusted according to the Flash specification. The initial value for new equipment is 1.0, and it linearly decreases to 0.8 when the maximum number of erases Ec≥0.5Em.
[0111]
[0112] Where: Ec: current maximum number of erases, Em: maximum number of erases;
[0113] S303, Dynamic Life Prediction
[0114] Estimate remaining lifetime using the following formula;
[0115]
[0116] Where L: Remaining lifetime (percentage); λ: Attenuation factor; fb: Baseline erase frequency (unit: times / 300 seconds); k: Erasure frequency trend slope;
[0117] S400, fault location and strategy optimization;
[0118] S401, Fault Cause Diagnosis
[0119] Based on the cumulative erase count (Ei) corresponding to the physical address of the bad block, the erase frequency per unit time before the fault, and the read FLASH status, the fault type is determined by a preset threshold: if Ei ≥ 0.9 × Em and the erase frequency ≥ 1.5 times the base frequency, it is determined to be wear and aging; if the erase frequency ≤ 1.5 times the base frequency, it is classified as natural aging; if Ei < 0.9 × Em but there are more than 3 consecutive ECC or FLASH status abnormal errors, it is determined to be a sudden fault; all others are unknown errors, and a log is printed to remind the user.
[0120] S402. Document Migration Strategy for Wear and Tear and Natural Aging
[0121] The operation log recorded by S102 is used to extract the files associated with bad blocks. At the same time, the free blocks with the lowest current wear are selected by traversing the dynamic wear coefficient table. The files are migrated in batches of 4 pages. After the migration and synchronization are completed, the requested memory resources are released.
[0122] S403, Similar block marking strategy for sudden failures
[0123] Obtain the erase / write frequency and the time interval between the last 5 erases from the S101 statistics. Then, iterate through all non-bad blocks, calculate the above characteristic parameters for each block, and compare them with the faulty blocks. When both the erase / write deviation rate and the time interval deviation rate are <20%, the block is judged as a "similar risk block" and write restrictions are added.
[0124] S404, Update Flash Prediction
[0125] After the bad block is introduced, the prediction interface is called to recalculate the Flash storage lifetime.
[0126] In specific implementation, the triggering period of the timed task in step S101 of the present invention can be adjusted through the system configuration interface. The default period is 300 seconds, and the statistical information is automatically synchronized to the non-volatile storage area.
[0127] The "append to file" method described in step S102 of this invention is a circular overwrite writing method, which can write up to 1024 bad block information.
[0128] The dedicated log buffer mentioned in step 102 of this invention has a size of 5KB and stores the most recent 512 operation records. Each record includes: timestamp (4 bytes, Unix format), physical block address (2 bytes), file handle index (2 bytes), operation type (1 byte, 0x01=erase, 0x02=write, 0x04=delete), and operation status (1 byte, recording the status read by Flash).
[0129] The automatic calculation of the wear factor contribution ratio of the faulty block in step S202 of this invention is achieved by automatically calling the update callback function after the faulty block is identified, through initial registration. This method achieves high cohesion and low coupling in model optimization. By decoupling the weight iteration algorithm from the faulty block detection event through the callback function mechanism, the system architecture becomes clearer and easier to maintain and extend. Simultaneously, the event-driven automatic invocation ensures that the model can respond to fault events instantly without waiting for periodic tasks, resulting in rapid optimization response.
[0130] The weight table in step S202 of this invention is stored in a fixed file and can be modified offline via a host computer. After modification, there is no need to restart the system, which greatly improves the practicality in commercial scenarios.
[0131] In step S302 of this invention, the least squares fitting method only retains the calculation of linear terms and omits higher-order terms to reduce the computational complexity of the system. This ensures that the algorithm can complete the calculation quickly even on a low-frequency MCU, meeting the stringent requirements of embedded systems for real-time performance and low computational load.
[0132] The file migration in step S402 of this invention adopts a checksum verification mechanism. The original block space is released only when the checksum of the file data before and after migration is consistent, thus ensuring data integrity. This method is an important measure to ensure data security and enhances the robustness of the entire system.
[0133] The time data, such as time consumption and CPU time occupied, mentioned in this invention were all obtained by testing with a 72MHz MCU main frequency;
[0134] The method described in this invention is applicable to embedded devices, power distribution, and industrial control scenarios. It is compatible with Nor / NandFlash chips and supports bare metal, RTOS, and Linux operating systems. The core algorithm code size is less than 32KB, which greatly reduces the deployment threshold and cost.
[0135] For example, taking the NandFlash (GD5F1GQ5, 1024 blocks, 128KB per block, Em=100000) in the power distribution terminal DTU as an example, when the device is powered on and running, the system obtains physical parameters through the MTD driver and registers erase / file operation callback functions; the Flash is newly deployed with no factory bad blocks, and there are 10 test files that are written in a ring at a frequency of 5~500s, each file being 1KB. Before writing, the files are deleted first, and the erase is automatically performed by the file system for wear leveling; the device is mounted for a long time, and the monitoring and prediction results are displayed in three stages: early stage, middle stage, and late stage, as shown in Table 1 below:
[0136] Table 1
[0137]
[0138] Note: The table data is generated based on the core logic in the file, including "Dynamic Wear Coefficient Table Construction", "Sliding Window Life Prediction", and "Strategy Optimization".
[0139] In summary, the present invention provides a file system-based real-time monitoring and lifespan monitoring method for Flash storage, enabling real-time health monitoring, lifespan prediction, and intelligent optimization management of Flash storage devices. Specifically, it includes: constructing a dynamic wear coefficient table by real-time collection of block erase counts, file and directory update frequencies to accurately reflect the health status of storage units; dynamically adjusting the prediction model based on a sliding window algorithm, combined with historical erase / write records and current wear trends, to achieve high-precision estimation of the remaining Flash lifespan; and locating the file to which the fault point belongs and its write / erase information by recording file operations before bad blocks, and optimizing subsequent file operation strategies. This method achieves lifespan prediction and strategy optimization through lightweight algorithms and real-time statistical data collection, making it suitable for various scenarios such as embedded devices, power distribution, and industrial control. It is compatible with mainstream Nor / NandFlash chips and supports bare-metal, RTOS, Linux, and other operating systems, offering advantages in real-time performance, high reliability, and wide adaptability.
[0140] Compared with the prior art, the advantages of this invention are as follows:
[0141] 1. This invention breaks through the traditional single evaluation mode that only uses the number of erases. It incorporates the number of block erases, file update frequency, directory update frequency, etc. into the wear assessment system and constructs a dynamic wear coefficient table, which can more comprehensively reflect the actual health status of the storage unit and solve the evaluation bias problem caused by ignoring indirect wear factors in the prior art.
[0142] 2. This invention uses a sliding window algorithm that combines historical erase and write records with current trends. By dynamically adjusting the window size and correcting the decay factor, it achieves high-precision estimation of remaining lifetime. At the same time, the intelligent weight iteration mechanism can continuously optimize the model based on bad block feedback, further improving prediction accuracy and meeting the stringent requirements for lifetime prediction in different scenarios.
[0143] 3. This invention significantly reduces system resource consumption through designs such as replacing division with shift operations, reducing computational load with 16-bit integer operations, low-priority scheduling of timed tasks, and a core algorithm code size of <32KB. It does not rely on large machine learning models and can be directly applied to resource-constrained scenarios such as embedded devices, balancing real-time performance and efficiency. It is also compatible with mainstream Nor / NandFlash flash memory and adaptable to various operating systems including bare metal, RTOS, and Linux, enhancing the technology's versatility and practicality.
[0144] In the above embodiments, implementation can be achieved entirely or partially through software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented entirely or partially in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid-state disk (SSD)).
[0145] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0146] The various embodiments in this specification are described in a related manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the system embodiments are basically similar to the method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions of the method embodiments.
[0147] The above embodiments are only used to illustrate the technical solutions of the present invention, and are not intended to limit it. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for real-time monitoring and lifetime prediction of Flash storage based on a file system, characterized in that, Includes the following steps: S100: Register the memory device, obtain its physical parameter information, collect the number of block erases, file update frequency and directory update frequency in real time, and record the operation log at the same time, thereby constructing a multi-dimensional data set to provide basic data support for the health status assessment and life prediction of the memory. S200, based on the multi-dimensional data set in S100, constructs a dynamic wear coefficient table through dynamic weight allocation and integer linear mapping strategy to accurately quantify the real-time health status of each storage unit; S300, combined with the dynamic wear coefficient table constructed by S200 and the multi-dimensional data set in S100, uses the sliding window method to extract wear trend features, dynamically adjusts the life prediction model, and achieves accurate calculation of remaining life. S400: Based on the operation log recorded in S100 and the dynamic wear coefficient table constructed in S200, the faulty file and related write and erase information are located by analyzing the file operation records before the bad block appears, and file migration or risk blocks are marked based on the fault type, thereby optimizing subsequent file operation behavior. Step S200 Includes the following steps, S201. Data Preprocessing: An integer linear mapping strategy is adopted, scaling the erasure count Ei proportionally and truncating the file update frequency Fi and directory update frequency Di directly. The results are uniformly rounded and mapped to the 0-100 range. The formula is as follows: in: The normalized value for the number of erases for the i-th block, ranging from 0 to 100; Let be the number of times the i-th block is erased; This represents the maximum nominal number of erase cycles per unit. This is a normalized value representing the file update frequency. Let i be the update frequency of the i-th file; Normalized value for the directory update frequency; Let be the update frequency of the i-th directory per unit time. S202, Dynamic Weight Allocation: Weight coefficients are determined using a lookup table method, with the industrial control scenario employing... Power distribution scenarios adopt Embedded scenarios adopt ; Where α, β, and γ are the weights of the number of erases, file update frequency, and directory update frequency, respectively, and α + β + γ = 100%; the weight combination is dynamically switched via API interface at system startup or during operation, with a switching response time ≤ 2 milliseconds; at the same time, an intelligent weight iteration mechanism is adopted, which automatically calculates the contribution ratio of wear factors to the faulty block each time a new bad block event is generated, with the specific formula as follows: In the formula: B The number of bad blocks is due to a sudden failure. B total This is the total number of bad blocks; S203 Wear Coefficient Calculation: Calculate the dynamic wear coefficient of each block according to the formula. The calculation process uses 16-bit integer multiplication and accumulation operation. The result is rounded and stored. The calculation time for a single block is ≤20 microseconds. The remainder is the execution time of the rest of the code. ; In the formula: Let be the current dynamic wear coefficient of the i-th block.
2. The method according to claim 1, characterized in that, Step S100 also includes the following steps: S101, Real-time Erasure Statistics: During system operation, the registered callbacks record the operated block, file, and corresponding timestamp each time an erasure or file operation is performed, and update the log buffer; create a low-priority software timer with a default trigger period of t seconds, and update the cumulative number of erasures and the maximum / minimum erase block information in the timer interrupt; S102, Bad Block Event Recording: When a new bad block is detected, the fault timestamp is recorded, and the operation records before the fault, including the number of writes, the number of erases, the file handles involved, and the operation status of Flash before the fault, are extracted from the dedicated log buffer and stored in the non-volatile memory area of the MCU in the form of file appending. S103. File and directory update frequency statistics: Calculate the file update frequency Fi per unit time; at the same time, calculate the number of file creations, deletions, renamings, and subdirectory changes for each directory per unit time to obtain the directory update frequency Di.
3. The method according to claim 2, characterized in that, Step S300 Includes the following steps, S301. Sliding window initialization: The window size is N=32, a power of 2. A circular buffer is used to store the wear coefficient Wi, the erase count increment ΔEi, and the time interval Δti of the most recent 64 erase operations, in seconds. S302, Trend Feature Extraction: Calculate the mean wear coefficient μW, variance σW, erase frequency slope k, and current attenuation factor λ within the window; Calculate the mean wear coefficient μW within the window: N is the window size; Calculate the variance of the wear coefficient σW within the window: Where: μW: mean wear coefficient within the window; Calculate the slope k of the erasure frequency trend: Using the timestamp ti (in seconds) of each erase within the window relative to the window's start time as the x-axis and the erase increment ΔEi as the y-axis, the least squares method is used to fit the straight line y=kx+b, and the formula for calculating the slope k is: In the formula: ti: timestamp of each erasure; Increment of erase count; Calculate the attenuation factor λ: The durability curve is dynamically adjusted according to the Flash specification. The initial value for new equipment is 1.0, and it linearly decreases to 0.8 when the maximum number of erases Ec≥0.5Em. Where: Ec: current maximum number of erases, Em: maximum number of erases; S303. Dynamic lifetime prediction: Estimate the remaining lifetime according to the following formula; In the formula: L is the remaining lifetime, expressed as a percentage; λ is the decay factor; fb is the reference erase frequency, in units of times / 300 seconds; and k is the slope of the erase frequency trend.
4. The method according to claim 3, characterized in that, S400 includes the following sub-steps: S401. Fault Cause Judgment: Combining the cumulative erase count Ei corresponding to the physical address of the bad block, the erase frequency per unit time before the fault, and the read FLASH status, the fault type is determined by a preset threshold: If Ei ≥ 0.9 × Em and the erase frequency ≥ 1.5 times the base frequency, it is determined to be wear and aging; if the erase frequency ≤ 1.5 times the base frequency, it is classified as natural aging; if Ei < 0.9 × Em but there are more than 3 consecutive ECC or FLASH status abnormal errors, it is determined to be a sudden fault; the rest are unknown errors, and a log is printed to remind the user. S402, file migration strategy for wear and natural aging: Extract files associated with bad blocks from the operation log recorded in S102, and at the same time, traverse the free block with the lowest current wear from the dynamic wear coefficient table, and migrate files in batches of 4 pages. Release the allocated memory resources after the migration and synchronization are completed. S403, Similar block marking strategy for sudden failures: Obtain the erase / write frequency and the time interval between the last 5 erases of the faulty block from the statistical data of S101, and traverse all non-bad blocks, calculate the characteristic parameters of each block, compare them with the faulty block, and when the erase / write deviation rate and the time interval deviation rate are both <20%, it is judged as a "similar risk block" and write restrictions are added. S404, Update Flash Prediction: After updating the bad block information, the prediction interface is called again to calculate the Flash storage lifetime.
5. The method according to claim 2, characterized in that, Step S101 includes adjusting the triggering period of the scheduled task through the system configuration interface. The default period t is 300 seconds, and the statistical information is automatically synchronized to the non-volatile storage area.
6. The method according to claim 2, characterized in that, The file appending method described in step S102 is a circular overwrite writing method, which can write up to 1024 bad block information.
7. The method according to claim 2, characterized in that, The dedicated log buffer is 5KB in size and stores the most recent 512 operation records. Each record contains: a timestamp in 4 bytes (Unix format), a physical block address in 2 bytes, a file handle index in 2 bytes, an operation type in 1 byte (0x01 = erase, 0x02 = write, 0x04 = delete), and an operation status in 1 byte, recording the status read from the Flash.
8. The method according to claim 1, characterized in that, The automatic calculation of the wear factor contribution ratio of the faulty block in step S202 is achieved by using the initialized and registered update callback function. After a bad block is identified, the function is automatically called to update the weight, and the weight is then incorporated into the calculation after the next scheduled task arrives.
9. The method according to claim 4, characterized in that, The file migration described in step S402 employs a verification mechanism. The original block space is only released when the verification sum of the file data before and after the migration is consistent, thus ensuring data integrity.
Citation Information
Patent Citations
Method for prolonging service life of Flash
CN110658981A
Flash memory wear leveling algorithm based on multiple thresholds
CN110688326A