A data storage method, apparatus, device, and medium for a Flash memory.
By setting up multiple storage areas in the Flash memory and writing a second value into the real-time recording block for data migration, the problem of limited write cycles of the Flash memory is solved, extending its service life and improving the accuracy and efficiency of data storage.
Patent Information
- Application Number
- CN202411871059.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-18
- Publication Date
- 2026-01-30
- Estimated Expiration
- 2044-12-18
AI Technical Summary
Flash memory has a limited number of erase/write cycles, which severely affects its lifespan. Traditional data storage methods increase the number of erase/write cycles, thus shortening the lifespan of Flash memory.
At least two storage regions are defined in the Flash memory, each region including a storage block and a real-time recording block. Data is synchronously recorded by writing a second value into the real-time recording block in the first region. After the stored data is written to the second region, the first region is erased, thereby realizing data migration and alternating use of multiple storage regions.
This effectively reduces the number of erase cycles, extends the lifespan of the Flash memory, and ensures the accuracy and efficiency of data storage.
Smart Images

Figure CN119883111B_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the field of electronic information technology, and specifically relates to a data storage method, apparatus, device and medium for a Flash memory. Background Technology
[0002] With the rapid development of technology, Flash memory is widely used in electronic devices to store non-volatile data. However, Flash memory has a limited number of erase / write cycles, typically between 10,000 and 1,000,000, making its lifespan a major limiting factor. Therefore, high-frequency erase / write operations severely impact the lifespan of Flash memory. Traditional Flash storage methods often use simple overwrite operations, which increases the number of erase / write cycles and thus shortens the Flash memory's lifespan.
[0003] Therefore, how to achieve efficient data writing and reasonably control the number of erasures is a technical problem that urgently needs to be solved by those skilled in the art. Summary of the Invention
[0004] This application provides a data storage method, apparatus, device, and medium for Flash memory. The purpose is to provide a novel data storage method that can effectively reduce the number of erase cycles and improve the lifespan of Flash memory while ensuring the accuracy of stored data.
[0005] In a first aspect, embodiments of this application provide a data storage method for a Flash memory, the method comprising:
[0006] At least two storage regions are defined in the Flash memory, each storage region including a storage block and a real-time recording block;
[0007] Using the first region as the real-time write region, when an increase in data to be stored is detected, the first value corresponding to the number of data increases is written as the second value in the real-time recording block of the first region.
[0008] After all the first values in the real-time recording block in the first region are written to the second values, the data to be stored recorded in the storage block in the first region and the real-time recording block are written to the storage block in the second region, and the second region is used as the instant writing area.
[0009] Erase the storage blocks and real-time recording blocks in the first area.
[0010] Furthermore, the method also includes:
[0011] When a query request for data to be stored is detected, the value stored in the storage block of the instant write area is identified, and / or the number of times the second value is written in the real-time record block of the instant write area is identified, so as to obtain the query result of the data to be stored.
[0012] Furthermore, writing the data to be stored recorded in the storage blocks and real-time recording blocks in the first region to the storage blocks in the second region includes:
[0013] The data to be stored, recorded in the storage blocks and real-time recording blocks in the first region, is written to the storage blocks in the second region in binary format.
[0014] Furthermore, the data to be stored recorded in the storage blocks and real-time recording blocks in the first region is written to the storage blocks in the second region in binary format, including:
[0015] The number of binary values read from the storage block in the first area and the number of second values read from the real-time recording block in the first area are summed to obtain the recorded data to be stored.
[0016] Write it to the storage block in the second area in binary format.
[0017] Furthermore, upon detecting an increase in data to be stored, the first value corresponding to the number of data increases is written as the second value in the real-time recording block of the first area, including:
[0018] When an increase in data to be stored is detected, the corresponding number of 1 values are written as 0 in the real-time recording block of the first area according to a preset order based on the number of data increases.
[0019] Furthermore, the method also includes:
[0020] After all the first values in the real-time recording block in the second region are written to the second values, the data to be stored recorded in the storage block in the second region and the real-time recording block are written to the storage block in the first region, and the first region is used as the instant write region.
[0021] Furthermore, the data to be stored is monotonically increasing data.
[0022] Secondly, embodiments of this application provide a data storage device for a Flash memory, the device comprising:
[0023] The storage area determination module is used to determine at least two storage areas in the Flash memory, each storage area including a storage block and a real-time recording block;
[0024] The data recording module is used to use the first area as the real-time writing area. When it detects that the data to be stored has increased, it writes the first value corresponding to the number of data increases into the real-time recording block in the first area as the second value.
[0025] The data migration module is used to write the data to be stored recorded in the storage block of the first area and the real-time recording block to the storage block of the second area after all the first values in the real-time recording block of the first area are written to the second values, and the second area is used as the instant writing area.
[0026] The erase processing module is used to erase the storage blocks and real-time recording blocks in the first area.
[0027] Thirdly, embodiments of this application provide an electronic device including a processor, a memory, and a program or instructions stored in the memory and executable on the processor, wherein the program or instructions, when executed by the processor, implement the steps of the method described in the first aspect.
[0028] Fourthly, embodiments of this application provide a readable storage medium on which a program or instructions are stored, which, when executed by a processor, implement the steps of the method described in the first aspect.
[0029] Fifthly, embodiments of this application provide a chip, the chip including a processor and a communication interface, the communication interface being coupled to the processor, the processor being used to run programs or instructions to implement the method as described in the first aspect.
[0030] In this embodiment, at least two storage regions are defined in the Flash memory, each including a storage block and a real-time recording block. A first region is used as the real-time write region. When an increase in data to be stored is detected, the first value corresponding to the number of data increases is written as a second value in the real-time recording block of the first region. After all the first values in the real-time recording block of the first region are written as second values, the data to be stored recorded in the storage block and real-time recording block of the first region is written to the storage block of the second region, and the second region is used as the real-time write region. The storage block and real-time recording block of the first region are then erased. This technical solution, by using multiple storage regions for alternating storage and synchronously recording by writing the first value as the second value when the data to be stored changes, eliminates the need for erasure operations. It allows for migration to another region for recording after all data in one region is written as the second value, and then erasure of the current region. This effectively reduces the number of erasures, ensuring the accuracy of the stored data while reducing the number of erasures and improving the lifespan of the Flash memory. Attached Figure Description
[0031] Figure 1 This is a flowchart illustrating the data storage method of the Flash memory provided in an embodiment of this application;
[0032] Figure 2 This is a schematic diagram of the first region provided in the embodiments of this application;
[0033] Figure 3 This is a flowchart illustrating the data storage method of the Flash memory provided in an embodiment of this application;
[0034] Figure 4 This is a schematic diagram illustrating data migration using two storage areas as an example, provided in an embodiment of this application.
[0035] Figure 5 This is a schematic diagram of the data storage device of the Flash memory provided in the embodiments of this application;
[0036] Figure 6 This is a schematic diagram of the structure of the electronic device provided in the embodiments of this application. Detailed Implementation
[0037] To make the objectives, technical solutions, and advantages of this application clearer, specific embodiments of this application will be described in further detail below with reference to the accompanying drawings. It should be understood that the specific embodiments described herein are merely for explaining this application and not for limiting it. It should also be noted that, for ease of description, only the parts relevant to this application are shown in the drawings, not all of them. Before discussing exemplary embodiments in more detail, it should be mentioned that some exemplary embodiments are described as processes or methods depicted as flowcharts. Although the flowcharts describe operations (or steps) as sequential processes, many of these operations can be performed in parallel, concurrently, or simultaneously. Furthermore, the order of the operations can be rearranged. The process can be terminated when its operation is completed, but may also have additional steps not included in the drawings. The process can correspond to a method, function, procedure, subroutine, subprogram, etc.
[0038] The technical solutions of the embodiments of this application will be clearly described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this application. All other embodiments obtained by those skilled in the art based on the embodiments of this application are within the scope of protection of this application.
[0039] The terms "first," "second," etc., used in the specification and claims of this application are used to distinguish similar objects and not to describe a specific order or sequence. It should be understood that such use of data can be interchanged where appropriate so that embodiments of this application can be implemented in orders other than those illustrated or described herein, and the objects distinguished by "first," "second," etc., are generally of the same class and the number of objects is not limited; for example, a first object can be one or more. Furthermore, in the specification and claims, "and / or" indicates at least one of the connected objects, and the character " / " generally indicates that the preceding and following objects are in an "or" relationship.
[0040] The data storage method, apparatus, device, and medium of the Flash memory provided in this application will be described in detail below with reference to the accompanying drawings and through specific embodiments and application scenarios.
[0041] Figure 1 This is a flowchart illustrating the data storage method of the Flash memory provided in an embodiment of this application. Figure 1 As shown, the specific steps include the following:
[0042] S101, at least two storage regions are determined in the Flash memory, each storage region including a storage block and a real-time recording block;
[0043] Flash memory, also known as flash storage, is a common electronic storage device. It uses floating gates in its storage cells to store electrical charge, representing data 0 or 1. By applying appropriate voltage, these storage cells can be programmed (written with data) and erased, thus enabling data storage and updates. Currently, NOR Flash is the most common type. Its storage cells are arranged similarly to ordinary memory cells, supporting byte-level random access with relatively fast read speeds. It is often used to store critical information requiring rapid access, such as boot code and firmware in embedded systems. However, its integration density is relatively lower, and its storage capacity is often smaller than NAND Flash under the same manufacturing process. NAND Flash uses a unique serial-parallel structure, achieving high storage density and large-capacity storage. Common high-capacity storage devices such as solid-state drives, USB flash drives, and memory cards primarily use NAND Flash. However, its read speed is generally slower than NOR Flash, as it cannot perform byte-level random access. Flash memory is non-volatile; even when power is off, the stored data is not lost, ensuring long-term data preservation. For example, the memory cards in digital cameras retain the photos even when the camera is out of power. Flash memory can be repeatedly erased and written to, allowing for easy updates to stored content as needed. Currently, Flash memory is available in various capacities, ranging from small capacities suitable for simple applications to ultra-large capacities for storing massive amounts of data. For example, there are small flash memory drives with capacities of a few megabytes for simple embedded devices, and larger solid-state drives for data center storage.
[0044] The system comprises at least two storage regions, each of which can be a page or a sector, and each storage region includes a storage block and a real-time recording block. For example, assuming a storage region comprises 4KB bytes, it can contain 32,768 bits. The first 32 bits can be used as the storage block, and the remaining bits as the real-time recording block. Therefore, the storage block can record a range of 0-4,294,967,295. The remaining bits, for example, could be 32,736 bits (32,768 minus 32). Each bit can have a default value of the first value, which can be changed to the second value after being written.
[0045] S102, using the first area as the real-time writing area, when the increase in data to be stored is detected, the first value corresponding to the number of data increases is written as the second value in the real-time recording block of the first area.
[0046] The instant write area is the area currently used for synchronizing and recording data to be stored. For example, if the data to be stored increases by 1, the instant write area will also increase by 1 based on the original recorded value, while other areas do not need to participate in the recording of this change.
[0047] In this embodiment, optionally, the data to be stored is monotonically increasing data.
[0048] Among these, monotonically increasing data includes, for example, the number of times a computer is turned on or other counters. The changes in this data are monotonically increasing and will not decrease.
[0049] In this solution, if the amount of data to be stored decreases, it may be necessary to rewrite the value 0 to the value 1, which would require erasing and rewriting. Therefore, by limiting the data to be stored to a monotonically increasing form, this solution can better ensure data storage and avoid excessive erasing operations during the storage process, thus improving the lifespan of the Flash memory.
[0050] In one embodiment, optionally, when an increase in data to be stored is detected, the first value corresponding to the number of data increases is written as the second value in the real-time recording block of the first area, including:
[0051] When an increase in data to be stored is detected, the corresponding number of 1 values are written as 0 in the real-time recording block of the first area according to a preset order based on the number of data increases.
[0052] The addition of data to be stored can be done in two ways: by adding a single value at a time, such as the number of system boots, or by adding multiple values at once, such as recording the number of applications opened by the user after the current boot. When multiple applications are opened at once, these values can be stored, for example, by adding three values at once. In this scheme, when an increase in data to be stored is detected, the corresponding number of 1s in the real-time recording block of the first area are written as 0s, according to the number of data additions. This allows for the synchronous recording of the data to be stored by counting the number of 0s in the real-time recording block of the first area. Furthermore, the operation of writing 1s as 0s is performed in a specific order.
[0053] Figure 2 This is a schematic diagram of the first region provided in an embodiment of this application. For example... Figure 2As shown, assuming the size of the first region is 4KB, it is equivalent to a total of 4096 bytes. Since 1 byte is 8 bits, there are a total of 32768 bits. Among them, 0X2000 is a storage block with 32 bits. If counted in binary, its countable range is 0 to 4294967295. 0X2004 to 0X2FFC are real-time recording blocks. 0X2004 has 32 bits, each with an initial value of 1. When the data to be stored is increased, the corresponding number of 1s can be rewritten to 0. After all the bits in 0X2004 are rewritten to 0, they can be rewritten in 0X2008. For example, if the current data to be stored is 14, the last 14 bits of the 32 1s in 0X2004 can be rewritten to 0, that is, from 11111111 1111 1111 1111 1111 1111 1111, it can be rewritten to 1111 1111 111111111 1100 0000 00000000.
[0054] This solution, through this configuration, can accurately record the data to be stored, and eliminates the need for erasure during the recording process, thereby improving recording efficiency and extending the lifespan of the Flash memory.
[0055] S103, after all the first values in the real-time recording block in the first region are written as the second values, the data to be stored recorded in the storage block in the first region and the real-time recording block are written to the storage block in the second region, and the second region is used as the instant writing region.
[0056] In this scheme, after all the first values in the real-time recording block of the first region are written to the second values, that is, after all the 1s are changed to 0s, the data to be stored recorded in the first region can be written to the storage block of the second region. For example, if there is no recorded data in the storage block of the first region, 32736 0s are read from the real-time recording block, that is, the data to be stored recorded is 32736, and written to the storage block of the second region. In this way, the migration of storage regions is realized, and the second region can be used as an immediate writing region, that is, the changes of the data to be stored can continue to be recorded through the real-time recording block of the second region. The recording method can still be to change the 1s to 0s.
[0057] In one embodiment, optionally, writing the data to be stored recorded in the storage blocks of the first region and the real-time recording blocks to the storage blocks of the second region includes:
[0058] The data to be stored, recorded in the storage blocks and real-time recording blocks in the first region, is written to the storage blocks in the second region in binary format.
[0059] In this scheme, the second region can have the same partitioning method as the first region, divided into storage blocks and real-time recording blocks.
[0060] The process of writing the data to be stored recorded in the first area to the storage block in the second area can be done in binary mode. Since the storage block in the second area also has 32 bits, if the data is recorded in binary mode, the storage block can record a range of 0-4294967295, which has a powerful recording capability.
[0061] Therefore, this solution, through such a configuration, can ensure the accuracy of the recorded data to be stored during the storage area migration process, while also possessing good recording capabilities, thus ensuring the feasibility of the solution.
[0062] In one embodiment, optionally, the data to be stored recorded in the storage blocks and real-time recording blocks in the first region is written to the storage blocks in the second region in binary format, including:
[0063] The number of binary values read from the storage block in the first area and the number of second values read from the real-time recording block in the first area are summed to obtain the recorded data to be stored.
[0064] Write it to the storage block in the second area in binary format.
[0065] In this scheme, there is another situation where data is also recorded in the storage block of the first area. In this case, since the data is recorded in binary mode, the recorded value can be read in binary mode and added to the number of 0s read in the real-time recording block to obtain the actual recorded value of the first area.
[0066] For example, if the data is migrated from the first region to the second region and then migrated back to the first region, the size of the data to be stored recorded during the migration will be stored in binary format in the storage block of the first region, so that the storage block will also have the corresponding value.
[0067] This solution, through such settings, ensures accurate recording of stored data during the migration process, preventing data loss and errors in data recording.
[0068] S104, Erase the storage block and real-time recording block in the first area.
[0069] In this scheme, since data migration has been performed, the data in the first area has been successfully written to the storage block in the second area. The second area is used as the immediate write area, so the first area can be erased, and the first area can be used as the target area for the next migration.
[0070] Understandably, when multiple regions exist, migration can be carried out in a certain order, such as region 1 → region 2 → region 3 → region 4 → region 1, etc. As long as there are at least two storage regions, data migration can be achieved, and the previous region can be erased after each migration, thereby reducing the number of times the storage region is erased and improving the lifespan of the Flash memory.
[0071] The technical solution provided in this embodiment defines at least two storage areas in the Flash memory, each storage area including a storage block and a real-time recording block. A first area is used as the real-time write area. When an increase in data to be stored is detected, the first value corresponding to the number of data increases is written as a second value in the real-time recording block of the first area. After all the first values in the real-time recording block of the first area are written as second values, the data to be stored recorded in the storage block and the real-time recording block of the first area is written to the storage block of the second area, and the second area is used as the real-time write area. The storage block and the real-time recording block of the first area are then erased. This technical solution, by using multiple storage areas for alternating storage and synchronously recording by writing the first value as the second value when the data to be stored changes, can achieve the goal of moving to another area for recording after all data in one area is written as the second value, and then erasing the current area, without the need for an erase operation. This effectively reduces the number of erase operations, ensuring the accuracy of the stored data while reducing the number of erase operations and improving the lifespan of the Flash memory.
[0072] In one embodiment, optionally, the method further includes:
[0073] When a query request for data to be stored is detected, the value stored in the storage block of the instant write area is identified, and / or the number of times the second value is written in the real-time record block of the instant write area is identified, so as to obtain the query result of the data to be stored.
[0074] Based on the above technical solution, if a query request for data to be stored is detected, the value stored in the storage block of the real-time write area (if any) and the number of times the second value is written in the real-time record block (if any) can be added together as the query result for the data to be stored.
[0075] For example, during the data recording process in the first area, since no migration operation has occurred yet, there will be no stored values in the storage blocks of the first area. At this time, we can only rely on the number of times the second value is written in the real-time recording block.
[0076] If a value has just been migrated from the first region to the second region, meaning there is a value stored in the storage block of the second region, but all values in the real-time recording block are 1 and no bit has been changed to 0, then the value stored in the storage block of the second region can be used as the standard.
[0077] In this scheme, in order to accurately read the data to be stored, after receiving the query request, both the storage block of the immediate write area and the real-time record block can be read once, and the data read can be summed to obtain the query result.
[0078] This solution, through such settings, can determine different reading methods for different regions and provide accurate data feedback to query requests based on the reading results.
[0079] In one embodiment, optionally, the method further includes:
[0080] After all the first values in the real-time recording block in the second region are written to the second values, the data to be stored recorded in the storage block in the second region and the real-time recording block are written to the storage block in the first region, and the first region is used as the instant write region.
[0081] In this scheme, after all the first values in the real-time recording block of the second region are written to the second values, the stored data can be migrated to the storage block of the first region, and the first region can be used as the real-time writing area again. This can realize the cyclic migration operation of multiple storage regions, so as to realize the recording of the data to be stored without investing in a lot of storage regions, effectively control the number of erases of storage regions, and improve the lifespan of the Flash memory.
[0082] To enable those skilled in the art to more clearly understand this technical solution, a preferred embodiment is also provided. Figure 3 This is a flowchart illustrating the data storage method of the Flash memory provided in an embodiment of this application. Figure 3 As shown, the specific steps include the following:
[0083] Step 1: Define two or more storage regions in the Flash memory, and divide the storage regions into several smaller blocks.
[0084] Each region can be 4KB in size. Within each region, a certain byte is designated to be used for cyclic inheritance of the total count, thereby recording the count of an incrementing variable and achieving partitioned cyclic storage.
[0085] Step 2: Each time the variable increases, the 1s in the byte are gradually converted to 0s using the method of converting 1s to 0s in the Flash memory, and the increment of the variable value is represented by the number of 0s in the byte.
[0086] For example, if there are 5 zeros in an address, it means that the value of the variable is "5". For example, if there is a variable 5 in the memory area 0X2000, when the monotonically increasing variable increases from 5 to 6, it is written to the address by overwriting, and the address content changes from 1110-0000 to 1100-0000. The embedded device obtains the value of the variable by reading the total number of zeros in the address. This method does not require erasing the original data.
[0087] Step 3: When the number of 0s in a region reaches the set maximum value, write the count value in that region to the specified location in another region.
[0088] The specified location can be the first four bytes or the last four bytes, and the data in the current area is erased, thereby realizing the periodic circular storage of data; for example: address 0x2000 is used as the total size of the statistical variable, 0x2004~0x2FFF is used for counting, the counting area is filled with "0", the total number is written to address 0x3000 to save the total number, and the counting continues from 0x3004~0x3FFF, and 0x2000~0x2FFF is erased.
[0089] Step 4: After the second area has finished counting, write the count value back to the first area and erase the second area.
[0090] In this way, each storage and erase / write operation is performed alternately, avoiding frequent erasure and writing of the same area, thereby effectively reducing the number of times the Flash memory is erased and written.
[0091] Furthermore, the storage method of this embodiment is suitable for scenarios that require recording incremental counts, such as device usage counts, system version numbers, etc. By writing the number of 0s in different areas to represent the cumulative count value, the storage efficiency is further improved without frequently erasing and writing the contents of the Flash memory.
[0092] The advantages of this preferred embodiment are: extending the lifespan of the Flash memory; reducing the number of erase / write cycles through partitioned cyclic storage and special statistical methods, significantly reducing the erase / write burden on the Flash memory and substantially extending the device's lifespan; improving storage efficiency: by using the number of zeros to represent data values, storage space waste can be effectively reduced and storage efficiency improved; suitable for storing monotonically increasing variables: this invention is suitable for embedded devices, IoT devices, wearable devices, etc., that require storing monotonically increasing data, especially performing well in storing data such as counters and device status; simplifying data management: this method simplifies data storage and management by alternately using different areas to store counters, avoiding frequent storage area allocation and cleanup.
[0093] The optimization scheme for extending the lifespan of Flash memory provided by this invention specifically includes: periodic allocation of storage areas: multiple storage areas of the same size are set in the Flash memory, and when the count value of one area reaches the maximum value, the system switches to the next area for storage. This avoids frequent erase and write operations on the same storage area, extending the lifespan of each area; and an incrementing variable representation method: the increment of the variable is represented by converting 1 to 0 in each byte. This method can effectively reduce the number of erase and write operations during each data write, further improving the durability of the Flash memory.
[0094] This invention also provides a counter storage method for embedded devices, IoT devices, and wearable devices. The counter stores monotonically increasing data such as device power-on count, version number, and device status change count. This method reduces frequent erase / write operations on the Flash storage area by using the incremental counting mechanism of the Flash memory, thus extending the device's lifespan. Theoretically, for the same storage space, compared to traditional storage methods, it reduces the number of erase operations by 32 times, thereby increasing the lifespan by 32 times.
[0095] The storage method provided in this invention can flexibly control the increment of the count within a range of data value variations. For example, after the count reaches a certain threshold, the size of the storage area can be increased or the upper limit of the count can be increased to adapt to the needs of data changes in different application scenarios.
[0096] Figure 4 This is a schematic diagram illustrating data migration using two storage areas as an example, provided in an embodiment of this application. Figure 4As shown: First, the Flash memory is divided into two storage areas, which are used to store incrementing variable values. The starting address of the storage area is used to store the total count, using a normal statistical method. The remaining addresses use the "0" count method of this invention. When it is necessary to record the increment of the variable, the actual value of the variable is not written directly. Instead, the increment is represented by changing the bit state of the Flash storage cell (from 1 to 0). For example, when the variable increases by 1, 0 is written to the free cell of the current storage area, representing the current increment of the variable. By recording the number of 0s in the current area, the current value of the variable can be represented. When the number of 0s in the current area reaches a set threshold, for example, when the entire 4KB storage area is filled with "0", the count value is transferred to the next storage area. For example, when the storage space of the first storage area is almost full, the total variable count recorded in the first storage area is transferred to the starting address of the second storage area, and the storage cells of the first storage area are erased and reinitialized to 1 for the next cycle.
[0097] This method uses a partitioned, cyclical approach to gradually transfer data to the next region, achieving space recycling and reducing the frequency of flash write / erase cycles. By writing zeros sequentially to each region to represent incremental data changes, flash wear can be effectively reduced, extending the lifespan of the flash memory.
[0098] Furthermore, the storage method of this embodiment is suitable for scenarios that require recording incremental counts, such as device usage counts, system version numbers, etc. By writing the number of 0s in different areas to represent the cumulative count value, the storage efficiency is further improved without frequently erasing and writing the contents of the Flash memory.
[0099] This invention provides an innovative storage method that can effectively improve the lifespan of Flash memory. By using an incremental storage method that represents the size of variables based on zero and a partitioned circular storage mechanism, the number of erase and write cycles of Flash memory is significantly reduced, thus providing a more efficient and durable data storage solution for various embedded systems, IoT devices, and the like.
[0100] Figure 5 This is a schematic diagram of the data storage device of the Flash memory provided in the embodiments of this application; as shown... Figure 5 As shown, the device includes:
[0101] The storage area determination module 501 is used to determine at least two storage areas in the Flash memory, each storage area including a storage block and a real-time recording block;
[0102] The data recording module 502 is used to use the first area as the real-time writing area. When it detects that the data to be stored has increased, it writes the first value corresponding to the number of data increases into the real-time recording block in the first area as the second value.
[0103] The data migration module 503 is used to write the data to be stored recorded in the storage block of the first area and the real-time recording block to the storage block of the second area after all the first values in the real-time recording block of the first area are written to the second values, and the second area is used as the instant writing area.
[0104] The erasure processing module 504 is used to erase the storage block and the real-time recording block in the first area.
[0105] The technical solution provided in this embodiment defines at least two storage areas in the Flash memory, each storage area including a storage block and a real-time recording block. A first area is used as the real-time write area. When an increase in data to be stored is detected, the first value corresponding to the number of data increases is written as a second value in the real-time recording block of the first area. After all the first values in the real-time recording block of the first area are written as second values, the data to be stored recorded in the storage block and the real-time recording block of the first area is written to the storage block of the second area, and the second area is used as the real-time write area. The storage block and the real-time recording block of the first area are then erased. This technical solution, by using multiple storage areas for alternating storage and synchronously recording by writing the first value as the second value when the data to be stored changes, can achieve the goal of moving to another area for recording after all data in one area is written as the second value, and then erasing the current area, without the need for an erase operation. This effectively reduces the number of erase operations, ensuring the accuracy of the stored data while reducing the number of erase operations and improving the lifespan of the Flash memory.
[0106] The data storage device of the Flash memory in this application embodiment can be a device, or it can be a component, integrated circuit, or chip in a terminal. The device can be a mobile electronic device or a non-mobile electronic device. For example, mobile electronic devices can be mobile phones, tablets, laptops, PDAs, in-vehicle electronic devices, wearable devices, ultra-mobile personal computers (UMPCs), netbooks, or personal digital assistants (PDAs), etc., while non-mobile electronic devices can be servers, network attached storage (NAS), personal computers (PCs), televisions (TVs), ATMs, or self-service machines, etc. This application embodiment does not specifically limit the scope.
[0107] The data storage device of the Flash memory in this application embodiment can be a device with an operating system. This operating system can be Android, iOS, or other possible operating systems; this application embodiment does not specifically limit the specific operating system used.
[0108] The data storage device of the Flash memory provided in this application embodiment can implement the various processes implemented in the above method embodiments. To avoid repetition, it will not be described again here.
[0109] Figure 6 This is a schematic diagram of the structure of the electronic device provided in an embodiment of this application. For example... Figure 6 As shown, this application embodiment also provides an electronic device 600, including a processor 601, a memory 602, and a program or instructions stored in the memory 602 and executable on the processor 601. When the program or instructions are executed by the processor 601, they implement the various processes of the data storage device embodiment of the Flash memory described above and can achieve the same technical effect. To avoid repetition, they will not be described again here.
[0110] It should be noted that the electronic devices in the embodiments of this application include the mobile electronic devices and non-mobile electronic devices described above.
[0111] This application also provides a readable storage medium storing a program or instructions. When the program or instructions are executed by a processor, they implement the various processes of the data storage device embodiment of the Flash memory described above and achieve the same technical effect. To avoid repetition, they will not be described again here.
[0112] The processor is the processor in the electronic device described in the above embodiments. The readable storage medium includes computer-readable storage media, such as computer read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk.
[0113] This application embodiment also provides a chip, which includes a processor and a communication interface. The communication interface is coupled to the processor. The processor is used to run programs or instructions to implement the various processes of the data storage device embodiment of the Flash memory described above, and can achieve the same technical effect. To avoid repetition, it will not be described again here.
[0114] It should be understood that the chip mentioned in the embodiments of this application may also be referred to as a system-on-a-chip, system chip, chip system, or system-on-a-chip, etc.
[0115] It should be noted that, in this document, 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 that element. Furthermore, it should be noted that the scope of the methods and apparatuses in the embodiments of this application is not limited to performing functions in the order shown or discussed, but may also include performing functions substantially simultaneously or in the reverse order, depending on the functions involved. For example, the described methods may be performed in a different order than described, and various steps may be added, omitted, or combined. Additionally, features described with reference to certain examples may be combined in other examples.
[0116] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a computer software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods described in the various embodiments of this application.
[0117] The embodiments of this application have been described above with reference to the accompanying drawings. However, this application is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of this application without departing from the spirit and scope of the claims, and all of these forms are within the protection scope of this application.
[0118] The above description is merely a preferred embodiment and the technical principles employed in this application. This application is not limited to the specific embodiments described herein, and various obvious changes, readjustments, and substitutions that can be made by those skilled in the art will not depart from the scope of protection of this application. Therefore, although this application has been described in detail through the above embodiments, this application is not limited to the above embodiments, and may include more other equivalent embodiments without departing from the concept of this application, the scope of which is determined by the scope of the claims.
Claims
1. A data storage method for a Flash memory, characterized by, The method comprises: determining at least two storage areas in a flash memory, each of the storage areas comprising a storage block and a real-time recording block; when an increase in the to-be-stored data is identified, writing a corresponding number of first values as second values in the real-time recording block in the first area according to the number of the increased data; after all the first values in the real-time recording block in the first area are written as second values, reading binary values in the storage block in the first area and the number of the second values in the real-time recording block in the first area, summing up the to-be-stored data recorded to write the data in the storage block of the second area in binary form, and taking the second area as the real-time writing area; erasing the storage block and the real-time recording block in the first area; after all the first values in the real-time recording block in the second area are written as second values, writing the to-be-stored data recorded in the storage block and the real-time recording block in the second area to the storage block of the first area, and taking the first area as the real-time writing area; when a query request of the to-be-stored data is identified, identifying the values stored in the storage block of the real-time writing area, identifying the number of the first values written as second values in the real-time recording block of the real-time writing area, summing up the number of the first values and the number of the second values to determine the query result of the to-be-stored data.
2. The data storage method of a Flash memory according to claim 1, wherein, When an increase in the to-be-stored data is identified, writing a corresponding number of first values as second values in the real-time recording block in the first area according to the number of the increased data, comprising: When an increase in the to-be-stored data is identified, writing a corresponding number of values 1 as values 0 in the real-time recording block in the first area according to a preset order according to the number of the increased data.
3. The data storage method of a Flash memory according to any one of claims 1-2, wherein, The to-be-stored data is monotonically increasing data.
4. A data storage device for a Flash memory, characterized by The device comprises: a storage area determination module configured to determine at least two storage areas in a flash memory, each of the storage areas comprising a storage block and a real-time recording block; a data recording module configured to, when an increase in the to-be-stored data is identified, write a corresponding number of first values as second values in the real-time recording block in the first area according to the number of the increased data; a data migration module configured to, after all the first values in the real-time recording block in the first area are written as second values, read binary values in the storage block in the first area and the number of the second values in the real-time recording block in the first area, sum up the to-be-stored data recorded to write the data in the storage block of the second area in binary form, and take the second area as the real-time writing area; an erasing processing module configured to erase the storage block and the real-time recording block in the first area; The data storage method of the Flash memory further comprises: after all the first values in the real-time recording block in the second area are written as the second values, writing the storage block in the second area and the to-be-stored data recorded in the real-time recording block into the storage block of the first area, and taking the first area as an instant writing area; and when a query request of the to-be-stored data is identified, identifying the values stored in the storage block of the instant writing area, identifying the number of the second values written in the real-time recording block of the instant writing area, and determining the sum of the number of the first values and the number of the second values as a query result of the to-be-stored data.
5. An electronic device, comprising: A computer readable storage medium stores a program or instructions, which, when executed by a processor, implement the steps of the data storage method of the Flash memory according to any one of claims 1-3.
6. A readable storage medium characterized by, A computer readable storage medium stores a program or instructions, which, when executed by a processor, implement the steps of the data storage method of the Flash memory according to any one of claims 1-3.
Citation Information
Patent Citations
Data storage method and read-write equipment
CN112711378A
Coding method and device and electronic equipment
CN117631952A