Data writing method and system for improving performance
By judging the spatial range and selecting an appropriate writing strategy, directly erase or power-off protection writes, combined with parallel processing of the erase backup area flag, the problem of slow writing performance of FLASH data is solved, significantly improving the writing efficiency.
Patent Information
- Application Number
- CN202411211762.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-30
- Publication Date
- 2024-12-06
- Estimated Expiration
- 2044-08-30
AI Technical Summary
In the embedded field, FLASH data is written with slow performance due to the need for full page erasing, especially under the power outage protection mechanism, backup and transaction buffer operation add additional overhead, affecting write efficiency.
By determining whether the space range to be written is in the new application space list, if so, use erect directly, otherwise use power off protection to write, and only write the actual data when the transaction is submitted, and in addition, when the direct erecting is performed, use power off protection to write the actual data. The operation of the page backup area flag is processed in parallel with the sending data.
It greatly improves data writing performance, reduces backup and cache area flag operations, and improves write efficiency, especially in the case of single writes and transaction mechanism writing.
Smart Images

Figure CN119088311A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the embedded field, and in particular to a FLASH data writing method and system for improving performance. Background Art
[0002] Most of the data storage in the embedded field uses FLASH. FLASH chips have the feature of requiring full page erasure, that is, before each write, you need to erase a page first, and then write. Some pages are 256 bytes, and some are 512 bytes. If you only write one byte, you will first read the entire page of data cache, modify that byte, then erase a page, and finally write the modified cache data to ensure that one byte is written successfully.
[0003] According to the above process, if there is a power outage after erasing a page, the data of the entire page will change, affecting the previous data of the FLASH. In order to avoid this power outage, the data of the page to be erased is generally saved before erasing the page, and then erased. The process is as follows: first write the page data to be erased to the FLASH backup area, then write the backup area valid flag, then erase the actual data, and finally clear the backup area valid flag. Check the backup area flag when powering on to see if there is a power outage during the writing process. If there is a power outage, restore the previously backed up data. This method ensures the correctness of the written data. However, this will cause more writing of the backup area, the backup area flag, and the erasing of the backup area flag, and the performance is slower.
[0004] The transaction mechanism write operation is to ensure that multiple write operations are either all written successfully or not. If you want to implement this mechanism, you need to have a FLASH transaction buffer. Each write operation first writes to the transaction buffer, sets the transaction buffer to be valid, then writes the actual data to protect the power off, and finally sets the transaction buffer to be invalid when the transaction is committed. However, this also causes multiple writes to the transaction buffer, sets the transaction buffer valid flag, and erases the transaction buffer valid flag, which also leads to performance degradation.
[0005] Now when writing FLASH data, first write the data of the page to be erased to the FLASH backup area, then write the backup area valid flag, then erase the actual data, and finally clear the backup area valid flag. Check the backup area flag at power-on to see if the power is off during the writing process. This method ensures the correctness of the written data. However, this method writes more backup areas, backup area flags, and erases backup area flags, resulting in slower performance. In actual use, the transaction mechanism is often used for writing, which also leads to slow performance.
[0006] Therefore, a data writing method with improved performance is urgently needed to solve the above problems. Summary of the invention
[0007] The main purpose of the present invention is to solve the problem of slow performance caused by page erasing for a single write, and to provide a data writing method and system that can greatly improve the writing performance of a transaction mechanism.
[0008] The technical solution adopted by the present invention is:
[0009] A method for writing data to improve performance is provided, characterized in that it includes the following steps:
[0010] When writing FLASH data, determine whether the space range to be written is in the newly applied space list; the newly applied space list records the address and size of the newly applied FLASH space in advance; the newly applied FLASH space is invalid data, and after the whole page is aligned, there is no need to use backup writing, and erase writing can be used directly;
[0011] If yes, erase directly without power-off protection; if no, write with power-off protection.
[0012] Following the above technical solution, when power-off protection is used for writing, the data written multiple times on the same page is placed in the RAM buffer area. When the transaction is committed, only the actual data is written for power-off protection.
[0013] According to the above technical solution, when erasing directly, the operation of erasing the backup area mark and sending the data are processed in parallel.
[0014] Following the above technical solution, each time a new space is applied for, a record is added to the application space record table.
[0015] Following the above technical solution, if the maximum record is reached, re-recording starts from the first record.
[0016] The present invention also provides a data writing system with improved performance, comprising:
[0017] A new space application module is used to apply for FLASH space and add the address and size of the applied FLASH space to the new application space record table;
[0018] The judgment module, when writing FLASH data through the transaction mechanism, determines whether the space range to be written is in the newly applied space list;
[0019] The execution module is used to directly erase and write without power-off protection when the space range to be written is in the newly applied space list; if not, write with power-off protection.
[0020] Following the above technical solution, the execution module is also used to place the data written multiple times on the same page in the RAM buffer area during direct erasing, and when the transaction is committed, only the power is cut off to protect the actual data from being written.
[0021] According to the above technical solution, the execution module is also used to process the operation of erasing the page backup area mark and sending the data in parallel during direct erasing.
[0022] According to the above technical solution, the new space application module is also used to add a record to the space application record table each time a new space is applied; if the maximum number of records is reached, the record is restarted from the first record.
[0023] The present invention also provides a computer storage medium, which stores a computer program that can be executed by a processor, and the computer program executes the data writing method for improving performance described in the above technical solution.
[0024] The beneficial effects of the present invention are as follows: the present invention proposes a newly applied space for single writing, and the space is invalid data. After the whole page is aligned, there is no need to use backup writing, and erase writing can be used directly, and the original data is useless; when the data to be written is in the newly applied space, the writing performance of the newly applied space can be greatly improved.
[0025] Furthermore, for transaction mechanism writing, the information to be written is first written to the RAM cache area. The RAM cache area is one page in size. When a transaction is written, it is first written to the RAM cache area. If multiple writes are all in the same page, they are all written to the RAM cache area first. When the transaction is committed, if they are all in the same page, the data only needs to be written once for power-off protection. The transaction backup area and the transaction cache area flag are not written, which greatly improves performance.
[0026] Furthermore, the operation of erasing the page backup area mark is put into operation when responding to data, so that the page backup area is erased and the data is sent in parallel, reducing the time of erasing the backup area mark before sending the response.
[0027] Of course, any product implementing the present invention does not necessarily need to achieve all of the advantages described above at the same time. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0029] Figure 1 is a flow chart of a data writing method for improving performance according to an embodiment of the present invention; Figure 2 is a flow chart of applying for FLASH space according to an embodiment of the present invention; Figure 3 This is a flow chart of direct erasing in one embodiment of the present invention; Figure 4 is a flow chart of a data writing method according to an embodiment of the present invention. DETAILED DESCRIPTION
[0030] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.
[0031] It should be noted that the illustrations provided in the embodiments of the present invention are only used to illustrate the basic concept of the present invention in a schematic manner. Therefore, the drawings only show components related to the present invention rather than being drawn according to the number, shape and size of components in actual implementation. In actual implementation, the type, quantity and proportion of each component may be changed arbitrarily, and the component layout type may also be more complicated.
[0032] In the present invention, it is also necessary to explain that, if the terms "center", "upper", "lower", "left", "right", "vertical", "horizontal", "inner", "outer", etc. appear, the orientation or position relationship indicated is based on the orientation or position relationship shown in the drawings, which is only for the convenience of describing the present application and simplifying the description, and does not indicate or imply that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as a limitation on the present application. In addition, if the terms "first" and "second" appear, they are only used for description and distinction purposes, and cannot be understood as indicating or implying relative importance.
[0033] The present invention aims at the problem that a single write requires page erasure resulting in slow performance, and proposes a newly applied space, in which data can be written directly using erase without using backup write, which can greatly improve the write performance of the newly applied space.
[0034] like Figure 1 As shown, the data writing method for improving performance according to an embodiment of the present invention comprises the following steps:
[0035] S101, when writing FLASH data, determine whether the space range to be written is in the newly applied space list; the newly applied space list records the address and size of the newly applied FLASH space in advance; the newly applied FLASH space is invalid data, and after the whole page is aligned, there is no need to use backup writing, and erase writing is used directly;
[0036] S102: If yes, directly erase and write without power-off protection;
[0037] S103, if not, use power-off protection writing. If power-off protection writing is used, the original data needs to be backed up first.
[0038] Among them, Figure 2 As shown, the steps to apply for FLASH space mainly include:
[0039] S201, apply for FLASH space;
[0040] S202. Add the address and size of the newly applied FLASH space to the newly applied space record table.
[0041] Specifically, the new application space record is shown in Table 1 below:
[0042] Table 1 New application space record
[0043]
[0044] Each time a new space is applied for, a record is added to the application space record table. If the maximum number of records is reached, the record is restarted from the first record.
[0045] like Figure 3 As shown, when directly erasing, the operation of erasing the page backup area mark can be put into operation when responding to data, so that the page backup area is erased and the data is sent in parallel, reducing the time of erasing the backup area mark before sending the response. The method of this embodiment specifically includes the following steps:
[0046] S301, receiving a command related to FLASH;
[0047] S302, determining whether the command has been received;
[0048] S303, when the command is received, start processing the command;
[0049] S304, determine whether the command needs to write FLASH;
[0050] S305, if the command requires writing FLASH, determine whether the address range of writing FLASH is a newly applied space;
[0051] S306, if the address range of the FLASH is a newly applied space, directly erase it, and then proceed to step S310;
[0052] S307, if the address range of the FLASH is not the newly applied space, back up the original data;
[0053] S308, write page backup flag;
[0054] S309, erasing data;
[0055] S310, after completing the write operation, send a command response message;
[0056] S311, determine whether there is a page backup flag;
[0057] S312, if there is a page backup flag, erase the page backup flag;
[0058] S313: If there is no page backup mark, or after erasing the page backup mark, determine whether the command response message is sent successfully. If so, end. If not, continue to determine until the message is sent successfully.
[0059] This embodiment is for transaction mechanism writing. The information to be written can be written to the RAM cache area first. The RAM cache area is a page size. When writing transactions, it is written to the RAM cache area first. If multiple writes are all in the same page, they are all written to the RAM cache area first. When the transaction is committed, if they are all in the same page, only the power-off protection writes the data once. It can be seen that the direct erasing of the present invention does not need to write the transaction backup area, and does not need to write the transaction cache area mark, thereby greatly improving performance. In reality, many application scenarios do have data written in one transaction in the same page.
[0060] The determination of whether there is a page backup flag is to optimize the time of erasing the backup flag during power-off protection writing, so that erasing and sending data can be processed concurrently. It can be seen that when writing with power-off protection, the operation of erasing the page backup area flag is put into the operation when responding to data, so that erasing the page backup area and sending data can be processed in parallel, which can reduce the time of erasing the backup area flag before sending the response.
[0061] By applying for new space to optimize writing without power-off protection, directly using erase and write, the writing time is optimized.
[0062] Furthermore, during the transaction mechanism writing process, the RAM cache area can be used to put the data of the same page written multiple times in the RAM cache area. When the transaction is committed, only the power is cut off to protect the actual data. There is no need to write the transaction FLASH cache area, and the transaction FLASH cache area flag is not written, thereby improving the transaction mechanism writing performance.
[0063] By adding a buffer to save transaction mechanism writes, as shown in Table 2 below, the buffer area information mainly includes:
[0064] Table 2 Cache information
[0065] FLASH page address The starting address within the page End address within the page Write FLASH page information
[0066] in:
[0067] FLASH page address: saves the address to be written.
[0068] Page start address: The start address within the page to be written.
[0069] Ending address within page: Ending address within the page to be written.
[0070] Write FLASH page information: one page size, the information of the page to be written.
[0071] When writing a transaction, first check whether there is information in the transaction mechanism write buffer. If not, add the information to be written to the transaction buffer. If there is information, check whether it is written on the same page. If so, update it to the transaction buffer. If not, write the information according to the normal transaction mechanism, and the information previously saved in the transaction buffer should also be written according to the normal transaction mechanism. If the information to be written is larger than one page, write it according to the normal transaction mechanism. When committing a transaction, check whether there is information in the transaction buffer. If there is information, write it directly. If not, write it according to the normal transaction mechanism and commit the transaction according to the normal transaction mechanism.
[0072] like Figure 4 As shown, the data writing method of this embodiment mainly includes the following steps:
[0073] S401, transaction write initialization;
[0074] S402, determining whether the size of the write data is greater than one page;
[0075] S403-S405, if the write data is larger than one page, write the transaction backup area, write the actual area and write the transaction backup area flag, and then go to step S413;
[0076] S406, if the data is less than or equal to one page, determine whether there is a message in the transaction buffer, if not, proceed to step S411; if not, proceed to step S407;
[0077] S407, determine whether the information stored in the transaction buffer is in the same page as the information to be written, if so, execute step S412, if not, execute steps S408-S410;
[0078] S408-S410, write the buffer information into the transaction backup area, write the buffer information into the actual area, and write the buffer information transaction backup area flag;
[0079] S411, adding the information to be written to the transaction buffer;
[0080] S412, update the information to be written to the transaction buffer area;
[0081] S413, when determining whether the transaction is committed, check whether there is information in the transaction buffer area, if yes, execute step S415, if no, execute step S414;
[0082] S414, transaction commit sets the transaction flag invalid, and the transaction write ends;
[0083] S415: Write the transaction buffer information into the actual area, and the transaction writing is completed.
[0084] The data writing system with improved performance according to the embodiment of the present invention is mainly used to implement the above method embodiment, and the system includes:
[0085] A new space application module is used to apply for FLASH space and add the address and size of the applied FLASH space to the new application space record table;
[0086] The judgment module, when writing FLASH data, determines whether the space range to be written is in the newly applied space list;
[0087] The execution module is used to directly erase and write without power-off protection when the space range to be written is in the newly applied space list; if not, write with power-off protection.
[0088] The execution module is also used to place the data written multiple times on the same page in the RAM buffer area during direct erasing and writing. When the transaction is committed, only the power is cut off to protect the actual data being written.
[0089] Furthermore, the execution module is also used to process the operation of erasing the page backup area mark and sending the data in parallel during direct erasing.
[0090] Furthermore, the new space application module is also used to add a record to the space application record table each time a new space is applied for; if the maximum number of records is reached, the record is restarted from the first record.
[0091] Each module is also mainly used to implement each step of the method embodiment, which will not be described in detail here.
[0092] The present application also provides a computer-readable storage medium, such as a flash memory, a hard disk, a multimedia card, a card-type memory (e.g., an SD or DX memory, etc.), a random access memory (RAM), a static random access memory (SRAM), a read-only memory (ROM), an electrically erasable programmable read-only memory (EEPROM), a programmable read-only memory (PROM), a magnetic memory, a disk, an optical disk, a server, an App application store, etc., on which a computer program is stored, and when the program is executed by a processor, a corresponding function is realized. When the computer-readable storage medium of this embodiment is executed by a processor, the data writing method of the method embodiment is realized to improve performance.
[0093] In summary, the present invention proposes a newly applied space for single writing, and the space is invalid data. After the whole page is aligned, there is no need to use backup writing, and erase writing is used directly, and the original data is useless; when the data to be written is in the newly applied space, the write performance of the newly applied space can be greatly improved; in addition, for transaction mechanism writing, the information to be written is first written to the RAM cache area, and the RAM cache area is a page size. For transaction writing, it is first written to the RAM cache area. If multiple writes are all in the same page, they are all written to the RAM cache area first. When the transaction is committed, if they are all in the same page, only the data needs to be written once for power-off protection, and the transaction backup area and the transaction cache area mark are not written, which greatly improves the performance; the operation of erasing the page backup area mark can also be put into the operation when responding to data, so that the page backup area and the sending data can be processed in parallel, thereby reducing the time of erasing the backup area mark before sending the response.
[0094] It should be pointed out that, according to the needs of implementation, the various steps / components described in this application can be split into more steps / components, and two or more steps / components or partial operations of steps / components can be combined into new steps / components to achieve the purpose of the present invention.
[0095] The order of execution of each step in the above embodiment does not mean the order of execution. The order of execution of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiment of the present application.
[0096] It should be understood that those skilled in the art can make improvements or changes based on the above description, and all these improvements and changes should fall within the scope of protection of the appended claims of the present invention.
Claims
1. A data writing method for improving performance, characterized in that: The following steps are involved: When writing FLASH data, determine whether the space range to be written is in the newly applied space list; The newly applied space list records the address and size of the newly applied FLASH space in advance; the newly applied FLASH space is invalid data, and after the whole page is aligned, there is no need to use backup writing, and erase writing can be used directly; If yes, erase directly without power-off protection; if no, write with power-off protection.
2. The data writing method for improving performance according to claim 1, characterized in that: When erasing directly, data written multiple times on the same page are placed in the RAM cache. When the transaction is committed, only the power is cut off to protect the actual data being written.
3. The data writing method for improving performance according to claim 1, characterized in that: When the power-off protection is written, the operation of erasing the page backup area mark and sending the data are processed in parallel.
4. The data writing method for improving performance according to claim 1, characterized in that: Every time a new space is applied for, a record is added to the space application record table.
5. The data writing method for improving performance according to claim 4, characterized in that: If the maximum number of records is reached, recording starts again from the first record.
6. A data writing system with improved performance, characterized in that: include: A new space application module is used to apply for FLASH space and add the address and size of the applied FLASH space to the new application space record table; The judgment module, when writing FLASH data, determines whether the space range to be written is in the newly applied space list; The execution module is used to directly erase and write without power-off protection when the space range to be written is in the newly applied space list; if not, write with power-off protection.
7. The data writing system for improving performance according to claim 6, characterized in that: The execution module is also used to place the data written multiple times on the same page in the RAM buffer area during direct erasing and writing. When the transaction is committed, only the power is cut off to protect the actual data being written.
8. The data writing system for improving performance according to claim 6, characterized in that: The execution module is also used to process the operation of erasing the page backup area mark and sending data in parallel during direct erasing.
9. The data writing system for improving performance according to claim 6, characterized in that: The new space application module is also used to add a record to the space application record table each time a new space is applied for; if the maximum number of records is reached, the record is restarted from the first record.
10. A computer storage medium, characterized in that: A computer program executable by a processor is stored therein, and the computer program executes the data writing method for improving performance as described in any one of claims 1 to 5.
Citation Information
Patent Citations
Page operation-based electrically erasable programmable read-only memory (EEPROM) cache method
CN102073544A
NAND Flash memory data storage method
CN103309619A
Method and system for quickly writing data into FLASH memory
CN112035378A
Mirror protection method and data structure based on FLASH chip with page atomicity
CN112948172A
Data storage method and device
CN115373607A
