Data storage method and apparatus
By introducing an SRAM cache and sequential address writing into the flash memory, combined with backup partition management, the problems of uneven lifespan and data loss caused by frequent erasure and write operations in flash memory are solved, achieving a longer lifespan and higher data reliability.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-31
- Publication Date
- 2026-03-27
AI Technical Summary
Existing data storage methods based on flash memory suffer from uneven lifespan of storage blocks due to frequent erasure and rewriting, affecting the overall lifespan, and data is easily lost when power is off.
It employs a data cache area built on static random access memory (SRAM) and a storage area built on flash memory, and writes data according to the storage block address order. Combined with backup partitions and frequent/infrequent recording partitions to manage data, it ensures that data is saved in time when power is lost and the number of erase and write cycles is balanced.
It effectively extends the lifespan of flash memory, avoids the problem of failure due to excessive wear of some storage blocks, and ensures that data is not lost when power is off, thereby improving the reliability of data storage and management efficiency.
Smart Images

Figure CN115373607B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of storage, in particular to a data storage method and device. BACKGROUND
[0002] With the development of technology, storage technology has also progressed. At present, the conventional technology generally uses flash memory (Flash EEPROM Memory, referred to as flash memory) to realize the performance of random access. Flash memory is a kind of storage chip, and the data inside can be modified through a specific program. Flash often means Flash Memory in the field of electronics and semiconductors, that is, "flash memory" as we usually say, wherein the data in the flash memory is stored in blocks of kilobytes. That is, after writing data, different storage blocks need to be erased in blocks when erasing. However, in actual application, since the conventional data storage process using flash needs to be constantly erased and written, especially in the process of random access, the number of erasing and writing will greatly increase. However, in this process, due to the different order of addresses, some storage blocks will be frequently erased and written, which leads to different lifespans of different storage blocks in the flash memory. Therefore, the existing data storage method based on flash greatly affects the overall service life of the flash memory. SUMMARY
[0003] The embodiments of the present application provide a data storage method and device, and the main purpose is to realize a data storage method based on flash, so as to solve the problem that the conventional data storage based on flash affects the overall service life of the flash memory.
[0004] To solve the above technical problems, the embodiments of the present application provide the following technical solutions:
[0005] In a first aspect, the present application provides a data storage method, which comprises:
[0006] determining first data to be written;
[0007] if it is determined that there is the same data as the first data in the first storage area, then when a power-off instruction is detected, the first data is written into the target storage block in the second storage area according to the writing order;
[0008] The write order is determined according to the address of each storage block in the second storage area, the first storage area is a data cache area constructed based on static random access memory (SRAM), and the second storage area is a storage area constructed based on flash. The storage block in the second storage area is a storage unit divided by a target byte number according to a preset rule.
[0009] Optionally, the method further comprises:
[0010] If it is determined that the first data is not the same as the data in the first storage area, the first data is written into the target storage block in the second storage area according to the write order.
[0011] Optionally, the writing of the first data into the target storage block in the second storage area according to the write order when the power-off instruction is detected comprises:
[0012] When the power-off instruction is detected, the target storage block is determined in the backup partition in the second storage area according to the write order of the backup partition, and the first data is written into the target storage block. The power-off instruction includes a hibernation instruction and a power-off instruction.
[0013] Optionally, the writing of the first data into the target storage block in the second storage area according to the write order when it is determined that the first data is not the same as the data in the first storage area comprises:
[0014] A frequently recorded partition is determined in the second storage partition, and the write order of the frequently recorded partition is obtained;
[0015] The target storage block is determined from the plurality of storage blocks of the frequently recorded partition based on the write order of the frequently recorded partition, and the first data is written into the target storage block.
[0016] Optionally, the determining of the target storage block from the plurality of storage blocks of the frequently recorded partition based on the write order of the frequently recorded partition and the writing of the first data into the target storage block comprise:
[0017] If it is determined that the target storage block does not store any data, the first data is written into the target storage block.
[0018] Or,
[0019] If it is determined that the target storage block stores second data, an erase operation is performed on the target storage block, and the first data is written into the target storage block after the erase operation is performed.
[0020] Optionally, if it is determined that the target storage block stores second data, an erase operation is performed on the target storage block, and the first data is written into the target storage block after the erase operation is performed, including:
[0021] If it is determined that the second data needs to be backed up, a non-frequently recorded area is determined in the second storage area, and a backup storage block is determined based on a write order of the non-frequently recorded area;
[0022] The second data is written into the backup storage block to back up the second data.
[0023] The erase operation is performed on the target storage block, and the first data is written into the target storage block after the erase operation is performed.
[0024] Optionally, the second data is written into the backup storage block to back up the second data, including:
[0025] If it is determined that the backup storage block stores third data, and the third data needs to be backed up, the third data is backed up in the remaining storage blocks in the non-frequently recorded partition except the backup storage block, and the erase operation is performed on the backup storage block, and the second data is written into the backup storage block after the erase operation is performed;
[0026] Or,
[0027] If it is determined that the backup storage block does not store any data, the second data is written into the backup storage block.
[0028] Optionally, the method further includes:
[0029] If it is determined that the same data as the second data exists in the first storage area, it is determined that the second data needs to be backed up.
[0030] If it is determined that the same data as the third data exists in the first storage area, it is determined that the third data needs to be backed up.
[0031] Optionally, the first data is written into the target storage block in the second storage area according to the write order, including:
[0032] In a plurality of storage pages in the second storage area, the target storage page is determined based on an address order between each of the storage pages.
[0033] determining the target storage block in the plurality of storage blocks in the target storage page based on an address sequence between each of the storage blocks;
[0034] writing the first data into the target storage block.
[0035] Optionally, the target storage page is determined in the plurality of storage pages in the second storage area based on an address sequence between each of the storage pages, comprising:
[0036] obtaining a page address of each of the storage pages in the second storage area, and determining a storage page corresponding to a previous write operation based on an address sequence of the page addresses, and determining a next storage page of the storage page corresponding to the previous write operation as the target storage page, wherein the page address is determined based on physical addresses of all storage blocks contained in each of the storage pages.
[0037] Optionally, the target storage block is determined in the plurality of storage blocks in the target storage page based on an address sequence between each of the storage blocks, comprising:
[0038] obtaining a physical address of each of the storage blocks in the storage page, and determining an address sequence of the storage blocks based on a sequence of the physical addresses and the physical addresses contained in each of the storage blocks, and determining a next storage block of a storage block corresponding to a previous write operation as the target storage block.
[0039] Optionally, the first data is written into the target storage block, comprising:
[0040] writing the first data into a storage sub-block of the target storage block, and adding a verification identifier in a verification sub-block in the target storage block, wherein the verification identifier is information for verifying integrity of the first data when the first data stored in the storage sub-block is read.
[0041] Optionally, the method further comprises:
[0042] traversing all storage blocks in the second storage area, and respectively determining starting positions in the backup sub-area, the frequently recorded sub-area and the non-frequently recorded sub-area in the second storage area;
[0043] respectively determining valid data in the backup sub-area, the frequently recorded sub-area and the non-frequently recorded sub-area based on the starting positions, wherein the valid data is data frequently used by a user, and the valid data comprises the first data, the second data and the third data;
[0044] adding the valid data to the first storage area.
[0045] Optionally, the determining the valid data in the backup partition, the frequently recorded partition and the non-frequently recorded partition based on the starting position respectively comprises:
[0046] acquiring a storage page identifier of each of the storage pages, and determining a storage page in which data is recorded in the second storage area based on the storage page identifier;
[0047] in the storage page in which data is recorded, determining a storage block in which data is stored based on a verification identifier of each of the storage blocks, and determining the data in the storage block in which data is stored as the valid data.
[0048] In a second aspect, the present application further provides a data storage device, and the method comprises:
[0049] a first determining unit configured to determine first data to be written;
[0050] a first executing unit configured to, if it is determined that the first data is identical to data in the first storage area, write the first data into the target storage block in the second storage area according to the write order when a power-off instruction is detected;
[0051] wherein the write order is determined according to the order of addresses of each of the storage blocks in the second storage area, the first storage area is a data cache area constructed based on static random access memory (SRAM), the second storage area is a storage area constructed based on flash, and the storage blocks in the second storage area are storage units divided according to a target byte number according to a preset rule.
[0052] Optionally, the device further comprises:
[0053] a second executing unit configured to, if it is determined that the first data is not identical to data in the first storage area, write the first data into the target storage block in the second storage area according to the write order.
[0054] Optionally, the first executing unit is specifically configured to, when the power-off instruction is detected, determine the target storage block in a plurality of the storage blocks in a backup partition in the second storage area based on a write order of the backup partition, and write the first data into the target storage block.
[0055] Optionally, the second executing unit comprises:
[0056] a determining module configured to determine a frequently recorded partition in the second storage partition, and acquire a write order of the frequently recorded partition;
[0057] The write module is used to determine the target storage block from multiple storage blocks of the frequent recording partition based on the write order of the frequent recording partition, and write the first data into the target storage block.
[0058] Optionally, the writing module is configured to write the first data to the target storage block if it is determined that the target storage block does not store any data.
[0059] The writing module is further configured to, if it is determined that the target storage block contains second data, perform an erase operation on the target storage block and write the first data into the target storage block after the erase operation has been performed.
[0060] Optionally, the writing module includes:
[0061] The determination submodule is used to determine a non-frequent record area in the second storage area if it is determined that the second data needs to be backed up, and to determine a backup storage block based on the writing order of the non-frequent record area;
[0062] A backup submodule is used to write the second data to the backup storage block to back up the second data;
[0063] The write submodule is used to perform the erase operation on the target storage block and write the first data to the target storage block that has performed the erase operation.
[0064] Optionally, the backup submodule is specifically used to back up the third data in the remaining storage blocks of the non-frequent recording partition (excluding the backup storage block) if it is determined that the backup storage block contains third data and the third data needs to be backed up, and to perform the erase operation on the backup storage block and write the second data into the backup storage block after the erase operation is performed.
[0065] The backup submodule is further configured to write the second data into the backup storage block if it is determined that no data is stored in the backup storage block.
[0066] Optionally, the device further includes:
[0067] The second determining unit is configured to determine that the second data needs to be backed up if it is determined that data identical to the second data exists in the first storage area.
[0068] The third determining unit is configured to determine that the third data needs to be backed up if it is determined that data identical to the third data exists in the first storage area.
[0069] Optionally, the first execution unit includes:
[0070] a first determining module, configured to determine the target storage page from a plurality of storage pages in the second storage area based on an address sequence between each of the storage pages;
[0071] a second determining module, configured to determine the target storage block from a plurality of storage blocks in the target storage page based on an address sequence between each of the storage blocks;
[0072] a writing module, configured to write the first data into the target storage block.
[0073] Optionally, the first determining module is specifically configured to acquire a page address of each storage page in the second storage area, and determine a storage page corresponding to a previous write operation based on an address sequence of the page addresses, and determine a next storage page of the storage page corresponding to the previous write operation as the target storage page, wherein the page address is determined based on physical addresses of all storage blocks contained in each of the storage pages.
[0074] Optionally, the second determining module is specifically configured to acquire a physical address of each storage block in the storage page, and determine an address sequence of the storage blocks based on a sequence of the physical addresses and physical addresses of all storage blocks contained in each of the storage blocks, and determine a next storage block of a storage block corresponding to a previous write operation as the target storage block.
[0075] Optionally, the writing module is specifically configured to write the first data into a storage sub-block of the target storage block, and add a verification identifier in a verification sub-block in the target storage block, wherein the verification identifier is information for verifying integrity of the first data when the first data stored in the storage sub-block is read.
[0076] Optionally, the apparatus further comprises:
[0077] a fourth determining unit, configured to traverse all storage blocks in the second storage area, and determine a starting position in the backup sub-area, the frequently recorded sub-area and the non-frequently recorded sub-area in the second storage area respectively;
[0078] a fifth determining unit, configured to determine valid data in the backup sub-area, the frequently recorded sub-area and the non-frequently recorded sub-area respectively based on the starting positions, wherein the valid data is data commonly used by a user, and the valid data includes the first data, the second data and the third data;
[0079] an adding unit, configured to add the valid data to the first storage area.
[0080] Optionally, the fifth determining unit comprises:
[0081] a first determining module, configured to acquire a storage page identifier of each of the storage pages, and determine, based on the storage page identifier, a storage page in which data is recorded in the second storage area;
[0082] a second determining module, configured to determine, in the storage page in which data is recorded, a storage block in which data is stored based on a verification identifier of each of the storage blocks, and determine the data in the storage block in which data is stored as the valid data.
[0083] In a third aspect, a storage medium is provided, and the storage medium includes a stored program. When the program is executed, the device in which the storage medium is located performs the data storage method in the first aspect.
[0084] In a fourth aspect, a data storage device is provided, and the device includes a storage medium and one or more processors. The storage medium is coupled to the processor, and the processor is configured to execute program instructions stored in the storage medium. When the program instructions are executed, the processor performs the data storage method in any one of the first aspect.
[0085] By means of the above technical solutions, the technical solutions provided by the present application have at least the following advantages:
[0086] The application provides a data storage method and device, which can determine first data to be written; if it is determined that the first data is identical to data in a first storage area, the first data is written into a target storage block in a second storage area according to a writing sequence when a power-off instruction is detected, so that a flash-based data storage function is realized. Compared with the prior art, in the flash-based data storage process of the application, since the writing sequence is determined according to the sequence of addresses of each storage block in the second storage area, a storage block can be selected as a target storage block for writing based on the writing sequence during the writing process, which ensures that the data can be written into different storage blocks in a certain sequence during the writing process, and the problem of excessive wear caused by repeated erasing and writing in a certain storage block or a few storage blocks is avoided, so that the problem that the service life of the entire flash memory is affected due to excessive wear of individual storage blocks is avoided. In addition, the first storage area is a data cache area constructed based on a static random access memory (SRAM), and the second storage area is a storage area constructed based on a flash, so that it can be ensured that if it is determined that the first data is identical to the data in the first storage area during the writing of the first data, the first data is commonly used by a user, and then it can be ensured that the first data in the first storage area constructed based on the SRAM can be written into the second storage area constructed based on the flash in time when the user suddenly issues a power-off instruction, so that the problem of data loss in the SRAM due to power-off is solved. Meanwhile, the storage blocks in the second storage area are storage units divided according to a target byte number according to a preset rule, so that the original storage block storage space division mode in units of kilobytes is avoided during the data storage process, which ensures that multiple different data can be stored in the original storage block when multiple different data are stored, and the different data can be managed individually, that is, a small-range erasing effect of several bytes or tens of bytes can be realized for the storage block with the target byte number during the erasing process, the problem of excessive erasing caused by erasing the entire original storage block with several kilobytes in a large range is avoided, and the service life of the flash memory can be further improved.
[0087] The above description is only a summary of the technical scheme of the application, in order to more clearly understand the technical means of the application, the specific embodiments of the application can be implemented according to the content of the description, and in order to make the above and other purposes, characteristics and advantages of the application more obvious and easy to understand, the following specific embodiments of the application are described. BRIEF DESCRIPTION OF DRAWINGS
[0088] The above and other objects, features and advantages of the present application will become more apparent from the following detailed description read in conjunction with the accompanying drawings, in which like reference numerals refer to like elements throughout. The drawings illustrate preferred embodiments of the present application, but the present application is not limited to the embodiments presented. In the drawings:
[0089] Figure 1 A flow chart of a data storage method provided by an embodiment of the present application is shown;
[0090] Figure 2 A flow chart of specific steps in the execution of another data storage method provided by an embodiment of the present application is shown;
[0091] Figure 3-a A schematic diagram of the execution of a data storage method provided by an embodiment of the present application is shown;
[0092] Figure 3-b A schematic diagram of the execution of another data storage method provided by an embodiment of the present application is shown;
[0093] Figure 4 A schematic diagram of the execution of yet another data storage method provided by an embodiment of the present application is shown.
[0094] Figure 5 A block diagram of a data storage device provided by an embodiment of the present application is shown;
[0095] Figure 6 A block diagram of another data storage device provided by an embodiment of the present application is shown. DETAILED DESCRIPTION
[0096] Exemplary embodiments of the present application will be described hereinafter with reference to the accompanying drawings. While exemplary embodiments of the present application are shown in the drawings, it should be understood that the present application can be embodied in various forms without being limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the application to those skilled in the art.
[0097] It should be noted that unless otherwise specified, technical or scientific terms used in the present application should be understood as having the same meaning as commonly understood by one of ordinary skill in the art to which the present application pertains.
[0098] A flow chart of a data storage method provided by an embodiment of the present application is shown; Figure 1 as shown, the method comprises:
[0099] 101, determining first data to be written.
[0100] Since the write operation instruction is generally based on the user in the process of data writing, the storage data in the embodiment, need to first judge whether there is a write behavior before storing data, that is, the write operation instruction is detected. When the write operation instruction is detected, it means that the user needs to write some data to the storage device, that is, there is currently first data to be written, and it is necessary to determine which data needs to be written based on the write operation instruction, that is, to determine the first data. In this embodiment, the form, type and quantity of the first data are not limited, and can be determined according to the actual situation of the user.
[0101] 102, if it is determined that the first storage area has the same data as the first data, the first data is written into the target storage block in the second storage area according to the write order when the power-off instruction is detected.
[0102] Among them, the write order is determined according to the order of the address of each storage block in the second storage area, the first storage area is a data cache area constructed based on static random access memory (SRAM), the second storage area is a storage area constructed based on flash, and the storage block in the second storage area is a storage unit divided by a target byte number according to a preset rule
[0103] When it is determined that there is first data to be written, it can be further judged whether the first data is the data frequently used by the user. Based on the characteristics of the flash memory, the data existing in the first storage area constructed based on SRAM is generally data for meeting the random write requirement, that is, the data here is the data frequently used by the user. Therefore, in this embodiment, the first storage area can be identified. Based on this, it can be judged whether there is the same first data as the write data in the first storage area. If the first data is stored in the first storage area, the data is most likely to be the data used before, that is, the frequently used data.
[0104] Based on this, in the process of data storage, it is necessary to ensure that data avoids data loss in any case, so after detecting the power-off instruction, the data stored in the internal storage is transferred to the second storage area. Since the second storage area is flash built, it is ensured that the data stored in the SARM will be timely transferred to the second storage area for storage even in the case of power failure, avoiding the problem of data loss after power failure. At the same time, in the embodiment, in the process of writing data in the first storage area to the second storage area, the storage blocks are not randomly selected for writing, but are based on the writing sequence. The writing sequence can be understood as a way of selecting storage blocks for writing data based on the address sequence of the plurality of storage blocks in the second storage area. In this way, in the process of writing data, the storage blocks with earlier address order will not be repeatedly written, and these storage blocks will not be repeatedly erased.
[0105] In this way, it is ensured that the plurality of storage blocks in the second storage area have the same number of erase-write times, and the life loss of the erase-write process can be balanced. This can make the flash memory be used in a whole balanced wear manner, and it will not cause excessive erase-write of some or a few storage blocks, so as to cause the wear degree to be more serious than the remaining storage blocks. The problem of affecting the overall life of the flash memory due to the failure of these storage blocks is avoided.
[0106] In the embodiment, when writing data in the first storage area to the second storage area, the target storage block is selected from the second storage area for storage, and the storage block in the embodiment is different from the storage block in the conventional flash memory. In the conventional original storage block, the size of each storage block is 1 kb to several kb, that is, the storage space is set according to the size of kilobyte. When the amount of data written each time is small, in order to realize the function of separately managing each different data, it is necessary to store only one data in each original storage block, which will cause a large waste of storage space. Once multiple different data are written into one original storage block, and the original storage block needs to be erased, the different data will be eliminated, which will cause the problem of mistaken deletion of data. In the process, only tens of kb of data may need to be erased, but actually, the storage space of several kb to tens of kb in the original storage block is erased, so the space corresponding to the remaining data is over-erased when it is erased. Therefore, in the embodiment, the storage block is set to a storage unit of a target byte number, which can form multiple different smaller storage units in the space of 1 kb or several kb in the original storage block. In this way, multiple different data can be stored in the space of the original storage block size, and each data can be managed, that is, the storage space is saved, the mistaken deletion is avoided, the over-erasing in the erasing process is avoided, the number of erasing and writing of each storage block is reduced as a whole, unnecessary wear and tear is reduced, and the life of the second storage area based on flash can be improved as a whole.
[0107] Based on this, the embodiment provides a data storage method. In the data storage process of the application, since the writing order is determined according to the address order of each storage block in the second storage area, the storage block can be selected as the target storage block for writing according to the writing order in the writing process, which ensures that the data can be written into different storage blocks in a certain order in the process of writing data, and the problem of excessive wear caused by repeated erasing and writing in one or several storage blocks is avoided, thereby avoiding the problem that the service life of the entire flash memory is affected due to the excessive wear of individual storage blocks. In addition, the first storage area is a data cache area constructed based on static random access memory (SRAM), and the second storage area is a storage area constructed based on flash, which can ensure that in the process of writing the first data, if it is determined that the first storage area contains the same data as the first data, it means that the first data is frequently used by the user, and then it can be ensured that when the user suddenly issues a power-off instruction, the first data in the first storage area constructed based on SRAM can be written into the second storage area constructed based on flash in time, solving the problem of data loss in SRAM due to power failure. At the same time, the storage blocks in the second storage area are storage units divided according to a preset rule with a target byte number, which ensures that the original storage block storage space division method with a unit of kilobytes is avoided in the process of data storage, which ensures that when storing multiple different data, multiple different data can be stored in the original storage block, and different data can be managed individually, that is, in the erasing process, the storage block with a target byte number can be erased in a small range of several bytes or tens of bytes, avoiding the problem of excessive erasing caused by erasing the entire original storage block with a large range of several kilobytes when using the conventional method, and further improving the service life of the flash memory.
[0108] In some embodiments, since the first data to be written can also be infrequently used data, but new data, after step 101 in the foregoing embodiment, the method can further include:
[0109] If it is determined that the first storage area does not contain the same data as the first data, the first data is written into the target storage block in the second storage area according to the writing order.
[0110] When it is determined that there is no data identical to the first data in the first storage area, it indicates that the first data is not recorded in the first storage area, and the first data is most likely new data that needs to be stored. If a power failure occurs, the first data may be lost before it is written to the second storage area. Therefore, the first data needs to be directly written to the second storage area. The data is written based on the characteristics of the flash memory, and even if a power failure occurs, the second storage area can save the data, avoiding the problem of data loss. At the same time, during the process of writing the first data to the second storage area, the writing needs to be performed in the order of writing. In this way, when it is found that the first data is new data during the writing process, the first data can be directly written to the second storage area based on the order of writing. This ensures that the first data will not be written to the first storage area, causing a power failure and loss. It also ensures that the writing to the target storage block is also performed in the order of writing, avoiding the problem of excessive erasing of some or several storage blocks caused by unordered writing, and improving the life of the flash memory as a whole.
[0111] In some embodiments, since the first storage area is based on SRAM, the SRAM will lose the data stored therein after a power failure. Therefore, in order to ensure data completeness, the SRAM can also be separately and accurately corresponded to a storage space in the second storage area, so as to timely transfer data after detecting a power failure instruction.
[0112] Based on this, in the step 102 in the foregoing embodiment, when the first data is written to the target storage block in the second storage area in the order of writing upon detecting a power failure instruction, the writing can include the following steps in execution:
[0113] When a power failure instruction is detected, the target storage block is determined in a plurality of storage blocks in a backup partition in the second storage area based on the order of writing of the backup partition, and the first data is written to the target storage block. The power failure instruction includes a hibernation instruction and a power failure instruction.
[0114] In the present embodiment, a partition for the first storage area, i.e., a backup partition, can be provided in the second storage area. When a power failure instruction is detected, all data of the first storage area can be written to the backup partition. Since the backup partition is also a part of the second storage area constructed by flash, it is ensured that even if the entire storage device is powered off later, the data originally existing in the first storage area constructed by SRAM will not be lost, ensuring the reliability of the data.
[0115] In some embodiments, due to the actual application process, the data stored in the flash is divided into two types according to the different read-write frequencies, one is frequently used data, and the other is rarely used data. Therefore, in order to facilitate the call, different partitions can be set in the second storage area for the storage of the two types of data. At this time, the storage partition further includes a frequently recorded partition and a non-frequently recorded partition.
[0116] Based on this, in the foregoing embodiment, if it is determined that the first storage area does not exist the same data as the first data, the first data is written into the target storage block in the second storage area according to the write order, which can be executed as follows:
[0117] Determine the frequently recorded partition in the second storage partition, and obtain the write order of the frequently recorded partition;
[0118] Based on the write order of the frequently recorded partition, determine the target storage block from the plurality of storage blocks of the frequently recorded partition, and write the first data into the target storage block.
[0119] In this way, when it is determined that the first storage area does not exist the same data as the first data, it means that the data can be new data, and the subsequent user usage can be high. Therefore, storing the first data in the frequently recorded partition can ensure that the data to be used by the user is saved in the frequently recorded partition, which is beneficial to the fast call of data.
[0120] In some embodiments, since there can be data in the storage block or there can be no data in the storage block during the writing of the first data into the storage block, based on this, in the foregoing embodiment, based on the write order of the frequently recorded partition, the target storage block is determined from the plurality of storage blocks of the frequently recorded partition, and the first data is written into the target storage block, which can be executed in the following two ways:
[0121] On the one hand, if it is determined that the target storage block does not store any data, the first data is written into the target storage block;
[0122] On the other hand, if it is determined that the target storage block stores second data, an erase operation is performed on the target storage block, and the first data is written into the target storage block after the erase operation.
[0123] For the first aspect, when it is determined that the target storage block does not store data, the target storage block can be understood as a "blank storage block", and the first data can be directly written.
[0124] For the latter, when it is determined that the target storage block stores data, an erase operation needs to be performed on the target storage block first. The erase operation can be understood as an operation of clearing the data content in the storage block, similar to the action of "erasing". Then, the first data is written into the target storage block, achieving the effect of writing the first data into the target storage block. In this way, when a storage block is determined as the target storage block based on the write order, the data in the storage block can be cleared, avoiding the problem of data write failure when a storage block stores data.
[0125] In some embodiments, the second data stored in the target storage block can be data that has been used by the user and can be used by the user later. Therefore, during the execution of the foregoing steps, the second data also needs to be backed up.
[0126] Based on this, in the foregoing embodiments, if it is determined that the target storage block stores second data, an erase operation is performed on the target storage block, and the first data is written into the target storage block after the erase operation is performed. During execution, the following can be performed: Figure 2 including:
[0127] 201. If it is determined that the second data needs to be backed up, a non-frequent recording area is determined in the second storage area, and a backup storage block is determined based on the write order of the non-frequent recording area.
[0128] After it is determined that the second data needs to be backed up, a storage block for backing up the second data, i.e., a backup storage block, can be selected. Since the second storage area is divided into a frequent recording partition and a non-frequent recording partition, and the target storage block to which the first data is written is in the frequent recording partition, it indicates that the first data is data frequently used by the user. The second data indicates data that is not frequently used by the user, and therefore needs to be transferred to the non-frequent recording partition. Therefore, the backup storage block needs to be selected in the non-frequent recording partition, and the selection needs to be based on the write order of the non-frequent recording partition.
[0129] 202. The second data is written into the backup storage block to back up the second data.
[0130] After the backup storage block is determined based on the write order, the second data can be directly written into the backup storage block to achieve the backup of the second data.
[0131] 203. An erase operation is performed on the target storage block, and the first data is written into the target storage block after the erase operation is performed.
[0132] After the second data is backed up, the second data in the target storage block can be directly deleted without any consideration, that is, an erase operation is performed on the target storage block, so that the target storage block no longer records any data, and the storage of the first data can be performed. At this time, the first data can be written into the target storage block.
[0133] In some embodiments, since the backup storage block is determined in the order of writing, the backup storage block can be divided into two cases, one is to store data, and the other is not to store data. Based on this, for the two cases, in step 202 in the foregoing embodiment, the second data is written into the backup storage block to back up the second data, and when executed, can include:
[0134] On the one hand, if it is determined that the backup storage block stores third data, and the third data needs to be backed up, the third data is backed up in the remaining storage blocks in the non-frequently recorded partition except the backup storage block, and the erase operation is performed on the backup storage block, and the second data is written into the backup storage block after the erase operation is performed.
[0135] On the other hand, if it is determined that the backup storage block does not store any data, the second data is written into the backup storage block.
[0136] When it is determined that the backup storage block still stores data, that is, third data, and it is determined that the third data also needs to be backed up, it means that the third data can also be historical data, that is, data that has been used by the user. In order to avoid the problem of loss of the third data when the user calls it again, backup in the second storage area is still needed. Of course, since the third data itself is stored in the non-frequently recorded partition, it can be explained that this data itself is not frequently used by the user, so backup can still be performed in the non-frequently recorded partition. That is, when it is determined that the third data needs to be backed up, a storage block can be selected from the remaining storage blocks except the backup storage block in the non-frequently recorded partition for backup. Then, after the third data is backed up, the erase operation can be performed on the backup storage block, so that the backup storage block no longer stores any data, so that the second data can be written into the backup storage block to achieve the effect of backing up the third data originally stored in the backup storage block in the process of backing up the second data. In the process of writing data based on the writing order to ensure the balance between the erase and write of the plurality of storage blocks, the problem of loss of the third data originally stored in the backup storage block when the backup storage block is erased can also be avoided.
[0137] In some embodiments, whether the second data and the third data need to be backed up can be based on whether the second data and the third data are used after the flash memory device is powered on this time, that is, whether the data exists in the first storage area built by SRAM.
[0138] Based on this, the method to which the embodiment belongs can further include:
[0139] On one hand, if it is determined that the same data as the second data exists in the first storage area, it is determined that the second data needs to be backed up.
[0140] On the other hand, if it is determined that the same data as the third data exists in the first storage area, it is determined that the third data needs to be backed up.
[0141] Since the first storage area is a storage area built based on SRAM, it itself has the characteristic of losing all data after power failure, so whether the second data or the third data is data used after the memory is powered on this time can be determined based on whether the first storage area has the same data as the second data and the third data. When it is determined that the same data as the second data and the third data exists in the first storage area, it means that the second data and the third data are used by the user, and these data need to be backed up.
[0142] In some embodiments, in order to further facilitate data storage and management, the second storage area can be further divided into a frequently recorded partition and a non-frequently recorded partition, that is, the storage blocks are managed in the form of being divided into different pages. In this case, the frequently recorded partition and the non-frequently recorded partition each contain at least one storage page; the storage pages are arranged in address order; and each storage page contains at least one storage block.
[0143] Based on this, in the foregoing embodiment, the first data is written into the target storage block in the second storage area according to the write order, and when executed, can include:
[0144] 301. Among the plurality of storage pages in the second storage area, the target storage page is determined based on the address order between each of the storage pages.
[0145] 302. Among the plurality of storage blocks in the target storage page, the target storage block is determined based on the address order between each of the storage blocks.
[0146] 303. The first data is written into the target storage block.
[0147] In the process of writing the first data to the target storage block, based on the above method, the target storage page, which is the storage page that currently needs to perform the write operation, can be first removed from the frequently recorded partition in the second storage area. In the process of determining the target storage page, the manner of determining the target storage block is consistent, that is, the storage page that currently can perform the write operation is determined based on the write order. It should be noted that in the present embodiment, the storage page can be understood as a collection determined by the storage blocks in address order. For example, when there are 10 storage blocks, storage block 1 to storage block 10, based on the address order, the order of which is also arranged from storage block 1 to storage block 10, then based on the method of the present embodiment, it can be divided into storage page A and storage page B, wherein storage page A can include storage block 1 to storage block 5, and storage page B can include storage block 6 to storage block 10, and based on the address order, the order between the two storage pages is also arranged from storage page A to storage page B, and the write order is also from storage page A to storage page B.
[0148] It should be noted that in actual application, since some storage pages may have just stored data, in this process, the storage page that allows the write operation to be performed can also be selected in the process of selecting the target storage page according to the write order. In this process, a storage page identifier can also be set in each storage page to indicate whether the storage page has performed erasing, that is, whether the write operation is allowed to be performed in the storage page. In this case, the step in the process of the present embodiment can also be: based on the storage page identifier, the storage page that allows the write operation to be performed is determined in the plurality of storage pages according to the write order as the target storage page, and a certain storage block in the target storage page is selected as the target storage block according to the write order.
[0149] The method of the present step can be specifically referred to as shown in Figure 3-a For example, when the frequently recorded partition contains a plurality of storage pages, storage page 1 to storage page x, each storage page has a storage page identifier. Since the storage page identifier can indicate whether the storage page can be used to write new data, the storage page identifier can be used to determine which storage page can meet the requirements of the write operation, and the determination is based on the write order. In this process, it can be as follows: Figure 3-aAs shown, from the storage page 1 to the storage page 2 to the storage page m and finally to the storage page x, they are arranged in the address order, at this time, the storage page identifiers of each storage page can be sequentially queried in the address order to determine which storage page meets the write requirement. When it is determined based on the storage page identifier m that the storage page m is a storage page that allows the write operation to be performed, the storage page m can be determined as the target storage page. Then, the target storage block is determined in the storage page m according to the write order between each storage block in the storage page m, for example, the storage block Bm can be determined as the target storage block based on the write order. After that, the first data is written into the storage block Bm of the storage page m.
[0150] In some embodiments, the step 301 in the foregoing embodiment can include, when executed, determining the target storage page based on the address order between each of the storage pages in the plurality of storage pages in the second storage area.
[0151] Firstly, the page address of each storage page in the second storage area is acquired, and the storage page corresponding to the previous write operation is determined based on the address order of the page address.
[0152] Then, the next storage page of the storage page corresponding to the previous write operation is determined as the target storage page, wherein the page address is determined based on the physical addresses of all storage blocks contained in each of the storage pages.
[0153] For example, in combination with the foregoing example, when it is determined that the storage page m is the storage page corresponding to the previous write operation, it can be determined that the write operation should be performed on the storage page m according to the write order, and therefore the storage page m can be determined as the target storage page.
[0154] In this way, in the process of determining the target storage page from the plurality of storage pages according to the write order, the target storage page is determined as the storage page subsequent to the storage page corresponding to the previous write operation according to the address order when the first data is written this time, which ensures that the target storage page can be determined in combination with the previous write operation in the process of determining the storage page according to the write order, and the accuracy of the target storage page is ensured.
[0155] In some embodiments, the step 302 in the foregoing embodiment can include, when executed, determining the target storage block based on the address order between each of the storage blocks in the plurality of storage blocks in the target storage page, and specifically can include:
[0156] The physical address of each storage block in the storage page is acquired, and the address order of each storage block is determined based on the physical address and the physical address contained in each of the storage blocks.
[0157] Based on the address order of the storage blocks, the next storage block of the storage block corresponding to the previous write operation is determined as the target storage block.
[0158] In the present embodiment, since the storage blocks are arranged in order based on the physical addresses, in the process of determining the target storage block, the storage block corresponding to the previous write operation can also be determined based on the physical address of the previous write. Then in the process of writing the first data, the next storage block after the storage block of the previous write can be determined as the storage block corresponding to the present write, i.e. the target storage block, based on the address order of the storage blocks.
[0159] In this way, the order of the storage blocks, i.e. the address order of the storage blocks, can be determined based on the order of the physical addresses of the storage blocks and the physical address corresponding to each storage block, and then the next storage block of the storage block corresponding to the previous write operation is determined as the target storage block, ensuring the accuracy of the determination result of the target storage block.
[0160] The method described in the foregoing embodiments can be combined with the following in the process of executing the writing of the first data to the target storage block in the present embodiment Figure 3-bThe method comprises: when the frequently recorded partition is traversed and queried according to the order of the storage pages from storage page 1 to storage page m based on the page addresses between the respective storage pages, it can be determined according to the storage page identifier of each storage page which storage pages have data recorded therein. At this time, when it is determined that storage page m is a storage page that needs to perform a write operation, that is, the storage page m is a target storage page. At the same time, when it is determined that the storage page m has data stored therein based on the storage page identifier, it is determined that the data stored in the storage page m has the same data in the first storage area, which indicates that the data stored in the storage page m needs to be backed up. At this time, a backup storage page can be selected in the non-frequently recorded partition. That is, when storage page β is determined to be a storage page that allows a write operation to be performed based on the storage page identifier β, the storage page β can be determined as a backup storage page. Since the foregoing step indicates that the storage page m in the frequently recorded partition needs to be backed up, the data in the storage page m can be written into the storage page β, thereby completing the backup. Then, an erase operation is performed on the storage page m. In this way, the erased storage page m has cleared the original data content, and at this time the storage page is blank, so the erased storage page m can continue to select a target storage block from storage block Am to storage block Nm according to the write order of the storage blocks. Since storage block Am is the first storage block at this time, storage block Am can be selected as the target storage block.
[0161] It should be noted that in the present embodiment, the storage page identifier carried in each storage page can be as follows Figure 3-a and 3-bThe storage space shown is separately opened in the storage page, similar to the storage block, except that the storage space is only responsible for storing the storage page identifier, and is not responsible for storing the data content during the write operation. Only after the erase operation is performed on the storage page, the storage page identifier involved therein is modified, which can avoid the problem that the subsequent erase record is affected due to the mistaken deletion and modification of the storage page identifier during the erase of the storage page. In addition, in the present embodiment, the storage page identifier can be the EraseCount in the storage page, and whether the storage page allows direct execution of the write operation based on the storage page identifier can be determined by judging whether the EraseCount is invalid. When the EraseCount is valid, it means that the storage page stores data content and cannot directly write data, but needs to be erased first. Conversely, when the EraseCount is invalid, it means that the storage page does not store data and can directly execute the write operation. In addition, it should be noted that in the present embodiment, after writing data in the storage page, the storage page identifier also needs to be modified, as in other types of storage, to ensure that the subsequent write operation is distinguished. The specific process is to restore the EraseCount to a valid state. This process is consistent with the way of modifying the erase record or erase identifier in other storage, and the specific details will not be described here.
[0162] In some embodiments, in order to avoid the data storage being too dense, which may affect some already stored data in some cases, the relevant storage page after writing data can also be analyzed in the present embodiment. Based on this, the method of the foregoing embodiment can also perform the following steps when executed:
[0163] After the first data is written to the target storage block, and it is determined that the adjacent storage page of the target storage page records data content, the data content is backed up in the infrequent record partition, and the adjacent storage page of the target storage page is executed with an erase operation.
[0164] Specifically, the method described in the present embodiment can be performed in the following manner during execution:
[0165] In the present embodiment, since the storage page identifier can reflect whether the corresponding storage page stores data. In order to avoid the data storage process being too dense and to avoid the problem of mistaken erasure during writing, the storage page identifier can be used to determine whether the adjacent storage page after the target storage page stores data, that is, whether the adjacent storage page allows execution of the write operation. When it is determined that the adjacent storage page does not allow execution of the write operation, it is determined whether the adjacent storage page needs to be backed up.
[0166] When it is determined that the adjacent storage page does not allow write operation, it indicates that the storage page stores data, which is a "dirty page". In order to avoid too dense data storage, the adjacent storage page needs to be erased. However, before erasing, it is necessary to determine whether the data in the adjacent storage page is important data that needs to be backed up.
[0167] Based on the determination result, there are two cases. One case is that when it is determined that the adjacent storage page needs to be backed up, it indicates that the data in the storage page affects the requirement of the first data stored in the target storage page on storage density, but is also important data, which cannot be directly erased but needs to be backed up. Therefore, in this process, the data needs to be backed up in the infrequently recorded area. After the backup is completed, the adjacent storage page can be erased. In this way, the adjacent storage page arranged in the target storage page is a "blank storage page". Therefore, in each write operation process, it can be ensured that the adjacent storage page of the target storage page after writing is not a "dirty page". In this way, the data storage density is reduced, which is beneficial to directly writing in the "blank storage page" when data needs to be written, without the need for erasing operation. In addition, it can avoid the problem of data deletion caused by deleting the data content in two adjacent storage pages in some special cases due to too high storage density. Moreover, in subsequent write operation, some special cases can directly write in the "blank storage page" without considering the storage density, which saves the erasing process and improves the write efficiency.
[0168] For another case of determination, when it is determined that the adjacent storage page does not need to be backed up, it indicates that the data stored in the adjacent storage page is actually abandoned data. Therefore, in this step, the adjacent storage page can be directly erased.
[0169] In some embodiments, the writing of the first data into the target storage block in the foregoing embodiment can include:
[0170] The first data is written into a storage block in the target storage block, and a verification identifier is added in a verification block in the target storage block, wherein the verification identifier is information for verifying the integrity of the first data when the first data stored in the storage block is read.
[0171] In this embodiment, the target storage block can include two parts, i.e., a storage block and a verification block. The storage block can be understood as a part for storing data content, and the verification block can be understood as a part for storing information representing data integrity.
[0172] In this way, in the process of writing the first data, not only the data content of the first data can be written into the storage block, but also the verification identifier reflecting the integrity of the data can be added to the storage block, which ensures that when the first data is read and called subsequently, the integrity of the first data can be checked based on the verification identifier in the verification block, effectively avoiding the occurrence of the case that the first data fails to be read due to data loss, and laying a foundation for the stability of the subsequent data reading and use process.
[0173] In some embodiments, the storage block can be further provided with a data length block and an address record block on the basis of the storage block, the verification block, based on which, after the first data is written into the storage block of the target storage block and the verification identifier is added to the verification block in the target storage block, the method further comprises:
[0174] According to the position of the first data in the storage block, address information is added to the address record block of the storage block, and the data length of the written data determined based on the address information is added to the data length block of the storage block.
[0175] In this way, in the process of storing the first data, the overall length of the first data can also be recorded, and the address of the first data in the storage block can also be recorded, which is beneficial to positioning the storage position of the first data and determining the data quantity at the system level. In the subsequent process of reading and calling the first data, the above information can be analyzed based on the above information, which is convenient for users to analyze and troubleshoot the data.
[0176] As shown in Figure 4 In the storage block A1, it can be seen that the storage block occupies the largest space in the storage block A1, which is used to store the specific data content. At the same time, since the data content actually needs to identify its storage position in the storage process, it is recorded as address information and added to the address record block. At the same time, since the data content can not completely occupy the entire space of the storage block. For example, when the storage block is 10 bytes and the data content is 5 bytes, the total length of the data, that is, the size of the actual occupied space, that is, the data length of the embodiment, 5 bytes, needs to be recorded when storing the data content. In addition, it is also necessary to identify whether the stored data content is incorrect in the data storage process, that is, to add a verification identifier in the verification block. It should be noted that the verification identifier can be different, which is determined based on whether the data content stored in the storage block is incorrect and the degree of error. Herein, the type and format of the verification identifier are not limited, and any verification identifier in the existing data storage process can be used.
[0177] In some embodiments, it is also possible to store the case of flash memory restart after power failure, in which case, in order to achieve the effect of restoring the previous running state, the data in the first storage area can also be restored based on the second storage area. Based on this, the method can also include:
[0178] First, traverse all the storage blocks in the second storage area, and determine the starting positions of the backup partition, the frequently recorded partition and the infrequently recorded partition in the second storage area, respectively;
[0179] Then, based on the starting positions, determine the valid data in the backup partition, the frequently recorded partition and the infrequently recorded partition, respectively, wherein the valid data is the data frequently used by the user, and the valid data includes the first data, the second data and the third data;
[0180] Finally, add the valid data to the first storage area.
[0181] Since the second storage area actually divides a complete flash memory into different areas, i.e. the backup partition, the frequently recorded partition and the infrequently recorded partition, based on the software level, before restoring the first storage area, it is necessary to first determine the starting positions of the partitions in the second storage area, so as to determine the distribution of the data.
[0182] After determining the starting positions of the partitions, it can be determined according to the starting positions which data are stored in the partitions, i.e. the valid data in the backup partition, the frequently recorded partition and the infrequently recorded partition. It can be known from the description of the foregoing embodiments that the first data, the second data and the third data are all data required by the user, and therefore these data also belong to the valid data in this embodiment. It should be noted that in this embodiment, the valid data includes but is not limited to the first data, the second data and the third data. That is, the data content in the second storage area, which is frequently used by the user, is valid data. After determining the valid data, it can be known which data in the second storage area is frequently used by the user, and then these data can be added to the first storage area, so as to restore the state of the first storage area before power failure, which is beneficial to subsequent timely response to corresponding read / write operations.
[0183] In some embodiments, since in the actual data storage process, not all the storage pages in the frequently recorded partition and the infrequently recorded partition record data, and similarly, there can be a case that part of the storage blocks in a storage page record data, therefore, in the process of determining the valid data, it is also necessary to analyze whether each storage page and each storage block in each storage page record data.
[0184] Based on this, the foregoing step of determining the valid data in the backup partition, the frequently recorded partition and the infrequently recorded partition based on the starting position respectively can include, when executed:
[0185] Firstly, the storage page identifier of each storage page is acquired, and the storage page in which data is recorded in the second storage area is determined based on the storage page identifier;
[0186] Secondly, in the storage page in which data is recorded, the storage block in which data is stored is determined in a plurality of storage blocks based on the verification identifier of each storage block, and the data in the storage block in which data is stored is determined as the valid data.
[0187] As can be known from the foregoing embodiment, each storage page records a storage page identifier, and each storage block records a verification identifier, which respectively indicate whether the storage page and the storage block store data. Therefore, in this embodiment, whether the storage page stores data can be determined based on the storage page identifier, and whether the storage block stores data can be determined based on the verification identifier of the storage block. In this way, the determination effect of whether the storage block stores data can be quickly determined, and the analysis process of data query in each storage block in each storage page is avoided, and the identification efficiency is improved.
[0188] Further, as an implementation of the foregoing method, Figures 1 to 4 An embodiment of the present application further provides a data storage device. The device embodiment corresponds to the foregoing method embodiment, and details in the foregoing method embodiment will not be described one by one for the convenience of reading. It should be clear that the device in this embodiment can correspondingly implement all contents in the foregoing method embodiment. The device is used to implement a flash-based data storage method to solve the problem that the conventional flash-based data storage method affects the overall service life of the flash memory. Specifically, as shown in the method embodiment, the device comprises: Figure 5
[0189] The first determining unit 51 can be used to determine the first data to be written;
[0190] The first executing unit 52 can be used to write the first data into the target storage block in the second storage area according to the write order when the power-off instruction is detected if it is determined that the first storage area has the same data as the first data.
[0191] The write order is determined according to the address of each storage block in the second storage area, the first storage area is a data cache area constructed based on static random access memory (SRAM), and the second storage area is a storage area constructed based on flash. The storage block in the second storage area is a storage unit divided by a target byte number according to a preset rule.
[0192] Further, as shown in Figure 6 the device further comprises:
[0193] The second execution unit 53 can be used to write the first data into the target storage block in the second storage area according to the write order if it is determined that the first storage area does not have the same data as the first data.
[0194] Further, as shown in Figure 6 the first execution unit 52 is specifically configured to determine the target storage block in the backup partition based on the write order of the backup partition in the second storage area when a power-off instruction is detected, and write the first data into the target storage block, wherein the power-off instruction includes a hibernation instruction and a power-off instruction.
[0195] Further, as shown in Figure 6 the second execution unit 53 comprises:
[0196] The determination module 531 can be used to determine a frequently recorded partition in the second storage partition and obtain the write order of the frequently recorded partition.
[0197] The write module 532 can be used to determine the target storage block from a plurality of storage blocks of the frequently recorded partition based on the write order of the frequently recorded partition, and write the first data into the target storage block.
[0198] Further, as shown in Figure 6 the write module 532 can be used to write the first data into the target storage block if it is determined that the target storage block does not store any data.
[0199] The write module 532 can also be used to perform an erase operation on the target storage block if it is determined that the target storage block stores second data, and write the first data into the target storage block after the erase operation.
[0200] Further, as shown in Figure 6 the write module 532 comprises:
[0201] The determination submodule 5321 can be used to determine a non-frequent record area in the second storage area and determine a backup storage block based on the writing order of the non-frequent record area if it is determined that the second data needs to be backed up.
[0202] The backup submodule 5322 can be used to write the second data to the backup storage block to back up the second data;
[0203] The write submodule 5323 can be used to perform the erase operation on the target storage block and write the first data to the target storage block that has performed the erase operation.
[0204] Furthermore, such as Figure 6 As shown, the backup submodule 5322 can be specifically used to back up the third data in the remaining storage blocks of the non-frequent recording partition except for the backup storage block if it is determined that the backup storage block stores third data and the third data needs to be backed up, and to perform the erase operation on the backup storage block, and write the second data into the backup storage block after the erase operation is performed.
[0205] The backup submodule 5322 can also be used to write the second data into the backup storage block if it is determined that no data is stored in the backup storage block.
[0206] Furthermore, such as Figure 6 As shown, the device further includes:
[0207] The second determining unit 54 can be used to determine that the second data needs to be backed up if it is determined that there is data identical to the second data in the first storage area.
[0208] The third determining unit 55 can be used to determine that the third data needs to be backed up if it is determined in the first storage area that there is data identical to the third data.
[0209] Furthermore, such as Figure 6 As shown, the first execution unit 52 includes:
[0210] The first determining module 521 can be used to determine the target storage page based on the address order between each of the multiple storage pages in the second storage area;
[0211] The second determining module 522 can be used to determine the target storage block based on the address order between each of the multiple storage blocks in the target storage page.
[0212] The writing module 523 can be used to write the first data to the target storage block.
[0213] Further, as shown in Figure 6 the first determining module 521 can be specifically used for obtaining a page address of each storage page in the second storage area, and determining a storage page corresponding to a previous write operation based on an address order of the page address, and determining a next storage page of the storage page corresponding to the previous write operation as the target storage page, where the page address is determined based on physical addresses of all storage blocks contained in each storage page.
[0214] Further, as shown in Figure 6 the second determining module 522 can be specifically used for obtaining a physical address of each storage block in the storage page, and determining an address order of each storage block based on a sequence of the physical address and physical addresses contained in each storage block, and determining a next storage block of a storage block corresponding to a previous write operation as the target storage block.
[0215] Further, as shown in Figure 6 the write module 523 can be specifically used for writing the first data into a storage sub-block of the target storage block, and adding a verification identifier in a verification sub-block in the target storage block, where the verification identifier is information for verifying integrity of the first data when the first data stored in the storage sub-block is read.
[0216] Further, as shown in Figure 6 the apparatus further comprises:
[0217] The fourth determining unit 56 can be used for traversing all storage blocks in the second storage area, and respectively determining starting positions in the backup partition, the frequently recorded partition and the non-frequently recorded partition in the second storage area;
[0218] The fifth determining unit 57 can be used for respectively determining valid data in the backup partition, the frequently recorded partition and the non-frequently recorded partition based on the starting positions, where the valid data is data commonly used by a user, and the valid data includes the first data, the second data and the third data;
[0219] The adding unit 58 can be used for adding the valid data to the first storage area.
[0220] Further, as shown in Figure 6 the fifth determining unit 57 comprises:
[0221] The first determining module 571 can be used for obtaining a storage page identifier of each storage page, and determining a storage page in which data is recorded in the second storage area based on the storage page identifier;
[0222] The second determining module 572 can be configured to determine, in the storage page in which the data is recorded, the storage block in which the data is stored based on the verification identifier of each storage block, and determine the data in the storage block in which the data is stored as the valid data.
[0223] To achieve the above object, according to another aspect of the present application, the embodiments of the present application further provide a storage medium, which comprises a stored program, wherein the program controls a device in which the storage medium is located to perform the data storage method when the program is run.
[0224] To achieve the above object, according to another aspect of the present application, the embodiments of the present application further provide a data storage device, which comprises a storage medium and one or more processors, the storage medium is coupled with the processor, the processor is configured to execute program instructions stored in the storage medium, and the program instructions perform the data storage method when the program instructions are run.
[0225] The embodiment of the present application provides a data storage method and device, the embodiment of the present application can determine first data to be written; if it is determined that the same data as the first data exists in a first storage area, the first data is written into the target storage block in the second storage area according to the write order when a power-off instruction is detected, so that the flash-based data storage function is realized. Compared with the prior art, in the flash-based data storage process of the present application, since the write order is determined according to the order of the addresses of each storage block in the second storage area, the storage block can be selected as the target storage block for writing based on the write order in the writing process, which ensures that the data can be written into different storage blocks in a certain order in the process of writing data, and the problem of excessive wear caused by repeatedly writing data in the same storage block due to the order of the addresses and the like is avoided, thereby avoiding the problem that the service life of the entire flash memory is affected due to the excessive wear and failure of individual storage blocks. In addition, the first storage area is a data cache area constructed based on a static random access memory (SRAM), and the second storage area is a storage area constructed based on a flash, so that it can be ensured that, in the process of writing the first data, if it is determined that the same data as the first data exists in the first storage area, it indicates that the first data is frequently used by the user, so that it can be ensured that the first data in the first storage area constructed based on SRAM can be written into the second storage area constructed based on flash in time when the user suddenly issues a power-off instruction, thereby solving the problem that the data in the SRAM is lost due to power-off. Meanwhile, the storage blocks in the second storage area are divided into storage units with a target byte number according to a preset rule, so that it is ensured that the original storage block storage space division mode with kilobyte as the unit is avoided in the process of data storage, so that it is ensured that different data can be stored in the original storage block when multiple different data are stored, and the different data can be managed individually, that is, the effect of small-range erasing of several bytes or tens of bytes can be realized on the storage block with the target byte number in the erasing process, the problem of excessive erasing caused by the large-range erasing of several kilobytes of the entire original storage block in the conventional mode is avoided, and the service life of the flash memory can be further improved.
[0226] The data storage device comprises a processor and a memory, the first determining unit, the first executing unit and the like are stored in the memory as program units, and the corresponding functions are realized by the processor executing the program units stored in the memory.
[0227] The processor includes a core, and the core retrieves corresponding program units in the memory. The core can be provided with one or more, and a data storage method is realized by adjusting core parameters to solve the problem of affecting the overall service life of the flash memory caused by the conventional flash-based data storage.
[0228] The embodiment of the present application provides a data storage device, which comprises a storage medium and one or more processors, the storage medium is coupled with the processor, and the processor is configured to execute program instructions stored in the storage medium; the program instructions perform the data storage method of any one of the preceding embodiments when running.
[0229] The embodiment of the present application provides a storage medium, which comprises stored programs, wherein the programs control a device where the storage medium is located to perform the data storage method described above when running.
[0230] The storage medium can include a non-permanent memory in a computer readable medium, random access memory (RAM) and / or non-volatile memory such as read-only memory (ROM) or flash memory (flash RAM), and the memory includes at least one memory chip.
[0231] The embodiment of the present application provides a device, which comprises a processor, a memory and a program stored in the memory and capable of running on the processor, and the processor performs the following steps when executing the program: if it is determined that the same data as the first data exists in a first storage area, the first data is written into a target storage block in a second storage area according to a write order when a power-off instruction is detected; wherein the write order is determined according to the order of addresses of each storage block in the second storage area, the first storage area is a data cache area constructed based on static random access memory (SRAM), the second storage area is a storage area constructed based on flash, and the storage block in the second storage area is a storage unit divided according to a target byte number according to a preset rule.
[0232] Further, the method further comprises:
[0233] If it is determined that the same data as the first data does not exist in the first storage area, the first data is written into the target storage block in the second storage area according to the write order.
[0234] Further, the first data is written into the target storage block in the second storage area according to the write order when the power-off instruction is detected, which comprises:
[0235] When a power-off instruction is detected, a target storage block is determined in a plurality of storage blocks in a backup partition in the second storage area based on a write order of the backup partition, and the first data is written into the target storage block, wherein the power-off instruction includes a hibernation instruction and a power-off instruction.
[0236] Further, the writing of the first data into the target storage block in the second storage area according to the write order includes:
[0237] A frequently recorded partition is determined in the second storage partition, and a write order of the frequently recorded partition is obtained;
[0238] The target storage block is determined from a plurality of storage blocks of the frequently recorded partition based on the write order of the frequently recorded partition, and the first data is written into the target storage block.
[0239] Further, the determination of the target storage block from the plurality of storage blocks of the frequently recorded partition based on the write order of the frequently recorded partition and the writing of the first data into the target storage block include:
[0240] If it is determined that the target storage block does not store any data, the first data is written into the target storage block.
[0241] Or,
[0242] If it is determined that the target storage block stores second data, an erase operation is performed on the target storage block, and the first data is written into the target storage block after the erase operation.
[0243] Further, if it is determined that the target storage block stores second data, an erase operation is performed on the target storage block, and the first data is written into the target storage block after the erase operation, including:
[0244] If it is determined that the second data needs to be backed up, a non-frequently recorded partition is determined in the second storage area, and a backup storage block is determined based on a write order of the non-frequently recorded partition.
[0245] The second data is written into the backup storage block to back up the second data.
[0246] The erase operation is performed on the target storage block, and the first data is written into the target storage block after the erase operation.
[0247] Further, the writing the second data into the backup storage block to backup the second data comprises:
[0248] If it is determined that the backup storage block stores third data and the third data needs to be backed up, the third data is backed up in the remaining storage blocks in the non-frequently recorded partition except the backup storage block, and the erase operation is performed on the backup storage block, and the second data is written into the backup storage block after the erase operation is performed;
[0249] Or,
[0250] If it is determined that the backup storage block does not store any data, the second data is written into the backup storage block.
[0251] Further, the method further comprises:
[0252] If it is determined that the same data as the second data exists in the first storage area, it is determined that the second data needs to be backed up;
[0253] If it is determined that the same data as the third data exists in the first storage area, it is determined that the third data needs to be backed up.
[0254] Further, the writing the first data into the target storage block in the second storage area according to the write order comprises:
[0255] In the plurality of storage pages in the second storage area, the target storage page is determined based on the address order between each of the storage pages;
[0256] In the plurality of storage blocks in the target storage page, the target storage block is determined based on the address order between each of the storage blocks;
[0257] The first data is written into the target storage block.
[0258] Further, the determining the target storage page in the plurality of storage pages in the second storage area based on the address order between each of the storage pages comprises:
[0259] The page address of each storage page in the second storage area is obtained, and the storage page corresponding to a previous write operation is determined based on the address order of the page address, and the next storage page of the storage page corresponding to the previous write operation is determined as the target storage page, wherein the page address is determined based on the physical address of all storage blocks contained in each of the storage pages.
[0260] Further, the target storage block is determined based on the address sequence between each of the storage blocks in the target storage page, comprising:
[0261] The physical address of each storage block in the storage page is obtained, and the address sequence of each storage block is determined based on the sequence of the physical addresses and the physical addresses contained in each storage block, and the next storage block of the storage block corresponding to the previous write operation is determined as the target storage block.
[0262] Further, the first data is written into the target storage block, comprising:
[0263] The first data is written into the storage sub-block of the target storage block, and a verification identifier is added in the verification sub-block in the target storage block, wherein the verification identifier is information for verifying the integrity of the first data when the first data stored in the storage sub-block is read.
[0264] Further, the method further comprises:
[0265] All storage blocks in the second storage area are traversed, and the starting positions in the backup sub-area, the frequently recorded sub-area and the non-frequently recorded sub-area in the second storage area are respectively determined;
[0266] The effective data in the backup sub-area, the frequently recorded sub-area and the non-frequently recorded sub-area is respectively determined based on the starting positions, wherein the effective data is commonly used by users, and the effective data comprises the first data, the second data and the third data;
[0267] The effective data is added to the first storage area.
[0268] Further, the effective data in the backup sub-area, the frequently recorded sub-area and the non-frequently recorded sub-area is respectively determined based on the starting positions, comprising:
[0269] The storage page identifier of each storage page is obtained, and the storage page in which data is recorded in the second storage area is determined based on the storage page identifier;
[0270] In the storage page in which data is recorded, the storage block in which data is stored is determined in a plurality of storage blocks based on the verification identifier of each storage block, and the data in the storage block in which data is stored is determined as the effective data.
[0271] The application further provides a computer program product, which is suitable for executing program codes for initializing the following method steps when executed on a data processing device: if it is determined that the same data as the first data exists in the first storage area, writing the first data into the target storage block in the second storage area according to the writing sequence when a power-off instruction is detected; wherein the writing sequence is determined according to the sequence of the addresses of each storage block in the second storage area, the first storage area is a data cache area constructed based on static random access memory (SRAM), and the second storage area is a storage area constructed based on flash, and the storage block in the second storage area is a storage unit divided according to a target byte number according to a preset rule.
[0272] Those skilled in the art will understand that the embodiments of the present application can be provided as methods, systems, or computer program products. Therefore, the present application can take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present application can take the form of a computer program product implemented on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROMs, optical storage media, etc.) containing computer-usable program code.
[0273] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each flow and / or block in the flowcharts and / or block diagrams, and the combination of flows and / or blocks in the flowcharts and / or block diagrams can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device produce the functions specified in the flowcharts and / or block diagrams. Figure 1 The functions specified in a flow or multiple flows and / or blocks Figure 1 The functions specified in a flow or multiple flows and / or blocks
[0274] These computer program instructions can also be stored in a computer-readable memory capable of guiding a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer-readable memory produce a product including instruction devices, which implement the functions specified in the flowcharts and / or block diagrams. Figure 1 The functions specified in a flow or multiple flows and / or blocks Figure 1 The functions specified in a flow or multiple flows and / or blocks
[0275] These computer program instructions can also be loaded into a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer-implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart block or blocks. Figure 1 Figure 1 The flowchart blocks or blocks in the multiple flows and / or blocks
[0276] In one typical configuration, the computing device includes one or more processors (CPUs), input / output interfaces, network interfaces, and memory.
[0277] The memory can include non-persistent memory and / or volatile memory, such as random access memory (RAM) about which the computer stores information about an operating system, application software, and / or the like. Memory is an example of computer readable media.
[0278] Computer readable media includes permanent and non-permanent, removable and non-removable media implemented in any method or technology for storage of information such as computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read only memory (ROM), electrically erasable programmable read only memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), digital versatile disc (DVD), or other optical storage, magnetic cassettes, magnetic tapes, magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information accessible to a computing device. According to the definition herein, computer readable media does not include transitory media, such as modulated data signals and carrier waves.
[0279] It should also be noted that the terms "comprising", "containing" or any other variant thereof are intended to cover a non-exclusive inclusion, such that a process, method, article or apparatus that comprises a list of elements does not include only those elements recited, but can also include other elements not expressly listed or inherent to such process, method, article or apparatus. Without more limitations, the element defined by the statement "comprising a" does not exclude the presence of additional identical elements in the process, method, article or apparatus that includes the element.
[0280] Those skilled in the art will appreciate that embodiments of the present application can be devised for a method, a system, or a computer program product. Accordingly, the present application can take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present application can take the form of a computer program product on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROMs, optical storage devices, etc.) embodying computer-readable program code thereon for use by or in connection with an instruction execution system. For the purposes of this description, a computer-usable or computer readable storage medium can be any apparatus that can contain, store, communicate, propagate, or transport the program for use by or in connection with the instruction execution system, apparatus, or device.
[0281] The foregoing is merely illustrative of the embodiments of this application, and is not intended to limit the application. The application can be practiced with variation within the spirit and scope of the application, which are delineated by the appended claims.
Claims
1. A data storage method, characterized in that, The method includes: Determine the first data to be written; If it is determined that there is data identical to the first data in the first storage area, indicating that the first data is frequently used data, then when a power failure command is detected, the first data is written into the target storage block in the second storage area in the order of writing. The writing order is determined according to the order of the physical addresses of each storage block in the second storage area. The first storage area is a data cache area built on static random access memory (SRAM), and the second storage area is a storage area built on flash memory. The storage blocks in the second storage area are storage units divided according to a preset rule based on the target number of bytes. The storage block is a smaller storage unit subdivided within the original storage block in the second storage area.
2. The method according to claim 1, characterized in that, The method further includes: If it is determined that there is no data identical to the first data in the first storage area, the first data is written into the target storage block in the second storage area according to the writing order.
3. The method according to claim 1, characterized in that, The step of writing the first data into the target storage block in the second storage area according to the writing order when a power failure command is detected includes: When a power-down command is detected, the target storage block is determined from among the multiple storage blocks in the backup partition based on the write order of the backup partition in the second storage area, and the first data is written to the target storage. The power-down command includes a hibernation command and a power-down command.
4. The method according to claim 2, characterized in that, If it is determined that there is no data identical to the first data in the first storage area, the step of writing the first data into the target storage block in the second storage area according to the writing order includes: In the second storage partition, identify frequently recorded partitions and obtain the write order of the frequently recorded partitions; Based on the write order of the frequently recorded partitions, the target storage block is determined from multiple storage blocks of the frequently recorded partitions, and the first data is written into the target storage block.
5. The method according to claim 4, characterized in that, The step of determining the target storage block from multiple storage blocks of the frequent recording partition based on the write order of the frequent recording partition, and writing the first data into the target storage block, includes: If it is determined that the target storage block does not store any data, then the first data is written to the target storage block; or, If it is determined that the target storage block contains the second data, then an erase operation is performed on the target storage block, and the first data is written into the target storage block after the erase operation has been performed.
6. The method according to claim 5, characterized in that, If it is determined that the target storage block contains second data, then an erase operation is performed on the target storage block, and the first data is written into the target storage block after the erase operation has been performed, including: If it is determined that the second data needs to be backed up, then a non-frequent record area is determined in the second storage area, and a backup storage block is determined based on the writing order of the non-frequent record area; The second data is written to the backup storage block to back up the second data; The erase operation is performed on the target storage block, and the first data is written to the target storage block on which the erase operation was performed.
7. The method according to claim 6, characterized in that, The step of writing the second data to the backup storage block to back up the second data includes: If it is determined that the backup storage block contains third data and the third data needs to be backed up, then the third data is backed up in the remaining storage blocks of the non-frequent recording partition except for the backup storage block, and the erase operation is performed on the backup storage block, and the second data is written into the backup storage block after the erase operation is performed. or, If it is determined that no data is stored in the backup storage block, then the second data is written into the backup storage block.
8. The method according to claim 7, characterized in that, The method further includes: If it is determined that there is data identical to the second data in the first storage area, then it is determined that the second data needs to be backed up; If it is determined that there is data identical to the third data in the first storage area, then it is determined that the third data needs to be backed up.
9. The method according to claim 1, characterized in that, The step of writing the first data into the target storage block in the second storage area according to the writing order includes: The target storage page is determined based on the address order among the multiple storage pages in the second storage area. Among the multiple storage blocks in the target storage page, the target storage block is determined based on the address order among the storage blocks; Write the first data into the target storage block.
10. The method according to claim 9, characterized in that, Determining the target storage page based on the address order among the multiple storage pages in the second storage area includes: Obtain the page address of each storage page in the second storage area, and determine the storage page corresponding to the previous write operation based on the address order of the page addresses. Then, determine the next storage page of the storage page corresponding to the previous write operation as the target storage page. The page address is determined based on the physical address of all storage blocks contained in each storage page.
11. The method according to claim 9, characterized in that, Determining the target storage block based on the address order among the multiple storage blocks in the target storage page includes: Obtain the physical address of each storage block in the storage page, determine the address order of the storage blocks based on the order of the physical addresses and the physical addresses contained in each storage block, and determine the next storage block corresponding to the storage block of the previous write operation as the target storage block.
12. The method according to claim 9, characterized in that, The step of writing the first data into the target storage block includes: The first data is written to a storage block of the target storage block, and a verification identifier is added to the verification block of the target storage block. The verification identifier is information for verifying the integrity of the first data when the first data stored in the storage block is read.
13. The method according to claim 12, characterized in that, The method further includes: Traverse all storage blocks in the second storage area and determine the starting positions of the backup partition, frequent record partition, and infrequent record partition in the second storage area respectively; Based on the starting position, valid data in the backup partition, the frequently recorded partition, and the infrequently recorded partition are determined respectively, wherein the valid data is data that the user frequently uses, and the valid data includes the first data, the second data, and the third data; Add the valid data to the first storage area.
14. The method according to claim 13, characterized in that, The step of determining the valid data in the backup partition, the frequently recorded partition, and the infrequently recorded partition based on the starting position includes: Obtain the storage page identifier of each storage page, and determine the storage page containing data in the second storage area based on the storage page identifier; In the storage page containing the recorded data, based on the verification identifier of each storage block, the storage block containing the data is identified among multiple storage blocks, and the data in the storage block containing the data is identified as the valid data.
15. A data storage device, characterized in that, The device includes: The first determining unit is used to determine the first data to be written; The first execution unit is configured to, if it is determined that there is data identical to the first data in the first storage area, indicating that the first data is frequently used data, write the first data into the target storage block in the second storage area in the order of writing when a power-down instruction is detected; The writing order is determined according to the order of the physical addresses of each storage block in the second storage area. The first storage area is a data cache area built on static random access memory (SRAM), and the second storage area is a storage area built on flash memory. The storage blocks in the second storage area are storage units divided according to a preset rule based on the target number of bytes. The storage block is a smaller storage unit subdivided within the original storage block in the second storage area.
16. A storage medium, characterized in that, The storage medium includes a stored program, wherein the program, when running, controls the device containing the storage medium to execute the data storage method according to any one of claims 1-14.
17. A data storage device, characterized in that, The device includes a storage medium; and one or more processors, the storage medium being coupled to the processors, the processors being configured to execute program instructions stored in the storage medium; the program instructions, when executed, perform the data storage method according to any one of claims 1-14.
Citation Information
Patent Citations
Nonvalatile storage medium access method as well as data updating method and equipment
CN103455449A
Wiping and writing management method and system for non-volatile flash memory
CN104156317A
SIM card file erasing and writing system and method applied to SoftSIM and readable storage medium
CN112231244A
Data operating method in flash memory medium
CN1635579A