A Wear-Leveling Method, System, Electronic Device and Medium for a Solid State Drive
By obtaining access characteristic data of data blocks in the hard disk area, dynamically classifying read and write priority blocks and performing data migration, the problem of insufficient accuracy of wear equalization in the prior art is solved, and more precise wear equalization and life extension are achieved.
Patent Information
- Application Number
- CN202510496818.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-21
- Publication Date
- 2025-07-08
- Estimated Expiration
- 2045-04-21
AI Technical Summary
The existing solid-state hard disk wear equalization method fails to effectively identify the wear difference of data blocks under different data access behaviors, resulting in insufficient accuracy of wear equalization.
By obtaining the access characteristic data of data blocks in the hard disk area, determining the read-write ratio, dynamically classifying it into read-first blocks and write-first blocks, and identifying the area to be equalized based on the number ratio, selecting the write-first blocks with the most erased times and the read-first blocks for data migration.
It realizes precise positioning of wear unbalanced areas and wear balance between data blocks, improves the accuracy and efficiency of wear balance, and extends the service life of the solid-state drive.
Smart Images

Figure CN120029555B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the technical field of data processing, and particularly to a wear leveling method, system, electronic device and medium for a solid state drive. Background Art
[0002] With the rapid development of information technology, solid state drives (SSDs) have been widely used in personal computers, data centers and other fields due to their advantages such as high-speed read and write performance, low power consumption and shock resistance. Different from traditional mechanical hard drives, the storage units of solid state drives have a limited number of erase and write cycles, and excessive erase and write will cause the storage units to fail. Therefore, wear leveling technology has become a key technology to improve the service life of solid state drives.
[0003] Currently, the wear leveling methods of existing solid state drives mainly achieve wear leveling of solid state drives by recording and tracking the erase and write times of data blocks, and evenly distributing the data of each data block after analysis. However, in actual applications, due to the differences in wear conditions of data blocks under different data access behaviors, simply using the existing method of evenly distributing data blocks often easily ignores the wear deviation of data blocks, thereby reducing the accuracy of wear leveling of solid state drives. Summary of the Invention
[0004] This application provides a wear leveling method, system, electronic device and medium for a solid state drive, which has the effect of improving the accuracy of wear leveling of the solid state drive.
[0005] In a first aspect, this application provides a wear leveling method for a solid state drive, including:
[0006] Obtaining access feature data of each data block in multiple hard disk regions;
[0007] In each of the hard disk regions, based on the access feature data of each data block, determining the read-write ratio of the corresponding data block within a preset time window, and determining the corresponding data block as a read-priority block or a write-priority block according to each read-write ratio;
[0008] Obtaining the quantity ratio of read-priority blocks to write-priority blocks in each hard disk region, and when the quantity ratio of any hard disk region exceeds a preset ratio range, determining the corresponding hard disk region as a region to be leveled;
[0009] Selecting the write-priority block with the most erase and write times as the first target block from the region to be leveled, and selecting the read-priority block with the least erase and write times from the remaining hard disk regions as the second target block;
[0010] Migrating the data in the first target block to the second target block.
[0011] In a second aspect of the present application, a wear leveling system for a solid-state drive is provided. The system includes:
[0012] A data acquisition module, configured to acquire access characteristic data of each data block in multiple hard disk regions;
[0013] A priority block determination module, configured to, in each of the hard disk regions, based on the access characteristic data of each data block, determine the read-write ratio of the corresponding data block within a preset time window, and determine the corresponding data block as a read-priority block or a write-priority block according to each read-write ratio;
[0014] A region determination module, configured to acquire the quantity ratio of read-priority blocks to write-priority blocks in each hard disk region, and when the quantity ratio of any hard disk region exceeds a preset ratio range, determine the corresponding hard disk region as a region to be balanced;
[0015] A data migration module, configured to select the write-priority block with the most erase-write times in the region to be balanced as a first target block, and select the read-priority block with the fewest erase-write times in the remaining hard disk regions as a second target block; and migrate the data in the first target block to the second target block.
[0016] In a third aspect of the present application, an electronic device is provided, including a memory, a processor, and a program stored on the memory and executable on the processor. When the program is loaded and executed by the processor, a wear leveling method for a solid-state drive can be implemented.
[0017] In a fourth aspect of the present application, a computer-readable storage medium is provided. The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the processor implements a wear leveling method for a solid-state drive.
[0018] In summary, one or more technical solutions provided in the embodiments of the present application have at least the following technical effects or advantages:
[0019] By adopting the above technical solution, by obtaining the access characteristic data of each data block in the hard disk area and determining the read-write ratio of the data block within a preset time window based on the access characteristic data, the access behavior characteristics of the data block are accurately identified, so that the data block is classified into a read-priority block and a write-priority block, effectively distinguishing the usage characteristics of the data block under different data access modes; furthermore, by calculating the quantity ratio of the read-priority blocks and the write-priority blocks in the hard disk area to identify the area to be balanced, the accurate positioning of the wear-uneven area is realized; then, by selecting the write-priority block with the most erasure-write times in the area to be balanced as the first target block and selecting the read-priority block with the fewest erasure-write times from other areas as the second target block, the optimal target selection for data migration is ensured; finally, by migrating the data in the first target block to the second target block, the wear balance between data blocks is realized on the basis of considering the actual access behavior differences of the data blocks, avoiding the wear deviation problem that may be caused by relying only on the average distribution method, effectively balancing the wear degree between different areas, and thus significantly improving the accuracy of the wear leveling of the solid-state drive. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] Figure 1 is a schematic flowchart of a wear leveling method for a solid-state drive provided by an embodiment of the present application;
[0021] Figure 2 is a schematic structural diagram of a wear leveling system for a solid-state drive provided by an embodiment of the present application;
[0022] Figure 3 is a schematic structural diagram of an electronic device provided by an embodiment of the present application.
[0023] DESCRIPTION OF REFERENCE NUMERALS: 300, electronic device; 301, processor; 302, communication bus; 303, user interface; 304, network interface; 305, memory. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0024] In order to enable those skilled in the art to better understand the technical solutions in this specification, the following will clearly and completely describe the technical solutions in the embodiments of this specification with reference to the accompanying drawings in the embodiments of this specification. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments.
[0025] In the description of the embodiments of the present application, words such as "for example" or "for instance" are used to represent examples, illustrations or explanations. Any embodiment or design solution described as "for example" or "for instance" in the embodiments of the present application should not be construed as being more preferred or having more advantages than other embodiments or design solutions. Exactly speaking, using words such as "for example" or "for instance" aims to present relevant concepts in a specific manner.
[0026] In the description of the embodiments of the present application, the term "plurality" means two or more. For example, a plurality of systems means two or more systems, and a plurality of screen terminals means two or more screen terminals. In addition, the terms "first" and "second" are only used for descriptive purposes and cannot be construed as indicating or implying relative importance or implicitly specifying the indicated technical features. Thus, the features defined with "first" and "second" may explicitly or implicitly include one or more of such features. The terms "comprise", "include", "have" and their variants all mean "including but not limited to", unless otherwise specifically emphasized in other ways.
[0027] The embodiments of the present application provide a wear leveling method for a solid state drive. In one embodiment, please refer to Figure 1 , Figure 1 which is a schematic flowchart of the wear leveling method for the solid state drive provided by the embodiments of the present application. This method can be implemented depending on a computer program, which can be integrated in an application or run as an independent tool-like application. This method can also be implemented depending on a single-chip microcomputer and can also run in a wear leveling system of a solid state drive based on the von Neumann architecture. Specifically, this method may include the following steps:
[0028] Step 101: Obtain access characteristic data of each data block in a plurality of hard disk areas.
[0029] Among them, a hard disk area refers to a storage area with continuous physical addresses divided in the storage space of the solid state drive, which can be understood as a set of storage units composed of a plurality of adjacent data blocks.
[0030] A data block refers to the smallest addressable storage unit in each hard disk area of the solid state drive. Each data block has a unique physical address identifier and establishes a corresponding relationship with a logical address through an address mapping table. As the basic unit for data read and write operations of the solid state drive, a data block needs to perform an erase operation first when writing data, and the erase operation will cause wear of the storage unit.
[0031] The access characteristic data refers to statistical information reflecting the read and write access behaviors of the data block during actual use.
[0032] Specifically, the solid-state drive divides its storage space into multiple hard disk regions, and each hard disk region contains multiple data blocks. To accurately grasp the usage status of each data block, it is first necessary to obtain the access characteristic data of each data block. Specifically, an access monitoring module is set in the controller of the solid-state drive, and this module can record the read operations and write operations of each data block in real time. When a read or write operation occurs on a data block, the access monitoring module records the operation type, operation timestamp, and data block identifier into the access log. The access monitoring module also counts the number of times each data block is read and written within a preset time window (such as 1 hour, 24 hours, etc.), and stores these statistical data as the access characteristic data of the data block in a specific storage area of the solid-state drive. These access characteristic data reflect the usage patterns of data blocks in actual application scenarios, providing a data basis for subsequent identification of the access tendencies of data blocks. By obtaining these access characteristic data, the actual usage of each data block can be understood more precisely, thereby providing a more accurate basis for subsequent wear leveling decisions and avoiding the leveling errors caused by relying solely on the statistics of the number of erase / write cycles. For example, for a data block that is frequently read but rarely written, even if its cumulative number of erase / write cycles is low, it should be preferentially retained in its current position instead of simply being used as a target for wear leveling migration. This analysis method based on access characteristics can better adapt to the data access patterns in different application scenarios, improving the accuracy and efficiency of wear leveling.
[0033] Step 102: Within each hard disk region, based on the access characteristic data of each data block, determine the read / write ratio of the corresponding data block within the preset time window, and determine the corresponding data block as a read-priority block or a write-priority block according to each read / write ratio.
[0034] Among them, the read / write ratio refers to the ratio between the read frequency and the write frequency of a data block within the preset time window, and can be understood as a quantitative indicator for measuring the access behavior tendency of a data block.
[0035] A read-priority block refers to a data block whose read operations are significantly more than its write operations within the preset time window, specifically manifested as its read / write ratio being greater than or equal to the dynamic classification threshold. Such data blocks usually store relatively stable data contents, such as operating system files, application program files, or user data that is frequently accessed but rarely modified. Since the write operations of read-priority blocks are less, the wear degree of their storage units is relatively low, so they are suitable as the target positions for data migration to receive the data in write-priority blocks.
[0036] A write-priority block refers to a data block with relatively frequent write operations within a preset time window, specifically manifested as its read-write ratio being less than the dynamic classification threshold. Such data blocks are usually used to store data content that is frequently updated, such as system logs, database files, or temporary cache files. Since write-priority blocks perform frequent data write operations, the wear level of their storage units is relatively high. It is necessary to timely migrate the data in them to read-priority blocks through wear leveling technology to avoid excessive wear of local storage units, thereby extending the overall service life of the solid-state drive.
[0037] Specifically, to accurately identify the access tendency of data blocks, it is necessary to analyze and process the obtained access feature data. First, extract the read count and write count of each data block within the preset time window from the access feature data. Then, based on the read count and the duration corresponding to the preset time window, calculate the read frequency of the data block. Similarly, based on the write count and the duration corresponding to the preset time window, calculate the write frequency of the data block. Calculate the ratio between the read frequency and the write frequency of the data block to obtain the read-write ratio of the data block. For example, if the read frequency of a certain data block in the past 24 hours is 20 times per hour and the write frequency is 2 times per hour, then its read-write ratio is 10. Next, based on the read-write ratios of each data block in the hard disk area, calculate the concentration eigenvalue of the read-write ratios. Specifically, first calculate the arithmetic mean of the read-write ratios of each data block in this area, then determine the deviation value between each read-write ratio and the arithmetic mean, and based on these deviation values, weight and correct the arithmetic mean, and determine the corrected arithmetic mean as the concentration eigenvalue. Based on this concentration eigenvalue, determine the dynamic classification threshold. When the read-write ratio of a data block is greater than or equal to this dynamic classification threshold, it is determined as a read-priority block, otherwise it is determined as a write-priority block. In this way, the data blocks can be dynamically classified according to their actual access patterns, avoiding the blindness brought by only balancing based on the number of erase-write cycles in the traditional method. This dynamic classification method based on the read-write ratio can more accurately reflect the usage characteristics of data blocks in actual applications, provide a more reasonable decision-making basis for subsequent wear leveling, and thus improve the accuracy and efficiency of wear leveling.
[0038] Based on the above embodiments, as an optional embodiment, in step 102: Based on the access feature data of each data block, determining the read-write ratio of the corresponding data block within the preset time window, this step may further include the following steps:
[0039] Step 201: Extract the read count and write count of the corresponding data block within the preset time window from each access feature data.
[0040] Specifically, the controller of the solid-state drive is provided with an access monitoring module, which maintains an access log table for recording the usage of data blocks. The structure of the access log table includes information such as data block numbers, operation types, and operation times. When extracting access feature data, the system first determines a preset time window. For example, with the current moment as the end point, it calculates back 24 hours as the starting point. Subsequently, the system retrieves all access records within this time window. For each data block, the system separately sets a read counter and a write counter. During the retrieval process, when a read operation is encountered, the read counter corresponding to the data block increments by one count; when a write operation is encountered, the write counter corresponding to the data block increments by one count. In this way, the system can obtain the exact number of reads and writes of each data block within the preset time window, and these data are saved in a special statistical table to prepare for subsequent frequency calculations.
[0041] Step 202: Calculate the read frequency of the corresponding data block based on each read count and the duration corresponding to the preset time window, and calculate the write frequency of the corresponding data block based on each write count and the duration corresponding to the preset time window.
[0042] Specifically, first, the system determines the duration of the preset time window, such as 24 hours. Then, for each data block, the system divides its read count by the duration of the time window to obtain the read frequency, and similarly divides the write count by the duration of the time window to obtain the write frequency. For example, if a certain data block is read 480 times and written 48 times within 24 hours, then its read frequency is 20 times per hour, and the write frequency is 2 times per hour. Considering that some data blocks may not have write operations within the preset time window, the system sets a minimum frequency value, such as 0.001 times per hour. When the calculated frequency is lower than this value, this minimum frequency value is used instead. This can avoid abnormal situations in subsequent calculations and also reflect the characteristic that the data block is rarely written. The system records the read frequency and write frequency of each data block in the frequency statistical table.
[0043] Step 203: Use the ratio between the read frequency and the write frequency of each data block as the read-write ratio of the corresponding data block.
[0044] Specifically, based on the calculated read frequency and write frequency, the system calculates a read-write ratio that reflects the access characteristics of data blocks. Specifically, for each data block, the system divides its read frequency by the write frequency to obtain the read-write ratio of the data block. For example, if the read frequency of a certain data block is twenty times per hour and the write frequency is two times per hour, then its read-write ratio is ten. For those data blocks whose write frequency is equal to the minimum frequency value, the system will set their read-write ratio to a relatively large preset value, such as one thousand, to indicate that these data blocks hardly perform write operations. The read-write ratios of all data blocks are restricted between zero and a preset maximum value to ensure data standardization. Finally, the system saves each data block and its corresponding read-write ratio in a ratio statistical table, which clearly shows the access tendencies of different data blocks and provides an important basis for subsequent classification of data blocks.
[0045] Based on the above embodiments, as an optional embodiment, in step 102: determining the corresponding data blocks as read-priority blocks or write-priority blocks according to the read-write ratios, this step may further include the following steps:
[0046] Step 204: Based on the read-write ratios of the data blocks in the hard disk area, calculate the concentration characteristic value of the read-write ratios, and determine the dynamic classification threshold according to the concentration characteristic value.
[0047] Specifically, the system needs to calculate the concentration characteristic value that reflects the overall access characteristics of the hard disk area based on the obtained read-write ratio data. First, the system obtains the read-write ratios of all data blocks in the hard disk area, adds these read-write ratios and divides by the total number of data blocks to obtain the arithmetic mean. Then, the system calculates the difference between the read-write ratio of each data block and the arithmetic mean to obtain the deviation value of each data block. Then, the system analyzes these deviation values and regards the deviation values that exceed the preset deviation range as outliers. For non-outlier deviation values, the system calculates their weighted sum with the arithmetic mean, where the weight coefficient can be dynamically adjusted according to the size of the deviation value, and the smaller the deviation value, the greater the weight. Finally, the system determines this weighted corrected arithmetic mean as the concentration characteristic value of the hard disk area. Based on this concentration characteristic value, the system obtains the dynamic classification threshold by multiplying by a preset adjustment coefficient. This calculation method not only considers the overall distribution characteristics of the data block read-write ratios, but also reduces the influence of abnormal data through the weighted correction mechanism, so that the finally obtained dynamic classification threshold can more accurately reflect the actual usage of the hard disk area.
[0048] Based on the above embodiments, as an optional embodiment, in step 204: calculating the concentration characteristic value of the read-write ratios based on the read-write ratios of the data blocks in the hard disk area, this step may further include the following steps:
[0049] Step 214: Calculate the arithmetic mean of the read / write ratios of each data block within the hard disk area.
[0050] Specifically, the system first obtains the read / write ratio data of all data blocks within the hard disk area. To obtain the overall access characteristics, the system accumulates these read / write ratios and then divides by the total number of data blocks to obtain the arithmetic mean. For example, assume there are one thousand data blocks within the hard disk area. The system adds up the read / write ratios of these one thousand data blocks and divides by one thousand to obtain the initial arithmetic mean that reflects the overall access characteristics. This arithmetic mean initially reflects the average access characteristics of the data blocks within this hard disk area and provides a reference value for subsequent deviation analysis. Using the arithmetic mean as the initial calculation result can ensure that the calculation process is simple and intuitive, and at the same time lay a foundation for subsequent refined processing.
[0051] Step 224: Determine the deviation values between each read / write ratio and the arithmetic mean.
[0052] Specifically, the system needs to analyze the degree of deviation of the read / write ratio of each data block from the arithmetic mean. The specific approach is that the system calculates the difference between the read / write ratio of each data block and the arithmetic mean one by one to obtain the deviation value of each data block. The system also statistically analyzes the distribution of positive and negative deviation values, records the maximum and minimum deviation values, and the quantity distribution of deviation values within each interval. These deviation data reflect the dispersion degree of the access characteristics of different data blocks and provide important references for subsequent weighted correction. By calculating the deviation values, the system can identify data blocks with abnormal access characteristics. The read / write ratios of these data blocks are quite different from the overall average level and need to be specially processed in subsequent corrections.
[0053] Step 234: Perform weighted correction on the arithmetic mean based on each deviation value and determine the corrected arithmetic mean as the centralized characteristic value.
[0054] Specifically, the system performs weighted correction on the arithmetic mean based on the deviation values obtained in the foregoing steps. First, the system sets a reference deviation range. When the deviation value of a data block exceeds this range, it is determined as an outlier, and these outliers will be given smaller weights during the weighted calculation. For deviation values within the normal range, the system adopts a decreasing weighting method, that is, the smaller the deviation value of the data block, the greater the weight it obtains. For example, the deviation values can be divided into multiple intervals according to their magnitudes. The weight of the data block with the deviation value in the smallest interval is one, and as the deviation value increases, the weights decrease to 0.8, 0.6, etc. in sequence. The system multiplies these weight values by the read-write ratios of the corresponding data blocks, sums up all the weighted read-write ratios, and then divides by the sum of the weights to obtain the corrected arithmetic mean, which is determined as the final centralized eigenvalue. This weighted correction mechanism can reduce the influence of abnormal data, enabling the centralized eigenvalue to more accurately reflect the main access characteristics of the hard disk area, providing a more reliable basis for determining the dynamic classification threshold subsequently. At the same time, due to the adoption of a dynamic weight allocation method based on deviation, this correction method can adapt to the data access patterns in different application scenarios, improving the accuracy and adaptability of eigenvalue calculation.
[0055] Step 205: When the read-write ratio is greater than or equal to the dynamic classification threshold, the corresponding data block is regarded as a read-priority block; when the read-write ratio is less than the dynamic classification threshold, the corresponding data block is regarded as a write-priority block.
[0056] Specifically, the system classifies the data blocks in the hard disk area using the dynamic classification threshold. The read-write ratio of each data block is read in sequence and compared with the dynamic classification threshold. When the read-write ratio of the data block is greater than or equal to the dynamic classification threshold, it indicates that the read operation of this data block is significantly more than the write operation. The system marks it as a read-priority block and updates the attribute identifier of this data block in the management table of the solid-state drive. When the read-write ratio of the data block is less than the dynamic classification threshold, it shows that the write operation of this data block is relatively frequent. The system marks it as a write-priority block and also updates the attribute identifier in the management table. Through this dynamic classification method, the system can classify the data blocks into two categories: read-priority blocks and write-priority blocks according to the actual data access pattern. This classification result can accurately reflect the usage characteristics of the data blocks, providing a reliable decision-making basis for subsequent wear leveling operations. For example, when data migration is required, the system will preferentially select write-priority blocks as source data blocks and read-priority blocks as target data blocks, thereby achieving more targeted wear leveling control. At the same time, since the classification threshold is dynamically calculated based on the overall characteristics of the hard disk area, this classification method can adapt to the data access patterns in different application scenarios, improving the accuracy and efficiency of wear leveling.
[0057] Step 103: Obtain the quantity ratio of read-priority blocks to write-priority blocks in each hard disk area. When the quantity ratio of any hard disk area exceeds the preset ratio range, determine the corresponding hard disk area as the area to be balanced.
[0058] Among them, the preset ratio range in this embodiment refers to the quantity ratio interval used to judge whether a hard disk area needs to perform wear leveling. This range is determined based on the statistical distribution characteristics of read and write operations when the solid-state drive is in normal use. When the quantity ratio in a hard disk area is within this range, it indicates that the data block distribution in this area is relatively balanced and does not require immediate wear leveling operations; when the ratio exceeds this range, it indicates that there is an obvious imbalance in the data block distribution within the area, and data migration is required to adjust the distribution state.
[0059] In this embodiment, the area to be balanced refers to the hard disk area where the quantity ratio exceeds the preset ratio range.
[0060] Specifically, the system analyzes and evaluates the data block distribution status of each hard disk area in the solid-state drive. First, the system reads the quantity information of read-priority blocks and write-priority blocks in each hard disk area from the management table of the solid-state drive. Based on this quantity information, the system calculates the quantity ratio of each hard disk area by dividing the quantity of read-priority blocks by the quantity of write-priority blocks. For example, if there are 800 read-priority blocks and 200 write-priority blocks in a certain hard disk area, its quantity ratio is 4. The system has preset a reasonable ratio range, such as [1.5, 6], which is determined based on the distribution characteristics of read and write operations when the solid-state drive is in normal use. When the quantity ratio of a certain hard disk area is less than 1.5 or greater than 6, it indicates that the data block distribution in this area has deviated significantly. A too low ratio means that there are too many write-priority blocks in the area, which may cause a large write pressure on the storage units in this area; a too high ratio indicates that the read-priority blocks are too concentrated, which is not conducive to the load balancing of subsequent write operations. Therefore, the system marks the hard disk areas with quantity ratios exceeding the preset range as areas to be balanced and gives priority to processing these areas in the subsequent wear leveling process. This evaluation method based on quantity ratio can timely detect hard disk areas with unbalanced data block distribution, and adjust the distribution of read and write priority blocks through targeted data migration to ensure that the wear degree of storage units in each area of the solid-state drive tends to be consistent, thereby extending the service life of the solid-state drive. At the same time, since the preset ratio range is used as the judgment criterion, this evaluation method has strong adaptability and can effectively identify hard disk areas that need to perform wear leveling in different application scenarios.
[0061] Step 104: Select the write-priority block with the most erase-write times as the first target block from the areas to be balanced, and select the read-priority block with the fewest erase-write times as the second target block from the remaining hard disk areas.
[0062] Among them, the first target block in this embodiment refers to the write-priority block with the most write-erase times selected from the area to be balanced, and is used as the source data block for data migration.
[0063] The second target block in this embodiment refers to the read-priority block with the least write-erase times selected from the non-area to be balanced (i.e., the remaining hard disk area), and is used as the target data block for data migration.
[0064] Specifically, first, the system accesses the wear status table of the solid-state drive, which records the write-erase times information of each data block. For the identified area to be balanced, the system traverses all the write-priority blocks therein, compares their write-erase times, and finds the write-priority block with the most write-erase times as the first target block. The reason for selecting the write-priority block with the most write-erase times is that the storage unit where this data block is located bears the greatest write pressure, has the highest wear degree, and most needs data migration. Then, the system traverses the other hard disk areas except the area to be balanced, and finds the data block with the least write-erase times from the read-priority blocks in these areas, and uses it as the second target block. The reason for selecting the read-priority block with the least write-erase times is that the storage unit where this data block is located has a lower wear degree and has enough write-erase margin to receive the data in the first target block. For example, if the write-erase times of the first target block is 1000 times, while the write-erase times of the second target block is only 100 times, then by migrating the data from the first target block to the second target block, the usage frequency of the high-wear storage unit can be significantly reduced. This selection strategy based on write-erase times can balance the wear status of each storage unit to the greatest extent. By migrating the frequently written data to the storage unit with a lower wear degree, more accurate and efficient wear leveling control is achieved, effectively extending the service life of the solid-state drive.
[0065] Step 105: Migrate the data in the first target block to the second target block.
[0066] Specifically, first, the system reads the data of the first target block into the cache for temporary storage, and at the same time records the metadata information of this data block, including the logical address mapping relationship of the data and the data block attributes, etc. Then, the system checks the status of the second target block to ensure that it is in a writable state and has sufficient storage space. If there is already data in the second target block, the system will transfer this data to other appropriate data blocks. Then, the system writes the data in the cache into the second target block and updates the corresponding mapping table, remapping the logical address that originally pointed to the first target block to the physical address of the second target block. After completing the data migration, the system marks the first target block as an invalid state, waiting for subsequent garbage collection operations. This data migration operation can achieve the dynamic transfer of the write load, transferring the frequently written data from the severely worn storage units to the less worn storage units. In this way, the system realizes the dynamic balance of the wear degree of the storage units, effectively extending the service life of the solid-state drive. At the same time, because the cache is used as a transfer medium during the data migration process and the logical address mapping relationship of the data is maintained, it ensures the transparency of the data migration operation to the upper-layer applications and does not affect the normal read and write operations.
[0067] Based on the above embodiments, as an optional embodiment, in step 105: migrating the data in the first target block to the second target block, this step may further include the following steps:
[0068] Step 301: Obtain the amount of data to be migrated in the first target block and the available storage capacity of the second target block; when the amount of data to be migrated is less than or equal to the available storage capacity, write the data in the first target block into the second target block.
[0069] Specifically, the system first needs to confirm the feasibility of the data migration operation. The system reads the data size information of the first target block to obtain the total amount of data to be migrated, and at the same time checks the storage status of the second target block to calculate its currently available storage space. By comparing these two values, the system can determine whether the second target block can completely accommodate all the data in the first target block. When the amount of data to be migrated is less than or equal to the available storage capacity, it indicates that the second target block has sufficient space, and the system will directly perform the data writing operation. Specifically, the system reads the data in the first target block into the cache and then writes it into the second target block. This direct data migration method can ensure the integrity of the data and reduce the management overhead caused by the scattered storage of the data.
[0070] Step 302: When the amount of data is greater than the available storage capacity, select at least one read-priority block with the largest available storage capacity from the remaining hard disk area as the backup target block.
[0071] Specifically, when the system detects that the data volume of the first target block exceeds the available capacity of the second target block, it is necessary to find additional storage space to accommodate the remaining data. The system will scan other hard disk areas except the area to be balanced, count the available storage capacities of all read-priority blocks, and sort them according to the capacity size. Then, it selects the read-priority block with the largest available capacity as the spare target block. If the capacity of a single read-priority block is still insufficient, multiple read-priority blocks may be needed. Selecting the read-priority block with the largest available capacity can reduce the degree of data dispersion, facilitating subsequent data management and access. In addition, since the selected blocks are read-priority blocks, these data blocks are originally mainly used for reading operations, with a low number of read / write cycles, and are suitable for receiving data from high-wear areas.
[0072] Step 303: Write the data exceeding the available storage capacity of the second target block into the spare target block; update the address mapping relationship between the first target block, the second target block, and the spare target block.
[0073] Specifically, the system performs a segmented data migration operation. First, the system calculates the data volume that the second target block can accommodate and writes this part of the data into the second target block; then writes the remaining data into the previously selected spare target block. After the data writing is completed, the system needs to update the address mapping table to map the original logical addresses pointing to the first target block to the corresponding physical addresses of the second target block and the spare target block respectively. This segmented migration strategy can still achieve the complete migration of data when the capacity of the second target block is insufficient, ensuring the effective execution of the wear leveling operation. By updating the address mapping relationship, the system ensures that the upper-layer application can correctly access the migrated data while maintaining the logical continuity of the data. This data migration scheme based on multiple target blocks enhances the flexibility and reliability of the system in handling large-capacity data migration and effectively supports the wear leveling management of solid-state drives.
[0074] Based on the above embodiments, as an alternative embodiment, in step 303: updating the address mapping relationship between the first target block, the second target block, and the spare target block, this step may further include the following steps:
[0075] Step 313: Obtain the original logical address corresponding to the first target block; delete the mapping relationship between the original logical address and the physical addresses of the first target block and the spare target block in the address mapping table.
[0076] Specifically, the system needs to update the address mapping relationship of the solid-state drive. First, the system looks up the original logical address information currently corresponding to the first target block in the address mapping table. The original logical address is the address used by the upper-layer application to access data, and there is a one-to-one mapping relationship with the physical address of the first target block. Since the data will be migrated to a new physical location, the system needs to clear these outdated mapping relationships from the address mapping table. Specifically, the system locates all mapping entries related to the original logical address in the address mapping table, including the mapping relationships pointing to the first target block and the alternative target blocks that may have been used previously, and then marks these mapping entries as invalid or directly deletes them. The purpose of doing this is to prepare for establishing new mapping relationships later, avoid address mapping conflicts, and ensure the accuracy of data access.
[0077] Step 323: According to the written data in the second target block and the alternative target block, map the original logical address to the physical addresses corresponding to the second target block and the alternative target block respectively.
[0078] Specifically, the system establishes a new address mapping relationship according to the actual situation of data migration. The system first confirms the actual written data ranges in the second target block and the alternative target block, and this range information can help the system accurately divide the mapping intervals of logical addresses. For the data part written to the second target block, the system maps the corresponding original logical address segment to the physical address of the second target block; for the data part written to the alternative target block, the system maps the corresponding original logical address segment to the physical address of the alternative target block. For example, if the size of the original data block is 8KB, with 5KB written to the second target block and 3KB written to the alternative target block, then the system will map the first 5KB of the original logical address to the physical address of the second target block, and the last 3KB to the physical address of the alternative target block. This mapping method based on the actual data distribution ensures that the upper-layer application can accurately access the migrated data, while maintaining the continuity of data at the logical level. Through this precise address mapping update, the system realizes the transparency of the data migration process to the upper-layer application, ensuring the correctness and efficiency of data access.
[0079] Based on the above embodiments, as an alternative embodiment, in step 323: According to the written data in the second target block and the alternative target block, map the original logical address to the physical addresses corresponding to the second target block and the alternative target block respectively. This step may further include the following steps:
[0080] Step 401: Calculate the first relative offset of the written data in the second target block and the second relative offset of the written data in the alternative target block.
[0081] Specifically, the system needs to accurately calculate the distribution of data in the new storage location. First, the system obtains the start position and end position of the actually written data in the second target block, and calculates the first relative offset by calculating the differences between these two positions and the start address of the second target block. Similarly, the system also calculates the start position and end position of the written data in the spare target block to obtain the second relative offset. For example, if data is written starting from the 1024th byte position in the second target block, the first relative offset is 1024; if data is written starting from the 512th byte position in the spare target block, the second relative offset is 512. These offset information are crucial for establishing an accurate address mapping relationship subsequently, because they reflect the actual distribution positions of the data in the physical storage space.
[0082] Step 402: In the original logical address, determine the first address segment corresponding to the first relative offset and the second address segment corresponding to the second relative offset.
[0083] Specifically, the system divides the original logical address space according to the calculated relative offsets. The system first obtains the start position of the original logical address, and then determines the range of the first address segment according to the first relative offset. This part of the address corresponds to the data written to the second target block. Then, according to the second relative offset, it determines the range of the second address segment. This part of the address corresponds to the data written to the spare target block. For example, assume the original logical address is 0x1000 - 0x3000, where the data from 0x1000 - 0x2000 is written to the second target block, and the data from 0x2000 - 0x3000 is written to the spare target block. Then the first address segment is 0x1000 - 0x2000, and the second address segment is 0x2000 - 0x3000. This offset-based address segment division ensures that the correspondence between the data in the logical space and the physical space remains consistent.
[0084] Step 403: Map the first address segment to the physical address of the second target block, and map the second address segment to the physical address of the spare target block.
[0085] Specifically, the system performs an actual address mapping update operation. First, the system establishes a mapping relationship between the first address segment and the physical address of the second target block, and writes this mapping information into the address mapping table. Similarly, the system establishes a mapping relationship between the second address segment and the physical address of the spare target block, and also writes this mapping information into the address mapping table. For example, if the data in the first address segment 0x1000 - 0x2000 is stored at the physical address 0xA000 - 0xB000 of the second target block, a mapping from the physical address 0x1000 - 0x2000 to 0xA000 - 0xB000 is established in the address mapping table; if the data in the second address segment 0x2000 - 0x3000 is stored at the physical address 0xC000 - 0xD000 of the spare target block, a mapping from 0x2000 - 0x3000 to 0xC000 - 0xD000 is established. This precise address mapping mechanism ensures that the system can correctly locate and access the scattered - stored data after data migration, while maintaining the logical continuity of the data and improving the efficiency of data access.
[0086] Refer to Figure 2 , a wear - leveling system for a solid - state drive provided by an embodiment of the present application. The system includes: a data acquisition module, a priority block determination module, a region determination module, and a data migration module, where:
[0087] The data acquisition module is configured to acquire access characteristic data of each data block in multiple hard - disk regions;
[0088] The priority block determination module is configured to, within each hard - disk region, based on the access characteristic data of each data block, determine the read - write ratio of the corresponding data block within a preset time window, and determine the corresponding data block as a read - priority block or a write - priority block according to each read - write ratio;
[0089] The region determination module is configured to acquire the quantity ratio of the read - priority blocks to the write - priority blocks in each hard - disk region, and when the quantity ratio of any hard - disk region exceeds a preset ratio range, determine the corresponding hard - disk region as a region to be balanced;
[0090] The data migration module is configured to select the write - priority block with the most erase - write times in the region to be balanced as the first target block, and select the read - priority block with the fewest erase - write times from the remaining hard - disk regions as the second target block; and migrate the data in the first target block to the second target block.
[0091] Based on the above embodiments, the priority block determination module is further configured to extract the number of reads and writes of the corresponding data block within a preset time window from each access feature data; calculate the read frequency of the corresponding data block based on each read count and the duration corresponding to the preset time window, and calculate the write frequency of the corresponding data block based on each write count and the duration corresponding to the preset time window; and use the ratio between the read frequency and the write frequency of each data block as the read-write ratio of the corresponding data block.
[0092] Based on the above embodiments, the priority block determination module is further configured to calculate a concentration eigenvalue of the read-write ratio based on the read-write ratios of each data block in the hard disk area, and determine a dynamic classification threshold according to the concentration eigenvalue; when the read-write ratio is greater than or equal to the dynamic classification threshold, use the corresponding data block as a read-priority block, and when the read-write ratio is less than the dynamic classification threshold, use the corresponding data block as a write-priority block.
[0093] Based on the above embodiments, the priority block determination module is further configured to calculate the arithmetic mean of the read-write ratios of each data block in the hard disk area; determine the deviation value between each read-write ratio and the arithmetic mean; perform weighted correction on the arithmetic mean based on each deviation value, and determine the corrected arithmetic mean as the concentration eigenvalue.
[0094] Based on the above embodiments, the data migration module is further configured to obtain the amount of data to be migrated of the first target block and the available storage capacity of the second target block; when the amount of data to be migrated is less than or equal to the available storage capacity, write the data in the first target block to the second target block; when the amount of data is greater than the available storage capacity, select at least one read-priority block with the largest available storage capacity from the remaining hard disk area as a standby target block; write the data exceeding the available storage capacity of the second target block to the standby target block; and update the address mapping relationship between the first target block, the second target block, and the standby target block.
[0095] Based on the above embodiments, the data migration module is further configured to obtain the original logical address corresponding to the first target block; delete the mapping relationship between the original logical address and the physical addresses of the first target block and the standby target block in the address mapping table; and map the original logical address to the physical addresses corresponding to the second target block and the standby target block respectively according to the written data in the second target block and the standby target block.
[0096] Based on the above embodiments, the data migration module is further configured to calculate a first relative offset of the written data in the second target block and a second relative offset of the written data in the standby target block; determine a first address segment corresponding to the first relative offset and a second address segment corresponding to the second relative offset in the original logical address; map the first address segment to the physical address of the second target block, and map the second address segment to the physical address of the standby target block.
[0097] It should be noted that: when the device provided in the above embodiment realizes its functions, only the division of the above functional modules is used for illustration. In actual applications, the above functions can be allocated to different functional modules according to needs, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. In addition, the device and method embodiments provided in the above embodiments belong to the same concept. For the specific implementation process, please refer to the method embodiments and will not be elaborated here.
[0098] This application also discloses an electronic device. Referring to Figure 3 , Figure 3 FIG. is a schematic structural diagram of an electronic device disclosed in an embodiment of the present application. The electronic device 300 may include: at least one processor 301, at least one network interface 304, a user interface 303, a memory 305, and at least one communication bus 302.
[0099] Among them, the communication bus 302 is used to realize the connection and communication between these components.
[0100] Among them, the user interface 303 may include a display (Display) interface and a camera (Camera) interface. Optionally, the user interface 303 may further include a standard wired interface and a wireless interface.
[0101] Among them, the network interface 304 may optionally include a standard wired interface and a wireless interface (such as a WI-FI interface).
[0102] Among them, the processor 301 may include one or more processing cores. The processor 301 connects various parts within the entire server using various interfaces and circuits. By running or executing instructions, programs, code sets, or instruction sets stored in the memory 305, and by invoking the data stored in the memory 305, it performs various functions of the server and processes data. Optionally, the processor 301 may be implemented in at least one hardware form of digital signal processing (DSP), field-programmable gate array (FPGA), or programmable logic array (PLA). The processor 301 may integrate a combination of one or more of a central processing unit (CPU), a graphics processing unit (GPU), and a modem, etc. Among them, the CPU mainly processes the operating system, user interface graphics, and application programs, etc.; the GPU is responsible for rendering and drawing the content to be displayed on the display screen; the modem is used to process wireless communication. It can be understood that the above-mentioned modem may not be integrated into the processor 301 and may be implemented separately by a single chip.
[0103] Among them, the memory 305 may include random access memory (RAM) and may also include read-only memory. Optionally, the memory 305 includes a non-transitory computer-readable storage medium. The memory 305 can be used to store instructions, programs, code, code sets, or instruction sets. The memory 305 may include a program storage area and a data storage area. Among them, the program storage area may store instructions for implementing the operating system, instructions for at least one function (such as touch function, sound playback function, image playback function, etc.), instructions for implementing the above-mentioned various method embodiments, etc.; the data storage area may store the data involved in the above-mentioned various method embodiments. Optionally, the memory 305 may also be at least one storage device located far from the aforementioned processor 301. Refer to Figure 3 , in the memory 305 as a computer storage medium, there may be included an operating system, a network communication module, a user interface module, and an application program for a wear leveling method of a solid-state drive.
[0104] In Figure 3In the electronic device 300 shown, the user interface 303 is mainly used to provide an interface for the user to input and obtain the data input by the user. The processor 301 can be used to call the application program stored in the memory 305 for a wear leveling method of a solid state drive. When executed by one or more processors 301, the electronic device 300 is caused to execute the method of one or more of the above embodiments. It should be noted that, for the foregoing method embodiments, for simplicity of description, they are all expressed as a series of action combinations. However, those skilled in the art should know that this application is not limited by the described order of actions, because according to this application, some steps can be in other orders or performed simultaneously. Secondly, those skilled in the art should also know that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily essential to this application.
[0105] In the above embodiments, the descriptions of the respective embodiments have their own emphases. For the parts not detailed in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0106] In several implementation manners provided by this application, it should be understood that the disclosed device can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of units is only a logical function division. In actual implementation, there can be other division methods. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed couplings or direct couplings or communication connections to each other can be through some service interfaces. The indirect couplings or communication connections of the devices or units can be in electrical or other forms.
[0107] The units described as separate components may or may not be physically separated. The components shown as units may or may not be physical units, that is, they can be located in one place, or can be distributed to multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0108] In addition, in each embodiment of this application, the functional units can be integrated into one processing unit, or each unit can exist physically alone, or two or more units can be integrated into one unit. The above integrated units can be implemented in the form of hardware or in the form of software functional units.
[0109] When the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable memory. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of this technical solution, can be embodied in the form of a software product. This computer software product is stored in a memory and includes several instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods of various embodiments of this application. The aforementioned memory includes: various media such as USB flash drives, mobile hard disks, magnetic disks, or optical discs that can store program codes.
[0110] The above are only exemplary embodiments of the present disclosure and should not be used to limit the scope of the present disclosure. That is, any equivalent changes and modifications made in accordance with the teachings of the present disclosure still fall within the scope covered by the present disclosure. Those skilled in the art will readily think of other implementation schemes of the present disclosure after considering the specification and the practice of the disclosure.
[0111] This application aims to cover any variations, uses, or adaptive changes of the present disclosure that follow the general principles of the present disclosure and include common general knowledge or conventional technical means in the technical field not recorded in the present disclosure. The specification and the embodiments are only regarded as exemplary.
Claims
1. A wear leveling method for a solid state drive, characterized in that Including: Obtaining access characteristic data of each data block in multiple hard disk regions; In each of the hard disk regions, based on the access characteristic data of each data block, determining the read-write ratio of the corresponding data block within a preset time window, and determining the corresponding data block as a read-priority block or a write-priority block according to each read-write ratio; Obtaining the quantity ratio of read-priority blocks to write-priority blocks in each hard disk region, and when the quantity ratio of any hard disk region exceeds the preset ratio range, determining the corresponding hard disk region as a region to be balanced; Selecting the write-priority block with the most erase-write times as the first target block from the region to be balanced, and selecting the read-priority block with the least erase-write times from the remaining hard disk regions as the second target block; Migrating the data in the first target block to the second target block; The determining the corresponding data block as a read-priority block or a write-priority block according to each read-write ratio includes: Based on the read-write ratios of each data block in the hard disk region, calculating the concentration eigenvalue of the read-write ratios, and determining the dynamic classification threshold according to the concentration eigenvalue; When the read-write ratio is greater than or equal to the dynamic classification threshold, taking the corresponding data block as a read-priority block, and when the read-write ratio is less than the dynamic classification threshold, taking the corresponding data block as a write-priority block; The calculating the concentration eigenvalue of the read-write ratios based on the read-write ratios of each data block in the hard disk region includes: Calculating the arithmetic mean of the read-write ratios of each data block in the hard disk region; Determining the deviation value between each read-write ratio and the arithmetic mean; Based on each deviation value, performing weighted correction on the arithmetic mean, and determining the corrected arithmetic mean as the concentration eigenvalue.
2. The wear leveling method of the solid state drive according to claim 1, characterized in that The determining the read-write ratio of the corresponding data block within a preset time window based on the access characteristic data of each data block includes: Extracting the read times and write times of the corresponding data block within the preset time window from each access characteristic data; Based on each read time and the duration corresponding to the preset time window, calculating the read frequency of the corresponding data block, and based on each write time and the duration corresponding to the preset time window, calculating the write frequency of the corresponding data block; Taking the ratio between the read frequency and the write frequency of each data block as the read-write ratio of the corresponding data block.
3. The wear leveling method of the solid state drive according to claim 1, characterized in that, The migrating the data in the first target block to the second target block includes: Obtaining the data volume to be migrated of the first target block and the available storage capacity of the second target block; When the data volume to be migrated is less than or equal to the available storage capacity, writing the data in the first target block into the second target block; When the data volume is greater than the available storage capacity, selecting at least one read-priority block with the largest available storage capacity from the remaining hard disk regions as the backup target block; Writing the data exceeding the available storage capacity of the second target block into the backup target block; Updating the address mapping relationship between the first target block, the second target block, and the backup target block.
4. The wear leveling method of the solid state drive according to claim 3, wherein The updating the address mapping relationship between the first target block, the second target block, and the backup target block includes: Obtain the original logical address corresponding to the first target block; Delete the mapping relationship between the original logical address and the physical addresses of the first target block and the spare target block in the address mapping table; According to the written data in the second target block and the spare target block, map the original logical address to the physical addresses corresponding to the second target block and the spare target block respectively.
5. The wear leveling method of the solid state drive according to claim 4, characterized in that, The step of mapping the original logical address to the physical addresses corresponding to the second target block and the spare target block respectively according to the written data in the second target block and the spare target block includes: Calculate the first relative offset of the written data in the second target block and the second relative offset of the written data in the spare target block; In the original logical address, determine the first address segment corresponding to the first relative offset and the second address segment corresponding to the second relative offset; Map the first address segment to the physical address of the second target block, and map the second address segment to the physical address of the spare target block.
6. A wear leveling system for a solid state drive, characterized in that, The system includes: A data acquisition module, configured to acquire access feature data of each data block in multiple hard disk areas; A priority block determination module, configured to, in each of the hard disk areas, based on the access feature data of each data block, determine the read-write ratio of the corresponding data block within a preset time window, and determine the corresponding data block as a read-priority block or a write-priority block according to each read-write ratio; A region determination module, configured to acquire the quantity ratio of the read-priority blocks and the write-priority blocks in each hard disk area, and when the quantity ratio of any hard disk area exceeds a preset ratio range, determine the corresponding hard disk area as an area to be balanced; A data migration module, configured to select the write-priority block with the most erase-write times in the area to be balanced as the first target block, and select the read-priority block with the least erase-write times from the remaining hard disk areas as the second target block; migrate the data in the first target block to the second target block; The step of determining the corresponding data block as a read-priority block or a write-priority block according to each read-write ratio includes: Based on the read-write ratios of the data blocks in the hard disk area, calculate the concentration characteristic value of the read-write ratios, and determine the dynamic classification threshold according to the concentration characteristic value; When the read-write ratio is greater than or equal to the dynamic classification threshold, use the corresponding data block as a read-priority block, and when the read-write ratio is less than the dynamic classification threshold, use the corresponding data block as a write-priority block; The step of calculating the concentration characteristic value of the read-write ratios based on the read-write ratios of the data blocks in the hard disk area includes: Calculate the arithmetic mean of the read-write ratios of the data blocks in the hard disk area; Determine the deviation value between each read-write ratio and the arithmetic mean; Based on each deviation value, perform weighted correction on the arithmetic mean, and determine the corrected arithmetic mean as the concentration characteristic value.
7. An electronic device, characterized in that, It includes a processor, a memory, a user interface and a network interface. The memory is used to store instructions. The user interface and the network interface are used to communicate with other devices. The processor is used to execute the instructions stored in the memory so that the electronic device executes the wear leveling method of the solid state drive as described in any one of claims 1-5.
8. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores instructions which, when executed, execute the wear leveling method of the solid state drive as described in any one of claims 1-5.
Citation Information
Patent Citations
Systems and methods for storage recovery
US20160188219A1
Storage system and operating method thereof
US20250077104A1