Garbage collection method, storage device, and storage medium
By calculating the difference in the number of free storage blocks and the garbage collection time of the storage device, a closed-loop control system was used to solve the problem of large performance fluctuations during garbage collection of the storage device, achieving smooth performance control and improving the user experience.
Patent Information
- Application Number
- CN202510680979.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-23
- Publication Date
- 2026-11-24
AI Technical Summary
Existing technologies can easily lead to large performance fluctuations during garbage collection in storage devices, especially when the number of free storage blocks is small. The performance switching is not smooth, which affects the user experience.
By calculating the difference in the number of free storage blocks in the storage device and the garbage collection time, a closed-loop control system is used to calculate performance parameters and data volume, and perform multiple rounds of garbage collection until the free storage space reaches the target, thus smoothly controlling performance changes.
It achieves smooth control of performance fluctuations during the garbage collection process of storage devices, thus improving the user experience.
Smart Images

Figure CN123157404A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data processing technology, and in particular to a waste recycling method, storage device and storage medium. Background Technology
[0002] After data in a storage device is overwritten or deleted, invalid data may remain. Garbage collection is needed to release the storage space occupied by this invalid data. Related technologies typically begin garbage collection when the number of free storage blocks in the storage device is low. During garbage collection, the storage device is switched from high performance to low performance, resulting in significant performance fluctuations. Furthermore, during multiple rounds of garbage collection for each storage block, the varying amounts of data written to the storage device can easily cause abrupt and uneven performance changes. Summary of the Invention
[0003] In view of this, it is necessary to provide a garbage collection method, storage device, and storage medium to solve the problem that performing garbage collection on storage devices can easily lead to large fluctuations in the performance of the storage devices and make them less smooth.
[0004] In a first aspect, embodiments of this application provide a waste recycling method applied to a storage device, the method comprising: If the free storage space of the storage device is less than or equal to the target storage space, multiple rounds of garbage collection are performed. Based on the difference between the first number of free storage blocks of the storage device in the current round of garbage collection and the second number of free storage blocks of the storage device in the first round of garbage collection, the first performance parameter of the storage device is calculated. Based on the first performance parameter and the time consumed by each round of garbage collection, calculate the amount of data written to the storage device after each round of garbage collection; After each round of garbage collection is completed and the amount of data written to the storage device reaches the target amount, the next round of garbage collection is performed until the free storage space of the storage device is greater than the target storage space.
[0005] In one possible implementation, the target storage space is the difference between the reserved storage space and the storage space for bad blocks and the redundant storage space in the storage device, and the reserved storage space is the difference between the total storage space of the storage device and the available storage space and the storage space occupied by private data.
[0006] In one possible implementation, calculating the performance parameters of the storage device based on the difference between a first number of free storage blocks in the current round of garbage collection and a second number of free storage blocks in the first round of garbage collection includes: Based on the difference, calculate the second performance parameter that the storage device reduces during each round of waste collection; The first performance parameter is obtained by calculating the difference between the preset performance parameter threshold of the storage device and the second performance parameter.
[0007] In one possible implementation, calculating the reduction in a second performance parameter of the storage device during each round of garbage collection based on the difference includes: The second performance parameter is calculated based on the preset proportional coefficient, preset integral coefficient, preset differential coefficient, the difference, and the difference in the previous round of waste recycling.
[0008] In one possible implementation, calculating the reduction in a second performance parameter of the storage device during each round of garbage collection based on the difference includes: The second performance parameter is calculated based on a preset proportional coefficient, a preset integral coefficient, a preset differential coefficient, the square of the difference, and the difference from the previous round of waste recycling.
[0009] In one possible implementation, calculating the amount of data written to the storage device during each round of garbage collection, based on the first performance parameter and the duration of each garbage collection cycle, includes: Calculate the product of the first performance parameter and the time consumed in each round of garbage collection to obtain the amount of data written to the storage device after each round of garbage collection.
[0010] In one possible implementation, the method further includes: During each round of garbage collection, the data in the data block containing invalid data is transferred to the free data block of the storage device, and the data in the data block containing the invalid data is erased.
[0011] In one possible implementation, the time consumed in each round of garbage collection is determined based on the number and speed at which the storage device transfers data during each round of garbage collection.
[0012] Secondly, embodiments of this application provide a storage device, the storage device including a processor and a memory, the memory being used to store instructions, and the processor being used to call the instructions in the memory, causing the storage device to execute the above-described garbage collection method.
[0013] Thirdly, embodiments of this application provide a computer-readable storage medium including computer instructions that, when executed on a storage device, cause the storage device to perform the aforementioned garbage collection method.
[0014] The waste recycling method, storage device, and storage medium provided in this application embodiment can smoothly and accurately control the performance of the storage device during the waste recycling process, avoid excessive performance fluctuations in the storage device, and effectively improve the user experience. Attached Figure Description
[0015] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of this application. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.
[0016] Figure 1 A flowchart of a waste recycling method provided in an embodiment of this application.
[0017] Figure 2 This is a schematic diagram of the structure of a waste recycling device provided in an embodiment of this application.
[0018] Figure 3 This is a schematic diagram of the structure of a storage device provided in an embodiment of this application. Detailed Implementation
[0019] It should be noted that in this application, "at least one" means one or more, and "more than one" means two or more. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, or B alone, where A and B can be singular or plural. The terms "first," "second," "third," "fourth," etc. (if present) in the specification, claims, and drawings of this application are used to distinguish similar objects, not to describe a specific order or sequence.
[0020] In the embodiments of this application, the terms "exemplary" or "for example" are used to indicate examples, illustrations, or descriptions. Any embodiment or design described as "exemplary" or "for example" in the embodiments of this application should not be construed as being more preferred or advantageous than other embodiments or design solutions. Specifically, the use of terms such as "exemplary" or "for example" is intended to present the relevant concepts in a specific manner. Unless otherwise specified, the following embodiments and features described herein can be combined with each other.
[0021] After data in a storage device is overwritten or deleted, invalid data may remain. Garbage collection is needed to release the storage space occupied by this invalid data. Related technologies typically begin garbage collection when the number of free storage blocks in the storage device is low. During garbage collection, the storage device is switched from high performance to low performance, resulting in significant performance fluctuations. Furthermore, during multiple rounds of garbage collection for each storage block, the varying amounts of data written to the storage device can easily cause abrupt and uneven performance changes.
[0022] For example, in related technologies, storage devices start garbage collection (GC) when the remaining space in the flash memory is low, such as when the number of free blocks is less than N. The storage device has multiple performance levels, such as three performance levels: level 1, level 2, and level 3, and the three performance levels increase sequentially. When performing garbage collection, the performance level is switched to level 1, and when the number of free blocks is higher than N, the performance level is switched back to level 3. This results in large fluctuations in the performance of the storage device.
[0023] Furthermore, due to the large amount of valid data in the source block or the uneven distribution of valid data, garbage collection of the source block is usually divided into multiple rounds. The amount of data written in each round of garbage collection = (the amount of valid data in the source block / the amount of invalid data in the source block) * the amount of data written by the host. The data distribution of the source block has a significant impact on the garbage collection time of each round, and the amount of data written by the host is divided into several performance levels, resulting in a step-like jump in performance and an uneven performance change.
[0024] Furthermore, the garbage collection of storage devices employs a non-closed-loop system, only classifying the input quantity (i.e., the number of free blocks) without real-time feedback. Consequently, garbage collection schemes in related technologies only focus on maintaining a balance between input and output, lacking a feedback mechanism for performance control, resulting in significant and uneven performance fluctuations in storage devices.
[0025] To address the aforementioned issues, this application provides a garbage collection method that can smoothly and accurately control the performance of storage devices during the garbage collection process, avoiding excessive performance fluctuations and effectively improving the user experience.
[0026] See Figure 1 The diagram shown is a flowchart of a waste recycling method provided in an embodiment of this application. The waste recycling method is applied to a storage device, and the method includes: S101, determine whether the free storage space of the storage device is less than or equal to the target storage space. If the free storage space of the storage device is less than or equal to the target storage space, the process proceeds to S102; if the free storage space of the storage device is greater than the target storage space, the process continues to S101.
[0027] In one embodiment of this application, the target storage space is the difference between the reserved storage space (Over Provisioning, OP) and the storage space containing bad blocks and the redundant storage space in the storage device. Bad blocks can include storage blocks damaged during use and bad blocks inherent to the storage device. For example, bad blocks in the storage device can be detected by running preset operation instructions or using specialized detection tools (such as CrystalDiskInfo, HD Tune, GParted, etc.).
[0028] In one embodiment of this application, the reserved storage space is the difference between the total storage space of the storage device and the available storage space and the storage space occupied by firmware private data. For example, if the total storage space of the storage device is 1G, the available storage space is 900M, and the storage space occupied by firmware private data is 74M, then the reserved storage space is 50M.
[0029] In one embodiment of this application, the redundant storage space is determined based on the reserved storage space. For example, the redundant storage space is a preset percentage of the reserved storage space, and the preset percentage can be 10%. If the reserved storage space is small, for example, when the reserved space is less than or equal to 30M, the redundant storage space can be set to 0.
[0030] In one embodiment of this application, when the storage device is powered on, the reserved storage space of the storage device is obtained, the number of bad blocks in the storage device is detected, the storage space occupied by bad blocks is obtained, and the redundant storage space of the storage device is obtained. The target storage space is calculated, and then the free storage space of the storage device is obtained. By comparison, it is determined whether the free storage space of the storage device is less than or equal to the target storage space. If the free storage space of the storage device is less than or equal to the target storage space, garbage collection is started. If the free storage space of the storage device is greater than the target storage space, the determination of whether the free storage space of the storage device is less than or equal to the target storage space is continued when the storage device is powered on again.
[0031] S102, calculate the first performance parameter of the storage device based on the difference between the first number of idle storage blocks in the current round of waste collection and the second number of idle storage blocks in the first round of waste collection.
[0032] In one embodiment of this application, if the free storage space of the storage device is less than or equal to the target storage space, multiple rounds of garbage collection are performed. During the first round of garbage collection, a second number of free storage blocks in the storage device is obtained, and the performance parameters of the storage device are determined. In one embodiment of this application, the performance parameter of the storage device is the data transfer rate. In other embodiments of this application, the performance parameters of the storage device may also be Input / Output Operations Per Second (IOPS) or processing latency.
[0033] In one embodiment of this application, the performance parameters of the storage device are obtained by calculating the difference between a preset performance parameter threshold and a reduced performance parameter. For example, the preset performance parameter threshold is 200 MB / s.
[0034] In one embodiment of this application, during the first round of garbage collection, a second number of free storage blocks can be determined, and the performance parameter of the storage device is reduced to 0. That is, at this time, the first performance parameter of the storage device is a preset performance parameter threshold.
[0035] In one embodiment of this application, during subsequent garbage collection rounds, a first performance parameter of the storage device is calculated based on the difference between the first number of free storage blocks in the current garbage collection round and the second number of free storage blocks in the first garbage collection round. Specifically, a second performance parameter is calculated based on the difference between the first and second numbers, indicating a decrease in the storage device's performance parameter during each garbage collection round. The first performance parameter is obtained by calculating the difference between a preset performance parameter threshold and the second performance parameter. The formula used to calculate the second performance parameter is as follows: ΔS=P*Δn+I*(Δn+Δn_last)+D*(Δn-Δn_last) (1).
[0036] In the calculation formula (1), ΔS is the second performance parameter, P is the preset proportional coefficient, I is the preset integral coefficient, D is the preset differential coefficient, Δn is the difference between the first number of free storage blocks in the current round of garbage collection and the second number of free storage blocks in the first round of garbage collection, and Δn_last is the difference between the number of free storage blocks in the previous round of garbage collection and the second number of free storage blocks in the first round of garbage collection. Thus, the first performance parameter S of the storage device is S0 - ΔS, where S0 is the preset performance parameter threshold.
[0037] In the calculation formula (1), the proportional coefficient P is used to amplify the feedback quantity proportionally, the integral coefficient I is used to react to the cumulative value of multiple feedback quantities. If the target value is not reached, positive feedback is continuously performed. After the target value is reached, the cumulative value is zero, which is used to eliminate steady-state error. The differential coefficient D is used to react to the difference between two feedback quantities. When the feedback quantity becomes smaller, negative feedback is performed. When the feedback quantity becomes larger, positive feedback is performed, which is used to suppress fluctuations.
[0038] In another embodiment of this application, the calculation formula used to calculate the second performance parameter may also be: ΔS=P*Δn 2 +I*(Δn+Δn_last)+D*(Δn-Δn_last) (2).
[0039] Based on the calculation formula (2), when the difference Δn is small, the performance reduction is also small, and when the difference Δn is large, the performance reduction is also large.
[0040] S103, based on the first performance parameter and the time consumed by the first round of garbage collection, calculates the target amount of data to be written to the storage device after each round of garbage collection.
[0041] In one embodiment of this application, after calculating the first performance parameters of the storage device, the storage device performs garbage collection, copying valid data from the storage block containing invalid data to a free storage block. After the copying is complete, the data in the storage block containing invalid data is erased. The above process is completed in multiple rounds of garbage collection. In each round of garbage collection, the number of data copies is a preset value, for example, 10 times.
[0042] In one embodiment of this application, after each round of garbage collection is completed, the time consumed in each round of garbage collection is calculated. The time consumed in each round of garbage collection is determined based on the number of times and the speed at which the storage device transfers data during each round of garbage collection. The product of a first performance parameter and the time consumed in each round of garbage collection is calculated to obtain the target amount of data written to the storage device after each round of garbage collection.
[0043] S104: After each round of garbage collection is completed and the amount of data written to the storage device reaches the target amount of data, the next round of garbage collection is carried out until the free storage space of the storage device is greater than the target storage space.
[0044] In one embodiment of this application, after each round of garbage collection is completed, the storage device pauses garbage collection, resumes normal use, and performs data reading and writing. After the amount of data written to the storage device reaches the target amount, the next round of garbage collection is performed. This cycle continues until the free storage space of the storage device is greater than the target storage space, at which point garbage collection is completed.
[0045] Through the above embodiments of this application, the data transmission performance of the storage device can be fed back based on the change in the number of free data blocks during multiple rounds of garbage collection. The data transmission performance of the storage device can be controlled based on the proportional coefficient, integral coefficient, and derivative coefficient of the closed-loop control system, so as to avoid large performance fluctuations of the storage device during garbage collection and to perform performance control smoothly and accurately.
[0046] See Figure 2 The diagram shown is a structural schematic of a waste recycling device according to an embodiment of this application. In one embodiment of this application, the waste recycling device 200 may include multiple functional modules composed of computer program segments. The computer program segments in the waste recycling device 200 may be stored in the memory of a storage device and executed by at least one processor to perform waste recycling functions.
[0047] In one embodiment of this application, the waste recycling device 200 can be divided into multiple functional modules according to the functions it performs. The functional modules of the waste recycling device 200 may include: a first calculation module 201, a second calculation module 202, and a writing module 203. In this embodiment, a module refers to a series of computer program segments that can be executed by at least one processor and perform a fixed function, and which are stored in memory.
[0048] The first calculation module 201 is used to calculate the first performance parameter of the storage device if the free storage space of the storage device is less than or equal to the target storage space, based on the difference between the first number of free storage blocks of the storage device in the current round of garbage collection and the second number of free storage blocks of the storage device in the first round of garbage collection.
[0049] The second calculation module 202 is used to calculate the amount of data written to the storage device after each round of garbage collection based on the first performance parameter and the time consumed by each round of garbage collection.
[0050] The write module 203 is used to perform the next round of garbage collection after each round of garbage collection is completed and the amount of data written to the storage device reaches the target storage space.
[0051] See Figure 3 The diagram shown is a schematic representation of a storage device according to an embodiment of this application. The storage device 1 includes, but is not limited to, a processor 10, a memory 20, and a computer program stored in the memory 20 and executable on the processor 10. For example, the computer program is a garbage collection program. When the processor 10 executes the computer program, it implements the steps of a garbage collection method.
[0052] For example, the computer program may be divided into one or more modules / units, which are respectively stored in the memory 20 and executed by the processor 10 to complete this application. The one or more modules / units may be a series of computer program instruction segments capable of performing specific functions, and the instruction segments are used to describe the execution process of the computer program in the storage device 1.
[0053] Those skilled in the art will understand that the schematic diagram is merely an example of storage device 1 and does not constitute a limitation on storage device 1. It may include more or fewer components than shown in the diagram, or combine certain components, or different components. For example, storage device 1 may also include input / output devices, network access devices, buses, etc.
[0054] The processor can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor, or any conventional processor. The processor is the control center of the storage device 1, connecting various parts of the storage device 1 via various interfaces and lines.
[0055] The memory can be used to store the firmware program and / or modules / units. The processor implements various functions of the storage device 1 by running or executing the computer programs and / or modules / units stored in the memory, and by calling data stored in the memory. The memory may mainly include a program storage area and a data storage area. The program storage area may store the operating system, applications required for at least one function, etc.; the data storage area may store data created based on the use of the storage device 1, etc. In addition, the memory may include volatile and non-volatile memory, such as hard disk, memory, plug-in hard disk, smart media card (SMC), secure digital (SD) card, flash card, at least one disk storage device, flash memory device, or other storage devices.
[0056] If the modules / units integrated in the storage device 1 are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the methods of the above embodiments can also be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the various method embodiments described above. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. The computer-readable medium can include any entity or device capable of carrying the computer program code, a recording medium, a USB flash drive, a portable hard drive, a magnetic disk, an optical disk, a computer memory, a read-only memory (ROM), or a random access memory (RAM).
[0057] The extended content of the specific embodiments of the computer-readable storage medium described in this application is basically the same as the embodiments of the above-described waste recycling methods, and will not be repeated here.
[0058] It will be apparent to those skilled in the art that this application is not limited to the details of the exemplary embodiments described above, and that this application can be implemented in other specific forms without departing from the spirit or essential characteristics of this application. Therefore, the embodiments should be considered exemplary and non-limiting in all respects, and the scope of this application is defined by the appended claims rather than the foregoing description. Thus, all variations falling within the meaning and scope of equivalents of the claims are intended to be embraced within this application. No reference numerals in the claims should be construed as limiting the scope of the claims. Furthermore, it is clear that the word "comprising" does not exclude other units or steps, and the singular does not exclude the plural. Multiple units or devices recited in the apparatus claims may also be implemented by the same unit or device in software or hardware. The terms "first," "second," etc., are used to indicate names and do not indicate any particular order.
[0059] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application and are not intended to limit it. Although this application has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can be made to the technical solutions of this application without departing from the spirit and scope of the technical solutions of this application.
Claims
1. A waste recycling method, applied to a storage device, characterized in that, The method includes: If the free storage space of the storage device is less than or equal to the target storage space, multiple rounds of garbage collection are performed. Based on the difference between the first number of free storage blocks of the storage device in the current round of garbage collection and the second number of free storage blocks of the storage device in the first round of garbage collection, the first performance parameter of the storage device is calculated. Based on the first performance parameter and the time consumed by each round of garbage collection, calculate the amount of data written to the storage device after each round of garbage collection; After each round of garbage collection is completed and the amount of data written to the storage device reaches the target amount, the next round of garbage collection is performed until the free storage space of the storage device is greater than the target storage space.
2. The waste recycling method as described in claim 1, characterized in that, The target storage space is the difference between the reserved storage space and the storage space for bad blocks and redundant storage space in the storage device. The reserved storage space is the difference between the total storage space of the storage device and the available storage space and the storage space occupied by private data.
3. The waste recycling method as described in claim 1, characterized in that, The calculation of the first performance parameter of the storage device based on the difference between the first number of free storage blocks in the current round of waste collection and the second number of free storage blocks in the first round of waste collection includes: Based on the difference, calculate the second performance parameter that the storage device reduces during each round of waste collection; The first performance parameter is obtained by calculating the difference between the preset performance parameter threshold of the storage device and the second performance parameter.
4. The waste recycling method as described in claim 3, characterized in that, The calculation of the second performance parameter reduction of the storage device in each round of garbage collection based on the difference includes: The second performance parameter is calculated based on the preset proportional coefficient, preset integral coefficient, preset differential coefficient, the difference, and the difference in the previous round of waste recycling.
5. The waste recycling method as described in claim 3, characterized in that, The calculation of the second performance parameter reduction of the storage device in each round of garbage collection based on the difference includes: The second performance parameter is calculated based on a preset proportional coefficient, a preset integral coefficient, a preset differential coefficient, the square of the difference, and the difference from the previous round of waste recycling.
6. The waste recycling method as described in claim 1, characterized in that, The calculation of the amount of data written to the storage device during each round of garbage collection, based on the first performance parameter and the time consumed by each round of garbage collection, includes: Calculate the product of the first performance parameter and the time consumed in each round of garbage collection to obtain the amount of data written to the storage device after each round of garbage collection.
7. The waste recycling method as described in claim 1, characterized in that, The method further includes: During each round of garbage collection, the data in the data block containing invalid data is transferred to the free data block of the storage device, and the data in the data block containing the invalid data is erased.
8. The waste recycling method as described in claim 7, characterized in that, The time consumed in each round of waste collection is determined based on the number of times and the speed at which the storage device transfers data during each round of waste collection.
9. A storage device, characterized in that, The storage device includes a processor and a memory, the memory being used to store instructions, and the processor being used to invoke the instructions in the memory, causing the storage device to perform the garbage collection method according to any one of claims 1 to 8.
10. A computer-readable storage medium, characterized in that, Includes computer instructions that, when executed on a storage device, cause the storage device to perform the garbage collection method as described in any one of claims 1 to 8.
