Wear leveling method and apparatus, solid state drive, and computer readable storage medium

By selecting lightly worn physical blocks from the solid-state drive (SSD) as source blocks and using heavily worn physical blocks as target blocks for data migration, the problem of uneven wear is solved, extending the lifespan of the SSD and improving performance.

CN122240032APending Publication Date: 2026-06-19SICHUAN YUNHAI XINKE MICROELECTRONICS TECH CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
SICHUAN YUNHAI XINKE MICROELECTRONICS TECH CO LTD
Filing Date
2026-04-15
Publication Date
2026-06-19

AI Technical Summary

Technical Problem

Uneven wear of physical blocks in solid-state drives (SSDs) causes some blocks to age prematurely, shortening their lifespan. Existing technologies struggle to effectively balance wear.

Method used

By selecting physical blocks with less wear and less effective data as source physical blocks and using severely worn physical blocks as target physical blocks for data migration, wear leveling can be achieved.

Benefits of technology

It extends the overall lifespan of solid-state drives, reduces performance degradation, improves wear leveling efficiency, and reduces write amplification.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122240032A_ABST
    Figure CN122240032A_ABST
Patent Text Reader

Abstract

This invention discloses a wear leveling method, apparatus, solid-state drive (SSD), and computer-readable storage medium, relating to the field of SSD technology. The method filters source and target physical blocks based on erase counts, write time, and effective data volume. Physical blocks containing cold data (with minimal wear and low effective data volume) are identified as source physical blocks, while heavily worn idle blocks or heavily worn hot data (with low effective data volume) are identified as target physical blocks. Data from the source physical blocks is migrated to the target physical blocks. This ensures that heavily worn physical blocks receive sufficient rest, while lightly worn physical blocks are fully utilized, thereby balancing the erase counts of physical blocks in the SSD. This prevents individual physical blocks from prematurely failing due to frequent erasures, helps extend the overall lifespan of the SSD, reduces performance degradation caused by localized wear, effectively reduces write amplification, and improves wear leveling efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of solid-state drive technology, and more specifically, to a wear leveling method, apparatus, solid-state drive, and computer-readable storage medium. Background Technology

[0002] Because solid-state drives (SSDs) do not support overwrite operations on physical blocks, they can only be erased before being written to. Frequent erasing and writing will accelerate the aging of physical blocks, eventually causing them to become bad blocks. This will reduce the number of usable physical blocks in the SSD, thus shortening its lifespan. In cases of uneven wear distribution on an SSD, timely implementation of wear leveling measures becomes particularly urgent. Summary of the Invention

[0003] In view of this, the purpose of the present invention is to provide a wear leveling method, apparatus, solid-state drive, and computer-readable storage medium that can reduce write amplification and improve the efficiency of wear leveling.

[0004] To achieve the above objectives, the technical solutions adopted in the embodiments of the present invention are as follows: In a first aspect, the present invention provides a wear leveling method applied to a solid-state drive (SSD), the SSD comprising multiple physical blocks; the method includes: When the solid-state drive meets the wear leveling startup conditions, the physical block with the highest cold data level and the smallest amount of effective data in the young blocks is determined as the source physical block; the young block is a physical block with fewer erase cycles than the average erase cycle and storing effective data; the longer the write time of the effective data in the physical block, the higher the cold data level of the physical block. If there is a free block with more erase counts than the average erase count, the free block with the highest number of erase counts is identified as the target physical block; the free block is a physical block that does not store valid data. If there are no free blocks with an erase count greater than the average erase count, the physical block with the lowest cold data level and the smallest amount of valid data among the old blocks is determined as the target physical block; the old block is a physical block with an erase count not less than the average erase count and storing valid data; Data from the source physical block is migrated to the target physical block to achieve wear leveling.

[0005] In an optional implementation, migrating the data from the source physical block to the target physical block includes: The free block with the fewest erase counts is identified as a candidate physical block; The data of the target physical block is written into the candidate physical block, and the data of the source physical block is written into the target physical block.

[0006] In an optional implementation, the method further includes: When a user writes data, a free block is allocated as the physical block to be written. Once the physical block to be written is full, set the cold data level and timestamp of the physical block to be written. If the number of erases on the physical block to be written does not exceed the average number of erases, the physical block to be written is identified as the young block; If the number of erases on the physical block to be written exceeds the average number of erases, the physical block to be written is identified as the old block; Update the erase count of the physical block to be written.

[0007] In an optional implementation, the solid-state drive maintains multiple young block chains and multiple old block chains, with different young block chains used to record young blocks of different cold data levels, and different old block chains used to record old blocks of different cold data levels; the method further includes: When the amount of data written in this cycle reaches the data volume threshold, the young blocks in the young block chain are updated according to the timestamp and the determination time; the determination time is the time when the amount of data written in the previous cycle reaches the data volume threshold. Update the old blocks in the old block chain according to the timestamp, the determination time, and the number of erasures; The determination time is updated to the time when the amount of data written in this cycle reaches the data volume threshold.

[0008] In an optional implementation, the cold data levels include normal temperature, slightly cold, cool, and ultra-cold; the multiple young blockchains include a young normal temperature chain, a young slightly cold chain, a young cool chain, and a young ultra-cold chain; the young normal temperature chain is used to record young blocks with a cold data level of normal temperature, the young slightly cold chain is used to record young blocks with a cold data level of slightly cold, the young cool chain is used to record young blocks with a cold data level of cool, and the young ultra-cold chain is used to record young blocks with an ultra-cold cold data level; updating the young blocks in the young blockchains according to the timestamp and the determination time includes: Migrate the physical blocks in the young, cold chain to the young, ultra-cold chain; The physical blocks in the young, slightly cold chain are migrated to the young, more cold chain. Physical blocks in the young ambient temperature chain with timestamps less than or equal to the determination time are migrated to the young slightly cold chain.

