Serial Flash Memory, Its Data Processing Method, Device, and Storage Medium

By dividing units in serial flash memory and using bitmaps and identification arrays, the problem of data update in embedded applications is solved, and more efficient data storage and updates are achieved.

CN114281241BActive Publication Date: 2025-05-27BEIJING SMARTCHIP MICROELECTRONICS TECHNOLOGY CO LTD +1
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202111342281.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-11-12
Publication Date
2025-05-27
Estimated Expiration
2041-11-12

AI Technical Summary

Technical Problem

Data updates for serial flash memory in existing embedded applications take a long time, mainly because the entire sector needs to be erased and programmed when data is updated.

Method used

By further dividing the sectors of serial flash into multiple subunits, and using subunit bitmap and subunit identification arrays to quickly find free subunits, achieving targeted erasing and writing, reducing the time-consuming of data updates.

Benefits of technology

Through the use of sub-unit bitmaps and identification arrays, data can be quickly positioned and updated, significantly reducing the time-consuming data update and improving the efficiency of data storage.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114281241B_ABST
    Figure CN114281241B_ABST
Patent Text Reader

Abstract

An embodiment of the present invention provides a serial flash memory, a data processing method, device, and storage medium thereof, belonging to the technical field of memories. The serial flash memory includes a plurality of sectors, and each sector includes: a plurality of sub-units, the plurality of sub-units being used to store data, a sub-unit bitmap, and a sub-unit identification array, the sub-unit bitmap recording the space occupancy of the plurality of sub-units, and the sub-unit identification array recording the identification of the data stored in each of the plurality of sub-units. The serial flash memory, its data processing method, device, and storage medium can perform data update quickly.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of memories, and particularly to a serial flash memory, a data processing method, device and storage medium thereof. Background Art

[0002] In embedded application software, there are often storage requirements for log data or key-value pair data. NOR flash memories with a serial (SPI) interface are a relatively commonly used type of flash memory chip in the market for embedded application data storage due to their simple interface, low price, and moderate capacity.

[0003] In existing data storage in embedded applications, a dedicated area for each purpose is generally adopted, that is, the serial flash memory is simply divided into equal specific-sized units, and the specified units are used to store specified data. When the data is updated, the data of the entire erased unit is read out, the specified data is updated, and then the data of the erased unit is erased and the updated data is written into the erased storage unit. In this way, when the data is updated, any change in the data will trigger the erasure and programming operations of the entire sector. Considering that the erasure and programming of the serial flash memory are time-consuming, the data update is time-consuming. Summary of the Invention

[0004] An object of an embodiment of the present invention is to provide a serial flash memory, a data processing method, device and storage medium thereof, which can perform data update quickly.

[0005] To achieve the above object, an embodiment of the present invention provides a serial flash memory, which includes a plurality of sectors, and each sector includes: a plurality of sub-units, the plurality of sub-units are used to store data, a sub-unit bitmap and a sub-unit identification array, the sub-unit bitmap records the space occupation of the plurality of sub-units, and the sub-unit identification array records the identification of the data stored in each of the plurality of sub-units.

[0006] Preferably, the plurality of sub-units are further used to store at least one of sector identification information, sector sequence number information, and sector check sequence, where the sector identification information is used to identify a legal data sector, the sector sequence number information is used to record the number of the sector, and the sector check sequence is used to check the legality of the sector identification information and the sector sequence number information.

[0007] Preferably, each sector includes 128 sub-units of 32 bytes. Among the first 9 sub-units at the beginning of each sector, the sector identification information is 4 bytes, the sector sequence number information is 4 bytes, the sector check sequence is 4 bytes, the sub-unit bitmap is 16 bytes, and the sub-unit identification array is 256 bytes.

[0008] Preferably, the sub-unit bitmap is a bit array with the same number of bits as the number of the multiple sub-units, and the sub-unit identification array is an array with the same number of elements as the number of the multiple sub-units.

[0009] Preferably, the data stored in the multiple sub-units includes at least one of data identification information, data length information, data content, and data check sequence, where the data identification information corresponds to the identification of the data recorded in the sub-unit identification array, the data length information is used to represent the length of the data content, and the data check sequence is used to verify the legality of the data.

[0010] Preferably, the data identification information is 2 bytes, the data length information is 2 bytes, and the data check sequence is 4 bytes, where the data length information includes pre-deletion status information of the data.

[0011] An embodiment of the present invention provides a method for processing data of a serial flash memory. Based on the serial flash memory described above, when storing key-value pair data to be stored, the method includes: in all sectors allocated to the key-value pair, searching for the identification of the data in the sub-unit identification array according to the data identification information of the key-value pair data to be stored; when obtaining the first data with the identification corresponding to the data identification information, deleting the first data; in all sectors allocated to the key-value pair, searching for the space occupancy of the sub-units recorded in the sub-unit bitmap; when obtaining at least one unoccupied sub-unit, storing the key-value pair data to be stored into any one of the at least one unoccupied sub-units.

[0012] Preferably, when obtaining the first data with the identification corresponding to the data identification information, deleting the first data includes: when obtaining the first data with the identification corresponding to the data identification information, marking the first data as in a pre-deleted state; after storing the key-value pair data to be stored into any one of the at least one unoccupied sub-units, deleting the first data.

[0013] Preferably, when at least one unoccupied sub-unit is not obtained, the method includes: in all sectors allocated to the key-value pair, searching for the sector with the fewest occupied sub-units as the recycle sector; writing the key-value pair data in the recycle sector to a spare sector; erasing the recycle sector; writing the key-value pair data in the spare sector back to the recycle sector; in the recycle sector, re-searching for the space occupancy of the sub-units recorded in the sub-unit bitmap.

