Garbage collection method, storage device and readable storage medium
By decomposing the garbage collection task into multiple time shards and performing alternately with the host read task, the problem of the garbage collection mechanism occupies system resources and causing slower read response speed, achieving faster read response speed and higher user experience.
Patent Information
- Application Number
- CN202510551662.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-29
- Publication Date
- 2025-05-30
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
The garbage collection mechanism in the existing SSD firmware policy will compete with the host's read tasks, causing the host's read response to slow down and affecting the user experience.
By decomposing the garbage collection task of the target time into multiple time shards and performing alternately after each host read task is completed until the sum of the time shards is equal to the target time.
This method reduces the impact of garbage collection tasks on the host's read response speed, shortens the data of a single garbage collection task, makes the system respond to read requests more timely, effectively reduces the delay time of read responses, and improves the read response speed.
Smart Images

Figure CN120066985A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of storage technologies, and in particular, to a garbage collection method, a storage device, and a readable storage medium. Background Art
[0002] In modern electronic devices, as a storage medium, the performance of a solid-state drive (SSD) plays a crucial role in the overall operating efficiency of the device and the user experience. However, there are some technical bottlenecks in the existing SSD firmware strategies in terms of the garbage collection (GC) mechanism, and these problems seriously affect the fluency and response speed of the device.
[0003] In the existing SSD firmware strategies, when the amount of data written by the host reaches a certain threshold, the garbage collection mechanism is triggered. The garbage collection mechanism reads valid data from blocks containing invalid data, temporarily stores it in a cache or an OP (Over-Provisioning) area, and then writes the merged valid data into a new block, thereby releasing storage space to provide sufficient space for new data writing. However, since the valid data needs to be read first during the garbage collection process, the garbage collection mechanism competes for resources with the host's read tasks, resulting in a significant increase in the host's read latency, thus affecting the host's response speed and causing a lag in the user experience.
[0004] In summary, the garbage collection mechanism of the existing storage device occupies system resources, resulting in a slower read response speed of the host. Summary of the Invention
[0005] The technical problem to be solved by the present invention is: to provide a garbage collection method, a storage device, and a readable storage medium, which can effectively improve the host read response speed during the garbage collection process.
[0006] To solve the above technical problem, a technical solution adopted by the present invention is: A garbage collection method, applied to a storage device, includes: Responding to an execution command of a garbage collection task, determining a target time consumed for executing the garbage collection task; Executing the garbage collection task according to a preset time slice after each host read task is completed, so that the host read task and the garbage collection task are executed alternately until the sum of the time slices is equal to the target time.
[0007] To solve the above technical problem, another technical solution adopted by the present invention is: A storage device, including a main control chip and a storage chip; The storage chip stores a computer program, and when the computer program is executed by the main control chip, each step in the above-mentioned garbage collection method is implemented.
[0008] To solve the above technical problems, another technical solution adopted by the present invention is: A computer-readable storage medium includes a memory, a processor, and a computer program stored on the memory and running on the processor. When the processor executes the computer program, each step in the above-mentioned garbage collection method is implemented.
[0009] The beneficial effect of the present invention is that by decomposing the garbage collection task of a target time into garbage collection tasks of multiple time slices and executing them after each host reading task, the impact of the garbage collection task on the host reading response speed is reduced. Compared with the traditional method of first executing the garbage collection task of a target time and then executing the host reading task, the present invention alternately executes the garbage collection tasks of multiple time slices and the host reading tasks in a loop, shortening the data for executing the garbage collection task each time, enabling the system to respond to the reading request more timely, effectively reducing the delay time of the reading response, and improving the reading response speed. Description of the Drawings
[0010] Figure 1 It is a flowchart of the steps of the garbage collection method provided by an embodiment of the present invention; Figure 2 It is an execution schematic diagram of a garbage collection method in the prior art; Figure 3 It is an execution schematic diagram of the garbage collection method provided by an embodiment of the present invention; Figure 4 It is a structural schematic diagram of a storage device provided by an embodiment of the present invention; Figure 5 It is a structural schematic diagram of a computer-readable storage medium provided by an embodiment of the present invention. Detailed Embodiments
[0011] To describe the technical content, the achieved objectives, and the effects of the present invention in detail, the following is described in conjunction with the embodiments and with reference to the drawings.
[0012] An embodiment of the present invention provides a garbage collection method applied to a storage device, including: In response to an execution command of a garbage collection task, determining a target time consumed for executing the garbage collection task; Executing the garbage collection task according to a preset time slice after each host reading task is completed, so that the host reading task and the garbage collection task are alternately executed until the sum of the time slices is equal to the target time.
[0013] As can be seen from the above description, the beneficial effects of the present invention are as follows: By decomposing the garbage collection task of a target time into garbage collection tasks of multiple time slices and executing them after each host reading task, the impact of the garbage collection task on the host reading response speed is reduced. Compared with the traditional method of first executing a garbage collection task of a target time and then executing the host reading task, the present invention alternately executes the garbage collection tasks of multiple time slices and the host reading task in a loop, shortening the data for executing the garbage collection task once, enabling the system to respond to reading requests more timely, effectively reducing the latency time of the reading response, and improving the reading response speed.
[0014] Further, after determining the target time consumed for executing the garbage collection task, it further includes: Detecting whether the target time is greater than the time slice; If so, performing the step of executing the garbage collection task according to a preset time slice after each host reading task is completed; Otherwise, executing the garbage collection task according to the target time.
[0015] As can be seen from the above description, by detecting whether the target time is greater than the time slice, the execution mode of garbage collection is dynamically selected. If the target time is short, the garbage collection task is directly executed to avoid unnecessary complex scheduling and improve the running efficiency of garbage collection. If the target time is long, the garbage collection task is executed in a time slice manner to ensure that the system performance is not affected by long garbage collection tasks.
[0016] Further, determining the target time consumed for executing the garbage collection task includes: Determining the target time consumed for executing the garbage collection task according to the number of available super blocks in the storage device.
[0017] As can be seen from the above description, the target time required for garbage collection is dynamically calculated according to the number of available super blocks in the storage device, enabling the garbage collection task to be optimized according to the current storage state. By considering the number of available super blocks, garbage collection resources can be more accurately allocated to avoid over-recycling or under-recycling, facilitating the execution of the next write task.
[0018] Further, executing the garbage collection task according to a preset time slice after each host reading task is completed, enabling the host reading task and the garbage collection task to be alternately executed until the sum of the time slices is equal to the target time includes: Dividing the target time according to the preset time slice to obtain the number of alternate executions; After each host read task is completed, a garbage collection task with the time slice as the execution duration is executed once, and the number of alternating executions is updated decrementally until the number of alternating executions is zero.
[0019] From the above description, we can see that by dividing the target time into preset time slices, the number of executions of the garbage collection task and the duration of each execution are clarified, making the garbage collection process more controllable. By decreasing and updating the number of alternating executions, the garbage collection task is gradually completed, avoiding long-term occupation of system resources.
[0020] Furthermore, the time slice is an integer multiple of the programming time of a group of flash memory blocks in the storage device.
[0021] From the above description, it can be seen that setting the time slice to an integer multiple of the programming time of a group of flash memory blocks in the storage device ensures that the garbage collection task matches the physical characteristics of the storage medium, avoids task anomalies, and ensures the reliability and stability of the garbage collection task, reducing the occurrence of errors.
[0022] Furthermore, it also includes: The host read task is preferentially executed after the host write task that triggers the garbage collection task is completed.
[0023] From the above description, it can be seen that the host read task is executed first after the write task that triggers the garbage collection instruction is completed, avoiding the delay of the read response. Through the reasonable task sequence arrangement, the system can perform garbage collection and host read tasks more efficiently and reduce resource competition.
[0024] Furthermore, it also includes: If the task execution command of the host is not received, it is detected whether the number of available super blocks in the storage device is greater than a preset threshold. If so, an idle garbage collection task with the time slice as the execution duration is executed once.
[0025] From the above description, it can be seen that since the system uses idle time to perform garbage collection, it will not compete with the host task for resources, that is, it will not affect the system's read response. Therefore, garbage collection is performed in advance when the system is idle (that is, when there is no host task execution command to be processed), optimizing the utilization of storage space and ensuring that the number of available super blocks in the storage device is sufficient, thereby reducing the time for the host to normally execute garbage collection tasks, thereby improving the system's read response speed.
[0026] Furthermore, it also includes: When executing the idle garbage collection task, if the task execution command is received, the idle garbage collection task is stopped and a host task corresponding to the task execution command is executed.
[0027] As can be seen from the above description, when performing the idle garbage collection task, if a task execution command from the host is received, the system will immediately exit the garbage collection state. Since in this mode, the number of available super blocks in the storage device is sufficient, the priority of the task execution command is higher than that of the garbage collection task, enabling the system to quickly respond to the read and write requests of the host. Therefore, while optimizing the storage space utilization rate, the idle garbage collection task can ensure the high response speed of the system.
[0028] Another embodiment of the present invention provides a storage device, including a main control chip and a storage chip; The storage chip stores a computer program, and when the computer program is executed by the main control chip, each step in the above-mentioned garbage collection method is implemented.
[0029] Another embodiment of the present invention provides a computer-readable storage medium, including a memory, a processor, and a computer program stored on the memory and running on the processor. When the processor executes the computer program, each step in the above-mentioned garbage collection method is implemented.
[0030] As can be seen from the above description, the beneficial effect of the present invention is that by decomposing the garbage collection task at a target time into multiple time-slice garbage collection tasks and executing them after each host read task, the impact of the garbage collection task on the host read response speed is reduced. Compared with the traditional method of first executing a garbage collection task at a target time and then executing the host read task, the present invention alternately executes multiple time-slice garbage collection tasks and host read tasks in a loop, shortening the data for a single execution of the garbage collection task, enabling the system to respond to read requests more timely, effectively reducing the latency time of the read response, and improving the read response speed.
[0031] When a storage device performs a host read task, the read speed includes two types. One is the sequential read speed, which determines the speed of the storage device (such as a mobile phone) when processing large chunks of data (such as videos, large games, etc.). A higher sequential read speed can ensure that the storage device can quickly read large chunks of data (that is, the mobile phone will not freeze when playing high-definition videos or running large games). The other is the random read speed, which determines the speed of the storage device (such as a mobile phone) when processing small chunks of data (such as the startup of applications, the opening of files, etc.). A higher random read speed can improve the system's response speed (such as shortening the startup time of applications). In addition, the reaction speed of the human eye is approximately around one twenty-fourth of a second (40 ms). This means that when the response time of the system to a read request is less than 40 ms, the slight lag of the host will be less obvious or reduced. Therefore, when the storage device performs a garbage collection task, the response time of the read request directly reflects the lag situation of the host. In order to improve the response speed of the read request, reduce the host lag phenomenon, and optimize the user experience, the present invention provides a garbage collection method, a storage device, and a readable storage medium, which will be described below through specific embodiments: Please refer to Figures 1 to 3 , Embodiment 1 of the present invention is as follows: A garbage collection method, applied to a storage device, includes: S10. In response to an execution command of a garbage collection task, determine the target time consumed for executing the garbage collection task.
[0032] Specifically, step S10 includes: S101. Determine the target time consumed for executing the garbage collection task according to the number of available superblocks in the storage device.
[0033] A superblock refers to a memory block composed of multiple physical blocks, and its size is usually 64 MB or 192 MB. Among them, since the memory blocks included in each superblock are different, the size of each superblock is also different. After the host write task is completed, the system will allocate the total time of the garbage collection task (GC) according to the number of remaining available superblocks. This dynamic GC time allocation mechanism can balance the host write pressure. When the host writes data slowly, the total GC time allocated is less, thereby reducing the impact on host requests and enabling the system to return to a response state without GC impact in a shorter time.
[0034] Specifically, after step S10, the method further includes: S12. Detect whether the target time is greater than the time slice. If so, execute step S20; otherwise, execute the garbage collection task according to the target time.
[0035] In addition, after the host write task that triggers the garbage collection task is completed, the host read task is preferentially executed. That is, during the execution of the host write task, if a host read task is received, after the host write task is completed, the host read task is first executed, and then the garbage collection task is executed according to time slices.
[0036] S20. After each host read task is completed, the garbage collection task is executed according to a preset time slice, so that the host read task and the garbage collection task are executed alternately until the sum of the time slices is equal to the target time.
[0037] Specifically, step S20 includes: S201. Divide the target time according to the preset time slice to obtain the number of alternate executions. Wherein, the time slice is an integer multiple of the programming time of a group of flash blocks in the storage device.
[0038] In some embodiments, the preset time slice is 5 ms. Since the common storage medium of current storage devices is TLC nand (flash memory technology that can store 3 bits of data per storage unit) or QLC nand (flash memory technology that can store 4 bits of data per storage unit), and its smallest operation unit is the physical page, programming 3 pages in a group of TLC nand is completed in about 1 ms. Therefore, the minimum execution granularity of GC must be an integer multiple of the programming time of a group of flash blocks. Since other read and erase operations are performed after the flash block programming is completed, and then the writing of the current block continues, the read and write granularity of GC needs to complete one page. Among them, the read time is 100 us, and the write time is within 1 ms. Therefore, as long as the single execution time of GC is greater than 1 ms, it will not cause abnormal flash operations. At the same time, considering the scheduling overhead of entering and exiting GC, a single execution of 5 ms for GC is a relatively reasonable time slice range. If the time consumed by the scheduling overhead is small, then a single execution of 5 ms can ensure that the actual write time of one GC is more than 4 ms.
[0039] In some embodiments, Table 1 records the GC target time allocated according to the number of remaining available super blocks and the number of alternate executions obtained based on time slice division when the host triggers the garbage collection task under different tasks.
[0040] Table 1 Target time and number of alternate executions of the garbage collection task
[0041] As can be seen from Table 1, the time for the host to execute a single write task is 4 ms. This is determined by testing in the actual application scenario. Writing 4 ms at a time makes the user's perceived fluency higher than writing 5 ms at a time, and can optimize the user experience to the greatest extent.
[0042] S202. After each host read task is completed, execute a garbage collection task with the time slice as the execution duration, and decrement and update the alternating execution count until the alternating execution count is 0.
[0043] Specifically, the method further includes: S30. If a task execution command from the host is not received, detect whether the number of available superblocks in the storage device is greater than a preset threshold. If so, execute an idle garbage collection task with the time slice as the execution duration. In some embodiments, the preset threshold is one-half of the storage space of the storage device. That is, when the number of available superblocks in the storage device is greater than one-half of the storage space, only execute an idle garbage collection task once.
[0044] Specifically, the method further includes: S40. When executing the idle garbage collection task, if the task execution command is received, stop executing the idle garbage collection task and execute the host task corresponding to the task execution command. It should be noted that since the task execution command is received at this time, the system will immediately stop the idle garbage collection task, and the exit time overhead of the idle garbage collection task is within 1 ms. Therefore, the maximum delay time for the system to respond to the task execution command is 1 ms, and it will not overly affect the response performance of the system.
[0045] In a specific scenario, the execution time of a single write task is 5 ms. At this time, the system triggers a garbage collection task, and the total time consumed by the garbage collection task is 50 ms. In the prior art, as Figure 2 shown, if the system receives a read task, after the 5-ms write task is completed, first execute the 50-ms garbage collection task, and finally execute the 200 us - 16 ms read task. According to the method of the present invention, as Figure 3 shown, if the system receives a read task, after the 5-ms write task is completed, preferentially execute the 200 us - 16 ms read task, and then execute the 5-ms garbage collection task. If a read task is still received, first execute the 200 us - 16 ms read task, and then execute the 5-ms garbage collection task, and alternately cycle in sequence until the 50-ms garbage collection task is completed. From the above Figure 2 and Figure 3By comparison, in the prior art, since the read task needs to be executed after a complete garbage collection task is completed, the read task needs to be delayed by 50 ms, and the response time is greater than 40 ms, which will cause obvious device lag. In the present invention, the read task only needs to be executed after a garbage collection task with time allocation is completed. Therefore, the read task only needs to be delayed by 5 ms, and the response time is much less than 40 ms. Therefore, the device lag phenomenon is effectively reduced.
[0046] Please refer to Figure 4 , Embodiment 2 of the present invention is as follows: A storage device, including a main control chip and a storage chip; The storage chip stores a computer program, and when the computer program is executed by the main control chip, it realizes each step in the garbage collection method described in Embodiment 1.
[0047] Please refer to Figure 5 , Embodiment 3 of the present invention is as follows: A computer-readable storage medium, including a memory, a processor, and a computer program stored on the memory and running on the processor. When the processor executes the computer program, it realizes each step in the garbage collection method described in Embodiment 1.
[0048] In summary, the present invention provides a garbage collection method, a storage device, and a readable storage medium. By decomposing the garbage collection task into multiple time slices and alternately executing them after the host read task is completed, the read response speed and overall performance of the system are significantly optimized. First, by presetting time slices to divide the target time, the number of executions of the garbage collection task and the execution duration of each time are clarified, making the garbage collection process more controllable. This method avoids occupying system resources for a long time and reduces the impact of the garbage collection task on the host read response speed. Second, the target time required for garbage collection is dynamically calculated according to the number of available super blocks in the storage device, so that the garbage collection task can be optimized according to the current storage state, avoiding over-recycling or under-recycling, and thus providing enough space for the next write task. In addition, the present invention preferentially executes the host read task after the host write task is completed, avoiding read response delays and further optimizing the task execution order. At the same time, when the system is idle, the idle garbage collection task is executed to optimize the storage space utilization rate in advance without competing for resources with the host task. When a host task execution command is received, the system will immediately stop the idle garbage collection task and give priority to responding to the host request to ensure the high response speed of the system. Compared with the traditional method, the present invention reduces the negative impact of the long garbage collection task on the system performance by decomposing a whole block into multiple small-time executions, and reduces the read delay through the task scheduling mechanism, and also improves the overall performance and user experience of the system.
[0049] In the above embodiments provided in the present application, it should be understood that the disclosed methods, devices, computer-readable storage media, and electronic devices can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of the modules is only a logical function division. In actual implementation, there may be other division methods. For example, multiple components or modules can be combined or integrated into another device, or some features can be ignored or not executed. Another point is that the displayed or discussed couplings or direct couplings or communication connections to each other can be through some interfaces. The indirect couplings or communication connections of devices or components or modules can be in electrical, mechanical, or other forms.
[0050] The components described as separate components may or may not be physically separated. The components shown as components may or may not be physical modules, that is, they may be located in one place or distributed to multiple network modules. Some or all of the components can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0051] In addition, in each embodiment of the present invention, the various functional modules can be integrated in a processing module, or each component can exist physically alone, or two or more modules can be integrated in one module. The above integrated modules can be implemented in the form of hardware or in the form of software functional modules.
[0052] 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 the present invention, in essence, or the part that contributes to the prior art, or all or part of this technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in each embodiment of the present invention. And the aforementioned storage medium includes: various media such as USB flash drives, mobile hard disks, read-only memories (ROM, Read-Only Memory), random access memories (RAM, Random Access Memory), magnetic disks, or optical discs that can store program codes.
[0053] It should be noted that, for the foregoing method embodiments, for the sake of simplicity of description, they are all expressed as a series of action combinations. However, those skilled in the art should know that the present invention is not limited by the described action sequence, because according to the present invention, certain steps can be performed in other sequences or simultaneously. Secondly, those skilled in the art should also know that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily essential to the present invention.
[0054] In the above embodiments, the descriptions of the respective embodiments have their own emphases. For the parts not detailed in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0055] The above are only the embodiments of the present invention, and do not limit the patent scope of the present invention accordingly. Any equivalent transformation made by using the content of the specification and drawings of the present invention, or directly or indirectly applied in the relevant technical fields, shall be equally included in the patent protection scope of the present invention.
Claims
1. A garbage collection method, applied to a storage device, characterized in that: include: In response to an execution command of a garbage collection task, determining a target time consumed for executing the garbage collection task; After each host read task is completed, the garbage collection task is executed according to the preset time slices, so that the host read task and the garbage collection task are executed alternately until the sum of the time slices is equal to the target time.
2. The method according to claim 1, characterized in that After determining the target time consumed by executing the garbage collection task, the method further includes: Detecting whether the target time is greater than the time slice; If yes, then executing the step of performing the garbage collection task according to the preset time slice after each host read task is completed; Otherwise, the garbage collection task is executed according to the target time.
3. The method according to claim 1, characterized in that Determining the target time consumed for executing the garbage collection task includes: The target time consumed for executing the garbage collection task is determined according to the number of available super blocks in the storage device.
4. The method according to claim 1, characterized in that: After each host read task is completed, a garbage collection task is executed according to a preset time slice, so that the host read task and the garbage collection task are executed alternately until the sum of the time slices is equal to the target time, including: Divide the target time into preset time slices to obtain the number of alternating executions; After each host read task is completed, a garbage collection task with the time slice as the execution duration is executed once, and the number of alternating executions is updated decrementally until the number of alternating executions is zero.
5. The method according to claim 1, characterized in that The time slice is an integer multiple of the programming time of a group of flash memory blocks in the storage device.
6. The method according to claim 1, characterized in that Also includes: The host read task is preferentially executed after the host write task that triggers the garbage collection task is completed.
7. The method according to claim 3, characterized in that Also includes: If the task execution command of the host is not received, it is detected whether the number of available super blocks in the storage device is greater than a preset threshold. If so, an idle garbage collection task with the time slice as the execution duration is executed once.
8. The method according to claim 7, characterized in that Also includes: When executing the idle garbage collection task, if the task execution command is received, the idle garbage collection task is stopped and a host task corresponding to the task execution command is executed.
9. A storage device, characterized in that: Including main control chip and storage chip; The storage chip stores a computer program, and when the computer program is executed by the main control chip, each step of the garbage collection method according to any one of claims 1 to 8 is implemented.
10. A computer-readable storage medium, comprising a memory, a processor, and a computer program stored in the memory and running on the processor, characterized in that: When the processor executes the computer program, the processor implements the steps of the garbage collection method as described in any one of claims 1 to 8.
Citation Information
Patent Citations
Garbage recycling method and device, storage medium and electronic equipment
CN113918350A
Garbage collection method and device, solid state disk, host and readable storage medium
CN119356606A
Method and System for Optimizing Deterministic Garbage Collection in Nand Flash Storage Systems
US20170300410A1