CN112558868A - Method, device and equipment for storing configuration data - Google Patents

Method, device and equipment for storing configuration data Download PDF

Info

Publication number
CN112558868A
CN112558868A CN202011436860.1A CN202011436860A CN112558868A CN 112558868 A CN112558868 A CN 112558868A CN 202011436860 A CN202011436860 A CN 202011436860A CN 112558868 A CN112558868 A CN 112558868A
Authority
CN
China
Prior art keywords
subspace
data
configuration item
configuration
item data
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202011436860.1A
Other languages
Chinese (zh)
Other versions
CN112558868B (en
Inventor
刘炜
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Actions Technology Co Ltd
Original Assignee
Actions Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Actions Technology Co Ltd filed Critical Actions Technology Co Ltd
Priority to CN202011436860.1A priority Critical patent/CN112558868B/en
Publication of CN112558868A publication Critical patent/CN112558868A/en
Application granted granted Critical
Publication of CN112558868B publication Critical patent/CN112558868B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F3/00Input arrangements for transferring data to be processed into a form capable of being handled by the computer; Output arrangements for transferring data from processing unit to output unit, e.g. interface arrangements
    • G06F3/06Digital input from, or digital output to, record carriers, e.g. RAID, emulated record carriers or networked record carriers
    • G06F3/0601Interfaces specially adapted for storage systems
    • G06F3/0602Interfaces specially adapted for storage systems specifically adapted to achieve a particular effect
    • G06F3/0604Improving or facilitating administration, e.g. storage management
    • G06F3/0607Improving or facilitating administration, e.g. storage management by facilitating the process of upgrading existing storage systems, e.g. for improving compatibility between host and storage device
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/08Error detection or correction by redundancy in data representation, e.g. by using checking codes
    • G06F11/10Adding special bits or symbols to the coded information, e.g. parity check, casting out 9's or 11's
    • G06F11/1004Adding special bits or symbols to the coded information, e.g. parity check, casting out 9's or 11's to protect a block of data words, e.g. CRC or checksum
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F3/00Input arrangements for transferring data to be processed into a form capable of being handled by the computer; Output arrangements for transferring data from processing unit to output unit, e.g. interface arrangements
    • G06F3/06Digital input from, or digital output to, record carriers, e.g. RAID, emulated record carriers or networked record carriers
    • G06F3/0601Interfaces specially adapted for storage systems
    • G06F3/0628Interfaces specially adapted for storage systems making use of a particular technique
    • G06F3/0646Horizontal data movement in storage systems, i.e. moving data in between storage devices or systems
    • G06F3/0652Erasing, e.g. deleting, data cleaning, moving of data to a wastebasket
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F3/00Input arrangements for transferring data to be processed into a form capable of being handled by the computer; Output arrangements for transferring data from processing unit to output unit, e.g. interface arrangements
    • G06F3/06Digital input from, or digital output to, record carriers, e.g. RAID, emulated record carriers or networked record carriers
    • G06F3/0601Interfaces specially adapted for storage systems
    • G06F3/0668Interfaces specially adapted for storage systems adopting a particular infrastructure
    • G06F3/0671In-line storage system
    • G06F3/0673Single storage device
    • G06F3/0679Non-volatile semiconductor memory device, e.g. flash memory, one time programmable memory [OTP]

Abstract

The invention provides a method, a device and equipment for storing configuration data, wherein the method comprises the following steps: acquiring configuration item data to be stored, and determining the expected occupied space of the configuration item data; in a plurality of subspaces obtained by dividing the configuration storage space, if the free space of a first subspace for storing the configuration item data last time is larger than the expected occupied space, determining the first subspace as a target subspace; otherwise, when determining that the next subspace exists and is not occupied, copying the effective data in the first subspace to the next subspace, and updating the next subspace to be the target subspace; when determining that the next subspace does not exist or is occupied, erasing the subspace where the configuration item data is stored firstly, copying effective data in the first subspace to the erased subspace, and updating the subspace to be a target subspace; and sequentially storing the configuration item data to the target subspace. The method of the invention can reduce the erasing times when the NOR Flash stores data and improve the performance.

Description

Method, device and equipment for storing configuration data
Technical Field
The present invention relates to the field of data storage technologies, and in particular, to a method, an apparatus, and a device for configuring data storage.
Background
NOR and NAND are the two major non-volatile flash technologies on the market today. NOR is characterized in that an application program can directly run in a NOR Flash chip without reading codes into a system RAM (Random Access Memory); and the transmission efficiency of the NOR FLASH is very high, and the NOR FLASH has very high cost benefit when the small-capacity transmission of 1-4 MB is carried out. In addition, the NOR FLASH chip has the advantages of high reliability, small volume, high density, erasability, rewritability and the like, and thus is widely applied to embedded systems.
The NOR Flash chip comprises a configuration storage space, and the operation of the embedded system on the configuration storage space mainly comprises reading configuration data, storing configuration data, erasing configuration data and the like. In the current scheme for storing configuration data, NOR Flash is usually written in units of bytes and erased in units of blocks, and before writing, an erase operation must be performed. When the NOR Flash is erased, the embedded system cannot read and execute data on the NOR Flash, and the erasing time of the NOR Flash is generally tens of milliseconds, which seriously affects the performance of the embedded system, especially the real-time performance of the embedded system.
Disclosure of Invention
The invention provides a method, a device and equipment for storing configuration data, which solve the problem that the performance of an embedded system is influenced by frequently erasing data when NOR Flash stores the configuration data.
In a first aspect, the present invention provides a method of configuring a data store, the method comprising:
acquiring configuration item data to be stored, and determining the expected occupied space of the configuration item data;
in a plurality of subspaces obtained by dividing a configuration storage space, if the free space of a first subspace for storing configuration item data last time is larger than the expected occupied space, determining that the first subspace is a target subspace;
otherwise, when determining that the next subspace exists and is not occupied, copying the effective data in the first subspace to the next subspace, and updating the next subspace to be the target subspace;
when determining that the next subspace does not exist or is occupied, erasing the subspace where the configuration item data is stored firstly, copying effective data in the first subspace to the erased subspace, and updating the subspace to be a target subspace;
and sequentially storing the configuration item data to the target subspace.
Optionally, the configuration storage space is divided into two subspaces.
Optionally, any subspace of the plurality of subspaces includes a plurality of spatial blocks having a size of a preset granularity.
Optionally, sequentially storing the configuration item data to the target subspace, including:
sequentially searching for free space blocks in the target subspace according to the number of space blocks occupied by the configuration item data;
and taking the searched free space block as an initial position for storing the configuration item data, and sequentially storing the configuration item data.
Optionally, copying the valid data in the first subspace to the next subspace/erased subspace includes:
determining the latest stored configuration item data in the configuration item data belonging to the same configuration item in the configuration item data stored in the first subspace as valid data;
copying valid data in the first subspace to the next subspace/erased subspace.
Optionally, sequentially storing the configuration item data to the target subspace, including:
sequentially storing the configuration item data into the target subspace, and setting the value of the state bit of the configuration item data as a first state bit value;
and updating the value of the state bit of the configuration item data which belongs to the same configuration item with the latest stored configuration item data into a second state bit value in the configuration item data stored in the target subspace.
Optionally, the method further comprises:
updating a search bitmap of a Random Access Memory (RAM) when the data change of the configuration item exists in the target subspace;
the search bitmap includes bits corresponding to the space blocks in the target subspace, one to one, each bit identifying a data storage state of the corresponding space block.
Optionally, for a plurality of space blocks in the target subspace, the starting space block occupied by the latest configuration item data of the same configuration item is identified by using the first bit value, and the other space blocks are identified by using the second bit value.
Optionally, the configuration item data includes header data and configuration parameters, and the configuration parameters include configuration item identifiers and configuration data, and further includes:
receiving a configuration parameter reading instruction, and determining a first hash value and a first configuration item identifier related to the configuration parameter;
determining an initial space block identified by a first bit value according to the search bitmap;
acquiring head data in configuration item data in the starting space block, and respectively and correspondingly matching the first hash value and the first configuration item identifier with a second hash value and a second configuration item identifier in the head data;
and determining an initial space block where the configuration parameters to be read are located according to the matching result, and reading the configuration parameters from the initial space block.
Optionally, after reading the configuration parameters, the method further includes:
calculating a second Cyclic Redundancy Check (CRC) of the read configuration parameters, and comparing the second CRC with the first CRC in the header data;
and if the second cyclic redundancy check bit CRC is inconsistent with the first cyclic redundancy check bit CRC, returning error information.
In a second aspect, the present invention provides an apparatus for configuring data storage, comprising a memory and a processor, wherein:
the memory is used for storing a computer program;
the processor is used for reading the program in the memory and executing the following steps:
acquiring configuration item data to be stored, and determining the expected occupied space of the configuration item data;
in a plurality of subspaces obtained by dividing a configuration storage space, if the free space of a first subspace for storing configuration item data last time is larger than the expected occupied space, determining that the first subspace is a target subspace;
otherwise, when determining that the next subspace exists and is not occupied, copying the effective data in the first subspace to the next subspace, and updating the next subspace to be the target subspace;
when determining that the next subspace does not exist or is occupied, erasing the subspace where the configuration item data is stored firstly, copying effective data in the first subspace to the erased subspace, and updating the subspace to be a target subspace;
and sequentially storing the configuration item data to the target subspace.
Optionally, the configuration storage space is divided into two subspaces.
Optionally, any subspace of the plurality of subspaces includes a plurality of spatial blocks having a size of a preset granularity.
Optionally, the processor sequentially stores the configuration item data to the target subspace, including:
sequentially searching for free space blocks in the target subspace according to the number of space blocks occupied by the configuration item data;
and taking the searched free space block as an initial position for storing the configuration item data, and sequentially storing the configuration item data.
Optionally, the copying, by the processor, valid data in the first subspace to the next subspace/erased subspace includes:
determining the latest stored configuration item data in the configuration item data belonging to the same configuration item in the configuration item data stored in the first subspace as valid data;
copying valid data in the first subspace to the next subspace/erased subspace.
Optionally, the processor sequentially stores the configuration item data to the target subspace, including:
sequentially storing the configuration item data into the target subspace, and setting the value of the state bit of the configuration item data as a first state bit value;
and updating the value of the state bit of the configuration item data which belongs to the same configuration item with the latest stored configuration item data into a second state bit value in the configuration item data stored in the target subspace.
Optionally, the processor is further configured to:
updating a search bitmap of a Random Access Memory (RAM) when the data change of the configuration item exists in the target subspace;
the search bitmap includes bits corresponding to the space blocks in the target subspace, one to one, each bit identifying a data storage state of the corresponding space block.
Optionally, for a plurality of space blocks in the target subspace, the starting space block occupied by the latest configuration item data of the same configuration item is identified by using the first bit value, and the other space blocks are identified by using the second bit value.
Optionally, the configuration item data includes header data and configuration parameters, the configuration parameters include configuration item identification and configuration data, and the processor is further configured to:
receiving a configuration parameter reading instruction, and determining a first hash value and a first configuration item identifier related to the configuration parameter;
determining an initial space block identified by a first bit value according to the search bitmap;
acquiring head data in configuration item data in the starting space block, and respectively and correspondingly matching the first hash value and the first configuration item identifier with a second hash value and a second configuration item identifier in the head data;
and determining an initial space block where the configuration parameters to be read are located according to the matching result, and reading the configuration parameters from the initial space block.
Optionally, after reading the configuration parameters, the processor is further configured to:
calculating a second Cyclic Redundancy Check (CRC) of the read configuration parameters, and comparing the second CRC with the first CRC in the header data;
and if the second cyclic redundancy check bit CRC is inconsistent with the first cyclic redundancy check bit CRC, returning error information.
In a third aspect, the present invention provides an apparatus for configuring data storage, comprising:
the data acquisition unit is used for acquiring the configuration item data to be stored and determining the expected occupied space of the configuration item data;
a first space determining unit, configured to determine, in a plurality of subspaces obtained by dividing a configuration storage space, that a first subspace storing configuration item data last time is a target subspace if an idle space of the first subspace is larger than the expected occupied space;
a second space determining unit, configured to copy valid data in the first subspace to a next subspace and update the next subspace to a target subspace if it is determined that the next subspace exists and is not occupied;
a third space determining unit, configured to determine that there is no next subspace or when the next subspace is occupied, erase a subspace in which configuration item data is first stored, copy valid data in the first subspace to the erased subspace, and update the subspace to a target subspace;
and the storage unit is used for sequentially storing the configuration item data to the target subspace.
Optionally, the configuration storage space is divided into two subspaces.
Optionally, any subspace of the plurality of subspaces includes a plurality of spatial blocks having a size of a preset granularity.
Optionally, the sequentially storing the configuration item data to the target subspace by the storage unit includes:
sequentially searching for free space blocks in the target subspace according to the number of space blocks occupied by the configuration item data;
and taking the searched free space block as an initial position for storing the configuration item data, and sequentially storing the configuration item data.
Optionally, the copying, by the second space determining unit, valid data in the first subspace to the next subspace includes:
determining the latest stored configuration item data in the configuration item data belonging to the same configuration item in the configuration item data stored in the first subspace as valid data;
copying valid data in the first subspace to the next subspace.
Optionally, the copying, by the third space determining unit, valid data in the first subspace to the erased subspace includes:
determining the latest stored configuration item data in the configuration item data belonging to the same configuration item in the configuration item data stored in the first subspace as valid data;
and copying the effective data in the first subspace to the erased subspace.
Optionally, the sequentially storing the configuration item data to the target subspace by the storage unit includes:
sequentially storing the configuration item data into the target subspace, and setting the value of the state bit of the configuration item data as a first state bit value;
and updating the value of the state bit of the configuration item data which belongs to the same configuration item with the latest stored configuration item data into a second state bit value in the configuration item data stored in the target subspace.
Optionally, the storage unit is further configured to:
updating a search bitmap of a Random Access Memory (RAM) when the data change of the configuration item exists in the target subspace;
the search bitmap includes bits corresponding to the space blocks in the target subspace, one to one, each bit identifying a data storage state of the corresponding space block.
Optionally, for a plurality of space blocks in the target subspace, the starting space block occupied by the latest configuration item data of the same configuration item is identified by using the first bit value, and the other space blocks are identified by using the second bit value.
Optionally, the configuration item data includes header data and configuration parameters, the configuration parameters include configuration item identifiers and configuration data, and the storage unit is further configured to:
receiving a configuration parameter reading instruction, and determining a first hash value and a first configuration item identifier related to the configuration parameter;
determining an initial space block identified by a first bit value according to the search bitmap;
acquiring head data in configuration item data in the starting space block, and respectively and correspondingly matching the first hash value and the first configuration item identifier with a second hash value and a second configuration item identifier in the head data;
and determining an initial space block where the configuration parameters to be read are located according to the matching result, and reading the configuration parameters from the initial space block.
Optionally, after reading the configuration parameter, the storage unit is further configured to:
calculating a second Cyclic Redundancy Check (CRC) of the read configuration parameters, and comparing the second CRC with the first CRC in the header data;
and if the second cyclic redundancy check bit CRC is inconsistent with the first cyclic redundancy check bit CRC, returning error information.
In a fourth aspect, the present invention provides a computer program medium having a computer program stored thereon, which when executed by a processor, performs the steps of a method of configuring a data store as provided in the first aspect above.
The method, the device and the equipment for storing the configuration data have the following beneficial effects that:
the storage of the configuration item data on the Nor Flash is realized, the erasing operation when the configuration item data is written is reduced, the influence of the erasing operation on the system performance is reduced, and the performance of the embedded system is improved.
Drawings
FIG. 1 is a flow chart of a method for configuring a data store according to an embodiment of the present invention;
FIG. 2 is a diagram illustrating configuration item data according to an embodiment of the present invention;
fig. 3 is a schematic diagram illustrating partitioning of a configuration space according to an embodiment of the present invention;
fig. 4 is a schematic diagram of a corresponding relationship between a search bitmap and a space block according to an embodiment of the present invention;
FIG. 5 is a flowchart illustrating a method for dividing a configuration storage space into two subspaces for storing configuration data according to an embodiment of the present invention;
fig. 6 is a flowchart of reading configuration parameters according to an embodiment of the present invention;
FIG. 7 is a diagram illustrating an apparatus for configuring data storage according to an embodiment of the present invention;
fig. 8 is a schematic diagram of an apparatus for configuring data storage according to an embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
It should be noted that the embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present invention. Rather, they are merely examples of apparatus and methods consistent with certain aspects of the present disclosure, as detailed in the appended claims.
Hereinafter, some terms in the embodiments of the present disclosure are explained to facilitate understanding by those skilled in the art.
(1) The term "NOR Flash" in the embodiments of the present disclosure is a non-volatile Flash technology that can erase and reprogram blocks of memory cells called blocks.
(2) In the embodiment of the present disclosure, the term "Random Access Memory" (RAM), also called main Memory, is an internal Memory that directly exchanges data with the central processing unit. Can be read and written at any time, is fast, and is usually used as a temporary data storage medium for an operating system or other programs in operation, for temporarily storing programs, data and intermediate results in computers and digital systems.
In order to make the objects, technical solutions and advantages of the present invention clearer, the present invention will be described in further detail with reference to the accompanying drawings, and it is apparent that the described embodiments are only a part of the embodiments of the present disclosure, not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present disclosure.
NOR and NAND are the two major non-volatile flash technologies on the market today.
NOR is characterized in that an application program can directly run in a NOR Flash chip without reading codes into a system RAM (Random Access Memory); and the transmission efficiency of the NOR FLASH is very high, and the NOR FLASH has very high cost benefit when the small-capacity transmission of 1-4 MB is carried out. In addition, the NOR FLASH chip has the advantages of high reliability, small volume, high density, erasability, rewritability and the like, and thus is widely applied to embedded systems.
The NOR Flash chip comprises a configuration storage space, and the operation of the embedded system on the configuration storage space mainly comprises reading configuration data, storing configuration data, erasing configuration data and the like.
The embedded system has the following requirements for storing configuration data:
(1) reliability: the configuration data cannot be lost and wrong configuration data cannot be read when power failure occurs accidentally;
(2) performance: the reading and writing speed is as fast as possible;
(3) resource overhead: the code is as simple as possible by using as little RAM as possible.
In the current scheme for storing configuration data, NOR Flash is usually written in units of bytes and erased in units of blocks, and before writing, an erase operation must be performed.
The characteristic of NOR Flash causes that data on NOR Flash cannot be read when NOR Flash is erased, and the erasing time of NOR Flash is generally tens of milliseconds, which affects the performance of an embedded system.
In addition, if power is unexpectedly lost after the NOR Flash performs an erase operation, the configuration item data may be lost.
In view of the foregoing problems, embodiments of the present application provide a method, an apparatus, and a device for configuring data storage, which optimize a process of configuring data storage by dividing a configuration storage space into a plurality of subspaces, thereby reducing erasing operations and improving performance.
Embodiments of a method, an apparatus, and a device for configuring data storage according to embodiments of the present invention are described below.
Example 1
An embodiment of the present invention provides a flowchart of a method for configuring data storage, as shown in fig. 1, including:
step S101, obtaining configuration item data to be stored, and determining the expected occupied space of the configuration item data;
the configuration item data is obtained by packaging configuration data to be stored into a preset format, and header data used for operations such as verification, auxiliary storage and the like is added to the configuration data during packaging.
The configuration item data obtained after encapsulation comprises header data and configuration parameters, wherein the configuration parameters comprise configuration item identifiers and configuration data, and the configuration item identifiers are used for identifying names of the configuration data.
The header data includes, but is not limited to, a HASH value HASH and a cyclic redundancy check bit CRC.
As shown in fig. 2, an embodiment of the present invention provides a schematic diagram of configuration item data, where the configuration item data includes:
head check position Magic: the size is 8 bits, and the initial check bit of the configuration item data is used for indicating whether the configuration item data is complete or not;
state: the size is 8 bits, and is used for indicating whether the configuration item data is valid data, wherein the status bit includes two values: the first state bit value and the second state bit value can be distinguished by using 0, 1 or 1, 0 or any different values.
The first status bit value is used to indicate that the configuration item data is valid data, the second status bit value is used to indicate that the configuration item data is invalid data, and the valid data is the latest stored configuration item data in the configuration item data belonging to the same configuration item.
And taking the value from the first state bit to the second state bit, and marking the state of the configuration item data to be changed from valid data to invalid data.
It should be noted that the first state bit value may be changed to the second state bit value, but the second state bit value cannot be changed to the first state bit value, that is, the configuration item data set as invalid data is not reset as valid data.
As an optional implementation manner, the first state bit takes a value of 1, and the second state bit takes a value of 0.
Hash value Hash: the size is 8 bits, the size of the configuration item identifier is reduced, and preliminary comparison is carried out when the configuration item data is read.
Cyclic Redundancy Check (CRC): the size is 8 bits and is used for checking whether the configuration item data has errors in the storage process.
The configuration item identifies the Size Name Size: the size is 5 bits and is used for representing the size of the configuration item identifier;
configuration Data Size: the size is 11 bits and is used for representing the size of the configuration data;
the configuration item identifies Name: the size is 1 to 31 bytes, and the complete configuration item identifier is used for distinguishing configuration item data;
configuration Data n: the size is 0 to 2047 bytes, and specific data in the configuration item data is configured;
alignment check bit Pad Data: the size is 0 to 31 bytes, and the data of the configuration items are aligned according to the principle that the length is aligned according to the fixed size.
It should be noted that the specific form of the configuration item data and the content and size of each configuration item are only given as an example of one configuration item data in the embodiment of the present invention, and do not limit the form of the configuration item data in the embodiment of the present invention at all, and any format of the configuration item data that can implement the configuration data storage method in the embodiment of the present invention may be applied to the embodiment of the present invention, and those skilled in the art may perform other forms of configuration item data encapsulation.
The expected occupied space is a space occupied in the configuration storage space calculated according to the configuration item data, and can be realized by the existing calculation method, which is not described herein again.
Step S102, judging whether the free space of a first subspace for storing configuration item data last time is larger than the expected occupied space in a plurality of subspaces obtained by dividing the configuration storage space, if so, executing step S103, otherwise, executing step S104;
it should be noted that the terms, such as the first in the first subspace, and the first, the second, and the fourth, related in the embodiments of the present invention are only used as conceptual differences, and no limitation on superiority or inferiority is generated, which is not described in detail later.
As shown in fig. 3, an embodiment of the present invention provides a schematic diagram for dividing a configuration space.
Fig. 3 specifically provides two schematic diagrams of configuration space division, which are from left to right:
(1) a schematic diagram of the configuration storage space, namely an undivided original configuration storage space;
(2) dividing the configuration storage space into two subspaces including a first subspace and a second subspace;
(3) dividing a configuration storage space into a first subspace, a second subspace and a third subspace;
the division of the total three subspaces is illustrated.
The three subspaces are used as specific examples of the plurality of subspaces, and other number of schemes are not described in detail, and in specific implementation, the specific division number may be determined according to specific implementation conditions.
It should be noted that the size of any subspace obtained by dividing the configuration storage space must be a multiple of the minimum erase unit of NOR Flash.
It should be noted that, when the configuration storage space is divided, the subspace may be divided into a plurality of subspaces with equal size, or the subspace may be divided into a plurality of subspaces with different sizes according to a specific implementation situation, which is not limited in the embodiment of the present invention.
Step S103, determining the first subspace as a target subspace, and executing step S107;
when performing configuration data storage, there are two cases:
in the first case, configuration item data is stored for the first time in all unoccupied free subspaces;
for the first case, the first subspace storing the configuration item data last time is not searched, and the first free subspace is updated to be the target subspace.
Case two, storing configuration item data for non-first time;
for the second case, if configuration data storage has been performed at least once before, it is first determined whether a free space of a first subspace where configuration item data is stored most recently is larger than the expected occupied space, if so, it is determined that the first subspace is a target subspace, and if not, the following steps are performed.
Step S104, determining that the next subspace exists and is not occupied, if so, executing step S105, otherwise, executing step S106;
when the free space of the first subspace for storing the configuration item data last time is not larger than the expected occupied space, that is, the free space in the first subspace is not enough to store the data to be stored, it is necessary to determine whether a next subspace exists, and whether the next subspace is unoccupied, and store the data to be stored in the unoccupied next subspace.
If there is no next subspace or the next subspace is occupied, step S106 is executed to perform an erase operation.
Step S105, copying the valid data in the first subspace to the next subspace, updating the next subspace to a target subspace, and executing step S107;
as an optional implementation manner, before copying the valid data in the first subspace to the next subspace, in the configuration item data stored in the first subspace, it is determined that, of the configuration item data belonging to the same configuration item, the latest stored configuration item data is valid data.
It should be noted that the above configuration item data belonging to the same configuration item refers to configuration item data with the same configuration item data identifier, and will not be described again hereinafter.
In the embodiment of the present invention, whether the configuration data is valid is identified by a value of a status bit in the configuration item data, where the valid data is the configuration item data whose value of the status bit is a value of a first status bit, for example, the value of the status bit is 1.
The determination of valid data may also be implemented in other manners, for example, labeling the storage order of the configuration item data in the same subspace, screening the configuration item data belonging to the same configuration item when determining valid data, and using the configuration item data with the storage order that is the latest as valid data.
The valid data can distinguish new data from old data in the configuration item data of the same configuration item, and only the valid data, namely the configuration item data which is newly stored in the configuration item data of the same configuration item, is copied when data copying is carried out, so that the storage space can be saved;
the effective data in the configuration item data is copied, so that the latest data can be stored in the configuration storage space forever, and the data loss caused by unexpected power failure is avoided.
Step S106, erasing the subspace where the configuration item data is firstly stored, copying the effective data in the first subspace to the erased subspace, updating the subspace to be a target subspace, and then executing step S107;
as an optional implementation manner, before copying the valid data in the first subspace to the erased subspace, in the configuration item data stored in the first subspace, it is determined that the latest stored configuration item data in the configuration item data belonging to the same configuration item is valid data.
In the embodiment of the present invention, whether the configuration data is valid is identified by a value of a status bit in the configuration item data, where the valid data is the configuration item data whose value of the status bit is a value of a first status bit, for example, the value of the status bit is 1.
The determination of valid data may also be implemented in other manners, for example, labeling the storage order of the configuration item data in the same subspace, screening the configuration item data belonging to the same configuration item when determining valid data, and using the configuration item data with the storage order that is the latest as valid data.
It should be noted that, after the valid data in the first subspace is copied to the next subspace in the step S105 or the valid data in the first subspace is copied to the erased subspace in the step S106, the free space in any free subspace or erased subspace in which the valid data is copied is still not greater than the expected occupied space, an error message is returned, and the configuration item data is not stored.
The scheme of the embodiment of the invention only erases the subspace storing the configuration item data firstly when the free space of the first subspace storing the configuration item data last time is not more than the expected occupation space and the next subspace is occupied, and the invalid subspaces can be erased uniformly in advance when the system is started at present, so that the execution times of the erasing operation during the storage of the configuration item data is greatly reduced.
And S107, sequentially storing the configuration item data into the target subspace.
The term "sequentially storing" means that after the configuration item data is stored in the last configuration item data stored in the target subspace, no storage space is left between the two configuration item data.
In the embodiment of the present invention, whether configuration item data is valid is identified by taking a value of a status bit in the configuration item data, and as an optional implementation manner, the configuration item data is sequentially stored in the target subspace, and the status bit is further updated, specifically including:
sequentially storing the configuration item data into the target subspace, and setting the value of the state bit of the configuration item data as a first state bit value;
and updating the value of the state bit of the configuration item data which belongs to the same configuration item with the latest stored configuration item data into a second state bit value in the configuration item data stored in the target subspace.
It should be noted that the status bit is used to indicate whether the configuration item data is valid data, where a first status bit value indicates that the configuration item data is valid data, and a second status bit value indicates that the configuration item data is invalid data.
In the above steps S105 and S106, when copying valid data, reading the value of the status bit, and if the value is the first status bit, the configuration item data is valid data; if the configuration item data is the second state bit value, the configuration item data is the invalid data, and the valid data and the invalid data can be rapidly distinguished through the value of the state bit.
In step S107, after the configuration item data is sequentially stored in the target subspace, the value of the status bit of the configuration item data stored in the target subspace is updated.
For example, the target subspace has 10 configuration item data, configuration item data 1 to configuration item data 10, and at this time, after the configuration item data 11 is sequentially stored in the target subspace, the configuration item data 8 in the 10 configuration item data belongs to the same configuration item as the configuration item data 11, and the value of the status bit of the configuration item data 8 is updated to the second status bit.
Thus, when the target subspace is filled and a copy operation is performed, the invalid data represented by the configuration item data 8 is not copied.
When the configuration item data is stored, the value of the status bit of the configuration item data is updated, so that the copying of effective data is realized in an auxiliary manner, and meanwhile, the reading of wrong data is avoided when the data is read.
Through the description of the above embodiment, the configuration storage space is divided into a plurality of subspaces, and new configuration data is sequentially written into the free space of the first subspace storing configuration item data, and no erasing operation is performed.
Only when one subspace is full, the valid data is copied to the other free subspace, and the configuration item data is continuously stored in the free space of the other free subspace.
And only when the subspace for storing the configuration item data last time is full and no free subspace exists, erasing the subspace for storing the configuration item data first, copying effective data to the subspace, and continuously storing the configuration item data in the subspace.
Therefore, effective configuration data are always stored in the Flash, and the configuration data damage caused by accidental power failure can be avoided.
In addition, the technical effect of reducing the erasing times can be achieved by the scheme, but in the embodiment, the configuration items are stored on the NOR Flash storage in an out-of-order mode, and the whole configuration storage space needs to be subjected to traversal search in order to find effective data, so that the efficiency is low.
In order to accelerate the search speed and avoid reading and comparing invalid storage contents, a bitmap is selected to record the storage position of the current valid configuration item.
Firstly, the subspace is divided into space blocks:
as an optional implementation manner, any subspace of the plurality of subspaces includes a plurality of space blocks with a preset granularity.
The preset granularity may be determined according to a specific implementation, for example, the preset granularity is set to be 32 bytes.
The space blocks are obtained by dividing the subspaces, and the sizes of the space blocks are all the preset granularity.
For example, the first subspace is 4096 bytes, the second subspace is 8192 bytes, and the set granularity is 1024 bytes, then the first subspace is divided to obtain 4 spatial blocks, and the second subspace is divided to obtain 8 spatial blocks.
When the division is performed, all subspaces need to be divided, and the remaining space which is less than the preset granularity cannot exist.
For example, the first subspace is 4096 bytes, 3072 bytes is set as the preset granularity, and the division of the first subspace into 3072-byte space blocks and 1024-byte space blocks is not allowed.
In an embodiment where each subspace is divided into spatial blocks of a preset granularity size, sequentially storing the configuration item data to the target subspace includes:
sequentially searching for free space blocks in the target subspace according to the number of space blocks occupied by the configuration item data;
and taking the searched free space block as an initial position for storing the configuration item data, and sequentially storing the configuration item data.
It should be noted that, in the embodiment where each subspace is divided into the space blocks with the preset granularity size, the expected occupied space of the configuration item data is determined first: and determining the number of space blocks occupied by the configuration item data according to the size of the configuration item data.
For example, if the size of the configuration item data is 48 bytes and the size of the space block is 32bytes, the number of space blocks occupied by the configuration item data is 2.
The meaning of sequentially searching the free space blocks is that whether the space blocks are unoccupied free space blocks is determined sequentially from front to back according to the sequence of the space blocks in the target subspace, if so, the search is stopped, otherwise, the search is continued backwards until the unoccupied free space blocks are found.
The above-mentioned sequential storage of the configuration item data means that after a free space block is full, the configuration item data is stored in the next free block in the sequence.
It should be noted that, when storing configuration item data, the start positions of the configuration item data are aligned according to a preset granularity, and the lengths of the configuration item data are aligned according to the preset granularity.
Specifically, if the granularity is set to be 32bytes, and the length of the configuration item data is 48 bytes, which is larger than one space block but smaller than two space blocks, the configuration item data is stored from the first free space block and occupies two space blocks when the configuration item data is stored.
The above embodiments describe dividing the subspace into space blocks, and in order to record the storage condition of the configuration item data in the space blocks, the embodiment of the present invention adds a search bitmap in the RAM.
The search bitmap includes bits corresponding to the space blocks in the target subspace in a one-to-one manner, each bit being used for identifying a data storage state of the corresponding space block, where a bit may be one or more bits.
And dividing each subspace into space blocks with preset granularity, identifying the data storage state of the corresponding space block by using the bit corresponding to the space block in the target subspace in the search bitmap, and determining the data storage state of the space block by searching the bit corresponding to each space block in the bitmap.
It should be noted that, the data storage state of the space block corresponding to the identifier may be:
(1) whether the corresponding space block stores configuration item data or not is marked;
(2) and marking whether the corresponding space block is a starting space block occupied by the latest configuration item data.
As previously described, the data storage state, including non-stored data, stores valid data, stores invalid data, wherein storing valid data further includes a starting location where valid data is stored and a non-starting location where valid data is stored. The above data storage status for identifying the corresponding space block may be implemented as follows:
embodiment 1: setting the bit corresponding to the space block as two bits, and determining the three storage states according to the value conditions of the two bits;
for example, setting 00 corresponds to no data stored, 01 and 10 correspond to invalid data stored, and 11 corresponds to valid data stored;
for another example, setting 00 corresponds to no data stored, 01 corresponds to invalid data stored, 10 corresponds to a non-start position where valid data is stored, and 11 corresponds to a start position where valid data is stored.
Embodiment 2: setting a bit corresponding to the space block, and mapping whether the space block stores data or not through two values of the bit.
When data searching is carried out, the space block with data can be directly positioned, and whether the data is valid or not is judged from the state bit in the space block with data.
For example, setting 0 corresponds to non-stored data and 1 corresponds to stored data;
further, whether the space block stores valid data or not can be mapped by setting the value of the bit.
For example, setting 0 corresponds to storing no data and storing invalid data, and 1 corresponds to storing valid data;
furthermore, the starting position of whether the space block stores the valid data or not can be mapped by setting the value of the bit.
For example, setting 0 corresponds to a non-start position where no data is stored, invalid data is stored, and valid data is stored, and 1 corresponds to a start position where valid data is stored;
as an optional implementation manner, in the embodiment of the present invention, the data storage state of the corresponding space block is identified in a manner that, for a plurality of space blocks in the target subspace, a starting space block occupied by the latest configuration item data of the same configuration item is identified by using a first bit value, and other space blocks are identified by using a second bit value.
In an alternative embodiment, the first bit value may be 1, and the second bit value may be 0.
As shown in fig. 4, an embodiment of the present invention provides a schematic diagram of a corresponding relationship between a search bitmap and a space block.
The storage medium is divided according to a certain granularity, such as the granularity of 32bytes, the initial addresses of the configuration item data writing are aligned according to the granularity, the effective configuration item initial position is recorded by using a bitmap, the bit corresponding to the bitmap is 1 to represent that the granularity is an effective configuration item initial position, and the bit corresponding to the bitmap is 0 to represent that the granularity has no data or is not the configuration item initial position.
In the embodiment shown in fig. 4, each bit in the search bitmap corresponds to a 32B granularity space block in the configuration storage space, for example, when the storage medium is 8KB in size, only 32bytes of bitmap are needed, so that a small amount of bitmap data is used, the storage offset position is recorded, and the search through the entire configuration storage space is avoided.
And updating the search bitmap of the random access memory RAM when the target subspace is determined to have the configuration item data change.
In a specific implementation, the bitmap updating method at least includes any one of the following embodiments:
when the configuration item data are sequentially stored in the target subspace, updating the value of the bit corresponding to the initial space block occupied by the configuration item data to be a first bit value;
updating the value of the bit corresponding to the initial space block occupied by the configuration item data belonging to the same configuration item as the latest stored configuration item data in the target subspace to a second bit value;
when the effective data in the first subspace is copied to any free subspace, updating the value of the bit corresponding to the initial space block occupied by the effective data to be a first bit value;
when a subspace storing configuration item data at first is erased, updating the value of a bit corresponding to a space block in the subspace to a second bit value;
determining a space block where the initial position of the effective data is located, and updating a bit corresponding to the space block in the search bitmap to a first bit value indicating the initial position;
and updating other bits in the search bitmap to a second bit value indicating a non-initial position.
In the following, the steps of storing configuration data will be described by taking as an example that the configuration storage space is divided into two subspaces, a subspace 1 and a subspace 2, and the two subspaces are divided into a plurality of space blocks.
As shown in fig. 5, an embodiment of the present invention provides a flowchart for dividing a configuration storage space into two subspaces for configuration data storage, where the flowchart includes:
step S501, obtaining configuration item data to be stored, and determining the number N of space blocks expected to be occupied by the configuration item data;
and determining the number of space blocks occupied by the configuration item data according to the size of the configuration item data. For example, if the size of the configuration item data is 48 bytes and the size of the space block is 32bytes, the number N of the space blocks occupied by the configuration item data is 2.
Step S502, judging whether the number M of free space blocks in a first subspace for storing configuration item data last time is larger than the number N of space blocks occupied by the configuration item data in a plurality of subspaces obtained by dividing the configuration storage space, if so, executing step S503, otherwise, executing step S504;
for example, the subspace in which the configuration storage space is divided into the subspace 1, the subspace 2, and the subspace 3 are used for storing the configuration item data last time is the subspace 2, and it is determined whether the number M of free space blocks in the subspace 2 is greater than N.
Step S503, determining the first subspace as a target subspace, and executing step S507;
assuming that M is 3, M is greater than N, and determining the subspace 2 as a target subspace;
step S504, determining that the next subspace exists and is unoccupied, if so, performing step S505, otherwise, performing step S506;
assuming that M is 1, M is smaller than N, and it is determined whether the subspace 3 is an unoccupied free subspace.
Step S505, copying the valid data in the first subspace to the next subspace, updating the next subspace to be the target subspace, and executing step S507;
the subspace 3 is an unoccupied free subspace, the valid data in the subspace 2 is copied to the subspace 3, and the subspace 3 is updated to be a target subspace;
step S506, erasing the subspace where the configuration item data is firstly stored, copying the effective data in the first subspace to the erased subspace, updating the subspace to be a target subspace, and executing step S507;
the subspace 3 is occupied, the subspace 1 which firstly stores configuration item data is erased, the effective data in the subspace 2 is copied to the erased subspace 1, and the subspace 1 is updated to be a target subspace;
and step S507, sequentially storing the configuration item data to the target subspace.
According to the above space block division and the setting of the search bitmap, the following provides a method for reading configuration parameters by using the search bitmap, including:
receiving a configuration parameter reading instruction, and determining a first hash value and a first configuration item identifier related to the configuration parameter;
determining an initial space block identified by a first bit value according to the search bitmap;
it should be noted that, when reading the configuration parameters, only the starting space block identified by the first bit value in the search bitmap is read in the target subspace according to the data of the search bitmap, specifically, in the specific embodiment shown in fig. 4, only the storage space corresponding to the bit of the search bitmap which is 1 is read.
Acquiring head data in configuration item data in the starting space block, and respectively and correspondingly matching the first hash value and the first configuration item identifier with a second hash value and a second configuration item identifier in the head data;
it should be noted that, the Hash value Hash is compared first, and the complete comparison of the configuration identifier is performed only if the Hash matching is successful.
As an optional implementation manner, matching the Hash of the configuration item data in the space block with the standard Hash, and determining the Hash-matched configuration item data;
comparing the identifier of the Hash matched configuration item data with the standard identifier to determine whether the identifiers are the same, and if not, continuously searching the Hash matched configuration item data;
and determining an initial space block where the configuration parameters to be read are located according to the matching result, and reading the configuration parameters from the initial space block.
It should be noted that, after reading the configuration parameters, the method further includes:
calculating a second Cyclic Redundancy Check (CRC) of the read configuration parameters, and comparing the second CRC with the first CRC in the header data;
and if the second cyclic redundancy check bit CRC is inconsistent with the first cyclic redundancy check bit CRC, returning error information.
And after reading the configuration item data with the same Hash and identification, calculating the CRC of the read configuration data, if the CRC is the same as the CRC in the header data, returning configuration parameters, and otherwise, returning error information.
It should be noted that, if there is an error in the last configuration item, such as a CRC error, which may be an unexpected power failure during writing, and cause a write interruption, a valid configuration item on the configuration item in the current subspace is used.
As shown in fig. 6, an embodiment of the present invention provides a flowchart for reading configuration parameters, including:
step S601, receiving a configuration parameter reading instruction, and determining a first hash value and a first configuration item identifier related to the configuration parameter;
step S602, determining an initial space block identified by a first bit value according to the search bitmap, and acquiring header data in configuration item data in the initial space block;
step S603, determining whether the second hash value in the header data matches the first hash value, if yes, performing step S604, otherwise, performing step S603;
step S604, determining whether the second configuration item identifier in the header data matches the first configuration item identifier, if yes, performing step S605, otherwise performing step S603;
step S605, determining an initial space block where the configuration parameters to be read are located, and starting to read the configuration parameters from the initial space block;
step S606, calculating a second Cyclic Redundancy Check (CRC) of the read configuration parameters, and comparing the CRC with the first CRC in the header data;
step S607, determining whether the second CRC is identical to the first CRC, if so, performing step S608, otherwise, performing step S609;
step S608, returning configuration parameters;
in step S609, an error message is returned.
Example 2
An embodiment of the present invention provides a schematic diagram of an apparatus 700 for configuring data storage, including a memory 701 and a processor 702, as shown in fig. 7, where:
the memory is used for storing a computer program;
the processor is used for reading the program in the memory and executing the following steps:
acquiring configuration item data to be stored, and determining the expected occupied space of the configuration item data;
in a plurality of subspaces obtained by dividing a configuration storage space, if the free space of a first subspace for storing configuration item data last time is larger than the expected occupied space, determining that the first subspace is a target subspace;
otherwise, when determining that the next subspace exists and is not occupied, copying the effective data in the first subspace to the next subspace, and updating the next subspace to be the target subspace;
when determining that the next subspace does not exist or is occupied, erasing the subspace where the configuration item data is stored firstly, copying effective data in the first subspace to the erased subspace, and updating the subspace to be a target subspace;
and sequentially storing the configuration item data to the target subspace.
Optionally, the configuration storage space is divided into two subspaces.
Optionally, any subspace of the plurality of subspaces includes a plurality of spatial blocks having a size of a preset granularity.
Optionally, the processor sequentially stores the configuration item data to the target subspace, including:
sequentially searching for free space blocks in the target subspace according to the number of space blocks occupied by the configuration item data;
and taking the searched free space block as an initial position for storing the configuration item data, and sequentially storing the configuration item data.
Optionally, the copying, by the processor, valid data in the first subspace to the next subspace/erased subspace includes:
determining the latest stored configuration item data in the configuration item data belonging to the same configuration item in the configuration item data stored in the first subspace as valid data;
copying valid data in the first subspace to the next subspace/erased subspace.
Optionally, the processor sequentially stores the configuration item data to the target subspace, including:
sequentially storing the configuration item data into the target subspace, and setting the value of the state bit of the configuration item data as a first state bit value;
and updating the value of the state bit of the configuration item data which belongs to the same configuration item with the latest stored configuration item data into a second state bit value in the configuration item data stored in the target subspace.
Optionally, the processor is further configured to:
updating a search bitmap of a Random Access Memory (RAM) when the data change of the configuration item exists in the target subspace;
the search bitmap includes bits corresponding to the space blocks in the target subspace, one to one, each bit identifying a data storage state of the corresponding space block.
Optionally, for a plurality of space blocks in the target subspace, the starting space block occupied by the latest configuration item data of the same configuration item is identified by using the first bit value, and the other space blocks are identified by using the second bit value.
Optionally, the configuration item data includes header data and configuration parameters, the configuration parameters include configuration item identification and configuration data, and the processor is further configured to:
receiving a configuration parameter reading instruction, and determining a first hash value and a first configuration item identifier related to the configuration parameter;
determining an initial space block identified by a first bit value according to the search bitmap;
acquiring head data in configuration item data in the starting space block, and respectively and correspondingly matching the first hash value and the first configuration item identifier with a second hash value and a second configuration item identifier in the head data;
and determining an initial space block where the configuration parameters to be read are located according to the matching result, and reading the configuration parameters from the initial space block.
Optionally, after reading the configuration parameters, the processor is further configured to:
calculating a second Cyclic Redundancy Check (CRC) of the read configuration parameters, and comparing the second CRC with the first CRC in the header data;
and if the second cyclic redundancy check bit CRC is inconsistent with the first cyclic redundancy check bit CRC, returning error information.
An embodiment of the present invention provides a schematic diagram of an apparatus for configuring data storage, as shown in fig. 8, including:
a data obtaining unit 801, configured to obtain configuration item data to be stored, and determine an expected occupied space of the configuration item data;
a first space determining unit 802, configured to determine, in a plurality of subspaces obtained by dividing a configuration storage space, that a first subspace storing configuration item data last time is a target subspace if an idle space of the first subspace is greater than the expected occupied space;
a second space determining unit 803, configured to otherwise, when it is determined that a next subspace exists and is not occupied, copy the valid data in the first subspace to the next subspace, and update the next subspace to a target subspace;
a third space determining unit 804, configured to determine that there is no next subspace or when the next subspace is occupied, erase the subspace where the configuration item data is stored first, copy the valid data in the first subspace to the erased subspace, and update the subspace to be the target subspace;
a storage unit 805, configured to sequentially store the configuration item data in the target subspace.
Optionally, the configuration storage space is divided into two subspaces.
Optionally, any subspace of the plurality of subspaces includes a plurality of spatial blocks having a size of a preset granularity.
Optionally, the sequentially storing the configuration item data to the target subspace by the storage unit includes:
sequentially searching for free space blocks in the target subspace according to the number of space blocks occupied by the configuration item data;
and taking the searched free space block as an initial position for storing the configuration item data, and sequentially storing the configuration item data.
Optionally, the copying, by the second space determining unit, valid data in the first subspace to the next subspace includes:
determining the latest stored configuration item data in the configuration item data belonging to the same configuration item in the configuration item data stored in the first subspace as valid data;
copying valid data in the first subspace to the next subspace.
Optionally, the copying, by the third space determining unit, valid data in the first subspace to the erased subspace includes:
determining the latest stored configuration item data in the configuration item data belonging to the same configuration item in the configuration item data stored in the first subspace as valid data;
and copying the effective data in the first subspace to the erased subspace.
Optionally, the sequentially storing the configuration item data to the target subspace by the storage unit includes:
sequentially storing the configuration item data into the target subspace, and setting the value of the state bit of the configuration item data as a first state bit value;
and updating the value of the state bit of the configuration item data which belongs to the same configuration item with the latest stored configuration item data into a second state bit value in the configuration item data stored in the target subspace.
Optionally, the storage unit is further configured to:
updating a search bitmap of a Random Access Memory (RAM) when the data change of the configuration item exists in the target subspace;
the search bitmap includes bits corresponding to the space blocks in the target subspace, one to one, each bit identifying a data storage state of the corresponding space block.
Optionally, for a plurality of space blocks in the target subspace, the starting space block occupied by the latest configuration item data of the same configuration item is identified by using the first bit value, and the other space blocks are identified by using the second bit value.
Optionally, the configuration item data includes header data and configuration parameters, the configuration parameters include configuration item identifiers and configuration data, and the storage unit is further configured to:
receiving a configuration parameter reading instruction, and determining a first hash value and a first configuration item identifier related to the configuration parameter;
determining an initial space block identified by a first bit value according to the search bitmap;
acquiring head data in configuration item data in the starting space block, and respectively and correspondingly matching the first hash value and the first configuration item identifier with a second hash value and a second configuration item identifier in the head data;
and determining an initial space block where the configuration parameters to be read are located according to the matching result, and reading the configuration parameters from the initial space block.
Optionally, after reading the configuration parameter, the storage unit is further configured to:
calculating a second Cyclic Redundancy Check (CRC) of the read configuration parameters, and comparing the second CRC with the first CRC in the header data;
and if the second cyclic redundancy check bit CRC is inconsistent with the first cyclic redundancy check bit CRC, returning error information.
The present invention also provides a computer program medium having stored thereon a computer program which, when executed by a processor, implements the steps of a method of configuring data storage provided in embodiment 1 above.
In the several embodiments provided in the present application, it should be understood that the disclosed system, apparatus and method may be implemented in other manners. For example, the above-described apparatus embodiments are merely illustrative, and for example, the division of the modules is merely a logical division, and in actual implementation, there may be other divisions, for example, multiple modules or components may be combined or integrated into another system, or some features may be omitted, or not implemented. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or modules, and may be in an electrical, mechanical or other form.
The modules described as separate parts may or may not be physically separate, and parts displayed as modules may or may not be physical modules, may be located in one place, or may be distributed on a plurality of network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment.
In addition, functional modules in the embodiments of the present application may be integrated into one processing module, or each of the modules may exist alone physically, or two or more modules are integrated into one module. The integrated module can be realized in a hardware mode, and can also be realized in a software functional module mode. The integrated module, if implemented in the form of a software functional module and sold or used as a stand-alone product, may be stored in a computer readable storage medium.
In the above embodiments, the implementation may be wholly or partially realized by software, hardware, firmware, or any combination thereof. When implemented in software, may be implemented in whole or in part in the form of a computer program product.
The computer program product includes one or more computer instructions. When loaded and executed on a computer, cause the processes or functions described in accordance with the embodiments of the application to occur, in whole or in part. The computer may be a general purpose computer, a special purpose computer, a network of computers, or other programmable device. The computer instructions may be stored in a computer readable storage medium or transmitted from one computer readable storage medium to another, for example, from one website site, computer, server, or data center to another website site, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, Digital Subscriber Line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that a computer can store or a data storage device, such as a server, a data center, etc., that is integrated with one or more available media. The usable medium may be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., Solid State Disk (SSD)), among others.
The technical solutions provided by the present application are introduced in detail, and the present application applies specific examples to explain the principles and embodiments of the present application, and the descriptions of the above examples are only used to help understand the method and the core ideas of the present application; meanwhile, for a person skilled in the art, according to the idea of the present application, there may be variations in the specific embodiments and the application scope, and in summary, the content of the present specification should not be construed as a limitation to the present application.
As will be appreciated by one skilled in the art, embodiments of the present application may be provided as a method, system, or computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present application is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to the application. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto 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 flow or flows and/or block diagram block or blocks.
It will be apparent to those skilled in the art that various changes and modifications may be made in the present application without departing from the spirit and scope of the application. Thus, if such modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is intended to include such modifications and variations as well.

