Disclosure of Invention
The application provides a solid state disk wear leveling method, a solid state disk wear leveling device and a computer readable storage medium, which realize solid state disk wear leveling based on a ZNS protocol and effectively prolong the service life of a solid state disk.
In order to solve the above technical problems, embodiments of the present invention provide the following technical solutions:
an embodiment of the present invention provides a method for wear leveling of a solid state disk, including:
the method comprises the steps that a plurality of idle block linked lists and dirty block linked lists which are prioritized by the erasing times of data blocks and used for storing the data blocks are constructed in advance, and each data block is classified into the idle block linked list or the dirty block linked list based on the erasing times and the erasing average value difference, the block type and the erasing time allowable range corresponding to each list;
when detecting that an idle block linked list meeting the wear leveling condition exists, setting a reset label for a block corresponding to a data block with the lowest erasing times; if a block reset instruction issued by a host end is not received within a preset time threshold, taking a data block with the lowest erasing frequency in each dirty block linked list as a source data block, and taking a data block with the highest erasing frequency in each idle block linked list as a target data block for data transfer;
when a request for applying for a data block is received, selecting the data block from the idle block chain table with the lowest erasing times;
the erasing times of the data blocks in the same idle block linked list or dirty block linked list are within the same erasing time allowable range, and the number of the tables is determined based on a preset abrasion threshold value and the erasing mean value; the block types are a free block and a dirty data block.
Optionally, when it is detected that there is an idle block linked list that meets the wear leveling condition, setting a reset tag for a block corresponding to the idle block linked list with the lowest erase frequency as:
and when detecting that the total number of the data blocks contained in the free block chain table with the maximum value of the allowable range of the erasing times lower than the erasing average value is lower than a number threshold, setting a reset label for the block corresponding to the free block chain table with the lowest erasing times.
Optionally, when a request for applying for a data block is received, selecting a data block from the idle block chain table with the lowest erasing frequency as:
when a request for applying for a data block is received, determining a target idle block linked list with the lowest erasing times from each idle block linked list;
and feeding back the data block with the lowest erasing times in the target idle block linked list.
Optionally, before the pre-constructing a plurality of free block linked lists and dirty block linked lists that are prioritized by the number of times of erasing the data block and are used for storing the data block, the method further includes:
and randomizing the abrasion times of each data block in the solid state disk according to a block logic number randomization algorithm.
Optionally, after the pre-constructing a plurality of free block linked lists and dirty block linked lists that are prioritized by the number of times of erasing the data block and are used for storing the data block, the method further includes:
and after the erasing mean value changing instruction is received, adjusting the data blocks stored in each idle block chain table and each dirty block chain table based on the difference value between the current erasing times of the data blocks and the updated erasing mean value.
Optionally, the allowable range of the number of times of erasing of each free block linked list and each dirty block linked list is determined according to the wear threshold and the total number of the lists.
Another aspect of the embodiments of the present invention provides a solid state disk wear leveling apparatus, including:
the table pre-construction module is used for pre-constructing a plurality of idle block linked lists and dirty block linked lists which are prioritized by the erasing times of the data blocks and are used for storing the data blocks; the erasing times of the data blocks in the same idle block linked list or dirty block linked list are within the same erasing time allowable range, and the number of the tables is determined based on a preset abrasion threshold value and the erasing mean value;
the data block classification module is used for classifying each data block into an idle block linked list or a dirty block linked list based on the erasing times and the erasing average value difference, the block type and the erasing time allowable range corresponding to each table; the block types are idle blocks and dirty data blocks;
the wear leveling processing module is used for setting a reset label for a block corresponding to a data block with the lowest erasing frequency when detecting that an idle block linked list meeting a wear leveling condition exists; if a block reset instruction issued by a host end is not received within a preset time threshold, taking a data block with the lowest erasing frequency in each dirty block linked list as a source data block, and taking a data block with the highest erasing frequency in each idle block linked list as a target data block for data transfer;
and the data block providing module is used for selecting the data block from the idle block chain table with the lowest erasing times when a request for applying for the data block is received.
Optionally, the system further includes a table updating module, where the table updating module is configured to adjust the free block linked lists and the data blocks stored in the dirty block linked lists based on a difference between a current erasing frequency of the data block and an updated erasing mean value after receiving the erasing mean value changing instruction.
The embodiment of the present invention further provides a solid state disk wear leveling device, which includes a processor, where the processor is configured to implement the steps of the solid state disk wear leveling method according to any one of the preceding items when executing a computer program stored in a memory.
Finally, an embodiment of the present invention provides a computer-readable storage medium, where a solid state disk wear leveling program is stored on the computer-readable storage medium, and when being executed by a processor, the solid state disk wear leveling program implements the steps of the solid state disk wear leveling method according to any one of the foregoing embodiments.
The technical scheme provided by the application has the advantages that the data blocks are classified into different tables according to the difference between the erasing times and the erasing mean value to realize priority discrimination, repeated operation caused by comparison between every two data blocks is avoided, and the data block priority classification efficiency is improved; the data moving is realized by improving and exchanging the data blocks with low erasing times in the dirty block linked list and the data blocks with high erasing times in the idle block linked list, the total erasing times of the data blocks in the dirty block linked list is increased, the total erasing times of the data blocks in the idle block linked list is reduced, and the number of the data blocks which are lower than the average erasing times in the idle block linked list is increased, so that the data blocks with low erasing times can be provided all the time when zoneopen applies for the data blocks, the wear balance of the solid state disk based on the ZNS protocol is realized, the wear balance of each data block in the solid state disk is favorably ensured, and the service life of the solid state disk is effectively prolonged.
In addition, the embodiment of the invention also provides a corresponding implementation device and a computer readable storage medium for the solid state disk wear leveling method, so that the method has higher practicability, and the device and the computer readable storage medium have corresponding advantages.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the disclosure.
Detailed Description
In order that those skilled in the art will better understand the disclosure, the invention will be described in further detail with reference to the accompanying drawings and specific embodiments. It is to be understood that the described embodiments are merely exemplary of the invention, and not restrictive of the full scope of the invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
The terms "first," "second," "third," "fourth," and the like in the description and claims of this application and in the above-described drawings are used for distinguishing between different objects and not for describing a particular order. Furthermore, the terms "comprising" and "having," as well as any variations thereof, are intended to cover non-exclusive inclusions. For example, a process, method, system, article, or apparatus that comprises a list of steps or elements is not limited to only those steps or elements but may include other steps or elements not expressly listed.
Having described the technical solutions of the embodiments of the present invention, various non-limiting embodiments of the present application are described in detail below.
Referring to fig. 1, fig. 1 is a schematic flow chart of a method for wear leveling of a solid state disk according to an embodiment of the present invention, where the embodiment of the present invention includes the following:
s101: a plurality of idle block linked lists and dirty block linked lists which are prioritized by the erasing times of the data blocks and used for storing the data blocks are constructed in advance, and each data block is classified into the idle block linked list or the dirty block linked list based on the erasing times and the erasing average value difference, the block type and the erasing time allowable range corresponding to each list.
In the present application, there are a plurality of idle block linked lists and dirty block linked lists, each idle block linked list and each dirty block linked list have a unique priority level, and the priority levels of the lists are distinguished by the number of times of database erasure. Each priority level uniquely corresponds to a group of allowable range of erasing times, and the erasing times of the data blocks in the same idle block linked list or the same dirty block linked list are within the same allowable range of erasing times. Before the idle block linked list and the dirty block linked list are constructed, a wear threshold value is preset, the total number of the idle block linked list and the dirty block linked list can be determined according to the wear threshold value and the erase mean value, the total number of the idle block linked list and the total number of the dirty block linked list can be the same or different, and the method is not limited at all. Of course, after the number of tables is determined, the allowable range of the erasing times of each free block linked list and each dirty block linked list can be determined according to the wear threshold and the total number of the tables.
It can be understood that after the free block chain table and the dirty block chain table are constructed, the free block chain table is used for storing free data blocks, where a free data block refers to a data block whose data block is empty or has a free space capacity to accommodate data, and these data blocks may be new data blocks, that is, data blocks that have not been subjected to an erase operation, or data blocks that have undergone multiple erase operations; the free block chain table is used for storing dirty data blocks, where a dirty data block refers to a data block in which data is written, and the data block may be a data block in which data is newly written full, that is, a data block in which an erase operation is not performed, or a data block in which multiple erase operations are performed. The total number of the data blocks stored in each free block chain table and each dirty block chain table can be determined according to an actual application scenario, which is not limited in this application. Because the priority levels of each idle block linked list and each dirty block linked list are distinguished based on the erasing times of the data blocks, and correspondingly, each idle block linked list and each dirty block linked list correspond to a unique erasing time allowable range, the data blocks can be classified into the idle block linked list or the dirty block linked list based on the erasing times and the erasing average value difference, the block type and the erasing time allowable range corresponding to each list, wherein the block type is an idle block and a dirty data block.
For example, the wear threshold is 100, and according to the threshold limit of wear leveling distance average 100, that is, 100 < the wear count of the current data block-the erase average < 100, the total number of tables of the idle block linked list and the dirty block linked list may be 20, that is, 20 priorities may be set for the idle block linked list and the dirty block linked list, each priority may include 10 PEs, based on which, the allowable range of the erase count of the first idle block linked list may be 0 to 10, the allowable range of the erase count of the second idle block linked list may be 10 to 20, the allowable range of the erase count of the third idle block linked list may be 20 to 30, the allowable range of the erase count of the fourth idle block linked list may be 30 to 40, the allowable range of the erase count of the fifth idle block linked list may be 40 to 50, and the allowable range of the erase count of the sixth idle block linked list may be 50 to 60, the allowable range of the erasing times of the seventh idle block linked list can be 60-70, the allowable range of the erasing times of the eighth idle block linked list can be 70-80, the allowable range of the erasing times of the ninth idle block linked list can be 80-90, the allowable range of the erasing times of the tenth idle block linked list can be 90-100, the allowable range of the erasing times of the eleventh idle block linked list can be-10-0, the allowable range of the erasing times of the twelfth idle block linked list can be-10-20, the allowable range of the erasing times of the thirteenth idle block linked list can be-20-30, the allowable range of the erasing times of the fourteenth idle block linked list can be-30-40, the allowable range of the erasing times of the fifteenth idle block linked list can be-40-50, the allowable range of the erasing times of the sixteenth idle block linked list can be-50-60, the allowable range of the erasing times of the seventeenth idle block linked list can be-60 to-70, the allowable range of the erasing times of the eighteenth idle block linked list can be-70 to-80, the allowable range of the erasing times of the nineteenth idle block linked list can be-80 to-90, and the allowable range of the erasing times of the twentieth idle block linked list can be-90 to-100. And adding the data blocks into different idle block linked lists according to the difference between the data block PE and the mean value PE, wherein the current data block is an idle data block, the erasing times are 25 times, and the erasing mean value is 100, so that the current data block can be classified into an eighteenth idle block linked list.
S102: and when detecting that the idle block linked list meeting the wear leveling condition exists, setting a reset label for the block corresponding to the data block with the lowest erasing frequency.
In this application, when it is detected that there is a free block linked list satisfying a wear leveling condition, a wear leveling operation is started, where the wear leveling operation may include S102, setting a reset tag for a block corresponding to a data block with the lowest erase frequency, and S103. Satisfying the wear leveling condition may be, for example, if the number of data blocks included in the free block linked list that is lower than the erase mean is lower than 8, starting wear leveling. The zone corresponding to the data block with low PE value can be selected to set a recormed reset mark, and the host end is waited to issue a reset instruction to the zone.
S103: and if the block reset instruction issued by the host end is not received within the preset time threshold, taking the data block with the lowest erasing frequency in each dirty block linked list as a source data block, and taking the data block with the highest erasing frequency in each idle block linked list as a target data block for data transfer.
Wherein, the preset time threshold can be determined according to the actual application scenario, for example, 30s can be selected, if within 30s, the block reset command of the block has not been issued, selecting the zone with low PE from the dirty block linked list as a source data block, selecting the data block with high PE from the idle block linked list as a target data block, moving the data, adding the source data block into the idle block linked list and the target data block into the dirty block linked list after the moving is finished and the block resetting instruction is finished, thus, the data transfer is realized by improving and exchanging the data blocks with low erasing times in the dirty block linked list and the data blocks with high erasing times in the idle block linked list, the total erasing times of the data blocks in the dirty block linked list are increased, the total erasing times of the data blocks in the idle block linked list are reduced, the number of the data blocks in the idle block linked list, which are lower than the average erasing times, is increased, therefore, when zoneopen applies for the data block, the data block with low erasing times can be guaranteed to be provided all the time.
S104: and when a request for applying for the data block is received, selecting the data block from the idle block chain table with the lowest erasing times.
After the wear leveling in S102 and S103, when the zone open newly applies for a data block, a data block with a low PE can be provided to the zone open all the time.
In the technical scheme provided by the embodiment of the invention, the data blocks are classified into different tables according to the difference between the erasing times and the erasing mean value to realize priority discrimination, so that repeated operation caused by comparison between every two data blocks is avoided, and the priority classification efficiency of the data blocks is improved; the data moving is realized by improving and exchanging the data blocks with low erasing times in the dirty block linked list and the data blocks with high erasing times in the idle block linked list, the total erasing times of the data blocks in the dirty block linked list is increased, the total erasing times of the data blocks in the idle block linked list is reduced, and the number of the data blocks which are lower than the average erasing times in the idle block linked list is increased, so that the data blocks with low erasing times can be provided all the time when zoneopen applies for the data blocks, the wear balance of the solid state disk based on the ZNS protocol is realized, the wear balance of each data block in the solid state disk is favorably ensured, and the service life of the solid state disk is effectively prolonged.
In the above embodiment, how to execute the wear leveling start condition of step S102 is not limited, and a specific set of implementation methods is provided in this embodiment, as shown in fig. 2, in step S102, when it is detected that there is a situation where the total number of data blocks included in the free block chain table whose maximum value of the allowable range of the erase times is lower than the erase mean value is lower than the number threshold, a reset tag is set for a block corresponding to the free block chain table whose erase times is the lowest.
The erase mean value is an average value of erase times, the threshold value of the number may be 8, for example, but may also be other values, and may be determined mainly according to the requirement of wear leveling and the total number of data blocks included in the table, which is not limited in this application.
As another alternative, S104 may include:
s1041: and when a request for applying for the data block is received, determining a target idle block linked list with the lowest erasing times from all the idle block linked lists.
S1042: and feeding back the data block with the lowest erasing times in the target idle block linked list.
In another embodiment, it is understood that, when the erasure average value changes, the data blocks included in the free block linked list and the dirty block linked list change, and based on this, the present application may further include:
s105: and when an erasing mean value changing instruction is received, adjusting the data blocks stored in each idle block chain table and each dirty block chain table based on the difference value between the current erasing times of the data blocks and the updated erasing mean value.
In addition, it can be understood that there may be a case where a large difference between the wear frequency of a large number of dirty data blocks and the erase mean value exists in the solid state disk, and each table establishes a limit based on the wear threshold and the erase mean value, so that the wear frequency of each data block in the solid state disk may be randomized within a preset random range according to the block logic number randomization algorithm, and the specific process of the wear frequency randomization may refer to the implementation process of the block logic number randomization algorithm described in the related art, and thus, details are not repeated here. That is, based on the above-described embodiments, the present application may further include:
s106: and randomizing the abrasion times of each dirty data block in the solid state disk according to a block logic number randomizing algorithm.
It should be noted that, in the present application, there is no strict sequential execution order among the steps, and as long as a logical order is met, the steps may be executed simultaneously or according to a certain preset order, and fig. 1 to fig. 2 are only schematic manners, and do not represent only such an execution order.
The embodiment of the invention also provides a corresponding device for the solid state disk wear leveling method, so that the method has higher practicability. Wherein the means can be described separately from the functional module point of view and the hardware point of view. In the following, the solid state disk wear leveling device provided by the embodiment of the present invention is introduced, and the solid state disk wear leveling device described below and the solid state disk wear leveling method described above may be referred to correspondingly.
Based on the angle of the functional module, referring to fig. 3, fig. 3 is a structural diagram of a solid state disk wear leveling apparatus according to an embodiment of the present invention, where the apparatus may include:
a table pre-construction module 301, configured to pre-construct a plurality of idle block linked lists and dirty block linked lists, which are prioritized by data block erasure times and used for storing data blocks; the erasing times of the data blocks in the same idle block linked list or dirty block linked list are within the same allowable range of the erasing times, and the number of the tables is determined based on a preset abrasion threshold value and an erasing average value.
A data block classification module 302, configured to classify each data block into an idle block linked list or a dirty block linked list based on an erase frequency and an erase mean difference, a block type, and an erase frequency allowable range corresponding to each table; the block types are free blocks and dirty data blocks.
The wear leveling processing module 303 is configured to set a reset tag for a block corresponding to a data block with the lowest erasure number when detecting that an idle block linked list satisfying a wear leveling condition exists; and if the block reset instruction issued by the host end is not received within the preset time threshold, taking the data block with the lowest erasing frequency in each dirty block linked list as a source data block, and taking the data block with the highest erasing frequency in each idle block linked list as a target data block for data transfer.
And the data block providing module 304 is configured to, when a request for applying for a data block is received, select a data block from the free block chain table with the lowest erasure number.
Optionally, in some embodiments of this embodiment, referring to fig. 4, for example, the apparatus may further include a table updating module 305, where the table updating module 305 may be configured to, after receiving the erase mean change instruction, adjust the data blocks stored in each free block chain table and each dirty block chain table based on a difference between a current number of times of erasing the data block and an updated erase mean. The method further includes a randomizing module 306, which is specifically configured to randomize the wear times of each dirty data block in the solid state disk according to a block logical number randomizing algorithm.
In other embodiments of this embodiment, the wear leveling processing module 303 is specifically configured to, when it is detected that there is a situation where the total number of data blocks included in the free block chain table whose maximum value of the allowable range of the erase times is lower than the erase mean is lower than a number threshold, set a reset tag for a block corresponding to the free block chain table with the lowest erase times.
In addition, in an alternative implementation, the data block providing module 304 may be configured to determine, when a request for applying for a data block is received, a target idle block linked list with the lowest erasing frequency from each idle block linked list; and feeding back the data block with the lowest erasing times in the target idle block linked list.
The functions of the functional modules of the wear leveling device for the solid state disk according to the embodiment of the present invention may be specifically implemented according to the method in the embodiment of the method, and the specific implementation process may refer to the related description of the embodiment of the method, which is not described herein again.
Therefore, the embodiment of the invention realizes the wear balance of the solid state disk based on the ZNS protocol, and effectively prolongs the service life of the solid state disk.
The solid state disk wear leveling device mentioned above is described from the perspective of a functional module, and further, the present application also provides a solid state disk wear leveling device described from the perspective of hardware. Fig. 5 is a structural diagram of another solid state disk wear leveling device according to an embodiment of the present application. As shown in fig. 5, the apparatus comprises a memory 50 for storing a computer program;
the processor 51 is configured to implement the steps of the solid state disk wear leveling method according to the above embodiments when executing the computer program.
The processor 51 is configured to implement the steps of the data access and storage method of the board chip mentioned in the above embodiments when executing the computer program.
The processor 51 may include one or more processing cores, such as a 4-core processor, an 8-core processor, and the like. The processor 51 may be implemented in at least one hardware form of a DSP (Digital Signal Processing), an FPGA (Field-Programmable Gate Array), and a PLA (Programmable Logic Array). In some embodiments, the processor 51 may be integrated with a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content required to be displayed on the display screen. In some embodiments, the processor 51 may further include an AI (Artificial Intelligence) processor for processing computing operations related to machine learning.
Memory 50 may include one or more computer-readable storage media, which may be non-transitory. Memory 50 may also include high speed random access memory, as well as non-volatile memory, such as one or more magnetic disk storage devices, flash memory storage devices. In this embodiment, the memory 50 is at least used for storing the following computer program 501, wherein after being loaded and executed by the processor 51, the computer program can implement the relevant steps of the testing method disclosed in any of the foregoing embodiments. In addition, the resources stored in the memory 50 may also include an operating system 502, data 503, and the like, and the storage manner may be a transient storage manner or a permanent storage manner. Operating system 502 may include Windows, Unix, Linux, etc. Data 503 may include, but is not limited to, data corresponding to test results, and the like.
In some embodiments, the data access device of the board chip may further include a display screen 52, an input/output interface 53, a communication interface 54, a power supply 55, and a communication bus 56.
Those skilled in the art will appreciate that the structure shown in fig. 5 does not constitute a limitation to the data access means of the board chip, and may include more or fewer components than those shown, for example, sensor 57.
The functions of the functional modules of the wear leveling device for the solid state disk according to the embodiment of the present invention may be specifically implemented according to the method in the embodiment of the method, and the specific implementation process may refer to the related description of the embodiment of the method, which is not described herein again.
Therefore, the embodiment of the invention realizes the wear balance of the solid state disk based on the ZNS protocol, and effectively prolongs the service life of the solid state disk.
It is understood that, if the solid state disk wear leveling method in the above embodiments is implemented in the form of a software functional unit and sold or used as a stand-alone product, it may be stored in a computer readable storage medium. Based on such understanding, the technical solutions of the present application may be substantially or partially implemented in the form of a software product, which is stored in a storage medium and executes all or part of the steps of the methods of the embodiments of the present application, or all or part of the technical solutions. And the aforementioned storage medium includes: a U disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), an electrically erasable programmable ROM, a register, a hard disk, a removable magnetic disk, a CD-ROM, a magnetic or optical disk, and other various media capable of storing program codes.
Based on this, an embodiment of the present invention further provides a computer-readable storage medium, which stores a solid state disk wear leveling program, where the solid state disk wear leveling program is executed by a processor, and the steps of the solid state disk wear leveling method according to any one of the above embodiments are provided.
The functions of the functional modules of the computer-readable storage medium according to the embodiment of the present invention may be specifically implemented according to the method in the foregoing method embodiment, and the specific implementation process may refer to the related description of the foregoing method embodiment, which is not described herein again.
Therefore, the embodiment of the invention realizes the wear balance of the solid state disk based on the ZNS protocol, and effectively prolongs the service life of the solid state disk.
The embodiments are described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same or similar parts among the embodiments are referred to each other. The device disclosed by the embodiment corresponds to the method disclosed by the embodiment, so that the description is simple, and the relevant points can be referred to the method part for description.
Those of skill would further appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware, computer software, or combinations of both, and that the various illustrative components and steps have been described above generally in terms of their functionality in order to clearly illustrate this interchangeability of hardware and software. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present invention.
The method, the apparatus, and the computer-readable storage medium for wear leveling of a solid state disk provided in the present application are described in detail above. The principles and embodiments of the present invention are explained herein using specific examples, which are presented only to assist in understanding the method and its core concepts. It should be noted that, for those skilled in the art, it is possible to make various improvements and modifications to the present invention without departing from the principle of the present invention, and those improvements and modifications also fall within the scope of the claims of the present application.