Write-in method, device and equipment of nonvolatile memory
By randomly selecting blank spare cells in non-volatile memory for data storage, the problem of reduced storage reliability and shortened life caused by multiple erasing of fixed addresses is solved, and the memory life is extended and storage efficiency is improved.
Patent Information
- Application Number
- CN202411296574.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-14
- Publication Date
- 2025-01-21
- Estimated Expiration
- 2044-09-14
AI Technical Summary
In the prior art, nonvolatile memory is erased multiple times at a fixed address, resulting in a decrease in storage reliability and a shortened lifetime.
By dividing the storage space of non -easy -to -sex memory into multiple reserve units, when receiving data storage requests, a blank preparatory unit is randomly selected as the storage unit and management unit, and the index number of the data object is recorded when writing the data. The index number, address offset and storage times of the storage unit.
It effectively avoids the frequent erasing and writing of fixed addresses, extends the service life of non-volatile memory, and improves the storage efficiency of the memory.
Smart Images

Figure CN119336253A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of data storage, and in particular to a method, device and equipment for writing into a non-volatile memory. Background Art
[0002] Non-volatile memory NVM is widely used in various electronic products because of its non-volatility, byte-by-byte access, high storage density, low energy consumption, high read and write performance, and the fact that the stored data can still be retained in the non-volatile memory without being lost when the power is turned off or a crash occurs.
[0003] In the related art, data is usually stored in the storage unit of the non-volatile memory in sequence, which may cause multiple erasures and writes at fixed addresses. Since the non-volatile memory device itself has a write durability problem, the total number of write operations that can be performed on each storage unit is limited. When the number of erasures and writes is too many, the storage reliability will decrease, which may shorten the life of the non-volatile memory and cause the entire memory to be unable to be used normally.
[0004] Therefore, how to effectively utilize non-volatile memory and extend its service life is a technical problem that needs to be solved urgently. Summary of the invention
[0005] The present application provides a writing method and device for a non-volatile memory, which can solve the technical problem in the prior art that sequentially storing data in a storage unit of a non-volatile memory may result in multiple erasing and writing at a fixed address, thereby shortening the life of the non-volatile memory.
[0006] In a first aspect, an embodiment of the present application provides a method for writing to a non-volatile memory, the method for writing to the non-volatile memory comprising:
[0007] The storage space of the non-volatile memory NVM includes a plurality of preparation units;
[0008] When a data storage request is received for the first time, any preparation unit is randomly selected from the blank preparation units of the plurality of preparation units as a storage unit, and the value of the data object is written into the storage unit, and any preparation unit is randomly selected from the blank preparation units as a management unit, and management information of the data object is written into the management unit, wherein the management information includes an index number of the data object, an index number of the storage unit where the data object is located, an address offset of the storage unit where the data object is located, and a storage count of the data object;
[0009] When a new data storage request is received, the value of the new data object is then written into the storage unit in which the value of the previous data object was written, and the management information of the new data object is then written into the management unit in which the management information of the previous data object was written. If the storage unit in which the value of the previous data object was written is full, any spare unit is randomly selected from the blank spare units as the storage unit and the value of the new data object is written therein. If the management unit in which the management information of the previous data object is written is full, any spare unit is randomly selected from the blank spare units as the management unit and the management information of the new data object is written therein.
[0010] In combination with the first aspect, in one implementation, after receiving the data storage request and before writing the value of the data object into the storage unit, the method further includes:
[0011] Sort the data objects according to the preset sorting rules and generate a unique corresponding index number for each data object;
[0012] When the value of the data object is written into the storage unit, the index number of the data object is written into the storage unit.
[0013] In one embodiment, writing the value of the data object into a storage unit further includes:
[0014] determining whether the storage cell is a blank cell;
[0015] If yes, then after writing a preset first identifier at the start byte of the storage unit, the value of the data object is written into the storage unit;
[0016] Otherwise, the value of the data object is directly written to the storage unit.
[0017] In one implementation, writing management information of a data object into a management unit includes:
[0018] If the index number of the data object already exists in the management unit and the value of the data object has not changed, the management information of the data object is not written into the management unit; otherwise, the management information of the data object is written into the management unit;
[0019] When writing the management information of the data object in the management unit, if the management unit is a blank unit, the preset second identifier is written at the starting byte of the management unit, and then the management information of the data object is written; otherwise, the management information of the data object is directly written in the management unit.
[0020] In one embodiment, the method further comprises:
[0021] Reading the history management information of each data object in the management unit according to the index number of each data object, and determining the target history management information with the largest number of storage times corresponding to each data object;
[0022] The target history management information corresponding to each data object is stored in a preset history data summary unit, and any blank preparation unit is randomly selected as a summary management unit for managing the history data summary unit, and the index number and address offset of the history data summary unit are stored in the summary management unit, wherein the starting byte of the summary management unit is a preset third identifier;
[0023] The historical data summary unit is read to obtain the target historical management information of each data object, and the latest value of the corresponding data object is determined according to the target historical management information, and stored in a preset memory image.
[0024] In one embodiment, after storing the latest value of each data object into the preset memory image, the method further includes:
[0025] When the management information of any data object is updated, after the latest value corresponding to the updated management information is successfully written into the storage unit, the latest value corresponding to the updated management information is read back and replaces the value of the corresponding data object in the memory image.
[0026] In one embodiment, the method further comprises:
[0027] When a preset proportion of the reserve units in the storage space are filled, a blank reserve unit is randomly selected as an update management unit and an update storage unit respectively;
[0028] Writing the latest value of each data object into the update storage unit, determining the update management information of each data object according to the position of the latest value of each data object in the update storage unit, writing the update management information of each data object into the update management unit, and clearing the storage times of the corresponding data object in each update management information;
[0029] After the NVM is powered on again, determining whether the latest value of the data object written into the update storage unit and the update management information written into the update management unit are all stored successfully;
[0030] If so, data in all units except the update management unit and the update storage unit are erased.
[0031] In one embodiment, the method further comprises:
[0032] If the latest value of the data object written into the update storage unit and the update management information written into the update management unit are not all stored successfully, the latest value of the data object that is not successfully stored is written into the update storage unit again, and the corresponding update management information is written into the update management unit again, wherein the number of storage times of the data object in the update management information of the corresponding data object is increased by 1 each time the data object is written;
[0033] When the latest values of all data objects and the corresponding update management information are still not successfully stored in the update storage unit and the update management unit for N consecutive times, an NVM failure reminder is issued.
[0034] In a second aspect, an embodiment of the present application provides a writing device for a non-volatile memory, the writing device for the non-volatile memory comprising: a first writing module and a second writing module, the storage space of the non-volatile memory NVM comprising a plurality of preparation units;
[0035] The first writing module is used to, when receiving a data storage request for the first time, randomly select any prepared unit from the blank prepared units of the plurality of prepared units as a storage unit, and write the value of the data object into the storage unit, randomly select any prepared unit from the blank prepared units as a management unit, and write the management information of the data object into the management unit, wherein the management information includes an index number of the data object, an index number of the storage unit where the data object is located, an address offset of the storage unit where the data object is located, and a storage count of the data object;
[0036] The second writing module is used to, when receiving a new data storage request, continue to write the value of the new data object in the storage unit in which the value of the previous data object was written, and continue to write the management information of the new data object in the management unit in which the management information of the previous data object was written; if the storage unit in which the value of the previous data object was written is full, randomly select any spare unit in the blank spare unit as the storage unit and write the value of the new data object; if the management unit in which the management information of the previous data object was written is full, randomly select any spare unit in the blank spare unit as the management unit and write the management information of the new data object.
[0037] The embodiment of the present application provides a writing method, device and equipment for a non-volatile memory, in which the storage space of the non-volatile memory NVM includes multiple preparation units. When a data storage request is received for the first time, any preparation unit is randomly selected from the blank preparation units of the multiple preparation units as a storage unit, and the value of the data object is written into the storage unit, and any preparation unit is randomly selected from the blank preparation units as a management unit, and the management information of the data object is written into the management unit, wherein the management information includes the index number of the data object, the index number of the storage unit where the data object is located, the address offset of the storage unit where the data object is located, and the number of times the data object is stored; when a new data storage request is received, The value of the new data object is then written into the storage unit in which the value of the previous data object is written, and the management information of the new data object is then written into the management unit in which the management information of the previous data object is written. If the storage unit in which the value of the previous data object is written is full, then any spare unit is randomly selected from the blank spare units as the storage unit and the value of the new data object is written therein. If the management unit in which the management information of the previous data object is written is full, then any spare unit is randomly selected from the blank spare units as the management unit and the management information of the new data object is written therein. This effectively avoids frequent storage and multiple erasures at a fixed address, and effectively improves the life of the non-volatile memory. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] Figure 1 A flowchart of an embodiment of a method for writing into a non-volatile memory of the present application;
[0039] Figure 2 This is a functional module diagram of an embodiment of a writing device for a non-volatile memory of the present application.
[0040] Figure 3 Schematic diagram of the hardware structure of the non-volatile memory writing device involved in the embodiments of the present application. DETAILED DESCRIPTION
[0041] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0042] In order to make the objectives, technical solutions and advantages of the present application clearer, the implementation methods of the present application will be further described in detail below with reference to the accompanying drawings.
[0043] In a first aspect, an embodiment of the present application provides a method for writing into a non-volatile memory.
[0044] In one embodiment, referring to Figure 1 , Figure 1 FIG. 1 is a flow chart of the first embodiment of the writing method of the non-volatile memory of the present application. Figure 1 As shown, the writing method of the non-volatile memory includes:
[0045] Step S101, the storage space of the non-volatile memory NVM includes multiple preparation units. When a data storage request is received for the first time, any preparation unit is randomly selected from the blank preparation units of the multiple preparation units as a storage unit, and the value of the data object is written into the storage unit. Any preparation unit is randomly selected from the blank preparation units as a management unit, and management information of the data object is written into the management unit, wherein the management information includes an index number of the data object, an index number of the storage unit where the data object is located, an address offset of the storage unit where the data object is located, and the number of storage times of the data object.
[0046] It is worth noting that before step S101, the storage space of the non-volatile memory NVM can be divided into n preparation units according to a division rule such as a preset space step length or the length of data to be written. When dividing, the storage space can be equally divided to obtain n preparation units of the same size, which is beneficial to the life of the memory.
[0047] Explanatory, a data object usually refers to an entity that can store and manipulate data. It can be a variable, a data structure, a file, or a database record. Data objects usually have a type, and values are a specific type of data. Data objects are containers for storing and manipulating values, and values are the information stored by data objects.
[0048] In this embodiment, each data storage request may include storage requests for multiple data objects. After receiving the data storage request, before writing the value of the data object into the storage unit, it also includes: sorting the data objects according to the preset sorting rules, and generating a unique corresponding index number for each data object. Among them, the sorting rules include sorting the data objects according to the importance of the data objects, or sorting the data objects according to the preset sorting rules such as the alphabetical order of the data objects. The length of the index number of the data object generated in this embodiment is len bytes, and the value of len can be set according to the requirements.
[0049] It should be understood that the data objects included in different data storage requests may be different or the same. For example, the first data storage request may include storage requests for the first data object, the second data object, and the third data object, and unique corresponding index numbers are generated for the first data object, the second data object, and the third data object respectively; the second data storage request may include storage requests for the first data object, the second data object, and a new fourth data object, and a unique corresponding index number is generated for the fourth data object. The first data object and the second data object already have unique corresponding index numbers, and there is no need to generate index numbers again; the third data storage request may include storage requests for the first data object, the second data object, and the third data object. The values of the same data object under different data storage requests may be different or the same. For example, the value of the first data object in the first data storage request is 1, the value in the second data storage request is 2, and the value in the third data storage request is 2. When the same data object requests to store different values, the index number of the data object remains unchanged.
[0050] In one embodiment, after a storage unit is selected, a unique corresponding index number is generated for each storage unit according to the generation order of each storage unit; after a management unit is selected, a unique corresponding index number is generated for each management unit according to the generation order of each management unit.
[0051] Exemplarily, when a data storage request is received for the first time, the n divided preparation units are all blank preparation units, and a preparation unit is randomly selected from the n blank preparation units as a storage unit, and an index number A0 uniquely corresponding to the storage unit is generated to represent the first storage unit; a preparation unit is randomly selected from the n-1 blank preparation units other than the storage unit A0 as a management unit, and an index number B0 uniquely corresponding to the management unit is generated to represent the first management unit.
[0052] Furthermore, after a unique corresponding index number is generated for each data object and a storage unit is randomly selected, the value of the data object can be written into the selected storage unit for storage.
[0053] In one embodiment, writing the value of a data object into a storage unit also includes: determining whether the storage unit is a blank unit, wherein a blank unit refers to an empty unit without any data written therein. If the storage unit is a blank unit, a preset first identifier is written at the starting byte of the storage unit, and then the value of the data object is written into the storage unit. The first identifier is used to mark the unit as a storage unit, for example, the first identifier can be 0xAA. If the storage unit already has the value of a data object written therein, that is, it is a non-blank unit, the first identifier has already been written when the value of the existing data object was written therein, and therefore the value of the data object can be directly written into the storage unit. Therefore, it can be understood that the starting byte of the storage unit is the first identifier.
[0054] It can be understood that when it is not the first time that a data storage request is received, there may be multiple storage cells in the non-volatile memory, that is, there are storage cells that are already full. At this time, to determine whether a storage cell is a blank cell, what is determined is whether the last storage cell is a blank cell, that is, to determine whether the latest storage cell is a blank cell.
[0055] In this embodiment, when a data storage request is received for the first time, the storage unit A0 is a blank unit, so 0xAA is written in the start byte of the storage unit A0 and then the value of the data object is written.
[0056] Furthermore, in one embodiment, the management information of a data object is written into a management unit, including: first determining whether the index number of the data object already exists in the management unit; if the index number of the data object already exists in the management unit, it indicates that a value has been stored in the data object; then determining whether the value of the data object has changed; if the value of the data object has not changed, the management information of the data object is not written into the management unit, so as to avoid repeated recording of management information for the same value of the same data object and wasting storage space; otherwise, the management information of the data object is written into the management unit.
[0057] It is worth noting that before writing the management information of the data object into the management unit, it also includes determining whether the management unit is a blank unit. If the management unit is a blank unit, the index number of the data object is written into the management unit after writing the preset second identifier at the starting byte of the management unit. The second identifier is used to mark the unit as a management unit, and the second identifier in this embodiment is the 0x55 identifier. If the management information has been written into the management unit, that is, it is a non-blank unit, the second identifier has been written when the existing management information is written, so the management information of the data object can be directly written into the management unit. Therefore, it can be understood that the starting byte of the management unit is the second identifier.
[0058] In this embodiment, when a data storage request is received for the first time, the selected management unit B0 is a blank unit. Therefore, 0x55 is written in the starting byte of the management unit B0 and then the management information of the data object is written to complete the response to the data storage request received for the first time.
[0059] As a preferred implementation, when writing the value of the data object into the storage unit, the index number of the data object can be written into the storage unit at the same time. When the value of the data object in the storage unit is read later according to the management information in the management unit, the index number of the data object in the storage unit and the index number of the data object in the management information can be compared and verified to ensure the accuracy of the value of the read data object.
[0060] Step S102, when a new data storage request is received, the value of the new data object is then written into the storage unit in which the value of the previous data object was written, and the management information of the new data object is then written into the management unit in which the management information of the previous data object was written; if the storage unit in which the value of the previous data object was written is full, any spare unit is randomly selected from the blank spare units as the storage unit and the value of the new data object is written therein; if the management unit in which the management information of the previous data object is written is full, any spare unit is randomly selected from the blank spare units as the management unit and the management information of the new data object is written therein.
[0061] For example, if the new data storage request is the second data storage request, the last data object in the first data storage request is the previous data object of the first data storage request. Therefore, when storing the value of the data object in the second data storage request, writing can be started from the next byte of the value of the last data object in the first data storage request in the storage unit, which can improve the utilization rate of the storage unit and avoid wasting the storage position in the storage unit.
[0062] If the first storage unit is full but the value of the data object in the second data storage request has not been written, a preparatory unit can be randomly selected from the n-2 preparatory units except the first storage unit A0 and the first management unit B0 as the storage unit, and the index number of the storage unit is A1, indicating the second storage unit, and since the second storage unit is an empty unit, 0xAA needs to be written at its initial byte, and then the value of the data object that has not been written in the second data storage request can be written into the second storage unit A1. When writing the value of a new data object in a new data storage request, it can be written in the same way as above.
[0063] Similarly, if the management unit is full, the preparatory unit that has been selected as the storage unit and the management unit is excluded, and a preparatory unit is randomly selected from the blank preparatory units as the management unit. The index number corresponding to the management unit is generated according to the generation order of the management unit, and 0x55 is written at its initial byte, and then the management information of the data object is continued to be written.
[0064] The index number of the newly selected storage unit is the value of the previous storage unit index number plus 1, and the index number of the newly selected management unit is the value of the previous management unit index number plus 1.
[0065] It is worth noting that the management system of the non-volatile memory NVM will count and record whether each storage unit and each management unit is full, and can record the index number of the full unit. According to the index number of the storage unit and the management unit, the value of the data object and the management information can be written into the corresponding unfilled storage unit and management unit.
[0066] It should be understood that this embodiment divides the storage space of the non-volatile memory into multiple preparatory units, and randomly selects a preparatory unit from multiple blank preparatory units as a storage unit and a management unit to store the value of the data object and the corresponding management information, thereby realizing random storage of the value of the data object and the management information, and will not perform overly frequent erasing and writing at a fixed address of the non-volatile memory, thereby effectively improving the life of the non-volatile memory. In addition, the stored management information includes the index number of the data object, the index number of the storage unit where the data object is located, the address offset of the storage unit where the data object is located, and the number of storage times of the data object, which can ensure that the value of the corresponding data object can be read accurately and quickly according to the management information.
[0067] In one embodiment, the writing method of the non-volatile memory of the present application further includes reading the latest value of each data object and storing it in a preset memory image, specifically including:
[0068] The historical management information of each data object is read in the management unit according to the index number of each data object, and the target historical management information with the largest storage times corresponding to each data object is determined. The target historical management information corresponding to each data object is stored in a preset historical data summary unit, and any blank preparatory unit is randomly selected as a summary management unit for managing the historical data summary unit, and the index number and address offset of the historical data summary unit are stored in the summary management unit, wherein the starting byte of the summary management unit is a preset third identifier. The target historical management information of each data object is obtained by reading the historical data summary unit, and the latest value of the corresponding data object is determined according to the target historical management information, and stored in a preset memory mirror. Among them, the embodiment of the present application is exemplified by taking the memory mirror as a RAM mirror.
[0069] Among them, a preparation unit can be randomly selected from the blank preparation units as the preset historical data summary unit, and a preset fourth identifier can be written at the starting byte of the historical data summary unit to indicate that the unit is a historical data summary unit; or when the latest selected management unit is not full, the management unit can be selected directly as the historical data summary unit, and before storing the target historical management information corresponding to each data object, the fourth identifier can be written first to indicate that the subsequently written content is the target historical management information.
[0070] It is worth noting that the above steps can be performed after the non-volatile memory NVM is powered on and when the management information of the data object is not updated.
[0071] It should be understood that the historical management information of a data object refers to the management information that has been stored in the management unit. The more times the management information is stored, the newer it is. Therefore, the latest value of the data object can be found in the storage unit according to the historical management information with the largest number of storage times corresponding to each data object. In this embodiment, by storing the historical management information with the largest number of storage times corresponding to each data object in a preset historical data summary unit, and storing the latest value of each data object in a preset RAM image, it is possible to directly read the historical data summary unit or directly access the RAM image to read the latest value of the data object, which can effectively improve the data reading efficiency.
[0072] In one embodiment, when the management information of any data object is updated, after the latest value corresponding to the updated management information is successfully written into the storage unit, the latest value corresponding to the updated management information is read back and the value of the corresponding data object in the memory mirror is replaced, thereby achieving the ability to read the latest value of the data object in the memory mirror after the value of the data object is updated, thereby improving the reading speed.
[0073] In a preferred embodiment, when data is stored according to the method described above, when the storage space of the non-volatile memory is about to be full, the latest value and the latest management information of the data object can be backed up, and then the storage unit and the management unit can be uniformly erased. On the one hand, this can reduce the data loss rate, and on the other hand, it can reduce the number of times the unit is erased.
[0074] Specifically, when a preset ratio of the preparation units in the storage space is filled, a blank preparation unit is randomly selected as an update management unit and an update storage unit, the latest value of each data object is written into the update storage unit, the update management information of each data object is determined according to the position of the latest value of each data object in the update storage unit, and the update management information of each data object is written into the update management unit, and the storage times of the corresponding data object in each update management information are cleared.
[0075] In this embodiment, it can be set that when a preset proportion of cells in the storage space is full, the remaining blank preparation cells are M. A preparation cell is randomly selected from the M blank preparation cells as an update storage cell, and a preparation cell is randomly selected from the remaining M-1 blank preparation cells as an update management cell, and the latest value of each data object is written into the update storage cell, and the latest management information of each data object is written into the update storage cell.
[0076] Next, after the NVM is powered on again, it is determined whether the latest value of the data object written into the update storage unit and the update management information written into the update management unit are all successfully stored; if so, data of all units except the update management unit and the update storage unit are erased. The latest value of the data object and the latest management information are backed up and then erased uniformly.
[0077] In one embodiment, if the latest value of the data object written into the update storage unit and the update management information written into the update management unit are not all stored successfully, the latest value of the data object that has not been stored successfully is written again into the update storage unit, and the corresponding update management information is written again into the update management unit, wherein the storage count of the data object in the update management information of the corresponding data object is increased by 1 each time it is written.
[0078] Specifically, in the process of writing the latest value of the data object that was not successfully stored into the update storage unit again and writing the corresponding update management information into the update management unit again, if the update storage unit is full, a blank preparation unit is randomly selected again as a new update storage unit, and the latest value of the data object that was not successfully stored is written into the new update storage unit; if the update management unit is full, a blank preparation unit is randomly selected again as a new update management unit, and the update management information corresponding to the data object that was not successfully stored is written into the new update management unit.
[0079] Exemplarily, when the latest value of the data object written into the update storage unit and the update management information written into the update management unit are not all stored successfully, the data object that is not successfully stored is determined. The latest value of the data object that is not successfully stored is written again to the next byte after the latest value of the data object that was last written into the update storage unit, and the update management information of the data object that is not successfully stored is written again to the next byte after the update management information of the data object that was last written into the update management unit. If the update storage unit is full, one of the M-2 blank reserve units is selected as a new update storage unit, and the latest value of the data object that is not successfully stored is written into the new update storage unit. If the update storage unit is full, one of the M-3 blank reserve units is selected as a new update management unit, and the update management information of the data object that is not successfully stored is written into the new update management unit.
[0080] When the latest values of all data objects and the corresponding update management information are still not successfully stored in the update storage unit and the update management unit for N consecutive times, an NVM fault reminder is issued and reported to the fault management module to notify the technicians to perform maintenance.
[0081] The writing method of the non-volatile memory provided by the embodiment of the present application has the beneficial effect that: by dividing the storage space of the non-volatile memory into a plurality of preparatory units, and randomly selecting a preparatory unit from the plurality of preparatory units as a storage unit and a management unit to store the value of the data object and the management information, random storage of data is realized, and over-frequent erasing and writing will not be performed at a fixed address of the non-volatile memory, which effectively improves the life of the non-volatile memory. And by storing the latest value of the data object in the RAM image, the reading efficiency of the data object can be effectively improved. And when the storage space of the non-volatile memory is almost full, the latest value and management information of the data object are first backed up to the update management unit and the update storage unit, and then the units except the update management unit and the update storage unit are erased, which can effectively reduce the data loss rate, and when the storage space is almost full, the overall erasing is performed, which effectively reduces the number of erasing and writing of the storage space and improves the life of the non-volatile memory.
[0082] In a second aspect, an embodiment of the present application also provides a writing device for a non-volatile memory.
[0083] In one embodiment, referring to Figure 2 , Figure 2 Schematic diagram of functional modules of an embodiment of a writing device for a non-volatile memory of the present application. Figure 2 As shown, the writing device of the non-volatile memory includes: a first writing module and a second writing module, and the storage space of the non-volatile memory NVM includes a plurality of preparation units;
[0084] The first writing module is used to, when receiving a data storage request for the first time, randomly select any prepared unit from the blank prepared units of the plurality of prepared units as a storage unit, and write the value of the data object into the storage unit, randomly select any prepared unit from the blank prepared units as a management unit, and write the management information of the data object into the management unit, wherein the management information includes an index number of the data object, an index number of the storage unit where the data object is located, an address offset of the storage unit where the data object is located, and a storage count of the data object;
[0085] The second writing module is used to, when receiving a new data storage request, continue to write the value of the new data object in the storage unit in which the value of the previous data object was written, and continue to write the management information of the new data object in the management unit in which the management information of the previous data object was written; if the storage unit in which the value of the previous data object was written is full, randomly select any spare unit in the blank spare unit as the storage unit and write the value of the new data object; if the management unit in which the management information of the previous data object was written is full, randomly select any spare unit in the blank spare unit as the management unit and write the management information of the new data object.
[0086] Furthermore, in one embodiment, the first writing module and the second writing module are further used to: sort the data objects according to a preset sorting rule, and generate a unique corresponding index number for each data object;
[0087] When the value of the data object is written into the storage unit, the index number of the data object is written into the storage unit.
[0088] Furthermore, in one embodiment, the first writing module and the second writing module are further configured to:
[0089] determining whether the storage cell is a blank cell;
[0090] If yes, then after writing a preset first identifier at the start byte of the storage unit, the value of the data object is written into the storage unit;
[0091] Otherwise, the value of the data object is directly written to the storage unit.
[0092] Furthermore, in one embodiment, the first writing module and the second writing module are further configured to:
[0093] If the index number of the data object already exists in the management unit and the value of the data object has not changed, the management information of the data object is not written into the management unit; otherwise, the management information of the data object is written into the management unit;
[0094] When writing the management information of the data object in the management unit, if the management unit is a blank unit, the preset second identifier is written at the starting byte of the management unit, and then the management information of the data object is written; otherwise, the management information of the data object is directly written in the management unit.
[0095] Furthermore, in one embodiment, the device further includes a storage module, and the storage module is used to:
[0096] Reading the history management information of each data object in the management unit according to the index number of each data object, and determining the target history management information with the largest number of storage times corresponding to each data object;
[0097] The target history management information corresponding to each data object is stored in a preset history data summary unit, and any blank preparation unit is randomly selected as a summary management unit for managing the history data summary unit, and the index number and address offset of the history data summary unit are stored in the summary management unit, wherein the starting byte of the summary management unit is a preset third identifier;
[0098] The historical data summary unit is read to obtain the target historical management information of each data object, and the latest value of the corresponding data object is determined according to the target historical management information, and stored in a preset memory image.
[0099] Furthermore, in one embodiment, the device further includes an updating module, wherein the updating module is configured to:
[0100] When the management information of any data object is updated, after the latest value corresponding to the updated management information is successfully written into the storage unit, the latest value corresponding to the updated management information is read back and replaces the value of the corresponding data object in the memory image.
[0101] Furthermore, in one embodiment, the device further includes an erasing module, wherein the erasing module is used to:
[0102] When a preset proportion of the reserve units in the storage space are filled, a blank reserve unit is randomly selected as an update management unit and an update storage unit respectively;
[0103] Writing the latest value of each data object into the update storage unit, determining the update management information of each data object according to the position of the latest value of each data object in the update storage unit, writing the update management information of each data object into the update management unit, and clearing the storage times of the corresponding data object in each update management information;
[0104] After the NVM is powered on again, determining whether the latest value of the data object written into the update storage unit and the update management information written into the update management unit are all stored successfully;
[0105] If so, data in all units except the update management unit and the update storage unit are erased.
[0106] Furthermore, in one embodiment, the device further includes an early warning module, and the early warning module is used to:
[0107] If the latest value of the data object written into the update storage unit and the update management information written into the update management unit are not all stored successfully, the latest value of the data object that is not successfully stored is written into the update storage unit again, and the corresponding update management information is written into the update management unit again, wherein the number of storage times of the data object in the update management information of the corresponding data object is increased by 1 each time the data object is written;
[0108] When the latest values of all data objects and the corresponding update management information are still not successfully stored in the update storage unit and the update management unit for N consecutive times, an NVM failure reminder is issued.
[0109] Among them, the functional implementation of each module in the above-mentioned writing device for non-volatile memory corresponds to each step in the above-mentioned writing method embodiment for non-volatile memory, and its functions and implementation processes are no longer repeated here.
[0110] In a third aspect, an embodiment of the present application provides a non-volatile memory writing device, which may be a personal computer (PC), a laptop computer, a server, or other device having a data processing function.
[0111] Reference Figure 3 , Figure 3 The hardware structure diagram of the non-volatile memory writing device involved in the embodiment of the present application is shown in FIG. In the embodiment of the present application, the non-volatile memory writing device may include a processor, a memory, a communication interface, and a communication bus.
[0112] The communication bus may be of any type and is used to interconnect the processor, the memory, and the communication interface.
[0113] The communication interface includes input / output (I / O) interfaces, physical interfaces, and logical interfaces, which are used to interconnect the devices inside the non-volatile memory writing device, and interfaces used to interconnect the non-volatile memory writing device with other devices (such as other computing devices or user devices). The physical interface can be an Ethernet interface, a fiber optic interface, an ATM interface, etc.; the user device can be a display, a keyboard, etc.
[0114] The memory can be various types of storage media, such as random access memory (RAM), read-only memory (ROM), non-volatile RAM (NVRAM), flash memory, optical storage, hard disk, programmable ROM (PROM), erasable PROM (EPROM), electrically erasable PROM (EEPROM), etc.
[0115] The processor may be a general-purpose processor, and the general-purpose processor may call the writing program of the non-volatile memory stored in the memory, and execute the writing method of the non-volatile memory provided in the embodiment of the present application. For example, the general-purpose processor may be a central processing unit (CPU). Among them, the method executed when the writing program of the non-volatile memory is called can refer to the various embodiments of the writing method of the non-volatile memory of the present application, which will not be repeated here.
[0116] Those skilled in the art will understand that Figure 3 The hardware structure shown in the figure does not constitute a limitation on the present application, and may include more or less components than shown in the figure, or combine certain components, or arrange the components differently.
[0117] It should be noted that the serial numbers of the above-mentioned embodiments of the present application are only for description and do not represent the advantages or disadvantages of the embodiments.
[0118] The terms "including" and "having" and any variations thereof in the specification and claims of this application and the above-mentioned drawings are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not limited to the listed steps or units, but optionally includes steps or units that are not listed, or optionally includes other steps or units inherent to these processes, methods, products or devices. The terms "first", "second" and "third" are used to distinguish different objects, etc., and do not represent a sequence, nor do they limit "first", "second" and "third" to different types.
[0119] In the description of the embodiments of the present application, "exemplary", "for example" or "for example" are used to indicate examples, illustrations or descriptions. Any embodiment or design described as "exemplary", "for example" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary", "for example" or "for example" is intended to present related concepts in a specific way.
[0120] In the description of the embodiments of the present application, unless otherwise specified, “ / ” means or, for example, A / B can mean A or B; the “and / or” in the text is merely a description of the association relationship of associated objects, indicating that three relationships may exist, for example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, in the description of the embodiments of the present application, “multiple” refers to two or more than two.
[0121] In some processes described in the embodiments of the present application, multiple operations or steps that appear in a specific order are included, but it should be understood that these operations or steps may not be executed in the order in which they appear in the embodiments of the present application or in parallel, and the sequence number of the operation is only used to distinguish the different operations, and the sequence number itself does not represent any execution order. In addition, these processes may include more or fewer operations, and these operations or steps may be executed in sequence or in parallel, and these operations or steps may be combined.
[0122] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, disk, CD) as described above, and includes a number of instructions for a terminal device to execute the methods described in each embodiment of the present application.
[0123] The above are only preferred embodiments of the present application, and are not intended to limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the present application specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present application.
Claims
1. A method for writing into a non-volatile memory, characterized in that: The writing method of the non-volatile memory comprises: The storage space of the non-volatile memory NVM includes a plurality of preparation units; When a data storage request is received for the first time, any preparation unit is randomly selected from the blank preparation units of the plurality of preparation units as a storage unit, and the value of the data object is written into the storage unit, and any preparation unit is randomly selected from the blank preparation units as a management unit, and management information of the data object is written into the management unit, wherein the management information includes an index number of the data object, an index number of the storage unit where the data object is located, an address offset of the storage unit where the data object is located, and a storage count of the data object; When a new data storage request is received, the value of the new data object is then written into the storage unit in which the value of the previous data object was written, and the management information of the new data object is then written into the management unit in which the management information of the previous data object was written. If the storage unit in which the value of the previous data object was written is full, any spare unit is randomly selected from the blank spare units as the storage unit and the value of the new data object is written therein. If the management unit in which the management information of the previous data object is written is full, any spare unit is randomly selected from the blank spare units as the management unit and the management information of the new data object is written therein.
2. The method for writing into a non-volatile memory according to claim 1, wherein: After receiving the data storage request and before writing the value of the data object into the storage unit, the method further includes: Sort the data objects according to the preset sorting rules and generate a unique corresponding index number for each data object; When the value of the data object is written into the storage unit, the index number of the data object is written into the storage unit.
3. The method for writing into a non-volatile memory according to claim 1, wherein: Writing the value of a data object into a storage unit also includes: determining whether the storage cell is a blank cell; If yes, then after writing a preset first identifier at the start byte of the storage unit, the value of the data object is written into the storage unit; Otherwise, the value of the data object is directly written to the storage unit.
4. The method for writing into a non-volatile memory according to claim 1, wherein: Write the management information of the data object into the management unit, including: If the index number of the data object already exists in the management unit and the value of the data object has not changed, the management information of the data object is not written into the management unit; otherwise, the management information of the data object is written into the management unit; When writing the management information of the data object in the management unit, if the management unit is a blank unit, the preset second identifier is written at the starting byte of the management unit, and then the management information of the data object is written; otherwise, the management information of the data object is directly written in the management unit.
5. The method for writing into a non-volatile memory according to any one of claims 1 to 4, characterized in that: The method further includes: Reading the history management information of each data object in the management unit according to the index number of each data object, and determining the target history management information with the largest number of storage times corresponding to each data object; The target history management information corresponding to each data object is stored in a preset history data summary unit, and any blank preparation unit is randomly selected as a summary management unit for managing the history data summary unit, and the index number and address offset of the history data summary unit are stored in the summary management unit, wherein the starting byte of the summary management unit is a preset third identifier; The historical data summary unit is read to obtain the target historical management information of each data object, and the latest value of the corresponding data object is determined according to the target historical management information, and stored in a preset memory image.
6. The method for writing into a non-volatile memory according to claim 5, wherein: After storing the latest values of each data object into the preset memory image, it also includes: When the management information of any data object is updated, after the latest value corresponding to the updated management information is successfully written into the storage unit, the latest value corresponding to the updated management information is read back and replaces the value of the corresponding data object in the memory image.
7. The method for writing into a non-volatile memory according to any one of claims 1 to 4, characterized in that: The method further includes: When a preset proportion of the reserve units in the storage space are filled, a blank reserve unit is randomly selected as an update management unit and an update storage unit respectively; Writing the latest value of each data object into the update storage unit, determining the update management information of each data object according to the position of the latest value of each data object in the update storage unit, writing the update management information of each data object into the update management unit, and clearing the storage times of the corresponding data object in each update management information; After the NVM is powered on again, determining whether the latest value of the data object written into the update storage unit and the update management information written into the update management unit are all stored successfully; If so, data in all units except the update management unit and the update storage unit are erased.
8. The method for writing into a non-volatile memory according to claim 7, wherein: The method further includes: If the latest value of the data object written into the update storage unit and the update management information written into the update management unit are not all stored successfully, the latest value of the data object that is not successfully stored is written into the update storage unit again, and the corresponding update management information is written into the update management unit again, wherein the number of storage times of the data object in the update management information of the corresponding data object is increased by 1 each time the data object is written; When the latest values of all data objects and the corresponding update management information are still not successfully stored in the update storage unit and the update management unit for N consecutive times, an NVM failure reminder is issued.
9. A writing device for a non-volatile memory, characterized in that: The writing device of the non-volatile memory comprises: a first writing module and a second writing module, and the storage space of the non-volatile memory NVM comprises a plurality of preparation units; The first writing module is used to, when receiving a data storage request for the first time, randomly select any prepared unit from the blank prepared units of the plurality of prepared units as a storage unit, and write the value of the data object into the storage unit, randomly select any prepared unit from the blank prepared units as a management unit, and write the management information of the data object into the management unit, wherein the management information includes an index number of the data object, an index number of the storage unit where the data object is located, an address offset of the storage unit where the data object is located, and a storage count of the data object; The second writing module is used to, when receiving a new data storage request, continue to write the value of the new data object in the storage unit in which the value of the previous data object was written, and continue to write the management information of the new data object in the management unit in which the management information of the previous data object was written; if the storage unit in which the value of the previous data object was written is full, randomly select any spare unit in the blank spare unit as the storage unit and write the value of the new data object; if the management unit in which the management information of the previous data object was written is full, randomly select any spare unit in the blank spare unit as the management unit and write the management information of the new data object.
10. A writing device for a non-volatile memory, characterized in that: The non-volatile memory writing device includes a processor, a memory, and a non-volatile memory writing program stored on the memory and executable by the processor, wherein when the non-volatile memory writing program is executed by the processor, the steps of the non-volatile memory writing method as described in any one of claims 1 to 8 are implemented.
Citation Information
Patent Citations
Data storage management method, device and equipment
CN117075801A
Memory card
JP2008112455A
Method for Uniformly Distributing Memory Blocks ofFlash Memory and Data Storage Device Using The Method
KR1020050064885A
Data writing method, memory control circuit unit and memory storage apparatus
US20150134887A1
Flash data power failure protection method and device
WO2022126470A1