[0014] Preferably, after writing the key-value pair data in the spare sector back to the recycle sector, setting the spare sector to an invalid state.

[0015] Preferably, when power failure occurs during data storage, the method further includes: deleting the key-value pair data that is not fully written in all sectors allocated to the key-value pairs; searching for key-value pair data with the same identifier as the key-value pair data marked as pre-deleted in all sectors allocated to the key-value pairs; when key-value pair data with the same identifier as the key-value pair data marked as pre-deleted is found, deleting the key-value pair data marked as pre-deleted; when key-value pair data with the same identifier as the key-value pair data marked as pre-deleted is not found, rewriting the key-value pair data marked as pre-deleted.

[0016] Preferably, when power failure occurs during data storage, the method further includes: searching for valid data in the spare sector; when valid data is found in the spare sector, erasing the recycled sector; writing the key-value pair data in the spare sector back to the recycled sector; in the recycled sector, re-searching for the space occupancy of the sub-units recorded in the sub-unit bitmap.

[0017] An embodiment of the present invention further provides a data processing method for a serial flash memory. Based on the serial flash memory described above, when storing log data to be stored, the method includes: searching for the space occupancy of the sub-units recorded in the sub-unit bitmap in the current write sector; when at least one unoccupied sub-unit is obtained, storing the log data to be stored in any one of the at least one unoccupied sub-units, where in the current write sector, the identifier of the data recorded in the sub-unit identifier array and the data identifier information of the stored log data are sequence numbers representing the write order.

[0018] Preferably, when at least one unoccupied sub-unit is not obtained, the method further includes: storing the log data to be stored in the next sector allocated to the log data that has at least one unoccupied sub-unit.

[0019] Preferably, the method further includes: when none of the sectors allocated to the log data has at least one unoccupied sub-unit, erasing the sub-unit that stores the log data first in all sectors allocated to the log data, and storing the log data to be stored in the erased sub-unit.

[0020] Preferably, when the log data is to be read, the method further includes: determining the sector of the subunit that stores the log data first among all sectors allocated to the log data as the current read sector; reading the log data stored in the current read sector sequentially according to the sequence numbers recorded in the subunit identification array in the current read sector; when the reading of the log data stored in the current read sector is completed, determining whether the next sector allocated to the log data is the current write sector; and stopping reading after completing the reading of the current write sector when the next sector allocated to the log data is the current write sector.

[0021] An embodiment of the present invention further provides a data processing device for a serial flash memory. Based on the serial flash memory described above, when key-value pair data is to be stored, the device includes: a first search unit, a deletion unit, and a first storage unit. Among them, the first search unit is used to search for the identification of data in the subunit identification array according to the data identification information of the key-value pair data to be stored among all sectors allocated to the key-value pair; the deletion unit is used to delete the first data when obtaining the first data corresponding to the identification of the data identification information; the first search unit is further used to search for the space occupancy of the subunits recorded in the subunit bitmap among all sectors allocated to the key-value pair; and the first storage unit is used to store the key-value pair data to be stored into any one of the at least one unoccupied subunit when obtaining the at least one unoccupied subunit.

[0022] An embodiment of the present invention further provides a data processing device for a serial flash memory. Based on the serial flash memory described above, when log data is to be stored, the device includes: a second search unit and a second storage unit. Among them, the second search unit is used to search for the space occupancy of the subunits recorded in the subunit bitmap in the current write sector; the second storage unit is used to store the log data to be stored into any one of the at least one unoccupied subunit when obtaining the at least one unoccupied subunit, where in the current write sector, the identification of the data recorded in the subunit identification array and the data identification information of the stored log data are sequence numbers representing the writing order.

[0023] An embodiment of the present invention further provides a machine-readable storage medium, on which instructions are stored, and the instructions are used to cause the machine to execute the data processing method of the serial flash memory described above.

[0024] Through the above technical solution, by using the serial flash memory, its data processing method, device and storage medium provided by the present invention, the space occupancy of multiple sub-units can be quickly found using the sub-unit bitmap, and the identifier of the data stored in each sub-unit among multiple sub-units can be quickly found using the sub-unit identifier array. Thus, targeted erasure and writing can be performed, the positioning of the erased and written sub-units is rapid, and the time consumed for data update execution is short.

[0025] Other features and advantages of the embodiments of the present invention will be described in detail in the subsequent specific implementation part. BRIEF DESCRIPTION OF THE DRAWINGS

[0026] The drawings are used to provide a further understanding of the embodiments of the present invention, and constitute a part of the specification. Together with the following specific implementation, they are used to explain the embodiments of the present invention, but do not constitute a limitation to the embodiments of the present invention. In the drawings:

[0027] Figure 1 is a schematic structural diagram of a serial flash memory provided by an embodiment of the present invention;

[0028] Figure 2 is a schematic diagram of the relationship between a sub-unit bitmap, a sub-unit identifier array and sub-units provided by an embodiment of the present invention;

[0029] Figure 3 is a schematic structural diagram of a serial flash memory provided by another embodiment of the present invention;

[0030] Figure 4 is a schematic structural diagram of data provided by an embodiment of the present invention;

[0031] Figure 5 is a flowchart of a data processing method for a serial flash memory provided by an embodiment of the present invention;

[0032] Figure 6 is a flowchart of a data processing method for a serial flash memory provided by another embodiment of the present invention;

[0033] Figure 7 is a flowchart of a data processing method for a serial flash memory provided by another embodiment of the present invention;

[0034] Figure 8 is a flowchart of a power-off processing method during data storage provided by an embodiment of the present invention;

[0035] Figure 9 is a flowchart of a power-off processing method during data storage provided by another embodiment of the present invention;

