Garbage recycling method and equipment and storage medium

By determining the target segment number and number of segments of the mapping table based on the recycling data during the garbage collection process of the flash memory device, and interrupting the action when the preset modification amount is reached, the problem of low garbage collection efficiency of flash memory device is solved, and precise control and efficiency improvement of the number of data transfers is achieved.

CN119917423APending Publication Date: 2025-05-02YEESTOR MICROELECTRONICS CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411951366.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-27
Publication Date
2025-05-02

AI Technical Summary

Technical Problem

Flash memory devices are less efficient when performing garbage collection, mainly due to the RAM resource limitation of the main control chip and the host command response timeout, resulting in low write table efficiency and response timeout.

Method used

When triggering the garbage collection action, determine the recycling data that needs to be moved, and determine the target segment number and number of segments of the mapping table that need to be modified based on the data. When the number of segments reaches the preset modification amount, the garbage collection action is interrupted to control the number of data transfers and improve efficiency.

Benefits of technology

By controlling the number of segments, the garbage collection action is interrupted, the precise control of the number of data transfers is achieved, the garbage collection efficiency is improved, and the migration needs of different types of data are met.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119917423A_ABST
    Figure CN119917423A_ABST
Patent Text Reader

Abstract

The invention discloses a garbage collection method and device and a storage medium, and relates to the technical field of data processing. The method comprises the following steps: when a garbage collection action is triggered, determining collection data moved by the garbage collection action, then determining a target segment number of a mapping table required to be modified by the collection data according to the collection data, and recording the segment number of the mapping table correspondingly modified by the collection data according to the target segment number, the segment number is used for representing the total number of modified segments of the garbage collection action based on each target segment number, and finally, when the segment number is equal to a preset modification amount, the garbage collection action is interrupted. In the garbage collection action, the garbage collection action is controlled by determining the number of segments, so that the data migration quantity is controlled, migration requirements of different types of data are met, and the garbage collection efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data processing technology, and in particular to a garbage collection method, device and storage medium. Background Art

[0002] The GC (Garbage Collection) of flash memory devices refers to the main control chip moving the valid pages on the old blocks that have become invalid due to the host writing overwrite of some page data to new blocks, so that these old blocks can be erased and used again.

[0003] Currently, during the garbage collection process, due to the resource limitations of the main control chip RAM (Random Access Memory) and the host command response timeout limit, the data is generally moved in segments. Usually, a fixed number of clusters are moved in a segment, such as 1024 clusters in a segment. On the one hand, when moving sequential data, the table writing efficiency is not high (for example, the flash memory page size is generally 16KB, but only 4KB of new tables are written); on the other hand, when moving random data, too many mapping tables may need to be modified, resulting in a host command response timeout. Therefore, problems such as low table writing efficiency and response timeouts lead to low efficiency of flash memory devices when performing garbage collection.

[0004] The above contents are only used to assist in understanding the technical solution of the present application and do not constitute an admission that the above contents are prior art. Summary of the invention

[0005] The present application provides a garbage collection method, device and storage medium, aiming to solve the technical problem of low efficiency of flash memory devices when performing garbage collection.

[0006] To achieve the above object, the present application provides a garbage collection method, which comprises the following steps:

[0007] When a garbage collection action is triggered, determining the recycled data moved by the garbage collection action;

[0008] Determining, according to the recovered data, a target segment number of a mapping table that needs to be modified for the recovered data;

[0009] According to the target segment number, recording the segment number of the mapping table modified corresponding to the recycled data, wherein the segment number is used to represent the total number of segments modified by the garbage collection action based on each of the target segment numbers;

[0010] When the number of segments is equal to the preset modification amount, the garbage collection action is interrupted.

[0011] In one embodiment, the step of determining, based on the recycled data, a target segment number of a mapping table that needs to be modified for the recycled data includes:

[0012] Obtaining the total number of segments of the mapping table and the logical address of the recovered data;

[0013] The target segment number is determined according to the ratio of the logical address to the total number of segments.

[0014] In one embodiment, the step of updating the segment number of the mapping table when recording the garbage collection action of the recycled data according to the target segment number includes:

[0015] According to the target segment number, determining whether the segment corresponding to the mapping table is updated;

[0016] When the segment corresponding to the target segment number has not been updated, updating the segment and accumulating the target value;

[0017] According to the garbage collection action, the updated target value is determined, and the target value is determined as the number of segments.

[0018] In one embodiment, after the step of interrupting the garbage collection action when the number of segments is equal to the preset modification amount, the method further includes:

[0019] Recording the garbage collection action and the amount of the reclaimed data moved;

[0020] When the transfer quantity is equal to a preset transfer amount, the garbage collection action is interrupted.

[0021] In one embodiment, before the step of determining the recycled data moved by the garbage collection action when the garbage collection action is triggered, the method further includes:

