CN116339628A - Method for determining storage partition of storage unit, storage medium and electronic device - Google Patents

Method for determining storage partition of storage unit, storage medium and electronic device Download PDF

Info

Publication number
CN116339628A
CN116339628A CN202310275330.0A CN202310275330A CN116339628A CN 116339628 A CN116339628 A CN 116339628A CN 202310275330 A CN202310275330 A CN 202310275330A CN 116339628 A CN116339628 A CN 116339628A
Authority
CN
China
Prior art keywords
data
unit
partition
storage
field
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.)
Pending
Application number
CN202310275330.0A
Other languages
Chinese (zh)
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.)
Weichai Power Co Ltd
Weifang Weichai Power Technology Co Ltd
Original Assignee
Weichai Power Co Ltd
Weifang Weichai Power 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 Weichai Power Co Ltd, Weifang Weichai Power Technology Co Ltd filed Critical Weichai Power Co Ltd
Priority to CN202310275330.0A priority Critical patent/CN116339628A/en
Publication of CN116339628A publication Critical patent/CN116339628A/en
Pending legal-status Critical Current

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/0628Interfaces specially adapted for storage systems making use of a particular technique
    • G06F3/0638Organizing or formatting or addressing of data
    • G06F3/0644Management of space entities, e.g. partitions, extents, pools
    • 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/0614Improving the reliability of storage systems
    • G06F3/0616Improving the reliability of storage systems in relation to life time, e.g. increasing Mean Time Between Failures [MTBF]
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Human Computer Interaction (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Techniques For Improving Reliability Of Storages (AREA)

Abstract

The application provides a method for determining a storage partition of a storage unit, a storage medium and electronic equipment, wherein the method comprises the following steps: acquiring a plurality of storage partitions, wherein each storage partition comprises a plurality of data units, and each data unit stores a plurality of fields; detecting each storage partition to obtain a plurality of detection results, wherein the detection results correspond to the storage partitions one by one, and the plurality of detection results comprise the number of effective units of the storage partition, the number of ineffective units of the storage partition and the number of blank units of the storage partition; according to at least one of the following: the number of valid units of each storage partition, the number of invalid units of each storage partition, and the number of blank units of each storage partition, and determining a target partition and a non-target partition. According to the method and the device, the target partition and the non-target partition are determined, so that partition switching is completed by means of the other partition when one storage partition is full, and the problems that the storage medium is frequently erased and written, the efficiency is low and the service life of the storage medium is influenced in the prior art are solved.

Description

Method for determining storage partition of storage unit, storage medium and electronic device
Technical Field
The present invention relates to the field of data reading and writing, and in particular, to a method for determining a storage partition of a storage unit, a device for determining a storage partition of a storage unit, a storage medium, and an electronic device.
Background
When data is read from or written to a storage medium (e.g., FLASH, EEPROM), unexpected interruption (e.g., power loss) may occur, which would likely cause data corruption (loss or modification) in the storage area if no protection measures were available. If the area originally stored important system data, then the corruption of data could have disastrous consequences for the overall system.
The existing technical scheme for improving the data read-write reliability of the storage medium generally comprises the steps of providing a data backup area, writing old data or new data into the backup area, and deleting the backup data after ensuring the correctness of the new and old data exchange. This not only requires a more complex control method, but also results in frequent erasure of the storage medium, lower efficiency and affects the lifetime of the storage medium.
Disclosure of Invention
The main object of the present application is to provide a method for determining a storage partition of a storage unit, a device for determining a storage partition of a storage unit, a storage medium and an electronic device, so as to at least solve the problems of frequent erasing and writing of the storage medium, low efficiency and influence on the service life of the storage medium in the prior art.
In order to achieve the above object, according to one aspect of the present application, there is provided a method for determining a storage partition of a storage unit, including: acquiring a plurality of storage partitions, wherein each storage partition comprises a plurality of data units, each data unit stores a plurality of fields, and the plurality of fields comprise a use field, a valid field, a data name field, a data length field, a data content field and a data verification field; detecting each storage partition to obtain a plurality of detection results, wherein the detection results are in one-to-one correspondence with the storage partition, the plurality of detection results comprise the effective unit number of the storage partition, the ineffective unit number of the storage partition and the blank unit number of the storage partition, the effective unit number is the number of data units with effective data stored in the storage partition, the ineffective unit number is the number of data units with ineffective data stored in the storage partition, and the blank unit number is the number of data units without data stored in the storage partition; according to at least one of the following: the method comprises the steps of determining a target partition and a non-target partition, wherein the target partition is the storage partition with the largest effective unit number or the largest blank unit number, the target partition is used for reading and writing data, and the non-target partition is used for continuing to write the data under the condition that the target partition is full of the data.
Optionally, according to at least one of: determining the target partition and the non-target partition from the number of valid units of each of the storage partitions, the number of invalid units of each of the storage partitions, and the number of blank units of each of the storage partitions, comprises: determining the storage partition with the largest number of effective units as the target partition under the condition that the effective units of at least two storage partitions are different; determining the storage partition with the least invalid unit number as the target partition under the condition that the valid unit numbers of any two storage partitions are the same; and determining the storage partition with the largest blank unit number as the target partition under the condition that the effective unit numbers of any two storage partitions are the same and the ineffective unit numbers of any two storage partitions are the same.
Optionally, detecting each storage partition to obtain a plurality of detection results, where the detection results are in one-to-one correspondence with the storage partitions, and the method includes: sequentially detecting a plurality of data units in the storage partition according to a preset sequence, and sequentially performing field detection, effective field detection, data length field detection and data check field detection on each data unit to obtain an initial detection result, wherein the initial detection result comprises one of an effective unit, an ineffective unit and a blank unit; and determining the effective unit number of the storage partition, the ineffective unit number of the storage partition and the blank unit number of the storage partition according to a plurality of initial detection results to obtain the detection results.
Optionally, performing usage field detection, valid field detection, data length field detection, and data check field detection sequentially for each data unit to obtain an initial detection result, including: continuing to sequentially perform the effective field detection, the data length field detection and the data check field detection under the condition that the used field meets a first condition, wherein the first condition is characterized in that the data unit is not the blank unit, so as to obtain the initial detection result; determining that the data unit is the invalid unit if the usage field does not satisfy the first condition and at least one detected data unit is not the blank unit; and determining that the data unit is the blank unit when the usage field does not meet the first condition and the detected data units are all the blank unit.
Optionally, performing usage field detection, valid field detection, data length field detection, and data check field detection sequentially for each data unit to obtain an initial detection result, including: continuing to perform the valid field detection when the usage field meets a first condition, and continuing to sequentially perform the data length field detection and the data check field detection when the valid field meets a second condition, so as to obtain the initial detection result, wherein the second condition is characterized in that the data unit is the valid unit, and the first condition is characterized in that the data unit is not the blank unit; and determining the data unit as the invalid unit under the condition that the valid field does not meet the second condition.
Optionally, performing usage field detection, valid field detection, data length field detection, and data check field detection sequentially for each data unit to obtain an initial detection result, including: continuing to perform the data length field detection when the usage field meets a first condition and the valid field meets a second condition, and continuing to perform the data check field detection when the data length field meets a third condition, wherein the third condition is that the data length represented by the data length field is within a preset length range, the first condition is characterized in that the data unit is not the blank unit, and the second condition is characterized in that the data unit is the valid unit, so as to obtain the initial detection result; and determining the data unit as the invalid unit in the case that the data length field does not meet the third condition.
Optionally, performing usage field detection, valid field detection, data length field detection, and data check field detection sequentially for each data unit to obtain an initial detection result, including: continuing to perform the data check field detection when the usage field satisfies a first condition, the valid field satisfies a second condition, and the data length field satisfies a third condition, and determining that the data unit is the valid unit when the data check field satisfies a fourth condition, the fourth condition being that the value of the data check field is a target value and the data written by the data unit is unique, the target value indicating that the data name field, the data length field, and the data content field are correct, the first condition being characterized in that the data unit is not the blank unit, the second condition being characterized in that the data unit is the valid unit, and the third condition being that the data length indicated by the data length field is within a preset length range; determining the data unit as the invalid unit under the condition that the data check field does not meet a fourth condition and the field bits of the data check field are not all of a preset value; and under the condition that the data check field does not meet the fourth condition and the field bits of the data check field are all the preset value, repairing the numerical value of the data check field and judging whether the repaired data check field meets the fourth condition.
Optionally, the memory partition is two, according to at least one of: after determining the target partition and the non-target partition, the method further includes: copying all valid data in the target partition to the non-target partition under the condition that the target data need to be written and the target partition does not have the blank unit, and confirming the non-target partition as a current target partition; and erasing the whole content in the target partition, and writing the target data into the current target partition.
According to another aspect of the present application, there is provided a computer readable storage medium, where the computer readable storage medium includes a stored program, and when the program runs, the device in which the computer readable storage medium is controlled to execute any one of the methods for determining a storage partition of a storage unit.
According to another aspect of the present application, there is provided an electronic device including: one or more processors, a memory, and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, the one or more programs comprising a method for performing a determination of a storage partition of any of the storage units.
By applying the technical scheme of the application, the method for determining the storage partition of the storage unit in the application comprises the steps of firstly acquiring a plurality of storage partitions, wherein each storage partition comprises a plurality of data units, each data unit stores a plurality of fields, and each field comprises a use field, an effective field, a data name field, a data length field, a data content field and a data verification field; detecting each storage partition to obtain a plurality of detection results, wherein the detection results correspond to the storage partitions one by one, the plurality of detection results comprise the effective unit number of the storage partitions, the ineffective unit number of the storage partitions and the blank unit number of the storage partitions, the effective unit number is the number of data units with effective data stored in the storage partitions, the ineffective unit number is the number of data units with ineffective data stored in the storage partitions, and the blank unit number is the number of data units without data stored in the storage partitions; finally according to at least one of the following: the method comprises the steps of determining a target partition and a non-target partition, wherein the target partition is a storage partition with the largest number of effective units or the largest number of blank units, and is used for reading and writing data, and the non-target partition is used for continuing to write the data when the target partition is full of the data. According to the method, the target partition and the non-target partition are determined, so that partition switching is completed by means of one partition when the other partition is full, frequent erasing of the storage medium is not caused, and the problems that the erasing of the storage medium is frequent, the efficiency is low and the service life of the storage medium is influenced in the prior art are solved.
Drawings
The accompanying drawings, which are included to provide a further understanding of the application and are incorporated in and constitute a part of this application, illustrate embodiments of the application and together with the description serve to explain the application and do not constitute an undue limitation to the application. In the drawings:
fig. 1 is a block diagram showing a hardware configuration of a mobile terminal according to a method of determining a memory partition of a memory unit provided in an embodiment of the present application;
FIG. 2 is a flow chart illustrating a method for determining a storage partition of a storage unit according to an embodiment of the present application;
FIG. 3 is a schematic diagram of a memory partition of a memory unit according to an embodiment of the present application;
FIG. 4 is a flow chart illustrating another method for determining a storage partition of a storage unit according to an embodiment of the present application;
FIG. 5 shows a flow diagram of a data writing process provided in accordance with an embodiment of the present application;
FIG. 6 shows a flow diagram of a data reading process provided in accordance with an embodiment of the present application;
fig. 7 shows a block diagram of a determination apparatus for a storage partition of a storage unit according to an embodiment of the present application.
Detailed Description
It should be noted that, in the case of no conflict, the embodiments and features in the embodiments may be combined with each other. The present application will be described in detail below with reference to the accompanying drawings in conjunction with embodiments.
In order to make the present application solution better understood by those skilled in the art, the following description will be made in detail and with reference to the accompanying drawings in the embodiments of the present application, it is apparent that the described embodiments are only some embodiments of the present application, not all embodiments. All other embodiments, which can be made by one of ordinary skill in the art based on the embodiments herein without making any inventive effort, shall fall within the scope of the present application.
It should be noted that the terms "first," "second," and the like in the description and claims of the present application and the above figures are used for distinguishing between similar objects and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used may be interchanged where appropriate in order to describe the embodiments of the present application described herein. Furthermore, the terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.
For convenience of description, the following will describe some terms or terms related to the embodiments of the present application:
FLASH: a nonvolatile memory can hold data for a long time even without current supply. A common non-volatile memory is NorFlash, nandFlash.
EEPROM: the charged erasable programmable read-only memory is a memory chip which is not lost in data after power failure and can be erased and reprogrammed (rewritten) by the action of higher than ordinary voltage.
As described in the background art, in the prior art, a more complex control method is required, and frequent erasing of a storage medium is caused, so that the efficiency is low and the service life of the storage medium is influenced.
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention.
The method embodiments provided in the embodiments of the present application may be performed in a mobile terminal, a computer terminal or similar computing device. Taking the mobile terminal as an example, fig. 1 is a block diagram of a hardware structure of the mobile terminal according to a method for determining a storage partition of a storage unit according to an embodiment of the present invention. As shown in fig. 1, a mobile terminal may include one or more (only one is shown in fig. 1) processors 102 (the processor 102 may include, but is not limited to, a microprocessor MCU or a processing device such as a programmable logic device FPGA) and a memory 104 for storing data, wherein the mobile terminal may also include a transmission device 106 for communication functions and an input-output device 108. It will be appreciated by those skilled in the art that the structure shown in fig. 1 is merely illustrative and not limiting of the structure of the mobile terminal described above. For example, the mobile terminal may also include more or fewer components than shown in fig. 1, or have a different configuration than shown in fig. 1.
The memory 104 may be used to store a computer program, for example, a software program of application software and a module, such as a computer program corresponding to a display method of device information in an embodiment of the present invention, and the processor 102 executes the computer program stored in the memory 104 to perform various functional applications and data processing, that is, to implement the above-described method. Memory 104 may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include memory remotely located relative to the processor 102, which may be connected to the mobile terminal via a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof. The transmission device 106 is used to receive or transmit data via a network. Specific examples of the network described above may include a wireless network provided by a communication provider of the mobile terminal. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, simply referred to as NIC) that can connect to other network devices through a base station to communicate with the internet. In one example, the transmission device 106 may be a Radio Frequency (RF) module, which is configured to communicate with the internet wirelessly.
In the present embodiment, a method for determining a storage partition of a storage unit operating on a mobile terminal, a computer terminal, or a similar computing device is provided, it should be noted that the steps illustrated in the flowchart of the drawings may be performed in a computer system such as a set of computer executable instructions, and that although a logical order is illustrated in the flowchart, in some cases, the steps illustrated or described may be performed in an order different from that illustrated herein.
Fig. 2 is a flowchart of a method of determining a storage partition of a storage unit according to an embodiment of the present application. As shown in fig. 2, the method comprises the steps of:
step S201, a plurality of storage partitions are obtained, each storage partition comprises a plurality of data units, each data unit stores a plurality of fields, and the plurality of fields comprise a use field, a valid field, a data name field, a data length field, a data content field and a data verification field;
specifically, in general, only two storage partitions are required to be set, namely a first storage partition and a second storage partition, and the number of data units included in the two storage partitions is equal, as shown in fig. 3, two areas with the same size are divided on the available space of the storage medium, so that the capacity of one storage space can meet the data storage requirement, in most cases, only one partition (target partition) can be operated, data transfer can be performed only when the storage space is used up, and valid data is copied to the other partition (non-target partition, which can also be called standby partition). As shown in the following figures, each memory partition is divided into small blocks of the same size, each of which may store one data unit, each of which is in turn made up of several sub-blocks. Initially all data units of the memory area are written to 1. And the storage content is managed in a data unit mode, and the correctness of the reading and writing process is ensured by setting various fields.
Wherein, as shown in fig. 3, the respective fields (sub-blocks) of the data unit are explained as follows:
1) Whether to use an identification (i.e., use a field): taking 4 bytes, all 1's indicate that the data unit is empty, i.e. not written with data. If data is written, the flag is set to a magic word that can be self-verified, such as 0xA55B5AA5, i.e. the upper 2 bytes are complements of the lower 2 bytes. When this field is other, then an error is considered to have occurred in writing.
2) Validity identification (i.e., valid field): taking 4 bytes, all 1's indicate that the data is valid. When the data is invalid, the flag is set to a magic word capable of self-checking, such as 0xA55B5AA5, i.e. the upper 2 bytes are complements of the lower 2 bytes. When this field is other, then an error is considered to have occurred in writing.
3) Data name: the data is managed in a key value pair mode, the field is a key, the storage content is a character string, and the character string can be used for judging whether the data exists or not when the data is written.
4) Data length: taking 4 bytes to represent the actual length of the data content, and when this value exceeds the agreed maximum limit, an error is considered to have occurred in writing.
5) Data content: the fixed length is occupied (which may be determined according to specific requirements), and the actual length is obtained from the "data length" field. The data is managed in a key value pair mode, the field is a value, and if the key exists and the values are equal when the data is written, the data is not written.
6) And (3) checking data: the data occupy 2 bytes, which is a numerical value obtained by performing Cyclic Redundancy Calculation (CRC) on the data name, the data length and the data content field, and is used for checking whether errors occur in the data of the parts during writing.
Step S202, detecting each storage partition to obtain a plurality of detection results, wherein the detection results are in one-to-one correspondence with the storage partitions, and the plurality of detection results comprise the effective unit number of the storage partitions, the ineffective unit number of the storage partitions and the blank unit number of the storage partitions, the effective unit number is the number of data units effective by data stored in the storage partitions, the ineffective unit number is the number of data units ineffective by data stored in the storage partitions, and the blank unit number is the number of data units not storing data in the storage partitions;
specifically, each time power is applied, data in a plurality of storage partitions are checked, error checking and even repairing can be performed on various abnormal conditions occurring in the data writing process through various measures, a target partition and a non-target partition are determined through a statistical result, and data of the non-target partition is erased (full writing 1).
The specific implementation steps of step S202 are as follows:
step S2021, detecting a plurality of data units in the storage partition sequentially according to a preset sequence, and sequentially performing usage field detection, valid field detection, data length field detection and data check field detection for each data unit to obtain an initial detection result, where the initial detection result includes one of the data units being valid units, invalid units and blank units;
first, the usage field detection is performed as follows:
step S301, when the usage field meets a first condition, continuing to perform the valid field detection, the data length field detection and the data check field detection in sequence to obtain the initial detection result, wherein the first condition is characterized in that the data unit is not the blank unit;
step S302, when the usage field does not satisfy the first condition and at least one detected data unit is not the blank unit, determining the data unit as the invalid unit;
step S303, determining that the data unit is the blank unit when the usage field does not satisfy the first condition and the detected data units are all the blank units.
Specifically, when the field is all 1, the data unit is represented as a blank unit, when the field is a flag magic word, the data unit is represented as not being the blank unit, the detection of the subsequent field is continued in sequence, and when the field is not all 1 or the flag magic word, the field is proved to be wrong, repair is needed, and the field is set as the flag magic word. And the field can be used for performing a self-checking function, namely, the self-checking can be performed under the condition that the field is in error, so that error checking and even repairing can be performed on various abnormal conditions occurring in the field during the data writing process.
Then, the effective field detection is performed as follows:
step S401, when the usage field satisfies a first condition, continuing to perform the valid field detection, and when the valid field satisfies a second condition, continuing to sequentially perform the data length field detection and the data check field detection, to obtain the initial detection result, wherein the second condition is characterized in that the data unit is the valid unit, and the first condition is characterized in that the data unit is not the blank unit;
Step S402, determining the data unit as the invalid unit when the valid field does not satisfy the second condition.
Specifically, the data unit is represented as an effective unit under the condition that the effective field is all 1, the data unit is proved to be an ineffective unit under the condition that the effective field is a marked magic word, the field is proved to be in error under the condition that the effective field is not all 1 nor is the marked magic word, repair is needed, and the field is set as the marked magic word. And the effective field can perform a self-checking function, namely, can perform self-checking under the condition of field errors, so that error checking and even repairing can be performed on various abnormal conditions of the effective field in the data writing process.
Then, the data length field detection is performed as follows:
step S501, when the usage field meets a first condition and the valid field meets a second condition, continuing to perform the data length field detection, and when the data length field meets a third condition, continuing to perform the data check field detection, to obtain the initial detection result, where the third condition is that a data length represented by the data length field is within a preset length range, the first condition is characterized in that the data unit is not the blank unit, and the second condition is characterized in that the data unit is the valid unit;
Step S502, determining the data unit as the invalid unit when the data length field does not satisfy the third condition.
Specifically, since the data length field does not have a self-checking function, the data length field is used for checking whether an error occurs in the data length field during writing, so that various abnormal conditions occurring in the data length field during data writing can be checked for errors and even repaired.
Finally, the data check field detection is performed according to the following steps:
step S601, when the usage field satisfies a first condition, the valid field satisfies a second condition, and the data length field satisfies a third condition, the data check field detection is continued, and when the data check field satisfies a fourth condition, the data unit is determined to be the valid unit, the fourth condition is that the value of the data check field is a target value and the data written by the data unit is unique, the target value indicates that the data name field, the data length field, and the data content field are correct, the first condition is characterized in that the data unit is not the blank unit, the second condition is characterized in that the data unit is the valid unit, and the third condition is that the data length indicated by the data length field is within a preset length range;
Step S602, determining the data unit as the invalid unit when the data check field does not satisfy the fourth condition and when the field bits of the data check field are not all the preset value;
step S603, repairing the value of the data check field and determining whether the repaired data check field satisfies the fourth condition when the data check field does not satisfy the fourth condition and when the field bits of the data check field are all the preset value.
Specifically, under the condition that the data check field is all 1, the error of the field is proved, the repair is needed, and the new numerical value is obtained by performing Cyclic Redundancy Calculation (CRC) on the data name field, the data length field and the data content field to rewrite the data check field, namely, the data check field cannot be all 1, so that the error check and even the repair can be performed on various abnormal conditions of the data check field in the data writing process.
Step S2022, determining the number of valid units of the memory partition, the number of invalid units of the memory partition, and the number of blank units of the memory partition according to the plurality of initial detection results, so as to obtain the detection results.
Data corruption generally occurs during data writing, and data is checked at the beginning of power-up to ensure data reliability. The power-on data checking process is to check and repair errors possibly occurring in the normal operation process and the data writing process of the power-on data checking process, and determine the current storage partition and the standby storage partition according to a certain judgment basis so as to ensure that the subsequent reading and writing processes can be performed normally.
Step S203, according to at least one of the following: the number of valid units of each storage partition, the number of invalid units of each storage partition, and the number of blank units of each storage partition are determined, and a target partition and a non-target partition are determined, wherein the target partition is the storage partition with the largest number of valid units or the largest number of blank units, the target partition is used for reading and writing data, and the non-target partition is used for continuing to write the data when the target partition is full of data.
Specifically, the data is read and written through the cooperation of the two storage areas, and the data reliability in the reading and writing process is ensured. The memory area operation mainly comprises several main processes of data reading, data writing and power-on data checking. Wherein each power-on data check process identifies a target partition, a non-target partition, and erases the non-target partition data (write-all 1).
The specific implementation steps of step S203 are as follows:
step S2031 of determining, as the target partition, the memory partition having the largest number of effective units when the effective units of at least two memory partitions are different;
for example: a total of 10 memory partitions, wherein the effective unit numbers of 3 memory partitions are different, and the effective unit numbers of the other 7 memory partitions are the same, and the memory partition with the largest effective unit number in the 10 memory partitions is determined as the target partition;
step S2032 of determining, as the target partition, the memory partition having the smallest number of invalid units when the number of valid units of any two memory partitions is the same;
for example, there are 10 storage partitions, where the number of valid units of the 10 storage partitions is the same, but the total number of data units and the number of invalid units of the 10 storage partitions are different, and determining the storage partition with the least number of invalid units of the 10 storage partitions as the target partition;
in step S2033, when the number of valid units of any two of the memory partitions is the same and the number of invalid units of any two of the memory partitions is the same, the memory partition having the largest number of blank units is determined as the target partition.
For example, there are 10 storage partitions, where the number of valid units and the number of invalid units of the 10 storage partitions are the same, but the total number of data units of the 10 storage partitions is different, and determining the storage partition with the largest number of blank units among the 10 storage partitions as the target partition;
specifically, the number of data units of the plurality of memory partitions may be the same or different, and if the number of data units of the plurality of memory partitions is the same, the determination is only required to step S2032, and the determination in step S2033 is not required, whereas if the number of data units of the plurality of memory partitions is different, the determination in step S2033 is further performed. Thus, the maximum number of available units which can be read in the target partition can be ensured, and the maximum number of blank units which can be written in the target partition can be ensured.
Wherein the memory partition is two, according to at least one of the following: after determining the target partition and the non-target partition, the method further includes: copying all valid data in the target partition to the non-target partition and confirming the non-target partition as a current target partition under the condition that target data need to be written and the target partition does not have the blank unit; and erasing the whole content in the target partition, and writing the target data into the current target partition.
The data is written into the blank unit of the current partition in sequence, and the partition switching can be completed by the aid of the standby partition only when the storage partition is full, so that frequent erasing of the storage medium can not be caused. (if the same data name exists, the original data is invalidated).
The method for determining the storage partition of the storage unit comprises the steps of firstly obtaining a plurality of storage partitions, wherein each storage partition comprises a plurality of data units, each data unit stores a plurality of fields, and the plurality of fields comprise a use field, a valid field, a data name field, a data length field, a data content field and a data verification field; detecting each storage partition to obtain a plurality of detection results, wherein the detection results correspond to the storage partitions one by one, the plurality of detection results comprise the effective unit number of the storage partitions, the ineffective unit number of the storage partitions and the blank unit number of the storage partitions, the effective unit number is the number of data units with effective data stored in the storage partitions, the ineffective unit number is the number of data units with ineffective data stored in the storage partitions, and the blank unit number is the number of data units without data stored in the storage partitions; finally according to at least one of the following: the method comprises the steps of determining a target partition and a non-target partition, wherein the target partition is a storage partition with the largest number of effective units or the largest number of blank units, and is used for reading and writing data, and the non-target partition is used for continuing to write the data when the target partition is full of the data. According to the method, the target partition and the non-target partition are determined, so that partition switching is completed by means of one partition when the other partition is full, frequent erasing of the storage medium is not caused, and the problems that the erasing of the storage medium is frequent, the efficiency is low and the service life of the storage medium is influenced in the prior art are solved.
In order to enable those skilled in the art to more clearly understand the technical solutions of the present application, the implementation procedure of the method for determining the storage partition of the storage unit of the present application will be described in detail below with reference to specific embodiments.
The present embodiment relates to a method for determining storage partitions of a specific storage unit, as shown in fig. 4, where the storage partitions are two, and the method includes:
step S1: firstly, carrying out power-on data inspection, then traversing two partitions in sequence from the last data unit of each storage partition, then detecting whether a used field is marked with 1, judging whether the detected data unit is a data unit which is not empty or not under the condition that the used field is marked with 1, proving that the data unit is wrong under the condition that the detected data unit is a data unit which is not empty, setting the data unit as used and invalid, setting the number of invalid units of the storage partition to +1, if the detected data unit is not empty, determining that the data unit is a blank unit, setting the number of blank units of the storage partition +1, then confirming whether the data unit is the last detected data unit, judging a target partition and a non-target partition through the number of valid units, invalid units and blank units if the detected data unit is not empty, and continuously analyzing the next data unit if the detected data unit is not.
Step S2: judging whether the used field is a marked magic word or not under the condition that the used field is not marked with 1, if not, proving that the used field is wrong, repairing, and setting the used field as the marked magic word; if so, detection of the valid field is performed.
Step S3: judging whether the effective field is 1, if the effective field is not 1, determining whether the effective field is a marked magic word, if not, repairing, resetting the effective field as a marked magic word, if the effective field is the marked magic word, determining that the data unit is an invalid unit, storing the number of the invalid units in a partition +1, and then confirming whether the data unit is the last detected data unit, if yes, judging the target partition and the non-target partition according to the number of the effective unit, the invalid unit and the blank unit, otherwise, continuously analyzing the next data unit.
Step S4: and judging whether the data length field exceeds a preset length range under the condition that the effective field mark is 1, determining that the data length field is in error under the condition that the data length field exceeds the preset length range, setting the data unit as invalid, storing the invalid unit number of the partition +1, and confirming whether the data unit is the last detected data unit, if so, judging the target partition and the non-target partition according to the number of the effective unit, the invalid unit and the blank unit, and if not, continuing to analyze the next data unit.
Step S5: judging whether the data check field is 1 or not under the condition that the data length field does not exceed the preset length range, determining that the data check field is wrong under the condition that the data check field is 1, repairing, writing the recalculated check value, namely the effective unit number of the storage partition where the unit is located is +1, and confirming whether the data unit is the last detected data unit, if so, judging the target partition and the non-target partition according to the number of the effective unit, the invalid unit and the blank unit, and if not, continuously analyzing the next data unit.
Step S6: and under the condition that the data check field is not all 1, judging whether the check value is expressed as the error of the data unit, if so, setting the data unit as an invalid unit, and judging whether the data unit is a repeated unit or not, namely comparing the data name field and the data content field of the data unit with the data name field and the data content field of the detected data unit, if not, judging the number of the invalid units in the storage partition to be +1. If the data unit is the repeating unit, the data unit is set as invalid, the number of invalid units in the storage partition is +1, if the data unit is not the repeating unit, the data unit is checked, the number of valid units in the storage partition is +1, whether the data unit is the last detected data unit is confirmed, if the data unit is the last detected data unit, the number of valid units, invalid units and blank units is used for judging the target partition and the non-target partition, and if the data unit is not the repeating unit, the next data unit is continuously analyzed.
After the target partition is determined, all data in the non-target partition is erased, i.e., write-through 1.
In an alternative embodiment, after the power-on data checking process is finished, the method further includes a data writing process, as shown in fig. 5, where the data writing process includes: determining a target partition, judging whether a same-name unit exists and the data content of the same-name unit is consistent with the data content of data to be written, if so, not writing the data, if not, judging whether the target partition has a blank unit, if so, sequentially filling all parts of the blank unit according to the data content to be written, if so, judging whether the same-name unit exists, if so, setting the same-name unit as invalid, if not, ending the process, if not, switching a storage area, copying all effective data of the target partition to a non-target partition, confirming the non-target partition as a current target partition, erasing the content (all written as 1) in the original target partition, positioning the blank unit to the position of the current target partition, sequentially filling all parts of the blank unit according to the data content to be written, and then carrying out a subsequent process. The data is written into the blank unit of the current partition in sequence, and the partition switching can be completed by the aid of the standby partition only when the storage partition is full, so that frequent erasing of the storage medium can not be caused. (if the same data name exists, the original data is invalidated)
As an alternative scheme, the method further includes a data reading process, as shown in fig. 6, including determining a target partition, then reading a data unit, judging whether the data unit is used, ending the flow if not used, continuing to judge whether the data unit is valid if used, judging whether the data name is consistent with the data name to be read if valid, reading the data content according to the data length if consistent, if the data unit is invalid, reading another data unit downstream, and if the data name is inconsistent with the data name to be read, reading another data unit downstream.
And (3) circularly reading the data units in the storage area, wherein the data are sequentially written, and when the current data unit is judged to be unused (blank unit), directly jumping out of the circle (the following data units are blank units).
It should be noted that the steps illustrated in the flowcharts of the figures may be performed in a computer system such as a set of computer executable instructions, and that although a logical order is illustrated in the flowcharts, in some cases the steps illustrated or described may be performed in an order other than that illustrated herein.
The embodiment of the application also provides a device for determining the storage partition of the storage unit, and the device for determining the storage partition of the storage unit can be used for executing the method for determining the storage partition of the storage unit. The device is used for realizing the above embodiments and preferred embodiments, and is not described in detail. As used below, the term "module" may be a combination of software and/or hardware that implements a predetermined function. While the means described in the following embodiments are preferably implemented in software, implementation in hardware, or a combination of software and hardware, is also possible and contemplated.
The following describes a device for determining a memory partition of a memory unit provided in an embodiment of the present application.
Fig. 7 is a schematic diagram of a determination apparatus of a memory partition of a memory unit according to an embodiment of the present application. As shown in fig. 7, the apparatus includes an acquisition unit 10, a detection unit 20, and a determination unit 30, where the acquisition unit 10 is configured to acquire a plurality of memory partitions, each of the memory partitions includes a plurality of data units, each of the data units stores a plurality of fields, and the plurality of fields includes a usage field, a valid field, a data name field, a data length field, a data content field, and a data check field; the detecting unit 20 is configured to detect each of the storage partitions to obtain a plurality of detection results, where the detection results correspond to the storage partitions one by one, and the plurality of detection results include an effective unit number of the storage partitions, an invalid unit number of the storage partitions, and a blank unit number of the storage partitions, where the effective unit number is a number of data units that are effective for data stored in the storage partitions, the invalid unit number is a number of data units that are invalid for data stored in the storage partitions, and the blank unit number is a number of data units that are not storing data in the storage partitions; the determining unit 30 is configured to determine the value according to at least one of: the number of valid units of each storage partition, the number of invalid units of each storage partition, and the number of blank units of each storage partition are determined, and a target partition and a non-target partition are determined, wherein the target partition is the storage partition with the largest number of valid units or the largest number of blank units, the target partition is used for reading and writing data, and the non-target partition is used for continuing to write the data when the target partition is full of data.
The determining unit includes a first determining subunit, a second determining subunit, and a third determining subunit, where the first determining subunit is configured to determine, when the effective unit numbers of at least two of the storage partitions are different, the storage partition with the largest effective unit number as the target partition; the second determining subunit is configured to determine, as the target partition, the memory partition having the smallest number of invalid units when the number of valid units of any two memory partitions is the same; and the third determining subunit is configured to determine, as the target partition, the storage partition with the largest number of blank units when the number of valid units of any two storage partitions is the same and the number of invalid units of any two storage partitions is the same. Thus, the maximum number of available units which can be read in the target partition can be ensured, and the maximum number of blank units which can be written in the target partition can be ensured.
As an alternative scheme, the detection unit includes a detection module and a determination module, where the detection module is configured to sequentially detect, according to a preset sequence, a plurality of the data units in the storage partition, and sequentially perform use field detection, valid field detection, data length field detection, and data check field detection for each of the data units to obtain an initial detection result, where the initial detection result includes that the data unit is one of a valid unit, an invalid unit, and a blank unit; the determining module is configured to determine, according to the plurality of initial detection results, the number of valid units of the storage partition, the number of invalid units of the storage partition, and the number of blank units of the storage partition, so as to obtain the detection results. The subsequent read-write process can be ensured to be normally carried out.
In an alternative embodiment, the detection module includes a first detection submodule, a first determination submodule and a second determination submodule, where the first detection submodule is configured to continue to perform the valid field detection, the data length field detection and the data check field detection in sequence when the usage field meets a first condition, where the first condition is characterized in that the data unit is not the blank unit, to obtain the initial detection result; a first determining submodule, configured to determine, when the usage field does not satisfy the first condition and at least one detected data unit is not the blank unit, that the data unit is the invalid unit; the second determining submodule is configured to determine that the data unit is the blank unit when the usage field does not satisfy the first condition and the detected data units are all the blank units. Thus, error checking and even repairing can be carried out on various abnormal conditions occurring in the using field in the data writing process.
As an alternative, the detection module includes a second detection sub-module and a third determination sub-module, where the second detection sub-module is configured to continue to perform the valid field detection if the usage field meets a first condition, and continue to perform the data length field detection and the data check field detection sequentially if the valid field meets a second condition, to obtain the initial detection result, where the second condition is characterized in that the data unit is the valid unit, and the first condition is characterized in that the data unit is not the blank unit; and the third determining submodule is used for determining the data unit as the invalid unit when the valid field does not meet the second condition. Thus, error checking and even repairing can be carried out on various abnormal conditions of the effective field in the data writing process.
The detection module includes a third detection sub-module and a fourth determination sub-unit, where the third detection sub-module is configured to continue the data length field detection when the usage field meets a first condition and the valid field meets a second condition, and to continue the data check field detection when the data length field meets a third condition, where the third condition is that a data length represented by the data length field is within a preset length range, the first condition is characterized in that the data unit is not the blank unit, and the second condition is characterized in that the data unit is the valid unit, so as to obtain the initial detection result; and a fourth determining subunit configured to determine, when the data length field does not satisfy the third condition, the data unit as the invalid unit. Thus, error checking and even repairing can be carried out on various abnormal conditions of the data length field in the data writing process.
In an alternative embodiment, the detection module includes a fourth detection sub-module, a fifth determination sub-unit, and a sixth determination sub-unit, where the fourth detection sub-module is configured to, when the usage field satisfies a first condition, the valid field satisfies a second condition, and the data length field satisfies a third condition, continue to perform the data check field detection, and when the data check field satisfies a fourth condition, determine that the data unit is the valid unit, the fourth condition is that a value of the data check field is a target value, and the data written by the data unit is unique, the target value indicates that the data name field, the data length field, and the data content field are correct, the first condition is characterized in that the data unit is not the blank unit, the second condition is characterized in that the data unit is the valid unit, and the third condition is that a data length indicated by the data length field is within a preset length range; a fifth determining subunit, configured to determine, when the data check field does not satisfy the fourth condition and when field bits of the data check field are not all the preset values, that the data unit is the invalid unit; the sixth determining subunit is configured to repair the value of the data check field and determine whether the repaired data check field meets the fourth condition when the data check field does not meet the fourth condition and when the field bits of the data check field are all the preset value. Thus, error checking and even repairing can be carried out on various abnormal conditions of the data check field in the data writing process.
In an alternative embodiment, the memory partition is two, and the apparatus further includes a copy unit and an erase unit, the copy unit being configured to perform at least one of: after determining a target partition and a non-target partition, copying all valid data in the target partition to the non-target partition and confirming the non-target partition as a current target partition under the condition that target data need to be written in and the target partition does not have the blank unit after determining the number of valid units of each storage partition, the number of invalid units of each storage partition and the number of blank units of each storage partition; and the erasing unit is used for erasing the whole content in the target partition and writing the target data into the current target partition. The data is written into the blank unit of the current partition in sequence, and the partition switching can be completed by the aid of the standby partition only when the storage partition is full, so that frequent erasing of the storage medium can not be caused. (if the same data name exists, the original data is invalidated).
The determining device of the storage partition of the storage unit is characterized in that the acquiring unit is used for acquiring a plurality of storage partitions, each storage partition comprises a plurality of data units, each data unit stores a plurality of fields, and the plurality of fields comprise a use field, a valid field, a data name field, a data length field, a data content field and a data verification field; the detection unit is used for detecting each storage partition to obtain a plurality of detection results, the detection results are in one-to-one correspondence with the storage partitions, the plurality of detection results comprise the number of effective units of the storage partitions, the number of ineffective units of data stored in the storage partitions and the number of blank units of the storage partitions, wherein the number of effective units is the number of effective data units of data stored in the storage partitions, the number of ineffective units is the number of ineffective data units of data stored in the storage partitions, and the number of blank units is the number of data units without data stored in the storage partitions; the determining unit is used for determining the following according to at least one of the following: the method comprises the steps of determining a target partition and a non-target partition, wherein the target partition is a storage partition with the largest number of effective units or the largest number of blank units, and is used for reading and writing data, and the non-target partition is used for continuing to write the data when the target partition is full of the data. According to the device, the target partition and the non-target partition are determined, so that partition switching is completed by means of one partition when the other partition is full, frequent erasing of the storage medium is not caused, and the problems that the erasing of the storage medium is frequent, the efficiency is low and the service life of the storage medium is influenced in the prior art are solved.
The memory partition determining device of the memory unit includes a processor and a memory, the acquisition unit and the like are stored as program units in the memory, and the processor executes the program units stored in the memory to realize corresponding functions. The modules are all located in the same processor; alternatively, the above modules may be located in different processors in any combination.
The processor includes a kernel, and the kernel fetches the corresponding program unit from the memory. The kernel can be provided with one or more than one, and the problems that the erasing of the storage medium is frequent, the efficiency is low and the service life of the storage medium is influenced in the prior art are solved by adjusting the kernel parameters.
The memory may include volatile memory, random Access Memory (RAM), and/or nonvolatile memory, such as Read Only Memory (ROM) or flash memory (flash RAM), among other forms in computer readable media, the memory including at least one memory chip.
The embodiment of the invention provides a computer readable storage medium, which comprises a stored program, wherein the program is used for controlling a device where the computer readable storage medium is located to execute a method for determining the storage partition of a storage unit.
Specifically, the method for determining the storage partition of the storage unit includes:
step S201, a plurality of storage partitions are obtained, each storage partition comprises a plurality of data units, each data unit stores a plurality of fields, and the plurality of fields comprise a use field, a valid field, a data name field, a data length field, a data content field and a data verification field;
specifically, in general, only two storage partitions need to be set, and the number of data units included in the two storage partitions is equal, as shown in fig. 3, two areas with the same size are divided on the available space of the storage medium, so that the capacity of one storage space can be guaranteed to meet the data storage requirement, in most cases, only one partition (target partition) can be operated, and only when the storage space is used up, data transfer can be performed, and valid data is copied to the other partition (non-target partition, which can also be called as a spare partition). As shown in the following figures, each memory partition is divided into small blocks of the same size, each of which may store one data unit, each of which is in turn made up of several sub-blocks. Initially all data units of the memory area are written to 1. And the storage content is managed in a data unit mode, and the correctness of the reading and writing process is ensured by setting various fields.
Step S202, detecting each storage partition to obtain a plurality of detection results, wherein the detection results are in one-to-one correspondence with the storage partitions, and the plurality of detection results comprise the effective unit number of the storage partitions, the ineffective unit number of the storage partitions and the blank unit number of the storage partitions, the effective unit number is the number of data units effective by data stored in the storage partitions, the ineffective unit number is the number of data units ineffective by data stored in the storage partitions, and the blank unit number is the number of data units not storing data in the storage partitions;
specifically, each time power is applied, data in a plurality of storage partitions are checked, error checking and even repairing can be performed on various abnormal conditions occurring in the data writing process through various measures, a target partition and a non-target partition are determined through a statistical result, and data of the non-target partition is erased (full writing 1).
Step S203, according to at least one of the following: the number of valid units of each storage partition, the number of invalid units of each storage partition, and the number of blank units of each storage partition are determined, and a target partition and a non-target partition are determined, wherein the target partition is the storage partition with the largest number of valid units or the largest number of blank units, the target partition is used for reading and writing data, and the non-target partition is used for continuing to write the data when the target partition is full of data.
Specifically, the data is read and written through the cooperation of the two storage areas, and the data reliability in the reading and writing process is ensured. The memory area operation mainly comprises several main processes of data reading, data writing and power-on data checking. Wherein each power-on data check process identifies a target partition, a non-target partition, and erases the non-target partition data (write-all 1).
The embodiment of the invention provides a processor, which is used for running a program, wherein the program runs to execute a method for determining the memory partition of a memory unit.
Specifically, the method for determining the storage partition of the storage unit includes:
step S201, a plurality of storage partitions are obtained, each storage partition comprises a plurality of data units, each data unit stores a plurality of fields, and the plurality of fields comprise a use field, a valid field, a data name field, a data length field, a data content field and a data verification field;
specifically, in general, only two storage partitions need to be set, and the number of data units included in the two storage partitions is equal, as shown in fig. 3, two areas with the same size are divided on the available space of the storage medium, so that the capacity of one storage space can be guaranteed to meet the data storage requirement, in most cases, only one partition (target partition) can be operated, and only when the storage space is used up, data transfer can be performed, and valid data is copied to the other partition (non-target partition, which can also be called as a spare partition). As shown in the following figures, each memory partition is divided into small blocks of the same size, each of which may store one data unit, each of which is in turn made up of several sub-blocks. Initially all data units of the memory area are written to 1. And the storage content is managed in a data unit mode, and the correctness of the reading and writing process is ensured by setting various fields.
Step S202, detecting each storage partition to obtain a plurality of detection results, wherein the detection results are in one-to-one correspondence with the storage partitions, and the plurality of detection results comprise the effective unit number of the storage partitions, the ineffective unit number of the storage partitions and the blank unit number of the storage partitions, the effective unit number is the number of data units effective by data stored in the storage partitions, the ineffective unit number is the number of data units ineffective by data stored in the storage partitions, and the blank unit number is the number of data units not storing data in the storage partitions;
specifically, each time power is applied, data in a plurality of storage partitions are checked, error checking and even repairing can be performed on various abnormal conditions occurring in the data writing process through various measures, a target partition and a non-target partition are determined through a statistical result, and data of the non-target partition is erased (full writing 1).
Step S203, according to at least one of the following: the number of valid units of each storage partition, the number of invalid units of each storage partition, and the number of blank units of each storage partition are determined, and a target partition and a non-target partition are determined, wherein the target partition is the storage partition with the largest number of valid units or the largest number of blank units, the target partition is used for reading and writing data, and the non-target partition is used for continuing to write the data when the target partition is full of data.
Specifically, the data is read and written through the cooperation of the two storage areas, and the data reliability in the reading and writing process is ensured. The memory area operation mainly comprises several main processes of data reading, data writing and power-on data checking. Wherein each power-on data check process identifies a target partition, a non-target partition, and erases the non-target partition data (write-all 1).
The embodiment of the invention provides equipment, which comprises a processor, a memory and a program stored in the memory and capable of running on the processor, wherein the processor realizes at least the following steps when executing the program:
step S201, a plurality of storage partitions are obtained, each storage partition comprises a plurality of data units, each data unit stores a plurality of fields, and the plurality of fields comprise a use field, a valid field, a data name field, a data length field, a data content field and a data verification field;
step S202, detecting each storage partition to obtain a plurality of detection results, wherein the detection results are in one-to-one correspondence with the storage partitions, and the plurality of detection results comprise the effective unit number of the storage partitions, the ineffective unit number of the storage partitions and the blank unit number of the storage partitions, the effective unit number is the number of data units effective by data stored in the storage partitions, the ineffective unit number is the number of data units ineffective by data stored in the storage partitions, and the blank unit number is the number of data units not storing data in the storage partitions;
Step S203, according to at least one of the following: the number of valid units of each storage partition, the number of invalid units of each storage partition, and the number of blank units of each storage partition are determined, and a target partition and a non-target partition are determined, wherein the target partition is the storage partition with the largest number of valid units or the largest number of blank units, the target partition is used for reading and writing data, and the non-target partition is used for continuing to write the data when the target partition is full of data.
The device herein may be a server, PC, PAD, cell phone, etc.
The present application also provides a computer program product adapted to perform a program initialized with at least the following method steps when executed on a data processing device:
step S201, a plurality of storage partitions are obtained, each storage partition comprises a plurality of data units, each data unit stores a plurality of fields, and the plurality of fields comprise a use field, a valid field, a data name field, a data length field, a data content field and a data verification field;
step S202, detecting each storage partition to obtain a plurality of detection results, wherein the detection results are in one-to-one correspondence with the storage partitions, and the plurality of detection results comprise the effective unit number of the storage partitions, the ineffective unit number of the storage partitions and the blank unit number of the storage partitions, the effective unit number is the number of data units effective by data stored in the storage partitions, the ineffective unit number is the number of data units ineffective by data stored in the storage partitions, and the blank unit number is the number of data units not storing data in the storage partitions;
Step S203, according to at least one of the following: the number of valid units of each storage partition, the number of invalid units of each storage partition, and the number of blank units of each storage partition are determined, and a target partition and a non-target partition are determined, wherein the target partition is the storage partition with the largest number of valid units or the largest number of blank units, the target partition is used for reading and writing data, and the non-target partition is used for continuing to write the data when the target partition is full of data.
It will be appreciated by those skilled in the art that the modules or steps of the invention described above may be implemented in a general purpose computing device, they may be concentrated on a single computing device, or distributed across a network of computing devices, they may be implemented in program code executable by computing devices, so that they may be stored in a storage device for execution by computing devices, and in some cases, the steps shown or described may be performed in a different order than that shown or described herein, or they may be separately fabricated into individual integrated circuit modules, or multiple modules or steps of them may be fabricated into a single integrated circuit module. Thus, the present invention is not limited to any specific combination of hardware and software.
It will be appreciated by those skilled in the art that 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 embodiments of the application. It will be understood that each flow and/or block of the flowchart illustrations and/or block diagrams, and combinations of flows and/or blocks in the flowchart illustrations 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.
In one typical configuration, a computing device includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
The memory may include volatile memory in a computer-readable medium, random Access Memory (RAM) and/or nonvolatile memory, etc., such as Read Only Memory (ROM) or flash RAM. Memory is an example of a computer-readable medium.
Computer readable media, including both non-transitory and non-transitory, removable and non-removable media, may implement information storage by any method or technology. The information may be computer readable instructions, data structures, modules of a program, or other data. Examples of storage media for a computer include, but are not limited to, phase change memory (PRAM), static Random Access Memory (SRAM), dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), read Only Memory (ROM), electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), digital Versatile Discs (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices, or any other non-transmission medium, which can be used to store information that can be accessed by a computing device. Computer-readable media, as defined herein, does not include transitory computer-readable media (transmission media), such as modulated data signals and carrier waves.
It should also be noted that the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article or apparatus that comprises an element.
From the above description, it can be seen that the above embodiments of the present application achieve the following technical effects:
1) Firstly, acquiring a plurality of storage partitions, wherein each storage partition comprises a plurality of data units, each data unit stores a plurality of fields, and each field comprises a use field, a valid field, a data name field, a data length field, a data content field and a data verification field; detecting each storage partition to obtain a plurality of detection results, wherein the detection results correspond to the storage partitions one by one, the plurality of detection results comprise the effective unit number of the storage partitions, the ineffective unit number of the storage partitions and the blank unit number of the storage partitions, the effective unit number is the number of data units with effective data stored in the storage partitions, the ineffective unit number is the number of data units with ineffective data stored in the storage partitions, and the blank unit number is the number of data units without data stored in the storage partitions; finally according to at least one of the following: the method comprises the steps of determining a target partition and a non-target partition, wherein the target partition is a storage partition with the largest number of effective units or the largest number of blank units, and is used for reading and writing data, and the non-target partition is used for continuing to write the data when the target partition is full of the data. According to the method, the target partition and the non-target partition are determined, so that partition switching is completed by means of one partition when the other partition is full, frequent erasing of the storage medium is not caused, and the problems that the erasing of the storage medium is frequent, the efficiency is low and the service life of the storage medium is influenced in the prior art are solved.
The foregoing description is only of the preferred embodiments of the present application and is not intended to limit the same, but rather, various modifications and variations may be made by those skilled in the art. Any modification, equivalent replacement, improvement, etc. made within the spirit and principles of the present application should be included in the protection scope of the present application.