[0036] Figure 10 is a flowchart of a data processing method for a serial flash memory provided by another embodiment of the present invention;

[0037] Figure 11 It is a flowchart of a data processing method for a serial flash memory provided by another embodiment of the present invention;

[0038] Figure 12 It is a structural block diagram of a data processing device for a serial flash memory provided by an embodiment of the present invention;

[0039] Figure 13 It is a structural block diagram of a data processing device for a serial flash memory provided by another embodiment of the present invention.

[0040] Description of Reference Numerals

[0041] 121 First search unit 122 Deletion unit

[0042] 123 First storage unit 131 Second search unit

[0043] 132 Second storage unit Detailed Embodiment

[0044] The following will describe in detail the specific embodiments of the embodiments of the present invention with reference to the accompanying drawings. It should be understood that the specific embodiments described herein are only for explaining and illustrating the embodiments of the present invention, and are not used to limit the embodiments of the present invention.

[0045] Figure 1 It is a schematic structural diagram of a serial flash memory provided by an embodiment of the present invention. As Figure 1 shown, the serial flash memory includes a plurality of sectors, and each sector includes: a plurality of sub-units for storing data, a sub-unit bitmap, and a sub-unit identification array. The sub-unit bitmap records the space occupancy of the plurality of sub-units, and the sub-unit identification array records the identification of the data stored in each sub-unit of the plurality of sub-units.

[0046] Specifically, the minimum erasable unit of a serial (SPI) interface NOR flash memory chip is a sector, and the size of a sector is generally 4096 bytes. In the embodiments of the present invention, the sector is further divided into a plurality of sub-units, and the length of each sub-unit can be arbitrarily set under reasonable circumstances. The data chunking method is flexible, and the storage space utilization rate is high. In the embodiments of the present invention, it is preferably divided into 128 sub-units of 32 bytes from the 4096 bytes. The 128 sub-units after division are numbered from 0 to 127, and consecutive sub-units are used to store the data to be saved. Here, the size of 32 is more appropriate, and the overall information occupies less space. If the data is large and cannot be stored in one sub-unit, multiple sub-units can be used to store it together.

[0047] Figure 2 It is a schematic diagram of the relationship between the sub-unit bitmap, the sub-unit identification array, and the sub-units provided by an embodiment of the present invention. As Figure 2As shown, the sub-unit bit map is a bit array with the same number of bits as the number of the multiple sub-units, and the sub-unit identification array is an array with the same number of elements as the number of the multiple sub-units. For example, among the 9 sub-units (i.e., numbered 0 - 8) at the beginning of each sector, there is a 16-byte sub-unit bit map and a 256-byte sub-unit identification array. The 16-byte sub-unit bit map can be a 128-bit bit array. The bits in the array are numbered from 0 to 127, and the value of each bit represents the space occupancy of the sub-unit with the same number as the bit number. For example, 1 indicates unoccupied, and 0 indicates occupied. The sub-unit bit map is used to quickly retrieve the available space in the current sector; the 256-byte sub-unit identification array is an array of 128 2-byte integers, and the data identification of each sub-unit is also represented by a 2-byte integer. The identifications in the sub-unit identification array are numbered from 0 to 127, and the value of each identification represents the identification of the data of the sub-unit with the same number as the identification number. The sub-unit identification array is used to quickly find and locate the data with a specified identification.

[0048] Figure 3 is a schematic structural diagram of a serial flash memory provided by another embodiment of the present invention. As Figure 3 shown, the multiple sub-units are further used to store at least one of sector identification information, sector sequence number information, and sector check sequence, wherein the sector identification information is used to identify a legal data sector, the sector sequence number information is used to record the number of the sector, and the sector check sequence is used to verify the legality of the sector identification information and the sector sequence number information.

[0049] Specifically, for example, among the 9 sub-units (i.e., numbered 0 - 8) at the beginning of each sector, the sector identification information is 4 bytes, the sector sequence number information is 4 bytes, and the sector check sequence is 4 bytes. The sector identification information is a set of specific byte sequences used to identify a legal data sector. The sector sequence number information records the number of the sector, and the sector check sequence is used to verify the sector identification information and the sector sequence number information to verify the legality of the sector information.

[0050] Figure 4 is a schematic structural diagram of data provided by an embodiment of the present invention. As Figure 4 shown, preferably, the data stored in the multiple sub-units includes at least one of data identification information, data length information, data content, and data check sequence, wherein the data identification information corresponds to the identification of the data recorded in the sub-unit identification array, the data length information is used to represent the length of the data content, and the data check sequence is used to verify the legality of the data.

[0051] Preferably, the data identification information is 2 bytes, the data length information is 2 bytes, and the data check sequence is 4 bytes. The data length information includes the pre-deletion status information of the data. The data identification information corresponds to the sub-unit data identification array. The valid data identification information cannot be all 0s and all 1s. The data identification information of all 0s represents the deleted data, and the data identification information of all 1s represents the unoccupied data space. The 15th bit of the 2-byte data length information is used to represent the pre-deletion status information. For example, 1 indicates that the data is in the normal state, and 0 indicates that the data is in the pre-deletion state, which is used for data recovery when a power failure occurs during data update (details will be described below). The 12-15 bits of the data length information are always calculated using 0 during the calculation of the data check sequence. The data cannot be stored across sectors, and the maximum value of the data length cannot exceed 3800. The sector check sequence and the data check sequence can both use CRC32 check.

[0052] Figure 5 is a flowchart of a data processing method for a serial flash memory provided by an embodiment of the present invention. As Figure 5 shown, based on the serial flash memory described above, when storing key-value pair data to be stored, the method includes:

[0053] Step S501, in all sectors allocated to the key-value pair, search for the identification of the data in the sub-unit identification array according to the data identification information of the key-value pair data to be stored;