[0022] Determining the discreteness of the corresponding data segment according to the logical address moved by the garbage collection action;

[0023] When it is determined according to the discreteness that the data segment is in a completely random state, determining the number of moved segments associated with the completely random state;

[0024] The number of moved segments is determined as the preset modification amount.

[0025] In one embodiment, after the step of determining the number of moving segments as the preset modification amount, the method further includes:

[0026] When it is determined according to the discrete degree that the data is in a complete sequence state, determining the total number of moves associated with the complete sequence state;

[0027] The total amount of movement is determined as a preset movement amount.

[0028] In one embodiment, before the step of determining the recycled data moved by the garbage collection action when the garbage collection action is triggered, the method further includes:

[0029] Detect the number of free blocks in the SSD;

[0030] When the number is lower than a preset number, it is determined that the remaining space of the current solid state drive is insufficient, and a corresponding target instruction is triggered;

[0031] The garbage collection action is started by triggering the target instruction.

[0032] In one embodiment, after the step of triggering the garbage collection action by the target instruction, the method further includes:

[0033] When it is detected that the garbage collection action is turned on, determining a target logical address that needs to be cleaned up;

[0034] Reading valid data in a target block corresponding to the target logical address;

[0035] Transferring the valid data to an idle data block and updating the mapping table;

[0036] After detecting that the target data to be cleaned up has been moved, the garbage collection action is interrupted.

[0037] In addition, to achieve the above-mentioned purpose, the present application also provides a garbage collection device, which includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the garbage collection method as described above.

[0038] In addition, to achieve the above-mentioned purpose, the present application also provides a storage medium, which is a computer-readable storage medium, and a computer program is stored on the computer-readable storage medium. When the computer program is executed by a processor, the steps of the garbage collection method as described above are implemented.

[0039] The present application provides a garbage collection method, a garbage collection device and a storage medium. When a garbage collection action is triggered, the method determines the recycled data moved by the garbage collection action, and then determines the target segment number of the mapping table that needs to be modified for the recycled data based on the recycled data, and records the number of segments of the mapping table that are modified corresponding to the recycled data based on the target segment number. The segment number is used to characterize the total number of segments modified by the garbage collection action based on each target segment number. Finally, when the segment number is equal to the preset modification amount, the garbage collection action is interrupted. In the garbage collection action, the present application controls the garbage collection action by determining the segment number, thereby controlling the amount of data moved, so as to meet the movement requirements of different types of data, thereby improving the garbage collection efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0040] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.

[0041] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0042] Figure 1 A schematic diagram of the flow chart of the first embodiment of the garbage collection method of the present application;

[0043] Figure 2 A schematic diagram of a second embodiment of the garbage collection method of the present application;

[0044] Figure 3 This is a flow chart of a third embodiment of the garbage collection method of the present application;

[0045] Figure 4 This is a flow chart of a fifth embodiment of the garbage collection method of the present application;

[0046] Figure 5 This is a flow chart of the seventh embodiment of the garbage collection method of the present application;

[0047] Figure 6 This is a schematic diagram of the architecture of the hardware operating environment of the garbage collection device involved in the embodiment of the present application.

[0048] The realization of the purpose, functional features and advantages of this application will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION

[0049] It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0050] In order to better understand the above technical solution, exemplary embodiments of the present application will be described in more detail below with reference to the accompanying drawings. Although exemplary embodiments of the present application are shown in the accompanying drawings, it should be understood that the present application can be implemented in various forms and should not be limited by the embodiments described herein. On the contrary, these embodiments are provided in order to enable a more thorough understanding of the present application and to fully convey the scope of the present application to those skilled in the art.

[0051] In order to better understand the above technical solution, the above technical solution will be described in detail below in conjunction with the accompanying drawings and specific implementation methods.

[0052] The main solution of the present application is: when a garbage collection action is triggered, determining the recycled data moved by the garbage collection action; based on the recycled data, determining the target segment number of the mapping table that needs to be modified for the recycled data; based on the target segment number, recording the number of segments of the mapping table that are modified corresponding to the recycled data, wherein the number of segments is used to represent the total number of segments modified by the garbage collection action based on each of the target segment numbers; when the number of segments is equal to a preset modification amount, interrupting the garbage collection action.

[0053] Currently, during the garbage collection process, due to the resource limitations of the main control chip RAM (Random Access Memory) and the host command response timeout limit, the data is generally moved in segments. Usually, a fixed number of clusters are moved in a segment, such as 1024 clusters in a segment. On the one hand, when moving sequential data, the table writing efficiency is not high (for example, the flash memory page size is generally 16KB, but only 4KB of new tables are written); on the other hand, when moving random data, too many mapping tables may need to be modified, resulting in a host command response timeout. Therefore, problems such as low table writing efficiency and response timeouts lead to low efficiency of flash memory devices when performing garbage collection.

