Hard disk garbage collection method and device, electronic equipment and storage medium
By using hash table to search and garbage collection based on data efficiency during hard disk garbage collection, the problem of opening a large number of erasing units during hard disk garbage collection is solved, improving efficiency and reducing the requirements for computing power.
Patent Information
- Application Number
- CN202510199862.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-21
- Publication Date
- 2025-06-10
AI Technical Summary
When collecting hard disk garbage, a large number of erasing units need to be opened at the same time, resulting in too high water level lines and high computing power required, which affects write amplification performance and random write performance.
By obtaining the number of free erase blocks of the hard disk in flexible data placement mode, if it is less than the garbage collection threshold, the erase blocks mounted in the recycling area of the hard disk are found from the table header of the hash table, and garbage collection is efficiently performed based on the data of the mounted erase block.
It reduces the computing power requirements during hard disk garbage collection, improves recycling efficiency, and reduces the impact on write amplification performance and random write performance.
Smart Images

Figure CN120123260A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the technical field of hard disks, and in particular, to a hard disk garbage collection method, apparatus, electronic device, and storage medium. Background Art
[0002] In an SSD (Solid-State Drive) that supports FDP (Flexible Data Placement), a single RG (Reclaim Group) contains multiple RUH (Reclaim Unit Handler).
[0003] In the related art, each RUH is responsible for managing a group of RUs (Reclaim Unit). During the GC (Garbage Collection) operation, to maintain the isolation of data streams, the RU data of different RUH cannot be mixed and processed in the same RU. The GC process is also divided into multiple independent data streams, and the data of each stream is only reclaimed through its dedicated GC manager.
[0004] However, in the related art during hard disk garbage collection, a large number of erase units usually need to be opened simultaneously for data recovery, resulting in a high water level line during the recovery process, that is, the lowest standard of the remaining writable space, requiring high computing power, thereby affecting the write amplification performance and random write performance. Summary of the Invention
[0005] This application provides a hard disk garbage collection method, apparatus, electronic device, and storage medium to at least solve the problem in the related art that during hard disk garbage collection, a large number of erase units usually need to be opened simultaneously for data recovery, requiring high computing power and affecting the write amplification performance and random write performance.
[0006] This application provides a hard disk garbage collection method, including: obtaining the number of idle erase blocks of the hard disk in the flexible data placement mode; if the number of idle erase blocks is less than the garbage collection threshold, searching for the erase blocks mounted in the recovery area of the hard disk from the head of the hash table, where the data availability rate of the used erase blocks is mounted at the head of the hash table; performing garbage collection on the recovery area of the hard disk according to the data availability rate of the mounted erase blocks.
[0007] The present application also provides a hard disk garbage collection device, including: an acquisition module, configured to acquire the number of idle erasure blocks of the hard disk in the flexible data placement mode; a search module, configured to, if the number of idle erasure blocks is less than the garbage collection threshold, search for the erasure blocks mounted in the recovery area of the hard disk from the head of the hash table, where the data efficiency of the used erasure blocks is mounted at the head of the hash table; and a recovery module, configured to perform garbage collection on the recovery area of the hard disk according to the data efficiency of the mounted erasure blocks.
[0008] The present application also provides an electronic device, including: a memory, configured to store a computer program; and a processor, configured to implement the steps of any of the above hard disk garbage collection methods when executing the computer program.
[0009] The present application also provides a computer-readable storage medium, in which a computer program is stored, and when the computer program is executed by a processor, the steps of any of the above hard disk garbage collection methods are implemented.
[0010] An embodiment of the present application also provides a computer program product, where the computer program product includes a computer program, and when the computer program is executed by a processor, the steps in any of the above embodiments of the hard disk garbage collection method are implemented.
[0011] An embodiment of the present application also provides another computer program product, including a non-volatile computer-readable storage medium, where the non-volatile computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps in any of the above embodiments of the hard disk garbage collection method are implemented.
[0012] Through the present application, since the data efficiency of the used erasure blocks is mounted at the head of the hash table, that is, before the hard disk garbage collection, the data efficiency of the used erasure blocks has been recorded through the hash table, and the data efficiency can effectively reflect the usage of the erasure blocks. Therefore, during the hard disk garbage collection, the appropriate erasure blocks can be determined from the used erasure blocks through the data efficiency to perform garbage collection on the recovery area of the hard disk. Since the hash table has completed the recording of the data efficiency before the hard disk garbage collection, the appropriate erasure blocks can be quickly and accurately determined by searching the hash table, improving the efficiency of the hard disk garbage collection, without the need to open a large number of erasure units for data recovery, reducing the computing power requirements during the hard disk garbage collection, and reducing the impact on the write amplification performance and random write performance during the hard disk garbage collection. Therefore, the problem in the related art that a large number of erasure units usually need to be opened simultaneously for data recovery during the hard disk garbage collection, requiring high computing power and affecting the write amplification performance and random write performance, can be solved, achieving the technical effect of accurately finding the appropriate erasure blocks for hard disk garbage collection with a smaller memory and reducing the computing power requirements during the hard disk garbage collection. BRIEF DESCRIPTION OF THE DRAWINGS
[0013] To more clearly illustrate the embodiments of the present application, the following will briefly introduce the drawings required in the embodiments. Obviously, the drawings in the following description are only some embodiments of the present application. For those of ordinary skill in the art, without creative efforts, other drawings can be obtained based on these drawings.
[0014] Figure 1 It is a schematic flowchart of the hard disk garbage collection method provided by the embodiment of the present application;
[0015] Figure 2 It is a schematic diagram of the recycling area division provided by an embodiment of the present application;
[0016] Figure 3 It is a schematic flowchart of the hard disk garbage collection method provided by an embodiment of the present application;
[0017] Figure 4 It is a schematic block diagram of the hard disk garbage collection device provided by the embodiment of the present application. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0018] The following will clearly and completely describe the technical solutions in the embodiments of the present application with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only some embodiments of the present application, not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts belong to the protection scope of the present application.
[0019] It should be noted that in the description of the present application, the terms "including", "comprising" or any other variant thereof are intended to cover a non-exclusive inclusion, so that a process, method, article or device including 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 device. The terms "first", "second", etc. in the present application are used to distinguish similar objects, not to describe a specific order or sequence.
[0020] To enable those skilled in the art of the present technology to better understand the solution of the present application, the following will further describe the present application in detail with reference to the drawings and specific embodiments.
[0021] The embodiment of the present application provides a hard disk garbage collection method. Using the hash sorting method, in the case of multi-stream data isolation, relatively accurate recycling targets can be selected during the source selection process with lower computing power and less memory.
[0022] The following will describe the hard disk garbage collection method with reference to the drawings. Specifically,Figure 1 A flowchart showing a method for hard disk garbage collection provided by an embodiment of the present application. The method includes the following steps:
[0023] In step S101, obtain the number of free erase blocks in the hard disk under the flexible data placement mode.
[0024] Among them, the flexible data placement mode is a technology for optimizing data management and garbage collection processes in solid-state drives. It can improve the overall performance of solid-state drives, extend the service life, and reduce the write amplification effect through intelligent and efficient data placement strategies; an erase block is a unit block composed of a group of erase units with independent performances for better management of solid-state drives. Each erase block corresponds to an erase recovery unit, and the erase unit can be the minimum erase unit of flash memory in the embodiment of the present application.
[0025] It can be understood that in the embodiment of the present application, it is first necessary to obtain the number of free erase blocks in the hard disk under the flexible data placement mode, including the number of erase blocks that are neither occupied by data nor marked for garbage collection processing.
[0026] In the embodiment of the present application, before obtaining the number of free erase blocks in the hard disk under the flexible data placement mode, it further includes: identifying the erase blocks to be recycled; during the garbage collection process, detecting the change value of the amount of valid data in the erase blocks to be recycled; adjusting the ratio of host writes to garbage collection according to the change value of the amount of valid data.
[0027] Among them, the ratio of host writes to garbage collection is:
[0028] Host_write∶GC_write=(tdfc–vdfc)∶vdfc
[0029] Among them, Host_write is the host write; GC_write is the garbage collection; vdfc is the amount of valid data in the erase blocks to be recycled; (tdfc–vdfc) is the amount of invalid data in the erase blocks to be recycled, where tdfc is the total amount of data in the erase blocks to be recycled.
[0030] It can be understood that in the embodiment of the present application, before obtaining the number of free erase blocks in the hard disk under the flexible data placement mode, it is first necessary to identify which erase blocks are expected to be included in the upcoming garbage collection process, and detect the change in the amount of valid data in these erase blocks to be recycled during the garbage collection process. Based on the amount of valid data and the amount of invalid data in the erase blocks to be recycled, according to the above formula, calculate and adjust the proportional relationship between host writes and garbage collection writes to ensure that free erase blocks will not be exhausted during the entire recycling process, maintain an efficient operating state, and effectively achieve optimized resource utilization.
[0031] In step S102, if the number of idle erase blocks is less than the garbage collection threshold, look for the erase blocks mounted in the recovery area of the hard disk from the head of the hash table, where the data efficiency of the used erase blocks is mounted at the head of the hash table.
[0032] The garbage collection threshold represents the critical value for the hard disk to start the garbage collection operation, and can be specifically set according to the computing resources of the device during actual use. The hash table is pre-constructed based on the data efficiency of each used erase block, and the specific construction method will be described in detail below and will not be elaborated here.
[0033] It can be understood that if it is detected that the number of idle erase blocks is lower than the set garbage collection threshold, it means that the number of idle erase blocks is small and the garbage collection function of the hard disk needs to be started. Therefore, in the embodiment of the present application, when it is detected that the number of idle erase blocks is lower than the set garbage collection threshold, look for the suitable erase blocks for recovery in the recovery area of the hard disk from the head of the pre-constructed hash table. Since the data efficiency of the used erase blocks has been recorded in the hash table before the hard disk garbage collection, the appropriate erase blocks can be quickly and accurately determined by looking up the hash table, improving the efficiency of the hard disk garbage collection, without opening a large number of erase units for data recovery, reducing the computing power requirements during the hard disk garbage collection, and reducing the impact on the write amplification performance and random write performance during the hard disk garbage collection.
[0034] In some embodiments, before looking for the erase blocks mounted in the recovery area of the hard disk from the head of the hash table, it includes: during the operation of the hard disk, identify the data efficiency of the used erase blocks; mount the data efficiency of the used erase blocks at the head of the hash table; use the hash sorting algorithm to sort the data efficiency in the hash table.
[0035] The specific calculation method of the data efficiency of the used erase blocks is as follows:
[0036] Data efficiency = effective data volume * 1000 / erase block capacity
[0037] Using the hash sorting algorithm to sort the data efficiency in the hash table, multiple linked lists can be established, and according to the data efficiency of the erase blocks, the erase blocks are assigned to different linked lists, so as to realize sorting the used erase blocks in the hash table according to the data efficiency.
[0038] It can be understood that before looking up the erased blocks mounted in the recycling area of the hard disk from the head of the hash table in the embodiments of the present application, it is necessary to calculate and identify the data efficiency of each used erased block, and based on these data efficiencies, the information of the erased blocks is dynamically mounted to the head of the hash table according to the hash sorting algorithm to obtain a hash table sorted by data efficiency, so as to ensure that when garbage collection is required, the erased blocks with low data efficiency and suitable for recycling can be quickly found starting from the head of the hash table, thereby improving the garbage collection efficiency and optimizing the storage resource management.
[0039] In step S103, garbage collection is performed on the recycling area of the hard disk according to the data efficiency of the mounted erased blocks.
[0040] Among them, the recycling area of the hard disk usually refers to the storage area that needs to perform garbage collection.
[0041] It can be understood that the data efficiency can effectively reflect the usage of the erased blocks. Therefore, during the hard disk garbage collection, the appropriate erased blocks can be determined from the used erased blocks through the data efficiency to perform garbage collection on the recycling area of the hard disk.
[0042] In the embodiments of the present application, performing garbage collection on the recycling area of the hard disk according to the data efficiency of the mounted erased blocks includes: determining the source erased block according to the data efficiency of the mounted erased blocks; selecting the destination erased block from the free erased blocks, and using the erase recovery control unit to recycle the data of the source erased block to the destination erased block.
[0043] Among them, the source erased block is the erased block with a relatively low amount of valid data and is selected as the source of garbage collection. The method for determining whether an erased block is a source erased block will be described in detail below and will not be elaborated here; the erase recovery control unit is responsible for managing and controlling the operations of specific erase recovery units.
[0044] It can be understood that when the embodiments of the present application perform garbage collection, first, the source erased block is determined based on the data efficiency of each erased block mounted in the hash table, and then one or more destination erased blocks are selected from the existing free erased block pool, and the erase recovery control unit is used to migrate the valid data in the selected source erased block to the destination erased block, so as to clean and release the space of the source erased block and make it a new free erased block, thereby optimizing the use of storage resources and improving the overall performance of the system.
[0045] In an embodiment of the present application, determining a source erase block according to the data efficiency of the mounted erase blocks includes: finding the erase blocks that have been scanned by the erase recovery control unit; obtaining the sum of the amounts of valid data in the erase blocks that have been scanned by the erase recovery control unit, and calculating the sum of the amounts of invalid data in the erase blocks that have been scanned by the erase recovery control unit according to the sum of the amounts of valid data; calculating the average data capacity of the erase blocks that have been scanned by the erase recovery control unit, and if both the sum of the amounts of invalid data and the sum of the amounts of valid data are greater than the average data capacity, selecting a source erase block from the erase blocks that have been scanned by the erase recovery control unit according to the data efficiency.
[0046] Among them, the sum of the amounts of invalid data is calculated by subtracting the sum of the amounts of valid data from the sum of the total amounts of data in the erase blocks that have been scanned by the erase recovery control unit.
[0047] It can be understood that in an embodiment of the present application, determining a source erase block according to the data efficiency of the mounted erase blocks is implemented by the following method: first, finding the erase blocks that have been scanned by each erase recovery control unit, obtaining the sum of the amounts of valid data in these erase blocks, and calculating the sum of the amounts of invalid data in these erase blocks according to the sum of the amounts of valid data, then calculating the average data capacity of all the erase blocks scanned by the erase recovery control unit, and making the following judgment based on the above three data. If both the sum of the amounts of invalid data and the sum of the amounts of valid data in the erase blocks scanned by the erase recovery control unit are greater than the average data capacity, selecting the suitable erase blocks as source erase blocks from these scanned erase blocks according to the data efficiency of each erase block, and recording the maximum value of the data efficiency in the source erase blocks.
[0048] In an embodiment of the present application, after using the erase recovery control unit to recycle the data of the source erase block to the destination erase block, it further includes: using the erase recovery control unit to find the erase blocks with a data efficiency lower than the switching threshold; if the erase recovery control unit finds an erase block with a data efficiency lower than the switching threshold, using the erase block with a data efficiency lower than the switching threshold as the source erase block; if the erase recovery control unit does not find an erase block with a data efficiency lower than the switching threshold, switching the erase recovery control unit.
[0049] Among them, the switching threshold is the maximum value of the data efficiency recorded in the source erase blocks in the above steps.
[0050] It can be understood that after the data of the source erasure block is recycled to the destination erasure block by the erasure recycling control unit in the embodiment of the present application, the erasure recycling control unit will continue to search for other erasure blocks with a data efficiency lower than the switching threshold. If such an erasure block is found, it will be regarded as a new source erasure block, and garbage collection operations will be performed on this source erasure block; if the erasure recycling control unit fails to find any erasure block with a data efficiency lower than the switching threshold, it indicates that all erasure blocks managed by the current erasure recycling control unit are not suitable for immediate garbage collection. At this time, the system will switch to another erasure recycling control unit to continue searching for and processing other erasure blocks that may be more suitable for garbage collection.
[0051] In the embodiment of the present application, after the data of the source erasure block is recycled to the destination erasure block by the erasure recycling control unit, it further includes: after it is recognized that the destination erasure block is full, obtaining the filling amount of the destination erasure unit corresponding to the erasure recycling control unit; if the filling amount of the destination erasure unit of the erasure recycling control unit is less than the preset value, selecting a new erasure block from the idle erasure blocks to recycle the data of the source erasure block; if the filling amount of the destination erasure unit of the erasure recycling control unit is greater than or equal to the preset value, switching the erasure recycling control unit.
[0052] Among them, the preset value is the filling amount record value of the destination erasure unit before the current erasure recycling control unit.
[0053] It can be understood that after the data of the source erasure block is recycled to the destination erasure block by the erasure recycling control unit in the embodiment of the present application, if it is recognized that a destination erasure block is full, it is necessary to obtain and judge whether the filling amount of the destination erasure unit of the current erasure recycling control unit reaches the preset value. If the filling amount of the destination erasure block is less than the preset value, it means that there is still space in this destination erasure block to continue receiving more data, so a new erasure block is selected from the idle erasure block pool, and it is continued to use it to recycle the remaining data in the source erasure block; if the filling amount of the destination erasure block has reached the preset value, it indicates that the current destination erasure block is approaching its capacity limit. At this time, the system will switch to another erasure recycling control unit to perform subsequent garbage collection work.
[0054] In the embodiment of the present application, before garbage collection is performed on the recycling area of the hard disk according to the data efficiency of the mounted erasure blocks, it further includes: obtaining the data efficiency of the erasure blocks in the recycling area of the hard disk; determining the number of erasure blocks in the corresponding recycling area according to the data efficiency in the recycling area.
[0055] Among them, the number of erasure blocks in the corresponding recovery area is determined according to the data efficiency rate in the recovery area. Specifically, for the high-frequency recovery area, such as the low-effective data rate area, a more detailed division is adopted, while for other areas with lower-frequency recovery, a coarser division method is used. For example, erasure blocks with a lower data efficiency rate are divided into areas with a 10% interval, and the number of erasure blocks in the divided recovery area can be relatively large; those with a higher data efficiency rate are divided into areas with a 5% interval; and for areas close to the average data efficiency rate, a more detailed division is carried out in units of 2‰, and the number of erasure blocks in the divided recovery area is small, and only one erasure block is mounted on average in each divided area as much as possible.
[0056] It can be understood that in the embodiment of the present application, the recovery area is divided into different parts according to the data efficiency rate. For the high-frequency recovery area, a more detailed division method is adopted, and the division of other areas is coarser. For example, the area close to the average data efficiency rate is a high-frequency recovery area, and a fine division method is adopted. For example, 2‰ is used as the division unit to ensure that the division in this area is as detailed as possible, and only one erasure block is mounted in each divided area as much as possible, so as to improve the search and processing efficiency. For the low-frequency recovery area with a higher data efficiency rate, a coarser division method is used, and more erasure blocks can be mounted in these areas.
[0057] According to the hard disk garbage collection method proposed in the embodiment of the present application, since the data efficiency rate of the used erasure blocks is mounted in the header of the hash table, that is, before the hard disk garbage collection, the data efficiency rate of the used erasure blocks has been recorded through the hash table, and the data efficiency rate can effectively reflect the usage of the erasure blocks. Therefore, during the hard disk garbage collection, the appropriate erasure blocks can be determined from the used erasure blocks through the data efficiency rate to perform garbage collection on the recovery area of the hard disk. Since the hash table has completed the recording of the data efficiency rate before the hard disk garbage collection, the appropriate erasure blocks can be quickly and accurately determined by searching the hash table, improving the efficiency of the hard disk garbage collection, without the need to open a large number of erasure units for data recovery, reducing the computing power requirements during the hard disk garbage collection, and reducing the impact on the write amplification performance and random write performance during the hard disk garbage collection. Therefore, it can solve the problem in the related art that during the hard disk garbage collection, a large number of erasure units usually need to be opened simultaneously for data recovery, requiring high computing power and affecting the write amplification performance and random write performance, and achieving the technical effect of accurately finding the appropriate erasure blocks for hard disk garbage collection with a smaller memory and reducing the computing power requirements during the hard disk garbage collection.
[0058] Through the description of the above embodiments, those skilled in the art can clearly understand that the method according to the above embodiments can be implemented by means of software plus a necessary general hardware platform. Of course, it can also be implemented by hardware, but in many cases, the former is a better implementation method.
[0059] The hard disk garbage collection method is further described below through a specific embodiment.
[0060] As Figure 2 shown, in this embodiment, a hash table is first initialized and created. During the polling detection process, each used erase block is mounted to the head of the table according to the proportion of valid data. Taking a granularity of 1000 as an example, the specific calculation method is as follows:
[0061] Data efficiency = valid data volume * 1000 / erase block capacity
[0062] In the figure, taking the average value of the data efficiency as 70% and the discrete area as 60% - 80% as an example, the erase blocks with lower efficiency are divided into areas with 10% as a unit, the ones with higher efficiency are divided into areas with 5% as a unit, and the area close to the average value of 60% - 80% is divided more finely, with 0.2% as a unit. During the program operation, all erase blocks are continuously scanned, and their positions are continuously updated according to the real-time data efficiency.
[0063] When the remaining amount of free erase blocks drops to the water level line, the source is selected according to the hash table. Each erase recovery control unit initializes a structure, which contains the following information: the erase block with the lowest valid data rate, the number of erased blocks that have been scanned, the cumulative value of valid data, and the cumulative capacity.
[0064] As Figure 3 , start searching from the area with the lowest valid data rate to see if there is an erase block mounted. If there is an erase block mounted, then check each of the erase blocks, and perform cumulative calculations on the number of erased blocks that have been scanned, the cumulative value of valid data, and the cumulative capacity of the erase recovery control unit where it is located. And when the erase recovery control unit scans an erase block for the first time, it is recorded as the erase block with the lowest valid data rate. After searching each head of the table, or after scanning the number of erase blocks equal to the number of erase recovery control units in a head of the table, check whether each erase recovery control unit meets the following conditions:
[0065] 1. The sum of the invalid data volumes of all erase blocks is greater than the average data capacity of these erase blocks, that is: (all_tdfc - all_vdfc) > Average_tdfc
[0066] 2. The valid data volume is greater than the average capacity, that is:
[0067] all_vdfc > Average_tdfc
[0068] If not found, keep looking backward. If these two conditions are met, record how many erased blocks have been scanned, how many destination erased blocks are to be recycled, and the current hash table area, i.e., the maximum valid data rate of the erased blocks recycled in the current erase and recycle control unit, and start garbage collection on this qualified erase and recycle control unit.
[0069] When a source erased block has been recycled, do not switch the erase and recycle control unit. Continue to look in this erase and recycle control unit to see if there is an erased block with a valid data rate lower than the previously recorded maximum. If there is, continue to select the erased block with the lowest valid data rate in the current erase and recycle control unit for recycling; otherwise, switch the erase and recycle control unit.
[0070] When a destination erased block is full, it is necessary to determine whether the fill level of the destination erase units in the current erase and recycle control unit has reached the previously recorded value. If not, continue to open a new free erased block to recycle the data in the current erase and recycle control unit; if it has reached the recorded value, reselect the erase and recycle control unit to initiate garbage collection until the water level is recovered above.
[0071] To ensure that free erased blocks are not exhausted during the recycling process, flow control is required to ensure the ratio of host writes to garbage collection. The flow control principle is to set the amount of data written for garbage collection and the amount of data written by the host according to the ratio of the amount of valid data to the amount of invalid data in the currently recycled erased blocks, i.e.:
[0072] Host_write∶GC_write=(tdfc–vdfc)∶vdfc
[0073] In the flexible data placement mode, the recycling is based on a group of erased blocks. It is necessary to accumulate the erased blocks expected to be recycled, calculate the total capacity and valid data, and then use this ratio as the basis for flow control. Since the garbage collection cycle of the erase and recycle control unit group is relatively long, and the flow control error will increase with the growth of the cycle. To reduce the overall flow control error, in this embodiment, it is possible to record the erased blocks expected to be recycled before the start of the entire cycle, regularly detect the change of vdfc of these erased blocks during the recycling process, and adjust the flow control ratio according to this change, so as to give a more accurate flow control.
[0074] In summary, in the embodiment of the present application, according to the hash sorting method, the written erasure blocks are stored in a hash table for sorting according to the data efficiency, and at the same time, the number of free erasure blocks of the hard disk in the flexible data placement mode is obtained. If the number is less than the garbage collection threshold, the erasure blocks mounted in the recovery area of the hard disk are searched from the head of the hash table, and garbage collection is performed on the recovery area of the hard disk according to the data efficiency of the mounted erasure blocks. The technical effects of using less memory and reducing the computing power requirements during the process and when selecting the source finally are achieved.
[0075] An embodiment of the present application also provides a hard disk garbage collection device. Figure 4 It is a block diagram of the hard disk garbage collection device, as Figure 4 shown. The hard disk garbage collection device 10 includes: an acquisition module 201, a search module 202, and a recovery module 203.
[0076] Among them, the acquisition module 201 is used to obtain the number of free erasure blocks of the hard disk in the flexible data placement mode; the search module 202 is used to search for the erasure blocks mounted in the recovery area of the hard disk from the head of the hash table if the number of the free erasure blocks is less than the garbage collection threshold, wherein the data efficiency of the used erasure blocks is mounted in the head of the hash table; the recovery module 203 is used to perform garbage collection on the recovery area of the hard disk according to the data efficiency of the mounted erasure blocks.
[0077] In the embodiment of the present application, for performing garbage collection on the recovery area of the hard disk according to the data efficiency of the mounted erasure blocks, the recovery module 203 is further used to: determine a source erasure block according to the data efficiency of the mounted erasure blocks; select a destination erasure block from the free erasure blocks, and use the erasure recovery control unit to recover the data of the source erasure block to the destination erasure block.
[0078] In the embodiment of the present application, for determining a source erasure block according to the data efficiency of the mounted erasure blocks, the recovery module 203 is further used to: search for the erasure blocks that the erasure recovery control unit has scanned; obtain the sum of the valid data amounts of the erasure blocks that the erasure recovery control unit has scanned, and calculate the sum of the invalid data amounts of the erasure blocks that the erasure recovery control unit has scanned according to the sum of the valid data amounts; calculate the average data capacity of the erasure blocks that the erasure recovery control unit has scanned. If both the sum of the invalid data amounts and the sum of the valid data amounts are greater than the average data capacity, select a source erasure block from the erasure blocks that the erasure recovery control unit has scanned according to the data efficiency, and record the maximum value of the data efficiency in the source erasure blocks.
[0079] In an embodiment of the present application, a switching module is further included. Specifically, the switching module is further configured to: after the data of the source erasure block is recycled to the destination erasure block by using the erasure recycling control unit, use the erasure recycling control unit to find an erasure block with a data efficiency lower than the switching threshold; if the erasure recycling control unit finds an erasure block with a data efficiency lower than the switching threshold, use the erasure block with a data efficiency lower than the switching threshold as the source erasure block; if the erasure recycling control unit does not find an erasure block with a data efficiency lower than the switching threshold, switch the erasure recycling control unit.
[0080] In an embodiment of the present application, the switching module is further configured to: after the data of the source erasure block is recycled to the destination erasure block by using the erasure recycling control unit, it further includes: after it is recognized that the destination erasure block is full, obtaining the filling amount of the destination erasure unit corresponding to the erasure recycling control unit; if the filling amount of the destination erasure unit of the erasure recycling control unit is less than a preset value, selecting a new erasure block from the idle erasure blocks to recycle the data of the source erasure block; if the filling amount of the destination erasure unit of the erasure recycling control unit is greater than or equal to the preset value, switching the erasure recycling control unit.
[0081] In an embodiment of the present application, a partitioning module is further included. Specifically, the partitioning module is further configured to: before performing garbage collection on the recycling area of the hard disk according to the data efficiency of the mounted erasure blocks, obtaining the data efficiency of the erasure blocks in the recycling area of the hard disk; partitioning the corresponding recycling area according to the data efficiency in the recycling area, and determining the number of erasure blocks in the corresponding recycling area.
[0082] In an embodiment of the present application, an adjustment module is further included. Specifically, the adjustment module is further configured to: before obtaining the number of idle erasure blocks of the hard disk in the flexible data placement mode, identifying the erasure blocks to be recycled; during the garbage collection process, detecting the change value of the number of valid data of the erasure blocks to be recycled; adjusting the ratio of host writing and garbage collection according to the change value of the number of valid data.
[0083] For the description of the features in the corresponding embodiments of the hard disk garbage collection device, reference can be made to the relevant description in the corresponding embodiments of the hard disk garbage collection method, which will not be elaborated here one by one.
[0084] According to the hard disk garbage collection device proposed in the embodiments of the present application, since the data efficiency of the used erase blocks is mounted in the header of the hash table, that is, before the hard disk garbage collection, the data efficiency of the used erase blocks has been recorded through the hash table. The data efficiency can effectively reflect the usage of the erase blocks. Therefore, during the hard disk garbage collection, the appropriate erase blocks can be determined from the used erase blocks through the data efficiency to perform garbage collection on the recycle area of the hard disk. Since the hash table has completed the recording of the data efficiency before the hard disk garbage collection, the appropriate erase blocks can be quickly and accurately determined by searching the hash table, improving the efficiency of the hard disk garbage collection, without the need to open a large number of erase units for data recovery, reducing the computing power requirements during the hard disk garbage collection, and reducing the impact on the write amplification performance and random write performance during the hard disk garbage collection. Therefore, it can solve the problem in the related art that during the hard disk garbage collection, a large number of erase units usually need to be opened simultaneously for data recovery, requiring high computing power and affecting the write amplification performance and random write performance, achieving the technical effect of accurately finding the appropriate erase blocks for hard disk garbage collection with a smaller memory and reducing the computing power requirements during the hard disk garbage collection.
[0085] An embodiment of the present application also provides an electronic device, including a memory and a processor. A computer program is stored in the memory, and the processor is configured to run the computer program to execute the steps in any of the above embodiments of the hard disk garbage collection method.
[0086] An embodiment of the present application also provides a computer-readable storage medium, in which a computer program is stored. The computer program is configured to execute the steps in any of the above embodiments of the hard disk garbage collection method when running.
[0087] In an exemplary embodiment, the above computer-readable storage medium may include, but is not limited to: USB flash drives, read-only memories (ROM for short), random access memories (RAM for short), external hard drives, magnetic disks, or optical discs and other media that can store computer programs.
[0088] Those skilled in the art may further realize that the units and algorithm steps of each example described in combination with the embodiments disclosed herein can be implemented by electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described according to functions in the above description. Whether these functions are executed in a hardware or software manner depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered as exceeding the scope of this application.
[0089] The above has introduced in detail a hard disk garbage collection method, device, electronic device, and storage medium provided by this application. Specific examples are used herein to elaborate on the principle and implementation manner of this application. The description of the above embodiments is only used to help understand the method and its core idea of this application. It should be noted that for those of ordinary skill in the art of this technology, without departing from the principle of this application, several improvements and modifications can still be made to this application, and these improvements and modifications also fall within the protection scope of the claims of this application.
Claims
1. A hard disk garbage collection method, characterized in that: include: Get the number of free erase blocks of the hard disk in flexible data placement mode; If the number of free erase blocks is less than the garbage collection threshold, searching the header of the hash table for erase blocks mounted in the recycling area of the hard disk, wherein the header of the hash table has data efficiency of used erase blocks mounted therein; Garbage collection is performed on the recycling area of the hard disk according to the data efficiency of the mounted erase block.
2. The hard disk garbage collection method according to claim 1, characterized in that: The process of efficiently performing garbage collection on the recycling area of the hard disk according to the data of the mounted erase block comprises: Determine the source erase block based on the data efficiency of the mounted erase block; A destination erase block is selected from the idle erase blocks, and the data of the source erase block is recycled to the destination erase block by using an erase recycling control unit.
3. The hard disk garbage collection method according to claim 2, characterized in that: The step of determining the source erase block according to the data efficiency of the mounted erase block includes: Searching for erase blocks that have been scanned by the erase recovery control unit; Acquire the sum of valid data amounts of the erase blocks that have been scanned by the erase recovery control unit, and calculate the sum of invalid data amounts of the erase blocks that have been scanned by the erase recovery control unit according to the sum of valid data amounts; The average data capacity of the erase blocks that have been scanned by the erase recovery control unit is calculated. If the sum of the invalid data amount and the sum of the valid data amount are both greater than the average data capacity, a source erase block is selected from the erase blocks that have been scanned by the erase recovery control unit according to the data efficiency.
4. The hard disk garbage collection method according to claim 2, characterized in that: After the erase recovery control unit is used to recover the data of the source erase block to the destination erase block, the method further includes: Using the erase recovery control unit to find erase blocks whose data efficiency is lower than the switching threshold; If the erase recovery control unit finds an erase block whose data efficiency is lower than the switching threshold, the erase block whose data efficiency is lower than the switching threshold is used as a source erase block; If the erase recovery control unit fails to find an erase block whose data efficiency is lower than the switching threshold, the erase recovery control unit is switched.
5. The hard disk garbage collection method according to claim 2, characterized in that: After the data of the source erase block is recovered to the destination erase block by using the erase recovery control unit, the method further includes: After identifying that the destination erase block is full, obtaining the filling amount of the destination erase unit corresponding to the erase recovery control unit; If the filling amount of the destination erase unit of the erase recovery control unit is less than a preset value, a new erase block is selected from the free erase blocks to recover the data of the source erase block; If the filling amount of the destination erasing unit of the erasing recovery control unit is greater than or equal to a preset value, the erasing recovery control unit is switched.
6. The hard disk garbage collection method according to claim 1, characterized in that: Before efficiently performing garbage collection on the recycling area of the hard disk according to the data of the mounted erase block, the method further includes: Acquire the data efficiency of the erased blocks in the recovery area of the hard disk; The corresponding recycling area is divided according to the data efficiency in the recycling area, and the number of erase blocks in the corresponding recycling area is determined.
7. The hard disk garbage collection method according to claim 1, characterized in that: Before obtaining the number of free erase blocks of the hard disk in flexible data placement mode, it also includes: Identify erase blocks that are expected to be reclaimed; During the garbage collection process, detecting the change in the amount of valid data of the erase block expected to be recovered; The ratio of host writing and garbage collection is adjusted according to the change value of the amount of valid data.
8. A hard disk garbage collection device, characterized in that: include: An acquisition module, used for acquiring the number of free erase blocks of the hard disk in a flexible data placement mode; A search module, configured to search the header of the hash table for the erase blocks mounted in the recycling area of the hard disk if the number of the free erase blocks is less than the garbage collection threshold, wherein the header of the hash table has a data efficiency of the used erase blocks mounted therein; The recycling module is used to efficiently perform garbage recycling on the recycling area of the hard disk according to the data efficiency of the mounted erase block.
9. An electronic device, characterized in that: include: Memory for storing computer programs; A processor, used to implement the steps of the hard disk garbage collection method according to any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, wherein the computer program, when executed by a processor, implements the steps of the hard disk garbage collection method according to any one of claims 1 to 7.