[0054] For example, first search for the identification that is the same as the data identification information of the key-value pair data to be stored in the sub-unit identification array of all sectors allocated to the key-value pair, and only need to search from the starting sector to the ending sector allocated to the key-value pair data.

[0055] Step S502, when obtaining the first data with the identification corresponding to the data identification information, delete the first data;

[0056] For example, if the first data with the identification corresponding to the data identification information is searched, it means that the first data needs to be updated, so the first data can be deleted. If the first data with the identification corresponding to the data identification information is not searched, it means that the key-value pair data to be stored is not any data in the sector to be updated, and only step S503 needs to be directly executed.

[0057] Step S503, in all sectors allocated to the key-value pair, search for the space occupancy of the sub-units recorded in the sub-unit bitmap;

[0058] For example, first search whether there is an idle sub-unit in all sectors allocated to the key-value pair. This search can be directly performed from the record of the sub-unit bitmap.

[0059] Step S504, when at least one unoccupied sub-unit is obtained, store the key-value pair data to be stored into any one of the at least one unoccupied sub-units.

[0060] For example, if there is sufficient free space in the sector allocated to the key-value pair, write the key-value pair data to be stored into the corresponding sub-unit. Preferably, in order to rotate the erasure and programming of sectors on different sectors and reduce the risk of flash memory life exhaustion, the sector where the key-value pair data to be stored is written can be different from the sector where the first data corresponding to its data identification information is located.

[0061] Figure 6 is a flowchart of a data processing method for a serial flash memory provided by another embodiment of the present invention. As Figure 6 shown, the method includes:

[0062] Step S601, when the first data corresponding to the data identification information is obtained, mark the first data as a pre-deletion state;

[0063] For example, in order to perform data recovery after a power failure and reduce the probability of data loss, in an embodiment of the present invention, after the first data is obtained, the first data is not directly deleted, but marked as a pre-deletion state, so that after a power failure, a recovery operation can be performed on the data marked as the pre-deletion state, which will be described in detail below.

[0064] Step S602, after storing the key-value pair data to be stored into any one of the at least one unoccupied sub-units, delete the first data.

[0065] For example, when it is determined that the key-value pair data to be stored has been completely stored, then delete the first data, so that data update can be completed.

[0066] Figure 7 is a flowchart of a data processing method for a serial flash memory provided by another embodiment of the present invention. As Figure 7 shown, when at least one unoccupied sub-unit is not obtained, the method includes:

[0067] Step S701, in all sectors allocated to key-value pairs, search for the sector with the fewest occupied sub-units as the recycling sector;

[0068] For example, when at least one unoccupied sub-unit is not obtained, it means that there is no sufficient space in all sectors allocated to key-value pairs to write the key-value pair data to be stored. At this time, a sector recycling operation needs to be performed. First, find the sector with the fewest occupied sub-units as the recycling sector. Since the sector stores the least amount of data, it is easier to perform subsequent data exchange with the spare sector.

[0069] Step S702: Write the key-value pair data in the recycled sector into the spare sector;

[0070] For example, set up a spare sector and write all the key-value pair data in the recycled sector into the spare sector first.

[0071] Step S703: Erase the recycled sector;

[0072] For example, after all the data in the recycled sector has been written into the spare sector, the recycled sector can be erased to release space as much as possible.

[0073] Step S704: Write the key-value pair data in the spare sector back to the recycled sector;

[0074] For example, subsequently, write the key-value pair data in the spare sector back to the recycled sector to ensure that no data is lost, and then set the spare sector to an invalid state.

[0075] Step S705: In the recycled sector, re-search for the space occupancy of the subunits recorded in the subunit bitmap.

[0076] For example, since the recycled sector has been erased and space may be released, re-search for the space occupancy of the subunits recorded in the subunit bitmap. When at least one unoccupied subunit is obtained, store the key-value pair data to be stored in any one of the at least one unoccupied subunits. If at least one unoccupied subunit still cannot be obtained, the write fails.

[0077] Figure 8 is a flowchart of a method for handling power failure during data storage provided by an embodiment of the present invention. As Figure 8 shown, when a power failure occurs during data storage, it will cause data write errors. There may be the following several situations. First, the write error may occur before the original data is pre-deleted. At this time, the original data remains unchanged and the new data is completely lost. Second, it occurs after the pre-deletion and before the new data is completely written. At this time, the original data is not completely lost in the pre-deleted state and the new data is not completely written. Third, it occurs after the new data is completely written and before the original data is completely deleted. At this time, neither the new data nor the original data is lost. Fourth, it occurs after the new data is completely written and the original data is completely deleted. The original data has been deleted and the new data has been completely written. For the above several situations, the present invention provides a method for power failure recovery, and this method includes:

[0078] Step S801: Delete the key-value pair data that is not completely written in all the sectors allocated to the key-value pairs;

[0079] For example, to check if there are key-value pair data that have not been fully written. If so, delete the key-value pair data that have not been fully written, which is the second case above.

[0080] Step S802: Determine whether key-value pair data with the same identifier as the key-value pair data marked as pre-deleted status is found among all sectors allocated to the key-value pair.

[0081] For example, search for key-value pair data with the same identifier as the key-value pair data in the pre-deleted status. If there is such data, it means that the key-value pair data to be stored has been completely written, which is the third case above; if not, it means that the key-value pair data that have not been fully written in step S801 have been deleted. As for the first and fourth cases above, no processing is required. Therefore, the first case directly corresponds to the state before the key-value pair data to be stored is written, and the fourth case directly corresponds to the state after the key-value pair data to be stored is written.