[0054] When triggering a garbage collection action, the present application determines the recycled data moved by the garbage collection action, and then determines the target segment number of the mapping table that needs to be modified for the recycled data based on the recycled data, and records the number of segments of the mapping table that are modified corresponding to the recycled data based on the target segment number. The number of segments is used to characterize the total number of segments modified by the garbage collection action based on each of the target segment numbers. Finally, when the number of segments is equal to the preset modification amount, the garbage collection action is interrupted. In the garbage collection action, the present application controls the garbage collection action by determining the number of segments, thereby controlling the amount of data moved, so as to meet the movement requirements of different types of data, thereby improving the efficiency of garbage collection.

[0055] Embodiment 1

[0056] Please refer to Figure 1 , Figure 1 In the first embodiment of the garbage collection method of the present application, the garbage collection method comprises the following steps:

[0057] Step S10: when a garbage collection action is triggered, determining the recycled data moved by the garbage collection action.

[0058] In this embodiment, the garbage collection system performs the processing action, and the garbage collection action is associated with the corresponding instruction, and the process corresponding to the garbage collection action is started by triggering the instruction. When the process corresponding to the garbage collection action is started, the garbage collection system can detect the start point of the action in real time through the detection module, thereby executing the step of determining the recycled data moved by the garbage collection action.

[0059] Optionally, before determining the recovered data moved by the garbage collection action, it is necessary to set a detection module for detecting the above two operation points at the starting point of the garbage collection action and the data moving point. Therefore, when the garbage collection action is started and when the data in the data block is moved, the detection module can detect the start of the action and detect that the data is moved in real time. After detecting that the data is moved, the total number of data moves, that is, the number of moves, is recorded by a counter set in the detection module. During the garbage collection process, all operations involving data block moves are monitored, including data copying and moving from the source address to the target address. The counter is updated each time a data block is moved. The specific update method varies depending on the algorithm and storage system. For example, in the copy collection algorithm, the counter is increased by 1 each time an object is copied to a new space. In addition to the total number, detailed information such as the logical address, physical address, size, etc. of the moved data block can also be recorded for subsequent analysis and optimization.

[0060] Optionally, the method of determining the reclaimed data to be moved can first identify and mark the data segment being moved through a structure such as a memory mapping table, a segment table, or a page table. Then, according to the garbage collection algorithm, determine the starting address and the ending address of the move operation. Read the data from the source address (i.e., the current position of the data segment being moved). And verify the read data to ensure the integrity and correctness of the data, which can be achieved through a checksum, a hash value, or other data integrity verification methods. Then mark the data that needs to be moved in the data segment so that the garbage collection action can correctly identify and process the data. Copy the data marked as needing to be moved from the source address to the target address (i.e., the new memory location) and determine the reclaimed data to be moved.

[0061] Specifically, when starting the process corresponding to the garbage collection action, it is necessary to determine the garbage collection algorithm used by the garbage collection action, such as reference counting, mark-and-sweep, generational collection, etc. Different algorithms have different behaviors and data movement methods during the garbage collection process, and the detection module works differently accordingly.

[0062] Step S20: According to the recovered data, determine the target segment number of the mapping table that needs to be modified for the recovered data.

[0063] In this embodiment, the detection module deployed in the garbage collection system detects the garbage collection action in real time. When it is detected that the garbage collection action starts to move the data segment, the subsequent steps are triggered to determine the reclaimed data to be moved. After the reclaimed data is determined, the target segment number that needs to be modified in the mapping table after the reclaimed data is moved can be determined based on the logical address to which the reclaimed data is moved.

[0064] As an optional implementation manner, the target segment number may also be determined by using the logical address and the rules corresponding to the mapping table to determine the target segment number in the mapping table after the reclaimed data is moved.

[0065] Optionally, after determining the recycled data to be moved, the target segment number of the mapping table to which the recycled data is to be moved can be determined based on the target address of the recycled data to be moved. The above steps can also be performed by a script or software integrated with code compilation, and the corresponding steps can be performed on the garbage collection action according to the logic of the preset algorithm to determine the target segment number of the mapping table to which the recycled data is to be reached.

[0066] Specifically, a mapping table refers to a mapping table from logical addresses to physical addresses. In an SSD (Solid State Drive), the mapping table is responsible for converting logical addresses (i.e., addresses seen by users or operating systems) to physical addresses (i.e., addresses where data is actually stored on the flash memory chip). The number of segments in the mapping table refers to a segment of physical address space that is subject to garbage collection.

[0067] Optionally, a corresponding mapping table is constructed according to a determined garbage collection algorithm, wherein the garbage collection algorithm includes a mark-sweep algorithm, a copy algorithm, a mark-sweep algorithm, and the like. These algorithms are suitable for different application scenarios. For example, the copy algorithm is mainly used for the recovery of new generation objects. By dividing two memory areas of equal size, only one of them is used at a time. When one memory area is used up, the surviving objects are moved to the other area, and then the used memory space is cleared. This can avoid the generation of memory fragmentation, but it will sacrifice a certain degree of memory usage efficiency. The mapping table is an important data structure used to record object reference relationships during the garbage collection process. When constructing the mapping table, it is necessary to ensure that the reference relationship between objects can be accurately reflected. At the same time, during the garbage collection process, the mapping table needs to be continuously updated to reflect changes in object reference relationships.