Claims (13)

1. A method of configuring a data store, comprising:
acquiring configuration item data to be stored, and determining the expected occupied space of the configuration item data;
in a plurality of subspaces obtained by dividing a configuration storage space, if the free space of a first subspace for storing configuration item data last time is larger than the expected occupied space, determining that the first subspace is a target subspace;
otherwise, when determining that the next subspace exists and is not occupied, copying the effective data in the first subspace to the next subspace, and updating the next subspace to be the target subspace;
when determining that the next subspace does not exist or is occupied, erasing the subspace where the configuration item data is stored firstly, copying effective data in the first subspace to the erased subspace, and updating the subspace to be a target subspace;
and sequentially storing the configuration item data to the target subspace.
2. The method of claim 1, wherein the configuration storage space is divided into two subspaces.
3. The method of claim 1, wherein any subspace of the plurality of subspaces comprises a plurality of spatial blocks having a predetermined granularity.
4. The method of claim 3, wherein sequentially storing the configuration item data to the target subspace comprises:
sequentially searching for free space blocks in the target subspace according to the number of space blocks occupied by the configuration item data;
and taking the searched free space block as an initial position for storing the configuration item data, and sequentially storing the configuration item data.
5. The method of claim 1, wherein copying valid data in the first subspace to the next/erased subspace comprises:
determining the latest stored configuration item data in the configuration item data belonging to the same configuration item in the configuration item data stored in the first subspace as valid data;
copying valid data in the first subspace to the next subspace/erased subspace.
6. The method of claim 1, wherein sequentially storing the configuration item data to the target subspace comprises:
sequentially storing the configuration item data into the target subspace, and setting the value of the state bit of the configuration item data as a first state bit value;
and updating the value of the state bit of the configuration item data which belongs to the same configuration item with the latest stored configuration item data into a second state bit value in the configuration item data stored in the target subspace.
7. The method of claim 3, further comprising:
updating a search bitmap of a Random Access Memory (RAM) when the data change of the configuration item exists in the target subspace;
the search bitmap includes bits corresponding to the space blocks in the target subspace, one to one, each bit identifying a data storage state of the corresponding space block.
8. The method of claim 7,
and for a plurality of space blocks in the target subspace, adopting a first bit value to identify a starting space block occupied by the latest configuration item data of the same configuration item, and adopting a second bit value to identify other space blocks.
9. The method of claim 8, wherein the configuration item data comprises header data and configuration parameters, wherein the configuration parameters comprise configuration item identification and configuration data, and further comprising:
receiving a configuration parameter reading instruction, and determining a first hash value and a first configuration item identifier related to the configuration parameter;
determining an initial space block identified by a first bit value according to the search bitmap;
acquiring head data in configuration item data in the starting space block, and respectively and correspondingly matching the first hash value and the first configuration item identifier with a second hash value and a second configuration item identifier in the head data;
and determining an initial space block where the configuration parameters to be read are located according to the matching result, and reading the configuration parameters from the initial space block.
10. The method of claim 9, wherein reading the configuration parameters further comprises:
calculating a second Cyclic Redundancy Check (CRC) of the read configuration parameters, and comparing the second CRC with the first CRC in the header data;
and if the second cyclic redundancy check bit CRC is inconsistent with the first cyclic redundancy check bit CRC, returning error information.
11. An apparatus for configuring data storage, comprising a memory and a processor, wherein:
the memory is used for storing a computer program;
the processor is used for reading the program in the memory and executing the method for storing the configuration data according to any one of claims 1 to 10.
12. An apparatus for configuring data storage, comprising:
the data acquisition unit is used for acquiring the configuration item data to be stored and determining the expected occupied space of the configuration item data;
a first space determining unit, configured to determine, in a plurality of subspaces obtained by dividing a configuration storage space, that a first subspace storing configuration item data last time is a target subspace if an idle space of the first subspace is larger than the expected occupied space;
a second space determining unit, configured to copy valid data in the first subspace to a next subspace and update the next subspace to a target subspace if it is determined that the next subspace exists and is not occupied;
a third space determining unit, configured to determine that there is no next subspace or when the next subspace is occupied, erase a subspace in which configuration item data is first stored, copy valid data in the first subspace to the erased subspace, and update the subspace to a target subspace;
and the storage unit is used for sequentially storing the configuration item data to the target subspace.
13. A computer program medium, on which a computer program is stored which, when being executed by a processor, carries out the steps of the method of configuring a data storage according to any one of claims 1 to 10.
CN202011436860.1A 2020-12-07 2020-12-07 Method, device and equipment for storing configuration data Active CN112558868B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011436860.1A CN112558868B (en) 2020-12-07 2020-12-07 Method, device and equipment for storing configuration data

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011436860.1A CN112558868B (en) 2020-12-07 2020-12-07 Method, device and equipment for storing configuration data

