Storage wear balancing method and device
By dividing sectors into multiple continuous Flash pages and dividing each Flash page into dynamic data and static data storage areas, the problem of poor storage equalization effect of Flash memory with pages in the prior art with poor ergonomic granularity is solved, and efficient data utilization and equalization wear are achieved.
Patent Information
- Application Number
- CN202411684931.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-22
- Publication Date
- 2025-03-11
AI Technical Summary
In the prior art, when processing Flash memory with all rewritten granularities, the effective data utilization rate is extremely low and cannot be used normally.
By dividing sectors into multiple consecutive Flash pages and dividing each Flash page into a dynamic data storage area and a static data storage area, page granular reading and writing operations are realized.
The data utilization rate of the memory is improved, and the balanced wear of Flash memory with a page-based erase granularity is achieved, which extends the service life of the memory.
Smart Images

Figure CN119597215A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of balanced storage with a flash page as the erasing granularity, and in particular to a storage wear-balancing method and device. Background Art
[0002] In embedded development, data persistence generally uses MCU built-in or external electrically erasable non-volatile memory Flash. Unlike EEPROM, Flash needs to be erased before writing, and the number of Flash erases is limited. The erase granularity is basically based on sectors. If the software does not do any processing and directly stores data, for some user data that needs to be updated frequently, the number of erases and writes may far exceed the limit allowed by Flash during the entire life cycle of the product, and it cannot meet user needs at all. For data with low change frequency, the erase and write life of the sector where it is located will be wasted.
[0003] At present, there are many Flash wear-leveling solutions proposed in the industry. The principle is to use two logical sectors composed of multiple physical sectors, one as the current working sector and the other as the backup sector. When the user requests storage, the data will be written in a certain format and order on the current working sector. When the entire sector is full, the latest data stored will be rewritten to the backup sector, and then the current working sector will be erased. At this time, the roles of the two sectors are exchanged, and subsequent operations are repeated in this way, so as to achieve balanced wear of storage units.
[0004] However, the inventors have found that the minimum write granularity of the Flash in this solution is bytes, and the erase granularity is sectors. For Flash whose erase and write granularity are both pages, the effective data utilization rate of this solution is extremely low and may even be unusable. Summary of the invention
[0005] In view of this, the purpose of the present invention is to provide a storage wear leveling method and device, which divides the sector into multiple continuous Flash pages, and then divides each Flash page into a dynamic data storage area and a static data storage area, so as to alleviate the technical problem in the prior art that the storage leveling effect of Flash with the erase granularity of pages is poor.
[0006] In a first aspect, an embodiment provides a storage wear leveling method, wherein a current working sector is composed of a plurality of continuous Flash pages, the erasing granularity of the current working sector is a Flash page, and each Flash page includes a log area and a data area; the log area records a serial number, a verification code and dynamic data, and the data area is used to record static data; the method comprises:
[0007] Traversing the log area corresponding to each Flash page in the current working sector, and determining the current starting Flash page according to the serial number and the verification code;
[0008] In response to a read data instruction and first user request information, traverse the log area and the data area of each Flash page in the current working sector starting from the starting Flash page, and read the first target data matching the first user request information;
[0009] In response to the write data instruction and the second user request information, the log area of each Flash page in the current working sector is traversed starting from the starting Flash page, the data obtained from the data area in the starting Flash page is updated, combined with the package data determined by the second user request information, and written to the starting Flash page.
[0010] In an optional implementation, the log area is also used to record the initial address, data length and data content of a data block, the data block includes at least one dynamic data; the data area is used to record a single static data corresponding to each address.
[0011] In an optional implementation manner, in response to a read data instruction and first user request information, traversing the log area and the data area of each Flash page in the current working sector starting from the starting Flash page, and reading the first target data matching the first user request information comprises:
[0012] Finding corresponding first static data from the data area of the current working sector according to the first user request information, and updating the first static data starting from the starting Flash page by using the first dynamic data matching the first user request information in the log area of each Flash page in the current working sector;
[0013] In response to the data read instruction, the updated first static data is read; wherein the updated first static data is the first target data matching the first user request information.
[0014] In an optional implementation manner, the first user request information includes a target initial address and a target data length; the step of searching for corresponding first static data from a data area of the current working sector according to the first user request information, and starting from the starting Flash page, using first dynamic data matching the first user request information in a log area of each Flash page in the current working sector, to update the first static data comprises:
[0015] Determine a target address range of the first target data based on a target initial address and a target data length in the first user request information;
[0016] Searching for at least one first static data with a matching address from the data area according to the target address range, and reading the first static data into a read buffer;
[0017] Traversing the log area from the starting Flash page, and determining at least one data block in the target address range from the log area according to the first user request information;
[0018] Each first dynamic data in the data block is used to overwrite the first static data in the read buffer that has the same address as each first dynamic data in the data block.
[0019] In an optional implementation manner, in response to a write data instruction and second user request information, traversing the log area of each Flash page in the current working sector starting from the starting Flash page, updating data obtained from the data area in the starting Flash page, combining the data with the package data determined by the second user request information, and writing the data into the starting Flash page, comprises:
[0020] Acquire the second static data in the data area of the starting Flash page and the address of each second static data, and update the second static data starting from the starting Flash page by using the second dynamic data matching the address of each second static data in the log area of each Flash page in the current working sector;
[0021] In response to a write data instruction, the package data and the updated second static data are written into the starting Flash page; wherein the package data includes a serial number corresponding to the starting Flash page, an initial address corresponding to the second user request information, a data length, dynamic data to be written and a check code set to a valid state.
[0022] In an optional implementation manner, the step of acquiring the second static data in the data area of the starting Flash page and the address of each second static data, and starting from the starting Flash page, using the second dynamic data matching the address of each second static data in the log area of each Flash page in the current working sector, to update the second static data comprises:
[0023] Cache each second static data in the data area of the starting Flash page into a write buffer;
[0024] Starting from the starting Flash page, traversing the log area corresponding to each Flash page in the current working sector, searching for the second dynamic data located in the data block that matches the address of the second static data;
[0025] The second static data in the write buffer having the same address as the second dynamic data is overwritten by the second dynamic data.
[0026] In an optional implementation manner, the step of traversing the log area corresponding to each Flash page in the current working sector and determining the current starting Flash page according to the serial number and the verification code includes:
[0027] Traversing the serial number and the verification code of the log area corresponding to each Flash page in the current working sector;
[0028] Determine whether the Flash page corresponding to each log area is valid based on the verification code;
[0029] The Flash page that is in a valid state and corresponds to the largest sequence number is determined as the current Flash page;
[0030] According to the next page of the current Flash page, the current starting Flash page is determined.
[0031] In a second aspect, an embodiment provides a storage wear leveling device, wherein a current working sector is composed of a plurality of continuous Flash pages, the erasing granularity of the current working sector is a Flash page, and each Flash page includes a log area and a data area; the log area records a serial number, a verification code and dynamic data, and the data area is used to record static data; the device includes:
[0032] A determination module traverses the log area corresponding to each Flash page in the current working sector, and determines the current starting Flash page according to the sequence number and the verification code;
[0033] A reading module, in response to a read data instruction and first user request information, traverses the log area and the data area of each Flash page in the current working sector starting from the starting Flash page, and reads first target data matching the first user request information;
[0034] The writing module, in response to the write data instruction and the second user request information, traverses the log area of each Flash page in the current working sector starting from the starting Flash page, updates the data obtained from the data area in the starting Flash page, combines the data with the package data determined by the second user request information, and writes the data into the starting Flash page.
[0035] In a third aspect, an embodiment provides an electronic device, including a memory and a processor, wherein the memory stores a computer program that can be run on the processor, and when the processor executes the computer program, the steps of the method described in any of the aforementioned implementation methods are implemented.
[0036] In a fourth aspect, an embodiment provides a machine-readable storage medium, wherein the machine-readable storage medium stores machine-executable instructions. When the machine-executable instructions are called and executed by a processor, the machine-executable instructions prompt the processor to implement the steps of the method described in any one of the aforementioned implementations.
[0037] An embodiment of the present invention provides a storage wear leveling method and device, wherein a working sector composed of multiple Flash pages includes a log area for storing dynamic data and a data area for storing static data; a start page is determined from multiple Flash pages through a serial number and a verification code recorded in the log area; in response to user request information for locating target data and corresponding read and write instructions, data located in each Flash page is traversed to participate in reading and writing, so as to achieve a storage wear leveling effect of page-granularity read and write operations.
[0038] Other features and advantages of the present disclosure will be set forth in the following description, or some features and advantages may be inferred or unambiguously determined from the description, or may be learned by implementing the above-mentioned technology of the present disclosure.
[0039] In order to make the above-mentioned objectives, features and advantages of the present disclosure more obvious and easy to understand, preferred embodiments are specifically cited below and described in detail with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0041] Figure 1 A flow chart of a storage wear leveling method provided by an embodiment of the present invention;
[0042] Figure 2 A schematic diagram of a current working sector provided by an embodiment of the present invention;
[0043] Figure 3 Another schematic diagram of a current working sector provided by an embodiment of the present invention;
[0044] Figure 4 A functional module diagram of a storage wear leveling device provided by an embodiment of the present invention;
[0045] Figure 5 A schematic diagram of the hardware architecture of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0046] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the accompanying drawings. Obviously, the described embodiments are 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 the present invention.
[0047] Flash: An electrically erasable non-volatile memory that supports random address reading and writing. An erase operation is required before effective writing, and the number of erase operations is limited. It is widely used in various embedded systems.
[0048] Wear leveling: A Flash erase equalization technology. Since the number of times Flash can be erased is limited, repeated erase and write operations on the same erase unit can easily cause damage and make it unusable. The purpose of this technology is to use each storage unit evenly to avoid certain special blocks from becoming bad blocks due to excessive use.
[0049] Erase granularity: One of the important characteristics of Flash, indicating the smallest erasable unit and the smallest write unit of the memory. The erase granularity may be different for different types and manufacturers. Common erase units include page erase (128B), sector erase (4KB) and block erase; common write units include byte write, word write (4B) and page write (128B); where B is the abbreviation of Byte.
[0050] Currently, if the Flash erase and write granularity is 128 bytes per page, then for the solution of dividing the physical sector into two sector roles, that is, dividing the physical sector into two logical sectors for interchangeable work, the storage limit of the physical sector will be reached after a few read and write operations, and the memory will be unable to continue working, unless a physical sector with a larger memory is used, which will incur a high cost.
[0051] Based on this, the embodiments of the present invention provide a storage wear leveling method and device, which can implement a storage wear leveling solution for Flash with a page erase granularity without using a larger physical sector of memory.
[0052] To facilitate understanding of this embodiment, a storage wear leveling method disclosed in an embodiment of the present invention is first introduced in detail. This method can be applied to intelligent control devices such as host computers, controllers, and servers to control storage devices to achieve a wear leveling effect.
[0053] The storage area in the storage device provided by the storage wear leveling method according to the embodiment of the present invention only needs one Flash logical sector, that is, one working sector. Figure 2As shown, the current working sector is composed of multiple continuous Flash pages, and the erase granularity of the current working sector is a Flash page, and each Flash page includes a log area and a data area; wherein the log area and the data area of each Flash page are configured according to a preset ratio, and the preset ratio of each Flash page configuration is the same; for example, if the preset ratio is 50%, the log area and the data area of each Flash page are distributed in a 1:1 manner; if the size of the Flash page is 128 bytes, the log area and the data area are 64 bytes each; the preset ratio can be adjusted according to the actual situation, and can also be set to other values such as 40%, 60%, etc. Among them, the log area records the serial number, verification code and dynamic data, and the data area is used to record static data. Dynamic data can be understood as the latest data with high real-time performance but time changes, and static data can be understood as data that does not require high real-time performance and generally does not change for a long time.
[0054] Figure 1 A flow chart of a storage wear leveling method provided by an embodiment of the present invention.
[0055] like Figure 1 As shown, the method comprises the following steps:
[0056] Step S102, traverse the log area corresponding to each Flash page in the current working sector, and determine the current starting Flash page according to the sequence number and the verification code.
[0057] Among them, each Flash page corresponds to a serial number recorded in the log area of the Flash page. The size of the serial number can be used to know the arrangement of the Flash page in the continuous Flash pages of the current working sector; each Flash page also corresponds to a verification code recorded in the log area of the Flash page, and the validity of the Flash page can be known through the verification code; according to the size of the Flash page serial number and whether it is valid, the current starting Flash page is determined.
[0058] Step S104 , in response to the data read instruction and the first user request information, traverse the log area and the data area of each Flash page in the current working sector starting from the starting Flash page, and read the first target data matching the first user request information.
[0059] Among them, the first user request information is used to locate the data to be read, that is, the first target data. Under the action of the read data instruction, the log area and data area of each Flash page can be traversed to read the first target data matching the first user request information to achieve the effect of balanced wear.
[0060] Step S106, in response to the write data instruction and the second user request information, the log area of each Flash page in the current working sector will be traversed starting from the starting Flash page, the data obtained from the data area in the starting Flash page will be updated, combined with the package data determined by the second user request information, and written to the starting Flash page.
[0061] Here, the second user request information corresponds to the corresponding information of the data to be written into the log area, such as the starting address, length, data content and other information; the log area of each Flash page is traversed, and the corresponding latest data is captured from the log area to overwrite the data area of the starting Flash page; the log area data corresponding to the second user request information and the updated data area data are combined and written into the starting Flash page.
[0062] In a preferred embodiment of practical application, a working sector composed of multiple Flash pages includes a log area for storing dynamic data and a data area for storing static data; the starting page is determined from the multiple Flash pages by the serial number and verification code recorded in the log area; in response to user request information and corresponding read and write instructions for locating target data, the data located in each Flash page is traversed to participate in reading and writing, so as to achieve a storage wear-balancing effect of page-granularity read and write operations.
[0063] In some embodiments, reference may be made to Figure 3 , assuming that the erase granularity of the current working sector is 2n bytes, the sector used for wear leveling consists of m consecutive Flash pages, the white filling part on the left is the log area, and the gray filling part on the right is the data area; the log area and the data area are configured and distributed in a 1:1 manner, the log area and the data area correspond to n bytes respectively, and the data supported by the current working sector is m*n bytes;
[0064] The data area in the Flash page of Page[j] includes static data in the address range [0, mn-1], and the static data corresponding to the address i in the data area is D[i]; the log area in the Flash page of Page[j] is used to record the serial number Sj, initial address Aj, data length Lj, data content Zj and check code Cj of the latest data block, and the data block includes at least one dynamic data; it can be understood that based on the initial address, data length and data content, the address and data content of each dynamic data in the data block can be known.
[0065] Based on the above-mentioned embodiment, step S102 determines the starting Flash page according to the size of the serial number and the validity of the verification code, and specifically includes:
[0066] Step 1.1), traverse the serial number and verification code of the log area corresponding to each Flash page in the current working sector.
[0067] Here, according to Figure 3 As shown, traverse in the order of sequence numbers from S0->Sm.
[0068] Step 1.2), determine whether the Flash page corresponding to each log area is valid based on the verification code.
[0069] Here, a verification code can be obtained according to a conventional CRC verification method to determine whether the Flash page corresponding to each log area is valid.
[0070] In step 1.3), the Flash page that is in a valid state and corresponds to the largest sequence number is determined as the current Flash page.
[0071] from Figure 3 It can be seen that, from top to bottom of the working sector, the serial number of each Flash page is continuous and incremented by 1, thus presenting the current Flash page with the largest serial number in a valid state.
[0072] Step 1.4), determine the current starting Flash page according to the next page of the current Flash page.
[0073] Here, the log area is traversed in the order of S0->Sm. Assuming that the largest valid sequence number is Sx-1, Page[x-1] is the current Flash page, and the next page of the current Flash page, Page[x], is the starting Flash page.
[0074] In some embodiments, data reading may be implemented according to the structural characteristics of the aforementioned working sectors to ensure the effect of storage wear leveling; specifically, step S104 includes:
[0075] Step 2.1), according to the first user request information, find the corresponding first static data from the data area of the current working sector, and start from the starting Flash page, use the first dynamic data matching the first user request information in the log area of each Flash page in the current working sector to update the first static data.
[0076] Here, the data area of the Flash page of the working sector is traversed to find the corresponding data requested by the user to achieve balanced wear; at the same time, the static data in the data area is overwritten by the newer dynamic data area in the log area, which can make the read data more real-time and more accurate.
[0077] Step 2.2), in response to the read data instruction, read the updated first static data.
[0078] The updated first static data is the first target data matching the first user request information.
[0079] Exemplarily, the first user request information includes a target initial address and a target data length; Figure 3 In the working sector example shown, step 2.1) can also be implemented by the following steps, specifically including:
[0080] Step 2.1.1), based on the target initial address and target data length in the first user request information, determine the target address range of the first target data.
[0081] Assuming that the target initial address in the first user request information is k and the target data length is 3, it can be known that the target address range of the first target data that satisfies the first user request information is [k, k+3-1]. It can be understood that the target address range is the sum of the target initial address and the target data length minus one.
[0082] It should be noted that the target address range must be within the address range [0, mn-1] of the data area.
[0083] Step 2.1.2), searching for at least one first static data with a matching address from the data area according to the target address range, and reading the first static data into the read buffer.
[0084] Here, the corresponding first static data is read from the data area according to the target address range [k, k+3-1], that is, the first static data of the address [k, k+2] is read and stored in the read buffer. If the actual value of k is n+1, the first static data corresponding to the address range [n+1, n+3] is D[n+1], D[n+2] and D[n+3].
[0085] Step 2.1.3), traverse the log area starting from the starting Flash page, and determine at least one data block within the target address range from the log area according to the first user request information.
[0086] According to the records of steps 1.1) to 1.4) of the aforementioned embodiment, the starting Flash page may be Page[x], and the log area is traversed in the order of serial numbers Sx->Sm, S0->Sx-1 to find the dynamic data corresponding to the target address range [n+1, n+3]. It should be noted that the dynamic data that meets the requirements of the target address range may exist in at least one data block, that is, the dynamic data that meets the requirements of the target address range may be composed of dynamic data 1 from data block 1 and dynamic data 2 from data block 2.
[0087] Here, Page[i] is taken as an example for explanation. Its log area data address range is [Ai, Ai+Li-1]. According to the above traversal order, the overlapping part with the address range of [n+1, n+3] is extracted from the data blocks in the log area of each Flash page; for example, the current starting Flash page is Flash page 4, and the target data address range is [2, 6]; the data address of data block 1 in Flash page 4 is [1, 3], and the data block overlapping with the target data address range is [2, 3]. According to the traversal order, it is found that the data address of data block 2 in Flash page 6 is [4, 5], and the data block overlapping with the target data address range is [4, 5].
[0088] Step 2.1.4), using each first dynamic data in the data block, overwrite the first static data in the read buffer that has the same address as each first dynamic data in the data block.
[0089] Here, each first dynamic data in the data block with an address range of [2, 3] in Flash page 4 and each first dynamic data in the data block 2 with an address range of [4, 5] in Flash page 6 are used to overwrite the first static data [2, 5] at the corresponding address in the read buffer respectively; it should be noted that the corresponding first dynamic data at address [6] is not found in the log area, so the first static data at address [6] in the read buffer is not updated and has not changed; at this time, the data at address [2, 6] in the read buffer is the first target data requested by the user to read.
[0090] In some embodiments, data writing may be implemented according to the structural characteristics of the aforementioned working sectors to ensure the effect of storage wear leveling; specifically, step S104 includes:
[0091] 3.1), obtain the second static data and the address of each second static data in the data area of the starting Flash page, and start from the starting Flash page, use the second dynamic data matching the address of each second static data in the log area of each Flash page in the current working sector to update the second static data.
[0092] Here, the second dynamic data having the same address as the second static data is searched for and overwritten by traversing the log area of each Flash page to ensure that the static data written to the data area of the starting Flash page is the latest. With this effect, when each Flash page is erased, the data block Zx recorded in its log area has been saved in the data area before erasing, so when each Flash page is erased, the dynamic data corresponding to the second user request information can be directly written into the log area.
[0093] Exemplarily, step 3.1) also includes the following steps to implement:
[0094] Step 3.1.1), cache each second static data in the data area of the starting Flash page into the write buffer.
[0095] Here, according to the records of steps 1.1) to 1.4) of the above embodiment, the starting Flash page may be Page[x]. At this time, the second static data cached to the write buffer in the data area of the starting Flash page is D[xn]..D[(x+1)n-1].
[0096] Step 3.1.2), starting from the starting Flash page, traverse the log area corresponding to each Flash page in the current working sector to find the second dynamic data located in the data block that matches the address of the second static data.
[0097] The log area is traversed in the order of serial numbers Sx->Sm, S0->Sx-1 to search for the second dynamic data corresponding to the address range [xn, (x+1)n-1]. Here, according to the aforementioned embodiment, the second dynamic data corresponding to the address range [xn, (x+1)n-1] may be distributed in at least one data block, which is not described in detail here.
[0098] Step 3.1.3), using the second dynamic data to overwrite the second static data in the write buffer having the same address as the second dynamic data.
[0099] At this time, the second dynamic data successfully found from the log area according to the address range [xn, (x+1)n-1] is used to update the second static data with the same address in the write buffer according to the addresses respectively corresponding to the second dynamic data.
[0100] 3.2), in response to the write data instruction, write the package data and the updated second static data into the starting Flash page.
[0101] The package data includes the serial number corresponding to the starting Flash page, the initial address corresponding to the second user request information, the data length, the dynamic data to be written and the check code set to a valid state. For example, the second user request information requests the writing of information with the initial address 7, the data length is 2, the dynamic data content is Zx', and the check code generates a corresponding value based on the preset check rule; the package data is obtained by combining the data corresponding to the second user request information with the serial number Sx of Page[x];
[0102] In an embodiment of the present invention, a null character used as a placeholder is determined based on the number of bytes corresponding to the log area and the number of bytes of the package data; under the effect of the null character, the package data and the updated second static data are taken together as page data and written into the page data of Page[x].
[0103] The embodiment of the present invention provides a Flash wear leveling solution based on page erase granularity, based on a storage algorithm of a log area and a data area with a fixed ratio, to store dynamic data and static data respectively, without the need for backup sectors, and with high space utilization; at the same time, the address of the log area used to record dynamic data is fixed, the traversal search efficiency is high, the read and write speed is fast, and the time is controllable; this working sector structure has good scalability, and the Flash page capacity can be expanded without destroying the original data.
[0104] In some embodiments, Figure 4 As shown, the embodiment of the present invention further provides a storage wear leveling device 200, wherein the current working sector is composed of a plurality of continuous Flash pages, the erasing granularity of the current working sector is one Flash page, and each Flash page includes a log area and a data area; the log area records a serial number, a verification code and dynamic data, and the data area is used to record static data; the device comprises:
[0105] The determination module 201 traverses the log area corresponding to each Flash page in the current working sector, and determines the current starting Flash page according to the sequence number and the verification code;
[0106] The reading module 202, in response to the data read instruction and the first user request information, traverses the log area and the data area of each Flash page in the current working sector starting from the starting Flash page, and reads the first target data matching the first user request information;
[0107] The write module 203, in response to the write data instruction and the second user request information, will traverse the log area of each Flash page in the current working sector starting from the starting Flash page, update the data obtained from the data area in the starting Flash page, combine it with the package data determined by the second user request information, and write it into the starting Flash page.
[0108] Furthermore, the log area is also used to record the initial address, data length and data content of the data block, and the data block includes at least one dynamic data; the data area is used to record a single static data corresponding to each address.
[0109] Furthermore, the reading module 202 is specifically used to find the corresponding first static data from the data area of the current working sector according to the first user request information, and starting from the starting Flash page, use the first dynamic data matching the first user request information in the log area of each Flash page in the current working sector to update the first static data; in response to the read data instruction, read the updated first static data; wherein the updated first static data is the first target data matching the first user request information.
[0110] Furthermore, the first user request information includes a target initial address and a target data length; the reading module 202 is specifically used to determine a target address range of the first target data based on the target initial address and the target data length in the first user request information; search for at least one first static data with a matching address from the data area according to the target address range, and read the first static data into a read buffer; traverse the log area starting from the starting Flash page, and determine at least one data block within the target address range from the log area according to the first user request information; and use each first dynamic data in the data block to overwrite the first static data in the read buffer that has the same address as each first dynamic data in the data block.
[0111] Furthermore, the write module 203 is specifically used to obtain the second static data in the data area of the starting Flash page and the address of each second static data, and starting from the starting Flash page, use the second dynamic data matching the address of each second static data in the log area of each Flash page in the current working sector to update the second static data; in response to the write data instruction, write the package data and the updated second static data into the starting Flash page; wherein the package data includes a serial number corresponding to the starting Flash page, an initial address corresponding to the second user request information, a data length, dynamic data to be written and a check code set to a valid state.
[0112] Furthermore, the reading module 202 is specifically used to cache each second static data in the data area of the starting Flash page to the write buffer; traverse the log area corresponding to each Flash page in the current working sector starting from the starting Flash page, and search for the second dynamic data located in the data block that matches the address of the second static data; and use the second dynamic data to overwrite the second static data in the write buffer that has the same address as the second dynamic data.
[0113] Furthermore, the determination module 201 is specifically used to traverse the serial number and the verification code of the log area corresponding to each Flash page in the current working sector; determine whether the Flash page corresponding to each log area is valid based on the verification code; determine the Flash page that is in a valid state and corresponds to the largest serial number as the current Flash page; and determine the current starting Flash page based on the next page of the current Flash page.
[0114] Figure 5 Schematic diagram of the hardware architecture of the electronic device 300 provided in an embodiment of the present invention. Figure 5 As shown, the electronic device 300 includes: a machine-readable storage medium 301 and a processor 302, and may also include a non-volatile storage medium 303, a communication interface 304 and a bus 305; wherein the machine-readable storage medium 301, the processor 302, the non-volatile storage medium 303 and the communication interface 304 communicate with each other through the bus 305. The processor 302 can execute the storage wear leveling method described in the above embodiment by reading and executing the machine-executable instructions for storage wear leveling in the machine-readable storage medium 301.
[0115] The machine-readable storage medium mentioned in this article can be any electronic, magnetic, optical or other physical storage device that can contain or store information, such as executable instructions, data, etc. For example, the machine-readable storage medium can be: RAM (Radom Access Memory), volatile memory, non-volatile memory, flash memory, storage drive (such as hard disk drive), any type of storage disk (such as CD, DVD, etc.), or similar storage medium, or a combination thereof.
[0116] The non-volatile medium may be a non-volatile memory, a flash memory, a storage drive (such as a hard drive), any type of storage disk (such as a CD, DVD, etc.), or a similar non-volatile storage medium, or a combination thereof.
[0117] It can be understood that the specific operation methods of each functional module in this embodiment can refer to the detailed description of the corresponding steps in the above method embodiment, and will not be repeated here.
[0118] The computer-readable storage medium provided in the embodiment of the present invention stores a computer program. When the computer program code is executed, the storage wear leveling method described in any of the above embodiments can be implemented. The specific implementation can be found in the method embodiment, which will not be repeated here.
[0119] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the system and device described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.
[0120] In addition, in the description of the embodiments of the present invention, unless otherwise clearly specified and limited, the terms "installed", "connected", and "connected" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection or an indirect connection through an intermediate medium, or it can be the internal communication of two components. For ordinary technicians in this field, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.
[0121] In the description of the present invention, it should be noted that the terms "center", "upper", "lower", "left", "right", "vertical", "horizontal", "inner", "outer", etc., indicating the orientation or positional relationship, are based on the orientation or positional relationship shown in the drawings, and are only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying 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 limiting the present invention. In addition, the terms "first", "second", and "third" are used for descriptive purposes only, and cannot be understood as indicating or implying relative importance.
[0122] Finally, it should be noted that the above-described embodiments are only specific implementation methods of the present invention, which are used to illustrate the technical solutions of the present invention rather than to limit them. The protection scope of the present invention is not limited thereto. Although the present invention has been described in detail with reference to the aforementioned embodiments, those of ordinary skill in the art should understand that any technician familiar with the technical field can still modify the technical solutions recorded in the aforementioned embodiments within the technical scope disclosed by the present invention, or can easily conceive of changes, or make equivalent replacements for some of the technical features therein. Such modifications, changes or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be covered within the protection scope of the present invention.
Claims
1. A storage wear leveling method, characterized in that: The current working sector is composed of a plurality of continuous Flash pages, the erasing granularity of the current working sector is one Flash page, and each Flash page includes a log area and a data area; The log area records the serial number, verification code and dynamic data, and the data area is used to record static data; The method comprises: Traversing the log area corresponding to each Flash page in the current working sector, and determining the current starting Flash page according to the serial number and the verification code; In response to a read data instruction and first user request information, traverse the log area and the data area of each Flash page in the current working sector starting from the starting Flash page, and read the first target data matching the first user request information; In response to the write data instruction and the second user request information, the log area of each Flash page in the current working sector is traversed starting from the starting Flash page, the data obtained from the data area in the starting Flash page is updated, combined with the package data determined by the second user request information, and written to the starting Flash page.
2. The method according to claim 1, characterized in that The log area is also used to record the initial address, data length and data content of the data block, and the data block includes at least one dynamic data; the data area is used to record a single static data corresponding to each address.
3. The method according to claim 2, characterized in that In response to a read data instruction and first user request information, traversing the log area and the data area of each Flash page in the current working sector starting from the starting Flash page, and reading the first target data matching the first user request information, comprises: Finding corresponding first static data from the data area of the current working sector according to the first user request information, and updating the first static data starting from the starting Flash page by using the first dynamic data matching the first user request information in the log area of each Flash page in the current working sector; In response to the data read instruction, the updated first static data is read; wherein the updated first static data is the first target data matching the first user request information.
4. The method according to claim 3, characterized in that The first user request information includes a target initial address and a target data length; searching for corresponding first static data from a data area of the current working sector according to the first user request information, and starting from the starting Flash page, using first dynamic data matching the first user request information in a log area of each Flash page in the current working sector, to update the first static data, including: Determine a target address range of the first target data based on a target initial address and a target data length in the first user request information; Searching for at least one first static data with a matching address from the data area according to the target address range, and reading the first static data into a read buffer; Traversing the log area from the starting Flash page, and determining at least one data block in the target address range from the log area according to the first user request information; Each first dynamic data in the data block is used to overwrite the first static data in the read buffer that has the same address as each first dynamic data in the data block.
5. The method according to claim 2, characterized in that: In response to a write data instruction and a second user request information, the step of traversing the log area of each Flash page in the current working sector starting from the starting Flash page, updating the data obtained from the data area in the starting Flash page, combining the data with the package data determined by the second user request information, and writing the data into the starting Flash page comprises: Acquire the second static data in the data area of the starting Flash page and the address of each second static data, and update the second static data starting from the starting Flash page by using the second dynamic data matching the address of each second static data in the log area of each Flash page in the current working sector; In response to a write data instruction, the package data and the updated second static data are written into the starting Flash page; wherein the package data includes a serial number corresponding to the starting Flash page, an initial address corresponding to the second user request information, a data length, dynamic data to be written and a check code set to a valid state.
6. The method according to claim 5, characterized in that The step of acquiring the second static data in the data area of the starting Flash page and the address of each of the second static data, and updating the second static data starting from the starting Flash page by using the second dynamic data matching the address of each of the second static data in the log area of each Flash page in the current working sector, comprises: Cache each second static data in the data area of the starting Flash page into a write buffer; Starting from the starting Flash page, traversing the log area corresponding to each Flash page in the current working sector, searching for the second dynamic data located in the data block that matches the address of the second static data; The second static data in the write buffer having the same address as the second dynamic data is overwritten by the second dynamic data.
7. The method according to claim 1, characterized in that The step of traversing the log area corresponding to each Flash page in the current working sector and determining the current starting Flash page according to the sequence number and the verification code includes: Traversing the serial number and the verification code of the log area corresponding to each Flash page in the current working sector; Determine whether the Flash page corresponding to each log area is valid based on the verification code; The Flash page that is in a valid state and corresponds to the largest sequence number is determined as the current Flash page; According to the next page of the current Flash page, the current starting Flash page is determined.
8. A storage wear leveling device, characterized in that: The current working sector is composed of a plurality of continuous Flash pages, the erasing granularity of the current working sector is one Flash page, and each Flash page includes a log area and a data area; The log area records the serial number, verification code and dynamic data, and the data area is used to record static data; The device comprises: A determination module traverses the log area corresponding to each Flash page in the current working sector, and determines the current starting Flash page according to the sequence number and the verification code; A reading module, in response to a read data instruction and first user request information, traverses the log area and the data area of each Flash page in the current working sector starting from the starting Flash page, and reads first target data matching the first user request information; The writing module, in response to the write data instruction and the second user request information, traverses the log area of each Flash page in the current working sector starting from the starting Flash page, updates the data obtained from the data area in the starting Flash page, combines the data with the package data determined by the second user request information, and writes the data into the starting Flash page.
9. An electronic device comprising a memory and a processor, wherein the memory stores a computer program that can be run on the processor, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A machine-readable storage medium, characterized in that: The machine-readable storage medium stores machine-executable instructions. When the machine-executable instructions are called and executed by a processor, the machine-executable instructions prompt the processor to implement the steps of the method described in any one of claims 1 to 7.
Citation Information
Cited By
Data read-write method, device and equipment for EEPROM (Electrically Erasable Programmable
CN120066423A
Embedded data storage method and device, terminal equipment and storage medium
CN120353386A