[0068] Step S30: According to the target segment number, the segment number of the mapping table modified corresponding to the recycled data is recorded, wherein the segment number is used to represent the total number of segments modified by the garbage collection action based on each of the target segment numbers.

[0069] In this embodiment, each time a garbage collection action is executed, if the data corresponding to the garbage collection action needs to be moved across segments, a target segment number will be generated accordingly. At the same time, the segment number of the mapping table modified corresponding to the recycled data is recorded, and the actual value of the segment number is counted in real time. The segment number is used to represent the total number of segments modified by the garbage collection action based on each of the target segment numbers, that is, the total number of cross-segment moves when the garbage collection action moves data.

[0070] In addition, determining the number of segments in the mapping table involves multiple factors, including the characteristics of the garbage collection algorithm and the distribution characteristics of the objects. Different garbage collection algorithms have different requirements for the mapping table. For example, the copy algorithm moves the surviving objects to another memory area every time the garbage is collected, so the mapping table needs to be updated frequently, while the mark-and-sweep algorithm only needs to traverse the objects and update the mapping table during the marking phase. The distribution characteristics of the objects will also affect the number of segments in the mapping table. For example, if the objects are distributed more evenly in the memory, fewer segments are required to cover the entire memory space. If the objects are distributed more sparsely or concentratedly, more segments are required to more accurately reflect the reference relationship of the objects. If the system has high requirements for the real-time performance of garbage collection, the mapping table needs to be updated more frequently, and the number of segments may need to be increased to improve the update efficiency. If the system has high requirements for memory usage efficiency, it is necessary to consider reducing the number of segments to reduce memory overhead.

[0071] Step S40: When the number of segments is equal to the preset modification amount, the garbage collection action is interrupted.

[0072] In this embodiment, a preset modification amount is pre-set in the garbage collection system, and the preset modification amount is the peak value that the number of segments moved in the mapping table can reach when the garbage collection action is in a certain threshold state. The detection module tracks and records the number of segments in real time, and when it reaches the preset modification amount, the operation of interrupting the garbage collection action is triggered.

[0073] Specifically, when the number of segments is equal to the preset modification amount, the garbage collection action is interrupted. An interrupt signal can be sent to the garbage collection thread, and the sending can be completed through the API to ensure that the garbage collection thread can stop the current garbage collection operation. After the garbage collection thread receives the interrupt signal, it completes the memory block currently being processed, and cleans up the resources occupied by the garbage collection thread after it stops. Finally, according to the previously saved status information, the normal operating state of the system is restored. In addition, after interrupting garbage collection, memory can also be managed manually, such as releasing objects that are no longer used, adjusting memory allocation strategies, etc.

[0074] Optionally, before interrupting garbage collection, ensure that all necessary status information is saved, including the status of GC tasks, memory allocation, object references, etc., and record the reason, time, and system status of interrupting garbage collection for subsequent analysis and debugging. Then lock related resources to avoid data inconsistency during the interruption process.

[0075] Optionally, when performing garbage collection, you can first determine which memory segments or objects need to be recycled based on the total data corresponding to the segment number. Mark the total data that needs to perform garbage collection, and based on the marking result, release the memory space occupied by all garbage objects, or transfer these marked objects to new storage space. If the transfer to the new storage space involves changes in memory addresses, the mapping table needs to be updated to reflect these changes.

[0076] In the technical solution provided in this embodiment, when a garbage collection action is triggered, the recycled data moved by the garbage collection action is determined, and then the target segment number of the mapping table that needs to be modified for the recycled data is determined based on the recycled data, and the number of segments of the mapping table modified corresponding to the recycled data is recorded based on the target segment number. The segment number is used to characterize the total number of segments modified by the garbage collection action based on each target segment number, and finally, when the segment number is equal to the preset modification amount, the garbage collection action is interrupted. In the garbage collection action, the present application controls the garbage collection action by determining the segment number, thereby controlling the amount of data moved, so as to meet the movement requirements of different types of data, thereby improving the garbage collection efficiency.

[0077] Embodiment 2

[0078] Please refer to Figure 2 , Figure 2 The second embodiment of the garbage collection method of the present application is based on the first embodiment, and the step S20 further includes:

[0079] Step S21: Obtain the total number of segments in the mapping table and the logical address of the recovered data.

[0080] Step S22: Determine the target segment number according to the ratio of the logical address to the total number of segments.

