Memory wear leveling method and device, equipment and medium
By defining high-priority and low-priority garbage collection status in memory, and dynamically adjusting the garbage collection strategy according to the number of times the flash memory can erase, the performance fluctuations caused by the wear balance mechanism in the test are solved to ensure the normal operation and performance of the memory.
Patent Information
- Application Number
- CN202410925101.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-11
- Publication Date
- 2024-11-12
AI Technical Summary
In embedded memory firmware testing, long-term tests and multiple rounds of full-disk loops overwriting will cause an increase in the difference in the number of flash erasable writes, which will in turn initiate the wear balance mechanism and affect memory performance.
By defining high-priority and low-priority garbage collection queues and active states, the memory-based flash memory erasable times sets the corresponding state and performs high-priority or low-priority garbage collection to avoid excessive or invalid Balanced wear.
It effectively avoids memory performance fluctuations, prevents excessive wear and balance or invalid wear and balance, and ensures the normal operation and performance of the memory.
Smart Images

Figure CN118942524A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of memory technology, and in particular to a memory wear leveling method, device, equipment and medium. Background Art
[0002] In the current mainstream embedded memory firmware testing, especially on mobile phone platforms such as Android, some data is usually pre-filled before performance testing, and then a test lasting several days is run. After the test, the difference in the number of times the flash memory can be erased and written to the memory block will increase too much. Or before the performance test, multiple rounds of full disk cycle overwrites are run, which will also cause the difference in the number of times the flash memory can be erased and written to the block to increase too much. If the test is run again at this time, the wear leveling mechanism will be activated, causing fluctuations in the test performance. Summary of the invention
[0003] In view of this, the purpose of the present invention is to overcome the deficiencies in the prior art and to provide a memory wear leveling method, apparatus, device and medium for performing corresponding garbage collection according to the specific state of the memory and the urgency of garbage collection to avoid affecting the normal operation and performance of the memory.
[0004] The present invention provides the following technical solutions:
[0005] In a first aspect, the present invention provides a memory wear leveling method, the method comprising:
[0006] Define the first queue state corresponding to high priority balanced garbage collection and the second queue state corresponding to low priority balanced garbage collection;
[0007] Setting the first queue state or the second queue state based on the number of times the flash memory of the memory can be erased and written;
[0008] defining a first activity state corresponding to the high priority balanced garbage collection and a second activity state corresponding to the low priority balanced garbage collection;
[0009] Based on the memory state and according to the setting status of the first queue state or the setting status of the second queue state, the first active state or the second active state is set, and the corresponding first queue state and second queue state are cleared.
[0010] In one embodiment, the setting of the first queue state or the second queue state based on the maximum number of times the flash memory can be erased and written includes:
[0011] Obtaining the maximum flash erasable times and the minimum flash erasable times of the entire disk of the memory, as well as the maximum flash erasable times of the free blocks and the minimum flash erasable times of the data blocks in the memory;
[0012] Determine the difference between the maximum erasable number of times of the flash memory of the entire disk and the minimum erasable number of times of the flash memory of the entire disk to obtain a first erasable difference;
[0013] Determine the difference between the maximum erasable number of times of the free block flash memory and the minimum erasable number of times of the data block flash memory to obtain a second erasable difference;
[0014] Determine a difference between a preset threshold and a preset value to obtain a third tolerable difference;
[0015] The first queue state or the second queue state is set based on a comparison result of the first erasable difference value, the second erasable difference value, the third tolerable difference value, and the preset threshold.
[0016] In one embodiment, the setting of the first queue state or the second queue state based on the comparison result of the first erasable difference value, the second erasable difference value, the third tolerable difference value, and the preset threshold value includes:
[0017] Determining whether the first erasable difference and the second erasable difference are both greater than the third tolerable difference;
[0018] If the first erasable difference value and the second erasable difference value are both greater than the third tolerable difference value, setting the second queue state;
[0019] If the first erasable difference value and the second erasable difference value are both equal to the third tolerable difference value, setting the first queue state;
[0020] If the first erasable difference value and the second erasable difference value are both smaller than the third tolerable difference value, determining whether the first erasable difference value and the second erasable difference value are both greater than the preset threshold value;
[0021] If the first erasable difference value and the second erasable difference value are both greater than the preset threshold value, the first queue state is set.
[0022] In one embodiment, the setting of the first active state or the second active state based on the memory state according to the setting of the first queue state or the setting of the second queue state, and clearing the corresponding first queue state and second queue state includes:
[0023] If the first queue state is set, and the first queue state belongs to write garbage collection, then the first activity state is set, and the first queue state and the second queue state are cleared;
[0024] If the second queue state is set, and the second queue state belongs to idle garbage collection, the second active state is set, and the second queue state is cleared.
[0025] In one embodiment, the method further comprises:
[0026] When the first activity state is set and the memory state is a write state, the high priority balanced garbage collection is normally performed based on the first activity state;
[0027] When the second activity state is set and the memory state is an idle state, the low priority balanced garbage collection performed based on the second activity state is exited.
[0028] In one embodiment, the method further comprises:
[0029] When the third activity state corresponding to the empty block sufficient garbage collection is set, and the memory state is a write state, then the empty block sufficient garbage collection executed based on the third activity state is exited;
[0030] When the fourth activity state corresponding to the empty block too low garbage collection or the fifth activity state corresponding to the patrol garbage collection is set, and the memory state is a write state, the empty block too low garbage collection is performed normally based on the fourth activity state or the patrol garbage collection is performed normally based on the fifth activity state.
[0031] In one embodiment, the normal execution of the high priority balanced garbage collection includes:
[0032] Determine a target data block from a plurality of data blocks in the memory based on a first target erasing condition, and determine a target free block from a plurality of free blocks in the memory based on a second target erasing condition;
[0033] The data in the target data block is moved to the target free block.
[0034] In a second aspect, the present invention provides a memory wear leveling device, the device comprising:
[0035] A first definition module is used to define a first queue state corresponding to a high priority balanced garbage collection and a second queue state corresponding to a low priority balanced garbage collection;
[0036] A first setting module, used for setting the first queue state or the second queue state based on the number of erasable and writable times of the flash memory of the memory;
[0037] A second definition module, used to define a first activity state corresponding to the high priority balanced garbage collection and a second activity state corresponding to the low priority balanced garbage collection;
[0038] The second setting module is used to set the first active state or the second active state based on the memory state according to the setting status of the first queue state or the setting status of the second queue state, and clear the corresponding first queue state and second queue state.
[0039] 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 wear leveling method as described in the first aspect are implemented.
[0040] In a third 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 wear leveling method as described in the first aspect.
[0041] The memory wear leveling method, device, equipment and medium disclosed in the present invention define a first queue state corresponding to a high-priority balanced garbage collection and a second queue state corresponding to a low-priority balanced garbage collection; set the first queue state or the second queue state based on the number of times the flash memory of the memory can be written and erased; define a first activity state corresponding to the high-priority balanced garbage collection and a second activity state corresponding to the low-priority balanced garbage collection; set the first activity state or the second activity state based on the memory state according to the setting of the first queue state or the setting of the second queue state, and clear the corresponding first queue state and second queue state. In this way, determining whether to perform high-priority balanced garbage collection or low-priority balanced garbage collection based on the number of times the flash memory of the memory can be written and erased and the memory state can avoid affecting the normal performance of the memory and prevent excessive wear leveling or invalid wear leveling.
[0042] 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
[0043] 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.
[0044] Figure 1 A schematic diagram of a process of a memory wear leveling method proposed by the present invention is shown;
[0045] Figure 2 A structural schematic diagram of the memory wear leveling device method proposed by the present invention is shown. DETAILED DESCRIPTION
[0046] 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.
[0047] It should be noted that when an element is referred to as being "fixed to" another element, it may be directly on the other element or there may be a central element. When an element is considered to be "connected to" another element, it may be directly connected to the other element or there may be a central element at the same time. In contrast, when an element is referred to as being "directly on" another element, there is no intermediate element. The terms "vertical", "horizontal", "left", "right" and similar expressions used herein are for illustrative purposes only.
[0048] In the present invention, unless otherwise clearly specified and limited, the terms "installed", "connected", "connected", "fixed" and the like 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, it can be the internal connection of two elements or the interaction relationship between two elements. For ordinary technicians in this field, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.
[0049] In addition, 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.
[0050] 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.
[0051] Example 1
[0052] The disclosed embodiment provides a memory wear leveling method for performing corresponding garbage collection according to the specific state of the memory and the urgency of garbage collection to avoid affecting the normal operation and performance of the memory.
[0053] See also Figure 1 The memory wear leveling method includes steps S101 to S104, and each step is described in detail below.
[0054] Step S101 , defining a first queue state corresponding to a high priority balanced garbage collection and a second queue state corresponding to a low priority balanced garbage collection.
[0055] In this embodiment, the balanced garbage collection (WERAR Leveling GC, WLGC) is further subdivided into high priority WL GC and low priority WL GC according to the urgency of execution; and the queue status signals (QueueStatus) for the high priority WL GC and the low priority WL GC are defined respectively. The high priority WL GC corresponds to the first queue status BW_Q_STATUS_FIND_SRC_WL, and the value can be defined as 0x0002; the low priority WL GC corresponds to the second queue status BW_Q_STATUS_FIND_LOW_LVL_WL, and the value can be defined as 0x0004. This can be used to distinguish the different queue status signals corresponding to the high priority WL GC and the low priority WL GC.
[0056] Step S102: setting the first queue state or the second queue state based on the number of times the flash memory of the memory can be erased and written.
[0057] In this embodiment, when the host writes data to the memory, the first queue state corresponding to the high priority WL GC is set, or the second queue state corresponding to the low priority WL GC is set according to the Program / Erase Cycle (PE) of the flash memory of the memory. In this way, the queue state to be set is determined according to the PE value of the memory, and wear leveling can be achieved according to the heat of the data, so as to achieve no speed reduction when the performance test of the memory is performed.
[0058] In a specific embodiment, the setting of the first queue state or the second queue state based on the maximum flash erasable number of times of the memory includes: obtaining the maximum flash erasable number of times and the minimum flash erasable number of times of the memory as a whole disk, as well as the maximum flash erasable number of times of the free blocks and the minimum flash erasable number of times of the data blocks in the memory; determining the difference between the maximum flash erasable number of times and the minimum flash erasable number of times of the whole disk to obtain a first erasable difference; determining the difference between the maximum flash erasable number of times and the minimum flash erasable number of times of the free blocks to obtain a second erasable difference; determining the difference between a preset threshold and a preset value to obtain a third tolerable difference; and setting the first queue state or the second queue state based on a comparison result of the first erasable difference, the second erasable difference, the third tolerable difference, and the preset threshold.
[0059] In this embodiment, firstly, the maximum PE and the minimum PE of the entire disk in the memory are obtained, and the maximum PE of the free block is obtained according to each free block of the memory, and the minimum PE of the data block is obtained according to each data block of the memory.
[0060] Furthermore, a first erasable difference between the maximum PE of the entire disk and the minimum PE of the entire disk, and a second erasable difference between the maximum PE of the free block and the minimum PE of the data block are obtained, and a third tolerable difference between a preset threshold and a preset value is calculated.
[0061] Further, the first queue state corresponding to the high priority WL GC or the second queue state corresponding to the low priority WL GC is determined according to the comparison result between the first erasable difference value, the second erasable difference value, the third tolerable difference value and the preset threshold value. In this way, the comparison between the specific PE difference value and the threshold value can ensure wear leveling and prevent excessive or ineffective execution of WL GC.
[0062] In a specific embodiment, the setting of the first queue state or the second queue state based on the comparison result of the first erasable difference, the second erasable difference, the third tolerable difference and the preset threshold value includes: judging whether the first erasable difference and the second erasable difference are both greater than the third tolerable difference; if the first erasable difference and the second erasable difference are both greater than the third tolerable difference, setting the second queue state; if the first erasable difference and the second erasable difference are both equal to the third tolerable difference, setting the first queue state; if the first erasable difference and the second erasable difference are both less than the third tolerable difference, judging whether the first erasable difference and the second erasable difference are both greater than the preset threshold; if the first erasable difference and the second erasable difference are both greater than the preset threshold, setting the first queue state.
[0063] In this embodiment, it is determined whether the first erasable difference and the second erasable difference are both greater than the third tolerable threshold value. If the first erasable difference and the second erasable difference are both greater than the third tolerable threshold value, the second queue state corresponding to the low priority WL GC is set. In this way, when any data block has a relatively high PE block, it can be prevented that when executing the low priority WLGC to select the target block, a data block with a small PE is selected, thereby preventing excessive or invalid WL GC.
[0064] If the first erasable difference value and the second erasable difference value are both equal to the third tolerable difference value, then the first queue state corresponding to the high priority WL GC is set.
[0065] If the first erasable difference and the second erasable difference are both smaller than the third tolerable difference, it is further determined whether the first erasable difference and the second erasable difference are both greater than a preset threshold.
[0066] If the first erasable difference and the second erasable difference are both greater than the preset threshold, the first queue state corresponding to the high priority WL GC is set. In this way, when the first erasable difference and the second erasable difference are both greater than the preset threshold, the high priority WL GC is executed by setting the second queue state to ensure wear leveling.
[0067] It should be noted that, by setting the value of the first queue state defined in step S101, the first queue state corresponding to the high priority WL GC can be set. That is, by setting the value to 0x0002, the first queue state can be set. Correspondingly, by setting the value of the second queue state defined in step S101, the second queue state corresponding to the low priority WL GC can be set. That is, by setting the value to 0x0004, the second queue state can be set.
[0068] It should be noted that the preset threshold and the preset value can be set according to actual needs. Preferably, the preset value can be 3. If the preset value is too large, low-priority WL GC will be started early, which may easily lead to write amplification. If the preset value is too small, the effect will not be achieved, and it will be meaningless to divide high-priority WL GC and low-priority WL GC.
[0069] Step S103: defining a first activity state corresponding to the high-priority balanced garbage collection and a second activity state corresponding to the low-priority balanced garbage collection.
[0070] In this embodiment, after setting the message queue state corresponding to the high priority WL GC or the low priority WL GC, it is also necessary to set the activity state corresponding to the message queue state so that the corresponding WL GC can be executed normally. Therefore, it is also necessary to define the first activity state corresponding to the high priority WL GC and the second activity state corresponding to the low priority WL GC. For example, the first activity state BW_STATUS_GC_ACTIVE_STATIC_WL has a value of 3, and the second activity state BW_STATUS_ACTIVE_LOWLVL_WL has a value of 5.
[0071] Step S104, based on the memory state and according to the setting status of the first queue state or the setting status of the second queue state, set the first active state or the second active state, and clear the corresponding first queue state and second queue state.
[0072] In this embodiment, after defining the first activity state corresponding to the high-priority balanced garbage collection and the second activity state corresponding to the low-priority balanced garbage collection, the activity state of the WL GC can be set according to the setting of the message queue state in step S102 and the memory state, that is, the source to which the GC belongs. After setting the corresponding activity state, the corresponding message queue state also needs to be cleared to prevent repeated execution of the WL GC.
[0073] In a specific embodiment, the memory-based state sets the first active state or the second active state and clears the corresponding first queue state and second queue state according to the setting status of the first queue state or the setting status of the second queue state, including: if the first queue state is set and the memory state is a write state, then the first active state is set and the first queue state and the second queue state are cleared; if the second queue state is set and the memory state is an idle state, then the second active state is set and the second queue state is cleared.
[0074] In this embodiment, when the first queue state is set and the first queue state belongs to write garbage collection (WriteGC), that is, the memory is in the data writing state, the first active state is set, and the corresponding first queue state is cleared, and the second queue state also needs to be cleared.
[0075] It should be noted that in the garbage collection (GC) queue state clearing, the high priority WL GC includes the low priority WL GC. Because the GC strategy is to decide to clean up the memory block based on the PE usage of the memory. Generally speaking, after the high priority WL GC cleans up the memory block, the PE difference may be smaller than the low priority WL GC, so there is no need to execute the low priority WL GC. Therefore, it is necessary to clear the second activity state corresponding to the low priority WL GC, so as to prevent excessive WL and increase write amplification.
[0076] When the second queue state is set and the second queue state belongs to idle garbage collection (Idle GC), that is, the memory is in an idle state, the second activity state is set and the second queue state is cleared. In this way, the low priority WL GC can be smoothly executed normally based on the second activity state.
[0077] In a specific embodiment, when the first activity state is set and the memory state is a write state, the high priority balanced garbage collection is performed normally based on the first activity state; when the second activity state is set and the memory state is a write state, the low priority balanced garbage collection performed based on the second activity state is exited.
[0078] In this embodiment, when the first activity state corresponding to the high priority WL GC is set, and the first activity state belongs to write garbage collection (Write GC), that is, when the memory is in the data writing state, the high priority WL GC is normally executed based on the first activity state; and when the second activity state corresponding to the low priority WL GC is set, and the second activity state belongs to write garbage collection (Write GC), that is, when the memory is in the data writing state, the low priority WL GC executed based on the second activity state is exited, which will not affect the normal operation of the memory. And at this time, it is not necessary to clear the second activity state, so that when the memory enters the idle state next time, the low priority WL GC can be executed based on the second activity state.
[0079] In a specific embodiment, when the third activity state corresponding to the empty block sufficient garbage collection is set and the memory state is a write state, the empty block sufficient garbage collection executed based on the third activity state is exited; when the fourth activity state corresponding to the empty block too low garbage collection or the fifth activity state corresponding to the patrol garbage collection is set and the memory state is a write state, the empty block too low garbage collection is executed normally based on the fourth activity state or the patrol garbage collection is executed normally based on the fifth activity state.
[0080] In this embodiment, free enough garbage collection (FREE ENOUGH GC), free too low garbage collection (FREE TOO LOW GC) and patrol garbage collection (RECLAIM GC) may also be performed on the memory.
[0081] Specifically, the message queue states corresponding to free block sufficient garbage collection (FREE ENOUGH GC), free block too low garbage collection (FREE TOO LOW GC) and patrol garbage collection (RECLAIM GC) can be defined first, and then the corresponding message queue states are set based on the specific working conditions of the memory, and then the activity states corresponding to free block sufficient garbage collection (FREE ENOUGH GC), free block too low garbage collection (FREE TOO LOW GC) and patrol garbage collection (RECLAIM GC) are set according to the setting conditions of the message queue states. After the corresponding activity states are set, it is also necessary to determine whether the corresponding GC is executed normally according to the working conditions of the memory.
[0082] Further, when the third activity state corresponding to FREE ENOUGH GC is set, and the third activity state belongs to Write GC, that is, the memory is in the data writing state at this time, then FREE ENOUGH GC executed based on the third activity state is exited; when the fourth activity state corresponding to FREE TOO LOW GC or the fifth activity state corresponding to RECLAIM GC is set, and the third activity state and the fourth activity state belong to Write GC, that is, the memory is in the data writing state at this time, then FREE TOO LOW GC is executed normally based on the fourth activity state or RECLAIM GC is executed normally based on the fifth activity state.
[0083] It should be noted that the priorities of FREE TOO LOW GC, RECLAIM GC, high priority WL GC, low priority WL GC, and FREE ENOUGH GC decrease in turn, that is, the urgency decreases in turn, and the sources of GC include Write GC, IdleGC, and Read GC. Among them, FREE TOO LOW GC and RECLAIM GC are more urgent, and the corresponding three GC sources need to be executed; the host will not cause PE to increase during the process of reading data from the memory, so the high priority WL GC is not executed during the data reading process, but can be executed during the data writing and idle state; the urgency of low priority WL GC and FREE ENOUGH GC is lower, and since the read and write performance cannot be affected when executing GC, they are only selected to be executed when the memory is idle.
[0084] In a specific embodiment, the normal execution of the high priority balanced garbage collection includes: determining a target data block from multiple data blocks in the memory based on a first target erase condition, and determining a target free block from multiple free blocks in the memory based on a second target erase condition; and moving the data in the target data block to the target free block.
[0085] In this embodiment, the specific process of executing high-priority WL GC is as follows: determine the data block with the smallest PE from multiple data blocks in the memory as the target data block, and determine the free block with a higher PE from multiple free blocks in the memory as the target free block; move the data in the target data block to the target free block. Correspondingly, the specific process of executing low-priority WL GC is also as described above, which is the same as the specific process of executing high-priority WL GC. Among them, the free block with a higher PE is selected as the target free block in order to reduce the PE difference and prevent the static wear from being aggravated.
[0086] The memory wear leveling method proposed in this embodiment defines a first queue state corresponding to a high-priority balanced garbage collection and a second queue state corresponding to a low-priority balanced garbage collection; sets the first queue state or the second queue state based on the number of times the flash memory of the memory can be written and erased; defines a first active state corresponding to the high-priority balanced garbage collection and a second active state corresponding to the low-priority balanced garbage collection; sets the first active state or the second active state based on the memory state according to the setting of the first queue state or the setting of the second queue state, and clears the corresponding first queue state and second queue state. In this way, determining whether to perform high-priority balanced garbage collection or low-priority balanced garbage collection based on the number of times the flash memory of the memory can be written and erased and the memory state can avoid affecting the normal performance of the memory and prevent excessive wear leveling or invalid wear leveling.
[0087] Example 2
[0088] In addition, the present disclosure provides a memory wear leveling device 200, see Figure 2 , the device comprises:
[0089] A first definition module 201 is used to define a first queue state corresponding to a high priority balanced garbage collection and a second queue state corresponding to a low priority balanced garbage collection;
[0090] A first setting module 202, configured to set the first queue state or the second queue state based on the number of times the flash memory of the memory can be erased and written;
[0091] A second definition module 203, used to define a first activity state corresponding to the high priority balanced garbage collection and a second activity state corresponding to the low priority balanced garbage collection;
[0092] The second setting module 204 is used to set the first active state or the second active state based on the memory state according to the setting status of the first queue state or the setting status of the second queue state, and clear the corresponding first queue state and second queue state.
[0093] In one embodiment, the first setting module 202 is also used to obtain the maximum flash erasable number of times and the minimum flash erasable number of times of the memory, as well as the maximum flash erasable number of times of the free blocks and the minimum flash erasable number of times of the data blocks in the memory; determine the difference between the maximum flash erasable number of times and the minimum flash erasable number of times of the full disk to obtain a first erasable difference; determine the difference between the maximum flash erasable number of times of the free blocks and the minimum flash erasable number of times of the data blocks to obtain a second erasable difference; determine the difference between a preset threshold and a preset value to obtain a third tolerable difference; and set the first queue state or the second queue state based on a comparison result of the first erasable difference, the second erasable difference, the third tolerable difference and the preset threshold.
[0094] In one embodiment, the first setting module 202 is also used to determine whether the first erasable difference and the second erasable difference are both greater than the third tolerable difference; if the first erasable difference and the second erasable difference are both greater than the third tolerable difference, the second queue state is set; if the first erasable difference and the second erasable difference are both equal to the third tolerable difference, the first queue state is set; if the first erasable difference and the second erasable difference are both less than the third tolerable difference, it is determined whether the first erasable difference and the second erasable difference are both greater than the preset threshold; if the first erasable difference and the second erasable difference are both greater than the preset threshold, the first queue state is set.
[0095] In one embodiment, the second setting module 204 is further used to set the first active state and clear the first queue state and the second queue state if the first queue state is set and the memory state is a write state; if the second queue state is set and the memory state is an idle state, set the second active state and clear the second queue state.
[0096] In one embodiment, the second setting module 204 is also used to, when the first activity state is set and the memory state is a write state, normally execute the high priority balanced garbage collection based on the first activity state; when the second activity state is set and the memory state is a write state, exit the low priority balanced garbage collection executed based on the second activity state.
[0097] In one embodiment, the second setting module 204 is further used for, when the third activity state corresponding to the empty block sufficient garbage collection is set and the memory state is a write state, exiting the empty block sufficient garbage collection executed based on the third activity state; when the fourth activity state corresponding to the empty block too low garbage collection or the fifth activity state corresponding to the patrol garbage collection is set and the memory state is a write state, normally executing the empty block too low garbage collection based on the fourth activity state or normally executing the patrol garbage collection based on the fifth activity state.
[0098] In one embodiment, the second setting module 204 is also used to determine a target data block from multiple data blocks in the memory based on a first target erase condition, and to determine a target free block from multiple free blocks in the memory based on a second target erase condition; and to move data in the target data block to the target free block.
[0099] The device provided in the embodiment of the present disclosure can execute the steps of the memory wear leveling method provided in Example 1, which will not be described again to avoid repetition.
[0100] The memory wear leveling device proposed in this embodiment defines a first queue state corresponding to a high-priority balanced garbage collection and a second queue state corresponding to a low-priority balanced garbage collection; sets the first queue state or the second queue state based on the number of times the flash memory of the memory can be written and erased; defines a first active state corresponding to the high-priority balanced garbage collection and a second active state corresponding to the low-priority balanced garbage collection; sets the first active state or the second active state based on the memory state according to the setting of the first queue state or the setting of the second queue state, and clears the corresponding first queue state and second queue state. In this way, determining whether to perform high-priority balanced garbage collection or low-priority balanced garbage collection based on the number of times the flash memory of the memory can be written and erased and the memory state can avoid affecting the normal performance of the memory and prevent excessive wear leveling or invalid wear leveling.
[0101] Example 3
[0102] 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 wear leveling method described in Embodiment 1 is implemented.
[0103] The device provided in the embodiment of the present disclosure can execute the steps of the memory wear leveling method provided in Example 1, which will not be described again to avoid repetition.
[0104] Example 4
[0105] 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 wear leveling method described in Embodiment 1 is implemented.
[0106] 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.
[0107] The computer-readable storage medium provided in this embodiment can implement the memory wear leveling method provided in Embodiment 1, and will not be described again here to avoid repetition.
[0108] 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.
[0109] 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.
[0110] 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 wear leveling method, characterized in that: The method comprises: Define the first queue state corresponding to high priority balanced garbage collection and the second queue state corresponding to low priority balanced garbage collection; Setting the first queue state or the second queue state based on the number of times the flash memory of the memory can be erased and written; defining a first activity state corresponding to the high priority balanced garbage collection and a second activity state corresponding to the low priority balanced garbage collection; Based on the memory state and according to the setting status of the first queue state or the setting status of the second queue state, the first active state or the second active state is set, and the corresponding first queue state and second queue state are cleared.
2. The memory wear leveling method according to claim 1, characterized in that: The step of setting the first queue state or the second queue state based on the maximum number of times the flash memory can be erased and written to the memory includes: Obtaining the maximum flash erasable times and the minimum flash erasable times of the entire disk of the memory, as well as the maximum flash erasable times of the free blocks and the minimum flash erasable times of the data blocks in the memory; Determine the difference between the maximum erasable number of times of the flash memory of the entire disk and the minimum erasable number of times of the flash memory of the entire disk to obtain a first erasable difference; Determine the difference between the maximum erasable number of times of the free block flash memory and the minimum erasable number of times of the data block flash memory to obtain a second erasable difference; Determine a difference between a preset threshold and a preset value to obtain a third tolerable difference; The first queue state or the second queue state is set based on a comparison result of the first erasable difference value, the second erasable difference value, the third tolerable difference value, and the preset threshold.
3. The memory wear leveling method according to claim 2, characterized in that: The step of setting the first queue state or the second queue state based on a comparison result of the first erasable difference value, the second erasable difference value, the third tolerable difference value, and the preset threshold value comprises: Determining whether the first erasable difference and the second erasable difference are both greater than the third tolerable difference; If the first erasable difference value and the second erasable difference value are both greater than the third tolerable difference value, setting the second queue state; If the first erasable difference value and the second erasable difference value are both equal to the third tolerable difference value, setting the first queue state; If the first erasable difference value and the second erasable difference value are both smaller than the third tolerable difference value, determining whether the first erasable difference value and the second erasable difference value are both greater than the preset threshold value; If the first erasable difference value and the second erasable difference value are both greater than the preset threshold value, the first queue state is set.
4. The memory wear leveling method according to claim 1, characterized in that: The setting of the first active state or the second active state based on the memory state according to the setting of the first queue state or the setting of the second queue state, and clearing the corresponding first queue state and second queue state includes: If the first queue state is set and the memory state is a write state, the first activity state is set, and the first queue state and the second queue state are cleared; If the second queue state is set and the memory state is an idle state, the second activity state is set and the second queue state is cleared.
5. The memory wear leveling method according to claim 1, characterized in that: The method further comprises: When the first activity state is set and the memory state is a write state, the high priority balanced garbage collection is normally performed based on the first activity state; When the second activity state is set and the memory state is a write state, the low priority balanced garbage collection performed based on the second activity state is exited.
6. The memory wear leveling method according to claim 1, characterized in that: The method further comprises: When the third activity state corresponding to the empty block sufficient garbage collection is set, and the memory state is a write state, then the empty block sufficient garbage collection executed based on the third activity state is exited; When the fourth activity state corresponding to the empty block too low garbage collection or the fifth activity state corresponding to the patrol garbage collection is set, and the memory state is a write state, the empty block too low garbage collection is performed normally based on the fourth activity state or the patrol garbage collection is performed normally based on the fifth activity state.
7. The memory wear leveling method according to claim 1, characterized in that: The normally executing the high priority balanced garbage collection comprises: Determine a target data block from a plurality of data blocks in the memory based on a first target erasing condition, and determine a target free block from a plurality of free blocks in the memory based on a second target erasing condition; The data in the target data block is moved to the target free block.
8. A memory wear leveling device, characterized in that: The device comprises: A first definition module is used to define a first queue state corresponding to a high priority balanced garbage collection and a second queue state corresponding to a low priority balanced garbage collection; A first setting module, used for setting the first queue state or the second queue state based on the number of erasable and writable times of the flash memory of the memory; A second definition module, used to define a first activity state corresponding to the high priority balanced garbage collection and a second activity state corresponding to the low priority balanced garbage collection; The second setting module is used to set the first active state or the second active state based on the memory state according to the setting status of the first queue state or the setting status of the second queue state, and clear the corresponding first queue state and second queue state.
9. A computer device, 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 wear leveling method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium, characterized in that: It stores a computer program, which, when executed by a processor, implements the steps of the memory wear leveling method according to any one of claims 1 to 7.
