Search

CN-121999819-A - Data writing method and related device

CN121999819ACN 121999819 ACN121999819 ACN 121999819ACN-121999819-A

Abstract

The application discloses a data writing method and a related device, which relate to the field of distributed control. When the current data writing environment is in a state of being unfavorable for data writing, the data package to be written is split into data segments with the number which is suitable for the current environment and is the target number, and writing is carried out by using smaller data segments, so that the physical influence range and failure cost of single operation are reduced. And when the data writing process of each data segment is sequentially executed according to the arrangement sequence of the target number of data segments, executing a writing cycle of not more than the target number of times for the current data segment in each data writing process, executing a data checking process for the current data segment after the current data segment is written into the flash memory in each writing cycle, and waiting for the target duration after the execution of the writing cycle is completed. By combining the combination of zero integration, one-by-one writing and timely waiting under severe environment, the success rate of the whole writing task is improved.

Inventors

  • ZHANG MINNAN
  • SUN DANFENG
  • CUI XIUYUAN
  • YAO BIN

Assignees

  • 青岛巨商汇网络科技有限公司

Dates

Publication Date
20260508
Application Date
20251231

Claims (10)

  1. 1. A data writing method, comprising: evaluating the current data writing environment of the target equipment according to the monitored temperature and the power supply voltage of the target equipment to obtain environment evaluation result data; Splitting a data packet to be written into data segments with target number when the environment evaluation result data represents that the current data writing environment is in a state of being unfavorable for data writing, wherein the target number is the number corresponding to the adverse degree of the current data writing environment; And sequentially executing the data writing process of each data segment according to the arrangement sequence of the target number of data segments, wherein in each data writing process, a writing cycle of a current data segment is executed, after the current data segment is written into a flash memory in each writing cycle, a data checking process of the current data segment is executed, if the current data segment passes the checking, the execution of the writing cycle is stopped, if the current data segment passes the checking, the writing cycle is continuously executed, the execution times of the writing cycle are not more than the target times, after the writing cycle is executed, the target time is waited, the target times are times corresponding to the adverse degree, and the target time is a time corresponding to the adverse degree.
  2. 2. The data writing method according to claim 1, wherein when the current data writing environment is restored from the unfavorable data writing state to the favorable data writing state, further comprising: And sequentially reading out the data segments of the target number, merging the data segments of the target number into a data packet, and writing the data packet into a target flash memory area.
  3. 3. The data writing method according to claim 2, wherein the determining of the target flash memory area includes: Determining a wear distribution histogram of each area according to the erasing times of each area of the flash memory; And determining the target flash memory area from the wear distribution histogram by taking wear balance of each area as a target.
  4. 4. A data writing method according to any one of claims 1 to 3, further comprising: Counting the occurrence times of the verification failure of the current data writing environment, and increasing the target number when the occurrence times are not smaller than a first threshold value.
  5. 5. The data writing method according to claim 3, wherein the process of determining that the current data writing environment is recovered from the unfavorable data writing state to the favorable data writing state includes: If the duration of the target device in the writing recovery state is not less than the set duration, determining that the current data writing environment is recovered to a state favorable for data writing, wherein the writing recovery state comprises that the monitoring temperature is in a first preset range and the power supply voltage is in a second preset range.
  6. 6. The data writing method according to claim 1, wherein the target number decreases as the degree of disadvantage of the current data writing environment increases, and the target number increases as the degree of disadvantage of the current data writing environment increases.
  7. 7. A data writing apparatus, comprising: the writing environment evaluation module is used for evaluating the current data writing environment of the target equipment according to the monitored temperature and the power supply voltage of the target equipment to obtain environment evaluation result data; A writing data segmentation module for splitting a data packet to be written into a target number of data segments when the environment evaluation result data characterize that the current data writing environment is in a state of being unfavorable for data writing, the target number being a number corresponding to the degree of the unfavorable of the current data writing environment, and And the writing process control module is used for sequentially executing the data writing process of each data segment according to the arrangement sequence of the target number of data segments, executing a writing cycle of the current data segment in each data writing process, executing a data checking process of the current data segment after writing the current data segment into the flash memory in each writing cycle, stopping executing the writing cycle if the current data segment passes the checking, continuously executing the writing cycle if the current data segment does not pass the checking, wherein the execution times of the writing cycle are not more than the target times, waiting for a target time after the writing cycle is executed, wherein the target times are times corresponding to the adverse degree, and the target time is a time corresponding to the adverse degree.
  8. 8. A computer program product comprising computer readable instructions which, when run on an electronic device, cause the electronic device to implement the data writing method of any of claims 1 to 6.
  9. 9. An electronic device comprising at least one processor and a memory coupled to the processor, wherein: the memory is used for storing a computer program; the processor is configured to execute the computer program to enable the electronic device to implement the data writing method according to any one of claims 1 to 6.
  10. 10. A computer storage medium carrying one or more computer programs which, when executed by an electronic device, enable the electronic device to implement a data writing method as claimed in any one of claims 1 to 6.

