Memory data processing method, device, computer equipment and storage medium
By judging and selecting appropriate blocks in the memory for data movement, the problem of uneven wear of blocks with large erase and write times of flash memory is solved, achieving wear balance and extending the service life of the memory.
Patent Information
- Application Number
- CN202410725793.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-06
- Publication Date
- 2024-09-06
- Estimated Expiration
- 2044-06-06
AI Technical Summary
In scenarios where hot and cold data change, blocks of flash memory with a larger number of erases and writes will suffer from uneven wear due to continued use, making it difficult to effectively control with existing technology.
By judging the number of flash erase and write times of the memory, select a block that meets specific conditions as the target moving block, and move the data block to be moved to this block to control the frequency of use of blocks with larger flash memory erasing times and achieve wear balancing. Specific steps include determining whether the block to be moved in is the data moving block when performing wear leveling. If the condition is not met, search for a new block, and when the condition is met, record the difference between the data write mark and the sequence number to determine the target block.
This effectively avoids the continued increase in the frequency of use of larger blocks of flash memory erase and write times, ensuring a balanced distribution of wear and tear in the memory and extending the service life of the memory.
Smart Images

Figure CN118295604B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of memory technology, and in particular to a memory data processing method, device, computer equipment and storage medium. Background Art
[0002] The hot and cold data will not remain unchanged, but will change with the user's usage. Therefore, wear leveling moves the cold data on the flash blocks with fewer erase times to the flash blocks with more erase times, and then these cold data become hot data again. When the data on the flash blocks with more erase times are released by the host, wear leveling continues to move the data on the flash blocks with fewer erase times to the released flash blocks with more erase times, making the flash blocks with more erase times continue to grow larger, and eventually the wear becomes more uneven. Summary of the invention
[0003] In view of this, the purpose of the present invention is to overcome the shortcomings of the prior art and provide a memory data processing method, device, equipment and storage medium, which are used to control the usage frequency of flash memory blocks with a large number of erase and write times by judging whether the selected moving-in block meets the data transfer processing conditions when selecting a target moving-in block for moving data from the candidate moving-in blocks, thereby solving the problem of more uneven wear caused by wear leveling in hot and cold data change scenarios.
[0004] The present invention provides the following technical solutions:
[0005] In a first aspect, the present invention provides a memory data processing method, the method comprising:
[0006] When the host writes data to the memory and triggers the memory to change blocks, it is determined whether wear leveling needs to be performed according to the number of flash memory erase and write times of the memory;
[0007] If the wear leveling needs to be performed, searching the memory for a flash memory block with the largest number of erase and write times as a block to be selected for moving in, and determining whether the block to be selected for moving in meets the data moving processing condition;
[0008] The step of judging whether the block to be selected meets the data transfer processing condition includes: judging whether the block to be selected is a data transfer block when performing wear leveling; if the block to be selected is not a data transfer block when performing wear leveling, the block to be selected meets the data transfer processing condition, and the block to be selected is determined to be a target transfer block;
[0009] The data to be transferred of the data block to be transferred is transferred to the target moving-in block through the wear leveling.
[0010] In one embodiment, after the data to be moved of the data block to be moved is moved to the target move-in block by the wear leveling, the step includes:
[0011] Recording data writing as a wear leveling data writing mark in the target moving-in block, and updating the current write data sequence number as the historical write data sequence number to the target moving-in block, wherein the writing mark is used to indicate whether the to-be-selected moving-in block is a data moving-in block when performing wear leveling;
[0012] The current write data sequence number is determined according to the number of times the memory writes the flash memory.
[0013] In one embodiment, after determining whether the to-be-selected block is a data-moving block for performing wear leveling, the method further includes:
[0014] If the block to be selected is the data block to be moved in when performing wear leveling, determining a sequence number difference between a historical write data sequence number and a current write data sequence number of the block to be selected, and judging whether the sequence number difference is greater than a target threshold;
[0015] If the sequence number difference is greater than the target threshold, the block to be selected meets the data handling condition, and the block to be selected is determined as the target block to be selected;
[0016] The increment value of the serial number after the host performs a full disk write to the memory is determined, and the target threshold is determined according to the product of the target multiple and the increment value of the serial number.
[0017] In one embodiment, after determining whether the sequence number difference is greater than a target threshold, the method further includes:
[0018] If the serial number difference is less than or equal to the target threshold, the block to be selected does not meet the data transfer processing conditions, and based on the number of flash memory erases and writes of the block to be selected, a new block to be selected is searched from the memory again, and the step of determining whether the new block to be selected meets the processing conditions is executed on the new block to be selected.
[0019] In one embodiment, the step of searching for a new block to be selected from the memory based on the number of times the flash memory of the block to be selected is erased and written comprises:
[0020] The number of times the flash memory of the block to be moved in is erased is used as the search upper limit;
[0021] The new block to be selected is searched from the memory based on the search upper limit.
[0022] In one implementation, determining whether wear leveling needs to be performed includes:
[0023] Determine whether the number of times that wear leveling is not performed on the memory is a first value;
[0024] If the number of times that wear leveling is not performed is not the first value, the number of times that wear leveling is not performed is decreased;
[0025] If the number of times that wear leveling is not performed is the first value, determining the erasure difference between the maximum number of flash memory erasures and the minimum number of flash memory erasures in the memory, and judging whether the erasure difference is greater than or equal to a tolerable threshold;
[0026] If the erase / write difference is greater than or equal to the tolerable threshold, the wear leveling needs to be performed.
[0027] In one embodiment, the method further comprises:
[0028] If the number of times the candidate block does not meet the data transfer processing conditions is greater than the target number, the step of searching for a new candidate block from the memory is stopped, and the number of times wear leveling is not performed is updated from the first value to the second value.
[0029] In a second aspect, the present invention provides a memory data processing device, wherein:
[0030] A judgment module, used for judging whether wear leveling needs to be performed according to the number of flash memory erase and write times of the memory when the host writes data to the memory to trigger the memory block change;
[0031] A search module, used for searching the flash memory block with the largest number of erasure times as a block to be selected for moving in from the memory if the wear leveling needs to be performed, and determining whether the block to be selected for moving in meets the data moving processing condition;
[0032] The search module is further used to determine whether the block to be selected is a data-moving block when performing wear leveling; if the block to be selected is not a data-moving block when performing wear leveling, the block to be selected satisfies the data handling processing condition, and determines that the block to be selected is a target moving-in block;
[0033] The transport module is used to move the to-be-transferred data of the to-be-transferred data block to the target move-in block through the wear leveling.
[0034] In a third aspect, the present invention proposes a computer device, comprising a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the steps of the memory data processing method described in the first aspect are implemented.
[0035] In a fourth aspect, the present invention proposes a computer-readable storage medium storing a computer program, wherein the computer program, when executed by a processor, implements the steps of the memory data processing method as described in the first aspect.
[0036] The memory data processing method, device, equipment and storage medium disclosed in the present invention, when the host writes data to the memory, it is determined whether wear leveling needs to be performed according to the number of times the flash memory of the memory is erased and written; if the wear leveling needs to be performed, the block with the largest number of times the flash memory is erased and written is searched from the memory as a block to be selected for moving in, and it is determined whether the block to be selected for moving in meets the data transfer processing conditions; wherein the step of determining whether the block to be selected for moving in meets the data transfer processing conditions comprises: determining whether the block to be selected for moving in is a data moving in block when wear leveling is performed; if the block to be selected for moving in is not a data moving in block when wear leveling is performed, the block to be selected for moving in meets the data transfer processing conditions, and determining the The block to be selected is the target block to be selected. If the block to be selected is not the data block to be moved in when performing wear leveling, determine whether the difference between the historical write data sequence number and the current write data sequence number of the block to be selected is greater than the target threshold. If it is greater than the target threshold, the data handling condition is met. Otherwise, based on the wear times of the block to be selected as the upper limit, the block to be selected is searched again. When the number of searches reaches a certain number, the number of times the memory does not perform wear leveling is set. The value is decremented each time it is determined whether wear leveling is performed until it reaches 0. Then, whether wear leveling is performed is determined based on the maximum and minimum wear difference of the memory. The data to be moved of the data block to be moved is moved to the target block to be moved in through the wear leveling. In this way, by determining whether the block to be selected meets the data handling condition, the use frequency of the block with a large number of flash memory erase and write times is controlled, and the number of flash memory erase and write times of the block with a large number of flash memory erase and write times in the memory is prevented from continuously increasing, thereby ensuring effective wear leveling.
[0037] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and understandable, preferred embodiments are given below and described in detail with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for use in the embodiments are briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present invention and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without creative work.
[0039] Figure 1 A schematic diagram of a flow chart of a memory data processing method proposed by the present invention is shown;
[0040] Figure 2Another schematic diagram of the flow of the memory data processing method proposed by the present invention is shown;
[0041] Figure 3 Another schematic diagram of the flow chart of the memory data processing method proposed by the present invention is shown;
[0042] Figure 4 Another schematic diagram of a flow chart of the memory data processing method proposed by the present invention is shown;
[0043] Figure 5 A schematic structural diagram of a memory data processing device proposed by the present invention is shown. DETAILED DESCRIPTION
[0044] Embodiments of the present invention are described in detail below, examples of which are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention, and cannot be understood as limiting the present invention.
[0045] It should be noted that the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined as "first" and "second" may explicitly or implicitly include one or more of the features. In the description of the present invention, the meaning of "plurality" is two or more, unless otherwise clearly and specifically defined.
[0046] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein in the specification of the template are only for the purpose of describing specific embodiments and are not intended to limit the present invention. The term "and / or" used herein includes any and all combinations of one or more of the related listed items.
[0047] Example 1
[0048] The disclosed embodiment provides a memory data processing method, which is used to control the usage frequency of flash memory blocks with a large number of erase and write times by judging whether the target moving-in block for moving data meets the data moving processing conditions when selecting the target moving-in block from the moving-in blocks to be selected, thereby solving the problem of more uneven wear caused by performing wear leveling in the scenario of cold and hot data changes.
[0049] See also Figure 1 The memory data processing method includes steps S101 to S103, and each step is described in detail below.
[0050] S101, when the host writes data to the memory and triggers the memory to change blocks, it is determined whether wear leveling needs to be performed according to the number of flash memory erase and write times of the memory.
[0051] In this embodiment, when a new block is requested from the memory to write host data, the requested new block will be erased first and then the data will be written. At this time, writing data to the erased new block will cause the flash memory to have a program / erase cycle (PE) change. Therefore, the memory needs to determine whether its own PE is unbalanced, and then determine whether wear leveling (WL) needs to be performed. In this way, the wear level of each flash memory particle can be kept in a relatively consistent state and finally scrapped at the same time.
[0052] In a specific embodiment, the determination of whether wear leveling needs to be performed includes: determining whether the number of times that wear leveling is not performed in the memory is a first value; if the number of times that wear leveling is not performed is not the first value, the number of times that wear leveling is not performed decreases; if the number of times that wear leveling is not performed is the first value, determining the erasure difference between the maximum number of flash memory erase times and the minimum number of flash memory erase times in the memory, and determining whether the erasure difference is greater than or equal to a tolerable threshold; if the erasure difference is greater than or equal to the tolerable threshold, wear leveling needs to be performed.
[0053] It should be noted that the number of times that wear leveling is not performed is a variable that can be used to control whether to perform wear leveling after the memory applies for a new block. For example, if the number of times that wear leveling is not performed is set to 2, then after the variable is set, the variable value is decremented each time the memory applies for a new block, and when the variable value is 0, it is necessary to determine whether wear leveling needs to be performed.
[0054] In this embodiment, after the memory applies for a new block, the memory needs to first determine whether the number of times that wear leveling is not performed at this time is a first value, and the first value can be 0; when the number of times that wear leveling is not performed is not 0, that is, the memory does not perform wear leveling when applying for a new block this time, then the number of times that wear leveling is not performed at this time is reduced by 1; if the number of times that wear leveling is not performed is 0, that is, wear leveling can be performed at this time, then the erase difference (PE difference) between the maximum PE value and the minimum PE value in the memory is determined, and the memory then determines whether the erase difference is greater than or equal to a tolerable threshold; if the PE difference is greater than or equal to the tolerable threshold, wear leveling needs to be performed, thereby ensuring that the PE gap in the memory is small.
[0055] Step S102: if the wear leveling needs to be performed, a block with the largest number of flash memory erase and write times is searched from the memory as a block to be selected for moving in, and it is determined whether the block to be selected for moving in meets the data transfer processing conditions.
[0056] In this embodiment, when the number of times that wear leveling is not performed is 0, and the PE difference between the maximum PE value and the minimum PE value in the memory is greater than or equal to the tolerable threshold, and wear leveling needs to be performed, the data block with the largest PE value is searched from the free blocks of the memory as the block to be selected for moving in, and it is determined whether the block to be selected for moving in meets the data transfer condition. In this way, the data block with the largest PE value can be prevented from being moved into hot data again, thereby preventing more uneven wear.
[0057] See also Figure 2 In a specific embodiment, the step of determining whether the block to be selected meets the data transfer processing conditions includes step S1021 to step S1022, and each step is described in detail below.
[0058] Step S1021, determining whether the block to be selected is a data-moving block for performing wear leveling.
[0059] Step S1022: If the block to be selected is not the data block to be moved in when performing wear leveling, the block to be selected satisfies the data transfer processing condition, and the block to be selected is determined as the target block to be moved in.
[0060] In this embodiment, after finding the block to be selected, it is determined whether the block to be selected is the data block to be moved in when executing WL based on the metadata of the block to be selected; if the block to be selected is not the data block to be moved in when executing WL, then the block to be selected meets the data transfer processing conditions and is determined to be the target block to be moved in.
[0061] It should be noted that if the block to be selected is a data-moving block when performing wear leveling, it means that the block to be selected is a block with a large PE of cold data written in the last WL. However, the block to be selected is released and new data is written, which means that the data written in the block to be selected is not cold data, but hot data. Continuing to use it will make the PE of the block to be selected become larger, and the wear will eventually be more uneven. Therefore, in order to avoid more uneven wear, it is necessary to move data to the block to be selected when the block to be selected is not a data-moving block when performing WL.
[0062] Step S103, moving the data to be moved of the data block to be moved to the target incoming block through the wear leveling.
[0063] In this embodiment, the smaller PE block is used as the data block to be moved; when the target moving-in block that meets the data moving processing conditions is determined, the valid data on the data block to be moved, that is, the data to be moved, is moved to the target moving-in block, so as to avoid WL from continuing to move the data on the smaller PE block to the larger PE block that has just released the data, thereby avoiding the PE of the larger PE block from continuing to grow larger.
[0064] In a specific embodiment, after the data to be moved of the data block to be moved is moved to the target moving-in block through the wear leveling, it includes: recording the data written in the target moving-in block as a write mark of wear leveling data, and updating the current write data sequence number as the historical write data sequence number to the target moving-in block, the write mark is used to indicate whether the selected moving-in block is a data moving-in block when performing wear leveling; wherein the current write data sequence number is determined according to the number of times the memory writes the flash memory.
[0065] In this embodiment, each time the host writes data to the memory, it synchronously records in the metadata of the target moved-in block that the target moved-in block is marked by the WL to move data from a smaller block of PE to it, that is, the write mark is used to indicate whether the target moved-in block is a data moved-in block for performing wear leveling when it is used as a candidate moved-in block for the next data processing. In other words, in step S1021, whether the candidate moved-in block meets the data transfer processing conditions can be determined based on whether the metadata of the candidate moved-in block contains a write mark.
[0066] And the current write data sequence number is generated according to the number of times the data is written; at the same time, when a data block of the memory is used as a moving-in block and data is moved in by WL, the moving-in block will synchronously record the current write data sequence number and use it as its own historical write data sequence number. For example, when the memory writes data to the flash memory for the 3001th time, the current write data sequence number is generated as 3001, and when the host performs WL data transfer on the determined moving-in block after writing data this time, the current write data sequence number 3001 will be recorded as the historical write data sequence number to the moving-in block.
[0067] See also Figure 3 In a specific embodiment, after determining whether the block to be selected is a data block to be moved in when performing wear leveling, it also includes steps S1023 to S1024, and each step is described in detail below.
[0068] Step S1023, if the block to be selected is the data block to be moved in when performing wear leveling, determine the sequence number difference between the historical write data sequence number and the current write data sequence number of the block to be selected, and judge whether the sequence number difference is greater than the target threshold.
[0069] Step S1024: If the sequence number difference is greater than the target threshold, the block to be selected meets the data transfer processing condition, and the block to be selected is determined as the target block to be selected.
[0070] In this embodiment, the serial number increment value after the host writes a round of data to all data blocks in the memory is determined, and the target threshold is determined according to the product of the target multiple and the serial number increment value. Among them, the target multiple can be 4. If the block to be selected is a data moving-in block when performing wear leveling, the serial number difference between the historical write data serial number of the block to be selected and the current write data serial number corresponding to the host's current write data is determined, and it is determined whether the serial number difference is greater than the target threshold; if the serial number difference is greater than the target threshold, the block to be selected meets the data handling processing conditions, and the block to be selected is determined as the target moving-in block.
[0071] It should be noted that if the difference between the historical write data sequence number and the current write data sequence number of the block to be moved in is greater than the sequence number increase value of a round of writing of all blocks, it means that the data in the block to be moved in has not been released or erased for a long time after being written and is used again after being released or erased. The sequence number increase value greater than 4 times is to control the block storing hot data to be used 4 times before the block is reused, so as to reduce the frequency of use of larger PE blocks.
[0072] In a specific embodiment, after determining whether the serial number difference is greater than a target threshold, the step further includes: if the serial number difference is less than or equal to the target threshold, the block to be selected does not meet the data transfer processing conditions, and based on the number of flash memory erase and write times of the block to be selected, a new block to be selected is searched from the memory again, and the step of determining whether the block to be selected meets the data transfer processing conditions is executed on the new block to be selected.
[0073] In this embodiment, if the serial number difference is less than or equal to the target threshold, the block to be selected does not meet the data transfer processing conditions, and a new block to be selected is searched again from the free blocks in the memory except the block to be selected corresponding to the serial number difference. In other words, the data block with the largest PE value except the block to be selected corresponding to the serial number difference is searched from the memory as the new block to be selected; and it is judged whether the new block to be selected meets the data transfer processing conditions.
[0074] It should be noted that before determining whether the new block to be selected meets the data transfer processing conditions, it is also necessary to determine whether the PE difference between the PE value of the new block to be selected and the minimum PE value of the memory is within the tolerable threshold for triggering WL data transfer. If the PE difference at this time is less than the tolerable threshold, stop querying the new block to be selected and cancel the WL data transfer process.
[0075] See also Figure 4 In a specific embodiment, the step of searching for a new block to be selected from the memory based on the number of flash memory erases and writes of the block to be selected includes steps S401 to S402. Each step is described in detail below.
[0076] Step S401, taking the number of times the flash memory of the block to be moved in is erased and written as the search upper limit.
[0077] Step S402: searching the memory for the new block to be selected based on the search upper limit.
[0078] In this embodiment, the PE value of the block to be selected for moving in is used as the search upper limit, and a data block with the largest PE value is searched downward according to the search upper limit as a new block to be selected for moving in.
[0079] In a specific embodiment, if the number of times the candidate block is searched for and does not meet the data transfer processing conditions is greater than the target number, the step of searching the candidate block from the memory is stopped, and the number of times wear leveling is not performed is updated from the first value to the second value.
[0080] In this embodiment, if the number of times the search for the candidate block to be moved in does not meet the data transfer processing conditions is greater than the target number, the step of searching for a new candidate block to be moved in from the memory is stopped, and the current WL data movement process is canceled. At the same time, the number of times wear leveling is not performed is updated from the first value to the second value.
[0081] Among them, the target number of times can be set to 5. When the block to be selected and moved in found by step S102 does not meet the data handling condition, four new blocks to be selected and moved in are searched again, and none of them meet the data handling condition. At this time, the search for new blocks to be selected and moved in from the memory is stopped. At the same time, the second value can also be set to other values other than the first value according to actual needs. For example, when the first value is 0, the second value can be 100. When the memory applies for a new block once, the second value is reduced by 1 until the second value 100 decreases to the first value 0, and it is re-determined whether the tolerable threshold for triggering WL is reached to determine whether WL is needed. In this way, when the block to be moved in by WL cannot be found, frequent searches can be avoided.
[0082] The memory data processing method proposed in this embodiment, when the memory applies for a new block once, determines whether it is necessary to perform wear leveling according to the number of flash memory erase and write times of the memory; if the wear leveling needs to be performed, the block with the largest number of flash memory erase and write times is searched from the memory as a block to be selected for moving in, and determines whether the block to be selected for moving in meets the data handling conditions; wherein, the step of determining whether the block to be selected for moving in meets the data handling conditions includes: determining whether the block to be selected for moving in is a data moving in block when performing wear leveling; if the block to be selected for moving in is not a data moving in block when performing wear leveling, the block to be selected for moving in meets the data handling conditions, and determines that the block to be selected for moving in is a target moving in block; and the data to be moved of the data block to be moved to the target moving in block through the wear leveling. In this way, by determining whether the block to be selected for moving in meets the data handling conditions, the use frequency of the block with a larger number of flash memory erase and write times is controlled, and the number of flash memory erase and write times of the block with a larger number of flash memory erase and write times in the memory is prevented from continuously increasing, thereby ensuring effective wear leveling.
[0083] Example 2
[0084] In addition, the present disclosure provides a memory data processing device 500, see Figure 5 , the device comprises:
[0085] A judgment module 501 is used to judge whether wear leveling needs to be performed according to the number of flash memory erase and write times of the memory when the host writes data to the memory to trigger the memory block change;
[0086] A search module 502 is used for searching a flash memory block with the largest number of erasure times as a block to be selected for loading from the memory if the wear leveling needs to be performed, and determining whether the block to be selected for loading satisfies a data transfer processing condition;
[0087] The search module 502 is further used to determine whether the block to be selected is a data-moving block when performing wear leveling; if the block to be selected is not a data-moving block when performing wear leveling, the block to be selected satisfies the data transfer processing condition, and the block to be selected is determined to be a target moving-in block;
[0088] The transfer module 503 is used to transfer the data to be transferred of the data block to be transferred to the target moving-in block through the wear leveling.
[0089] Optionally, the transport module 503 is further used to record the data written in the target moved-in block as a wear leveling data write mark, and update the current write data sequence number as the historical write data sequence number to the target moved-in block, and the write mark is used to indicate whether the selected moved-in block is a data moved-in block when performing wear leveling;
[0090] The device also includes a synthesis module, which is used to determine the current write data sequence number according to the number of times the memory writes the flash memory.
[0091] Optionally, the search module 502 is further configured to determine, if the block to be selected is the data moving-in block when performing wear leveling, a sequence number difference between a historical write data sequence number and a current write data sequence number of the block to be selected, and judge whether the sequence number difference is greater than a target threshold; if the sequence number difference is greater than the target threshold, the block to be selected satisfies the data transfer processing condition, and the block to be selected is determined to be the target moving-in block;
[0092] The comprehensive module is also used to determine the serial number increase value after the host performs a full disk write to the memory, and determine the target threshold value according to the product of the target multiple and the serial number increase value.
[0093] Optionally, the search module 502 is also used to, if the serial number difference is less than or equal to the target threshold, then the block to be selected does not meet the data transfer processing conditions, and based on the number of flash memory erases and writes of the block to be selected, search for a new block to be selected from the memory again, and execute the step of determining whether the new block to be selected meets the processing conditions.
[0094] Optionally, the search module 502 is further configured to use the number of times the flash memory of the block to be selected is erased and written as an upper limit for the search; and search the memory for the new block to be selected based on the upper limit for the search.
[0095] Optionally, the judgment module 501 is also used to judge whether the number of times that wear leveling is not executed in the memory is a first value; if the number of times that wear leveling is not executed is not the first value, the number of times that wear leveling is not executed decreases; if the number of times that wear leveling is not executed is the first value, the erase difference between the maximum erase number and the minimum erase number of the flash memory in the memory is determined, and it is judged whether the erase difference is greater than or equal to a tolerable threshold; if the erase difference is greater than or equal to the tolerable threshold, the wear leveling needs to be executed.
[0096] Optionally, the search module 502 is also used to stop executing the step of searching for a new block to be moved in from the memory if the number of times the block to be moved in is searched and does not satisfy the data transfer processing conditions is greater than a target number, and update the number of times wear leveling is not performed from the first value to a second value.
[0097] The device provided in the embodiment of the present disclosure can execute the steps of the memory data processing method provided in Example 1, which will not be described again to avoid repetition.
[0098] The memory data processing device proposed in this embodiment, when the host writes data to the memory, determines whether it is necessary to perform wear leveling according to the number of times the flash memory of the memory is erased and written; if the wear leveling needs to be performed, the block with the largest number of times the flash memory is erased and written is searched from the memory as a block to be selected for moving in, and determines whether the block to be selected for moving in meets the data handling conditions; wherein, the step of determining whether the block to be selected for moving in meets the data handling conditions includes: determining whether the block to be selected for moving in is a data moving in block when performing wear leveling; if the block to be selected for moving in is not a data moving in block when performing wear leveling, the block to be selected for moving in meets the data handling conditions, and determines that the block to be selected for moving in is a target moving in block; and the data to be moved of the data block to be moved to the target moving in block through the wear leveling. In this way, by determining whether the block to be selected for moving in meets the data handling conditions, the use frequency of the block with a larger number of times the flash memory is erased and written is controlled, and the number of times the flash memory erased and written of the block with a larger number of times in the memory is prevented from continuously increasing, thereby ensuring effective wear leveling.
[0099] Example 3
[0100] In addition, an embodiment of the present disclosure provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the memory data processing method described in Embodiment 1 is implemented.
[0101] The device provided in the embodiment of the present disclosure can execute the steps of the memory data processing method provided in Example 1, which will not be described again to avoid repetition.
[0102] Example 4
[0103] The embodiment of the present disclosure provides a computer-readable storage medium storing a computer program. When the computer program is executed by a processor, the memory data processing method described in Embodiment 1 is implemented.
[0104] In this embodiment, the computer-readable storage medium may be a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.
[0105] The computer-readable storage medium provided in this embodiment can implement the memory data processing method provided in Embodiment 1, and will not be described again here to avoid repetition.
[0106] In all examples shown and described herein, any specific values should be interpreted as merely exemplary and not as limiting, and thus other examples of the exemplary embodiments may have different values.
[0107] It should be noted that similar reference numerals and letters denote similar items in the following drawings, and therefore, once an item is defined in one drawing, further definition and explanation thereof is not required in subsequent drawings.
[0108] The above-mentioned embodiments only express several implementation methods of the present invention, and the description thereof is relatively specific and detailed, but it cannot be understood as limiting the scope of the present invention. It should be pointed out that for ordinary technicians in this field, several modifications and improvements can be made without departing from the concept of the present invention, which all belong to the protection scope of the present invention.
Claims
1. A memory data processing method, It is characterized in that The method comprises: When the host writes data to the memory and triggers the memory to change blocks, it is determined whether wear leveling needs to be performed according to the number of flash memory erase and write times of the memory; If the wear leveling needs to be performed, searching the memory for a flash memory block with the largest number of erase and write times as a block to be selected for moving in, and determining whether the block to be selected for moving in meets the data moving processing condition; The step of judging whether the block to be selected meets the data transfer processing condition includes: judging whether the block to be selected is a data transfer block when performing wear leveling; if the block to be selected is not a data transfer block when performing wear leveling, the block to be selected meets the data transfer processing condition, and the block to be selected is determined to be a target transfer block; The data to be moved of the data block to be moved is moved to the target moving-in block by the wear leveling; After the data to be transferred of the data block to be transferred is moved to the target moving-in block by the wear leveling, the method includes: updating the current write data sequence number as the historical write data sequence number to the target move-in block, wherein the current write data sequence number is determined according to the number of times the memory writes the flash memory; After determining whether the to-be-selected moving-in block is a data moving-in block for performing wear leveling, the method further includes: If the block to be selected is the data block to be moved in when performing wear leveling, determining a sequence number difference between a historical write data sequence number and a current write data sequence number of the block to be selected, and judging whether the sequence number difference is greater than a target threshold; If the sequence number difference is greater than the target threshold, the block to be selected meets the data handling condition, and the block to be selected is determined as the target block to be selected; The increment value of the serial number after the host performs a full disk write to the memory is determined, and the target threshold is determined according to the product of the target multiple and the increment value of the serial number.
2. The memory data processing method according to claim 1, It is characterized in that After the data to be transferred of the data block to be transferred is moved to the target moving-in block by the wear leveling, the method includes: A write mark indicating that the written data is wear leveling data is recorded in the target moved-in block, and the write mark is used to indicate whether the to-be-selected moved-in block is a data moved-in block when performing wear leveling.
3. The memory data processing method according to claim 1, It is characterized in that After determining whether the sequence number difference is greater than the target threshold, the method further includes: If the serial number difference is less than or equal to the target threshold, the block to be selected does not meet the data transfer processing conditions, and based on the number of flash memory erases and writes of the block to be selected, a new block to be selected is searched from the memory again, and the step of determining whether the new block to be selected meets the processing conditions is executed on the new block to be selected.
4. The memory data processing method according to claim 3, It is characterized in that The step of searching for a new block to be selected for moving in from the memory based on the number of times the flash memory of the block to be selected for moving in is written and erased includes: The number of flash memory erasures and writes of the selected moving-in block corresponding to the serial number difference is used as the search upper limit; The new block to be selected is searched from the memory based on the search upper limit.
5. The memory data processing method according to claim 1, It is characterized in that The determining whether wear leveling needs to be performed includes: Determine whether the number of times that wear leveling is not performed on the memory is a first value; If the number of times that wear leveling is not performed is not the first value, the number of times that wear leveling is not performed is decreased; If the number of times that wear leveling is not performed is the first value, determining the erasure difference between the maximum number of flash memory erasures and the minimum number of flash memory erasures in the memory, and judging whether the erasure difference is greater than or equal to a tolerable threshold; If the erase / write difference is greater than or equal to the tolerable threshold, the wear leveling needs to be performed.
6. The memory data processing method according to claim 5, It is characterized in that The method further comprises: If the number of times the candidate block does not meet the data transfer processing conditions is greater than the target number, the step of searching for a new candidate block from the memory is stopped, and the number of times wear leveling is not performed is updated from the first value to the second value.
7. A memory data processing device, It is characterized in that The device: A judgment module, used for judging whether wear leveling needs to be performed according to the number of flash memory erase and write times of the memory when the host writes data to the memory to trigger the memory block change; A search module, used for searching the flash memory block with the largest number of erasure times as a block to be selected for moving in from the memory if the wear leveling needs to be performed, and determining whether the block to be selected for moving in meets the data moving processing condition; The search module is further used to determine whether the block to be selected is a data-moving block when performing wear leveling; if the block to be selected is not a data-moving block when performing wear leveling, the block to be selected meets the data handling processing condition, and the block to be selected is determined to be a target moving-in block; A transport module, used for moving the to-be-transferred data of the to-be-transferred data block to the target move-in block through the wear leveling; The transport module is further used to update the current write data sequence number as the historical write data sequence number to the target move-in block; The device further comprises a comprehensive module, the comprehensive module being used to determine the current write data sequence number according to the number of times the memory writes the flash memory; The search module is further configured to determine a sequence number difference between a historical write data sequence number and a current write data sequence number of the block to be selected for moving in, and determine whether the sequence number difference is greater than a target threshold value if the block to be selected for moving in is the data moving in block when performing wear leveling; If the sequence number difference is greater than the target threshold, the block to be selected meets the data handling condition, and the block to be selected is determined as the target block to be selected; The comprehensive module is also used to determine the serial number increase value after the host performs a full disk write to the memory, and determine the target threshold value according to the product of the target multiple and the serial number increase value.
8. A computer device, It is characterized in that The method comprises a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the steps of the memory data processing method according to any one of claims 1 to 6 are implemented.
9. A computer-readable storage medium, It is characterized in that It stores a computer program, which, when executed by a processor, implements the steps of the memory data processing method according to any one of claims 1 to 6.
