A method for dynamic garbage collection of a solid state disk and a solid state disk
By setting the power-on restart time t1 on the solid-state drive and dynamically adjusting the write ratio, the user write timeout problem caused by frequent power-on and power-off cycles was solved, and timely garbage collection and stable write speed were achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- ZHEJIANG DAHUA TECH CO LTD
- Filing Date
- 2022-11-03
- Publication Date
- 2026-07-07
AI Technical Summary
In existing technologies, the garbage collection mechanism of solid-state drives (SSDs) is prone to causing timeouts for user write operations under frequent power cycles, especially when free blocks are about to be exhausted. Existing methods have failed to effectively solve this problem.
By setting a power-on restart garbage collection time t1, when the SSD power-on restart time is less than or equal to t1 and the number of free blocks is below a threshold, the garbage collection mechanism is started, and the ratio of GC write operations to user write operations is set to the power-on ratio, prohibiting user write operations; under other circumstances, the write ratio is dynamically adjusted according to the available space and the effective data volume of the source block to control GC and user write operations.
It enables timely garbage collection even under frequent power-on and power-off conditions, avoiding timeouts for user write operations and ensuring the stability and efficiency of write speed.
Smart Images

Figure CN115687174B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of solid-state drive (SSD) control, and in particular to a method for dynamic garbage collection of SSDs and an SSD. Background Technology
[0002] Currently, the vast majority of solid-state drives (SSDs) use NAND flash memory as their storage medium. Therefore, the working principle of SSDs is mostly based on the characteristics of flash memory. Among them, garbage collection (GC) is based on the "erase before write" characteristic of flash memory.
[0003] During SSD operation, if the user's free block space falls below a certain threshold, the garbage collection (GC) mechanism is activated to release more free blocks. Since GC write operations consume bandwidth from user write operations, to avoid impacting user write speed, the GC mechanism is not completed all at once. It calculates the write ratio based on the current available NAND Flash space and the effective data volume of the source blocks, allowing GC write operations and user write operations to be completed in a time-sharing manner. For example, if the GC write to user write ratio is n:m, then when the GC writes n pages of data to the NAND Flash, it will be unable to continue writing until the user writes m pages of data to the NAND Flash.
[0004] After the garbage collection mechanism has been running for a period of time, if the number of free blocks on the SSD exceeds a certain threshold, the GC mechanism can be turned off in order not to affect the user's write speed.
[0005] Chinese patent CN114168082A discloses a method, apparatus, computer device, and storage medium for preventing SSD free block exhaustion. The method includes: stopping response to host commands, pausing the current garbage collection process, and recording the state of impending free block exhaustion; in the state of impending free block exhaustion, performing only the internal garbage collection process of the SSD until the current destination block is full; after the destination block is full, saving the mapping table information and reclaiming the current garbage blocks; checking if the number of free blocks is higher than the exhaustion threshold; if the number of free blocks is higher than the exhaustion threshold, resuming response to host commands, restarting the garbage collection task, and clearing the state of impending free block exhaustion. However, this method only performs the internal garbage collection process of the SSD until the current destination block is full in the state of impending free block exhaustion. This condition of ending the GC process based on whether the destination block is full is not applicable to all scenarios. For example, if the available space of the current destination block is large and the effective data volume of the source block is small, the GC mechanism can release multiple free blocks in a short time, thus avoiding the risk of free block exhaustion. If the user write is only resumed after the destination block is full, it is likely to cause timeout problems.
[0006] There is currently no effective solution to the problem of excessive GC causing user write timeouts when GC mechanisms occur simultaneously with frequent power-on and power-off cycles in related technologies. Summary of the Invention
[0007] This embodiment provides a method for dynamic garbage collection of a solid-state drive (SSD) and an SSD to solve the problem of excessive GC causing user write timeouts when the GC mechanism occurs simultaneously with frequent power-on and power-off cycles in related technologies.
[0008] Firstly, this embodiment provides a method for dynamic garbage collection of solid-state drives.
[0009] Set the garbage collection time t1 to restart upon power-on;
[0010] When the power-on restart time of the solid-state drive is less than or equal to the power-on restart garbage collection time t1 and the number of free blocks in the solid-state drive is lower than a set threshold, the garbage collection (GC) mechanism of the solid-state drive is started, and the ratio of GC write operations to user write operations is set as the power-on ratio; the power-on ratio indicates that the solid-state drive allows GC write operations and prohibits user write operations.
[0011] In some embodiments, when the power-on restart time of the solid-state drive is greater than the power-on restart garbage collection time t1, it is determined whether the number of free blocks in the solid-state drive is lower than a set threshold.
[0012] If so, the GC mechanism of the solid-state drive is activated, and the dynamic ratio of the GC write operation to the user write operation is calculated based on the available space of the solid-state drive and the effective data volume of the source block; the solid-state drive is controlled to perform the GC write operation and the user write operation according to the dynamic ratio.
[0013] If not, disable the GC mechanism for the solid-state drive.
[0014] In some embodiments, during the power-on period of the solid-state drive, it is determined whether the number of free blocks in the solid-state drive is lower than a set threshold.
[0015] If so, the GC mechanism of the solid-state drive is activated, and the dynamic ratio of the GC write operation to the user write operation is calculated based on the available space of the solid-state drive and the effective data volume of the source block; the solid-state drive is controlled to perform the GC write operation and the user write operation according to the dynamic ratio.
[0016] If not, disable the GC mechanism for the solid-state drive.
[0017] In some embodiments, the GC initiation mechanism includes: reading valid data from the source block, writing the valid data into the GC target block, performing an erase operation on the source block, and turning the source block into a free block.
[0018] In some embodiments, reading valid data information from the source block and writing the valid data information into the GC target block includes:
[0019] Read the valid data in the source block into the main control RAM area of the solid-state drive;
[0020] The valid data in the main control RAM area of the solid-state drive is integrated and written into the GC target block.
[0021] In some embodiments, the GC initiation mechanism further includes: traversing the data blocks of the solid-state drive and finding the data block with the smallest amount of valid data as the source block.
[0022] Secondly, this embodiment provides a dynamic garbage collection device for solid-state drives, the device comprising:
[0023] The time setting module is used to set the garbage collection time t1 after power-on restart;
[0024] The processing module is configured to initiate the garbage collection (GC) mechanism of the solid-state drive (SSD) when the power-on restart time of the SSD is less than or equal to the power-on restart garbage collection time t1 and the number of free blocks in the SSD is lower than a set threshold, and set the ratio of GC write operations to user write operations as the power-on ratio; the power-on ratio indicates that the SSD allows GC write operations and prohibits user write operations.
[0025] Thirdly, this embodiment provides a solid-state drive (SSD), the SSD comprising:
[0026] Controller and flash memory chip;
[0027] The controller is used to execute the method for implementing dynamic garbage collection of solid-state drives as described in the first aspect above on the flash memory chip.
[0028] Fourthly, this embodiment provides an electronic device including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the method for dynamic garbage collection of a solid-state drive as described in the first aspect.
[0029] Fifthly, this embodiment provides a storage medium storing a computer program that, when executed by a processor, implements the steps of the dynamic garbage collection method for solid-state drives described in the first aspect.
[0030] Compared with related technologies, the solid-state drive (SSD) dynamic garbage collection method and SSD provided in this embodiment, by setting a power-on restart garbage collection time t1, when the power-on restart time of the SSD is less than or equal to the power-on restart garbage collection time t1 and the number of free blocks in the SSD is lower than a set threshold, initiates the SSD's garbage collection (GC) mechanism, and only allows GC write operations while prohibiting user write operations. This solves the problem of excessive GC causing user write timeouts when the GC mechanism occurs together with frequent power-on and power-off cycles in the prior art, and realizes timely garbage collection under frequent power-on and power-off conditions.
[0031] Details of one or more embodiments of this application are set forth in the following drawings and description to make other features, objects and advantages of this application more readily apparent. Attached Figure Description
[0032] The accompanying drawings, which are included to provide a further understanding of this application and form part of this application, illustrate exemplary embodiments and are used to explain this application, but do not constitute an undue limitation of this application. In the drawings:
[0033] Figure 1This is a hardware structure block diagram of a terminal for a method of dynamic garbage collection of solid-state drives in this embodiment;
[0034] Figure 2 This is a flowchart of a dynamic garbage collection method for solid-state drives in this embodiment;
[0035] Figure 3 This is a flowchart of a dynamic garbage collection method for solid-state drives according to a preferred embodiment of the present invention;
[0036] Figure 4 This is a structural block diagram of a solid-state drive according to this embodiment;
[0037] Figure 5 This is a structural block diagram of a solid-state drive dynamic garbage collection device according to this embodiment. Detailed Implementation
[0038] To better understand the purpose, technical solution, and advantages of this application, the application is described and explained below in conjunction with the accompanying drawings and embodiments.
[0039] Unless otherwise defined, the technical or scientific terms used in this application shall have the general meaning as understood by one of ordinary skill in the art to which this application pertains. Words such as “a,” “an,” “an,” “the,” “the,” and “these,” used in this application, do not indicate quantitative limitation and may be singular or plural. The terms “comprising,” “including,” “having,” and any variations thereof used in this application are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or device that comprises a series of steps or modules (units) is not limited to the listed steps or modules (units) but may include steps or modules (units) not listed, or may include other steps or modules (units) inherent to such processes, methods, products, or devices. The terms “connected,” “linked,” and “coupled,” used in this application, are not limited to physical or mechanical connections but may include electrical connections, whether direct or indirect. The term “multiple” used in this application refers to two or more. The "and / or" operator describes the relationship between related objects, indicating that three relationships can exist. For example, "A and / or B" can represent three cases: A alone, A and B simultaneously, and B alone. Typically, the character " / " indicates that the objects before and after it are in an "or" relationship. The terms "first," "second," and "third," etc., used in this application are merely for distinguishing similar objects and do not represent a specific ordering of the objects.
[0040] The method embodiments provided in this example can be executed on a terminal, computer, or similar computing device. For example, it can run on a terminal. Figure 1This is a hardware structure block diagram of the terminal for a method of dynamic garbage collection of a solid-state drive according to this embodiment. For example... Figure 1 As shown, a terminal may include one or more ( Figure 1 Only one is shown in the diagram. A processor 102 and a memory 104 for storing data are also included. The processor 102 may be, but is not limited to, a microprocessor (MCU) or a programmable logic device (FPGA). The terminal may also include a transmission device 106 for communication functions and an input / output device 108. Those skilled in the art will understand that… Figure 1 The structure shown is for illustrative purposes only and does not limit the structure of the terminal described above. For example, the terminal may also include components that are larger than... Figure 1 The more or fewer components shown, or having the same Figure 1 The different configurations shown are illustrated.
[0041] The memory 104 can be used to store computer programs, such as application software programs and modules, like the computer program corresponding to a method for dynamic garbage collection of a solid-state drive in this embodiment. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, thereby implementing the above-described method. The memory 104 may include high-speed random access memory and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include memory remotely located relative to the processor 102, and these remote memories can be connected to the terminal via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.
[0042] The transmission device 106 is used to receive or send data via a network. This network includes a wireless network provided by the terminal's communication provider. In one example, the transmission device 106 includes a Network Interface Controller (NIC), which can connect to other network devices via a base station to communicate with the Internet. In another example, the transmission device 106 can be a Radio Frequency (RF) module used for wireless communication with the Internet.
[0043] This embodiment provides a method for dynamic garbage collection of solid-state drives. Figure 2 This is a flowchart of a method for dynamic garbage collection of a solid-state drive according to this embodiment, such as... Figure 2 As shown, the process includes the following steps:
[0044] Step S201: Set the power-on restart garbage collection time t1.
[0045] Specifically, set the garbage collection time t1 after power-on restart. The specific time t1 can be determined through multiple debugging experiments and will vary depending on different hard drives or application environments. For example, it can be set to 10 seconds.
[0046] Step S202: When the power-on restart time of the solid-state drive is less than or equal to the power-on restart garbage collection time t1 and the number of free blocks in the solid-state drive is lower than the set threshold, the garbage collection (GC) mechanism of the solid-state drive is started, and the ratio of GC write operations to user write operations is set as the power-on ratio; the power-on ratio indicates that the solid-state drive allows GC write operations and prohibits user write operations.
[0047] Specifically, when the number of free blocks in the SSD falls below a set threshold from the moment the SSD powers on and restarts until the set power-on garbage collection time t1, the SSD's garbage collection (GC) mechanism is activated, and the ratio of GC write operations to user write operations is set to the power-on ratio. The power-on ratio indicates that the SSD allows GC write operations and prohibits user write operations. For example, the power-on ratio can be 1:0. When the power-on ratio is 1:0, it means that the SSD only performs GC write operations and prohibits user write operations.
[0048] As a further example, if the set power-on restart garbage collection time t1 is 10 seconds, and the solid-state drive loses power after only 7 seconds of power-on restart, then the solid-state drive will only perform 7 seconds of GC write operations and prohibit user write operations.
[0049] Through the above steps, by setting a power-on restart garbage collection time t1, when the power-on restart time of the solid-state drive is less than or equal to the power-on restart garbage collection time t1 and the number of free blocks in the solid-state drive is lower than the set threshold, the solid-state drive's garbage collection (GC) mechanism is activated, and only GC write operations are allowed while user write operations are prohibited. This solves the problem of excessive GC causing user write timeouts when the GC mechanism occurs together with frequent power-on and power-off cycles in the prior art, and realizes timely garbage collection under frequent power-on and power-off conditions.
[0050] In some of these embodiments, when the power-on restart time of the solid-state drive is greater than the power-on restart garbage collection time t1, it is determined whether the number of free blocks in the solid-state drive is lower than a set threshold.
[0051] If so, enable the SSD's GC mechanism, calculate the dynamic ratio of GC write operations to user write operations based on the available space of the SSD and the effective data volume of the source blocks; control the SSD to perform GC write operations and user write operations according to the dynamic ratio.
[0052] If not, disable the GC mechanism for the SSD.
[0053] In some of these embodiments, while the solid-state drive is powered on, it is determined whether the number of free blocks in the solid-state drive is below a set threshold.
[0054] If so, enable the SSD's GC mechanism, calculate the dynamic ratio of GC write operations to user write operations based on the available space of the SSD and the effective data volume of the source blocks; control the SSD to perform GC write operations and user write operations according to the dynamic ratio.
[0055] If not, disable the GC mechanism for the SSD.
[0056] Specifically, during SSD operation, if the user's available space (Free Block) falls below a certain threshold, the GC mechanism is activated to release more Free Block.
[0057] Specifically, since GC write operations consume bandwidth from user write operations, to avoid impacting user write speed, the GC mechanism does not complete the operation all at once. Instead, it calculates the write ratio based on the available NAND Flash space and the effective data volume of the source block, allowing GC write operations and user write operations to be completed in a time-sharing manner. For example, if the GC write to user write ratio is n:m, then when the GC writes n pages of data to the NAND Flash, it will be unable to continue writing until the user writes m pages of data to the NAND Flash. Here, n and m are obtained by calculating the dynamic ratio of GC write operations to user write operations based on the available space of the SSD and the effective data volume of the source block.
[0058] Furthermore, after powering on for a period of time, the ratio of GC writes to user writes is dynamically adjusted to avoid affecting the user write rate.
[0059] Furthermore, after the garbage collection mechanism has been running for a period of time, if the number of free blocks on the SSD exceeds a certain threshold, the GC mechanism can be turned off in order not to affect the user's write speed.
[0060] In some of these embodiments, initiating the GC mechanism includes:
[0061] Read valid data from the source block, write the valid data into the GC target block, perform an erase operation on the source block, and turn the source block into a free block.
[0062] Specifically, the vast majority of solid-state drives (SSDs) currently use NAND flash memory as their storage medium. Therefore, the working principle of SSDs is largely based on the characteristics of flash memory. Garbage collection (GC) is based on the "erase before write" characteristic of flash memory. Data is written to a page, and erased from a block. As data is continuously written, a large amount of invalid data eventually accumulates in the blocks. Garbage collection is then used to move the valid data out of these blocks and erase the blocks containing only invalid data.
[0063] Specifically, the GC mechanism mainly includes the following steps:
[0064] Step 1: Find the data block with the smallest effective data volume and use it as the source block for GC;
[0065] Step 2: Combine the logical-physical address forward table (L2P Table) and reverse table (P2L Table) to determine the physical address of the smallest valid data unit in the Source Block;
[0066] Step 3: Read the valid data from the Source Block into the SSD controller RAM area;
[0067] Step 4: After integrating the valid data in the RAM area, write it back to the GC target block.
[0068] Step 5: Repeat steps 2, 3, and 4 to rewrite all valid data from the Source Block into the Target Block, erase the Source Block, and then the Source Block becomes the Free Block.
[0069] In some embodiments, reading valid data from the source block and writing the valid data into the GC target block includes:
[0070] Read the valid data from the source block into the main control RAM area of the solid-state drive;
[0071] The valid data in the main controller RAM area of the solid-state drive is integrated and written into the GC target block.
[0072] In some embodiments, initiating the GC mechanism further includes:
[0073] Traverse the data blocks of the solid-state drive and find the data block with the smallest amount of valid data, which will be used as the source block.
[0074] The present embodiment will now be described and illustrated through preferred embodiments.
[0075] Figure 3 This is a flowchart of a dynamic garbage collection method for solid-state drives according to a preferred embodiment of this invention. Figure 3 As shown, the dynamic garbage collection method for solid-state drives includes the following steps:
[0076] Step S301: During the SSD power-on period, the user continuously writes data to the NAND Flash.
[0077] Step S302: When the number of free blocks in the NAND Flash is lower than a certain threshold, the SSD starts the GC mechanism.
[0078] Step S303: Obtain the Source Block. Based on its effective data volume and the available space in the NAND Flash, determine the ratio of GC writes to user writes as n:m.
[0079] Step S304: Record the source location and other relevant information of the valid data that has been rewritten in the Source Block in real time, and store this information in the NAND Flash.
[0080] Specifically, the source block records information such as the source location of rewritten valid data in real time and stores this information in the NAND Flash. For example, a source block that needs to be garbage collected contains 1000 pages (numbered 0-999, some pages contain valid data, some do not). Before the SSD loses power, this block is undergoing garbage collection, starting from page_0 and incrementing sequentially until page_999 is completed. When valid data is being transferred from page_500, the power goes out. Page_500 is one of the relevant information of the source block, and this information is recorded in the NAND before the power outage so that it can be retrieved upon the next power-on. Therefore, when the SSD performs garbage collection on this source block, it does not need to retrace from page_0; it can simply continue from the position where the power outage ended, improving the efficiency of garbage collection. Of course, the relevant information is not only page information but also other marker information that helps with garbage collection.
[0081] Step S305: Power off the SSD at any time.
[0082] Specifically, "any time" refers to any moment during the SSD's power-on period. At the moment of power loss, the SSD may be performing garbage collection or not. In short, the SSD can be in any state when power is off. This refers to any power outage occurring during the normal operation of the hard drive.
[0083] Step S306: Power on the SSD again. If the number of free blocks in the NAND Flash is lower than a certain threshold, proceed to step S307; otherwise, proceed to step S311.
[0084] Specifically, at the power-on restart time, it is determined whether the number of free blocks in the NAND Flash of the solid-state drive is lower than a certain threshold. If so, proceed to step S307; otherwise, proceed to step S311.
[0085] Step S307: Start the GC mechanism to recover the relevant information of the Source Block before power failure from the NAND Flash, so as to avoid repeatedly searching for pages that have been searched before power failure.
[0086] Step S308: After power-on, for a period of time, directly set the ratio of GC write to user write to 1:0, that is: only GC write is performed, and user write is prohibited.
[0087] Specifically, this time period was determined by technicians through multiple debugging tests. Different hard drives and application environments will result in different time periods. Under normal circumstances, it can be set to 10 seconds or tens of seconds, depending on the specific situation. During frequent power-on and power-off cycles, only GC writes are performed for a short period, and user writes are prohibited, based on time conditions.
[0088] Specifically, during a power-on restart period, for example, set to 10 seconds, only GC writes are performed during the first 10 seconds of the restart, and user writes are prohibited. An exception is if a power outage occurs after only 6 seconds of power-on; in this case, only 6 seconds of GC write operations are performed, this step is terminated, and the remaining 4 seconds of GC write operations are not executed.
[0089] Furthermore, when frequent power-on / off scenarios occur simultaneously with the GC mechanism, the GC only needs to be fully executed for a short period of time to avoid exhausting the available space.
[0090] Step S309: If the SSD is powered on for a shorter period than the time set in step S308, power off the SSD and proceed to step S306; otherwise, proceed to step S310.
[0091] Specifically, if the SSD is powered on for less than the time set in step S308, for example, if the SSD power-on restart time is 6 seconds and it is less than the set time of 10 seconds, a power failure occurs. At this time, the process jumps to step S306 and waits for the SSD to be powered on again. If the SSD is powered on for more than or equal to the time set in step S308, the process jumps to step S310.
[0092] In step S310, if the GC mechanism still needs to be performed, the ratio of GC writes to user writes needs to be recalculated based on the effective data volume of the Source Block and the available space in the NAND Flash.
[0093] Specifically, when the SSD is powered on for a duration not less than the set time in step S308, it is determined whether the GC mechanism still needs to be performed. If so, the ratio of GC writes to user writes is recalculated based on the effective data volume of the Source Block and the available space in the NAND Flash, so that GC write operations and user write operations are completed in a time-sharing manner. For example, if the ratio of GC writes to user writes is n:m, that is, when the GC writes n pages of data into the NAND Flash, the GC will be unable to continue writing until the user writes m pages of data into the NAND Flash, thereby avoiding user write operation timeouts.
[0094] Step S311: Disable the GC mechanism.
[0095] Specifically, after the garbage collection mechanism has been running for a period of time, if the number of free blocks on the SSD exceeds a certain threshold and the available space in the NAND Flash is sufficient, the GC mechanism can be turned off in order to improve the user's write speed.
[0096] It should be noted that the steps shown in the above process or in the flowchart of the accompanying figures can be executed in a computer system such as a set of computer-executable instructions, and 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.
[0097] Figure 4 This is a structural block diagram of a solid-state drive according to this embodiment, such as... Figure 4 As shown, the solid-state drive 1 includes: an SSD controller 11 and a flash memory chip 12;
[0098] SSD controller 11 is used to perform the solid-state drive dynamic garbage collection method in the above embodiment on flash memory chip 12.
[0099] Specifically, the solid-state drive also includes RAM 13 and a logical control interface 14. For each user page (Host Page) written by the host, the SSD controller 11 will find a physical page in the flash memory chip 12 to write the Host data. The SSD controller 11 also records such a mapping Map internally. The SSD maintains a mapping table. This embodiment takes an SSD based on the Sandforce controller as an example. When the solid-state drive 1 is working, most of its mappings are stored in the flash memory chip 12, and a portion is stored on the on-chip RAM 13.
[0100] This embodiment also provides a solid-state drive dynamic garbage collection device, which is used to implement the above embodiments and preferred embodiments, and will not be repeated as described above. The terms "module," "unit," "subunit," etc., used below can refer to a combination of software and / or hardware that performs 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.
[0101] Figure 5 This is a structural block diagram of a solid-state drive dynamic garbage collection device according to this embodiment, as shown below. Figure 5 As shown, the device includes:
[0102] Time setting module 10 is used to set the power-on restart garbage collection time t1;
[0103] The processing module 20 is used to start the solid-state drive's garbage collection (GC) mechanism when the power-on restart time of the solid-state drive is less than or equal to the power-on restart garbage collection time t1 and the number of free blocks in the solid-state drive is lower than a set threshold, and to set the ratio of GC write operations to user write operations as the power-on ratio; the power-on ratio indicates that the solid-state drive allows GC write operations and prohibits user write operations.
[0104] It should be noted that the above modules can be functional modules or program modules, and can be implemented through software or hardware. For modules implemented through hardware, the above modules can reside in the same processor; or the above modules can be located in different processors in any combination.
[0105] This embodiment also provides an electronic device including a memory and a processor, the memory storing a computer program and the processor being configured to run the computer program to perform the steps in any of the above method embodiments.
[0106] Optionally, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor and the input / output device is connected to the processor.
[0107] Optionally, in this embodiment, the processor can be configured to perform the following steps via a computer program:
[0108] S1, set the time t1 for restarting garbage collection upon power-on;
[0109] S2, when the power-on restart time of the solid-state drive is less than or equal to the power-on restart garbage collection time t1 and the number of free blocks in the solid-state drive is lower than the set threshold, the garbage collection (GC) mechanism of the solid-state drive is started, and the ratio of GC write operations to user write operations is set as the power-on ratio; the power-on ratio means that the solid-state drive allows GC write operations and prohibits user write operations.
[0110] It should be noted that the specific examples in this embodiment can refer to the examples described in the above embodiments and optional implementations, and will not be repeated in this embodiment.
[0111] Furthermore, in conjunction with the solid-state drive dynamic garbage collection method provided in the above embodiments, this embodiment can also provide a storage medium for implementation. This storage medium stores a computer program; when executed by a processor, the computer program implements any of the solid-state drive dynamic garbage collection methods described in the above embodiments.
[0112] It should be understood that the specific embodiments described herein are merely illustrative of the application and not intended to limit it. All other embodiments derived by those skilled in the art based on the embodiments provided in this application without inventive effort are within the scope of protection of this application.
[0113] Obviously, the accompanying drawings are merely some examples or embodiments of this application. Those skilled in the art can apply this application to other similar situations based on these drawings without any creative effort. Furthermore, it is understood that although the work done in this development process may be complex and lengthy, for those skilled in the art, certain design, manufacturing, or production modifications made based on the technical content disclosed in this application are merely conventional technical means and should not be considered as insufficient disclosure of this application.
[0114] The term "embodiment" in this application refers to a specific feature, structure, or characteristic described in connection with an embodiment that may be included in at least one embodiment of this application. The appearance of this phrase in various places in the specification does not necessarily imply the same embodiment, nor does it imply that it is mutually exclusive with or independent of other embodiments. It will be clearly or implicitly understood by those skilled in the art that the embodiments described in this application may be combined with other embodiments without conflict.
[0115] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of patent protection. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the appended claims.
Claims
1. A method for dynamic garbage collection of solid-state drives, characterized in that, include: Set the garbage collection time t1 to restart upon power-on; When the power-on restart time of the solid-state drive is less than or equal to the power-on restart garbage collection time t1 and the number of free blocks in the solid-state drive is lower than a set threshold, the garbage collection (GC) mechanism of the solid-state drive is started, and the ratio of GC write operations to user write operations is set as the power-on ratio; the power-on ratio indicates that the solid-state drive allows GC write operations and prohibits user write operations. When the power-on restart time of the solid-state drive is greater than the power-on restart garbage collection time t1, determine whether the number of free blocks in the solid-state drive is lower than the set threshold. If so, the GC mechanism of the solid-state drive is activated, and the dynamic ratio of the GC write operation to the user write operation is calculated based on the available space of the solid-state drive and the effective data volume of the source block; the solid-state drive is controlled to perform the GC write operation and the user write operation according to the dynamic ratio. If not, disable the GC mechanism for the solid-state drive.
2. The method for dynamic garbage collection of solid-state drives according to claim 1, characterized in that, The method further includes: During the period when the solid-state drive is powered on, it is determined whether the number of free blocks in the solid-state drive is lower than a set threshold. If so, the GC mechanism of the solid-state drive is activated, and the dynamic ratio of the GC write operation to the user write operation is calculated based on the available space of the solid-state drive and the effective data volume of the source block; the solid-state drive is controlled to perform the GC write operation and the user write operation according to the dynamic ratio. If not, disable the GC mechanism for the solid-state drive.
3. The method for dynamic garbage collection of solid-state drives according to any one of claims 1 to 2, characterized in that, The GC initiation mechanism includes: Read valid data from the source block, write the valid data into the GC target block, perform an erase operation on the source block, and turn the source block into a free block.
4. The method for dynamic garbage collection of solid-state drives according to claim 3, characterized in that, The step of reading valid data from the source block and writing the valid data into the GC target block includes: Read the valid data in the source block into the main control RAM area of the solid-state drive; The valid data in the main control RAM area of the solid-state drive is integrated and written into the GC target block.
5. The method for dynamic garbage collection of solid-state drives according to claim 3, characterized in that, The GC initiation mechanism also includes: Traverse the data blocks of the solid-state drive and find the data block with the smallest amount of valid data, which is then used as the source block.
6. A dynamic garbage collection device for solid-state drives, characterized in that, The device includes: The time setting module is used to set the garbage collection time t1 after power-on restart; The processing module is configured to initiate the garbage collection (GC) mechanism of the solid-state drive (SSD) when the power-on restart time is less than or equal to the power-on restart garbage collection time t1 and the number of free blocks in the SSD is lower than a set threshold, and set the ratio of GC write operations to user write operations as the power-on ratio; the power-on ratio indicates that the SSD allows GC write operations and prohibits user write operations. When the power-on restart time of the solid-state drive is greater than the power-on restart garbage collection time t1, determine whether the number of free blocks in the solid-state drive is lower than the set threshold. If so, the GC mechanism of the solid-state drive is activated, and the dynamic ratio of the GC write operation to the user write operation is calculated based on the available space of the solid-state drive and the effective data volume of the source block; the solid-state drive is controlled to perform the GC write operation and the user write operation according to the dynamic ratio. If not, disable the GC mechanism for the solid-state drive.
7. A solid-state drive, characterized in that, The solid-state drive includes: SSD controller, flash memory chip; The SSD controller is used to perform the method of dynamic garbage collection of solid-state drives according to any one of claims 1 to 5 on the flash memory chip.
8. An electronic device comprising a memory and a processor, characterized in that, The memory stores a computer program, and the processor is configured to run the computer program to perform the method for dynamic garbage collection of a solid-state drive as described in any one of claims 1 to 5.
9. A readable storage medium, characterized in that, The readable storage medium stores a computer program that, when executed by a processor, implements the steps of the method for dynamic garbage collection of a solid-state drive as described in any one of claims 1 to 5.