[0009] In an optional implementation, the plurality of aged blockchains include aged ambient temperature blockchains, aged slightly cold blockchains, aged partially cold blockchains, and aged ultra-cold blockchains; the aged ambient temperature blockchains are used to record aged blocks with a cold data level of ambient temperature, the aged slightly cold blockchains are used to record aged blocks with a cold data level of slightly cold, the aged partially cold blockchains are used to record aged blocks with a cold data level of partially cold, and the aged ultra-cold blockchains are used to record aged blocks with a cold data level of ultra-cold; updating the aged blocks in the aged blockchains according to the timestamp, the determination time, and the number of erasures includes: The physical blocks in the older ultra-cold chain that have been erased no more than the average number of erasures are migrated to the younger ultra-cold chain; Physical blocks in the older, colder chain with fewer than the average number of erases are migrated to the younger, ultra-colder chain, and physical blocks in the older, colder chain with more than the average number of erases are migrated to the older, ultra-colder chain. Physical blocks in the older micro-cold chain whose number of erases does not exceed the average number of erases are migrated to the younger, slightly colder chain, and physical blocks in the older micro-cold chain whose number of erases exceeds the average number of erases are migrated to the older, slightly colder chain. Physical blocks in the aged ambient temperature chain whose number of erases does not exceed the average number of erases and whose timestamps are less than or equal to the determination time are migrated to the aged slightly cold chain, and physical blocks in the aged ambient temperature chain whose number of erases exceeds the average number of erases and whose timestamps are less than or equal to the determination time are migrated to the aged micro cold chain.

[0010] In an optional implementation, the method further includes: Periodically migrate older blocks in the older block chain that have been erased less than the average number of erasures to the younger block chain containing younger blocks of the same cold data level.

[0011] Secondly, the present invention provides a wear leveling device applied to a solid-state drive (SSD), the SSD comprising a plurality of physical blocks; the device comprising: The processing module is used to determine the physical block with the highest cold data level and the smallest amount of effective data in the young blocks as the source physical block when the solid-state drive meets the wear leveling startup conditions; the young block is a physical block with fewer erase cycles than the average erase cycle and storing effective data; the cold data level is related to the effective data write time, and the longer the write time, the higher the level. The processing module is further configured to, if there are idle blocks with a wipe count greater than the average wipe count, identify the idle block with the highest wipe count as the target physical block; the idle block is a physical block that does not store valid data; if there are no idle blocks with a wipe count greater than the average wipe count, identify the physical block with the lowest cold data level and the smallest amount of valid data among the old blocks as the target physical block; the old block is a physical block with a wipe count not less than the average wipe count and storing valid data. The migration module is used to migrate the data of the source physical block to the target physical block in order to achieve wear leveling.

[0012] Thirdly, the present invention provides a solid-state drive, including a processor and a memory, the memory including a plurality of physical blocks, the memory storing a computer program executable by the processor, the processor executing the computer program to implement the wear leveling method described in any of the foregoing embodiments.

[0013] Fourthly, the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the wear leveling method as described in any of the foregoing embodiments.

[0014] Compared to existing technologies, the wear leveling method, apparatus, solid-state drive (SSD), and computer-readable storage medium provided in this invention filter source physical blocks and target physical blocks based on the number of erases, write data time, and effective data volume. The physical block containing cold data with less wear and less effective data is identified as the source physical block, while the physical block containing idle data with severe wear or hot data with severe wear and less effective data is identified as the target physical block. Data from the source physical blocks is then migrated to the target physical blocks. This ensures that severely worn physical blocks receive sufficient rest, while lightly worn physical blocks are fully utilized. This balances the number of erases on the physical blocks in the SSD, preventing premature failure of individual physical blocks due to frequent erasures. This helps extend the overall lifespan of the SSD, reduces performance degradation caused by localized wear, effectively reduces write amplification, and improves the efficiency of wear leveling.

[0015] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings. Attached Figure Description

[0016] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of the present invention and should not be regarded as a limitation on the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.

[0017] Figure 1 A schematic flowchart of a wear leveling method provided in an embodiment of the present invention is shown.

[0018] Figure 2 This diagram illustrates another flow chart of the wear leveling method provided in an embodiment of the present invention.

[0019] Figure 3This diagram illustrates another flow chart of the wear leveling method provided in an embodiment of the present invention.

[0020] Figure 4 This diagram illustrates another flow chart of the wear leveling method provided in an embodiment of the present invention.

[0021] Figure 5 A block diagram of a wear equalization device provided in an embodiment of the present invention is shown.

[0022] Figure 6 A block diagram of a solid-state drive provided in an embodiment of the present invention is shown.

[0023] Icons: 400 - Wear leveling device; 401 - Processing module; 402 - Migration module; 500 - Solid state drive; 510 - Processor; 520 - Memory. Detailed Implementation

[0024] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. The components of the embodiments of the present invention described and shown in the accompanying drawings can generally be arranged and designed in various different configurations.

[0025] Therefore, the following detailed description of the embodiments of the invention provided in the accompanying drawings is not intended to limit the scope of the claimed invention, but merely to illustrate selected embodiments of the invention. All other embodiments obtained by those skilled in the art based on the embodiments of the invention without inventive effort are within the scope of protection of the invention.