[0082] Step S803: When key-value pair data with the same identifier as the key-value pair data marked as pre-deleted status is found, delete the key-value pair data marked as pre-deleted status.

[0083] For example, when key-value pair data with the same identifier as the key-value pair data marked as pre-deleted status is found, this is the third case at this time. Just directly delete the key-value pair data marked as pre-deleted status, and at this time, it returns to the state after the key-value pair data to be stored is written.

[0084] Step S804: When key-value pair data with the same identifier as the key-value pair data marked as pre-deleted status is not found, rewrite the key-value pair data marked as pre-deleted status.

[0085] For example, when key-value pair data with the same identifier as the key-value pair data marked as pre-deleted status is found, this is the second case at this time. Just directly rewrite the key-value pair data marked as pre-deleted status, and at this time, it returns to the state before the key-value pair data to be stored is written.

[0086] Figure 9 It is a flowchart of the method for handling power failure during data storage provided by another embodiment of the present invention. As Figure 9 shown, when a power failure occurs during data storage, there may also be a situation where the data on the backup sector has not been written to the original recycled sector in time. Therefore, it is necessary to perform a data recovery check on the data on the backup sector. The method further includes:

[0087] Step S901: Determine whether valid data is found in the spare sector.

[0088] For example, search for valid data in the spare sector. If there is valid data, it indicates that the data in the spare sector has not been fully written to the recycled sector, or it has been written to the recycled sector, but the spare sector has not been set to invalid. If there is no valid data, there is no need to recover the recycled sector.

[0089] Step S902, when valid data is found in the spare sector, erase the recycled sector;

[0090] For example, at this time, regardless of the above situation, for safety reasons, the recycled sector can be erased first to re - execute the write.

[0091] Step S903, write the key - value pair data in the spare sector back to the recycled sector;

[0092] For example, subsequently, write the key - value pair data in the spare sector back to the recycled sector and set the spare sector to invalid.

[0093] Step S904, in the recycled sector, re - search for the space occupancy of the sub - units recorded in the sub - unit bitmap.

[0094] For example, since writing the spare sector data back to the recycled sector is a sector recycling operation performed when the sector has no space, it is still necessary to continue with an operation similar to step S705, which will not be elaborated here.

[0095] Figure 10 It is a flowchart of a data processing method for a serial flash memory provided by another embodiment of the present invention. As Figure 10 shown, based on the serial flash memory described above, when storing log data to be stored, the method includes:

[0096] Step S1001, in the current write sector, search for the space occupancy of the sub - units recorded in the sub - unit bitmap;

[0097] For example, this step is similar to step S503 above and will not be elaborated here.

[0098] Step S1002, when obtaining at least one unoccupied sub - unit, store the log data to be stored in any one of the at least one unoccupied sub - units, where in the current write sector, the identifier of the data recorded in the sub - unit identifier array and the data identifier information of the stored log data are sequence numbers representing the write order.

[0099] For example, when at least one unoccupied subunit is obtained, the log data to be stored can be directly stored in any subunit of the sector. To record the order of writing the log data, the identifier of the data recorded in the subunit identifier array in the sector allocated to the log data is a serial number, such as 1, 2... N, and the data identifier information of the log data is also the corresponding serial number to indicate the writing order of the log data.

[0100] When at least one unoccupied subunit is not obtained, it means that there is no space in the sector to write the log data. At this time, the log data to be stored can be stored in the next sector allocated to the log data that has at least one unoccupied subunit. Similarly, the identifier of the data recorded in the subunit identifier array and the data identifier information of the log data are both serial numbers indicating the writing order of the log data.

[0101] In addition, when none of the sectors allocated to the log data have at least one unoccupied subunit, it means that all sectors allocated to the log data have no space. Therefore, the subunit that stores the log data first in all sectors allocated to the log data can be erased, and the log data to be stored can be stored in the erased subunit to complete the update of the log data.

[0102] Figure 11 It is a flowchart of the data processing method of the serial flash memory provided by another embodiment of the present invention.

[0103] As Figure 11 shown, when the log data is to be read, the method further includes:

[0104] Step S1101, determining the sector of the subunit that stores the log data first in all sectors allocated to the log data as the current read sector;

[0105] For example, since log data generally has time information, the log data should also be read in the order of the time when the log data is generated. Therefore, first find the log data that is stored first among all log data from all sectors allocated to the log data, and take the sector of the subunit where it is stored as the current read sector to read first.

[0106] Step S1102, reading the log data stored in the current read sector in sequence according to the serial number recorded in the subunit identifier array in the current read sector;

[0107] For example, read the log data corresponding to the serial number recorded in the subunit identifier array in the current read sector in sequence. For example, it can start reading from serial number 1, and stop when there is no corresponding log data when the serial number increases to serial number M.

[0108] Step S1103, when the reading of the log data stored in the current read sector is completed, determine whether the next sector allocated to the log data is the current write sector;

[0109] For example, when the reading of the current read sector is completed, the next sector allocated to the log data can be continuously read until the next sector allocated to the log data is the current write sector.

[0110] Step S1104, when the next sector allocated to the log data is the current write sector, stop reading after completing the reading of the current write sector.

[0111] For example, when the next sector allocated to the log data is the current write sector, it indicates that basically all the written logs have been read, and only the current write sector needs to be read to complete all the log readings. When the next sector allocated to the log data is not the current write sector, then this sector becomes the current read sector, and step S1102 is continued.