Description

Data writing method and related device Technical Field The present application relates to the field of distributed systems, and in particular, to a data writing method and related apparatus. Background Flash memory, as a non-volatile storage medium, is a very delicate physical process that precisely injects electrons into the floating gate/charge trapping layer, primarily by incremental step pulse programming, which is highly sensitive to the operating environment. However, edge devices (such as an internet of things gateway, a vehicle-mounted terminal, an industrial controller and the like) are often deployed in harsh and fluctuating environments, and often face challenges such as high temperature and unstable power supply. These operating scenarios of edge devices just magnify these physical limitations, such as the outdoor monitoring device's temperature surge in summer insolation, the battery-powered mobile sensor still having to record the last data before the power is exhausted, etc. The success rate of flash writing will be seriously affected in these scenarios, and the running of the device is being produced. Disclosure of Invention In view of the above, the present application provides a data writing method and related apparatus, so as to achieve the purpose of improving the writing success rate. The specific scheme is as follows: the first aspect of the present application provides a data writing method, including: evaluating the current data writing environment of the target equipment according to the monitored temperature and the power supply voltage of the target equipment to obtain environment evaluation result data; Splitting a data packet to be written into data segments with target number when the environment evaluation result data represents that the current data writing environment is in a state of being unfavorable for data writing, wherein the target number is the number corresponding to the adverse degree of the current data writing environment; And sequentially executing the data writing process of each data segment according to the arrangement sequence of the target number of data segments, wherein in each data writing process, a writing cycle of a current data segment is executed, after the current data segment is written into a flash memory in each writing cycle, a data checking process of the current data segment is executed, if the current data segment passes the checking, the execution of the writing cycle is stopped, if the current data segment passes the checking, the writing cycle is continuously executed, the execution times of the writing cycle are not more than the target times, after the writing cycle is executed, the target time is waited, the target times are times corresponding to the adverse degree, and the target time is a time corresponding to the adverse degree. In one possible implementation, when the current data writing environment is recovered from the state unfavorable for data writing to the state favorable for data writing, the method further includes: And sequentially reading out the data segments of the target number, merging the data segments of the target number into a data packet, and writing the data packet into a target flash memory area. In one possible implementation, the determining the target flash memory area includes: Determining a wear distribution histogram of each area according to the erasing times of each area of the flash memory; And determining the target flash memory area from the wear distribution histogram by taking wear balance of each area as a target. In one possible implementation, the data writing method further includes: Counting the occurrence times of the verification failure of the current data writing environment, and increasing the target number when the occurrence times are not smaller than a first threshold value. In one possible implementation, the determining process that the current data writing environment is recovered from the unfavorable data writing state to the favorable data writing state includes: If the duration of the target device in the writing recovery state is not less than the set duration, determining that the current data writing environment is recovered to a state favorable for data writing, wherein the writing recovery state comprises that the monitoring temperature is in a first preset range and the power supply voltage is in a second preset range. In one possible implementation, the target number decreases as the level of the current data writing environment increases, and the target number increases as the level of the current data writing environment increases. A second aspect of the present application provides a data writing apparatus comprising: the writing environment evaluation module is used for evaluating the current data writing environment of the target equipment according to the monitored temperature and the power supply voltage of the target equipment to obtain environment evaluation res