[0026] It should be noted that relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0027] Because data written to an SSD has different update frequency characteristics, frequently updated data is called hot data, and data that has not been updated for a long time is called cold data. Physical blocks storing cold data are erased less frequently over a long period of time, so their write cycles are relatively low, and they can be called young physical blocks. Conversely, physical blocks storing hot data are erased and written more frequently, so their write cycles are high, and they are called old physical blocks.

[0028] The inventors discovered that older blocks, due to frequent use, may become bad blocks, which reduces the number of usable physical blocks and shortens the lifespan of the SSD. Therefore, in cases of uneven wear, wear leveling is needed to allow younger blocks to handle hot data writes, thus reducing the stress on older blocks and giving them a proper rest.

[0029] When performing wear leveling, it is necessary to select suitable physical blocks to ensure that young blocks can be put into use, while older blocks can rest as needed. Therefore, accurately selecting the source physical block (i.e., the block to be processed) and the target physical block (i.e., the destination of data migration) as the objects of wear leveling is particularly critical.

[0030] Based on this, the wear leveling method and apparatus provided in this embodiment of the invention screen source physical blocks and target physical blocks according to the number of erases, write data time, and effective data volume. The physical block containing cold data with less wear and less effective data volume is identified as the source physical block, and the physical block containing idle data with severe wear or hot data with severe wear and less effective data volume is identified as the target physical block. The data of the source physical block is then migrated to the target physical block. This ensures that the severely worn physical blocks are given sufficient rest, while the less worn physical blocks are fully utilized. This balances the number of erases on the physical blocks in the solid-state drive, prevents individual physical blocks from failing prematurely due to frequent erases, helps extend the overall lifespan of the solid-state drive, reduces performance degradation caused by local wear, effectively reduces write amplification, and improves the efficiency of wear leveling.

[0031] Please refer to Figure 1 , Figure 1 This diagram illustrates a flow chart of a wear leveling method provided by an embodiment of the present invention. The method is applied to a solid-state drive (SSD), which includes multiple physical blocks. The method includes the following steps: Step S200: When the solid-state drive meets the boot conditions for wear leveling, the physical block with the highest cold data level and the smallest amount of effective data in the young blocks is determined as the source physical block; the young block is a physical block with fewer erase cycles than the average erase cycle and storing effective data; the longer the write time of the effective data in the physical block, the higher the cold data level of the physical block.

[0032] In this embodiment of the invention, it is determined whether the number of erases of physical blocks in the solid-state drive meets the start conditions for wear leveling. For example, when the variance of the number of erases of all physical blocks in the solid-state drive is greater than the high threshold for wear leveling start, it indicates that the solid-state drive meets the start conditions for wear leveling.

[0033] When starting the wear leveling process, wear leveling is performed on physical blocks that have not been updated for a long time, have the smallest amount of valid data, and have been erased infrequently. This effectively reduces the amount of data movement during the wear leveling process and reduces write amplification.

[0034] Step S210: If there is a free block with more than the average number of erases, the free block with the largest number of erases is determined as the target physical block; a free block is a physical block that does not store valid data.

[0035] In this embodiment of the invention, when there are free blocks in the solid-state drive with an erase count greater than the average erase count, the free block with the highest erase count is selected as the target physical block. Here, a free block refers to a physical block that does not store valid data. By selecting the free block with the lowest erase count, the amount of data migration during wear leveling can be effectively reduced, thereby reducing write amplification.

[0036] Step S220: If there is no free block with an erase count greater than the average erase count, the physical block with the lowest cold data level and the smallest amount of valid data among the old blocks is determined as the target physical block; an old block is a physical block with an erase count not less than the average erase count and storing valid data.

[0037] Step S230: Migrate the data from the source physical block to the target physical block to achieve wear leveling.

[0038] In this embodiment of the invention, if there are no free blocks in the solid-state drive (SSD) with an erase count greater than the average erase count, the physical block with the lowest cold data priority (i.e., hot data) and the smallest effective data volume among the older blocks will be selected as the target physical block. This ensures that even without suitable free blocks, data migration can still be performed by selecting the older block with the lowest cold data priority and the smallest effective data volume, minimizing the additional burden of data migration and ensuring that young and healthy physical blocks continue to efficiently store hot data, thereby extending the overall lifespan of the SSD. Simultaneously, the optimized distribution of cold data allows older physical blocks to get sufficient rest, further improving the overall performance of the system.

[0039] In summary, the wear leveling method provided by this invention filters source physical blocks and target physical blocks based on the number of erases, write time, and effective data volume. It identifies the physical block containing cold data with less wear and less effective data as the source physical block, and identifies the idle block or the hot data containing severely worn data with less effective data as the target physical block. Data from the source physical block is then migrated to the target physical block. This ensures that severely worn physical blocks receive sufficient rest, while lightly worn physical blocks are fully utilized. This balances the number of erases on physical blocks in the solid-state drive (SSD), preventing premature failure of individual physical blocks due to frequent erasures. This helps extend the overall lifespan of the SSD, reduces performance degradation caused by localized wear, effectively reduces write amplification, and improves the efficiency of wear leveling.

[0040] Alternatively, one possible implementation method for migrating data from the source physical block to the target physical block is provided below. Figure 1 The sub-steps of step S230 may include: The free block with the fewest erase cycles is identified as the candidate physical block; the data of the target physical block is written into the candidate physical block, and the data of the source physical block is written into the target physical block.

[0041] In this embodiment of the invention, a physical block with the fewest erase cycles is selected from the free blocks as a candidate physical block. Data from the target physical block is written into the candidate physical block, and data from the source physical block is written into the target physical block, so as to achieve a more uniform wear distribution during the data migration process.