[0112] Figure 12 is a structural block diagram of a data processing device for a serial flash memory provided by an embodiment of the present invention. As Figure 12 shown, based on the serial flash memory described above, when key-value pair data is to be stored, the device includes: a first search unit 121, a deletion unit 122, and a first storage unit 123. Among them, the first search unit 121 is used to search for the identifier of the data in the subunit identifier array according to the data identifier information of the key-value pair data to be stored among all the sectors allocated to the key-value pairs; the deletion unit 122 is used to delete the first data when obtaining the first data corresponding to the identifier of the data identifier information; the first search unit 121 is also used to search for the space occupancy of the subunits recorded in the subunit bitmap among all the sectors allocated to the key-value pairs; the first storage unit 123 is used to store the key-value pair data to be stored into any one of the at least one unoccupied subunit when obtaining at least one unoccupied subunit.

[0113] Figure 13 is a structural block diagram of a data processing device for a serial flash memory provided by another embodiment of the present invention. As Figure 13As shown, the device is based on the serial flash memory described above. When storing log data, the device includes: a second search unit 131 and a second storage unit 132. Among them, the second search unit 131 is used to search for the space occupancy of the sub-units recorded in the sub-unit bitmap in the current write sector; the second storage unit 132 is used to store the log data to be stored into any one of the at least one unoccupied sub-unit when at least one unoccupied sub-unit is obtained. Among them, in the current write sector, the identifier of the data recorded in the sub-unit identifier array and the data identifier information of the stored log data are sequence numbers representing the write order.

[0114] The data processing device of the serial flash memory includes a processor and a memory. The above first search unit 121, deletion unit 122, first storage unit 123, second search unit 131, and second storage unit 132 are all stored in the memory as program units, and the corresponding functions are implemented by the processor executing the above program units stored in the memory.

[0115] The processor contains a kernel, and the kernel retrieves the corresponding program units from the memory. One or more kernels can be set, and data processing is performed by adjusting the kernel parameters.

[0116] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of, for example, read-only memory (ROM) or flash memory (flash RAM), and the memory includes at least one memory chip.

[0117] An embodiment of the present invention provides a storage medium, on which a program is stored, and when the program is executed by a processor, the data processing method of the serial flash memory is implemented.

[0118] An embodiment of the present invention provides a processor, and the processor is used to run a program. Among them, when the program runs, the data processing method of the serial flash memory is executed.

[0119] An embodiment of the present invention provides a device, which includes a processor, a memory, and a program stored on the memory and executable on the processor. When the processor executes the program, the following steps are implemented:

[0120] A data processing method for a serial flash memory. Based on the serial flash memory described above, when storing key-value pair data to be stored, the method includes: in all sectors allocated to the key-value pairs, searching for the identifier of the data in the sub-unit identifier array according to the data identifier information of the key-value pair data to be stored; when obtaining the first data with the identifier corresponding to the data identifier information, deleting the first data; in all sectors allocated to the key-value pairs, searching for the space occupancy of the sub-units recorded in the sub-unit bitmap; when obtaining at least one unoccupied sub-unit, storing the key-value pair data to be stored into any one of the at least one unoccupied sub-units.

[0121] Preferably, when obtaining the first data with the identifier corresponding to the data identifier information, deleting the first data includes: when obtaining the first data with the identifier corresponding to the data identifier information, marking the first data as in a pre-deleted state; after storing the key-value pair data to be stored into any one of the at least one unoccupied sub-units, deleting the first data.

[0122] Preferably, when not obtaining at least one unoccupied sub-unit, the method includes: in all sectors allocated to the key-value pairs, searching for the sector with the fewest occupied sub-units as the recycled sector; writing the key-value pair data in the recycled sector to a spare sector; erasing the recycled sector; writing the key-value pair data in the spare sector back to the recycled sector; in the recycled sector, re-searching for the space occupancy of the sub-units recorded in the sub-unit bitmap.

[0123] Preferably, after writing the key-value pair data in the spare sector back to the recycled sector, setting the spare sector to an invalid state.

[0124] Preferably, when power failure occurs during the data storage process, the method further includes: deleting the key-value pair data that is not fully written in all sectors allocated to the key-value pairs; searching for the key-value pair data with the same identifier as the key-value pair data marked as in a pre-deleted state in all sectors allocated to the key-value pairs; when searching for the key-value pair data with the same identifier as the key-value pair data marked as in a pre-deleted state, deleting the key-value pair data marked as in a pre-deleted state; when not searching for the key-value pair data with the same identifier as the key-value pair data marked as in a pre-deleted state, re-writing the key-value pair data marked as in a pre-deleted state.

[0125] Preferably, when power failure occurs during the data storage process, the method further includes: searching for valid data in the spare sector; when searching for valid data in the spare sector, erasing the recycled sector; writing the key-value pair data in the spare sector back to the recycled sector; in the recycled sector, re-searching for the space occupancy of the sub-units recorded in the sub-unit bitmap.

[0126] A data processing method for a serial flash memory, which is based on the serial flash memory described above. When storing log data to be stored, the method includes: searching for the space occupancy of sub-units recorded in the sub-unit bitmap in the current write sector; when obtaining at least one unoccupied sub-unit, storing the log data to be stored into any one of the at least one unoccupied sub-units, wherein in the current write sector, the identifier of the data recorded in the sub-unit identifier array and the data identifier information of the stored log data are sequence numbers representing the write order.

[0127] Preferably, when not obtaining at least one unoccupied sub-unit, the method further includes: storing the log data to be stored into the next sector allocated to the log data that has at least one unoccupied sub-unit.

[0128] Preferably, the method further includes: when all sectors allocated to the log data have no at least one unoccupied sub-unit, erasing the sub-unit that stores the log data first among all sectors allocated to the log data, and storing the log data to be stored into the erased sub-unit.