Claims (10)

1. A method for determining a memory partition of a memory cell, comprising:
acquiring a plurality of storage partitions, wherein each storage partition comprises a plurality of data units, each data unit stores a plurality of fields, and the plurality of fields comprise a use field, a valid field, a data name field, a data length field, a data content field and a data verification field;
detecting each storage partition to obtain a plurality of detection results, wherein the detection results are in one-to-one correspondence with the storage partition, the plurality of detection results comprise the effective unit number of the storage partition, the ineffective unit number of the storage partition and the blank unit number of the storage partition, the effective unit number is the number of data units with effective data stored in the storage partition, the ineffective unit number is the number of data units with ineffective data stored in the storage partition, and the blank unit number is the number of data units without data stored in the storage partition;
According to at least one of the following: the method comprises the steps of determining a target partition and a non-target partition, wherein the target partition is the storage partition with the largest effective unit number or the largest blank unit number, the target partition is used for reading and writing data, and the non-target partition is used for continuing to write the data under the condition that the target partition is full of the data.
2. The method of determining according to claim 1, wherein the method is based on at least one of: determining the target partition and the non-target partition from the number of valid units of each of the storage partitions, the number of invalid units of each of the storage partitions, and the number of blank units of each of the storage partitions, comprises:
determining the storage partition with the largest number of effective units as the target partition under the condition that the effective units of at least two storage partitions are different;
determining the storage partition with the least invalid unit number as the target partition under the condition that the valid unit numbers of any two storage partitions are the same;
and determining the storage partition with the largest blank unit number as the target partition under the condition that the effective unit numbers of any two storage partitions are the same and the ineffective unit numbers of any two storage partitions are the same.
3. The method according to claim 1, wherein detecting each of the memory partitions to obtain a plurality of detection results, the detection results corresponding to the memory partitions one by one, comprises:
sequentially detecting a plurality of data units in the storage partition according to a preset sequence, and sequentially performing field detection, effective field detection, data length field detection and data check field detection on each data unit to obtain an initial detection result, wherein the initial detection result comprises one of an effective unit, an ineffective unit and a blank unit;
and determining the effective unit number of the storage partition, the ineffective unit number of the storage partition and the blank unit number of the storage partition according to a plurality of initial detection results to obtain the detection results.
4. A method of determining as claimed in claim 3, wherein the sequentially performing, for each of the data units, the use field detection, the valid field detection, the data length field detection, and the data check field detection to obtain an initial detection result comprises:
continuing to sequentially perform the effective field detection, the data length field detection and the data check field detection under the condition that the used field meets a first condition, wherein the first condition is characterized in that the data unit is not the blank unit, so as to obtain the initial detection result;
Determining that the data unit is the invalid unit if the usage field does not satisfy the first condition and at least one detected data unit is not the blank unit;
and determining that the data unit is the blank unit when the usage field does not meet the first condition and the detected data units are all the blank unit.
5. A method of determining as claimed in claim 3, wherein the sequentially performing, for each of the data units, the use field detection, the valid field detection, the data length field detection, and the data check field detection to obtain an initial detection result comprises:
continuing to perform the valid field detection when the usage field meets a first condition, and continuing to sequentially perform the data length field detection and the data check field detection when the valid field meets a second condition, so as to obtain the initial detection result, wherein the second condition is characterized in that the data unit is the valid unit, and the first condition is characterized in that the data unit is not the blank unit;
and determining the data unit as the invalid unit under the condition that the valid field does not meet the second condition.
6. A method of determining as claimed in claim 3, wherein the sequentially performing, for each of the data units, the use field detection, the valid field detection, the data length field detection, and the data check field detection to obtain an initial detection result comprises:
continuing to perform the data length field detection when the usage field meets a first condition and the valid field meets a second condition, and continuing to perform the data check field detection when the data length field meets a third condition, wherein the third condition is that the data length represented by the data length field is within a preset length range, the first condition is characterized in that the data unit is not the blank unit, and the second condition is characterized in that the data unit is the valid unit, so as to obtain the initial detection result;
and determining the data unit as the invalid unit in the case that the data length field does not meet the third condition.
7. A method of determining as claimed in claim 3, wherein the sequentially performing, for each of the data units, the use field detection, the valid field detection, the data length field detection, and the data check field detection to obtain an initial detection result comprises:
Continuing to perform the data check field detection when the usage field satisfies a first condition, the valid field satisfies a second condition, and the data length field satisfies a third condition, and determining that the data unit is the valid unit when the data check field satisfies a fourth condition, the fourth condition being that the value of the data check field is a target value and the data written by the data unit is unique, the target value indicating that the data name field, the data length field, and the data content field are correct, the first condition being characterized in that the data unit is not the blank unit, the second condition being characterized in that the data unit is the valid unit, and the third condition being that the data length indicated by the data length field is within a preset length range;
determining the data unit as the invalid unit under the condition that the data check field does not meet a fourth condition and the field bits of the data check field are not all of a preset value;
and under the condition that the data check field does not meet the fourth condition and the field bits of the data check field are all the preset value, repairing the numerical value of the data check field and judging whether the repaired data check field meets the fourth condition.
8. The method of any of claims 1 to 7, wherein the memory partition is two, according to at least one of: after determining the target partition and the non-target partition, the method further includes:
copying all valid data in the target partition to the non-target partition under the condition that the target data need to be written and the target partition does not have the blank unit, and confirming the non-target partition as a current target partition;
and erasing the whole content in the target partition, and writing the target data into the current target partition.
9. A computer-readable storage medium, characterized in that the computer-readable storage medium comprises a stored program, wherein the program, when run, controls a device in which the computer-readable storage medium is located to perform the method of determining a storage partition of a storage unit according to any one of claims 1 to 8.
10. An electronic device, comprising: one or more processors, a memory, and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, the one or more programs comprising a method for performing the determination of the storage partitioning of the storage unit of any of claims 1-8.
CN202310275330.0A 2023-03-16 2023-03-16 Method for determining storage partition of storage unit, storage medium and electronic device Pending CN116339628A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310275330.0A CN116339628A (en) 2023-03-16 2023-03-16 Method for determining storage partition of storage unit, storage medium and electronic device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310275330.0A CN116339628A (en) 2023-03-16 2023-03-16 Method for determining storage partition of storage unit, storage medium and electronic device