[0042] As can be seen, by selecting the free block with the fewest erase cycles as the candidate physical block, the embodiments of the present invention can maximize the effect of wear leveling. This not only reduces the impact on young and healthy physical blocks, but also makes full use of less used physical blocks, thereby reducing the overall wear level and improving the lifespan and long-term reliability of the solid-state drive.

[0043] Optionally, regarding how to divide young blocks and old blocks, one possible implementation is provided below. Please refer to... Figure 2 The method also includes the following steps: Step S100: When a user writes data, a free block is allocated as the physical block to be written.

[0044] In this embodiment of the invention, a free block chain and a working block chain are maintained on the solid-state drive (SSD). Initially, all physical blocks in the SSD are free (i.e., free blocks) and stored on the free block chain. When a user writes data, a free block is allocated as the physical block to be written to, the physical block to be written to is moved from the free block chain to the working block chain, and the user data is written to the physical block to be written to, such as... Figure 3 As shown.

[0045] Step S110: After the physical block to be written is full, set the cold data level and timestamp of the physical block to be written.

[0046] In this embodiment of the invention, when the physical block to be written is full of data, the timestamp of the physical block to be written is set to the current system time, and the cold data level of the physical block to be written is set to normal temperature.

[0047] Step S120: If the number of erases of the physical block to be written does not exceed the average number of erases, the physical block to be written is determined as a young block.

[0048] Step S130: If the number of erases of the physical block to be written exceeds the average number of erases, the physical block to be written is identified as an old block.

[0049] Step S140: Update the erase count of the physical block to be written.

[0050] In this embodiment of the invention, if the number of erases on the physical block to be written does not exceed the average number of erases, it is determined as a young block; otherwise, it is determined as an old block. Finally, the number of erases on the physical block to be written is updated by incrementing the number of erases by 1. Figure 3 As shown, if the number of erases on the physical block to be written does not exceed the average number of erases, the physical block to be written is treated as a young block and migrated from the working block chain to the young ambient temperature chain. If the number of erases on the physical block to be written exceeds the average number of erases, the physical block to be written is treated as an old block and migrated from the working block chain to the old ambient temperature chain.

[0051] As can be seen, the embodiments of the present invention can dynamically classify physical blocks into young or old blocks based on the number of erases and the data written to them, thereby managing the wear and tear of the dynamic hard drive more precisely. By updating the erase count in a timely manner, physical blocks with different levels of wear can be better identified and managed, data storage strategies can be optimized, the overall lifespan of the solid-state drive can be extended, and high performance can be maintained.

[0052] Optionally, in practical applications, the solid-state drive maintains multiple young block chains and multiple old block chains. Different young block chains are used to record young blocks with different cold data levels, and different old block chains are used to record old blocks with different cold data levels. Regarding how to use young block chains and old block chains to adjust the cold data level of physical blocks, a possible implementation method is provided below. Please refer to... Figure 4 The method also includes the following steps: Step S300: When the amount of data written in this cycle reaches the data volume threshold, update the young blocks in the young block chain according to the timestamp and the determination time; the determination time is the time when the amount of data written in the previous cycle reaches the data volume threshold.

[0053] In this embodiment of the invention, assuming the total capacity of the solid-state drive is 8TB, when a user first fills the entire drive with data, normally, wear leveling will not occur if no overwrite occurs. However, due to the distinction between hot and cold data, overwrites will inevitably occur. During the process of writing 8TB of data, all young and old blocks may undergo garbage collection and migration to free blocks, and then back to young or old blocks. In this process, the physical blocks that have not been overwritten or garbage collected are the physical blocks containing cold data.

[0054] Assuming the data volume threshold is set to 8TB of total solid-state drive capacity, when the amount of data written to the solid-state drive reaches 8TB in the current cycle, young blocks in multiple young block chains are moved based on timestamps and decision times.

[0055] It is worth mentioning that the decision time is set to an initial value (e.g., 0) when wear leveling is initiated. The decision time and data volume threshold can be set according to the actual application scenario, and this invention does not limit this setting.

[0056] Step S310: Update the old blocks in the old block chain according to the timestamp, judgment time, and number of erasures.

[0057] Step S320: Update the determination time to the time when the amount of data written in this period reaches the data volume threshold.

[0058] In this embodiment of the invention, older blocks in multiple older block chains are moved based on timestamps, decision times, and erase counts. This ensures that physical blocks in the younger block chains always represent the newest and least worn blocks, while physical blocks in the older block chains always represent the oldest and most worn blocks. This helps optimize data migration strategies, reduces wear on older blocks from frequently accessed hot data, and thus extends the lifespan of the solid-state drive and maintains high performance. Finally, the time when the amount of data written within the current cycle reaches the data volume threshold is updated as the decision time.

[0059] Optionally, in practical applications, cold data levels include normal temperature, slightly cold, moderately cold, and ultra-cold; multiple young blockchains include a young normal temperature chain, a young slightly cold chain, a young moderately cold chain, and a young ultra-cold chain; the young normal temperature chain is used to record young blocks with a cold data level of normal temperature, the young slightly cold chain is used to record young blocks with a cold data level of slightly cold, the young moderately cold chain is used to record young blocks with a cold data level of moderately cold, and the young ultra-cold chain is used to record young blocks with a cold data level of ultra-cold. Regarding how to migrate young blocks from multiple young blockchains, a possible implementation method is provided below. Figure 4 The sub-steps of step S300 may include: Migrate physical blocks from the young, slightly cold chain to the young, ultra-cold chain; migrate physical blocks from the young, slightly cold chain to the young, slightly cold chain; migrate physical blocks from the young, room-temperature chain whose timestamps are less than or equal to the decision time to the young, slightly cold chain.