Publications (2)

Publication Number Publication Date
CN112558868A true CN112558868A (en) 2021-03-26
CN112558868B CN112558868B (en) 2024-04-09

Family

ID=75060317

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011436860.1A Active CN112558868B (en) 2020-12-07 2020-12-07 Method, device and equipment for storing configuration data

Country Status (1)

Country Link
CN (1) CN112558868B (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113239114A (en) * 2021-05-13 2021-08-10 中国邮政储蓄银行股份有限公司 Data storage method, data storage device, storage medium and electronic device
CN113282247A (en) * 2021-06-24 2021-08-20 京东科技控股股份有限公司 Data storage method, data reading method, data storage device, data reading device and electronic equipment

Citations (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6687815B1 (en) * 2000-02-01 2004-02-03 Sun Microsystems, Inc. Method and apparatus for storing non-volatile configuration information
CN1913040A (en) * 2005-08-12 2007-02-14 中兴通讯股份有限公司 Method for configuring parameter in NOR FLASH
US20090037681A1 (en) * 2007-08-03 2009-02-05 Fujitsu Limited Computer-readable storage medium in which storage-management program is recorded, storage-management apparatus, and storage-management method
CN103442000A (en) * 2013-08-22 2013-12-11 北京星网锐捷网络技术有限公司 Method and device for replacing WEB caches and HTTP proxy server
US20150113210A1 (en) * 2013-10-22 2015-04-23 Renesas Electronics Corporation Data storage flash memory management method and program
CN105528301A (en) * 2015-12-07 2016-04-27 中国人民解放军信息工程大学 NAND Flash memory garbage collection method
US20170003885A1 (en) * 2014-03-14 2017-01-05 Beijing Kingsoft Network Technology Co., Ltd. Method and apparatus for downloading data
CN106484331A (en) * 2015-09-29 2017-03-08 华为技术有限公司 A kind of data processing method, device and flash memory device
US20180088805A1 (en) * 2016-09-23 2018-03-29 Toshiba Memory Corporation Storage device that writes data from a host during garbage collection
US20190235782A1 (en) * 2018-01-31 2019-08-01 EMC IP Holding Company LLC Techniques for rebalancing storage between subspaces
CN110968253A (en) * 2018-09-29 2020-04-07 阿里巴巴集团控股有限公司 Data storage method, device and system
US20200218662A1 (en) * 2017-09-29 2020-07-09 SZ DJI Technology Co., Ltd. Data caching device and control method therefor, data processing chip, and data processing system

Patent Citations (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6687815B1 (en) * 2000-02-01 2004-02-03 Sun Microsystems, Inc. Method and apparatus for storing non-volatile configuration information
CN1913040A (en) * 2005-08-12 2007-02-14 中兴通讯股份有限公司 Method for configuring parameter in NOR FLASH
US20090037681A1 (en) * 2007-08-03 2009-02-05 Fujitsu Limited Computer-readable storage medium in which storage-management program is recorded, storage-management apparatus, and storage-management method
CN103442000A (en) * 2013-08-22 2013-12-11 北京星网锐捷网络技术有限公司 Method and device for replacing WEB caches and HTTP proxy server
US20150113210A1 (en) * 2013-10-22 2015-04-23 Renesas Electronics Corporation Data storage flash memory management method and program
US20170003885A1 (en) * 2014-03-14 2017-01-05 Beijing Kingsoft Network Technology Co., Ltd. Method and apparatus for downloading data
CN106484331A (en) * 2015-09-29 2017-03-08 华为技术有限公司 A kind of data processing method, device and flash memory device
CN105528301A (en) * 2015-12-07 2016-04-27 中国人民解放军信息工程大学 NAND Flash memory garbage collection method
US20180088805A1 (en) * 2016-09-23 2018-03-29 Toshiba Memory Corporation Storage device that writes data from a host during garbage collection
US20200218662A1 (en) * 2017-09-29 2020-07-09 SZ DJI Technology Co., Ltd. Data caching device and control method therefor, data processing chip, and data processing system
US20190235782A1 (en) * 2018-01-31 2019-08-01 EMC IP Holding Company LLC Techniques for rebalancing storage between subspaces
CN110968253A (en) * 2018-09-29 2020-04-07 阿里巴巴集团控股有限公司 Data storage method, device and system

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113239114A (en) * 2021-05-13 2021-08-10 中国邮政储蓄银行股份有限公司 Data storage method, data storage device, storage medium and electronic device
CN113282247A (en) * 2021-06-24 2021-08-20 京东科技控股股份有限公司 Data storage method, data reading method, data storage device, data reading device and electronic equipment

Also Published As

Publication number Publication date
CN112558868B (en) 2024-04-09

Similar Documents

Publication Publication Date Title
CN110531940B (en) Video file processing method and device
EP3678015A1 (en) Metadata query method and device
CN110442473B (en) Nonvolatile data storage method and device, electronic equipment and medium
CN110399333B (en) Method, apparatus and computer program product for deleting snapshots
CN112631950B (en) L2P table saving method, system, device and medium
CN112558868B (en) Method, device and equipment for storing configuration data
CN111966287B (en) Data storage method, electronic device and storage medium
CN110147203B (en) File management method and device, electronic equipment and storage medium
US20190317698A1 (en) Disk Data Reading/Writing Method and Device
CN107807886B (en) Index management in flash memory
EP3336702B1 (en) Metadata recovery method and device
CN115292266A (en) High-reliability log storage method based on memory
CN112988611A (en) Data writing method of nonvolatile memory, terminal and readable storage medium
CN112463020A (en) Data access method, device and equipment based on Flash
CN108829342B (en) Log storage method, system and storage device
CN108664482B (en) FLASH memory and storage file management method
CN110209349B (en) Data processing method and terminal equipment
CN115857811A (en) Data processing method and device, solid state disk and readable storage medium
US20200042440A1 (en) Memory management method and storage controller
CN115328851A (en) Data protection method, device, equipment and medium
CN112148220B (en) Method, device, computer storage medium and terminal for realizing data processing
CN111399759B (en) Method for reading data and writing data and object file system
CN110008059B (en) Data updating method and device for nonvolatile storage medium and storage medium
CN113467724A (en) CRC (Cyclic redundancy check) code storage method, device, equipment and medium
CN109213421B (en) Storage recording method and device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant