Wear balance method and device, electronic equipment and storage medium
By using the physical aging factor and data heat factor in the Flash memory to determine the degree of wear and selecting the physical block with less wear for data writing, the problem of limited erase times of the Flash memory is solved, and the reasonable management of the memory and the extension of its service life are achieved.
Patent Information
- Application Number
- CN202510755260.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-06
- Publication Date
- 2025-09-26
AI Technical Summary
The Flash memory has a limited number of erase cycles. Exceeding the maximum erase cycle will reduce the stability and reliability of data storage and shorten its service life.
The wear degree of each idle physical block is determined by the physical aging factor and the data heat factor. The physical block with low wear degree is selected as the target physical block for data writing. When necessary, data migration and exchange are performed to balance the wear degree of each physical block in the memory.
It realizes the reasonable management of memory, improves the stability and reliability of data storage, and extends the service life of memory.
Smart Images

Figure CN120704597A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of storage technology, and are related to but not limited to a wear leveling method, device, electronic device, and storage medium. Background Art
[0002] Flash memory is a commonly used non-volatile memory (hereinafter referred to as Flash memory) and is widely used in consumer electronics, mobile devices, and other fields. Because Flash memory has a limited storage capacity, in most cases, an erase operation is required before data can be written to free up storage space.
[0003] However, each Flash memory has a limited number of erase cycles. Exceeding this maximum erase cycle not only reduces the stability and reliability of data storage but also damages the Flash memory, shortening its lifespan. Therefore, managing the memory and extending its lifespan remains a technical challenge. Summary of the Invention
[0004] In view of this, an embodiment of the present application provides a wear leveling method, device, electronic device, and storage medium, which can reasonably manage the memory and extend its service life.
[0005] An embodiment of the present application provides a wear leveling method, the method comprising:
[0006] Determining a degree of wear of each of the plurality of idle physical blocks of the memory according to a physical aging factor and a data heat factor corresponding to each of the idle physical blocks, wherein the physical aging factor is used to indicate an aging degree of the physical block, and the data heat factor is used to indicate a data heat characteristic of a logical block corresponding to the physical block;
[0007] Determining at least one free physical block that meets a preset condition among the plurality of free physical blocks as a target physical block, wherein the wear degree of the free physical block that meets the preset condition is lower than the wear degree of the free physical blocks that do not meet the preset condition;
[0008] The data to be written is written into the target physical block.
[0009] In the above embodiment, before writing data, the degree of wear of each physical block is determined by multiple factors (physical aging factor and data heat factor) of each physical block, and the physical block with low wear is used as the target physical block to write the data to be written. This method comprehensively considers the factors affecting the physical block from multiple dimensions, that is, the degree of wear of each physical block can be determined more accurately through the aging degree of the physical block and the data heat characteristics of the logical block corresponding to the physical block, so that data is written to the physical block with lower wear, and data is avoided from being written to the physical block with high wear. In other words, when writing data, the wear degree of each physical block in the memory is balanced, the data writing pressure of each physical block is dispersed, and some physical blocks are avoided from being excessively worn, thereby realizing reasonable management of the memory, improving the stability and reliability of data storage, and helping to extend the service life of the memory.
[0010] In some embodiments, the physical aging factor is determined based on at least one of a historical number of erase times of the physical block, an operating temperature, and a supply voltage fluctuation.
[0011] In the above embodiment, affected by the physical characteristics of the memory, the historical number of erase times, operating temperature and power supply voltage fluctuations will affect the reliability of data storage of each physical block in the memory, as well as its service life. Therefore, the aging degree of the physical block is determined by at least one of the historical number of erase times, operating temperature and power supply voltage fluctuations, and the aging degree of each physical block is accurately judged and dynamically evaluated from multiple angles, thereby improving the accuracy of determining the wear degree of the physical block.
[0012] In some embodiments, the data heat factor is determined based on at least one of the cold-hot data ratio of the logical block corresponding to the physical block and the update frequency of the logical block, the cold-hot data ratio includes a cold data ratio and a hot data ratio, the cold data ratio is the ratio of cold data in the data corresponding to the logical block, and the hot data ratio is the ratio of hot data in the data corresponding to the logical block.
[0013] In the above embodiment, the memory writes data to the associated physical blocks through logical blocks. Since the hot and cold data ratio of the logical blocks corresponding to each physical block reflects the proportion of different types of data (cold data and hot data), and since hot data is usually updated frequently and cold data is usually updated and modified less frequently, the hot and cold data ratio reflects, to a certain extent, the frequency with which the data corresponding to the logical block is read and written. At the same time, the update frequency also reflects, to a certain extent, the frequency with which new data is written to the logical block. Therefore, accurate judgment and dynamic evaluation of the data heat characteristics of the logical blocks corresponding to each physical block are achieved from multiple angles, thereby improving the accuracy of determining the degree of wear of the physical blocks.
[0014] In some embodiments, the method further comprises:
[0015] determining a degree of wear of each physical block among a plurality of physical blocks of the memory according to a physical aging factor and a data heat factor corresponding to each physical block;
[0016] According to the wear degree of each physical block, a data migration operation and / or a data exchange operation is performed on the data stored in the plurality of physical blocks, wherein:
[0017] The data migration operation is: migrating hot data stored in at least one non-free physical block with a wear level higher than a first threshold to at least one free physical block with a wear level lower than a second threshold, and / or migrating cold data stored in at least one non-free physical block with a wear level lower than the second threshold to at least one free physical block with a wear level higher than the first threshold;
[0018] The data exchange operation is to exchange hot data stored in at least one non-idle physical block whose wear level is higher than a first threshold with cold data stored in at least one non-idle physical block whose wear level is lower than a second threshold;
[0019] The first threshold is greater than the second threshold.
[0020] In the above embodiment, based on the wear level of each physical block, the data stored in multiple physical blocks are migrated and / or exchanged between different physical blocks from the perspective of the entire memory. The data storage location can be adjusted according to actual conditions to avoid failure of certain physical blocks due to excessive wear. This method is conducive to balancing the wear level of each physical block in the memory. Wear balancing can make the wear level of each physical block as uniform as possible, avoid premature damage of certain physical blocks and lead to waste of storage resources, realize dynamic management of storage resources, and help improve the overall performance of the memory and extend the service life of the memory.
[0021] In some embodiments, determining at least one idle physical block that meets a preset condition among the plurality of idle physical blocks as a target physical block includes:
[0022] Determine the idle physical block with the lowest wear level among the plurality of idle physical blocks as the target physical block; or,
[0023] At least one free physical block with a wear level less than a preset threshold among the plurality of free physical blocks is determined as the target physical block.
[0024] In the above embodiment, when determining the target physical block, an idle physical block with the lowest wear level can be determined as the target physical block, or an idle physical block with a wear level less than a preset threshold can be determined as the target physical block. That is to say, one physical block can be selected to write data, or one or more physical blocks with a wear level less than the preset threshold can be selected to write data, thereby improving the flexibility when writing data.
[0025] In some embodiments, after writing the data to be written into the target physical block, the method further includes:
[0026] At least one of a historical erase count, an operating temperature, and a supply voltage fluctuation of the target physical block is updated.
[0027] In the above embodiment, since the erase count, operating temperature and power supply voltage fluctuations will affect the wear degree of the physical block, after the data to be written is written into the target physical block, at least one of the historical erase count, operating temperature and power supply voltage fluctuations of the target physical block can also be updated in real time. By updating these parameters in real time, it is helpful to timely evaluate the aging degree of the target physical block.
[0028] In some embodiments, when the number of erasure times of the physical block is greater than or equal to a third threshold, the number of erasure times of the physical block is encoded using a logarithmic encoding method.
[0029] In the above embodiment, the number of erasures of each physical block needs to be stored. When the number of erasures of the physical block is higher than the preset third threshold, it indicates that the number of erasures of the physical block is high. In this case, the number of erasures of the physical block can be stored in a logarithmic encoding manner. Since the logarithmic encoding method can reduce the data length occupied when storing the number of erasures, it means that each time the erase count is updated, the storage space and write time occupied by storing the number of erasures are reduced, which not only reduces the wear on the physical block, but also improves the storage efficiency. Therefore, dynamically adjusting the encoding method based on the number of erasures further balances the degree of wear of each physical block in the memory.
[0030] In some embodiments, the data heat factor includes a hot data factor, a warm data factor or a cold data factor, and the multiple physical blocks of the memory have a mapping relationship with the multiple logical blocks, the multiple logical blocks include a logical block with the hot data factor, a logical block with the warm data factor and a logical block with the cold data factor, the multiple physical blocks include an old physical block, a middle-aged physical block and a young physical block, the logical block with the hot data factor corresponds to the young physical block, the logical block with the warm data factor corresponds to the middle-aged physical block, the logical block with the cold data factor corresponds to the old physical block, the wear degree of the old physical block is higher than that of the middle-aged physical block, and the wear degree of the middle-aged physical block is higher than that of the young physical block.
[0031] In the above embodiment, through the mapping relationship between multiple physical blocks and multiple logical blocks, hot data is preferentially stored in younger physical blocks with the lowest degree of wear, reducing unnecessary erase and read and write operations, and avoiding hot data from being stored in older physical blocks with higher degrees of wear, thereby reducing the degree of wear of older physical blocks. This method optimizes the allocation of storage resources, is conducive to balancing the degree of wear of each physical block in the memory, and extends the service life of the memory.
[0032] An embodiment of the present application provides a wear leveling device, the device comprising:
[0033] a processing module, configured to determine a degree of wear of each of a plurality of idle physical blocks of a memory based on a physical aging factor and a data heat factor corresponding to each of the idle physical blocks, wherein the physical aging factor is used to indicate an aging degree of the physical block, and the data heat factor is used to indicate a data heat characteristic of a logical block corresponding to the physical block;
[0034] The processing module is further configured to determine at least one idle physical block among the plurality of idle physical blocks that meets a preset condition as a target physical block, wherein the wear level of the idle physical block that meets the preset condition is lower than the wear level of the idle physical blocks that do not meet the preset condition;
[0035] The writing module is used to write the data to be written into the target physical block.
[0036] An electronic device provided in an embodiment of the present application includes a memory and a processor, wherein the memory stores a computer program that can be run on the processor, and when the processor executes the program, the method described in the embodiment of the present application is implemented.
[0037] The computer-readable storage medium provided in the embodiment of the present application stores a computer program thereon, and when the computer program is executed by a processor, the method described in the embodiment of the present application is implemented.
[0038] The computer program product provided in the embodiments of the present application includes a computer program, which implements the method described in the embodiments of the present application when executed by a processor. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] The drawings herein are incorporated into and constitute a part of the specification. These drawings illustrate embodiments consistent with the present application and, together with the specification, are used to illustrate the technical solutions of the present application.
[0040] Figure 1 is a flow chart of a wear leveling method disclosed in an embodiment of the present application;
[0041] Figure 2 is a flow chart of another wear leveling method disclosed in an embodiment of the present application;
[0042] Figure 3 is a flow chart of another wear leveling method disclosed in an embodiment of the present application;
[0043] Figure 4 is a flow chart of another wear leveling method disclosed in an embodiment of the present application;
[0044] Figure 5 1 is a flow chart of another wear leveling method disclosed in an embodiment of the present application;
[0045] Figure 6 It is a structural schematic diagram of a wear leveling device disclosed in an embodiment of the present application;
[0046] Figure 7 This is a structural diagram of an electronic device disclosed in an embodiment of the present application. DETAILED DESCRIPTION
[0047] To make the purpose, technical solutions and advantages of the embodiments of the present application clearer, the specific technical solutions of the present application will be further described in detail below in conjunction with the drawings in the embodiments of the present application. The following embodiments are used to illustrate the present application but are not intended to limit the scope of the present application.
[0048] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by those skilled in the art to which this application pertains. The terms used herein are for the purpose of describing the embodiments of this application only and are not intended to limit this application.
[0049] In the following description, reference is made to “some embodiments”, which describes a subset of all possible embodiments, but it will be understood that “some embodiments” may be the same subset or different subsets of all possible embodiments and may be combined with each other without conflict.
[0050] It should be pointed out that the terms "first\second\third" involved in the embodiments of the present application are used to distinguish similar or different objects, and do not represent a specific ordering of the objects. It can be understood that "first\second\third" can be interchanged with a specific order or sequence where permitted, so that the embodiments of the present application described here can be implemented in an order other than that illustrated or described here.
[0051] Flash memory is a commonly used non-volatile memory (hereinafter referred to as Flash memory) with advantages such as low power consumption, large capacity, compact size, light weight, and high access speed. It has been widely used in consumer electronics, mobile devices, and other fields. Common Flash memory operations include reading, writing, and erasing data. Due to the limited storage capacity of Flash memory, write operations can only be performed within free or erased physical blocks. Therefore, in most cases, an erase operation is required before data is written to free up free physical blocks for data storage. For example, before writing data to a physical block, an erase operation must be performed on that physical block.
[0052] However, each Flash memory has a limited number of erase cycles, meaning each physical block also has a limited number of erase cycles. For example, there are only 1,000 valid erase cycles. If the number of erase operations exceeds this number, not only will the stability and reliability of data storage in each physical block be reduced, but the Flash memory will also be easily damaged, shortening its lifespan. Therefore, managing the memory and extending its lifespan remains a technical challenge that needs to be addressed.
[0053] In view of this, an embodiment of the present application provides a wear leveling method, device, electronic device, and storage medium, the method comprising: determining the degree of wear of each idle physical block according to the physical aging factor and data heat factor corresponding to each idle physical block in a plurality of idle physical blocks of a memory, wherein the physical aging factor is used to indicate the degree of aging of the physical block, and the data heat factor is used to indicate the data heat characteristics of the logical block corresponding to the physical block; determining at least one idle physical block that meets a preset condition among the plurality of idle physical blocks as a target physical block, wherein the degree of wear of the idle physical block that meets the preset condition is lower than the degree of wear of the idle physical block that does not meet the preset condition; and writing the data to be written into the target physical block. The embodiment of the present application realizes the reasonable management of the memory, improves the stability and reliability of data storage, and is conducive to extending the service life of the memory.
[0054] A wear leveling method provided in an embodiment of the present application is applied to an electronic device, which may be a mobile phone, a tablet computer, a laptop computer, a mobile internet device (MID), a wearable device, a virtual reality (VR) device, an augmented reality (AR) device, a headset, a terminal in industrial control, a terminal in self-driving, a personal digital assistant (PDA), etc., but the embodiment of the present application is not limited to this.
[0055] In the embodiments of the present application, an electronic device includes a memory. The memory may include a non-volatile memory such as a Flash memory, for example, a solid-state drive, a flash drive, an SD card, a memory card, etc. It should be noted that the number of memories included in the electronic device may be one or more, and this application does not impose any limitation on this.
[0056] Memory consists of multiple physical blocks, which are the actual physical units for data storage within the memory. A physical block typically contains multiple physical pages, each of which is the smallest unit for data writing. As you can see, the memory's storage space is composed of multiple physical blocks, which are used to store written data. Therefore, before writing data, the erase operation targets the physical blocks.
[0057] Each physical block has a limited number of erase cycles. For example, physical blocks exist in multiple modes (e.g., single-layer cell mode and multi-layer cell mode). Physical blocks in the single-layer cell mode have a write / erase cycle of approximately 100,000 cycles, characterized by fast transmission speeds, low power consumption, long lifespan, and stable performance. Physical blocks in the multi-layer cell mode have a write / erase cycle of approximately 3,000 to 10,000 cycles. Compared to physical blocks in the single-layer cell mode, they have slower transmission speeds, higher power consumption, a shorter storage cell lifespan, and higher storage density.
[0058] The memory also includes multiple logical blocks, which divide the physical storage space into logically continuous blocks. The main function of the logical block is to provide a unified interface so that the data in the memory can be easily managed and the data can be written to the physical block associated with the logical block through the logical address of the logical block.
[0059] In the embodiments of the present application, each logical block corresponds to one or more physical blocks. It is understood that the size of a logical block is generally the same as the size of a physical block, or may be an integer multiple of the size of a physical block. For example, if data from a logical block needs to be written to multiple physical blocks, the correspondence between the logical blocks and the physical blocks is recorded through a mapping relationship so that the data can be written to the associated physical blocks.
[0060] In the embodiment of the present application, the erasing operation of the physical block can be before data is written, or when the memory is initially formatted, or when the memory performs garbage collection. The present application does not limit the execution scenario of the erasing operation. For ease of understanding, the process of storing data in the memory is explained by example. For example, before writing data, the corresponding target physical block is found according to the identifier of the logical block. If the target physical block has data written, garbage collection is required first to move the valid data to other free physical blocks. Then, the target physical block is erased to restore all storage units of the target physical block to their initial state. Finally, the data is written to the target physical block in units of pages.
[0061] It should be noted that, in addition to the memory, the electronic device of the embodiment of the present application may also include more modules, or combine certain modules, or separate certain modules. Other modules may be implemented in hardware, software, or a combination of software and hardware, and this application does not limit this.
[0062] In order to make the purpose and technical solution of this application clearer and more intuitive, the wear leveling method, device, electronic device and storage medium disclosed in this application are described below in conjunction with the accompanying drawings.
[0063] See Figure 1 , Figure 1 FIG. 1 is a flow chart of a wear leveling method disclosed in an embodiment of the present application. Figure 1 The method shown may include the following steps:
[0064] In step 101 , the electronic device determines the wear degree of each idle physical block in a memory according to a physical aging factor and a data heat factor corresponding to each idle physical block.
[0065] In the embodiment of the present application, the memory includes multiple physical blocks, which include multiple idle physical blocks and multiple non-idle physical blocks. It is understood that the idle physical blocks indicate that there is storage space for writing data, while the non-idle physical blocks indicate that there is no storage space for writing data.
[0066] In an embodiment of the present application, after the memory receives a data write request, the electronic device can determine the target physical block among multiple free physical blocks to write the data based on the degree of wear of each free physical block in the memory, wherein the data write request is used to indicate that the data to be written is written into the memory.
[0067] In an embodiment of the present application, an electronic device can obtain a physical aging factor corresponding to each of a plurality of idle physical blocks. The physical aging factor is used to indicate the degree of aging of the physical block. It is understood that each physical block will wear out during use due to read / write operations, erase operations, etc. This wear increases the aging rate of the physical block, thereby affecting the service life of the physical block.
[0068] In an embodiment of the present application, the electronic device may obtain a data heat factor corresponding to each of a plurality of idle physical blocks, where the data heat factor is used to represent a data heat characteristic of a logical block corresponding to the physical block.
[0069] Data characteristics are typically reflected through the storage of hot and cold data. Hot data refers to frequently updated data, such as system logs, caches, and database indexes. Cold data refers to less frequently updated or rarely accessed data, such as archived files and static data. For example, in a database system, current business data that users frequently query and update is considered hot data, while historical records and archived data, which may not be modified or queried for a long time, are considered cold data. Another example is that in a file storage system, documents that users frequently open and edit are considered hot data, while older versions of documents that are rarely viewed are considered cold data.
[0070] It can be understood that when the data heat characteristics of the logical block corresponding to the physical block indicate that the corresponding data is hot data, it means that the data of the physical block is frequently accessed, and frequent access will cause wear, which will increase the aging degree of the physical block and thus affect the service life of the physical block.
[0071] In the embodiment of the present application, the physical aging factor and data heat factor corresponding to each idle physical block are both intended to reflect the degree of wear of each idle physical block. For example, when the physical aging factor is high and the data heat factor is high, it indicates that the physical block has a high degree of wear; conversely, when the physical aging factor is low and the data heat factor is low, it indicates that the physical block has a low degree of wear.
[0072] In step 102, the electronic device determines at least one idle physical block among a plurality of idle physical blocks that meets a preset condition as a target physical block, wherein the wear degree of the idle physical block that meets the preset condition is lower than the wear degree of the idle physical block that does not meet the preset condition.
[0073] In the embodiment of the present application, the wear level of the idle physical blocks that meet the preset conditions is lower than the wear level of the idle physical blocks that do not meet the preset conditions. That is, the idle physical blocks with lower wear levels are used as target physical blocks.
[0074] In some embodiments, the preset condition may include determining the idle physical block with the lowest wear level among the plurality of idle physical blocks as the target physical block. It is understood that in this embodiment, the wear levels of other physical blocks with higher wear levels than the target physical block may be reduced.
[0075] It should be noted that there may be physical blocks with the same degree of wear in the memory, that is, there may be one or more free physical blocks with the lowest degree of wear.
[0076] In some embodiments, the preset condition may include determining, as the target physical block, an idle physical block among a plurality of idle physical blocks whose wear level is below a wear level threshold. It will be appreciated that, in this embodiment, the wear level of other physical blocks exceeding the wear level threshold may be reduced. The wear level threshold may be any preset value and is not limited in this application.
[0077] In some embodiments, the preset condition may include determining, among a plurality of idle physical blocks, an idle physical block with a wear level most within a preset wear level range as the target physical block. It will be appreciated that in this embodiment, the wear level of other physical blocks that are not within the preset wear level range may be reduced. The preset wear level range may be any preset range and is not limited in this application.
[0078] It should be noted that any of the above preset conditions can be used as an implementation method for determining the target physical block, and this application does not limit this.
[0079] Step 103: The electronic device writes the data to be written into the target physical block.
[0080] In the embodiment of the present application, after the target physical block is determined, the data to be written is written into the target physical block, thereby completing the writing of the data.
[0081] It can be seen that when the above embodiment is implemented, before writing data, the degree of wear of each physical block is determined by multiple factors of each physical block (physical aging factor and data heat factor), and the physical block with low wear is used as the target physical block to write the data to be written. This method comprehensively considers the factors affecting the physical block from multiple dimensions, that is, the degree of wear of each physical block can be determined more accurately through the aging degree of the physical block and the data heat characteristics of the logical block corresponding to the physical block, so that data is written to the physical block with lower wear, and data is avoided from being written to the physical block with high wear. In other words, when writing data, the degree of wear of each physical block in the memory is balanced, the data writing pressure of each physical block is dispersed, and some physical blocks are avoided from being excessively worn, thereby realizing reasonable management of the memory, improving the stability and reliability of data storage, and helping to extend the service life of the memory.
[0082] In some embodiments, the preset condition includes determining a free physical block with the lowest wear level as the target physical block. Figure 2 , Figure 2 FIG. 1 is a flow chart of another wear leveling method disclosed in an embodiment of the present application. Figure 2 The method shown may include the following steps:
[0083] In step 201 , the electronic device determines the wear degree of each idle physical block in a memory according to a physical aging factor and a data heat factor corresponding to each idle physical block.
[0084] In some embodiments, the physical aging factor is determined based on at least one of a historical erase count of the physical block, an operating temperature, and a supply voltage fluctuation.
[0085] Each physical block has a limited number of erase cycles. Therefore, the historical erase cycle count of each idle physical block is one of the indicators for measuring the aging of the corresponding physical block. For example, in Flash memory, due to the physical characteristics of Flash memory, each physical block of the memory has a limited erase durability. Typically, after thousands to tens of thousands of erase operations, the insulation layer and floating gate structure of the physical block will gradually degrade. This degradation will cause the threshold voltage of the physical block to drift, reducing the accuracy of read and write operations, and thus affecting data stability. As the number of erase cycles increases, the oxide layer of the physical block will also gradually damage, reducing the effective charge in the floating gate, thereby reducing the reliability and service life of the physical block.
[0086] The operating temperature of a physical block also significantly affects its aging. For example, in Flash memory, high temperatures accelerate chemical reactions and physical degradation processes within the memory. High temperatures can lead to thermal leakage of charge, changes in conductivity, accelerated aging and oxidation of the insulating layer, and thermal expansion, causing structural stress changes within the physical block. Low temperatures, on the other hand, can cause threshold voltage drift and physical brittleness. These factors, combined, make the physical block more susceptible to failure, increase data error rates, and thus reduce the overall reliability of the memory.
[0087] Optionally, the operating temperature of each idle physical block may be collected through a built-in temperature sensor.
[0088] Fluctuations in the physical block's supply voltage also significantly impact its aging. For example, in Flash memory, long-term data retention relies on the stability of the floating gate charge. Voltage fluctuations can accelerate charge leakage and data inversion, leading to decreased storage stability and data loss. For example, during a write operation, unstable voltage can cause the physical block to experience excessively high electric field strength, accelerating transistor degradation. Furthermore, voltage fluctuations can trigger electron migration, where carriers move through the medium under the influence of a high electric field, causing permanent changes in the material structure. These changes can gradually degrade the performance of the physical block, increase the error rate of data writes and reads, and ultimately lead to premature failure of the physical block.
[0089] In this embodiment, the above-mentioned factors affecting the aging degree of the physical block are all physical factors. That is, the aging degree of each idle physical block can be comprehensively determined from the dimensions of the number of erase times, structure, material, etc. based on at least one of the key physical factors affecting the aging factors of the physical block (the historical number of erase times of the physical block, the operating temperature and the power supply voltage fluctuation).
[0090] It can be understood that the physical aging factor can be determined based on the historical number of erasures of the physical block, or based on the operating temperature of the physical block, or based on the power supply voltage fluctuation of the physical block, or based on the historical number of erasures of the physical block and the operating temperature, or based on the historical number of erasures of the physical block and the power supply voltage fluctuation, or based on the operating temperature of the physical block and the power supply voltage fluctuation, or based on the historical number of erasures of the physical block, the operating temperature and the power supply voltage fluctuation.
[0091] With this implementation, influenced by the physical characteristics of the memory, the historical number of erase times, operating temperature, and power supply voltage fluctuations all affect the data storage reliability and service life of each physical block in the memory. Therefore, the degree of aging of the physical block is determined by at least one of the historical number of erase times, operating temperature, and power supply voltage fluctuations, thereby achieving accurate judgment and dynamic evaluation of the aging degree of each physical block from multiple perspectives, thereby improving the accuracy of determining the degree of wear of the physical block.
[0092] In some embodiments, at least one of the historical erase counts, operating temperature, and power supply voltage fluctuations of each idle physical block can be input into a target life prediction model to obtain a physical aging factor corresponding to each idle physical block, wherein the target life prediction model is obtained by training a preset life prediction model based on sample data, and the sample data includes the relationship between at least one of the historical erase counts, operating temperature, and power supply voltage fluctuations of each physical block and the corresponding physical aging factor.
[0093] Exemplarily, the target life prediction model is: Li=α×ECi+β×Tavg,i+γ×Vdev,i.
[0094] Where Li represents the physical aging factor; ECi represents the historical number of erases; Tavg,i represents the average operating temperature; Vdev,i represents the supply voltage fluctuation variance; i represents a physical block, α, β, and γ represent the weights corresponding to the historical number of erases, operating temperature, and supply voltage fluctuation, respectively. α, β, and γ can be arbitrarily set constants.
[0095] In some embodiments, the data heat factor includes a hot data factor, a warm data factor, or a cold data factor. The multiple logic blocks of the memory include logic blocks with hot data factors, logic blocks with warm data factors, and logic blocks with cold data factors. It can be understood that the wear degree of the physical blocks corresponding to the logic blocks with different types of data heat factors is different, and the wear degree of the physical blocks corresponding to the logic blocks with hot data factors, the logic blocks with warm data factors, and the logic blocks with cold data factors decrease in sequence. That is to say, the logic blocks are divided into different logic blocks according to the different data heat factors. For example, a certain memory includes 100 logic blocks, which are divided into three types of logic blocks, of which 30 logic blocks are logic blocks with hot data factors, 20 are logic blocks with warm data factors, and 50 are logic blocks with cold data factors.
[0096] In some embodiments, the data heat factor is determined based on at least one of the ratio of cold data to hot data of the logical block corresponding to the physical block and the update frequency of the logical block, wherein the ratio of cold data to hot data includes a cold data ratio and a hot data ratio, the cold data ratio is the ratio of cold data in the data corresponding to the logical block, and the hot data ratio is the ratio of hot data in the data corresponding to the logical block.
[0097] In this implementation, a higher cold data ratio indicates a higher proportion of cold data in the data corresponding to the logical block. Since cold data is not frequently updated, a higher cold data ratio indicates a lower degree of wear on the corresponding physical block. Conversely, a higher hot data ratio indicates a higher proportion of hot data in the data corresponding to the logical block. Since hot data is frequently updated, a higher hot data ratio indicates a higher degree of wear on the corresponding physical block.
[0098] In this embodiment, the update frequency of the logical block indicates how frequently new data is written to the logical address or updated data, that is, the update frequency of the data. Since data must be accessed and modified through the logical block, the update frequency of the logical block also reflects, to a certain extent, the degree of wear of the corresponding physical block. The higher the update frequency of the logical block, the higher the degree of wear of the corresponding physical block; conversely, the lower the update frequency of the logical block, the lower the degree of wear of the corresponding physical block.
[0099] In this implementation, the memory writes data to associated physical blocks via logical blocks. Since the hot and cold data ratio of the logical blocks corresponding to each physical block reflects the proportions of different types of data (cold data and hot data), and since hot data is typically updated frequently and cold data is seldom updated or modified, the hot and cold data ratio reflects, to a certain extent, the frequency with which the data corresponding to the logical block is read and written. At the same time, the update frequency also reflects, to a certain extent, the frequency with which new data is written to the logical block. Therefore, accurate judgment and dynamic evaluation of the data heat characteristics of the logical blocks corresponding to each physical block are achieved from multiple perspectives, thereby improving the accuracy of determining the degree of wear of the physical blocks.
[0100] Alternatively, a data heat factor can be determined based on the ratio of hot and cold data in the logical block corresponding to each free physical block to determine the data heat characteristics of the logical block corresponding to each free physical block, thereby determining the degree of wear of each free physical block. In other words, the logical blocks are divided into different logical blocks based on the ratio of hot and cold data.
[0101] It can be understood that a logic block in which the hot data ratio is higher than the cold data ratio in the hot and cold data ratio is a logic block with a hot data factor, a logic block in which the hot data ratio and the cold data ratio are approximately the same in the hot and cold data ratio is a logic block with a warm data factor, and a logic block in which the cold data ratio is higher than the hot data ratio in the hot and cold data ratio is a logic block with a cold data factor.
[0102] Exemplarily, a first hot data ratio threshold and a second hot data ratio threshold are pre-set, and the first hot data ratio threshold is greater than the second hot data ratio threshold; the data heat factor corresponding to the logical block whose hot data ratio in the hot and cold data ratio of the logical block corresponding to the physical block is greater than the first hot data ratio threshold is determined as the hot data factor, that is, the logical block with the hot data factor is determined; the data heat factor corresponding to the logical block whose hot data ratio in the hot and cold data ratio of the logical block corresponding to the physical block is greater than the second hot data ratio threshold and less than the first hot data ratio threshold is determined as the warm data factor, that is, the logical block with the warm data factor is determined; the data heat factor corresponding to the logical block whose hot data ratio in the hot and cold data ratio of the logical block corresponding to the physical block is less than the second hot data ratio threshold is determined as the cold data factor, that is, the logical block with the cold data factor is determined.
[0103] It should be noted that the type of the data heat factor corresponding to the logic block can also be determined by setting a first cold data ratio threshold and a second cold data ratio threshold, which will not be elaborated in this application.
[0104] Alternatively, a data heat factor can be determined based on the update frequency of the logical block corresponding to each idle physical block to determine the data heat characteristics of the logical block corresponding to each idle physical block, thereby determining the wear level of each idle physical block. In other words, the logical blocks are divided into different logical blocks based on their update frequency.
[0105] It can be understood that logic blocks with higher update frequencies are logic blocks with hot data factors, logic blocks with moderate update frequencies are logic blocks with warm data factors, and logic blocks with higher and lower update frequencies are logic blocks with cold data factors.
[0106] Exemplarily, a first update frequency threshold and a second update frequency threshold are pre-set, and the first update frequency threshold is greater than the second update frequency threshold; the data heat factor corresponding to the logical block whose update frequency is greater than the first update frequency threshold corresponding to the physical block is determined as the hot data factor, that is, the logical block with the hot data factor is determined; the data heat factor corresponding to the logical block whose update frequency is greater than the second update frequency threshold and less than the first update frequency threshold corresponding to the physical block is determined as the warm data factor, that is, the logical block with the warm data factor is determined; the data heat factor corresponding to the logical block whose update frequency is less than the second update frequency threshold corresponding to the physical block is determined as the cold data factor, that is, the logical block with the cold data factor is determined.
[0107] Alternatively, a data heat factor can be determined based on the hot-cold data ratio and update frequency of the logical block corresponding to each idle physical block to determine the data heat characteristics of the logical block corresponding to each idle physical block, thereby determining the degree of wear of each idle physical block. In other words, the logical blocks are divided into different logical blocks based on the hot-cold data ratio and the update frequency of the logical blocks.
[0108] Exemplarily, a first hot data ratio threshold and a second hot data ratio threshold are pre-set, and the first hot data ratio threshold is greater than the second hot data ratio threshold, a first update frequency threshold and a second update frequency threshold are pre-set, and the first update frequency threshold is greater than the second update frequency threshold; the data heat factor corresponding to a logical block whose hot data ratio in the hot and cold data ratio of the logical block corresponding to the physical block is greater than the first hot data ratio threshold and whose update frequency is greater than the first update frequency threshold is determined as a hot data factor, that is, a logical block with a hot data factor is determined; the data heat factor corresponding to a physical block whose hot data ratio in the hot and cold data ratio of the logical block corresponding to the physical block is greater than the second hot data ratio threshold and less than the first hot data ratio threshold is determined as a warm data factor, and the data heat factor corresponding to a logical block whose update frequency is greater than the second update frequency threshold and less than the first update frequency threshold is determined as a warm data factor, that is, a logical block with a warm data factor is determined; the data heat factor corresponding to a logical block whose hot data ratio in the hot and cold data ratio of the logical block corresponding to the physical block is less than the second hot data ratio threshold and whose update frequency is less than the second update frequency threshold is determined as a cold data factor, that is, a logical block with a cold data factor is determined.
[0109] In some embodiments, the plurality of physical blocks of a memory include older physical blocks, middle-aged physical blocks, and younger physical blocks, wherein the older physical blocks have a higher degree of wear than the middle-aged physical blocks, and the middle-aged physical blocks have a higher degree of wear than the younger physical blocks. It is understood that the older physical blocks, middle-aged physical blocks, and younger physical blocks can be determined based on their degree of wear.
[0110] In some embodiments, multiple physical blocks of a memory have a mapping relationship with multiple logical blocks, and the mapping relationship is: logical blocks with hot data factors correspond to young physical blocks, logical blocks with warm data factors correspond to medium-aged physical blocks, and logical blocks with cold data factors correspond to old physical blocks.
[0111] In this embodiment, after the logical block is determined, the physical block corresponding to the logical block can be determined through the logical address and the mapping relationship between multiple physical blocks and multiple logical blocks, so that the data to be written can be written to the corresponding physical block. Since a high proportion of hot data is frequently updated, the memory will be frequently erased and written, which will accelerate the wear of the memory, shorten the service life, and may also cause write amplification problems and reduce storage efficiency; while the cold data has a high proportion and is rarely updated. Although the number of erases and writes can be reduced, data redundancy and fragmentation may increase, affecting space utilization and reading performance. Therefore, when constructing the mapping relationship between multiple physical blocks and multiple logical blocks, in order to avoid frequent writing of hot data to old physical blocks, a corresponding relationship can be established between old physical blocks and logical blocks with hot data factors, a corresponding relationship can be established between middle-aged physical blocks and logical blocks with warm data factors, and a corresponding relationship can be established between young physical blocks and logical blocks with cold data factors.
[0112] That is, by dividing the logical blocks into different types, different types of logical blocks can be mapped to physical blocks with different degrees of wear.
[0113] By adopting this implementation, through the mapping relationship between multiple physical blocks and multiple logical blocks, hot data is preferentially stored in younger physical blocks with the lowest degree of wear, reducing unnecessary erase and read and write operations, and avoiding hot data from being stored in older physical blocks with higher degrees of wear, thereby reducing the degree of wear of older physical blocks. This method optimizes the allocation of storage resources, is conducive to balancing the degree of wear of each physical block in the memory, and extends the service life of the memory.
[0114] In some embodiments, after obtaining the physical aging factor and data heat factor corresponding to each of the multiple free physical blocks of the memory, the comprehensive weight value of each free physical block can be determined based on the physical aging factor and data heat factor corresponding to each free physical block, and the degree of wear of each free physical block can be determined based on the comprehensive weight value of each free physical block. For example, assuming that the physical aging factor of the i-th free physical block is Li and the data heat factor is DataType, the comprehensive weight value Wi = f(Li, DataType) of the i-th free physical block can be calculated in combination with the physical aging factor Li and the data heat factor DataType, and the degree of wear of the i-th free physical block can be determined based on the comprehensive weight value.
[0115] For other implementations of step 201 , please refer to the contents of the aforementioned step 101 , which will not be described in detail here.
[0116] In step 202 , the electronic device determines an idle physical block with the lowest wear level among a plurality of idle physical blocks as a target physical block.
[0117] In some implementations, a comprehensive weight value for each free physical block may be determined based on the physical aging factor and data heat factor corresponding to each free physical block, and the free physical block with the lowest comprehensive weight value may be determined as the target physical block. For example, after determining that there are five free physical blocks, the comprehensive weight value for each of the five free physical blocks may be calculated, and the free physical block with the lowest comprehensive weight value may be determined as the target physical block.
[0118] In some embodiments, a physical block having the lowest physical aging factor and the lowest corresponding logical block with the lowest data heat factor among a plurality of free physical blocks may be determined as the target physical block. It is understood that the lowest physical aging factor indicates that the physical block has the lowest degree of aging, and the lowest data heat factor indicates that the logical block corresponding to the physical block has the lowest degree of wear.
[0119] Optionally, a physical block with the lowest physical aging factor among the plurality of free physical blocks and corresponding to a logical block with a cold data factor may be determined as the target physical block. It will be understood that the lowest physical aging factor indicates that the physical block has the lowest degree of aging, and the logical block with a cold data factor indicates that it is accessed the least frequently, that is, the physical block corresponding to the logical block has the lowest degree of wear.
[0120] Step 203: The electronic device writes the data to be written into the target physical block.
[0121] For other implementations of step 203 , please refer to the contents of the aforementioned step 103 , which will not be described in detail here.
[0122] It can be seen that when the above embodiment is implemented, before writing data, the degree of wear of each physical block is determined by multiple factors of each physical block (physical aging factor and data heat factor), and the physical block with the lowest wear rate is used as the target physical block to write the data to be written. This method comprehensively considers the factors affecting the physical block from multiple dimensions, that is, the degree of wear of each physical block can be determined more accurately through the aging degree of the physical block and the data heat characteristics of the logical block corresponding to the physical block, so that data is written to the physical block with lower wear degree, and data is avoided from being written to the physical block with high wear degree. In other words, when writing data, the degree of wear of each physical block in the memory is balanced, the data writing pressure of each physical block is dispersed, and some physical blocks are avoided from being excessively worn, thereby realizing reasonable management of the memory, improving the stability and reliability of data storage, and helping to extend the service life of the memory.
[0123] In some embodiments, the preset condition includes determining at least one free physical block with a wear level less than a preset threshold among the plurality of free physical blocks as the target physical block. Figure 3 , Figure 3FIG. 1 is a flow chart of another wear leveling method disclosed in an embodiment of the present application. Figure 3 The method shown may include the following steps:
[0124] In step 301 , the electronic device determines the wear degree of each idle physical block in a memory according to a physical aging factor and a data heat factor corresponding to each idle physical block.
[0125] Regarding the implementation of step 301, reference may be made to the contents of steps 101 and 201 above, which will not be repeated here.
[0126] In step 302 , the electronic device determines at least one idle physical block with a wear level less than a preset threshold among a plurality of idle physical blocks as a target physical block.
[0127] In some embodiments, the wear level of each idle physical block can be determined based on the physical aging factor and data heat factor corresponding to each of the multiple idle physical blocks of the memory, and at least one idle physical block with a wear level less than a preset threshold value can be determined as a target physical block. It is understood that since the wear level of each idle physical block is determined by comparison with a preset threshold value, the number of idle physical blocks less than the preset threshold value can be one or more, that is, the number of target physical blocks can be one or more, and this application does not impose any limitation on this.
[0128] In some implementations, a comprehensive weight value of each idle physical block can be determined based on the physical aging factor and data heat factor corresponding to each idle physical block, and an idle physical block with a comprehensive weight value less than a preset threshold is determined as a target physical block.
[0129] It should be noted that the preset threshold can be set by those skilled in the art according to actual needs, and this application does not limit this.
[0130] In some embodiments, a physical block of a plurality of free physical blocks having a physical aging factor less than a preset physical aging factor threshold and a logical block corresponding to a data heat factor less than a preset data heat factor threshold may be determined as a target physical block.
[0131] It should be noted that the preset physical aging factor threshold and the preset data heat factor threshold can be set by those skilled in the art according to actual needs, and this application does not limit this.
[0132] Optionally, a physical block among the plurality of free physical blocks, the physical aging factor of which is less than a preset physical aging factor threshold and the physical block corresponding to the logical block with the cold data factor may be determined as the target physical block.
[0133] Step 303: The electronic device writes the data to be written into the target physical block.
[0134] In some embodiments, after writing the data to be written to the target physical block, the electronic device may further update at least one of a historical erase count, an operating temperature, and a supply voltage fluctuation of the target physical block. In this embodiment, since an erase operation must be performed before data is written, the historical erase count of the target physical block may be updated after the data to be written is written to the target physical block. For example, assuming that the historical erase count of the target physical block is initially 50 times, after the data is written, the historical erase count of the target physical block is updated to 51 times.
[0135] In this embodiment, since the operating temperature and power supply voltage fluctuations of the memory will also change during the reading and writing process, after the data to be written is written into the target physical block, the operating temperature and power supply voltage fluctuations of the target physical block can be updated. When a new data read and write request is received next time, the updated operating temperature and power supply voltage fluctuations can be directly used.
[0136] It can be understood that the electronic device can also update the historical erase count of the target physical block, or the operating temperature of the target physical block, or the power supply voltage fluctuation of the target physical block, or the historical erase count and operating temperature of the target physical block, or the historical erase count and power supply voltage fluctuation of the target physical block, or the operating temperature and power supply voltage fluctuation of the target physical block, or the historical erase count, operating temperature and power supply voltage fluctuation of the target physical block.
[0137] With this implementation, since the erase count, operating temperature, and power supply voltage fluctuations affect the degree of wear of the physical block, after the data to be written is written into the target physical block, at least one of the historical erase count, operating temperature, and power supply voltage fluctuations of the target physical block can also be updated in real time. By updating these parameters in real time, it is helpful to timely evaluate the degree of aging of the target physical block.
[0138] In some embodiments, after performing an erase, the memory needs to count each erase to update the erase count. The erase count process is called metadata writing. When erasing, the erase count needs to be encoded according to a certain encoding method to complete the metadata writing process. In the related art, when erasing, the erase count is encoded using a fixed length. Since the metadata itself also needs to be stored in the memory, the erase count is usually stored in a preset storage location (such as the head position) of the corresponding physical block. Therefore, this method is very wasteful of storage space, especially when the erase count is still low. For example, the erase count storage is encoded using a fixed 32-bit, that is, a fixed-length 32-bit storage is used. It means that the erase count of each physical block requires 32 bits to represent. For example, a physical block with an erase count of 1000 is represented by 32-bit binary as 0000 0000 0000 00000000 0011 1110 1000 (binary representation of 1000).
[0139] In some embodiments, when the erase count of a physical block is less than a third threshold, the erase count of the physical block is encoded using a linear encoding method. In this embodiment, the use of a linear encoding method for the erase count corresponding to the physical block whose erase count is less than the third threshold can improve the efficiency of the erase count. Furthermore, for low erase count areas, the use of linear encoding can more accurately represent the erase count value, ensuring that each erase operation can be accurately recorded when the erase count is small. For example, the linear coding method can be used for low erase counts (e.g., erase counts of 0-255) and directly stored in binary form using 8-bit linear coding, that is, the new erase count is converted into an 8-bit binary code and written into the metadata area of the physical block. For example, the initial erase count of a physical block is 0, which is represented by 00000000 in binary. After the first erase, the erase count becomes 1, and the binary code is 00000001. After the second erase, it becomes 2, and the binary code is 00000010, and so on, until the erase count reaches the third threshold value 255, and the binary code is 11111111.
[0140] In some embodiments, when the number of erase counts for a physical block is greater than or equal to a third threshold, the number of erase counts for the physical block is encoded using a logarithmic encoding method. In this embodiment, a higher frequency of erase counting results in a higher degree of wear on the physical block, and a greater number of erase counts also results in a greater amount of storage space occupied by the physical block. The next time an erase operation is performed on the physical block, the wear on the physical block will also increase. Therefore, in order to reduce the wear on the memory each time an erase count is performed, the encoding method for storing the erase count can be adjusted based on the number of erase counts.
[0141] In this embodiment, when the number of erasures is greater than or equal to a third threshold, the erasure count is encoded using a logarithmic encoding method. Since the erasure count itself also needs to be stored in the memory, the erasure count corresponding to the physical block with an erasure count greater than or equal to the third threshold is converted into a metadata compression method. This can reduce the storage space required for metadata, thereby freeing up more space for storing other data. For example, the logarithmic encoding method can represent the larger value of the erasure count with fewer bits for high erasure counts (e.g., erasure counts of 256-10000). For example, a count of 1024 can be represented as log21024=10, thereby reducing the space required for storage.
[0142] It should be noted that the third threshold can be set by those skilled in the art according to actual needs, and this application does not limit this.
[0143] With this implementation, the number of erase times of each physical block needs to be stored. When the number of erase times of the physical block is higher than a preset third threshold, it indicates that the number of erase times of the physical block is high. In this case, the number of erase times of the physical block can be stored in a logarithmic encoding manner. Since the logarithmic encoding method can reduce the data length occupied when storing the erase times, it means that each time the erase count is updated, the storage space and write time occupied by storing the erase times are reduced, which not only reduces the wear on the physical block, but also improves the storage efficiency. Therefore, dynamically adjusting the encoding method based on the number of erase times further balances the degree of wear of each physical block in the memory.
[0144] For other implementations of step 303 , please refer to the contents of steps 103 and 203 above, which will not be described in detail here.
[0145] It can be seen that when the above embodiment is implemented, before writing data, the degree of wear of each physical block is determined by multiple factors (physical aging factor and data heat factor) of each physical block, and the physical block with a wear rate less than a preset threshold is used as the target physical block to write the data to be written. This method comprehensively considers the factors affecting the physical block from multiple dimensions, that is, the degree of wear of each physical block can be determined more accurately through the aging degree of the physical block and the data heat characteristics of the logical block corresponding to the physical block, so that data is written to the physical block with lower wear, and data is avoided from being written to the physical block with high wear. In other words, when writing data, the degree of wear of each physical block in the memory is balanced, the data writing pressure of each physical block is dispersed, and some physical blocks are avoided from being excessively worn, thereby realizing reasonable management of the memory, improving the stability and reliability of data storage, and helping to extend the service life of the memory.
[0146] In some embodiments, the target physical block can be determined by using any of the above steps 202 or not 302, and this application does not limit this. That is to say, when determining the target physical block, the idle physical block with the lowest wear level can be determined as the target physical block, or the idle physical block with a wear level less than a preset threshold can be determined as the target physical block, that is, one physical block can be selected to write data, or one or more physical blocks with a wear level less than the preset threshold can be selected to write data, thereby improving the flexibility when writing data. This flexible selection mechanism can adapt to different application scenarios and load requirements. For example, in a high-frequency writing scenario, at least one idle physical block with a wear level less than a preset threshold among multiple idle physical blocks can be selected as the target physical block, so that multiple physical blocks with low wear levels can be selected for concurrent writing to improve write throughput.
[0147] In some embodiments, the electronic device may also perform a data migration operation on data stored in multiple physical blocks. Figure 4 , Figure 4 FIG. 1 is a flow chart of another wear leveling method disclosed in an embodiment of the present application. Figure 4 The method shown may include the following steps:
[0148] In step 401 , the electronic device determines the wear degree of each physical block in a memory according to a physical aging factor and a data heat factor corresponding to each physical block.
[0149] In an embodiment of the present application, the multiple physical blocks of the memory can be all free physical blocks, all non-free physical blocks, or all free physical blocks and non-free physical blocks. The present application does not limit the type and number of the multiple physical blocks.
[0150] Regarding the implementation of determining the wear degree of each physical block in step 401, reference may be made to the contents of the aforementioned steps, which will not be repeated here.
[0151] In step 402 , the electronic device performs a data migration operation on data stored in multiple physical blocks according to the wear level of each physical block.
[0152] It is understandable that since the degree of wear of each physical block in the memory may vary, data stored in multiple physical blocks in the memory may be migrated according to the degree of wear of each physical block, so that the degree of wear of each physical block in the memory can be balanced to a certain extent.
[0153] In some implementations, the data migration operation may include the following two methods:
[0154] Method 1: The data migration operation is as follows: hot data stored in at least one non-idle physical block with a wear level higher than a first threshold is migrated to at least one idle physical block with a wear level lower than a second threshold, where the first threshold is greater than the second threshold. The at least one non-idle physical block with a wear level higher than the first threshold indicates that such physical block is in a non-idle state and has a high wear level; the at least one idle physical block with a wear level lower than the second threshold indicates that such physical block is in an idle state (no stored data) and has a low wear level. Furthermore, hot data is typically frequently accessed and updated, which also increases the wear level of the physical block. Therefore, migrating hot data stored in a physical block with a high wear level and in a non-idle state to a physical block with a low wear level and in an idle state reduces the wear level and storage pressure of the physical block with a high wear level and in a non-idle state.
[0155] Method 2: The data migration operation involves migrating cold data stored in at least one non-idle physical block with a wear level below a second threshold to at least one free physical block with a wear level above a first threshold, where the first threshold is greater than the second threshold. The at least one non-idle physical block with a wear level below the second threshold indicates that such physical block is in a non-idle state but has a low wear level; the at least one free physical block with a wear level above the first threshold indicates that such physical block is in an idle state (no stored data) but has a high wear level. Furthermore, cold data is typically infrequently accessed and updated, which can mitigate the increase in wear level to a certain extent. Therefore, migrating cold data from a non-idle physical block with a low wear level to another free physical block with a high wear level can reduce the frequency of data access to the other physical block with a high wear level, thereby reducing the wear level of the other physical block with a high wear level. This can also reduce the storage pressure on the non-idle physical block with a low wear level.
[0156] It should be noted that the first threshold and the second threshold can be set by those skilled in the art according to actual needs, and this application does not limit this.
[0157] It should be noted that the electronic device may adopt any one or more of the above-mentioned methods when performing data migration operations on data stored in multiple physical blocks, and this application does not limit this.
[0158] It can be seen that by implementing the above embodiment, data stored in multiple physical blocks can be migrated between different physical blocks according to the wear level of each physical block from the perspective of the entire memory. The data storage location can be adjusted according to actual conditions to avoid failure of certain physical blocks due to excessive wear. This method is conducive to balancing the wear level of each physical block in the memory. Wear balancing can make the wear level of each physical block as uniform as possible, avoid premature damage of certain physical blocks and lead to waste of storage resources, realize dynamic management of storage resources, and help improve the overall performance of the memory and extend the service life of the memory.
[0159] In some embodiments, the electronic device may also perform a data exchange operation on data stored in multiple physical blocks. Figure 5 , Figure 5 FIG. 1 is a flow chart of another wear balancing method disclosed in an embodiment of the present application. Figure 5 The method shown may include the following steps:
[0160] In step 501 , the electronic device determines the wear degree of each physical block in a memory according to a physical aging factor and a data heat factor corresponding to each physical block.
[0161] Regarding the implementation of step 501, reference may be made to the content of the aforementioned step 401, which will not be repeated here.
[0162] Regarding the implementation of determining the wear degree of each physical block in step 501, reference may be made to the contents of the aforementioned steps, which will not be repeated here.
[0163] In step 502 , the electronic device performs a data exchange operation on data stored in multiple physical blocks according to the wear level of each physical block.
[0164] It is understandable that since the degree of wear of each physical block in the memory may vary, data stored in multiple physical blocks in the memory may be exchanged according to the degree of wear of each physical block, which may balance the degree of wear of each physical block in the memory to a certain extent.
[0165] In some embodiments, the data swap operation involves swapping hot data stored in at least one non-idle physical block with a wear level above a first threshold with cold data stored in at least one non-idle physical block with a wear level below a second threshold, where the first threshold is greater than the second threshold. The at least one non-idle physical block with a wear level above the first threshold indicates that such physical block is in a non-idle state and has a high wear level; the at least one non-idle physical block with a wear level below the second threshold indicates that such physical block is in a non-idle state and has a low wear level. Furthermore, hot data is typically frequently accessed and updated, which increases the wear level of the physical block, while cold data is typically less frequently accessed and updated, which can mitigate the increase in wear to a certain extent. Therefore, swapping hot data stored in a non-idle physical block with cold data stored in a non-idle physical block with a low wear level reduces the wear level of the non-idle physical block. It should be noted that before performing the data swap, the free areas of the physical blocks containing the old cold data and hot data must be erased.
[0166] Optionally, the data exchange operation is as follows: reading hot data from a first number of non-free physical blocks with a wear level higher than a first threshold into a first cache, and reading cold data from a second number of non-free physical blocks with a wear level lower than a second threshold into a second cache; writing the hot data read from the first cache to the second number of non-free physical blocks, and writing the cold data read from the second cache to the first number of non-free physical blocks. It will be appreciated that a preset first amount of hot data stored in physical blocks with a higher wear level and in a non-free state may be exchanged with a preset second amount of cold data stored in physical blocks with a lower wear level and in a non-free state.
[0167] It can be seen that by implementing the above embodiment, data stored in multiple physical blocks can be exchanged between different physical blocks according to the wear degree of each physical block from the perspective of the entire memory. The data storage location can be adjusted according to actual conditions to avoid failure of certain physical blocks due to excessive wear. This method is conducive to balancing the wear degree of each physical block in the memory. Wear balancing can make the wear degree of each physical block as uniform as possible, avoid premature damage of certain physical blocks and lead to waste of storage resources, realize dynamic management of storage resources, and help improve the overall performance of the memory and extend the service life of the memory.
[0168] In some embodiments, the electronic device may perform data migration operations and data exchange operations on data stored in multiple physical blocks based on the degree of wear of each physical block. It is understood that in order to balance the degree of wear of multiple physical blocks in the memory, the electronic device may perform the above-mentioned data migration operations on the data stored in multiple physical blocks and the above-mentioned data exchange operations on the data stored in multiple physical blocks based on the degree of wear of the physical blocks. It should be noted that the implementation method of the electronic device performing the data migration operation and the data exchange operation in this embodiment can be referred to the content of the aforementioned steps 402 and 502, and will not be repeated here.
[0169] It should be understood that, although the various steps in the above-mentioned flowcharts are displayed in sequence according to the instructions of the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless clearly stated herein, the execution of these steps is not strictly restricted in order, and these steps can be executed in other orders. Moreover, at least a portion of the steps in the above-mentioned flowcharts may include a plurality of sub-steps or a plurality of stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these sub-steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with at least a portion of other steps or sub-steps or stages of other steps. In addition, the above-mentioned multiple embodiments can be implemented independently or in combination with each other, and are not limited thereto.
[0170] Based on the foregoing embodiments, an embodiment of the present application provides a wear leveling device, which includes the modules included and the units included in each module, and can be implemented by a processor; of course, it can also be implemented by a specific logic circuit; in the implementation process, the processor can be a central processing unit (CPU), a microprocessor (MPU), a digital signal processor (DSP) or a field programmable gate array (FPGA), etc.
[0171] See Figure 6 , Figure 6 This is a schematic diagram of the structure of a wear balancing device disclosed in an embodiment of the present application. Figure 6 The device shown includes a processing module 601 and a writing module 602 .
[0172] Processing module 601 is configured to determine the wear level of each idle physical block of a memory based on a physical aging factor and a data heat factor corresponding to each idle physical block, wherein the physical aging factor indicates the aging level of the physical block, and the data heat factor indicates the data heat characteristic of the logical block corresponding to the physical block.
[0173] The processing module 601 is further configured to determine at least one idle physical block that meets a preset condition among the plurality of idle physical blocks as a target physical block, wherein the wear level of the idle physical block that meets the preset condition is lower than the wear level of the idle physical blocks that do not meet the preset condition;
[0174] The writing module 602 is configured to write the data to be written into the target physical block.
[0175] In some embodiments, the physical aging factor is determined based on at least one of a historical erase count of the physical block, an operating temperature, and a supply voltage fluctuation.
[0176] In some embodiments, the data heat factor is determined based on at least one of the ratio of cold data to hot data of the logical block corresponding to the physical block and the update frequency of the logical block. The ratio of cold data to hot data includes the ratio of cold data and the ratio of hot data. The cold data ratio is the ratio of cold data in the data corresponding to the logical block, and the hot data ratio is the ratio of hot data in the data corresponding to the logical block.
[0177] In some embodiments, the processing module 601 is further configured to determine the wear degree of each physical block of the memory according to the physical aging factor and the data heat factor corresponding to each physical block; and perform a data migration operation and / or a data exchange operation on the data stored in the multiple physical blocks according to the wear degree of each physical block, wherein:
[0178] The data migration operation is: migrating hot data stored in at least one non-free physical block with a wear level higher than a first threshold to at least one free physical block with a wear level lower than a second threshold, and / or migrating cold data stored in at least one non-free physical block with a wear level lower than the second threshold to at least one free physical block with a wear level higher than the first threshold;
[0179] The data exchange operation is: exchanging hot data stored in at least one non-idle physical block whose wear level is higher than a first threshold with cold data stored in at least one non-idle physical block whose wear level is lower than a second threshold;
[0180] The first threshold is greater than the second threshold.
[0181] In some embodiments, the processing module 601 is specifically configured to:
[0182] Determine a free physical block with the lowest wear level among a plurality of free physical blocks as the target physical block; or,
[0183] At least one idle physical block with a wear level less than a preset threshold among the plurality of idle physical blocks is determined as a target physical block.
[0184] In some embodiments, the apparatus further comprises an update module;
[0185] An update module is configured to update at least one of a historical erase count, an operating temperature, and a supply voltage fluctuation of a target physical block.
[0186] In some embodiments, when the number of erasure times of the physical block is greater than or equal to a third threshold, the number of erasure times of the physical block is encoded using a logarithmic encoding method.
[0187] In some embodiments, the data heat factor includes a hot data factor, a warm data factor or a cold data factor, and a plurality of physical blocks of the memory have a mapping relationship with a plurality of logical blocks. The plurality of logical blocks include a logical block with a hot data factor, a logical block with a warm data factor and a logical block with a cold data factor. The plurality of physical blocks include an old physical block, a middle-aged physical block and a young physical block. The logical block with a hot data factor corresponds to a young physical block, the logical block with a warm data factor corresponds to a middle-aged physical block, and the logical block with a cold data factor corresponds to an old physical block. The wear degree of the old physical block is higher than that of the middle-aged physical block, and the wear degree of the middle-aged physical block is higher than that of the young physical block.
[0188] It should be noted that the division of modules in the wear leveling device shown in the embodiment of the present application is schematic and is merely a logical function division. There may be other division methods in actual implementation.
[0189] An electronic device provided in the embodiment of the present application, please refer to Figure 7 , Figure 7 This is a schematic diagram of the structure of an electronic device disclosed in an embodiment of the present application. Figure 7 As shown, the electronic device includes:
[0190] A memory 701 storing executable program code;
[0191] a processor 702 coupled to the memory 701;
[0192] The processor 702 calls the executable program code stored in the memory 701 to execute any one of the wear leveling methods in the above method embodiments.
[0193] An embodiment of the present application provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, part or all of the steps of any one of the wear leveling methods provided in the above embodiments are implemented.
[0194] An embodiment of the present application also provides a computer program product, including a computer program, which, when executed by a processor, implements part or all of the steps of any one of the wear leveling methods provided in the above embodiments.
[0195] Those skilled in the art will understand that Figure 7 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the electronic device to which the solution of the present application is applied. The specific electronic device may include more or fewer components than shown in the figure, or combine certain components, or have a different component arrangement.
[0196] It should be noted that the descriptions of the above embodiments of the apparatus, electronic device, computer-readable storage medium, and computer program product are similar to the descriptions of the above-mentioned method embodiments and have similar beneficial effects as the method embodiments. For technical details not disclosed in the embodiments of the apparatus, electronic device, computer-readable storage medium, and computer program product of this application, please refer to the descriptions of the method embodiments of this application for understanding.
[0197] It should be understood that "one embodiment" or "an embodiment" or "some embodiments" mentioned throughout the specification means that the specific features, structures or characteristics related to the embodiment are included in at least one embodiment of the present application. Therefore, "in one embodiment" or "in an embodiment" or "in some embodiments" appearing throughout the specification do not necessarily refer to the same embodiment. In addition, these specific features, structures or characteristics can be combined in one or more embodiments in any suitable manner. It should be understood that in the various embodiments of the present application, the size of the serial numbers of the above-mentioned processes does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application. The above-mentioned serial numbers of the embodiments of the present application are for description only and do not represent the advantages and disadvantages of the embodiments. The above description of the various embodiments tends to emphasize the differences between the various embodiments. The same or similar aspects can be referenced to each other. For the sake of brevity, they will not be repeated here.
[0198] The term "and / or" in this article is only a description of the association relationship between associated objects, indicating that there can be three relationships. For example, object A and / or object B can mean: object A exists alone, object A and object B exist at the same time, and object B exists alone.
[0199] It should be noted that, in this document, the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, article, or apparatus comprising a series of elements includes not only those elements but also other elements not explicitly listed, or elements inherent to such process, method, article, or apparatus. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of other identical elements in the process, method, article, or apparatus comprising the element.
[0200] In the several embodiments provided in this application, it should be understood that the disclosed methods, devices and electronic devices can be implemented in other ways. The embodiments described above are merely illustrative. For example, the division of the modules above is only a logical function division. In actual implementation, there may be other division methods, such as: multiple modules or components can be combined, or can be integrated into another system, or some features can be ignored or not executed. In addition, the coupling, direct coupling, or communication connection between the components shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or modules, which can be electrical, mechanical or other forms.
[0201] Those skilled in the art will understand that all or part of the steps of implementing the above-mentioned method embodiments can be completed by hardware related to program instructions, and the aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it executes the steps of the above-mentioned method embodiments; and the aforementioned storage medium includes: mobile storage devices, read-only memories (ROM), magnetic disks or optical disks, and other media that can store program codes.
[0202] The methods disclosed in the several method embodiments provided in this application can be arbitrarily combined without conflict to obtain new method embodiments.
[0203] The features disclosed in the several device embodiments provided in this application can be arbitrarily combined without conflict to obtain new device embodiments.
[0204] The above is merely an embodiment of the present application, but the scope of protection of the present application is not limited thereto. Any changes or substitutions that can be easily conceived by a person skilled in the art within the technical scope disclosed in this application should be included in the scope of protection of this application. Therefore, the scope of protection of this application should be based on the scope of protection of the claims.
Claims
1. A wear leveling method, characterized in that: The method comprises: Determining a degree of wear of each of the plurality of idle physical blocks of the memory according to a physical aging factor and a data heat factor corresponding to each of the idle physical blocks, wherein the physical aging factor is used to indicate an aging degree of the physical block, and the data heat factor is used to indicate a data heat characteristic of a logical block corresponding to the physical block; Determining at least one free physical block that meets a preset condition among the plurality of free physical blocks as a target physical block, wherein the wear degree of the free physical block that meets the preset condition is lower than the wear degree of the free physical blocks that do not meet the preset condition; The data to be written is written into the target physical block.
2. The method according to claim 1, characterized in that The physical aging factor is determined according to at least one of a historical number of erase times of the physical block, an operating temperature, and a supply voltage fluctuation.
3. The method according to claim 1, characterized in that The data heat factor is determined based on at least one of a cold-hot data ratio of a logical block corresponding to the physical block and an update frequency of the logical block. The cold-hot data ratio includes a cold data ratio and a hot data ratio. The cold data ratio is the ratio of cold data in the data corresponding to the logical block, and the hot data ratio is the ratio of hot data in the data corresponding to the logical block.
4. The method according to any one of claims 1 to 3, characterized in that The method further comprises: determining a degree of wear of each physical block among a plurality of physical blocks of the memory according to a physical aging factor and a data heat factor corresponding to each physical block; According to the wear degree of each physical block, a data migration operation and / or a data exchange operation is performed on the data stored in the plurality of physical blocks, wherein: The data migration operation is: migrating hot data stored in at least one non-free physical block with a wear level higher than a first threshold to at least one free physical block with a wear level lower than a second threshold, and / or migrating cold data stored in at least one non-free physical block with a wear level lower than the second threshold to at least one free physical block with a wear level higher than the first threshold; The data exchange operation is to exchange hot data stored in at least one non-idle physical block whose wear level is higher than a first threshold with cold data stored in at least one non-idle physical block whose wear level is lower than a second threshold; The first threshold is greater than the second threshold.
5. The method according to any one of claims 1 to 3, characterized in that The step of determining at least one idle physical block that meets a preset condition among the plurality of idle physical blocks as a target physical block includes: Determine the idle physical block with the lowest wear level among the plurality of idle physical blocks as the target physical block; or, At least one free physical block with a wear level less than a preset threshold among the plurality of free physical blocks is determined as the target physical block.
6. The method according to claim 2, characterized in that After writing the data to be written into the target physical block, the method further includes: At least one of a historical erase count, an operating temperature, and a supply voltage fluctuation of the target physical block is updated.
7. The method according to claim 2, characterized in that In a case where the number of erasure times of the physical block is greater than or equal to a third threshold, the number of erasure times of the physical block is encoded in a logarithmic encoding manner.
8. The method according to any one of claims 1 to 3, characterized in that The data heat factor includes a hot data factor, a warm data factor, or a cold data factor. The multiple physical blocks of the memory have a mapping relationship with the multiple logical blocks. The multiple logical blocks include a logical block with the hot data factor, a logical block with the warm data factor, and a logical block with the cold data factor. The multiple physical blocks include an old physical block, a middle-aged physical block, and a young physical block. The logical block with the hot data factor corresponds to the young physical block, the logical block with the warm data factor corresponds to the middle-aged physical block, and the logical block with the cold data factor corresponds to the old physical block. The old physical block has a higher degree of wear than the middle-aged physical block, and the middle-aged physical block has a higher degree of wear than the young physical block.
9. A wear leveling device, characterized in that: The device comprises: a processing module, configured to determine a degree of wear of each of a plurality of idle physical blocks of a memory based on a physical aging factor and a data heat factor corresponding to each of the idle physical blocks, wherein the physical aging factor is used to indicate an aging degree of the physical block, and the data heat factor is used to indicate a data heat characteristic of a logical block corresponding to the physical block; The processing module is further configured to determine at least one idle physical block among the plurality of idle physical blocks that meets a preset condition as a target physical block, wherein the wear level of the idle physical block that meets the preset condition is lower than the wear level of the idle physical blocks that do not meet the preset condition; The writing module is used to write the data to be written into the target physical block.
10. An electronic device, characterized in that: The method comprises a memory and a processor, wherein the memory stores a computer program that can be run on the processor, and is characterized in that when the processor executes the program, the steps of the method according to any one of claims 1 to 8 are implemented.
11. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 8 is implemented.
12. A computer program product, characterized in that The method comprises a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 8 is implemented.