[0081] In this embodiment, during the data migration process, for each logical block address read, the target segment number from the logical address to the physical address to which it belongs is calculated, which usually involves the internal addressing mechanism of the hard disk. The target segment number can be calculated and determined by the recovered data moved and the total number of segments.

[0082] Specifically, assuming that the size of a known segment is the total number of segments, the segment number to which the recovered data belongs can be determined by dividing the logical address of the recovered data by the total number of segments, that is, target segment number = logical address of the recovered data / / total number of segments (integer division operation).

[0083] In the technical solution provided in this embodiment, the target segment number is determined by calculating the moved recovery data and the total number of segments, so that it is possible to determine whether it has been updated by the target segment number, and then record the segment number to improve the accuracy of determining the segment number.

[0084] Embodiment 3

[0085] Please refer to Figure 3 , Figure 3 This is the third embodiment of the garbage collection method of the present application. Based on the first embodiment, the step S30 further includes:

[0086] Step S31: According to the target segment number, determine whether the segment corresponding to the mapping table is updated.

[0087] Step S32: When the segment corresponding to the target segment number has not been updated, update the segment and accumulate the target value.

[0088] Step S33: Determine the updated target value according to the garbage collection action, and determine the target value as the number of segments.

[0089] In this embodiment, a target array is first constructed in the garbage collection system, and the target array is initialized so that the target array is all 0. The target array is used to indicate whether a certain segment in the mapping table has been updated in the garbage collection action. After obtaining the target segment number of the moved recycled data, the bit value of the target array corresponding to the target segment number is obtained. The bit value represents the value of a specific position in the array, which is generally 1 or 0. In this embodiment, it is used to characterize whether the segment of the mapping table has been updated. If it is 0, it means that it has not been updated, otherwise it is 1, which means that it has been updated. When it is a preset value, that is, 0, it means that the target segment number of the mapping table has not been updated. At this time, the target segment number of the mapping table is updated, and the bit value corresponding to the target segment number in the target array is set to 1, and the target value is accumulated, that is, the numerical value of the target value is increased by 1, indicating that the mapping table has completed the update of a segment.

[0090] After the target value is accumulated, the next data moved by the garbage collection action is obtained, and the segment number corresponding to the next data is determined, and it is determined whether the position corresponding to the segment number is a preset value. If it is a preset value, the target value is accumulated. It can be understood that the segment number will change as the garbage collection action proceeds, that is, it will continue to increase as the process proceeds. When it increases to the first preset threshold, the garbage collection action is interrupted.

[0091] For example, suppose that the target array L2PBitArr[X] is constructed first, where X is the total number of L2P segments / 8. During the data movement process, the logical address is read and the segment number of the mapping table is calculated. Then the corresponding bit of the array L2PBitArr[] is checked according to the segment number. If it is 0, it is set to 1 and the target value is L2PSegNum++;

[0092] In the technical solution provided in this embodiment, the segment number of the moved data is combined with the calculation of the array to determine whether the segment number corresponding to the mapping table is updated, and the number of segments is accumulated if it is not updated. This allows the number of segments in the garbage collection action to be counted to achieve precise control of the amount of movement of the garbage collection action.

[0093] In the fourth embodiment, based on the first embodiment, after step S40, the following further includes:

[0094] Step S41: recording the garbage collection action and the amount of the reclaimed data moved.

[0095] Step S42: When the transfer quantity is equal to a preset transfer quantity, the garbage collection action is interrupted.

[0096] In this embodiment, a preset moving amount is pre-set in the garbage collection system, and the preset moving amount is the peak value that the moving amount can reach when the garbage collection action is in a certain threshold state. The moving amount is tracked in real time by the detection module, and when it reaches the preset moving amount, the operation of interrupting the garbage collection action is triggered.

[0097] In the technical solution provided in this embodiment, the garbage collection process is controlled by controlling the amount of movement, thereby controlling the garbage collection process.

[0098] Embodiment 5

[0099] Please refer to Figure 4 , Figure 4 This is the fifth embodiment of the garbage collection method of the present application. Based on the first embodiment, the method further includes:

[0100] Step S50: Determine the discreteness of the corresponding data segment according to the logical address moved by the garbage collection action.

[0101] Step S60: When it is determined according to the discreteness that the data segment is in a completely random state, the number of moved segments associated with the completely random state is determined.

[0102] Step S70: determining the number of moved segments as the preset modification amount.

[0103] In this embodiment, when the garbage collection action is turned on, the logical address moved by the garbage collection action is determined, and the corresponding data segment is obtained through the logical address. The data in the data segment is stored in the data segment as a target type, and the discreteness of the data can be determined by obtaining the target type. The discreteness of the data can be divided into two threshold states, namely, completely sequential and completely random.

