Solid-state drive (SSD) garbage collection methods, devices, computer equipment, and storage media
By introducing a reclaimed unit segment linked list into the host file system, the host can actively control the garbage collection of solid-state drives, solving the problem of the host's inability to control garbage collection in the existing technology and improving the service quality of the system.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- DOUYIN VISION CO LTD
- Filing Date
- 2024-12-25
- Publication Date
- 2026-05-26
AI Technical Summary
In existing technologies, garbage collection of solid-state drives (SSDs) is controlled by the drive itself, making it difficult for the host to actively control and affecting the system's QoS.
By introducing a reclaimable unit segment linked list into the host file system, garbage collection on the host side is achieved by judging and maintaining the validity of reclaimable unit segments, including rewriting valid segments and releasing the storage space of invalid segments.
It enables garbage collection of solid-state drives on the host side, improving the system's QoS.
Smart Images

Figure CN119759288B_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of waste recycling technology, specifically to waste recycling methods, apparatus, computer equipment, and storage media for solid-state drives. Background Technology
[0002] Solid-state drives (SSDs) use Nand (Notand) flash memory, which only allows sequential writes. However, upper-layer software writes can exhibit various behaviors. Therefore, SSDs typically use an FTL (Flash Translation Layer) table to convert these write behaviors into sequential writes within Superblocks. In this case, some data within a Superblock may be valid, while other data may be invalid. If the SSD needs to reclaim valid space, garbage collection (CG) must be performed.
[0003] In the current design, when using SSDs, garbage collection is controlled by the hard drive itself, and the host has no control over it. Garbage collection in SSDs that is not controlled by the host often affects the system's QoS (Quality of Service). Summary of the Invention
[0004] In view of this, the present disclosure provides a method, apparatus, computer equipment and storage medium for garbage collection of solid-state drives, in order to solve the problem that the host computer has difficulty in actively controlling garbage collection.
[0005] Firstly, this disclosure provides a garbage collection method for solid-state drives, applied to a host file system, including:
[0006] When solid-state drives require garbage collection, identify the first collection unit that needs to be garbage collected;
[0007] Obtain the first recycling unit segment linked list from the host file system; the first recycling unit segment linked list is used to record segments belonging to the first recycling unit;
[0008] Determine whether each segment in the first recycling unit segment list is valid;
[0009] If a valid segment exists in the first recycling unit segment linked list, the data corresponding to the valid segment is rewritten to the second recycling unit, and the valid segment is written to the second recycling unit segment linked list of the second recycling unit.
[0010] If an invalid segment exists in the first recycling unit segment linked list, the storage space corresponding to the invalid segment is released.
[0011] Secondly, this disclosure provides a garbage collection device for a solid-state drive, applied to a host file system, comprising:
[0012] The recycling unit determination module is used to determine the first recycling unit that needs to be recycled when the solid-state drive needs to be recycled.
[0013] The linked list acquisition module is used to acquire the first recycling unit segment linked list of the first recycling unit from the host file system; the first recycling unit segment linked list is used to record segments belonging to the first recycling unit;
[0014] The judgment module is used to determine whether each segment in the first recycling unit segment linked list is valid;
[0015] The garbage collection module is used to rewrite the data corresponding to the valid segment to the second collection unit and write the valid segment to the second collection unit's second collection unit segment list when a valid segment exists in the first collection unit segment list; and to release the storage space corresponding to the invalid segment when an invalid segment exists in the first collection unit segment list.
[0016] Thirdly, this disclosure provides a computer device, including: a memory and a processor, which are communicatively connected to each other. The memory stores computer instructions, and the processor executes the computer instructions to perform the solid-state drive garbage collection method of the first aspect or any corresponding embodiment described above.
[0017] Fourthly, this disclosure provides a computer-readable storage medium storing computer instructions for causing a computer to execute the solid-state drive garbage collection method of the first aspect or any corresponding embodiment described above.
[0018] Fifthly, this disclosure provides a computer program product, including computer instructions for causing a computer to execute the solid-state drive garbage collection method of the first aspect or any corresponding embodiment described above.
[0019] This disclosure establishes a linked list of reclaimed unit segments based on the segments corresponding to each reclaimed unit. The host file system records and maintains the linked list of reclaimed unit segments for each reclaimed unit. When garbage collection is required for the first reclaimed unit, the host file system can perform garbage collection based on the linked list of the first reclaimed unit segments. During the garbage collection process, appropriate processing can be performed on valid and invalid segments respectively, ensuring that data in valid segments can be read and written correctly. This solution enables host-side garbage collection of SSDs, that is, garbage collection can be performed at the host file system level, which can help improve system QoS. Attached Figure Description
[0020] To more clearly illustrate the technical solutions in the specific embodiments or related technologies of this disclosure, the accompanying drawings used in the description of the specific embodiments or related technologies will be briefly introduced below. Obviously, the accompanying drawings described below are some embodiments of this disclosure. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0021] Figure 1 This is a schematic flowchart of a solid-state drive garbage collection method according to an embodiment of the present disclosure;
[0022] Figure 2 This is a schematic flowchart of a garbage collection method for a solid-state drive according to an embodiment of the present disclosure;
[0023] Figure 3 This is a schematic flowchart of a garbage collection method for a solid-state drive according to an embodiment of the present disclosure;
[0024] Figure 4 This is a schematic diagram illustrating two files stored by two RUs according to an embodiment of this disclosure;
[0025] Figure 5 This is a schematic diagram illustrating waste recycling of RU2 according to an embodiment of this disclosure;
[0026] Figure 6 This is a structural block diagram of a solid-state drive garbage collection device according to an embodiment of the present disclosure;
[0027] Figure 7 This is a schematic diagram of the hardware structure of a computer device according to an embodiment of the present disclosure. Detailed Implementation
[0028] To make the objectives, technical solutions, and advantages of the embodiments of this disclosure clearer, the technical solutions of the embodiments of this disclosure will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this disclosure, and not all embodiments. Based on the embodiments of this disclosure, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this disclosure.
[0029] In recent years, a new technology called FDP has been developed under the NVMe protocol framework to optimize data storage and management. FDP technology introduces the concepts of RU (Reclaim Unit), RG (Reclaim Group), and RUH (Reclaim Unit Handle). An RU is a physical unit that can be independently erased and written; multiple RUs form an RG, and the performance and reliability of RGs are independent of each other. RUH is the write pointer to the RU; when one RU is full, the write operation switches to another RU. The host can use I / O (input / output) commands to write data from different applications into RUs through different RUHs, achieving data isolation.
[0030] For example, a user can write using multiple data streams, with the data stream ID labeled RUH. At the same time, a SuperBlock can correspond to one RU, and one RU can only correspond to one RUH at a time. Therefore, whether data is distributed on the same SuperBlock can be determined by whether the RU has been changed.
[0031] The solid-state drive garbage collection method provided in this embodiment maintains a segment linked list of each collection unit in the host-side file system, i.e., a collection unit segment linked list. By using this collection unit segment linked list, the host can perform garbage collection on the SSD in units of collection units. In other words, the host can control the garbage collection process of the SSD, which is beneficial to improving the QoS of the system.
[0032] According to an embodiment of this disclosure, a method for garbage collection of a solid-state drive is provided. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.
[0033] This embodiment provides a garbage collection method for solid-state drives (SSDs), which can be applied to a host capable of connecting to the SSD, such as a mobile terminal or a server. Specifically, the method is applied to the host file system, and garbage collection of the SSD is implemented based on the host file system. Figure 1 This is a flowchart of a solid-state drive garbage collection method according to an embodiment of the present disclosure, such as... Figure 1 As shown, the process includes the following steps.
[0034] Step S101: When it is necessary to perform garbage collection on the solid-state drive, determine the first recycling unit that needs to be garbage collected.
[0035] In this embodiment, PDF technology enables the host to perceive the data being written to the solid-state drive (SSD), thus aiding in determining data writing and recycling strategies. For example, the host can obtain the remaining capacity of the RU (Real Estate Runner) through relevant interfaces.
[0036] When the host determines that the solid-state drive (SSD) needs garbage collection, such as when the SSD is running out of space or when it receives a garbage collection command initiated by the user, it can determine that garbage collection of the SSD is currently required. At this time, the host determines the recycling unit (RU) in the SSD that needs garbage collection, which is the first recycling unit, also known as the first RU.
[0037] One approach is to prioritize garbage collection of RUs storing older data; alternatively, the amount of valid data in each RU can be determined, and the RU with the least valid data can be selected as the first RU to be garbage collected, thereby reducing write amplification when garbage collecting is performed on the first RU.
[0038] Step S102: Obtain the first reclaim unit segment linked list from the host file system; the first reclaim unit segment linked list is used to record segments belonging to the first reclaim unit.
[0039] In this embodiment, the host file system uses extents as the logical unit for allocating and managing storage space. An extent is a contiguous block of data that can be allocated to files sequentially. Furthermore, a reclaimed unit typically corresponds to multiple extents. In this embodiment, the extents corresponding to a reclaimed unit are represented by a linked list, forming a reclaimed unit extent linked list. That is, the reclaimed unit extent linked list can record the extents belonging to the corresponding reclaimed unit.
[0040] For ease of description, the recycling unit segment linked list of the first recycling unit is referred to as the first recycling unit segment linked list; wherein, the recycling unit segment linked list can also be referred to as the RU segment linked list, and correspondingly, the first recycling unit segment linked list can also be referred to as the first RU segment linked list.
[0041] In this embodiment, the host file system records and maintains the RU segment linked list for each RU. After the first RU is determined, the corresponding first RU segment linked list can be obtained from the host file system, thereby determining each segment corresponding to the first RU.
[0042] Step S103: Determine whether each segment in the first recycling unit segment list is valid.
[0043] In this embodiment, each entry in the first RU segment linked list corresponds to a segment of the first RU. The validity of a segment can be determined by judging whether the data stored in each segment is valid. For example, if a segment belonging to the first RU segment linked list stores invalid data, then that segment is also invalid.
[0044] As mentioned above, an extent is a contiguous block of data, typically represented by a starting address and a length. Once data is stored in an extent, it is initially valid; if the data in that extent is no longer used, for example, if the data in that extent is deleted, the extent becomes invalid.
[0045] Step S104: If a valid segment exists in the first recycling unit segment linked list, the data corresponding to the valid segment is rewritten to the second recycling unit, and the valid segment is written to the second recycling unit segment linked list of the second recycling unit.
[0046] In this embodiment, an RU can correspond to multiple segments, that is, multiple segments can belong to the same RU. For the first RU, if it corresponds to a segment that stores valid data, it can be determined that there is a valid segment in the first RU segment list. When garbage collection is performed on the first RU, the valid segment needs to be rewritten so that the data corresponding to the valid segment can be rewritten to other collection units, that is, the second collection unit (i.e., the second RU).
[0047] Similar to the first RU, the host file system also records the RU segment linked list of the second RU, i.e., the second RU segment linked list. When a valid segment is rewritten, the valid segment is written into the second RU segment linked list. Based on the second RU segment linked list, it can be determined that the valid segment belongs to the second RU. When garbage collection is performed on the second RU later, the segment corresponding to the second RU can also be correctly located.
[0048] Step S105: If there is an invalid segment in the first recycling unit segment linked list, release the storage space corresponding to the invalid segment.
[0049] In this embodiment, for the first RU, if it corresponds to a segment storing invalid data, then it can be determined that an invalid segment exists in the first RU segment list; for example, if data in a segment is deleted, then that segment is an invalid segment. For invalid segments of the first RU, when performing garbage collection on the first RU, it is not necessary to rewrite the invalid segment; the storage space corresponding to the invalid segment can be directly released. For example, based on the logical address corresponding to the invalid segment, the logical address space occupied by the invalid segment can be released, thereby erasing the data block corresponding to the invalid segment.
[0050] Furthermore, if the first RU corresponds to multiple valid segments or multiple invalid segments, each valid segment or each invalid segment can be processed according to steps S104 and S105 respectively, so that all segments corresponding to the first RU can be processed accordingly, and finally the garbage collection operation of the first RU can be realized.
[0051] It is understandable that if the first RU segment linked list of the first RU is empty, it means that there is no valid data in the first RU, which is equivalent to all segments of the first RU being invalid segments. When performing garbage collection on the first RU, the Super Block corresponding to the first RU can be directly erased. At this time, there is no write amplification caused by data migration due to the need for space reclamation.
[0052] The solid-state drive (SSD) garbage collection method provided in this embodiment establishes a linked list of reclaimed unit segments based on the segments corresponding to each reclaimed unit. The host file system records and maintains the linked list of reclaimed unit segments for each reclaimed unit. When garbage collection is required for the first reclaimed unit, the host file system can perform garbage collection based on the linked list of the first reclaimed unit segments. During the garbage collection process, corresponding processing can be performed on valid and invalid segments respectively, ensuring that data in valid segments can be read and written correctly. This method enables garbage collection of SSDs on the host side, that is, garbage collection can be performed at the host file system level, which can help improve system QoS.
[0053] This embodiment provides a garbage collection method for solid-state drives (SSDs), which can be applied to a host capable of connecting to the SSD, such as a mobile terminal or a server. Specifically, the method is applied to the host file system, and garbage collection of the SSD is implemented based on the host file system. Figure 2 This is a flowchart of a solid-state drive garbage collection method according to an embodiment of the present disclosure, such as... Figure 2 As shown, the process includes the following steps.
[0054] Step S201: When it is necessary to perform garbage collection on the solid-state drive, determine the first recycling unit that needs to be garbage collected.
[0055] Please see details Figure 1 Step S101 of the illustrated embodiment will not be described again here.
[0056] Step S202: Obtain the first reclaim unit segment linked list from the host file system; the first reclaim unit segment linked list is used to record segments belonging to the first reclaim unit.
[0057] Please see details Figure 1 Step S102 of the illustrated embodiment will not be described again here.
[0058] Step S203: Determine whether each segment in the first recycling unit segment list is valid.
[0059] Specifically, the above step S203, "determine whether each segment in the first recycling unit segment list is valid", includes the following steps S2031 to S2035.
[0060] Step S2031: Determine the target file corresponding to the target segment in the first recycling unit segment list.
[0061] In this embodiment, for each segment in the first RU segment list, it is necessary to determine whether it is valid. For ease of description, the segments in the first RU segment list are referred to as target segments to determine whether the target segments are valid. For each segment in the first RU segment list, its validity can be determined according to the processing method for the target segments.
[0062] Each segment is used to store part or all of the data of the corresponding file. The file corresponding to the target segment is called the target file, that is, the target segment corresponding to the first RU, which stores part or all of the data of the target file.
[0063] In some optional implementations, the host file system records and maintains metadata for each segment, i.e., segment metadata, which represents the correspondence between segments and files. Specifically, step S2031, "determining the target file corresponding to the target segment in the first recycling unit segment list," may include steps a1 to a2.
[0064] Step a1: Obtain the segment metadata of the target segment; the segment metadata includes the file identifier.
[0065] Step a2: Determine the corresponding target file based on the file identifier in the segment metadata of the target segment.
[0066] In this embodiment, each segment has segment metadata, which records the storage space corresponding to that segment. For example, the segment metadata can record the starting address and length of the corresponding segment's storage space. Furthermore, the segment metadata also includes a file identifier. After some or all of a file's data is stored in a segment, the segment metadata records the corresponding file identifier, such as a file ID.
[0067] For the target segment of the first RU, its segment metadata also includes a corresponding file identifier, which is the identifier of the target file. Therefore, the target file corresponding to the target segment can be determined based on the file identifier in the segment metadata of the target segment.
[0068] Step S2032: Obtain the file segment list of the target file from the host file system; the file segment list of the target file is used to record the segments belonging to the target file.
[0069] In this embodiment, the host file system also records a segment linked list for each file, i.e., a file segment linked list. Specifically, based on the file size, it can be stored in one or more segments, that is, the file corresponds to one or more segments, or one or more segments also belong to the file; these segments can form corresponding linked lists, i.e., file segment linked lists.
[0070] For example, if a file is divided into three non-contiguous segments, a file segment linked list can record information about the three segments, with each segment pointing to the starting address and length of its corresponding storage space. When the file needs to be read or written, the host file system will traverse this file segment linked list, accessing each segment sequentially to complete the read / write operation.
[0071] Once the target linked list corresponding to the target segment is determined, the file segment linked list of the target file can be determined, thereby determining each segment corresponding to the target file, that is, which segment(s) the target file is stored in.
[0072] Optionally, step S2032, "obtaining the file segment list of the target file from the host file system", includes steps b1 to b2.
[0073] Step b1: Determine the inode metadata of the target file based on the file identifier of the target file; the inode metadata includes the file identifier and the file segment list.
[0074] Step b2: Obtain the file segment list of the target file from the inode metadata of the target file.
[0075] In this embodiment, metadata of the inode is set for each file, and a corresponding file segment list is set in the inode metadata. Thus, after determining the inode metadata of the target file, the file segment list of the target file can be further obtained.
[0076] For example, the inode metadata records the head of the file segment linked list, and the corresponding file segment linked list can be obtained based on the linked list head.
[0077] Step S2033: Determine whether the segment corresponding to the target segment in the file segment linked list of the target file is valid.
[0078] In this embodiment, the file segment linked list can represent whether each segment is valid. Specifically, when writing to the target file, each segment in the target file's file segment linked list is initially valid; when the data in the target file is no longer used, the segments in the target file's file segment linked list corresponding to the no-longer-used data are set to invalid. For example, if the entire target file is deleted, then all segments of the target file are set to invalid.
[0079] Step S2034: If the segment corresponding to the target segment is valid, determine that the target segment is valid.
[0080] Step S2035: If the segment corresponding to the target segment is invalid, determine that the target segment is invalid.
[0081] In this embodiment, if the same segment exists in both the first RU segment list and the target file's file segment list, it indicates that the segment belongs to the corresponding first RU and stores some or all of the target file's data. If a segment in the target file's file segment list is invalid, it can be determined that the corresponding segment in the first RU segment list is also invalid, for example, the target segment is invalid; therefore, it can be determined whether the corresponding segment in the first RU segment list is valid.
[0082] In this way, a flag can be set for each entry in the file segment list to indicate whether it is valid; or, when some data in a file is set to invalid (e.g., deleted), the segment corresponding to the invalid data can be directly deleted from the file segment list of that file, and the validity of the target segment can be determined by checking whether the target segment is in the file segment list of the target file.
[0083] Step S204: If a valid segment exists in the first recycling unit segment linked list, the data corresponding to the valid segment is rewritten to the second recycling unit, and the valid segment is written to the second recycling unit segment linked list of the second recycling unit.
[0084] Please see details Figure 1 Step S104 of the illustrated embodiment will not be described again here.
[0085] Step S205: If there is an invalid segment in the first recycling unit segment linked list, release the storage space corresponding to the invalid segment.
[0086] Please see details Figure 1 Step S105 of the illustrated embodiment will not be described again here.
[0087] The solid-state drive (SSD) garbage collection method provided in this embodiment enables host-side garbage collection of SSDs, helping to improve system QoS. Furthermore, by using segment metadata to record corresponding file identifiers, the files corresponding to each segment can be quickly and easily identified. This allows the use of a file segment linked list to determine whether a segment is still valid, enabling different processing for different segments and ensuring correct garbage collection based on the host file system.
[0088] This embodiment provides another method for garbage collection of solid-state drives (SSDs), which can be applied to a host that can connect to the SSD, such as a mobile terminal or a server. Specifically, the method is applied to the host file system, and garbage collection of the SSD is implemented based on the host file system.
[0089] This involves setting up various structures for the host file system, recording corresponding metadata based on different structures, and using this metadata to record and maintain relevant information for each RU and segment, thereby enabling file reading, writing, and garbage collection based on the host file system.
[0090] In this embodiment, a structure for a reclaim unit is provided, namely the reclaim unit structure (struct ru); the reclaim unit structure includes: a reclaim unit identifier field (ru_id), a reclaim unit handle identifier field (ru_h_id), and a reclaim unit segment linked list field (ru_extents); and may also include a field (reclaim_group) to which the reclaim unit belongs.
[0091] For example, one representation of the recycling unit structure can be shown below:
[0092]
[0093] Based on this recycling unit structure, the recycling unit metadata, i.e., RU metadata, of each recycling unit can be recorded. Accordingly, the RU metadata includes: recycling unit identifier, recycling unit handle identifier, and recycling unit segment linked list; and may also include the recycling group to which the recycling unit belongs.
[0094] Furthermore, in this embodiment, the metadata of each segment is recorded using the structure of the extent. In this embodiment, in addition to the starting address field (start) and length field of the storage space, the struct extent also includes the following: file identifier field (file_id), first link pointer field (file_link) for linking to the file extent list (file_extents), and second link pointer field (ru_link) for linking to the reclaim unit extent list (ru_extents).
[0095] For example, one representation of a segment structure can be shown below:
[0096]
[0097] Based on this segment structure, the segment metadata of each segment can be recorded. Accordingly, the segment metadata includes: file identifier, first link pointer for linking to the file segment linked list, and second link pointer for linking to the recycling unit segment linked list, etc.
[0098] In addition, this embodiment also includes a file inode structure (struct file_inode), which includes a file identifier field (file_id) and a file segment list field (file_extents).
[0099] For example, one representation of an index node structure can be shown below:
[0100]
[0101]
[0102] Based on this inode structure, the inode metadata of each file can be recorded. Accordingly, the inode metadata includes: file identifier and file segment linked list.
[0103] In this embodiment, by introducing the three types of metadata mentioned above into the host file system, file reading and writing and garbage collection can be achieved by maintaining and updating each type of metadata. Figure 3 This is a flowchart of a solid-state drive garbage collection method according to an embodiment of the present disclosure, such as... Figure 3 As shown, the process includes the following steps.
[0104] Step S301: When writing the current file to the solid-state drive, determine the current reclaim unit and the current reclaim unit handle that need to be written to the current file.
[0105] In this embodiment, when a file needs to be written to the solid-state drive, the file is designated as the current file, and the recycling unit and recycling unit handle that need to be written to the current file can be determined, namely the current recycling unit and the current recycling unit handle, which are also the current RU and the current RUH.
[0106] When the host writes data, it can obtain the remaining capacity of the RU according to the FDP technology. If the amount of data to be written can be written to the RU (i.e., the amount of data to be written is less than the remaining capacity), the RU can be kept unchanged and data can continue to be written to the RU, that is, the RU is used as a current RU for writing to the current file; if the remaining capacity of the RU is insufficient, the RU needs to be replaced and the next RU is used as the current RU.
[0107] Furthermore, when writing a file, the host can specify the corresponding RUH, and after the RU pointed to by the RUH is used up, it can point to the next RU.
[0108] Step S302: Record the metadata of the current recycling unit and the metadata of the current file's inode; the metadata of the recycling unit includes: recycling unit identifier, recycling unit handle identifier and recycling unit segment list; the metadata of the inode includes file identifier and file segment list.
[0109] Step S303: Determine at least one segment corresponding to the current file and record the segment metadata of each segment; the segment metadata includes: file identifier, a first link pointer for linking to the file segment linked list and a second link pointer for linking to the recycling unit segment linked list.
[0110] Step S304: Link the current file's segment to the current file's file segment linked list according to the first link pointer; link the current file's segment to the current recycling unit's recycling unit's recycling unit's segment linked list according to the second link pointer.
[0111] As described above, the host file system records RU metadata for each RU and extent metadata for each extent. The RU metadata includes: an RU identifier (e.g., the RU ID) and a linked list of RU extents. The extent metadata includes: a file identifier, a first link pointer to the file's linked list of extents, and a second link pointer to the RU's linked list of extents. Furthermore, each file records corresponding inode metadata.
[0112] After determining the current RU and current RUH of the current file, in addition to writing some or all of the data of the current file to the current RU, the RU metadata of the current RU can also be recorded, which specifically includes the identifier of the current RU, the identifier of the current RUH, and the RU segment linked list of the current RU.
[0113] For the current file, record the inode metadata of the current file, which specifically includes the identifier of the current file and the file segment linked list.
[0114] Furthermore, since a file can be divided into multiple segments, the current file may correspond to one segment or multiple segments. For each segment corresponding to the current file, segment metadata can be recorded based on a segment structure. As mentioned above, this segment metadata includes: a file identifier, a first link pointer to the file segment list, and a second link pointer to the reclaimed unit segment list.
[0115] Specifically, the first link pointer is used to link the corresponding section of the current file to the file section linked list of the current file. The second link pointer is used to link the corresponding section of the current file to the RU section linked list of the current RU. Since the current file may be stored in different RUs, the second link pointer for different sections of the same file may be used to link to the RU section linked lists of different RUs.
[0116] Figure 4 This diagram illustrates a scenario where two files are stored using two RUs. For example... Figure 4 As shown, for file 1, the inode metadata, including file segment linked list 1, is recorded. Since file 1 is large, it is divided into six segments, namely segments E11 to E16, and the segment metadata of these six segments can be recorded. Furthermore, based on the first link pointer in the segment metadata of these six segments, these six segments can be sequentially linked to file segment linked list 1 of file 1. A schematic diagram of file segment linked list 1 can be found in [reference needed]. Figure 4 As shown.
[0117] Similarly, for file 2, the inode metadata, including file segment linked list 2, is recorded. Since file 2 is small, it is divided into four segments, namely segments E21 to E24, and the segment metadata of these four segments can be recorded. Furthermore, based on the first link pointer in the segment metadata of these four segments, these four segments can be sequentially linked to file segment linked list 2 of file 2. A schematic diagram of file segment linked list 2 can also be found in [reference needed]. Figure 4 As shown.
[0118] And, as Figure 4 As shown, each RU corresponds to five segments; assuming that RU1 and RU2 are empty before writing files 1 and 2. When writing file 1, most of the data of file 1 can be written to segments E11 to E15 corresponding to RU1; after RU1 is full, the RU is updated, and the remaining data of file 1 is written to the next RU, that is, to segment E16 corresponding to RU2. Afterwards, when writing file 2, the data of file 2 is written to segments E21 to E24 corresponding to RU2.
[0119] Specifically, RU 1 and RU 2 record corresponding RU metadata, which includes their respective RU segment linked lists, namely RU segment linked list 1 and RU segment linked list 2. By configuring the second link pointer in the segment metadata of segments E11 to E15, segments E11 to E15 can be linked to RU segment linked list 1. Similarly, by configuring the second link pointer in segments E16 and E21 to E24, segments E16 and E21 to E24 can be linked to RU segment linked list 2. The generated RU segment linked list 1 and RU segment linked list 2 can be found in [reference needed]. Figure 4 .
[0120] Step S305: If garbage collection of the solid-state drive is required, determine the first recycling unit that needs to be garbage collected.
[0121] Please see details Figure 1 Step S101 of the illustrated embodiment will not be described again here.
[0122] Step S306: Obtain the first reclaim unit segment linked list from the host file system; the first reclaim unit segment linked list is used to record segments belonging to the first reclaim unit.
[0123] Please see details Figure 1 Step S102 of the illustrated embodiment will not be described again here.
[0124] Step S307: Determine whether each segment in the first recycling unit segment list is valid.
[0125] Please see details Figure 1 Step S103 of the illustrated embodiment will not be described again here.
[0126] Step S308: If a valid segment exists in the first recycling unit segment linked list, the data corresponding to the valid segment is rewritten to the second recycling unit, and the valid segment is written to the second recycling unit segment linked list of the second recycling unit.
[0127] Please see details Figure 1 Step S104 of the illustrated embodiment will not be described again here.
[0128] In some optional implementations, as described above, the host file system records reclaimer metadata for each reclaimer unit and segment metadata for each segment; the reclaimer metadata includes: a reclaimer unit identifier and a reclaimer segment list; the segment metadata includes: a file identifier, a first link pointer to the file segment list and a second link pointer to the reclaimer unit segment list.
[0129] Furthermore, the aforementioned step S308, "writing the valid segment to the second recycling unit segment linked list of the second recycling unit," may specifically include steps c1 to c2.
[0130] Step c1: Record the recycling unit metadata of the second recycling unit; the recycling unit metadata of the second recycling unit includes the recycling unit identifier of the second recycling unit and the second recycling unit segment linked list.
[0131] Step c2: Update the second link pointer in the segment metadata of the valid segment from linking to the first recycling unit segment list to linking to the second recycling unit segment list;
[0132] In this embodiment, when it is necessary to rewrite data to the second RU, similar to the first RU, it is necessary to record the RU metadata of the second RU. The RU metadata of the second RU includes the identifier of the second RU and the linked list of the second RU segments.
[0133] When rewriting a valid segment, the corresponding data is written to the second RU; and the valid segment needs to be changed from being linked from the first RU segment list to being linked from the second RU segment list. Specifically, this is done by updating the second link pointer of the second segment, which links the valid segment to the second RU segment list.
[0134] It is understandable that if the data storage location corresponding to the valid segment changes, the starting address, length, and other data in the segment metadata of the valid segment also need to be updated, which will not be elaborated here.
[0135] Step S309: If there is an invalid segment in the first recycling unit segment linked list, release the storage space corresponding to the invalid segment.
[0136] Please see details Figure 1 Step S105 of the illustrated embodiment will not be described again here.
[0137] Optionally, step S309, "Release the storage space corresponding to the invalid segment", may include step d1.
[0138] Step d1: Delete the first and second link pointers from the segment metadata of the invalid segment.
[0139] In this embodiment, after writing to the current file and updating each metadata, if some or all of the data in the current file is set to invalid data that is no longer used, then the segment corresponding to the invalid data in the file segment linked list of the current file is set to invalid.
[0140] If a segment corresponds to invalid data, such as deleted data, the segment metadata can be updated to remove the first and second link pointers. This means the segment is no longer linked to any file segment list or RU segment list. When the segment is subsequently reassigned to a file, the first and second link pointers in the segment metadata are reset.
[0141] Alternatively, if a valid segment exists in the first recycling unit segment list, the valid segment can be deleted from the first recycling unit segment list; and if an invalid segment exists in the first recycling unit segment list, the invalid segment can also be deleted from the first recycling unit segment list.
[0142] By deleting segments from the RU segment list that have been garbage collected, the RU segment list can be updated, and the corresponding segments can be re-linked when storing data later.
[0143] Figure 5 A schematic diagram of waste recycling for RU2 is shown. Figure 5 As shown, after writing to file 1 and file 2, if file 2 is deleted, all segments in file segment list 2 of file 2 will be invalidated, for example, all segments in file segment list 2 will be deleted. Figure 5 The gray-shaded sections indicate invalid sections.
[0144] Subsequently, if garbage collection is required, the minimum number of valid RUs can be determined based on the RU metadata of each RU and the corresponding file segment linked list. Figure 5 Since there is only one valid data in RU 2 (the data corresponding to segment E16), garbage collection can be performed on RU 2.
[0145] During the garbage collection process of RU2, based on the metadata recorded in the host file system, it can be determined that only segment E16 in the RU segment linked list 2 of RU2 is valid, while the remaining segments E21 to E24 are invalid segments. Therefore, segment E16 is rewritten and the space corresponding to segments E21 to E24 is released.
[0146] If the data corresponding to segment E16 needs to be written to RU 3 (i.e., RU 3 is the second RU mentioned above), then the RU segment linked list 3 (i.e., the second RU segment linked list) of RU 3 can be recorded, and segment E16 can be linked to RU segment linked list 3. The host file system can then perform garbage collection on the SSD by updating various metadata.
[0147] In some alternative implementations, the host can determine whether to perform garbage collection based on its own actual situation. For example, the host can determine its own utilization rate. If the utilization rate is less than a preset threshold, it indicates that the host is relatively idle, and the host can choose to use the file system for garbage collection, such as by initiating a garbage collection command to the host file system. If the host's utilization rate is higher than the preset threshold, it indicates that the host's current resources are strained, and garbage collection can be performed by the solid-state drive.
[0148] In addition, this method can also achieve hybrid garbage collection, where one part of the RU performs garbage collection based on the host file system and the other part performs garbage collection based on the SSD, that is, garbage collection is handled in the SSD.
[0149] Specifically, step S305, "determining the first recycling unit that needs to be garbage collected," may include: determining a first recycling unit handle for garbage collection performed by the host file system, and designating the recycling unit corresponding to the first recycling unit handle as the first recycling unit; determining a second recycling unit handle for garbage collection performed by the solid-state drive, and instructing the solid-state drive to perform garbage collection on the recycling unit corresponding to the second recycling unit handle.
[0150] In this embodiment, garbage collection can be performed based on different RUHs. Specifically, the RU that needs to be garbage collected by the host file system is determined based on the first RUH, i.e., the first RU; while the RUs that need to be garbage collected by the SSD are determined based on other second RUHs, such as the third RU, thereby enabling the host file system to perform garbage collection on the first RU, while the SSD performs garbage collection on the third RU.
[0151] The solid-state drive (SSD) garbage collection method provided in this embodiment records and maintains the segment metadata of each partition, the RU metadata of each RU, and the inode metadata of each file through the host file system. By maintaining and updating this metadata, based on PDF technology, the host file system can perform garbage collection on the RUs, allowing the host to control the QoS of read and write behavior to a greater extent. Furthermore, it can determine whether to perform garbage collection at the file system layer based on the file system's operating status; and it can perform hybrid garbage collection, that is, garbage collection of RUs can be achieved collaboratively by the file system layer and the SSD layer.
[0152] This embodiment also provides a solid-state drive garbage collection device for implementing the above embodiments and preferred embodiments; details already described will not be repeated. As used below, the term "module" can be a combination of software and / or hardware that implements a predetermined function. Although the device described in the following embodiments is preferably implemented in software, hardware implementation, or a combination of software and hardware, is also possible and contemplated.
[0153] This embodiment provides a garbage collection device for a solid-state drive, applied to a host file system, such as... Figure 6 As shown, it includes:
[0154] The recycling unit determination module 601 is used to determine the first recycling unit that needs to be recycled when it is necessary to recycle solid-state drives.
[0155] The linked list acquisition module 602 is used to acquire the first recycling unit segment linked list of the first recycling unit from the host file system; the first recycling unit segment linked list is used to record segments belonging to the first recycling unit;
[0156] The judgment module 603 is used to determine whether each segment in the first recycling unit segment linked list is valid;
[0157] The garbage collection module 604 is used to rewrite the data corresponding to the valid segment to the second collection unit and write the valid segment to the second collection unit's second collection unit segment list when a valid segment exists in the first collection unit segment list; and to release the storage space corresponding to the invalid segment when an invalid segment exists in the first collection unit segment list.
[0158] In some optional implementations, the determination module 603 determines whether each segment in the first recycling unit segment linked list is valid, including:
[0159] Determine the target file corresponding to the target segment in the first recycling unit segment list;
[0160] Obtain the file segment list of the target file from the host file system; the file segment list of the target file is used to record the segments belonging to the target file;
[0161] Determine whether the segment corresponding to the target segment in the file segment linked list of the target file is valid;
[0162] If the segment corresponding to the target segment is valid, the target segment is determined to be valid;
[0163] If the segment corresponding to the target segment is invalid, the target segment is determined to be invalid.
[0164] In some optional implementations, the determining module 603 determines the target file corresponding to the target segment in the first recycling unit segment linked list, including:
[0165] Obtain the segment metadata of the target segment; the segment metadata includes a file identifier;
[0166] The corresponding target file is determined based on the file identifier in the segment metadata of the target segment.
[0167] In some optional implementations, the determining module 603 obtains the file segment list of the target file from the host file system, including:
[0168] Based on the file identifier of the target file, the inode metadata of the target file is determined; the inode metadata includes the file identifier and a file segment list;
[0169] Obtain the file segment list of the target file from the inode metadata of the target file.
[0170] In some optional implementations, the host file system records the reclaim unit metadata of each reclaim unit and the segment metadata of each segment; the reclaim unit metadata includes: a reclaim unit identifier and a reclaim unit segment linked list; the segment metadata includes: a file identifier, a first link pointer for linking to a file segment linked list and a second link pointer for linking to a reclaim unit segment linked list;
[0171] The waste recycling module 604 writes the valid segment to the second recycling unit segment linked list of the second recycling unit, including:
[0172] Record the recycling unit metadata of the second recycling unit; the recycling unit metadata of the second recycling unit includes the recycling unit identifier of the second recycling unit and the second recycling unit segment linked list;
[0173] The second link pointer in the segment metadata of the valid segment is updated from linking to the first recycling unit segment list to linking to the second recycling unit segment list;
[0174] The garbage collection module 604 releases the storage space corresponding to the invalid segment, including:
[0175] Delete the first and second link pointers from the segment metadata of the invalid segment.
[0176] In some alternative implementations, the waste recycling module 604 is further configured to:
[0177] If a valid segment exists in the first recycling unit segment linked list, the valid segment is deleted from the first recycling unit segment linked list;
[0178] If an invalid segment exists in the first recycling unit segment linked list, the invalid segment is deleted from the first recycling unit segment linked list.
[0179] In some optional implementations, the recycling unit determining module 601 determines a first recycling unit that needs to be recycled, including:
[0180] Determine the handle of the first garbage collection unit to be garbage collected by the host file system, and take the garbage collection unit corresponding to the first garbage collection unit handle as the first garbage collection unit;
[0181] A second recycling unit handle for garbage collection by the solid-state drive is determined, and the solid-state drive is instructed to perform garbage collection on the recycling unit corresponding to the second recycling unit handle.
[0182] In some alternative implementations, the apparatus further includes a write module for:
[0183] When writing the current file to the solid-state drive, determine the current reclaim unit and the current reclaim unit handle that need to be written to the current file;
[0184] Record the metadata of the current recycling unit; the metadata of the recycling unit includes: recycling unit identifier, recycling unit handle identifier, and recycling unit segment linked list;
[0185] Record the inode metadata of the current file; the inode metadata includes the file identifier and the file segment list;
[0186] Identify at least one segment corresponding to the current file and record the segment metadata of each segment; the segment metadata includes: file identifier, a first link pointer for linking to the file segment linked list and a second link pointer for linking to the recycling unit segment linked list;
[0187] The segment of the current file is linked to the file segment list of the current file according to the first link pointer; the segment of the current file is linked to the recycling unit segment list of the current recycling unit according to the second link pointer.
[0188] Further functional descriptions of the above modules and units are the same as those in the corresponding embodiments described above, and will not be repeated here.
[0189] In this embodiment, the solid-state drive garbage collection device is presented in the form of a functional unit. Here, a unit refers to an ASIC (Application Specific Integrated Circuit) circuit, including a processor and memory that execute one or more software or fixed programs, and / or other devices that can provide the above functions.
[0190] This disclosure also provides a computer device having the above-described features. Figure 6 The solid-state drive shown has a garbage collection device.
[0191] Please see Figure 7 , Figure 7 This is a schematic diagram of the structure of a computer device provided in an optional embodiment of this disclosure, such as... Figure 7 As shown, the computer device includes one or more processors 10, memory 20, and interfaces for connecting the components, including high-speed interfaces and low-speed interfaces. The components communicate with each other via different buses and can be mounted on a common motherboard or otherwise installed as needed. The processors can process instructions executed within the computer device, including instructions stored in or on memory to display graphical information of a GUI on external input / output devices (such as display devices coupled to the interfaces). In some alternative implementations, multiple processors and / or multiple buses can be used with multiple memories, if desired. Similarly, multiple computer devices can be connected, each providing some of the necessary operations (e.g., as a server array, a group of blade servers, or a multiprocessor system). Figure 7 Take a processor 10 as an example.
[0192] Processor 10 may be a central processing unit, a network processor, or a combination thereof. Processor 10 may further include a hardware chip. The hardware chip may be an application-specific integrated circuit (ASIC), a programmable logic device (PLD), or a combination thereof. The programmable logic device may be a complex programmable logic device (CAMP), a field-programmable gate array (FPGA), a general-purpose array logic (GDA), or any combination thereof.
[0193] The memory 20 stores instructions executable by at least one processor 10 to cause the at least one processor 10 to perform the method shown in the above embodiments.
[0194] The memory 20 may include a program storage area and a data storage area. The program storage area may store the operating system and applications required for at least one function; the data storage area may store data created based on the use of the computer device. Furthermore, the memory 20 may include high-speed random access memory and may also include non-transitory memory, such as at least one disk storage device, flash memory device, or other non-transitory solid-state storage device. In some alternative embodiments, the memory 20 may optionally include memory remotely located relative to the processor 10, which can be linked to the computer device via a network. Examples of such networks include, but are not limited to, the Internet, intranets, local area networks, mobile communication networks, and combinations thereof.
[0195] The memory 20 may include volatile memory, such as random access memory; the memory may also include non-volatile memory, such as flash memory, hard disk or solid-state drive; the memory 20 may also include a combination of the above types of memory.
[0196] The computer device also includes an input device 30 and an output device 40. The processor 10, memory 20, input device 30, and output device 40 can be connected via a bus or other means. Figure 7 Taking the example of a connection between China and Israel via a bus.
[0197] Input device 30 can receive input numerical or character information, and generate key signal inputs related to user settings and function control of the computer device, such as a touchscreen, keypad, mouse, trackpad, touchpad, joystick, one or more mouse buttons, trackball, joystick, etc. Output device 40 may include display devices, auxiliary lighting devices (e.g., LEDs), and haptic feedback devices (e.g., vibration motors). The aforementioned display devices include, but are not limited to, liquid crystal displays, light-emitting diodes, displays, and plasma displays. In some alternative embodiments, the display device may be a touchscreen.
[0198] The computer device may also include a communication interface for communicating with other devices or communication networks.
[0199] This disclosure also provides a computer-readable storage medium in which the methods described in this disclosure can be implemented in hardware or firmware, or implemented as recordable on a storage medium, or implemented as computer code originally stored on a remote storage medium or a non-transitory machine-readable storage medium and subsequently stored on a local storage medium after being downloaded over a network. Thus, the methods described herein can be processed by software stored on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. The storage medium may be a magnetic disk, optical disk, read-only memory, random access memory, flash memory, hard disk, or solid-state drive, etc.; further, the storage medium may also include combinations of the above types of memory. It is understood that computers, processors, microprocessor controllers, or programmable hardware include storage components capable of storing or receiving software or computer code that, when accessed and executed by the computer, processor, or hardware, implements the methods shown in the above embodiments.
[0200] A portion of this disclosure can be applied to computer program products, such as computer program instructions, which, when executed by a computer, can invoke or provide methods and / or technical solutions according to this disclosure through the operation of the computer. Those skilled in the art will understand that the forms in which computer program instructions exist in a computer-readable medium include, but are not limited to, source files, executable files, and installation package files. Accordingly, the ways in which computer program instructions are executed by a computer include, but are not limited to: the computer directly executing the instructions; the computer compiling the instructions and then executing the corresponding compiled program; the computer reading and executing the instructions; or the computer reading and installing the instructions and then executing the corresponding installed program. Here, the computer-readable medium can be any available computer-readable storage medium or communication medium accessible to a computer.
[0201] Although embodiments of the present disclosure have been described in conjunction with the accompanying drawings, those skilled in the art can make various modifications and variations without departing from the spirit and scope of the present disclosure, and all such modifications and variations should be covered within the protection scope of the present disclosure.
Claims
1. A method for garbage collection of a solid-state drive, characterized in that, Applied to a host file system, the method includes: When solid-state drives require garbage collection, identify the first collection unit that needs to be garbage collected; Obtain the first recycling unit segment linked list from the host file system; the first recycling unit segment linked list is used to record segments belonging to the first recycling unit; Determine whether each segment in the first recycling unit segment list is valid; If a valid segment exists in the first recycling unit segment linked list, the data corresponding to the valid segment is rewritten to the second recycling unit, and the valid segment is written to the second recycling unit segment linked list of the second recycling unit. If an invalid segment exists in the first recycling unit segment linked list, release the storage space corresponding to the invalid segment; The step of determining whether each segment in the first recycling unit segment list is valid includes: Determine the target file corresponding to the target segment in the first recycling unit segment list; Obtain the file segment list of the target file from the host file system; the file segment list of the target file is used to record the segments belonging to the target file; Determine whether the segment corresponding to the target segment in the file segment linked list of the target file is valid; If the segment corresponding to the target segment is valid, the target segment is determined to be valid; If the segment corresponding to the target segment is invalid, the target segment is determined to be invalid.
2. The method according to claim 1, characterized in that, Determining the target file corresponding to the target segment in the first recycling unit segment list includes: Obtain the segment metadata of the target segment; the segment metadata includes a file identifier; The corresponding target file is determined based on the file identifier in the segment metadata of the target segment.
3. The method according to claim 2, characterized in that, The step of obtaining the file segment list of the target file from the host file system includes: Based on the file identifier of the target file, the inode metadata of the target file is determined; the inode metadata includes the file identifier and a file segment list; Obtain the file segment list of the target file from the inode metadata of the target file.
4. The method according to claim 1, characterized in that, The host file system records the metadata of each recycling unit and the metadata of each segment. The recycling unit metadata includes: a recycling unit identifier and a recycling unit segment linked list; the segment metadata includes: a file identifier, a first link pointer to the file segment linked list, and a second link pointer to the recycling unit segment linked list; The step of writing the valid segment to the second recycling unit segment linked list of the second recycling unit includes: Record the recycling unit metadata of the second recycling unit; the recycling unit metadata of the second recycling unit includes the recycling unit identifier of the second recycling unit and the second recycling unit segment linked list; The second link pointer in the segment metadata of the valid segment is updated from linking to the first recycling unit segment list to linking to the second recycling unit segment list; Releasing the storage space corresponding to the invalid segment includes: Delete the first and second link pointers from the segment metadata of the invalid segment.
5. The method according to claim 1, characterized in that, Also includes: If a valid segment exists in the first recycling unit segment linked list, the valid segment is deleted from the first recycling unit segment linked list; If an invalid segment exists in the first recycling unit segment linked list, the invalid segment is deleted from the first recycling unit segment linked list.
6. The method according to any one of claims 1 to 5, characterized in that, The first recycling unit that determines the need for waste recycling includes: Determine the handle of the first garbage collection unit to be garbage collected by the host file system, and take the garbage collection unit corresponding to the first garbage collection unit handle as the first garbage collection unit; A second recycling unit handle for garbage collection by the solid-state drive is determined, and the solid-state drive is instructed to perform garbage collection on the recycling unit corresponding to the second recycling unit handle.
7. The method according to any one of claims 1 to 5, characterized in that, Also includes: When writing the current file to the solid-state drive, determine the current reclaim unit and the current reclaim unit handle that need to be written to the current file; Record the metadata of the current recycling unit; the metadata of the recycling unit includes: recycling unit identifier, recycling unit handle identifier, and recycling unit segment linked list; Record the inode metadata of the current file; the inode metadata includes the file identifier and the file segment list; Identify at least one segment corresponding to the current file and record the segment metadata of each segment; the segment metadata includes: file identifier, a first link pointer for linking to the file segment linked list and a second link pointer for linking to the recycling unit segment linked list; The segment of the current file is linked to the file segment list of the current file according to the first link pointer; the segment of the current file is linked to the recycling unit segment list of the current recycling unit according to the second link pointer.
8. A waste recycling device for a solid-state drive, characterized in that, Applied to a host file system, the device includes: The recycling unit determination module is used to determine the first recycling unit that needs to be recycled when the solid-state drive needs to be recycled. The linked list acquisition module is used to acquire the first recycling unit segment linked list of the first recycling unit from the host file system; the first recycling unit segment linked list is used to record segments belonging to the first recycling unit; The judgment module is used to determine whether each segment in the first recycling unit segment linked list is valid; The garbage collection module is used to rewrite the data corresponding to the valid segment to the second collection unit and write the valid segment to the second collection unit's second collection unit segment linked list when a valid segment exists in the first collection unit segment linked list; and to release the storage space corresponding to the invalid segment when an invalid segment exists in the first collection unit segment linked list. The step of determining whether each segment in the first recycling unit segment list is valid includes: Determine the target file corresponding to the target segment in the first recycling unit segment list; Obtain the file segment list of the target file from the host file system; the file segment list of the target file is used to record the segments belonging to the target file; Determine whether the segment corresponding to the target segment in the file segment linked list of the target file is valid; If the segment corresponding to the target segment is valid, the target segment is determined to be valid; If the segment corresponding to the target segment is invalid, the target segment is determined to be invalid.
9. A computer device, characterized in that, include: A memory and a processor are communicatively connected, the memory stores computer instructions, and the processor executes the computer instructions to perform the garbage collection method of the solid-state drive according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions for causing a computer to perform the garbage collection method of the solid-state drive according to any one of claims 1 to 7.