[0060] In this embodiment of the invention, continuing with Figure 3 For example, when the data volume threshold (e.g., total capacity 8TB) is reached in this cycle, firstly, the physical blocks on the young and cold chain are checked. Because the timestamps of the physical blocks on the young and cold chain are all less than the judgment time, they are physical blocks that have not been overwritten after three full disk writes, and the data is colder. The cold data level of the physical blocks on the young and cold chain is upgraded (i.e., upgraded from cold to ultra-cold). The physical blocks in the young and cold chain are taken out of the young and cold chain and attached to the young ultra-cold chain.

[0061] Next, check the physical blocks on the young slightly cold chain. The physical blocks on the young slightly cold chain have all undergone two full writes without being overwritten. Upgrade the cold data level of the physical blocks on the young slightly cold chain (i.e., upgrade from slightly cold to slightly cold). Remove the physical blocks from the young slightly cold chain and attach them to the young slightly cold chain.

[0062] Finally, examine the physical blocks on the young ambient temperature chain. If the timestamp of a physical block is greater than the determination time, it means that the data on that physical block was written in this cycle and is not considered cold data, so it will not be processed this time. If the timestamp of a physical block is less than or equal to the determination time, it means that the physical block was not overwritten during the full write in this cycle, and the data on that physical block is considered cold data. The cold data level of that physical block will be upgraded (i.e., upgraded from ambient temperature to slightly cold), and the physical block will be removed from the young ambient temperature chain and attached to the young slightly cold chain.

[0063] It should be noted that when selecting source physical blocks in wear leveling, the process first checks whether a physical block exists in the young ultra-cold chain. If it does, the physical block with the smallest effective data volume from the young ultra-cold chain is selected as the source physical block. If not, the process checks whether a physical block exists in the young moderately cold chain. If it does, the physical block with the smallest effective data volume from the moderately cold chain is selected as the source physical block. If not, the process checks whether a physical block exists in the young slightly cold chain. If it does, the physical block with the smallest effective data volume from the young slightly cold chain is selected as the source physical block. If not, the physical block with the smallest effective data volume from the young room temperature chain is selected as the source physical block.

[0064] As can be seen, the embodiments of the present invention dynamically select young blocks storing cold data as source physical blocks based on three dimensions: the number of erases, the timestamp of the written data, and the amount of effective data. The young blocks are released to store hot data to ensure wear leveling of the solid-state drive. At the same time, the amount of data migration during the wear leveling process is minimized, write amplification is reduced, and wear leveling efficiency is improved.

[0065] Optionally, in practical applications, multiple aged blockchains include aged normal-temperature chains, aged slightly cold chains, aged partially cold chains, and aged ultra-cold chains. Aged normal-temperature chains are used to record aged blocks with a cold data level of normal temperature; aged slightly cold chains are used to record aged blocks with a cold data level of slightly cold; aged partially cold chains are used to record aged blocks with a cold data level of partially cold; and aged ultra-cold chains are used to record aged blocks with a cold data level of ultra-cold. Regarding how to migrate aged blocks from multiple aged blockchains, a possible implementation method is provided below. Figure 4 The sub-steps of step S310 may include: Migrate physical blocks from old ultra-cold chains whose erase count does not exceed the average erase count to young ultra-cold chains; migrate physical blocks from old semi-cold chains whose erase count does not exceed the average erase count to young ultra-cold chains, and migrate physical blocks from old semi-cold chains whose erase count exceeds the average erase count to old ultra-cold chains; migrate physical blocks from old micro-cold chains whose erase count does not exceed the average erase count to young semi-cold chains, and migrate physical blocks from old micro-cold chains whose erase count exceeds the average erase count to old semi-cold chains; migrate physical blocks from old ambient temperature chains whose erase count does not exceed the average erase count and whose timestamp is less than or equal to the decision time to young slightly cold chains, and migrate physical blocks from old ambient temperature chains whose erase count exceeds the average erase count and whose timestamp is less than or equal to the decision time to old micro-cold chains.

[0066] In this embodiment of the invention, continuing with Figure 3 For example, when the data volume threshold (e.g., total capacity 8TB) is reached within the current cycle, in addition to migrating young blocks from multiple young blockchains, it is also necessary to migrate old blocks from multiple old blockchains. First, check the physical blocks on the old ultra-cold chains. When the erasure of a physical block does not exceed the average erasure value, migrate the physical block from the old ultra-cold chain to the young ultra-cold chain. In other words, the physical block is transformed from an old block into a young block.

[0067] Next, examine the physical blocks on the older, colder chains. Since the timestamps of the physical blocks on the older, colder chains are all less than the determination time, they are physical blocks that have undergone three full disk writes without being overwritten, and the data is even colder. Upgrade the cold data level of the physical blocks on the older, colder chains (i.e., upgrade from colder to ultra-colder). Move physical blocks whose number of erases does not exceed the average number of erases from the older, colder chains to the younger ultra-colder chains, and move physical blocks whose number of erases exceeds the average number of erases from the older, colder chains to the older ultra-colder chains.

[0068] Continue to examine the physical blocks on the old micro-cold chain. Since the timestamps of the physical blocks on the old micro-cold chain are all less than the judgment time, they are physical blocks that have undergone two full writes without being overwritten. Upgrade the cold data level of the physical blocks on the old micro-cold chain (i.e., upgrade from micro-cold to slightly cold). Move the physical blocks whose number of erases does not exceed the average number of erases from the old micro-cold chain to the young slightly cold chain, and move the physical blocks whose number of erases exceeds the average number of erases from the old micro-cold chain to the old slightly cold chain.