[0104] Assuming that the discreteness is completely random, the number of logical addresses varies from 1K to 4K, that is, the minimum number of GC moves is 1024 LBAs (logical addresses), and the maximum number of GC moves is 4096 LBAs (logical addresses). Under the completely random discreteness, at most 1K LBAs are moved, and the mapping table of 1K segs is updated. Therefore, the number of 1K moved segments is set to the preset modification amount, and the trigger threshold for ending the recycling process can be set when the number of moves is the least in the garbage collection action.

[0105] As an optional implementation method for determining the degree of discreteness, the logical space of the disk can be divided into several equal parts, such as 3 or 4 equal parts. Taking 4 equal parts as an example, you can imagine that the disk space is divided into 4 equal parts, just like 4 grids. Each grid represents a continuous space on the disk. When data (such as a file or a group of data blocks) are completely stored in the same grid (or partition), the data can be considered continuous. This usually means that the data is physically or logically continuous, that is, they occupy a continuous space on the disk. When data spans multiple grids (or partitions), the data can be considered to be stored randomly. In this case, the data blocks may be scattered in different locations on the disk instead of being concentrated in a continuous space.

[0106] In the technical solution provided in this embodiment, the number of moved segments is set as a preset modification amount through the discrete degree, so as to improve the accuracy of controlling the garbage collection action.

[0107] In the sixth embodiment, based on the fifth embodiment, after step 70, the following further includes:

[0108] Step S71: When it is determined that the data is in a complete sequence state according to the discrete degree, the total number of moves associated with the complete sequence state is determined.

[0109] Step S72: Determine the total amount of movement as a preset movement amount.

[0110] In this embodiment, the complete sequence state refers to another threshold state of the discreteness, that is, the data block corresponding to the logical address is in a complete sequence state.

[0111] Assume that the range of GC LBA number is: 1K-4K, that is, the minimum number of GC moves is 1024 LBAs, and the maximum number is 4096 LBAs. In the fully sequential state, the LBA with the most moves, that is, 4096 LBAs, corresponds to a full page of the mapping table, where a full page is a continuous group of entries in the mapping table without spanning. Therefore, the total number of moves of 4096 is set as the preset move amount, and the trigger threshold for ending the recycling process can be set when the total number of moves is the largest in the garbage collection action.

[0112] In the technical solution provided in this embodiment, the total number of moves is set as a preset move amount by discrete degree, so as to improve the accuracy of controlling the garbage collection action.

[0113] Embodiment 7

[0114] Please refer to Figure 5 , Figure 5 This is the seventh embodiment of the garbage collection method of the present application. Based on the first embodiment, before step S10, it also includes:

[0115] Step S11: Detect the number of free blocks in the solid state drive.

[0116] Step S12: When the number is lower than a preset number, it is determined that the remaining space of the current solid state drive is insufficient, and a corresponding target instruction is triggered.

[0117] Step S13: triggering the garbage collection action through the target instruction.

[0118] In the present embodiment, the SMART data of the hard disk is accessed to detect the number of spare blocks (the number of spare blocks can indirectly reflect the number of free blocks) through professional hard disk detection software such as CrystalDiskInfo. The above software can read the value of the spare block counter to determine the current idle state of the hard disk. Then, according to factors such as the capacity, usage requirements, and performance requirements of the solid-state hard disk, a reasonable threshold value of the number of free blocks is set as a preset number. This threshold value should be able to ensure that the target instruction is triggered in time when the remaining space is insufficient, while avoiding frequent false alarms. Finally, the detected number of free blocks is compared with the preset number. If the detected value is lower than the preset value, it is determined that the current solid-state hard disk has insufficient remaining space.

[0119] When the remaining space of the solid-state drive is insufficient, the written target instructions are automatically executed. This can be achieved by writing scripts, setting up scheduled tasks, or using the system's built-in task scheduler. In addition, before this, one or more target instructions must be written according to actual needs. These instructions can automatically turn on the garbage collection function of the solid-state drive when the remaining space is insufficient. For solid-state drives that support the TRIM command, the TRIM command can be sent to inform the operating system which data blocks are no longer needed, allowing the operating system to reclaim these spaces at the appropriate time.

[0120] As an optional implementation method for detecting solid-state drives, you can use the command line function of the Windows system to perform the detection. By entering a specific command (such as "wmic diskdrive get status"), you can view the status information of the hard disk. However, this method may not be able to directly obtain the specific value of the number of free blocks. You need to write a specific script or program to parse this information to obtain the free blocks.

[0121] In the technical solution provided in this embodiment, by detecting the number of free blocks of the solid-state hard disk, it is determined whether to execute the garbage collection action, so as to improve the accuracy of starting the garbage collection action and avoid starting the garbage collection action when the hard disk is idle.

[0122] In the eighth embodiment, based on the seventh embodiment, after the step S13, the method further includes:

[0123] Step S131: when it is detected that the garbage collection action is turned on, determining the target logical address that needs to be cleaned up.

[0124] Step S132: Read valid data in the target block corresponding to the target logical address.

