Method, device and apparatus for writing non-volatile memory
By dividing the storage space of the non-volatile memory into multiple preparation units and randomly selecting storage and management units, the problem of shortened life of the non-volatile memory is solved, and a longer service life and higher data reading efficiency are achieved.
Patent Information
- Application Number
- CN202411296574.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-14
- Publication Date
- 2025-09-19
- Estimated Expiration
- 2044-09-14
AI Technical Summary
In the prior art, non-volatile memories have a problem of shortened lifespan due to repeated erasing and writing at fixed addresses.
The storage space of the non-volatile memory is divided into multiple preparation units. When a data storage request is received, a blank preparation unit is randomly selected as a storage unit and a management unit. When writing data, the index number, address offset and storage count are recorded to avoid frequent erasure and writing of fixed addresses.
It effectively extends the service life of non-volatile memory, improves data reading efficiency through memory mirroring, and reduces data loss rate.
Smart Images

Figure CN119336253B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of data storage, and in particular to a method, apparatus and device for writing data 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 related technologies, data is typically stored sequentially in non-volatile memory cells, which can lead to multiple erase and write operations at fixed addresses. Because non-volatile memory devices inherently have write endurance issues, each cell can only perform a limited number of write operations. Excessive erase and write cycles can reduce storage reliability, potentially shortening the lifespan of the non-volatile memory and potentially rendering the entire memory unusable.
[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 storage cells of a non-volatile memory may result in multiple erasures and writes at fixed addresses, 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 data to a non-volatile memory, the method 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 prepared unit is randomly selected from the blank prepared units of the plurality of prepared units as a storage unit, and the value of the data object is written into the storage unit; any prepared unit is randomly selected from the blank prepared 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 conjunction with the first aspect, in one embodiment, 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] Determine whether the storage cell is a blank cell;
[0015] If yes, then after writing a preset first identifier at the starting 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 embodiment, 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] Among them, 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 written directly 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] Storing the target history management information corresponding to each data object in a preset history data summary unit, randomly selecting any blank preliminary unit as a summary management unit for managing the history data summary unit, and storing the index number and address offset of the history data summary unit 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 in 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 count 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 successfully stored;
[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 successfully stored, the latest value of the data object that has not been 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 times the data object is stored 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, wherein a storage space of the non-volatile memory NVM comprises a plurality of preparation units;
[0035] The first writing module is configured to, upon receiving a data storage request for the first time, randomly select any of the blank preliminary units among the plurality of preliminary units as a storage unit, and write the value of the data object into the storage unit, and randomly select any of the blank preliminary units as a management unit, and write 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 number of times the data object has been stored;
[0036] The second writing module is used to, when receiving a new data storage request, write the value of the new data object into the storage unit in which the value of the previous data object was written, and write the management information of the new data object 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, randomly select any preparation unit from the blank preparation 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 preparation unit from the blank preparation 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, apparatus and device for a non-volatile memory, wherein 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. 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 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 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 preparation unit is randomly selected from the blank preparation 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 preparation unit is randomly selected from the blank preparation units as the management unit and the management information of the new data object is written therein. This effectively avoids the situation of 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 This is a flowchart of an embodiment of a method for writing data 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 This is a 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 present invention, the following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, 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 this application clearer, the implementation methods of this 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 times the data object is stored.
[0046] It is worth noting that before step S101, the storage space of the non-volatile memory NVM can be divided into n preliminary units according to a division rule such as a preset space step size or the length of the data to be written. During the division, the storage space can be equally divided to obtain n preliminary units of equal size, which is beneficial to the life of the memory.
[0047] To explain, a data object generally 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 typically have a type, and a value is a specific type of data. A data object is a container for storing and manipulating values, while a value is the information stored by the data object.
[0048] In this embodiment, each data storage request may include storage requests for multiple data objects. After receiving the data storage request and before writing the data object's value into the storage unit, the process further includes sorting the data objects according to a preset sorting rule and generating a unique index number for each data object. The sorting rule may include sorting the data objects by importance or alphabetically, or other preset sorting rules. In this embodiment, the index number generated for the data object is len bytes long, and the value of len can be set as needed.
[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 no index number needs to be generated 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 in 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 further includes: determining whether the storage unit is a blank unit, wherein a blank unit refers to an empty unit in which no data is written. 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 into it, it is a non-blank unit, and the first identifier has already been written when the value of the existing data object was written, so 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 units in the non-volatile memory, that is, there are storage units that are already full. At this time, when determining whether a storage unit is a blank unit, what is determined is whether the last storage unit is a blank unit, that is, whether the latest storage unit is a blank unit.
[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 into the starting 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 the data object is written into the 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 means that the data object has already been stored with a value; 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. In this embodiment, the second identifier is the 0x55 identifier. If the management unit already has management information written into it, that is, it is a non-blank unit, the second identifier has been written when the existing management information was 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 the data storage request is received for the first time, the selected management unit B0 is a blank unit. Therefore, after writing 0x55 in the starting byte of the management unit B0 and then writing the management information of the data object, the response to the first received data storage request can be completed.
[0059] As a preferred embodiment, when writing the value of the data object into the storage unit, the index number of the data object can be simultaneously written into the storage unit. Later, when reading the value of the data object in the storage unit based on the management information in the management unit, the index number of the data object in the storage unit can be compared and verified with the index number of the data object in the management information to ensure the accuracy of the read data object value.
[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 data object immediately preceding the first data object in the second data storage request. Therefore, when storing the value of the data object in the second data storage request, writing can be started in the storage unit from the byte following the value of the last data object in the first data storage request. This improves storage unit utilization and avoids wasting storage space 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 random storage unit can be selected from the n-2 spare units excluding the first storage unit A0 and the first management unit B0 as the storage unit. The index number of this storage unit is A1, indicating the second storage unit. Since the second storage unit is an empty unit, 0xAA needs to be written at its initial byte. Then, the value of the data object that was not written in the second data storage request can be written to the second storage unit A1. When writing the value of a new data object in a new data storage request, the above method can be used for writing.
[0063] Similarly, if the management unit is full, the preparatory unit that has been selected as the storage unit and 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 the 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 the multiple blank preparatory units as a storage unit and a management unit to store the numerical value of the data object and the corresponding management information. This achieves random storage of the numerical value of the data object and the management information, prevents excessive erasure and writing at a fixed address in the non-volatile memory, and effectively improves the lifespan of the non-volatile memory. Furthermore, 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 times the data object has been stored, thereby ensuring that the numerical value of the corresponding data object can be quickly and accurately read based on the management information.
[0067] In one embodiment, the non-volatile memory writing method 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] According to the index number of each data object, the historical management information of each data object is read in the management unit, 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. In this embodiment of the application, the memory mirror is exemplified as a RAM mirror.
[0069] Among them, a preparation unit can be randomly selected from the blank preparation unit as a 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 historical management information for a data object refers to management information already stored in the management unit. Management information that has been stored more frequently is more recent. Therefore, the latest value of a data object can be found in the storage unit based on the historical management information with the greatest number of storages corresponding to each data object. This embodiment stores the historical management information with the greatest number of storages corresponding to each data object in a preset historical data summary unit, and stores the latest value of each data object in a preset RAM image. This allows the latest value of a data object to be read directly from the historical data summary unit or by directly accessing the RAM image, effectively improving 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 enabling the latest value of the data object to be read 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, it 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 proportion of the spare cells in the storage space are full, a blank spare cell is randomly selected as an update management cell and an update storage cell. The latest value of each data object is written into the update storage cell. The update management information for each data object is determined based on the position of the latest value of each data object in the update storage cell. The update management information for each data object is written into the update management cell, and the storage count for the corresponding data object in each update management information is reset to zero.
[0075] In this embodiment, when a preset proportion of cells in the storage space are fully written, the number of remaining blank spare cells is M. One of the M blank spare cells is randomly selected as the update storage cell, and one of the remaining M-1 blank spare cells is randomly selected as the update management cell. 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 values of the data objects written to the update storage unit and the update management information written to the update management unit have all been successfully stored. If so, data in all units except the update management unit and the update storage unit is erased. This allows the latest values of the data objects and the latest management information to be backed up and then erased collectively.
[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 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 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 successfully stored, the data object that was not successfully stored is determined. The latest value of the data object that was not successfully stored is written again to the next byte after the last latest value of the data object was written into the update storage unit, and the update management information of the data object that was not successfully stored is written again to the next byte after the last update management information of the data object was written into the update management unit. If the update storage unit is full, one of the M-2 blank spare units is selected 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 storage unit is full, one of the M-3 blank spare units is selected as a new update management unit, and the update management information of the data object that was 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 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 technical personnel to perform maintenance.
[0081] The non-volatile memory writing method provided in the embodiments of the present application has the beneficial effects of: by dividing the storage space of the non-volatile memory into multiple preparatory units and randomly selecting a preparatory unit from the multiple preparatory units as a storage unit and a management unit to store the numerical value and management information of the data object, random data storage is achieved, and over-frequent erasure and writing at a fixed address of the non-volatile memory is avoided, effectively improving the lifespan of the non-volatile memory. Furthermore, by storing the latest numerical value of the data object in a RAM image, the efficiency of reading the data object can be effectively improved. Furthermore, when the storage space of the non-volatile memory is almost full, the latest numerical 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 excluding the update management unit and the update storage unit are erased, which effectively reduces the data loss rate. When the storage space is almost full, the entire storage space is erased, effectively reducing the number of erases and writes to the storage space and improving the lifespan of the non-volatile memory.
[0082] In a second aspect, an embodiment of the present application further provides a writing device for a non-volatile memory.
[0083] In one embodiment, referring to Figure 2 , Figure 2 This is a functional module diagram 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 configured to, upon receiving a data storage request for the first time, randomly select any of the blank preliminary units among the plurality of preliminary units as a storage unit, and write the value of the data object into the storage unit, and randomly select any of the blank preliminary units as a management unit, and write 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 number of times the data object has been stored;
[0085] The second writing module is used to, when receiving a new data storage request, write the value of the new data object into the storage unit in which the value of the previous data object was written, and write the management information of the new data object 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, randomly select any preparation unit from the blank preparation 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 preparation unit from the blank preparation 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 configured 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] Determine whether the storage cell is a blank cell;
[0090] If yes, then after writing a preset first identifier at the starting 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] Among them, 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 written directly in the management unit.
[0095] Furthermore, in one embodiment, the device further includes a storage module, wherein the storage module is configured 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] Storing the target history management information corresponding to each data object in a preset history data summary unit, randomly selecting any blank preliminary unit as a summary management unit for managing the history data summary unit, and storing the index number and address offset of the history data summary unit 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 apparatus 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 configured 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 count 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 successfully stored;
[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, which is configured 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 successfully stored, the latest value of the data object that has not been 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 times the data object is stored 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 not repeated here one by one.
[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 with data processing capabilities.
[0111] Reference Figure 3 , Figure 3 Schematic diagram of the hardware structure of the non-volatile memory writing device involved in the embodiment of the present application. 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, memory, and communication interface.
[0113] Communication interfaces include input / output (I / O) interfaces, physical interfaces, and logical interfaces, which interconnect components within the nonvolatile memory writing device and connect the nonvolatile memory writing device to other devices (such as other computing devices or user devices). Physical interfaces can include Ethernet, fiber, or ATM interfaces; user devices can include displays and keyboards.
[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 that can call a non-volatile memory write program stored in a memory and execute the non-volatile memory write method provided in the embodiments of the present application. For example, the general-purpose processor may be a central processing unit (CPU). The method executed when the non-volatile memory write program is called can refer to the various embodiments of the non-volatile memory write method of the present application, and 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 to the present application and may include more or fewer components than shown in the figure, or a combination of certain components, or a different arrangement of components.
[0117] It should be noted that the serial numbers of the above-mentioned embodiments of the present application are for description only 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 the "first", "second" and "third" to different types.
[0119] In the description of the embodiments of this application, the words "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 this application should not be construed as being preferred or advantageous over other embodiments or designs. Rather, the use of words such as "exemplary," "for example," or "for example" is intended to present the relevant concepts in a concrete manner.
[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; “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 are included that appear in a specific order. However, it should be understood that these operations or steps may not be performed in the order in which they appear in the embodiments of the present application or may be performed in parallel. The sequence numbers of the operations are only used to distinguish between different operations, and the sequence numbers themselves do not represent any order of execution. In addition, these processes may include more or fewer operations, and these operations or steps may be performed 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 the necessary general hardware platform, of course, it can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present application, 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, magnetic disk, optical disk) as described above, and includes a number of instructions for enabling 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 do not 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 data into a non-volatile memory, characterized in that: The writing method of the non-volatile memory includes: 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 prepared unit is randomly selected from the blank prepared units of the plurality of prepared units as a storage unit, and the value of the data object is written into the storage unit; any prepared unit is randomly selected from the blank prepared 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 data 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 data into a non-volatile memory according to claim 1, wherein: Writing the value of a data object into a storage unit also includes: Determine whether the storage cell is a blank cell; If yes, then after writing a preset first identifier at the starting 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 data 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; Among them, 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 written directly in the management unit.
5. The method for writing into a non-volatile memory according to any one of claims 1 to 4, wherein: 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; Storing the target history management information corresponding to each data object in a preset history data summary unit, randomly selecting any blank preliminary unit as a summary management unit for managing the history data summary unit, and storing the index number and address offset of the history data summary unit 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, wherein: 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 count 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 successfully stored; 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 successfully stored, the latest value of the data object that has not been 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 times the data object is stored 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 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; The first writing module is configured to, upon receiving a data storage request for the first time, randomly select any of the blank preliminary units among the plurality of preliminary units as a storage unit, and write the value of the data object into the storage unit, and randomly select any of the blank preliminary units as a management unit, and write 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 number of times the data object has been stored; The second writing module is used to, when receiving a new data storage request, write the value of the new data object into the storage unit in which the value of the previous data object was written, and write the management information of the new data object 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, randomly select any preparation unit from the blank preparation 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 preparation unit from the blank preparation 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