Hard disk garbage recovery method, device, equipment and computer-readable storage medium
By creating a garbage collection state machine in a solid-state drive and performing garbage collection tasks when idle, optimizing the data transfer and erasing process, the problem of garbage collection tasks taking time and affecting user read and write requests is solved, and more efficient garbage collection and hard disk life extension is achieved.
Patent Information
- Application Number
- CN202210611287.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-31
- Publication Date
- 2025-08-12
- Estimated Expiration
- 2042-05-31
AI Technical Summary
In the prior art, garbage collection tasks are time-consuming in solid-state disks and are prone to hindering normal user read and write requests, resulting in inefficiency.
By pre-creating a garbage collection state machine, using the processor to read the state in a polled manner and perform garbage collection tasks, garbage collection is only performed when the state machine is idle, avoiding the impact on user read and write tasks, and optimizing the data transfer and erasing process.
It improves the fluency and efficiency of garbage collection tasks, reduces the impact on normal user read and write requests, and extends the service life of the hard disk.
Smart Images

Figure CN114968839B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of storage technology, and in particular to a hard disk garbage recovery method, apparatus, device, and computer-readable storage medium. Background Art
[0002] With the rapid development of internet technology, human society has entered the era of big data, where data volumes are exponentially growing. This era of big data places a greater demand on storage technology, and diverse big data applications pose significant challenges to the performance and reliability of storage systems. With the emergence and widespread use of NAND flash memory, solid-state drives (SSDs) based on NAND flash have become a hot topic in the storage industry due to their higher reliability, improved performance, and lower energy consumption.
[0003] Garbage collection is designed to recycle invalid pages of flash memory blocks in the SSD so that the flash memory blocks can be reused. It is an important function to ensure the normal operation of the SSD and is also an important factor affecting the performance of the SSD.
[0004] The garbage collection method commonly used in the industry is as follows: When the number of available flash memory blocks on the solid-state drive is insufficient, garbage collection will be triggered, and the valid data in the recovered blocks will be moved to new free blocks. After the move is completed, an erase operation will be performed to complete the recycling and reuse of the flash memory blocks.
[0005] Since both the data movement and erasure operations during the recycling process are very time-consuming, read and write failures may cause the garbage collection process to become stuck at any stage, which not only makes the garbage collection process very inefficient, but also hinders normal user read and write requests.
[0006] How to perform garbage collection tasks more smoothly, improve the execution efficiency of garbage collection tasks while reducing the impact on normal user read and write requests is a technical problem that needs to be solved by those skilled in the art. Summary of the Invention
[0007] The purpose of this application is to provide a hard disk garbage collection method, device, equipment and computer-readable storage medium, which are used to improve the fluency of garbage collection tasks, improve the execution efficiency of garbage collection tasks while reducing the impact on normal user read and write requests.
[0008] To solve the above technical problems, the present application provides a hard disk garbage collection method, comprising:
[0009] Pre-create the garbage collection state machine;
[0010] After determining that the garbage collection triggering condition is met, checking the status of the garbage collection state machine;
[0011] If the garbage collection state machine is in an idle state, the garbage collection state machine is set to a garbage collection state to perform a garbage collection task.
[0012] Optionally, if the garbage collection state machine is in an idle state, setting the garbage collection state machine to a garbage collection state to perform a garbage collection task specifically includes:
[0013] Based on the garbage collection triggering condition, if the garbage collection state machine is in an idle state, entering a target data block information acquisition state to select an idle target data block;
[0014] After the target data block is selected, the state of obtaining source data block information is entered to select the source data block;
[0015] After the source data block is selected, a data migration state is entered to migrate valid data in the source data block to the target data block;
[0016] After the data migration is completed, the source data block erasing state is entered to perform an erasing operation on the source data block to release the space of the source data block.
[0017] Optionally, selecting an idle target data block specifically includes:
[0018] If there is an idle data block in the garbage collection reserved storage space, selecting the target data block in the garbage collection reserved storage space;
[0019] If there is no free data block in the garbage collection reserved storage space, the target data block is selected outside the garbage collection reserved storage space.
[0020] Optionally, the selecting of an idle target data block is specifically:
[0021] Selecting a data block with the least number of erasures and writes among the idle data blocks as a first target data block, and selecting a data block with the most number of erasures and writes among the idle data blocks as a second target data block;
[0022] The moving of valid data in the source data block to the target data block is specifically as follows:
[0023] Hot data in the valid data of the source data block is moved to the first target data block, and cold data in the valid data of the source data block is moved to the second target data block.
[0024] Optionally, the selecting of the source data block is specifically:
[0025] A data block with a small amount of valid data and a small number of erasures and writes is selected as the source data block.
[0026] Optionally, the selecting of the source data block is specifically:
[0027] Selecting the data block with the smallest recovery evaluation value as the source data block;
[0028] The recovery estimate is calculated using the following equation:
[0029]
[0030] Wherein, value is the recycling evaluation value, α is the weighting factor, VDFC is the amount of valid data in the candidate source data block at the current moment, N df is the total amount of data that can be stored in the selected source data block, N pe is the number of erasures of the selected source data block, MAX pe is the maximum number of erase and write times among all the source data blocks to be selected.
[0031] Optionally, the trade-off factor is calculated by the following equation:
[0032]
[0033] Where α is the trade-off factor, N src_block is the number of the source data blocks to be selected, SUM block is the number of all data blocks in the hard disk, N bad_block is the number of bad blocks in the hard disk.
[0034] Optionally, the moving the valid data in the source data block to the target data block is specifically:
[0035] Aggregate valid data with similar valid data access frequency ratios into the same batch, and move the valid data in the source data blocks to the target data blocks in batches;
[0036] The effective data access frequency ratio is calculated by the following equation:
[0037]
[0038] Wherein, F is the effective data access frequency ratio, N pv is the average number of valid page data accesses in each candidate source data block at the current moment, MAX pv is the maximum number of valid page data access times in each of the to-be-selected source data blocks.
[0039] Optionally, the effective data access frequency ratios are close, specifically: a difference between effective data access frequency ratios of different effective data is greater than a frequency ratio closeness threshold;
[0040] The frequency ratio is close to the threshold value and is calculated by the following equation:
[0041]
[0042] Wherein, T is the frequency ratio close to the threshold, Page pv N is the number of page data accesses read at the current moment. pv is the average number of valid page data access times in each of the candidate source data blocks, MAX pv is the maximum number of valid page data access times in each of the selected source data blocks, MIN pv is the minimum number of access times of valid page data in each of the to-be-selected source data blocks.
[0043] Optionally, the garbage collection triggering condition is specifically: the number of free data blocks is less than a garbage collection start threshold, and / or an erroneous data block is detected.
[0044] To solve the above technical problems, the present application also provides a hard disk garbage recovery device, comprising:
[0045] Creation unit, used to pre-create the garbage collection state machine;
[0046] A checking unit, configured to check the state of the garbage collection state machine after determining that a garbage collection triggering condition is satisfied;
[0047] The execution unit is configured to set the garbage collection state machine to a garbage collection state if the garbage collection state machine is in an idle state, so as to execute a garbage collection task.
[0048] To solve the above technical problems, the present application also provides a hard disk garbage recovery device, comprising:
[0049] memory for storing computer programs;
[0050] The processor is used to execute the computer program, and when the computer program is executed by the processor, the steps of the hard disk garbage collection method as described in any one of the above are implemented.
[0051] To solve the above technical problems, the present application also provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps of the hard disk garbage collection method as described in any one of the above items are implemented.
[0052] The hard disk garbage collection method provided by this application implements the garbage collection task in the form of a state machine to improve the fluency of the garbage collection task. By pre-creating the garbage collection state machine and utilizing the characteristic that the processor processes the state machine in a polling manner to read the state and execute, if a jam occurs in the garbage collection link, it will not affect the execution of other normal user read and write tasks, and the next time the garbage collection state machine is polled, it can continue to execute from the state of the last jam. Based on this, after determining that the garbage collection trigger condition is met, the state of the garbage collection state machine is checked. If the garbage collection state machine is in an idle state, the garbage collection state machine is set to the garbage collection state to execute the garbage collection task, thereby improving the fluency of the garbage collection task, while improving the execution efficiency of the garbage collection task and reducing the impact on normal user read and write requests.
[0053] The present application also provides a hard disk garbage recovery device, equipment and computer-readable storage medium, which have the above-mentioned beneficial effects and are not described in detail here. BRIEF DESCRIPTION OF THE DRAWINGS
[0054] In order to more clearly illustrate the embodiments of the present application or the technical solutions of the prior art, the following is a brief introduction to the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0055] Figure 1 A flowchart of a hard disk garbage collection method provided in an embodiment of the present application;
[0056] Figure 2 A schematic diagram of the operation process of a garbage collection state machine provided in an embodiment of the present application;
[0057] Figure 3 A schematic diagram of the structure of a hard disk garbage collection device provided in an embodiment of the present application;
[0058] Figure 4 A structural diagram of a hard disk garbage collection device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0059] The core of this application is to provide a hard disk garbage collection method, device, equipment and computer-readable storage medium, which are used to improve the fluency of garbage collection tasks, improve the execution efficiency of garbage collection tasks while reducing the impact on normal user read and write requests.
[0060] The following will be combined with the drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0061] Example 1
[0062] Figure 1 A flowchart of a hard disk garbage collection method provided in an embodiment of the present application.
[0063] like Figure 1 As shown, the hard disk garbage collection method provided by the embodiment of the present application includes:
[0064] S101: Pre-create a garbage collection state machine.
[0065] S102: After determining that the garbage collection triggering condition is met, checking the status of the garbage collection state machine.
[0066] S103: If the garbage collection state machine is in an idle state, the garbage collection state machine is set to a garbage collection state to perform a garbage collection task.
[0067] The hard disk garbage collection method provided in the embodiment of the present application is generally applied to the central processing unit (CPU) in a storage system. Compared with the traditional solid-state hard disk garbage collection task, if a jam occurs during execution, not only will the garbage collection task be unable to continue, but the execution of normal user read and write tasks will also be affected. The hard disk garbage collection method provided in the embodiment of the present application creates a garbage collection task in the form of a state machine, and utilizes the characteristic that the processor reads the status and executes state machine-type tasks in a polling manner, thereby avoiding the garbage collection task from blocking or freezing the disk management software abstraction layer FTL (Flash translation layer). Therefore, if a jam occurs during the garbage collection process, it will not affect the execution of other normal user read and write tasks, and the next time the garbage collection state machine is polled, the execution can continue from the state of the last jam.
[0068] In a storage system, one or more garbage collection state machines can be created for each logical unit (LUN). If multiple garbage collection state machines are created, the garbage collection state machines on a single LUN cannot simultaneously execute data migration tasks.
[0069] In S101, a garbage collection state machine is created. This involves programming the garbage collection task in the form of a state machine, programming the various steps required for the task as corresponding state values of the state machine, configuring state description statements for each state machine, and forming the switching sequence and switching conditions between the various states of the garbage collection state machine, thereby completing the creation of the garbage collection state machine. By referring to existing garbage collection tasks, the idle state and garbage collection state can be configured for the garbage collection state machine.
[0070] For S102 , a garbage collection triggering condition is pre-set, so that when the CPU detects that the current storage system meets the garbage collection triggering condition, it attempts to start the garbage collection state machine.
[0071] The specific triggering conditions for garbage collection can be: the number of free data blocks is less than the garbage collection start threshold, and / or an erroneous data block is detected. In other words, garbage collection can be triggered in two situations. In the first situation, the garbage collection start threshold is pre-set based on the hardware structure. When the number of free data blocks is less than the garbage collection start threshold, if the current garbage collection state machine is detected to be in the idle state, the garbage collection task is initiated and the garbage collection state machine is set to the garbage collection state. In the second situation, when a data block is erroneous (when the user writes data, a checksum of the data actually written to the hard disk is returned. If the checksum finds that the written data is different from the data the user intended to write, it indicates that the data block is erroneous), the valid data on the data block needs to be forcibly moved and garbage collection is forcibly initiated to prevent data loss. In this situation, no threshold is required. That is, once an erroneous data block is detected and the garbage collection state machine is currently in the idle state, garbage collection is forcibly initiated, the garbage collection state machine is set to the garbage collection state, and the erroneous data block is forcibly collected.
[0072] The garbage collection start threshold can be set per hard disk or per logical unit. For example, the garbage collection start threshold for a logical unit can be set to 4. This means that when the number of free data blocks in a logical unit is less than 4, if a garbage collection state machine is currently in the idle state for that logical unit, the garbage collection state machine is set to the garbage collection state and garbage collection is performed on that logical unit. If no garbage collection state machine is currently in the idle state for that logical unit, the system waits for the next CPU poll.
[0073] In S103, if the garbage collection state machine is not in the idle state, it indicates that the garbage collection task is being executed. If all garbage collection state machines are not in the idle state, then wait for the next polling. If there is a garbage collection state machine in the idle state, then the garbage collection state machine is set to the garbage collection state to execute the garbage collection program preset in the garbage collection state machine.
[0074] Example 2
[0075] Figure 2 A schematic diagram of the operation process of a garbage collection state machine provided in an embodiment of the present application.
[0076] Based on the above embodiment, the garbage collection state machine may specifically include five states: GC_IDLE, GC_DST, GC_SRC, GC_RUN, and GC_ERASE.
[0077] Among them, GC_IDLE is the idle state, which is the startup state of the garbage collection state machine.
[0078] GC_DST is to obtain the target data block information status, specifically to select the target data block according to the preset target data block selection criteria. The target data block is the data block used as the data transfer destination.
[0079] GC_SRC is used to obtain the source data block information status, specifically to select the source data block according to the preset selection criteria for the source data block. The source data block is the data block at the source of the data migration.
[0080] GC_RUN is the data movement state, specifically the state of moving valid data in the source data block to the target data block. It is the core function of the garbage collection state machine.
[0081] GC_ERASE is the source data block erasure state. Specifically, after completing the migration of valid data on the data block, the source data block is erased and released.
[0082] Then S103: if the garbage collection state machine is in the idle state, the garbage collection state machine is set to the garbage collection state to perform the garbage collection task, specifically including:
[0083] Based on the garbage collection trigger condition, if the garbage collection state machine is in the idle state, it enters the state of obtaining target data block information to select an idle target data block;
[0084] After the target data block is selected, the state of obtaining the source data block information is entered to select the source data block;
[0085] After the source data block is selected, the data migration state is entered to migrate the valid data in the source data block to the target data block;
[0086] After the data migration is completed, the source data block erasing state is entered to perform an erasing operation on the source data block to release the space of the source data block.
[0087] The CPU polls the above five states of the garbage collection state machine in turn, and the operation process of the garbage collection state machine is as follows: Figure 2 As shown, specifically including:
[0088] S201: GC_IDLE (idle state).
[0089] S202: Determine whether the garbage collection triggering condition is successfully triggered; if yes, proceed to S203; if not, proceed to S211.
[0090] S203: GC_SRC (obtaining source data block information status).
[0091] S204: Determine whether the information of the target data block is selected; if yes, proceed to S205; if not, proceed to S211.
[0092] S205: GC_SRC (obtaining source data block information status).
[0093] S206: Determine whether a source data block is selected; if yes, proceed to S207; if not, proceed to S211.
[0094] S207: GC_RUN (data migration state).
[0095] S208: Determine whether the data migration is completed; if yes, proceed to S209; if not, proceed to S211.
[0096] S209: GC_ERASE (source data block erase state).
[0097] S210: Determine whether the source data block is erased successfully; if yes, return to S201; if not, proceed to S211.
[0098] S211: CPU polling. Specifically, the current state of the garbage collection state machine is recorded and re-entered in the next CPU polling.
[0099] To select the target data block, garbage collection reserved storage space can be allocated in advance for the garbage collection state machine. When the data block in the garbage collection reserved storage space is in an empty state, it does not receive normal user write tasks and only serves as a target data block to be selected for garbage collection.
[0100] Then select the available target data blocks, which may include:
[0101] If there is an idle data block in the garbage collection reserved storage space, select the target data block in the garbage collection reserved storage space;
[0102] If there is no free data block in the garbage collection reserved storage space, a target data block is selected outside the garbage collection reserved storage space.
[0103] The garbage collection reserved storage space can be a fixed space. After all the free data blocks in the garbage collection reserved storage space are used, some data blocks will meet the conditions of the source data blocks and will be cleared by the garbage collection task, completing the aggregation of valid data.
[0104] The criteria for selecting source data blocks can be: selecting data blocks with less valid data and fewer erase / write (PE) cycles as source data blocks. Selecting data blocks with less valid data as source data blocks can reduce the amount of data that needs to be moved on each data block, thereby releasing available data blocks as quickly as possible. Selecting data blocks with fewer erase / write cycles as source data blocks, i.e., setting some data blocks with longer lifespans as vacant data blocks, and shifting the next erase / write task to data blocks with fewer erase / write cycles, helps balance the erase / write cycles between data blocks on the hard disk. The selected source data blocks can be one or more. For example, the valid data of multiple source data blocks can be aggregated and migrated to a target data block, thereby releasing more available free data blocks.
[0105] Specifically, by setting a valid data volume threshold and an erasure count threshold, some candidate source data blocks can be selected, and then a source data block can be selected from the candidate data blocks based on a comprehensive evaluation of the two indicators: valid data volume and erasure count.
[0106] Example 3
[0107] The above embodiment provides a solution for implementing a garbage collection state machine to improve the fluency of garbage collection tasks. On this basis, the embodiment of the present application further improves garbage collection efficiency and quality by optimizing the garbage collection task process.
[0108] In the hard disk garbage collection method provided in the embodiment of the present application, an idle target data block is selected, specifically: the data block with the least number of erases and writes among the idle data blocks is selected as the first target data block, and the data block with the most erases and writes among the idle data blocks is selected as the second target data block.
[0109] The valid data in the source data block is moved to the target data block, specifically: hot data in the valid data of the source data block is moved to the first target data block, and cold data in the valid data of the source data block is moved to the second target data block.
[0110] It can be understood that hot data refers to data that is accessed more frequently, while cold data refers to data that is accessed less frequently. By moving the hot data in the valid data of the source data block to the first target data block with the least number of erases and writes, and moving the cold data in the valid data of the source data block to the second target data block with the most number of erases and writes, the erase and write count of the first target data block increases rapidly, while the erase and write count of the second target data block increases slowly, thereby balancing the difference between the erase and write counts of the first target data block and the second target data block, achieving wear leveling, and thus extending the service life of the hard disk; by distinguishing between cold and hot data and moving data, the number of garbage collection tasks started can be effectively reduced, reducing the impact of garbage collection tasks on NAND, and thus extending the service life of the hard disk.
[0111] Example 4
[0112] The above embodiment provides a solution for implementing a garbage collection state machine to improve the fluency of garbage collection tasks. On this basis, the embodiment of the present application further improves garbage collection efficiency and quality by optimizing the garbage collection task process.
[0113] On this basis, in the hard disk garbage collection method provided in the embodiment of the present application, the source data block is selected as follows:
[0114] Select the data block with the smallest recovery evaluation value as the source data block;
[0115] The recovery estimate is calculated using the following equation:
[0116]
[0117] Among them, value is the recycling evaluation value, α is the weighting factor, VDFC is the amount of valid data in the candidate source data block at the current moment, N df is the total amount of data that can be stored in the selected source data block, N pe is the number of erase and write times of the source data block to be selected, MAX pe The maximum number of erase and write times among all candidate source data blocks.
[0118] Specifically, multiple candidate source data blocks can be selected first. For example, multiple source data blocks can be selected based on the minimum percentage of valid data, and then based on the minimum number of erase / write cycles, thereby narrowing down the number of candidate source data blocks. By setting a trade-off factor, the influence of the two factors, namely the percentage of valid data and the percentage of erase / write cycles, on the selection of source data blocks can be controlled. After weighted calculation, data blocks with a small amount of finite data and a low number of erase / write cycles can be selected as source data blocks. The size of the trade-off factor can be set by operations and maintenance personnel.
[0119] Optionally, the trade-off factor is calculated using the following equation:
[0120]
[0121] Among them, α is the trade-off factor, N src_block is the number of source data blocks to be selected, SUM block is the number of all data blocks in the hard disk, N bad_block The number of bad blocks in the hard disk.
[0122] Specifically, the more valid data a source data block has, the less likely it is to be recycled; giving priority to recycling source data blocks with fewer erase and write times helps achieve wear leveling of the hard disk. Based on the equation of the above trade-off factor α, the trade-off factor α represents the proportion of source data blocks to be selected. The smaller the trade-off factor α, the fewer selectable data blocks. At this time, the focus is on selecting source data blocks with less valid data to avoid frequent triggering of garbage collection and quickly release data blocks to obtain valid space. The larger the trade-off factor α, the more selectable data blocks. At this time, the focus is on selecting data blocks with fewer erase and write times, taking wear leveling into account. As the service life increases, the number of erase and write times increases, and the number of bad blocks increases. The trade-off factor α is proportional to the number of source data blocks to be selected, N. src_bl The number of bad blocks N in the hard disk when ock is the same bad_block As the value gets larger, the trade-off factor α becomes relatively larger, which places more emphasis on wear balance and prolongs the service life of the hard disk.
[0123] Example 5
[0124] Garbage collection efficiency can be improved by aggregating valid data during data migration. Specifically, depending on the system configuration, valid data from multiple source data blocks with the same configuration can be aggregated and migrated together. This not only improves garbage collection efficiency but also improves the rationality of data distribution.
[0125] In addition, the frequency of valid data access can be used as the basis for aggregating valid data, and valid data with similar valid data access frequency ratios can be aggregated into the same batch, and the valid data in the source data block can be moved to the target data block in batches.
[0126] The effective data access frequency ratio is calculated using the following equation:
[0127]
[0128] Among them, F is the effective data access frequency ratio, N pv is the average number of valid page data accesses in each candidate source data block at the current moment, MAX pv The maximum number of valid page data accesses in each candidate source data block.
[0129] In combination with the solution provided in Example 3 of the present application of moving hot data in the valid data of the source data block to the first target data block with the least number of erase and write times, and moving cold data in the valid data of the source data block to the second target data block with the most erase and write times, by aggregating valid data with similar valid data access frequency ratios into the same batch for data migration, it helps to efficiently realize the batch migration of cold data and hot data.
[0130] Specifically, the data block information maintained in the firmware includes the number of data block accesses and the number of accesses to each page. After calculation using equation (3), page data with similar effective data access frequency ratios are aggregated together.
[0131] The effective data access frequency ratio distinction threshold for cold data and hot data can be set to 0.4, that is, effective data with an effective data access frequency ratio less than 0.4 is considered cold data, and effective data with an effective data access frequency ratio greater than or equal to 0.4 is considered hot data.
[0132] On this basis, the embodiments of the present application further provide a scheme for quantifying the concept of effective data access frequency ratio proximity. In the hard disk garbage collection method provided in the embodiments of the present application, effective data access frequency ratio proximity specifically refers to: the difference between the effective data access frequency ratios of different effective data is greater than a frequency ratio proximity threshold.
[0133] The frequency ratio is close to the threshold value and is calculated by the following equation:
[0134]
[0135] Among them, T is the frequency ratio close to the threshold, Page pv N is the number of page data accesses read at the current moment. pv is the average number of valid page data accesses in each candidate source data block, MAX pv MIN is the maximum number of valid page data accesses in each candidate source data block. pv It is the minimum number of valid page data accesses in each candidate source data block.
[0136] By calculating equation (4), valid data with a valid data access frequency ratio close to (greater than a frequency ratio close to threshold T) are aggregated and moved together.
[0137] The above describes in detail various embodiments corresponding to the hard disk garbage collection method. On this basis, the present application also discloses a hard disk garbage collection device, equipment and computer-readable storage medium corresponding to the above method.
[0138] Example 6
[0139] Figure 3A structural diagram of a hard disk garbage collection device provided in an embodiment of the present application.
[0140] like Figure 3 As shown, the hard disk garbage collection device provided in the embodiment of the present application includes:
[0141] A creation unit 301 is used to pre-create a garbage collection state machine;
[0142] A checking unit 302 is used to check the status of the garbage collection state machine after determining that the garbage collection triggering condition is met;
[0143] The execution unit 303 is configured to set the garbage collection state machine to a garbage collection state if the garbage collection state machine is in an idle state, so as to execute a garbage collection task.
[0144] Specifically, the execution unit 303 includes:
[0145] A first selection subunit is configured to enter a target data block information acquisition state to select an idle target data block based on a garbage collection trigger condition if the garbage collection state machine is in an idle state;
[0146] The second selection subunit is configured to enter a state of obtaining source data block information after selecting a target data block, so as to select a source data block;
[0147] The data moving subunit is used to enter the data moving state after selecting the source data block, so as to move the valid data in the source data block to the target data block;
[0148] The data erasing subunit is used to enter the source data block erasing state after completing the data migration, so as to perform an erasing operation on the source data block to release the space of the source data block.
[0149] Furthermore, the first selection subunit selects an idle target data block, specifically including:
[0150] If there is an idle data block in the garbage collection reserved storage space, select the target data block in the garbage collection reserved storage space;
[0151] If there is no free data block in the garbage collection reserved storage space, a target data block is selected outside the garbage collection reserved storage space.
[0152] Furthermore, the first selection subunit selects an idle target data block, specifically:
[0153] Selecting a data block with the least number of erasures and writes among the idle data blocks as a first target data block, and selecting a data block with the most number of erasures and writes among the idle data blocks as a second target data block;
[0154] The data migration subunit moves valid data from the source data block to the target data block, specifically:
[0155] Hot data in the valid data of the source data block is moved to the first target data block, and cold data in the valid data of the source data block is moved to the second target data block.
[0156] Furthermore, the second selection subunit selects the source data block, specifically:
[0157] The data blocks with less effective data and fewer erase / write times are used as source data blocks.
[0158] Furthermore, the second selection subunit selects the source data block, specifically:
[0159] Select the data block with the smallest recovery evaluation value as the source data block;
[0160] The recovery estimate is calculated using the following equation:
[0161]
[0162] Among them, value is the recycling evaluation value, α is the weighting factor, VDFC is the amount of valid data in the candidate source data block at the current moment, N df is the total amount of data that can be stored in the selected source data block, N pe is the number of erase and write times of the source data block to be selected, MAX pe The maximum number of erase and write times among all candidate source data blocks.
[0163] Specifically, the trade-off factor is calculated by the following equation:
[0164]
[0165] Among them, α is the trade-off factor, N src_block is the number of source data blocks to be selected, SUM block is the number of all data blocks in the hard disk, N bad_block The number of bad blocks in the hard disk.
[0166] Furthermore, the data migration subunit migrates the valid data in the source data block to the target data block, specifically:
[0167] Aggregate valid data with similar access frequency ratios into the same batch, and move valid data from the source data block to the target data block in batches;
[0168] The effective data access frequency ratio is calculated using the following equation:
[0169]
[0170] Among them, F is the effective data access frequency ratio, N pv is the average number of valid page data accesses in each candidate source data block at the current moment, MAX pv The maximum number of valid page data accesses in each candidate source data block.
[0171] Specifically, the effective data access frequency ratios are close, specifically: the difference between the effective data access frequency ratios of different effective data is greater than the frequency ratio closeness threshold;
[0172] The frequency ratio is close to the threshold value and is calculated by the following equation:
[0173]
[0174] Among them, T is the frequency ratio close to the threshold, Page pv N is the number of page data accesses read at the current moment. pv is the average number of valid page data accesses in each candidate source data block, MAX pv MIN is the maximum number of valid page data accesses in each candidate source data block. pv It is the minimum number of valid page data accesses in each candidate source data block.
[0175] Furthermore, the garbage collection triggering condition is specifically: the number of free data blocks is less than a garbage collection start threshold, and / or an erroneous data block is detected.
[0176] Since the embodiments of the apparatus part correspond to the embodiments of the method part, please refer to the description of the embodiments of the method part for the embodiments of the apparatus part, and they will not be repeated here.
[0177] Example 7
[0178] Figure 4 A structural diagram of a hard disk garbage collection device provided in an embodiment of the present application.
[0179] like Figure 4 As shown, the hard disk garbage collection device provided in the embodiment of the present application includes:
[0180] Memory 410 for storing computer programs 411;
[0181] The processor 420 is configured to execute the computer program 411 . When the computer program 411 is executed by the processor 420 , the steps of the hard disk garbage collection method described in any one of the above embodiments are implemented.
[0182] Among them, the processor 420 may include one or more processing cores, such as a 3-core processor, an 8-core processor, etc. The processor 420 can be implemented in at least one hardware form of digital signal processing DSP (Digital Signal Processing), field programmable gate array FPGA (Field-Programmable Gate Array), and programmable logic array PLA (Programmable Logic Array). The processor 420 may also include a main processor and a coprocessor. The main processor is a processor for processing data in the awake state, also known as the central processing unit CPU (Central Processing Unit); the coprocessor is a low-power processor for processing data in the standby state. In some embodiments, the processor 420 may be integrated with a graphics processor GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content to be displayed on the display screen. In some embodiments, the processor 420 may also include an artificial intelligence AI (Artificial Intelligence) processor, which is used to process computing operations related to machine learning.
[0183] The memory 410 may include one or more computer-readable storage media, which may be non-transitory. The memory 410 may also include a high-speed random access memory, and a non-volatile memory, such as one or more disk storage devices, flash memory storage devices. In this embodiment, the memory 410 is at least used to store the following computer program 411, wherein, after the computer program 411 is loaded and executed by the processor 420, it can implement the relevant steps in the hard disk garbage collection method disclosed in any of the aforementioned embodiments. In addition, the resources stored in the memory 410 may also include an operating system 412 and data 413, etc., and the storage method may be temporary storage or permanent storage. Among them, the operating system 412 may be Windows. The data 413 may include but is not limited to the data involved in the above method.
[0184] In some embodiments, the hard disk garbage collection device may further include a display screen 430 , a power supply 440 , a communication interface 450 , an input / output interface 460 , a sensor 470 , and a communication bus 480 .
[0185] Those skilled in the art will understand that Figure 4 The structure shown in the figure does not constitute a limitation to the hard disk garbage collection device, and may include more or fewer components than shown in the figure.
[0186] The hard disk garbage collection device provided in the embodiment of the present application includes a memory and a processor. When the processor executes the program stored in the memory, it can implement the hard disk garbage collection method as described above, and the effect is the same as above.
[0187] It should be noted that the above-described embodiments of the apparatus and equipment are merely illustrative. For example, the division of modules is merely a logical function division. In actual implementation, there may be other division methods, such as multiple modules or components may be combined or integrated into another system, or some features may be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed may be through some interfaces, indirect coupling or communication connection of the apparatus or module, which may be electrical, mechanical or other forms. The modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical modules, that is, they may be located in one place, or they may be distributed on multiple network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment.
[0188] In addition, the functional modules in the various embodiments of the present application may be integrated into a processing module, or each module may exist physically separately, or two or more modules may be integrated into a single module. The above-mentioned integrated modules may be implemented in the form of hardware or software functional modules.
[0189] If the integrated module is implemented in the form of a software functional module and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, or the part that contributes to the existing technology, or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium and executes all or part of the steps of the method described in each embodiment of this application.
[0190] To this end, an embodiment of the present application further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the hard disk garbage collection method are implemented.
[0191] The computer-readable storage medium may include: a USB flash drive, a mobile hard disk, a read-only memory ROM (Read-Only Memory), a random access memory RAM (Random Access Memory), a magnetic disk or an optical disk, and other media that can store program codes.
[0192] The computer program contained in the computer-readable storage medium provided in this embodiment can implement the steps of the hard disk garbage collection method described above when executed by the processor, and the effect is the same as above.
[0193] The above is a detailed introduction to a hard disk garbage recovery method, device, equipment and computer-readable storage medium provided by the present application. The various embodiments in the specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same and similar parts between the various embodiments can be referred to each other. For the devices, equipment and computer-readable storage media disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the description is relatively simple, and the relevant parts can be referred to the method part description. It should be pointed out that for ordinary technicians in this technical field, without departing from the principles of the present application, several improvements and modifications can be made to the present application, and these improvements and modifications also fall within the scope of protection of the claims of the present application.
[0194] It should also be noted that, in this specification, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variants thereof are intended to cover 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 additional identical elements in the process, method, article, or apparatus comprising the element.
Claims
1. A hard disk garbage collection method, characterized in that: include: Create a garbage collection state machine in advance; the garbage collection state machine is created separately for each logical unit. If multiple garbage collection state machines are created, the garbage collection state machines on a logical unit cannot execute data migration tasks simultaneously; After determining that the garbage collection triggering condition is met, checking the status of the garbage collection state machine; The garbage collection triggering condition is specifically: the number of free data blocks is less than the garbage collection start threshold, and / or an erroneous data block is detected; the garbage collection start threshold is a threshold pre-set according to the hardware structure; The garbage collection state machine reads the state and executes it through the polling method of the processor. If a freeze occurs, it will continue to execute from the state before the freeze at the next polling; If the garbage collection state machine is in an idle state, the garbage collection state machine is set to a garbage collection state to perform a garbage collection task.
2. The hard disk garbage collection method according to claim 1, characterized in that: If the garbage collection state machine is in an idle state, setting the garbage collection state machine to a garbage collection state to perform a garbage collection task specifically includes: Based on the garbage collection triggering condition, if the garbage collection state machine is in an idle state, entering a target data block information acquisition state to select an idle target data block; After the target data block is selected, the state of obtaining source data block information is entered to select the source data block; After the source data block is selected, a data migration state is entered to migrate valid data in the source data block to the target data block; After the data migration is completed, the source data block erasing state is entered to perform an erasing operation on the source data block to release the space of the source data block.
3. The hard disk garbage collection method according to claim 2, characterized in that: The selecting of an idle target data block specifically includes: If there is an idle data block in the garbage collection reserved storage space, selecting the target data block in the garbage collection reserved storage space; If there is no free data block in the garbage collection reserved storage space, the target data block is selected outside the garbage collection reserved storage space.
4. The hard disk garbage collection method according to claim 2, characterized in that: The selection of an idle target data block is specifically as follows: Selecting a data block with the least number of erasures and writes among the idle data blocks as a first target data block, and selecting a data block with the most number of erasures and writes among the idle data blocks as a second target data block; The moving of valid data in the source data block to the target data block is specifically as follows: Hot data in the valid data of the source data block is moved to the first target data block, and cold data in the valid data of the source data block is moved to the second target data block.
5. The hard disk garbage collection method according to claim 2, characterized in that: The selection of the source data block is specifically as follows: A data block with a small amount of valid data and a small number of erasures and writes is selected as the source data block.
6. The hard disk garbage collection method according to claim 2, characterized in that: The selection of the source data block is specifically as follows: Selecting the data block with the smallest recovery evaluation value as the source data block; The recovery estimate is calculated using the following equation: Wherein, value is the recycling evaluation value, α is the weighting factor, VDFC is the amount of valid data in the candidate source data block at the current moment, N df is the total amount of data that can be stored in the selected source data block, N pe is the number of erasures of the selected source data block, MAX pe is the maximum number of erase and write times among all the source data blocks to be selected.
7. The hard disk garbage collection method according to claim 6, characterized in that: The trade-off factor is specifically calculated by the following equation: Where α is the trade-off factor, N src_block is the number of the source data blocks to be selected, SUM block is the number of all data blocks in the hard disk, N bad_block is the number of bad blocks in the hard disk.
8. The hard disk garbage collection method according to claim 2, characterized in that: The moving of valid data in the source data block to the target data block is specifically as follows: Aggregate valid data with similar valid data access frequency ratios into the same batch, and move the valid data in the source data blocks to the target data blocks in batches; The effective data access frequency ratio is calculated by the following equation: Wherein, F is the effective data access frequency ratio, N pv is the average number of valid page data accesses in each candidate source data block at the current moment, MAX pv is the maximum number of valid page data access times in each of the to-be-selected source data blocks.
9. The hard disk garbage collection method according to claim 8, characterized in that: The effective data access frequency ratio is close, specifically: the difference between the effective data access frequency ratios of different effective data is greater than the frequency ratio close threshold; The frequency ratio is close to the threshold value and is calculated by the following equation: Wherein, T is the frequency ratio close to the threshold, Page pv N is the number of page data accesses read at the current moment. pv is the average number of valid page data access times in each of the candidate source data blocks, MAX pv is the maximum number of valid page data access times in each of the selected source data blocks, MIN pv is the minimum number of access times of valid page data in each of the to-be-selected source data blocks.
10. A hard disk garbage collection device, characterized in that: include: A creation unit is used to pre-create a garbage collection state machine; the garbage collection state machine is created separately for each logical unit. If multiple garbage collection state machines are created, the garbage collection state machines on a logical unit cannot execute data migration tasks simultaneously; A checking unit, configured to check the state of the garbage collection state machine after determining that a garbage collection triggering condition is satisfied; The garbage collection triggering condition is specifically: the number of free data blocks is less than the garbage collection start threshold, and / or an erroneous data block is detected; the garbage collection start threshold is a threshold pre-set according to the hardware structure; The garbage collection state machine reads the state and executes it through the polling method of the processor. If a freeze occurs, it will continue to execute from the state before the freeze at the next polling; The execution unit is configured to set the garbage collection state machine to a garbage collection state if the garbage collection state machine is in an idle state, so as to execute a garbage collection task.
11. A hard disk garbage collection device, characterized in that: include: memory for storing computer programs; A processor is used to execute the computer program, and when the computer program is executed by the processor, the steps of the hard disk garbage collection method according to any one of claims 1 to 9 are implemented.
12. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the hard disk garbage collection method according to any one of claims 1 to 9 are implemented.
Citation Information
Patent Citations
Host and solid-state disk collaborative garbage collection method for full-flash memory array
CN110309078A
Service recovery method and system for offline nodes of storage cluster system and related components
CN112463437A