[0125] Step S133: Transfer the valid data to the free data block and update the mapping table.

[0126] Step S134: After detecting that the target data to be cleaned up has been moved, interrupting the garbage collection action.

[0127] In this embodiment, in the controller of the solid state drive (SSD), a detection mechanism is set to detect the start of the garbage collection action. When the garbage collection action is triggered, the detection mechanism should respond immediately and record relevant information. Then, according to the garbage collection strategy, the logical address block that needs to be cleaned up is determined. A logical-to-physical mapping table is used to find the physical storage block corresponding to the target logical address, that is, the target block. Among them, the mapping table is usually stored in the controller of the SSD and updated in real time to reflect the correspondence between the logical address and the physical address.

[0128] Then, valid data can be read from the target block by performing a read operation on the storage unit and checking the validity mark of each data page. Ensure that no valid data is missed during the reading process, and minimize the reading of invalid data. Then, find and allocate a sufficient number of free data blocks in the free storage pool of the SSD to store the valid data read from the target block. And write the valid data read from the target block to the allocated free data block. After the data transfer is completed, the L2P mapping table is updated to reflect the correspondence between the new logical address and the physical address. It is also necessary to delete or mark the old mapping relationship between the target logical address and the target block, and add a new mapping relationship to point to the free data block storing valid data to ensure that the update of the mapping table is atomic and consistent, avoiding data access conflicts or inconsistencies. After the data transfer and mapping table update are completed, the target block can be safely erased to free up storage space.

[0129] In addition, the detection module detects in real time whether the target data to be cleaned is moved from the target address to the free address, and detects whether the corresponding mapping table is updated. After the above two steps are completed, an interrupt signal is sent to the garbage collection action to interrupt the garbage collection action.

[0130] In the technical solution provided in this embodiment, the data block corresponding to the target logical address is cleaned up through the garbage collection action, so that the space in the data block can be released through the garbage collection action. After the move is completed, the garbage collection action is interrupted to avoid the situation where the garbage collection action cannot be stopped normally when the number of segments or the number of moves does not reach the preset modification amount or the preset move amount.

[0131] Since the system introduced in the embodiment of the present application is a system used to implement the method of the embodiment of the present application, based on the method introduced in the embodiment of the present application, the person skilled in the art can understand the specific structure and deformation of the system, so it is not repeated here. All systems used in the method of the embodiment of the present application belong to the scope of protection of this application.

[0132] The present application provides a garbage collection device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the garbage collection method in the above-mentioned embodiment one.

[0133] Reference below Figure 6, which shows a schematic diagram of the structure of a garbage collection device suitable for implementing the embodiment of the present application. The garbage collection device in the embodiment of the present application may include but is not limited to mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 6 The garbage collection device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0134] like Figure 6 As shown, the garbage collection device may include a processing device 1001 (e.g., a core processor, a graphics processor, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM: Read Only Memory) 1002 or a program loaded from a storage device 1003 to a random access memory (RAM: Random Access Memory) 1004. In RAM1004, various programs and data required for the operation of the garbage collection device are also stored. The processing device 1001, ROM1002, and RAM1004 are connected to each other through a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Generally, the following systems can be connected to the I / O interface 1006: an input device 1007 including, for example, a touch screen, a touch pad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; an output device 1008 including, for example, a liquid crystal display (LCD: Liquid Crystal Display), a speaker, a vibrator, etc.; a storage device 1003 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1009. The communication device 1009 can allow the garbage collection device to communicate with other devices wirelessly or wired to exchange data. Although the garbage collection device with various systems is shown in the figure, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems can be implemented or have alternatively.

[0135] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device, or installed from a storage device 1003, or installed from a ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are executed.

[0136] The garbage collection device provided by the present application adopts the garbage collection method in the above embodiment, which can solve the technical problem of low efficiency of flash memory devices when performing garbage collection. Compared with the prior art, the beneficial effects of the garbage collection device provided by the present application are the same as the beneficial effects of the garbage collection method provided by the above embodiment, and other technical features in the garbage collection device are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.

[0137] It should be understood that the various parts disclosed in this application can be implemented by hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.

[0138] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

[0139] The present application provides a computer-readable storage medium having computer-readable program instructions (ie, computer programs) stored thereon, and the computer-readable program instructions are used to execute the garbage collection method in the above-mentioned embodiment.

[0140] The computer-readable storage medium provided in the present application may be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared or semiconductor systems, systems or devices, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, system or device. The program code contained on the computer-readable storage medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination of the above.

[0141] The computer-readable storage medium may be included in the garbage collection device; or may exist independently without being assembled into the garbage collection device.