Publications (1)

Publication Number Publication Date
CN116339628A true CN116339628A (en) 2023-06-27

Family

ID=86892446

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310275330.0A Pending CN116339628A (en) 2023-03-16 2023-03-16 Method for determining storage partition of storage unit, storage medium and electronic device

Country Status (1)

Country Link
CN (1) CN116339628A (en)

Similar Documents

Publication Publication Date Title
KR101675075B1 (en) Method and apparatus for non-volatile ram error re-mapping
CN102449613B (en) Object oriented memory in solid state devices
JP5629391B2 (en) Semiconductor memory device and method for controlling semiconductor memory device
CN108646982B (en) Automatic data restoration method and device based on UBIFS
CN110286853B (en) Data writing method and device and computer readable storage medium
WO2018118837A1 (en) Method to dynamically inject errors in a repairable memory on silicon and a method to validate built-in-self-repair logic
CN102171659A (en) Data error recovery in non-volatile memory
US9881682B1 (en) Fine grained data retention monitoring in solid state drives
CN101369240A (en) System and method for managing memory errors in an information handling system
CN110618892B (en) Bug positioning method and device of solid state disk, electronic equipment and medium
CN104094237A (en) Enhanced error correction in memory devices
US11221933B2 (en) Holdup self-tests for power loss operations on memory systems
CN104282342A (en) Flash memory device, memory controller and control method of flash memory
CN109165115A (en) A method of enhancing FLASH memory reliability
CN109933340A (en) A kind of spacecraft EEPROM in-orbit write-in and self checking method based on page mode
TWI616807B (en) Data writing method and storage controller
US11733909B2 (en) Secure-erase prediction for data storage devices
CN101086715A (en) Method and device for reading CPU code
US9465705B2 (en) Processing a target memory
CN111124294B (en) Sector mapping information management method and device, storage medium and equipment
CN116339628A (en) Method for determining storage partition of storage unit, storage medium and electronic device
CN113434086B (en) Data storage method, device, nonvolatile memory device and memory
CN108108118B (en) Data writing method and storage controller
US9558110B2 (en) Method for managing a flash memory
CN203882621U (en) Storing 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