A garbage collection method and device applied to a solid state disk
By marking and saving valid data pages of flash memory blocks when the solid-state drive is idle, the problem of high resource consumption in the garbage collection process in the prior art is solved, and faster data migration and system performance improvement are achieved.
Patent Information
- Application Number
- CN202111403037.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-24
- Publication Date
- 2026-02-03
- Estimated Expiration
- 2041-11-24
AI Technical Summary
The existing solid-state drive garbage collection process consumes a lot of resources, affecting system performance.
When the solid-state drive is idle, the valid data pages of each flash memory block are marked and stored in memory. The target flash memory block is located and moved for erasure operation to ensure the speed of valid data transfer.
It improves the speed of efficient data transfer, reduces the consumption of solid-state drive resources, and enhances system performance.
Smart Images

Figure CN114201415B_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of computer technology, and provides a method and apparatus for garbage collection of solid-state drives. Background Technology
[0002] Solid State Drive (SSD) is a hard drive made of solid-state electronic storage chip arrays. The storage unit of an SSD consists of flash memory blocks, and a flash memory block can be divided into several data pages.
[0003] During system operation, new data is constantly generated. In this situation, the stored data needs to be updated accordingly. The previously stored data automatically becomes garbage data, and the updated data becomes valid data. The page containing the valid data is called the valid data page. When the available space on the solid-state drive (SSD) is insufficient, old flash memory blocks need to be reclaimed. This involves moving the valid data pages from the old flash memory blocks to new flash memory blocks. After the valid data migration is complete, the entire old flash memory block is erased, thus freeing it up for writing new data.
[0004] Currently, the garbage collection process for old flash memory blocks first involves traversing the data across all flash memory blocks to find valid data pages in each block, moving the valid data from those pages to other flash memory blocks, and then erasing one of the aforementioned flash memory blocks. This garbage collection process consumes significant resources and impacts system performance. Summary of the Invention
[0005] This disclosure provides a garbage collection method and apparatus for solid-state drives (SSDs) to improve the speed of efficient data transfer.
[0006] The specific technical solution provided in this disclosure is as follows:
[0007] In a first aspect, embodiments of this disclosure provide a garbage collection method for solid-state drives (SSDs). The method is applied to a computing device, which includes an SSD and memory, and includes:
[0008] When the SSD is found to be idle, each valid data page in the flash memory block on the SSD is marked, resulting in multiple valid page tags. Each valid data page must contain at least one valid data record.
[0009] Multiple valid page tags are stored in memory, and the target flash block containing valid page tags is located in memory.
[0010] When the number of available flash memory blocks is detected to be lower than the usage threshold, the valid data in the target flash memory block is moved to other flash memory blocks, and the target flash memory block is erased. The total storage space of the other flash memory blocks is greater than the size of the moved valid data.
[0011] Optionally, when the solid-state drive (SSD) is found to be idle, each valid data page in the flash memory block on the SSD is marked, resulting in multiple valid page marks, including:
[0012] When the SSD is found to be idle, obtain the number of available flash memory blocks on the SSD.
[0013] If the number of available flash blocks is less than the statistical threshold, then obtain the first number of valid data pages in each flash block on the solid-state drive and the second number of valid data pages in each flash block in memory that has stored valid page tags, wherein the statistical threshold is greater than the usage threshold;
[0014] If the first number is less than the second number, then each valid data page in each flash block on the solid-state drive is marked, resulting in multiple valid page marks.
[0015] Optionally, multiple valid page tags are stored in memory, including:
[0016] Determine whether the used storage space in memory has reached the capacity threshold;
[0017] If so, then replace the target tag of the valid data page of the flash memory block corresponding to the second number stored in memory with the valid page tag of the flash memory block corresponding to the first number;
[0018] Otherwise, multiple valid page tags are stored in memory in units of flash blocks.
[0019] Optionally, the capacity threshold can be determined in the following way:
[0020] Calculate the storage capacity of the memory;
[0021] Mark each data page in any flash block on the solid-state drive and obtain the sum of the capacity occupied by each mark;
[0022] Based on the sum of the storage space capacity and the capacity occupied by each tag, the capacity threshold that can be stored in memory for flash memory blocks is determined.
[0023] Optionally, before finding that the solid-state drive is in an idle state, the process also includes:
[0024] After the solid-state drive is detected to be powered on and started, the number of valid data pages contained in each flash memory block on the solid-state drive is counted.
[0025] Select multiple flash memory blocks that match the capacity threshold, wherein the number of valid data pages in the selected flash memory blocks is no greater than the number of valid data pages in the unselected flash memory blocks;
[0026] Each valid data page in multiple flash memory blocks is marked to obtain multiple target tags, and the multiple target tags are stored in memory in units of flash memory blocks.
[0027] Optionally, locating the target flash block containing valid page tags in memory includes:
[0028] Get the number of marked valid data pages stored in each flash memory block that is already stored in memory;
[0029] In the stored flash memory blocks, the found flash memory blocks are used as target flash memory blocks, wherein the number of valid data pages marked in the target flash memory blocks is no greater than the number of unfound flash memory blocks.
[0030] Optionally, the valid data in the target flash memory block is moved to other flash memory blocks, including:
[0031] Based on multiple valid page tags, determine the valid data to be moved contained in the target flash memory block, and determine the size of the valid data to be moved;
[0032] Locate multiple flash blocks in the solid-state drive whose total storage space is greater than the size of the valid data to be moved, and identify the found flash blocks as other flash blocks;
[0033] The valid data to be moved is stored in the total storage space of other flash memory blocks.
[0034] Secondly, embodiments of this disclosure also provide a garbage collection device for solid-state drives, comprising:
[0035] A marking unit is used to mark each valid data page in the flash memory block on the solid-state drive (SSD) when the SSD is found to be idle, resulting in multiple valid page marks, wherein each valid data page contains at least one valid data record; and
[0036] The lookup unit is used to store multiple valid page tags in memory and to locate the target flash memory block containing valid page tags in memory;
[0037] The erase unit is used to move valid data from the target flash memory block to other flash memory blocks and erase the target flash memory block when the number of available flash memory blocks is detected to be lower than the usage threshold. The total storage space of the other flash memory blocks is greater than the size of the moved valid data.
[0038] Optionally, when the solid-state drive (SSD) is found to be idle, each valid data page in the flash memory block on the SSD is marked to obtain multiple valid page marks. The marking unit is used for:
[0039] When the SSD is found to be idle, obtain the number of available flash memory blocks on the SSD.
[0040] If the number of available flash blocks is less than the statistical threshold, then obtain the first number of valid data pages in each flash block on the solid-state drive and the second number of valid data pages in each flash block in memory that has stored valid page tags, wherein the statistical threshold is greater than the usage threshold;
[0041] If the first number is less than the second number, then each valid data page in each flash block on the solid-state drive is marked, resulting in multiple valid page marks.
[0042] Optionally, multiple valid page tags are stored in memory, and the tag unit is used for:
[0043] Determine whether the used storage space in memory has reached the capacity threshold;
[0044] If so, then replace the target tag of the valid data page of the flash memory block corresponding to the second number stored in memory with the valid page tag of the flash memory block corresponding to the first number;
[0045] Otherwise, multiple valid page tags are stored in memory in units of flash blocks.
[0046] Optionally, the capacity threshold can be determined in the following way:
[0047] Calculate the storage capacity of the memory;
[0048] Mark each data page in any flash block on the solid-state drive and obtain the sum of the capacity occupied by each mark;
[0049] Based on the sum of the storage space capacity and the capacity occupied by each tag, the capacity threshold that can be stored in memory for flash memory blocks is determined.
[0050] Optionally, before finding that the solid-state drive is in an idle state, the process also includes:
[0051] After the solid-state drive is detected to be powered on and started, the number of valid data pages contained in each flash memory block on the solid-state drive is counted.
[0052] Select multiple flash memory blocks that match the capacity threshold, wherein the number of valid data pages in the selected flash memory blocks is no greater than the number of valid data pages in the unselected flash memory blocks;
[0053] Each valid data page in multiple flash memory blocks is marked to obtain multiple target tags, and the multiple target tags are stored in memory in units of flash memory blocks.
[0054] Optionally, the target flash memory block containing a valid page tag is located in memory. The lookup unit is used for:
[0055] Get the number of marked valid data pages stored in each flash memory block that is already stored in memory;
[0056] In the stored flash memory blocks, the found flash memory blocks are used as target flash memory blocks, wherein the number of valid data pages marked in the target flash memory blocks is no greater than the number of unfound flash memory blocks.
[0057] Optionally, the valid data in the target flash memory block is moved to other flash memory blocks. The erase unit is used for:
[0058] Based on multiple valid page tags, determine the valid data to be moved contained in the target flash memory block, and determine the size of the valid data to be moved;
[0059] Locate multiple flash blocks in the solid-state drive whose total storage space is greater than the size of the valid data to be moved, and identify the found flash blocks as other flash blocks;
[0060] The valid data to be moved is stored in the total storage space of other flash memory blocks.
[0061] Thirdly, a computing device, comprising:
[0062] Memory, used to store executable instructions;
[0063] A processor for reading and executing executable instructions stored in memory to implement the method as described in any of the first aspects.
[0064] Fourthly, a computer-readable storage medium, when instructions in the storage medium are executed by a processor, enables the processor to perform the method described in any of the first aspects above.
[0065] The beneficial effects of this disclosure are as follows:
[0066] In summary, the embodiments of this disclosure provide a garbage collection method and apparatus for solid-state drives (SSDs). The method is applied to a computing device, which includes an SSD and memory. The method includes: when the SSD is found to be idle, marking each valid data page in the flash memory blocks on the SSD to obtain multiple valid page tags. This allows marking valid data pages on the flash memory blocks even when the SSD is idle. Each valid data page contains at least one valid data record. The method also includes storing the multiple valid page tags in memory and searching for a target flash memory block containing valid page tags in memory. This pre-locks the target flash memory block in memory. When the number of available flash memory blocks is detected to be lower than a usage threshold, the valid data in the target flash memory block is moved to other flash memory blocks, and the target flash memory block is erased, thereby improving the speed of valid data movement.
[0067] Other features and advantages of this disclosure will be set forth in the following description and will be apparent in part from the description or may be learned by practicing the disclosure. The objects and other advantages of this disclosure may be realized and obtained by means of the structures particularly pointed out in the written description, claims, and drawings. Attached Figure Description
[0068] The accompanying drawings, which are included to provide a further understanding of this disclosure and form part of this disclosure, illustrate exemplary embodiments of the present disclosure and are used to explain the disclosure, but do not constitute an undue limitation of the disclosure. In the drawings:
[0069] Figure 1 This is a schematic diagram of a garbage collection system architecture applied to solid-state drives in an embodiment of this disclosure;
[0070] Figure 2 This is a schematic diagram of the garbage collection process applied to solid-state drives in an embodiment of this disclosure;
[0071] Figure 3 This is a schematic diagram of the process for obtaining target markers in an embodiment of this disclosure;
[0072] Figure 4 This is a schematic diagram illustrating the process of marking valid data pages in an embodiment of this disclosure;
[0073] Figure 5 This is a flowchart illustrating the process of determining whether the used storage space in memory has reached the capacity threshold in an embodiment of this disclosure;
[0074] Figure 6 This is a schematic diagram of the process for obtaining the target flash memory block in an embodiment of this disclosure;
[0075] Figure 7This is a schematic diagram illustrating the process of transferring valid data in an embodiment of this disclosure;
[0076] Figure 8 This is a schematic diagram of the logical architecture of a garbage collection device applied to a solid-state drive in an embodiment of this disclosure;
[0077] Figure 9 This is a schematic diagram of the physical architecture of the computing device in an embodiment of this disclosure. Detailed Implementation
[0078] To make the objectives, technical solutions, and advantages of the embodiments of this disclosure clearer, the technical solutions 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 the technical solutions of this disclosure, and not all embodiments. Based on the embodiments recorded in this disclosure, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the technical solutions of this disclosure.
[0079] The terms "first," "second," etc., used in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that embodiments of the invention described herein can be implemented in sequences other than those illustrated or described herein.
[0080] The preferred embodiments of this disclosure will now be described in detail with reference to the accompanying drawings.
[0081] See Figure 1 As shown in this embodiment, the computing device includes at least one solid-state drive (SSD), which contains memory. The memory used in this application is a segment of memory within the SSD. Figure 1 In this diagram, flash memory block 1, flash memory block 2, and flash memory block n are used to exemplarily represent flash memory blocks loaded with data, some or all of which contain valid data. It should also be noted that each of these flash memory blocks contains multiple data pages; if a data page contains at least one valid data page, then that data page is considered a valid data page.
[0082] In this embodiment of the disclosure, the implementation of the garbage collection method applied to solid-state drives is mainly executed on the computing device side, which will be described in detail below.
[0083] See Figure 2 As shown in this embodiment, the specific process of garbage collection applied to solid-state drives is as follows:
[0084] Step 201: When the solid-state drive (SSD) is found to be idle, mark each valid data page in the flash memory block on the SSD, resulting in multiple valid page tags. Each valid data page must contain at least one valid data entry.
[0085] To avoid consuming the storage time of the solid-state drive (SSD), during implementation, the computing device will search for valid data pages in the flash memory blocks on the SSD when it is idle, thereby improving the performance of the SSD.
[0086] It should be noted that, in order to determine the status of valid data pages in each flash memory block of the SSD immediately after power-on, refer to [the relevant documentation] before the SSD is found to be in an idle state. Figure 3 As shown, it also includes:
[0087] Step 101: After the solid-state drive is detected to be powered on and started, count the number of valid data pages contained in each flash memory block on the solid-state drive.
[0088] Once the solid-state drive (SSD) is detected to be powered on, the computing device will count the number of valid data pages contained in any given flash memory block. A valid data page is defined as a data page containing at least one piece of valid data.
[0089] For example, when a solid-state drive has three flash blocks, namely flash block A, flash block B, and flash block C, the computing device counts the number of valid data pages contained in flash block A as 'a', the number of valid data pages contained in flash block B as 'b', and the number of valid data pages contained in flash block C as 'c'.
[0090] Step 102: Select multiple flash memory blocks that match the capacity threshold, wherein the number of valid data pages in the selected flash memory blocks is no greater than the number of valid data pages in the unselected flash memory blocks.
[0091] The capacity threshold here is used to represent the number of flash memory blocks that can be stored in memory. Since the number of data pages in memory is stored in memory nodes, which are units corresponding to flash memory blocks, it should be noted that the data pages in the flash memory block include valid data pages and invalid data pages. During the marking process, when marking the above-mentioned valid data pages and invalid data pages, the space size of each data page being marked (e.g., the bitmap marker used for marking) is the same.
[0092] Specifically, the capacity threshold is determined in the following ways:
[0093] (1) Calculate the storage capacity of the memory.
[0094] Since the memory specifically used to store the tags corresponding to valid data pages is a segment of the entire memory, the memory storage capacity calculated here is the size of the memory specifically used to store the tags, such as the number of bytes.
[0095] (2) Mark each data page in any flash block on the solid-state drive and obtain the sum of the capacity occupied by each mark.
[0096] Considering that a flash memory block contains multiple data pages, and a data page contains multiple data entries, during the detection process, if at least one data entry in a data page is valid, then the data page is determined to be a valid data page.
[0097] Since the marking space for each data page is the same during the marking process, when marking valid and invalid data pages, in practice, to obtain the capacity required to store the markings for one data page, each data page in the flash memory block is marked separately, and the sum of the capacities corresponding to each mark in the flash memory block is obtained. The marking format can be a bitmap, which minimizes the memory footprint while describing valid data.
[0098] (3) Based on the sum of the storage space capacity and the capacity occupied by each tag, determine the capacity threshold of the flash memory blocks that can be stored in memory.
[0099] After obtaining the storage space capacity corresponding to the memory and the sum of the capacity occupied by each tag corresponding to each data page, the storage space capacity is divided by the sum of the capacity occupied by each tag to obtain the capacity threshold of flash memory blocks that can be stored in the memory. That is, the storage space capacity of the memory is divided into multiple storage units with flash memory blocks (usually also called memory nodes) as the unit.
[0100] After determining the memory capacity threshold, multiple flash blocks that match the capacity threshold are selected from the solid-state drive (SSD). The selection principle is that the flash blocks contain fewer valid data pages. Specifically, multiple flash blocks are selected from the SSD in order of increasing number of valid data pages.
[0101] In actual operation, after power-on, the solid-state drive searches through all flash memory blocks in ascending order of the number of valid data pages, and filters out the flash memory blocks with fewer valid data pages. Thus, the number of valid data pages in the final filtered flash memory blocks is no greater than the number of valid data pages in the unfiltered flash memory blocks.
[0102] Step 103: Mark each valid data page in multiple flash memory blocks to obtain multiple target tags, and store the multiple target tags in memory in units of flash memory blocks.
[0103] During step 102, after the solid-state drive powers on and starts up, several flash blocks with a small number of valid data pages are selected. Each valid data page in the multiple flash blocks is then marked. For example, the valid data in each valid data page of the flash block is marked in the form of a bitmap to obtain multiple target marks. In order to save memory storage space, the above multiple target marks are stored in memory in units of flash blocks.
[0104] It should be noted that the above-mentioned method of storing memory in units of flash memory blocks can be as follows: the memory can be divided into multiple virtual flash memory blocks, and multiple target tags stored in each virtual flash memory block correspond to the flash memory blocks in the solid-state drive; or the above-mentioned multiple target tags can carry the identifier of the corresponding flash memory block in the solid-state drive.
[0105] After describing the process after a solid-state drive (SSD) powers on and boots up, the following section details how, when the SSD is found to be idle, each valid data page in the flash memory blocks on the SSD is marked, resulting in multiple valid page markers. (See [link to relevant documentation]). Figure 4 As shown, it includes:
[0106] Step 2011: When the solid-state drive is found to be in an idle state, obtain the number of available flash memory blocks on the solid-state drive.
[0107] To minimize the impact on data stored on the solid-state drive (SSD), in this embodiment, when counting the valid data pages in the flash memory blocks, it is necessary to check whether the SSD is in an idle state. Only when the SSD is in an idle state, i.e., when the SSD is idle, is the number of available flash memory blocks on the SSD obtained. Here, available flash memory blocks mean that the flash memory block can still continue to store work, such as running data and business data.
[0108] Step 2012: If the number of available flash blocks is less than the statistical threshold, obtain the first number of valid data pages in each flash block on the solid-state drive and the second number of valid data pages in each flash block with valid page tags stored in memory, wherein the statistical threshold is greater than the usage threshold.
[0109] Since the number of flash memory blocks in a solid-state drive (SSD) is limited, a statistical threshold is pre-set during the processing. This threshold indicates that the number of available flash memory blocks in the SSD is not large. In addition, if this statistical threshold is greater than the usage threshold, it means that the number of available flash memory blocks is greater than the usage threshold, and that the flash memory blocks can currently meet the data storage needs. Here, the usage threshold is the minimum number of flash memory blocks in the SSD that can meet the data storage needs.
[0110] During implementation, when the number of available flash blocks obtained from the above statistics is less than the above statistical threshold, and considering that the valid data in the flash blocks of the solid-state drive may be updated to invalid data after power-on, the first number of valid data pages in each flash block on the solid-state drive is specifically counted when the number of available flash blocks is less than the statistical threshold. This first number can clearly indicate the storage status of each flash block on the solid-state drive. In addition, under the above circumstances, the second number of valid data pages in each flash block that has stored valid page markers is specifically counted.
[0111] Step 2013: If the first quantity is less than the second quantity, then mark each valid data page in each flash block on the solid-state drive to obtain multiple valid page marks.
[0112] During implementation, if the first number obtained from the above statistics is less than the second number, it indicates that the number of valid data pages in the flash memory blocks of the solid-state drive is small, while the number of valid data pages in the flash memory blocks stored in memory is large. In this case, it is obvious that the flash memory blocks with fewer valid data pages should be deleted to store new running data, etc. In order to identify the flash memory block, each valid data page in each flash memory block on the solid-state drive is marked, resulting in multiple valid page tags. This allows for the specific identification of flash memory blocks on the solid-state drive that contain fewer valid data pages.
[0113] Step 202: Store multiple valid page tags in memory and locate the target flash block containing valid page tags in memory.
[0114] After identifying flash blocks with fewer valid data pages when the SSD is idle, the corresponding valid page markers for these flash blocks are promptly saved to memory. This ensures that each flash block stored in memory contains fewer valid data pages, meaning that the corresponding flash block in memory is a candidate flash block to be cleared and used to store other operational data.
[0115] Specifically, multiple valid page tags are stored in memory; see [link / reference]. Figure 5 As shown, it specifically includes:
[0116] Step 2021: Determine whether the used storage space in memory has reached the capacity threshold. If yes, proceed to step 2022; otherwise, proceed to step 2023.
[0117] Since memory storage space is limited, in this embodiment, a capacity threshold is used to represent the maximum available storage space in memory. Before storing multiple valid page tags in memory, it is first determined whether the used storage space in memory has reached the capacity threshold. This determination confirms the number of valid page tags for each flash memory block.
[0118] Furthermore, if it is determined that the used storage space in memory has reached the capacity threshold, then step 2022 is executed; if it is determined that the used storage space in memory has not yet reached the capacity threshold, then step 2023 is executed.
[0119] Step 2022: Replace the target marker of the valid data page of the flash memory block corresponding to the second number stored in memory with the valid page marker of the flash memory block corresponding to the first number.
[0120] When the used storage space in memory reaches the capacity threshold, it means that the memory can no longer store the markers of valid data pages in the flash memory blocks. At this time, it is detected that the first number of valid data pages in each flash memory block on the solid-state drive is less than the second number of valid data pages in each flash memory block that have stored valid page markers in memory.
[0121] To ensure that the number of valid data pages in each flash block corresponding to the valid page markers stored in memory is small, the target markers of the valid data pages of the flash blocks corresponding to the second number stored in memory are replaced with the valid page markers of the flash blocks corresponding to the first number.
[0122] Step 2023: Store multiple valid page tags in memory storage space as units of flash blocks.
[0123] During implementation, for ease of unified access, multiple valid page tags stored in memory are typically stored in memory as units of flash memory blocks. This is consistent with the way solid-state drives (SSDs) store data in memory as units of flash memory blocks after power-on, so it will not be elaborated further.
[0124] After storing multiple valid page tags in memory, locate the target flash memory block containing the valid page tags in memory. See [link to documentation]. Figure 6 As shown, it specifically includes:
[0125] Step 2021': Obtain the number of marked valid data pages stored in each flash memory block that is already stored in memory.
[0126] Since the size of the valid page tags already stored in memory can only reach the capacity threshold, the number of corresponding flash memory blocks is also relatively large. To accurately determine the number of valid page tags stored in memory, during implementation, the number of valid data pages stored in each flash memory block is obtained, thus determining the corresponding number of flash memory blocks stored in memory.
[0127] Step 2022': Among the stored flash memory blocks, the multiple found flash memory blocks are used as target flash memory blocks, wherein the number of valid data pages marked in the target flash memory blocks is no greater than the number of unfound flash memory blocks.
[0128] To meet the storage requirements of solid-state drives (SSDs), the search criteria described above are based on the number of marked valid data pages stored, from lowest to highest. In other words, the flash memory blocks with fewer marked valid data pages in memory are selected. Therefore, the number of marked valid data pages in the multiple flash memory blocks found (i.e., the target flash memory blocks) will be less than or equal to the number of flash memory blocks that were not found.
[0129] Step 203: When the number of available flash memory blocks is detected to be lower than the usage threshold, the valid data in the target flash memory block is moved to other flash memory blocks, and the target flash memory block is erased. The total storage space of the other flash memory blocks is greater than the size of the moved valid data.
[0130] During the storage process of a solid-state drive (SSD), if the number of available flash memory blocks falls below a usage threshold, it indicates that the used flash memory blocks need to be cleared to make room for new operational data. In this case, to ensure the integrity of the valid data, the valid data in the flash memory blocks to be cleared needs to be further processed.
[0131] Specifically, the valid data in the target flash memory block is moved to other flash memory blocks. See [link / reference]. Figure 7 As shown, it specifically includes:
[0132] Step 2031: Based on multiple valid page tags, determine the valid data to be moved contained in the target flash memory block, and determine the size of the valid data to be moved.
[0133] During implementation, the valid data to be moved was determined based on the valid page tags in memory. However, considering that only multiple valid page tags are stored in memory, while the valid data corresponding to these page tags is actually stored on the solid-state drive (SSD), it is necessary to further determine the size of the valid data to be moved contained in the target flash memory block based on these multiple valid page tags.
[0134] Step 2032: Locate multiple flash memory blocks in the solid-state drive whose total storage space is greater than the size of the valid data to be moved, and identify the found flash memory blocks as other flash memory blocks.
[0135] To ensure the integrity of the transferred data, during the implementation process, multiple flash memory blocks can be located in the solid-state drive (SSD). The total storage space of these multiple flash memory blocks is larger than the size of the data to be transferred. In other words, the storage space reserved for the transferred data in these other flash memory blocks is sufficient. Thus, the total storage space of these other flash memory blocks (including one or more flash memory blocks) can be used to store the size of the transferred data. To clearly identify these flash memory blocks, during the implementation process, the multiple flash memory blocks found are designated as "other flash memory blocks."
[0136] Step 2033: Store the valid data to be moved into the total storage space of the other flash memory blocks.
[0137] After determining the valid data to be moved and the corresponding new flash memory block (i.e., other flash memory blocks), the valid data to be moved is stored in the total storage space of the other flash memory blocks. It should be noted that, usually, the above storage space can be a part of the storage space of the other flash memory blocks. When the storage space of one of the other flash memory blocks is sufficient, it can be used to store the moved valid data multiple times. When the storage space of one of the other flash memory blocks is insufficient, it can be used to store a part of the moved valid data. The remaining valid data can be stored by another flash memory block in the other flash memory blocks.
[0138] During the process, after the valid data is moved to other flash memory blocks, the target flash memory block can be erased, that is, all data in the target flash memory block is cleared. After the erasure is completed, the target flash memory block can perform storage functions.
[0139] Based on the same inventive concept, see [reference] Figure 8 As shown in the figure, this disclosure provides a garbage collection device for solid-state drives, comprising:
[0140] The marking unit 801 is used to mark each valid data page in the flash memory block on the solid-state drive (SSD) when the SSD is found to be in an idle state, thereby obtaining multiple valid page marks, wherein each valid data page contains at least one valid data record; and
[0141] The lookup unit 802 is used to store multiple valid page tags in memory and to search for a target flash memory block containing valid page tags in memory;
[0142] The erase unit 803 is used to move the valid data in the target flash memory block to other flash memory blocks and erase the target flash memory block when the number of available flash memory blocks is detected to be lower than the usage threshold. The total storage space of the other flash memory blocks is greater than the size of the moved valid data.
[0143] Optionally, when the solid-state drive is found to be in an idle state, each valid data page in the flash memory block on the solid-state drive is marked to obtain multiple valid page marks. The marking unit 801 is used for:
[0144] When the SSD is found to be idle, obtain the number of available flash memory blocks on the SSD.
[0145] If the number of available flash blocks is less than the statistical threshold, then obtain the first number of valid data pages in each flash block on the solid-state drive and the second number of valid data pages in each flash block in memory that has stored valid page tags, wherein the statistical threshold is greater than the usage threshold;
[0146] If the first number is less than the second number, then each valid data page in each flash block on the solid-state drive is marked, resulting in multiple valid page marks.
[0147] Optionally, multiple valid page tags are stored in memory, and the tag unit 801 is used for:
[0148] Determine whether the used storage space in memory has reached the capacity threshold;
[0149] If so, then replace the target tag of the valid data page of the flash memory block corresponding to the second number stored in memory with the valid page tag of the flash memory block corresponding to the first number;
[0150] Otherwise, multiple valid page tags are stored in memory in units of flash blocks.
[0151] Optionally, the capacity threshold can be determined in the following way:
[0152] Calculate the storage capacity of the memory;
[0153] Mark each data page in any flash block on the solid-state drive and obtain the sum of the capacity occupied by each mark;
[0154] Based on the sum of the storage space capacity and the capacity occupied by each tag, the capacity threshold that can be stored in memory for flash memory blocks is determined.
[0155] Optionally, before finding that the solid-state drive is in an idle state, the process also includes:
[0156] After the solid-state drive is detected to be powered on and started, the number of valid data pages contained in each flash memory block on the solid-state drive is counted.
[0157] Select multiple flash memory blocks that match the capacity threshold, wherein the number of valid data pages in the selected flash memory blocks is no greater than the number of valid data pages in the unselected flash memory blocks;
[0158] Each valid data page in multiple flash memory blocks is marked to obtain multiple target tags, and the multiple target tags are stored in memory in units of flash memory blocks.
[0159] Optionally, the lookup unit 802 locates the target flash memory block containing a valid page tag in memory, and is used for:
[0160] Get the number of marked valid data pages stored in each flash memory block that is already stored in memory;
[0161] In the stored flash memory blocks, the found flash memory blocks are used as target flash memory blocks, wherein the number of valid data pages marked in the target flash memory blocks is no greater than the number of unfound flash memory blocks.
[0162] Optionally, the valid data in the target flash memory block is moved to other flash memory blocks. The erase unit 803 is used for:
[0163] Based on multiple valid page tags, determine the valid data to be moved contained in the target flash memory block, and determine the size of the valid data to be moved;
[0164] Locate multiple flash blocks in the solid-state drive whose total storage space is greater than the size of the valid data to be moved, and identify the found flash blocks as other flash blocks;
[0165] The valid data to be moved is stored in the total storage space of other flash memory blocks.
[0166] Based on the same inventive concept, see [reference] Figure 9 As shown, this disclosure provides a computing device, including: a memory 901 for storing executable instructions; and a processor 902 for reading and executing the executable instructions stored in the memory, and executing any of the methods described in the first aspect above.
[0167] Based on the same inventive concept, embodiments of this disclosure provide a computer-readable storage medium that, when instructions in the storage medium are executed by a processor, enables the processor to perform the method described in any of the first aspects above.
[0168] In summary, the embodiments of this disclosure provide a garbage collection method and apparatus for solid-state drives (SSDs). The method is applied to a computing device equipped with an SSD and memory. The method includes: when the SSD is found to be in an idle state, marking each valid data page in the flash memory blocks on the SSD to obtain multiple valid page markers. This allows marking valid data pages on the flash memory blocks even when the SSD is idle. Each valid data page contains at least one valid data record. Furthermore, the method involves storing the multiple valid page markers in memory and searching for a target flash memory block containing valid page markers in memory, i.e., pre-locking the target flash memory block in memory. When the number of available flash memory blocks is detected to be lower than a usage threshold, the valid data in the target flash memory block is moved to other flash memory blocks, and the target flash memory block is erased, thereby improving the speed of valid data movement.
[0169] Those skilled in the art will understand that embodiments of this disclosure can be provided as methods, systems, or computer program product systems. Therefore, this disclosure can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this disclosure can take the form of a computer program product system implemented on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0170] This disclosure is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program product systems according to this disclosure. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0171] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0172] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0173] Obviously, those skilled in the art can make various modifications and variations to this disclosure without departing from its spirit and scope. Therefore, if such modifications and variations fall within the scope of the claims of this disclosure and their equivalents, this disclosure is also intended to include such modifications and variations.
Claims
1. A garbage collection method for solid-state drives, characterized in that, The method is applied to a computing device, which includes a solid-state drive (SSD) and memory. When the solid-state drive (SSD) is found to be idle, the number of available flash memory blocks on the SSD is obtained. If the number of available flash memory blocks is less than a statistical threshold, a first number of valid data pages in each flash memory block on the SSD and a second number of valid data pages in each flash memory block with stored valid page tags in memory are obtained. If the first number is less than the second number, each valid data page in each flash memory block on the SSD is marked, resulting in multiple valid page tags. The statistical threshold is greater than a usage threshold, where the statistical threshold represents the number of available flash memory blocks on the SSD, and the usage threshold is the minimum number of flash memory blocks on the SSD that can meet the data storage requirements. Each valid data page contains at least one valid data record. The plurality of valid page tags are stored in memory, and a target flash memory block containing the valid page tags is located in the memory. When the number of available flash memory blocks is detected to be lower than the usage threshold, the valid data in the target flash memory block is moved to other flash memory blocks, and the target flash memory block is erased. The total storage space of the other flash memory blocks is greater than the size of the moved valid data.
2. The method as described in claim 1, characterized in that, The step of storing the plurality of valid page tags in memory includes: Determine whether the used storage space in the memory has reached the capacity threshold; If so, then the target marker of the valid data page of the flash memory block corresponding to the second quantity stored in the memory is replaced with the valid page marker of the flash memory block corresponding to the first quantity; Otherwise, the multiple valid page tags are stored in memory in units of flash memory blocks.
3. The method as described in claim 2, characterized in that, The capacity threshold is determined in the following way: Calculate the storage capacity of the memory; Mark each data page in any flash memory block on the solid-state drive, and obtain the sum of the capacity occupied by each mark; Based on the sum of the storage space capacity and the capacity occupied by each tag, a capacity threshold for storing the flash memory block in the memory is determined.
4. The method as described in claim 3, characterized in that, Before the process of finding that the solid-state drive is in an idle state is completed, the process also includes: After the solid-state drive is detected to be powered on and started, the number of valid data pages contained in each flash memory block on the solid-state drive is counted. Multiple flash memory blocks that match the capacity threshold are selected, wherein the number of valid data pages in the selected flash memory blocks is not greater than the number of valid data pages in the unselected flash memory blocks; Each valid data page in the plurality of flash memory blocks is marked to obtain a plurality of target marks, and the plurality of target marks are stored in the memory in units of flash memory blocks.
5. The method as described in claim 1, characterized in that, The step of locating the target flash memory block containing the valid page tag in the memory includes: Obtain the number of marked valid data pages stored in each flash memory block already stored in the memory; Among the stored flash memory blocks, the found flash memory blocks are used as the target flash memory blocks, wherein the number of valid data pages marked in the target flash memory blocks is no greater than the number of unfound flash memory blocks.
6. The method as described in claim 1, characterized in that, The step of moving valid data from the target flash memory block to other flash memory blocks includes: Based on the multiple valid page tags, determine the valid data to be moved contained in the target flash memory block, and determine the size of the valid data to be moved; Locate multiple flash memory blocks in the solid-state drive whose total storage space is greater than the size of the effective data to be moved, and identify the found multiple flash memory blocks as the other flash memory blocks; The valid data to be moved is stored in the storage space of the other flash memory blocks.
7. A waste recycling device for solid-state drives, characterized in that, include: A marking unit is used to, when the solid-state drive (SSD) is found to be idle, obtain the number of available flash memory blocks on the SSD. If the number of available flash memory blocks is less than a statistical threshold, it obtains a first number of valid data pages in each flash memory block on the SSD and a second number of valid data pages in each flash memory block with stored valid page tags in memory. If the first number is less than the second number, it marks each valid data page in each flash memory block on the SSD, obtaining multiple valid page tags. The statistical threshold is greater than a usage threshold, where the statistical threshold represents the number of available flash memory blocks on the SSD, and the usage threshold is the minimum number of flash memory blocks on the SSD that can meet the data storage requirements. Each valid data page contains at least one valid data record. The lookup unit is used to store the plurality of valid page tags in memory and to search for a target flash memory block containing the valid page tags in memory; An erasure unit is used to move valid data from the target flash memory block to other flash memory blocks and erase the target flash memory block when the number of available flash memory blocks is detected to be lower than the usage threshold. The total storage space of the other flash memory blocks is greater than the size of the moved valid data.
8. A computing device, characterized in that, include: Memory, used to store executable instructions; A processor for reading and executing executable instructions stored in the memory to implement the method as claimed in any one of claims 1-6.
9. A computer-readable storage medium, characterized in that, When the instructions in the storage medium are executed by the processor, the processor is able to perform the method as described in any one of claims 1-6.
Citation Information
Patent Citations
A data recovery method and device
CN109725853A
Data deletion and garbage collection method, device and system and storage medium
CN112783420A