[0129] Preferably, when reading the log data, the method further includes: determining the sector of the sub-unit that stores the log data first among all sectors allocated to the log data as the current read sector; sequentially reading the log data stored in the current read sector according to the sequence number recorded in the sub-unit identifier array in the current read sector; when the reading of the log data stored in the current read sector is completed, determining whether the next sector allocated to the log data is the current write sector; when the next sector allocated to the log data is the current write sector, stopping reading after completing the reading of the current write sector.

[0130] The device herein can be a server, a PC, a PAD, a mobile phone, etc.

[0131] The present application also provides a computer program product, which is suitable for executing a program initialized with the following method steps when executed on a data processing device:

[0132] A data processing method for a serial flash memory, which is based on the serial flash memory described above. When storing key-value pair data, the method includes: in all sectors allocated to the key-value pairs, searching for the identifier of the data in the subunit identifier array according to the data identifier information of the key-value pair data to be stored; when obtaining the first data with the identifier corresponding to the data identifier information, deleting the first data; in all sectors allocated to the key-value pairs, searching for the space occupancy of the subunits recorded in the subunit bitmap; when obtaining at least one unoccupied subunit, storing the key-value pair data to be stored into any one of the at least one unoccupied subunits.

[0133] Preferably, when obtaining the first data with the identifier corresponding to the data identifier information, deleting the first data includes: when obtaining the first data with the identifier corresponding to the data identifier information, marking the first data as in a pre-deleted state; after storing the key-value pair data to be stored into any one of the at least one unoccupied subunits, deleting the first data.

[0134] Preferably, when not obtaining at least one unoccupied subunit, the method includes: in all sectors allocated to the key-value pairs, searching for the sector with the fewest occupied subunits as the recycled sector; writing the key-value pair data in the recycled sector to a spare sector; erasing the recycled sector; writing the key-value pair data in the spare sector back to the recycled sector; in the recycled sector, re-searching for the space occupancy of the subunits recorded in the subunit bitmap.

[0135] Preferably, after writing the key-value pair data in the spare sector back to the recycled sector, setting the spare sector to an invalid state.

[0136] Preferably, when power failure occurs during the data storage process, the method further includes: deleting the key-value pair data that is not fully written in all sectors allocated to the key-value pairs; searching for the key-value pair data with the same identifier as the key-value pair data marked as in a pre-deleted state in all sectors allocated to the key-value pairs; when searching for the key-value pair data with the same identifier as the key-value pair data marked as in a pre-deleted state, deleting the key-value pair data marked as in a pre-deleted state; when not searching for the key-value pair data with the same identifier as the key-value pair data marked as in a pre-deleted state, re-writing the key-value pair data marked as in a pre-deleted state.

[0137] Preferably, when power failure occurs during the data storage process, the method further includes: searching for valid data in the spare sector; when searching for valid data in the spare sector, erasing the recycled sector; writing the key-value pair data in the spare sector back to the recycled sector; in the recycled sector, re-searching for the space occupancy of the subunits recorded in the subunit bitmap.

[0138] A data processing method for a serial flash memory. Based on the serial flash memory described above, when log data is to be stored, the method includes: searching for the space occupancy of the sub-units recorded in the sub-unit bitmap in the current write sector; when at least one unoccupied sub-unit is obtained, storing the log data to be stored into any one of the at least one unoccupied sub-units, wherein in the current write sector, the identifier of the data recorded in the sub-unit identifier array and the data identifier information of the stored log data are sequence numbers representing the write order.

[0139] Preferably, when at least one unoccupied sub-unit is not obtained, the method further includes: storing the log data to be stored into the next sector allocated to the log data that has at least one unoccupied sub-unit.

[0140] Preferably, the method further includes: when none of the sectors allocated to the log data has at least one unoccupied sub-unit, erasing the sub-unit that stores the log data first among all the sub-units in all the sectors allocated to the log data, and storing the log data to be stored into the erased sub-unit.

[0141] Preferably, when the log data is to be read, the method further includes: determining the sector of the sub-unit that stores the log data first among all the sectors allocated to the log data as the current read sector; sequentially reading the log data stored in the current read sector according to the sequence number recorded in the sub-unit identifier array in the current read sector; when the reading of the log data stored in the current read sector is completed, determining whether the next sector allocated to the log data is the current write sector; when the next sector allocated to the log data is the current write sector, stopping reading after completing the reading of the current write sector.

[0142] Those skilled in the art should understand that the embodiments of the present application can be provided as a method, a system, or a computer program product. Therefore, the present application can take the form of a complete hardware embodiment, a complete 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-ROM, optical storage, etc.) that contain computer-usable program code.

[0143] This application is described with reference to the flowcharts and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the present application. It should be understood that each flow and / or block in the flowchart and / or block diagram can be implemented by computer program instructions, and the combination of the flows and / or blocks in the flowchart and / or block diagram can also be implemented. These computer program instructions can be provided to the processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing devices to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing devices generate means for implementing the functions specified in one or more of the flows Figure 1 one or more of the flows and / or blocks Figure 1 or means for implementing the functions specified in one or more of the blocks.

[0144] These computer program instructions can also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer-readable memory generate a manufactured article including instruction means, and the instruction means implement the functions specified in one or more of the flows Figure 1 one or more of the flows and / or blocks Figure 1 or means for implementing the functions specified in one or more of the blocks.

[0145] These computer program instructions can also be loaded onto a computer or other programmable data processing device, so that a series of operation steps are executed on the computer or other programmable device to generate a computer-implemented process, and thus the instructions executed on the computer or other programmable device provide steps for implementing the functions specified in one or more of the flows Figure 1 one or more of the flows and / or blocks Figure 1 or means for implementing the functions specified in one or more of the blocks.

[0146] In a typical configuration, a computing device includes one or more processors (CPUs), an input / output interface, a network interface, and a memory.