[0142] The above-mentioned computer-readable storage medium carries one or more programs. When the above-mentioned one or more programs are executed by the garbage collection device, the garbage collection device: determines the recycled data moved by the garbage collection action when the garbage collection action is triggered; determines the target segment number of the mapping table that needs to be modified for the recycled data based on the recycled data; records the number of segments of the mapping table modified corresponding to the recycled data based on the target segment number, wherein the number of segments is used to represent the total number of segments modified by the garbage collection action based on each target segment number; and interrupts the garbage collection action when the number of segments is equal to the preset modification amount.

[0143] Computer program code for performing the operations of the present application may be written in one or more programming languages ​​or a combination thereof, including object-oriented programming languages ​​such as Java, Smalltalk, C++, and conventional procedural programming languages ​​such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0144] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present application. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of a code, and the module, a program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, and the combination of boxes in the block diagram and / or flowchart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0145] The modules involved in the embodiments described in this application may be implemented by software or hardware, wherein the name of the module does not constitute a limitation on the unit itself in some cases.

[0146] The readable storage medium provided in the present application is a computer-readable storage medium, which stores computer-readable program instructions (i.e., computer programs) for executing the above-mentioned garbage collection method, and can solve the technical problem that the flash memory device has low efficiency when performing garbage collection. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided in the present application are the same as the beneficial effects of the garbage collection method provided in the above-mentioned embodiment, and will not be described in detail here.

[0147] An embodiment of the present application provides a computer program product, including a computer program, which implements the steps of the above-mentioned garbage collection method when executed by a processor.

[0148] The computer program product provided in this application can solve the technical problem that the flash memory device has low efficiency when performing garbage collection. Compared with the prior art, the beneficial effects of the computer program product provided in the embodiment of this application are the same as the beneficial effects of the garbage collection method provided in the above embodiment, which will not be repeated here.

[0149] The above are only preferred embodiments of the present application, and are not intended to limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the present application specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent processing scope of the present application.

Claims

1. A garbage collection method, characterized in that: The garbage collection method comprises the following steps: When a garbage collection action is triggered, determining the recycled data moved by the garbage collection action; Determining, according to the recovered data, a target segment number of a mapping table that needs to be modified for the recovered data; According to the target segment number, recording the segment number of the mapping table modified corresponding to the recycled data, wherein the segment number is used to represent the total number of segments modified by the garbage collection action based on each of the target segment numbers; When the number of segments is equal to the preset modification amount, the garbage collection action is interrupted.

2. The method according to claim 1, characterized in that The step of determining, based on the recovered data, a target segment number of a mapping table that needs to be modified for the recovered data comprises: Obtaining the total number of segments of the mapping table and the logical address of the recovered data; The target segment number is determined according to the ratio of the logical address to the total number of segments.

3. The method according to claim 1, characterized in that The step of updating the segment number of the mapping table when recording the recycling data to perform the garbage collection action according to the target segment number comprises: According to the target segment number, determining whether the segment corresponding to the mapping table is updated; When the segment corresponding to the target segment number has not been updated, updating the segment and accumulating the target value; According to the garbage collection action, the updated target value is determined, and the target value is determined as the number of segments.

4. The method according to claim 1, characterized in that After the step of interrupting the garbage collection action when the number of segments is equal to the preset modification amount, the method further includes: Recording the garbage collection action and the amount of the reclaimed data moved; When the transfer quantity is equal to a preset transfer amount, the garbage collection action is interrupted.

5. The method according to claim 1, characterized in that Before the step of determining the recycled data moved by the garbage collection action when the garbage collection action is triggered, the step further includes: Determining the discreteness of the corresponding data segment according to the logical address moved by the garbage collection action; When it is determined according to the discreteness that the data segment is in a completely random state, determining the number of moved segments associated with the completely random state; The number of moved segments is determined as the preset modification amount.

6. The method according to claim 5, characterized in that After the step of determining the number of moving segments as the preset modification amount, the method further includes: When it is determined according to the discrete degree that the data is in a complete sequence state, determining the total number of moves associated with the complete sequence state; The total amount of movement is determined as a preset movement amount.

7. The method according to claim 1, characterized in that Before the step of determining the recycled data moved by the garbage collection action when the garbage collection action is triggered, the step further includes: Detect the number of free blocks in the SSD; When the number is lower than a preset number, it is determined that the remaining space of the current solid state drive is insufficient, and a corresponding target instruction is triggered; The garbage collection action is started by triggering the target instruction.

8. The method according to claim 7, characterized in that After the step of triggering the garbage collection action by the target instruction, the method further includes: When it is detected that the garbage collection action is turned on, determining a target logical address that needs to be cleaned up; Reading valid data in a target block corresponding to the target logical address; Transferring the valid data to an idle data block and updating the mapping table; After detecting that the target data to be cleaned up has been moved, the garbage collection action is interrupted.

9. A garbage recycling device, characterized in that: The garbage collection device comprises: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the garbage collection method according to any one of claims 1 to 8.

10. A storage medium, characterized in that: The storage medium is 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 garbage collection method according to any one of claims 1 to 8 are implemented.