[0069] Finally, check the physical blocks on the old ambient temperature chain. When the timestamp of a physical block is less than or equal to the judgment time, it means that no data has been written to the physical block in this cycle. The data in the physical block is cold data. Physical blocks with timestamps less than or equal to the judgment time and the number of erases does not exceed the average number of erases are migrated from the old ambient temperature chain to the old slightly cold chain. Physical blocks with timestamps less than or equal to the judgment time and the number of erases exceeds the average number of erases are migrated from the old ambient temperature chain to the old micro-cold chain.

[0070] It should be noted that in this embodiment of the invention, wear leveling data migration involves migrating cold data from younger blocks to older blocks, freeing up younger blocks with fewer erase cycles. When selecting target physical blocks (i.e., the target blocks for data migration during wear leveling), the system first checks if any free blocks in the free block chain have an erase cycle greater than the average erase cycle. If so, the physical block with the highest erase cycle is selected as the target physical block. If not, the physical block with the smallest effective data volume is selected from the older, normal-temperature block chain as the target physical block. Data from the target physical block is migrated to a free block, and data from the source physical block is migrated to the target physical block, thus achieving wear leveling for the solid-state drive.

[0071] As can be seen, this embodiment of the invention sets up a free block chain, a working block chain, a young normal-temperature chain, a young slightly cold chain, a young moderately cold chain, a young ultra-cold chain, an old normal-temperature chain, an old slightly cold chain, an old moderately cold chain, and an old ultra-cold chain on the solid-state drive, using storage chains of multiple physical blocks to classify and manage physical blocks. Through a refined cold data migration strategy, it can be ensured that physical blocks are reasonably distributed in different levels of cold chains according to their erase count and timestamp. This not only helps to balance the wear level of each physical block, ensuring that older blocks rest and avoiding uneven wear caused by continued erasing and writing of older physical blocks, but also optimizes data access efficiency and improves the lifespan and overall performance of the solid-state drive.

[0072] Optionally, regarding how to adjust young and old blocks in a timely manner, the following is a possible implementation method. This method also includes the following steps: Periodically migrate older blocks in the older block chain that have been erased less than the average number of erasures to the younger block chain containing younger blocks of the same cold data level.

[0073] In this embodiment of the invention, as data is written to the solid-state drive, the average erase count is continuously updated. According to a preset period, each old block chain is periodically traversed. Physical blocks in the old ambient temperature chain with fewer erase counts than the average erase count are migrated to the young ambient temperature chain. Physical blocks in the old slightly cold chain with fewer erase counts than the average erase count are migrated to the young slightly cold chain. Physical blocks in the old partially cold chain with fewer erase counts than the average erase count are migrated to the young partially cold chain. Physical blocks in the old ultra-cold chain with fewer erase counts than the average erase count are migrated to the young ultra-cold chain.

[0074] As can be seen, the embodiments of the present invention periodically and dynamically adjust the less worn physical blocks from the old block chain to the young block chain based on the average erasure value, which more rationally manages physical blocks with different degrees of wear, ensures that the severely worn physical blocks are given sufficient rest, and the less worn physical blocks are fully utilized, ensuring a more uniform data distribution, which helps to extend the overall lifespan of the solid-state drive, while improving data access performance and reliability.

[0075] Based on the same inventive concept, the basic principle and technical effects of the wear equalization device provided in this embodiment are the same as those in the above embodiments. For the sake of brevity, any parts not mentioned in this embodiment can be referred to the corresponding content in the above embodiments.

[0076] Please refer to Figure 5 , Figure 5 This is a block diagram of a wear leveling device 400 provided in an embodiment of the present invention. The wear leveling device 400 is applied to a solid-state drive (SSD), which includes multiple physical blocks. The wear leveling device 400 includes a processing module 401 and a migration module 402.

[0077] The processing module 401 is used to determine the physical block with the highest cold data level and the smallest amount of effective data in the young blocks as the source physical block when the solid-state drive meets the start conditions for wear leveling. The young block is a physical block with fewer erase cycles than the average erase cycle and storing effective data. The cold data level is related to the effective data write time, and the longer the write time, the higher the level.

[0078] The processing module 401 is further configured to, if there are idle blocks with a number of erases greater than the average number of erases, determine the idle block with the largest number of erases as the target physical block; an idle block is a physical block that does not store valid data; if there are no idle blocks with a number of erases greater than the average number of erases, determine the physical block with the lowest cold data level and the smallest amount of valid data among the old blocks as the target physical block; an old block is a physical block with a number of erases not less than the average number of erases and storing valid data.

[0079] Migration module 402 is used to migrate data from the source physical block to the target physical block in order to achieve wear leveling.

[0080] In summary, the wear leveling device provided in this embodiment of the invention filters source physical blocks and target physical blocks based on the number of erases, write data time, and effective data volume. It identifies the physical block containing cold data with less wear and less effective data as the source physical block, and the physical block containing idle blocks with severe wear or hot data with severe wear and less effective data as the target physical block. Data from the source physical blocks is then migrated to the target physical blocks. This ensures that severely worn physical blocks receive sufficient rest, while lightly worn physical blocks are fully utilized. This balances the number of erases on the physical blocks in the solid-state drive (SSD), preventing individual physical blocks from failing prematurely due to frequent erasures. This helps extend the overall lifespan of the SSD, reduces performance degradation caused by localized wear, effectively reduces write amplification, and improves the efficiency of wear leveling.