[0147] The memory may include non-permanent memory in the form of computer-readable media, random access memory (RAM), and / or non-volatile memory, such as read-only memory (ROM) or flash memory (flash RAM). The memory is an example of computer-readable media.

[0148] A computer-readable medium includes both permanent and non-permanent, removable and non-removable media and can implement information storage by any method or technology. The information can be 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 technologies, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices, or any other non-transitory medium that can be used to store information that can be accessed by a computing device. As defined herein, a computer-readable medium does not include transitory computer-readable media such as modulated data signals and carrier waves.

[0149] It should also be noted that the term "comprising", "including" or any other variant thereof is intended to cover non-exclusive inclusion, such that a process, method, article or apparatus comprising a series of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article or apparatus. Without further limitation, an element defined by the statement "comprising an..." does not exclude the presence of additional identical elements in the process, method, article or apparatus comprising the element.

[0150] The above are only embodiments of the present application and are not used to limit the present application. For those skilled in the art, various changes and modifications can be made to the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included within the scope of the claims of the present application.

Claims

1. A data processing method for a serial flash memory, characterized in that, the method is based on a serial flash memory, the serial flash memory includes a plurality of sectors, and each sector includes: a plurality of sub-units for storing data, a sub-unit bitmap, and a sub-unit identification array. The sub-unit bitmap records the space occupancy of the plurality of sub-units, and the sub-unit identification array records the identification of the data stored in each of the plurality of sub-units. When storing key-value pair data to be stored, the method includes: In all sectors allocated to the key-value pair, search for the identification of the data in the sub-unit identification array according to the data identification information of the key-value pair data to be stored; When obtaining the first data with the identification corresponding to the data identification information, delete the first data; In all sectors allocated to the key-value pair, search for the space occupancy of the sub-units recorded in the sub-unit bitmap; When obtaining at least one unoccupied sub-unit, store the key-value pair data to be stored into any one of the at least one unoccupied sub-units; wherein, the sector for writing the key-value pair data to be stored is different from the sector where the first data with the identification corresponding to its data identification information is located.

2. The data processing method for a serial flash memory according to claim 1, characterized in that, the step of deleting the first data when obtaining the first data with the identification corresponding to the data identification information includes: When obtaining the first data with the identification corresponding to the data identification information, mark the first data as a pre-deleted state; After storing the key-value pair data to be stored into any one of the at least one unoccupied sub-units, delete the first data.

3. The data processing method for a serial flash memory according to claim 1, characterized in that, When not obtaining at least one unoccupied sub-unit, the method includes: In all sectors allocated to the key-value pair, search for the sector with the fewest occupied sub-units as the recycling sector; Write the key-value pair data in the recycling sector to a spare sector; Erase the recycling sector; Write the key-value pair data in the spare sector back to the recycling sector; In the recycling sector, re-search for the space occupancy of the sub-units recorded in the sub-unit bitmap.

4. The data processing method for a serial flash memory according to claim 3, characterized in that, After writing the key-value pair data in the spare sector back to the recycling sector, set the spare sector to an invalid state.

5. The data processing method for a serial flash memory according to claim 2, characterized in that, When power failure occurs during the data storage process, the method further includes: Delete the key-value pair data that is not fully written in all sectors allocated to the key-value pair; Search for the key-value pair data with the same identification as the key-value pair data marked as pre-deleted in all sectors allocated to the key-value pair; When searching for the key-value pair data with the same identification as the key-value pair data marked as pre-deleted, delete the key-value pair data marked as pre-deleted. When no key-value pair data with the same identifier as the identifier of the key-value pair data marked as pre-deleted is searched, rewrite the key-value pair data marked as pre-deleted.

6. The data processing method of a serial flash memory according to claim 3, wherein, when power failure occurs during data storage, the method further includes: searching for valid data in the spare sector; when valid data is searched in the spare sector, erasing the recycle sector; writing the key-value pair data in the spare sector back to the recycle sector; in the recycle sector, re-searching the space occupancy of the sub-units recorded by the sub-unit bitmap.

7. A data processing device for a serial flash memory, wherein, the device is based on a serial flash memory, the serial flash memory includes a plurality of sectors, each sector includes: a plurality of sub-units, the plurality of sub-units are used to store data, a sub-unit bitmap, and a sub-unit identifier array, the sub-unit bitmap records the space occupancy of the plurality of sub-units, the sub-unit identifier array records the identifier of the data stored in each of the plurality of sub-units, when key-value pair data is to be stored, the device includes: a first search unit, a deletion unit, and a first storage unit, wherein, the first search unit is configured to search for the identifier of the data in the sub-unit identifier array according to the data identifier information of the key-value pair data to be stored in all sectors allocated to the key-value pair; the deletion unit is configured to delete the first data when obtaining the first data with the identifier corresponding to the data identifier information; the first search unit is further configured to search for the space occupancy of the sub-units recorded by the sub-unit bitmap in all sectors allocated to the key-value pair; the first storage unit is configured to store the key-value pair data to be stored in any one of the at least one unoccupied sub-unit when obtaining the at least one unoccupied sub-unit; wherein, the sector for writing the key-value pair data to be stored is different from the sector where the first data with the identifier corresponding to its data identifier information is located.

8. A machine-readable storage medium, wherein, instructions are stored on the machine-readable storage medium, and the instructions are used to cause the machine to execute the method described in any one of claims 1-6 of the present application.

Citation Information

Patent Citations

  • Method for storing station name of security receiving chip

    CN101184155A

  • Quick read-write method and device for flash memory

    CN102073592A

  • Embedded file system based on norflash

    CN107908364A

  • Storage management method and device, single-chip microcomputer equipment and readable storage medium

    CN109918024A

  • Data processing method and terminal equipment

    CN110209349A