[0081] Optionally, the migration module 402 is specifically used to determine the free block with the fewest erase counts as a candidate physical block; write the data of the target physical block into the candidate physical block, and write the data of the source physical block into the target physical block.

[0082] Optionally, the processing module 401 is further configured to allocate a free block as a physical block to be written when the user writes data; when the physical block to be written is full, set the cold data level and timestamp of the physical block to be written; if the number of erases of the physical block to be written does not exceed the average number of erases, the physical block to be written is determined as a young block; if the number of erases of the physical block to be written exceeds the average number of erases, the physical block to be written is determined as an old block; and update the number of erases of the physical block to be written.

[0083] Optionally, the solid-state drive maintains multiple young block chains and multiple old block chains. Different young block chains are used to record young blocks of different cold data levels, and different old block chains are used to record old blocks of different cold data levels. The processing module 401 is further configured to, when the amount of data written in the current cycle reaches a data volume threshold, update the young blocks in the young block chain according to the timestamp and the determination time; the determination time is the time when the amount of data written in the previous cycle reached the data volume threshold; update the old blocks in the old block chain according to the timestamp, the determination time, and the number of erases; and update the determination time to the time when the amount of data written in the current cycle reaches the data volume threshold.

[0084] Optionally, cold data levels include normal temperature, slightly cold, cool, and ultra-cold; multiple young blockchains include young normal temperature blockchains, young slightly cold blockchains, young cool blockchains, and young ultra-cold blockchains; young normal temperature blockchains are used to record young blocks with a cold data level of normal temperature, young slightly cold blockchains are used to record young blocks with a cold data level of slightly cold, young cool blockchains are used to record young blocks with a cold data level of cool, and young ultra-cold blockchains are used to record young blocks with a cold data level of ultra-cold.

[0085] The processing module 401 is also used to migrate physical blocks in the young cold chain to the young ultra-cold chain; migrate physical blocks in the young slightly cold chain to the young cold chain; and migrate physical blocks in the young room temperature chain whose timestamps are less than or equal to the determination time to the young slightly cold chain.

[0086] Optionally, the multiple aged blockchains include aged ambient temperature blockchains, aged slightly cold blockchains, aged partially cold blockchains, and aged ultra-cold blockchains; aged ambient temperature blockchains are used to record aged blocks with cold data at the ambient temperature level, aged slightly cold blockchains are used to record aged blocks with cold data at the slightly cold level, aged partially cold blockchains are used to record aged blocks with cold data at the partially cold level, and aged ultra-cold blockchains are used to record aged blocks with cold data at the ultra-cold level.

[0087] Processing module 401 is further configured to migrate physical blocks in the old ultra-cold chain whose number of erases does not exceed the average number of erases to the young ultra-cold chain; migrate physical blocks in the old semi-cold chain whose number of erases does not exceed the average number of erases to the young ultra-cold chain, and migrate physical blocks in the old semi-cold chain whose number of erases exceeds the average number of erases to the old ultra-cold chain; migrate physical blocks in the old micro-cold chain whose number of erases does not exceed the average number of erases to the young semi-cold chain, and migrate physical blocks in the old micro-cold chain whose number of erases exceeds the average number of erases to the old semi-cold chain; migrate physical blocks in the old room temperature chain whose number of erases does not exceed the average number of erases and whose timestamp is less than or equal to the determination time to the young slightly cold chain, and migrate physical blocks in the old room temperature chain whose number of erases exceeds the average number of erases and whose timestamp is less than or equal to the determination time to the old micro-cold chain.

[0088] Optionally, the processing module 401 is also used to periodically migrate older blocks in the older block chain whose number of erasures is less than the average number of erasures to the younger block chain containing younger blocks of the same cold data level.

[0089] Please refer to Figure 6 , Figure 6 This is a block diagram of a solid-state drive 500 provided in an embodiment of the present invention. The solid-state drive 500 includes a processor 510 and a memory 520, the memory 520 including multiple physical blocks. The memory 520 stores a computer program that can be executed by the processor 510, and the processor 510 executes the computer program to implement the wear leveling method disclosed in the above embodiments.

[0090] This invention also provides a computer-readable storage medium storing a computer program thereon, wherein a processor 510 executes the computer program to implement the wear leveling method disclosed in the above embodiments.

[0091] This invention also provides a program product, which is executed by processor 510 to implement the wear leveling method disclosed in the above embodiments.

[0092] In the several embodiments provided by this invention, it should be understood that the disclosed apparatus and methods can also be implemented in other ways. The apparatus embodiments described above are merely illustrative; for example, the flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods, and computer program products according to various embodiments of the invention. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than those marked in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram and / or flowchart, and combinations of blocks in block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.

[0093] In addition, the functional modules in the various embodiments of the present invention can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part.

[0094] If the aforementioned functions are implemented as software functional modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this invention, essentially, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, ROM (Read-Only Memory), RAM (Random Access Memory), magnetic disks, or optical disks.

[0095] The above description is merely a preferred embodiment of the present invention and is not intended to limit the invention. Various modifications and variations can be made to the present invention by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.

Claims

1. A wear leveling method, characterized in that, Applied to a solid-state drive (SSD), the SSD comprising multiple physical blocks; the method includes: When the solid-state drive meets the wear leveling startup conditions, the physical block with the highest cold data level and the smallest amount of effective data in the young blocks is determined as the source physical block; the young block is a physical block with fewer erase cycles than the average erase cycle and storing effective data; the longer the write time of the effective data in the physical block, the higher the cold data level of the physical block. If there is a free block with more erase counts than the average erase count, the free block with the highest number of erase counts is identified as the target physical block; the free block is a physical block that does not store valid data. If there are no free blocks with an erase count greater than the average erase count, the physical block with the lowest cold data level and the smallest amount of valid data among the old blocks is determined as the target physical block; the old block is a physical block with an erase count not less than the average erase count and storing valid data; Data from the source physical block is migrated to the target physical block to achieve wear leveling.

2. The wear equalization method according to claim 1, characterized in that, The step of migrating data from the source physical block to the target physical block includes: The free block with the fewest erase counts is identified as a candidate physical block; The data of the target physical block is written into the candidate physical block, and the data of the source physical block is written into the target physical block.

3. The wear equalization method according to claim 1, characterized in that, The method further includes: When a user writes data, a free block is allocated as the physical block to be written. Once the physical block to be written is full, set the cold data level and timestamp of the physical block to be written. If the number of erases on the physical block to be written does not exceed the average number of erases, the physical block to be written is identified as the young block; If the number of erases on the physical block to be written exceeds the average number of erases, the physical block to be written is identified as the old block; Update the erase count of the physical block to be written.

4. The wear equalization method according to claim 3, characterized in that, The solid-state drive maintains multiple young block chains and multiple old block chains, with different young block chains used to record young blocks of different cold data levels, and different old block chains used to record old blocks of different cold data levels; the method further includes: When the amount of data written in this cycle reaches the data volume threshold, the young blocks in the young block chain are updated according to the timestamp and the determination time; the determination time is the time when the amount of data written in the previous cycle reaches the data volume threshold. Update the old blocks in the old block chain according to the timestamp, the determination time, and the number of erasures; The determination time is updated to the time when the amount of data written in this cycle reaches the data volume threshold.

5. The wear equalization method according to claim 4, characterized in that, The cold data levels include normal temperature, slightly cold, cool, and ultra-cold; the multiple young blockchains include young normal temperature chains, young slightly cold chains, young cool chains, and young ultra-cold chains; the young normal temperature chains are used to record young blocks with a cold data level of normal temperature, the young slightly cold chains are used to record young blocks with a cold data level of slightly cold, the young cool chains are used to record young blocks with a cold data level of cool, and the young ultra-cold chains are used to record young blocks with an ultra-cold cold data level; updating the young blocks in the young blockchains according to the timestamp and the determination time includes: Migrate the physical blocks in the young, cold chain to the young, ultra-cold chain; The physical blocks in the young, slightly cold chain are migrated to the young, more cold chain. Physical blocks in the young ambient temperature chain with timestamps less than or equal to the determination time are migrated to the young slightly cold chain.

6. The wear equalization method according to claim 5, characterized in that, The multiple aged blockchains include aged ambient temperature blockchains, aged slightly cold blockchains, aged partially cold blockchains, and aged ultra-cold blockchains; the aged ambient temperature blockchains are used to record aged blocks with a cold data level of ambient temperature, the aged slightly cold blockchains are used to record aged blocks with a cold data level of slightly cold, the aged partially cold blockchains are used to record aged blocks with a cold data level of partially cold, and the aged ultra-cold blockchains are used to record aged blocks with a cold data level of ultra-cold; updating the aged blocks in the aged blockchains according to the timestamp, the determination time, and the number of erasures includes: The physical blocks in the older ultra-cold chain that have been erased no more than the average number of erasures are migrated to the younger ultra-cold chain; Physical blocks in the older, colder chain with fewer than the average number of erases are migrated to the younger, ultra-colder chain, and physical blocks in the older, colder chain with more than the average number of erases are migrated to the older, ultra-colder chain. Physical blocks in the older micro-cold chain whose number of erases does not exceed the average number of erases are migrated to the younger, slightly colder chain, and physical blocks in the older micro-cold chain whose number of erases exceeds the average number of erases are migrated to the older, slightly colder chain. Physical blocks in the aged ambient temperature chain whose number of erases does not exceed the average number of erases and whose timestamps are less than or equal to the determination time are migrated to the aged slightly cold chain, and physical blocks in the aged ambient temperature chain whose number of erases exceeds the average number of erases and whose timestamps are less than or equal to the determination time are migrated to the aged micro cold chain.

7. The wear equalization method according to claim 4, characterized in that, The method further includes: Periodically migrate older blocks in the older block chain that have been erased less than the average number of erasures to the younger block chain containing younger blocks of the same cold data level.

8. A wear equalization device, characterized in that, Applied to a solid-state drive, the solid-state drive comprising a plurality of physical blocks; the device includes: The processing module is used to determine the physical block with the highest cold data level and the smallest amount of effective data in the young blocks as the source physical block when the solid-state drive meets the wear leveling startup conditions; the young block is a physical block with fewer erase cycles than the average erase cycle and storing effective data; the cold data level is related to the effective data write time, and the longer the write time, the higher the level. The processing module is further configured to, if there are idle blocks with a wipe count greater than the average wipe count, identify the idle block with the highest wipe count as the target physical block; the idle block is a physical block that does not store valid data; if there are no idle blocks with a wipe count greater than the average wipe count, identify the physical block with the lowest cold data level and the smallest amount of valid data among the old blocks as the target physical block; the old block is a physical block with a wipe count not less than the average wipe count and storing valid data. The migration module is used to migrate the data of the source physical block to the target physical block in order to achieve wear leveling.

9. A solid-state drive, characterized in that, It includes a processor and a memory, the memory comprising a plurality of physical blocks, the memory storing a computer program executable by the processor to implement the wear leveling method according to any one of claims 1-7.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the wear leveling method as described in any one of claims 1-7.