Garbage collection method and system for fast entering steady state of solid state disk
By using the open data block being written in the solid state drive as the target block for garbage collection, and alternately writing user data and garbage collection valid data, the problem of SSD requiring additional flash blocks during the garbage collection process is solved, and the performance and service life of SSD is improved.
Patent Information
- Application Number
- CN202411883507.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-19
- Publication Date
- 2025-04-25
AI Technical Summary
Existing SSDs require additional flash blocks during garbage collection, resulting in reduced reserved space, reduced random write performance, and affecting the service life of SSDs.
When writing data to the Nand flash memory block, there is an open data block that is being written. When the solid-state drive starts garbage collection, the open data block is used as the write destination block for garbage collection, obtains user data and effective data of garbage collection, calculates the write ratio, and alternately writes it into the write destination block for garbage collection based on the write ratio.
By reducing the overhead of open data blocks, improving the performance and service life of solid-state drives, ensuring that the solid-state drive quickly enters a stable state after garbage collection, and improving user experience.
Smart Images

Figure CN119883946A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of solid state hard disks, and in particular to a garbage collection method and system for a solid state hard disk to quickly enter a steady state. Background Art
[0002] The storage medium used by solid-state drives is generally NAND flash memory, which has the following characteristics: Flash memory blocks must be erased before they can be written, and cannot be overwritten; Flash memory does not allow overwriting, and when a new set of data is written, it is not allowed to change directly in the old location (flash memory does not allow repeated writing on a flash memory page), and needs to be written to a new location. Therefore, the SSD firmware needs to maintain a mapping table from logical addresses to physical addresses to track the location of the latest data stored in each logical block in the flash memory.
[0003] In addition, writing data to a new location will cause the data at the old location to become invalid, and these data become garbage data. Garbage data will occupy flash memory space. When the flash memory is insufficient, FTL needs to do garbage collection, that is, move the valid data on several flash blocks to a new flash block, and then erase these flash blocks to obtain available flash blocks. This is garbage collection.
[0004] Currently, most strategies for garbage collection use reserved flash blocks as write blocks for garbage collection, or use the SLC area to cache valid data; although the above solutions can improve the garbage collection speed to a certain extent and quickly release space for user data, they all require additional flash blocks to serve garbage collection, which to a certain extent reduces the reserved space of the SSD, resulting in reduced random write performance and shortened SSD life. Summary of the invention
[0005] In view of this, the purpose of the present invention is to provide a garbage collection method and system for a solid-state hard disk to quickly enter a steady state, thereby improving the stability of the solid-state hard disk performance, increasing the efficiency of garbage collection and the life of the solid-state hard disk, and improving the user experience.
[0006] In a first aspect, an embodiment of the present invention provides a garbage collection method for a solid state hard disk to quickly enter a steady state, the method comprising:
[0007] During the process of writing data to the nand flash memory block, there is an open data block being written at the same time;
[0008] When garbage collection is started on the solid state drive, the open data block is used as a write destination block for garbage collection;
[0009] Obtain valid data of user data and garbage collection, and calculate the write ratio;
[0010] The user data and the valid data of the garbage collection are alternately written into the writing destination block of the garbage collection according to the writing ratio.
[0011] Furthermore, the write ratio is calculated, including:
[0012] Obtaining the number of free physical pages remaining in the write destination block of the garbage collection and the number of valid physical pages on the garbage collection original block;
[0013] The write ratio of the write amount of the garbage collected valid data to the write amount of the user data is calculated according to the number of the remaining free physical pages and the number of the valid physical pages.
[0014] Further, calculating the write ratio of the write amount of the garbage collected valid data to the write amount of the user data according to the number of the remaining free physical pages and the number of the valid physical pages includes:
[0015] When the number of the remaining free physical pages is greater than the number of the valid physical pages, obtaining a difference between the number of the remaining free physical pages and the number of the valid physical pages;
[0016] Calculating the write ratio according to the difference and the number of valid physical pages;
[0017] When the number of the remaining free physical pages is less than a first preset threshold, the write ratio is 1.
[0018] Further, calculating the write ratio according to the difference and the number of valid physical pages includes:
[0019] The write ratio is calculated according to the following formula:
[0020] MoveRatio=(FreePageCnt-SrcValidPageCnt) / SrcValidPageCnt
[0021] =A / SrcValidPageCnt
[0022] Wherein, MoveRatio is the write ratio, A is the difference, FreePageCnt is the number of remaining free physical pages, and SrcValidPageCnt is the number of valid physical pages.
[0023] Furthermore, the method further comprises:
[0024] When the writing destination block of the garbage collection is full, the garbage collection source block is released.
[0025] Furthermore, the method further comprises:
[0026] When the background monitoring finds that the nand flash memory block cannot read or write data, the garbage collection block is forced to start;
[0027] The valid data of the physical page on the forced garbage collection block is recycled in batches through a second preset threshold.
[0028] In a second aspect, an embodiment of the present invention provides a garbage collection system for a solid state hard disk to quickly enter a steady state, the system comprising:
[0029] There is a module for writing data to a nand flash memory block when there is an open data block being written at the same time;
[0030] A startup module, used for using the open data block as a write destination block for garbage collection when the solid state drive starts garbage collection;
[0031] The calculation module is used to obtain valid data of user data and garbage collection, and calculate the write ratio;
[0032] The alternating writing module is used to write the user data and the valid data of the garbage collection alternately into the writing destination block of the garbage collection according to the writing ratio.
[0033] Furthermore, the calculation module is specifically used for:
[0034] Obtaining the number of free physical pages remaining in the write destination block of the garbage collection and the number of valid physical pages on the garbage collection original block;
[0035] The write ratio of the write amount of the garbage collected valid data to the write amount of the user data is calculated according to the number of the remaining free physical pages and the number of the valid physical pages.
[0036] In a third aspect, an embodiment of the present invention provides an electronic device, including a memory and a processor, wherein the memory stores a computer program executable on the processor, and the processor implements the method described above when executing the computer program.
[0037] In a fourth aspect, an embodiment of the present invention provides a computer-readable medium having a non-volatile program code executable by a processor, wherein the program code enables the processor to execute the method as described above.
[0038] The embodiment of the present invention provides a garbage collection method and system for a solid-state hard disk to quickly enter a steady state, including: in the process of writing data to a NAND flash memory block, there is an open data block being written at the same time; when the solid-state hard disk starts garbage collection, the open data block is used as a writing target block for garbage collection; user data and valid data of garbage collection are obtained, and a writing ratio is calculated; user data and valid data of garbage collection are alternately written into the writing target block of garbage collection according to the writing ratio; the stability of the solid-state hard disk performance is improved, the efficiency of garbage collection and the life of the solid-state hard disk are improved, and the user experience is improved.
[0039] Other features and advantages of the present invention will be described in the following description, and partly become apparent from the description, or understood by practicing the present invention. The purpose and other advantages of the present invention are realized and obtained by the structures particularly pointed out in the description, claims and drawings.
[0040] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, preferred embodiments are given below and described in detail with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0042] Figure 1 A flow chart of a garbage collection method for a solid-state hard disk to quickly enter a steady state provided in the first embodiment of the present invention;
[0043] Figure 2 This is a diagram showing the effect of writing data when the writing ratio is 1 provided in the first embodiment of the present invention;
[0044] Figure 3 A schematic diagram of a garbage collection system for a solid-state hard disk that quickly enters a steady state provided in Embodiment 2 of the present invention. DETAILED DESCRIPTION
[0045] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the accompanying drawings. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0046] After the solid-state drive starts garbage collection during use, the solid-state drive will perform more read, write and erase operations inside, which will have a fluctuating effect on the host IO performance. In actual use, customers expect that after starting garbage collection, the solid-state drive can quickly enter a stable state to ensure performance consistency. At the same time, in order to improve the efficiency of garbage collection and the life of the solid-state drive, a suitable garbage collection strategy is particularly important in the use of the solid-state drive. The present application proposes a garbage collection method for the solid-state drive to quickly enter a steady state. After starting garbage collection, the acceleration disk quickly enters a stable state and can release OP, thereby increasing the service life of the solid-state drive and improving the user experience.
[0047] To facilitate understanding of this embodiment, the embodiment of the present invention is described in detail below.
[0048] Embodiment 1:
[0049] Figure 1 A flow chart of a garbage collection method for enabling a solid-state hard disk to quickly enter a steady state provided in Embodiment 1 of the present invention.
[0050] Reference Figure 1 , the method comprises the following steps:
[0051] Step S101, during the process of writing data into a nand flash memory block, there is an open data block being written at the same time;
[0052] Step S102, when the solid state drive starts garbage collection, the open data block is used as the write target block for garbage collection;
[0053] Step S103, obtaining user data and valid data of garbage collection, and calculating the write ratio;
[0054] Step S104, writing the user data and the valid data of garbage collection alternately into the writing destination block of garbage collection according to the writing ratio.
[0055] When a solid-state drive is used in random scenarios, it is expected that the solid-state drive can quickly enter a stable state after garbage collection is started. At the same time, in order to improve the efficiency of garbage collection and the life of the solid-state drive, and to ensure the consistency of the solid-state drive performance, this application proposes a garbage collection method for the solid-state drive to quickly enter a steady state, improve the performance stability of the solid-state drive, and enhance the user experience, in response to this scenario and the defects of the prior art.
[0056] The user data (host data) is written into the open data block, and the open data block is used as the write destination block for garbage collection. That is, in the random write scenario, there is an open data block in the NAND flash memory block at the same time, which is used as the write destination block for garbage collection. On this open data block, user data and valid data for garbage collection are written alternately, and the write frequency is controlled by the write ratio.
[0057] Further, step S103 includes the following steps:
[0058] Step S201, obtaining the number of free physical pages remaining in the garbage collection writing target block and the number of valid physical pages on the garbage collection original block;
[0059] Step S202 , calculating a write ratio of a write amount of valid data for garbage collection to a write amount of user data according to the number of remaining free physical pages and the number of valid physical pages.
[0060] Further, step S202 includes the following steps:
[0061] Step S301, when the number of remaining free physical pages is greater than the number of valid physical pages, obtaining the difference between the number of remaining free physical pages and the number of valid physical pages;
[0062] Step S302, calculating the write ratio according to the difference and the number of valid physical pages;
[0063] Step S303: when the number of remaining free physical pages is less than a first preset threshold, the write ratio is 1.
[0064] Further, step S302 includes:
[0065] The write ratio is calculated according to formula (1):
[0066] MoveRatio=(FreePageCnt-SrcValidPageCnt) / SrcValidPageCnt
[0067] =A / SrcValidPageCnt (1)
[0068] Among them, MoveRatio is the write ratio, A is the difference, FreePageCnt is the number of remaining free physical pages, and SrcValidPageCnt is the number of valid physical pages.
[0069] Specifically, refer to Figure 2When the write ratio is 1, page0 writes user data, page1 writes GC data (valid data for garbage collection), page2 writes user data, page3 writes GC data, and so on. That is, write a page of user data and then write a page of GC data, and the two are written alternately.
[0070] Furthermore, the method further comprises the following steps:
[0071] Step S401, when the writing destination block of garbage collection is full, the garbage collection source block is released.
[0072] Specifically, when there is no other background forced garbage collection (normal garbage collection), the above strategy is used to fill up a flash memory block and release a free block for data writing through garbage collection.
[0073] The purpose of garbage collection is to release free blocks. The process is to move the valid data on the garbage collection source block. After the move, the source block is erased and turned into a free block. This free block can be used to write new user data.
[0074] Furthermore, the method further comprises the following steps:
[0075] Step S501, when the background monitor detects that the nand flash memory block cannot read or write data, the garbage collection block is forced to start;
[0076] Step S502: Recycling valid data of physical pages on the forced garbage collection block in batches when the data reaches a second preset threshold.
[0077] Specifically, the background is a monitor running on the software. When the background monitors that the nand flash memory block cannot read or write data, the forced garbage collection block is started. The valid data of the physical page on the forced garbage collection block is recycled in batches.
[0078] In order to ensure that performance and free space are not affected, the amount of valid data in the physical page collected each time by forced garbage collection cannot exceed a second preset threshold TH, which can generally be 1% of the total physical page data amount of the current flash memory block.
[0079] In the use of the solid-state drive, the present application has an open data block being written at the same time, which reduces the block overhead introduced by multiple open data blocks, thereby increasing the OP of the solid-state drive, improving the random write performance and the service life of the solid-state drive.
[0080] In the scenario of completely random write, the above method of controlling the amount of effective data and user data written for garbage collection is used. Since the efficiency of each flash block is evenly distributed in this scenario, the ratio of effective data and user data for garbage collection can be quickly stabilized, so that the solid-state drive can quickly enter a stable state. At the same time, this strategy can ensure the release of free blocks, which can prevent the solid-state drive from abnormalities caused by excessive consumption of idle blocks; when there is forced garbage collection, it is recycled in batches to reduce its impact on performance and normal garbage collection.
[0081] The present application has the following beneficial effects: writing the valid data and user data of garbage collection into the same open data block, reducing the overhead of the open data block, improving the OP of the solid-state drive, and thus improving the performance and service life of the solid-state drive; adopting an alternating flow control algorithm for valid data and user data of garbage collection, which can accelerate the solid-state drive to quickly enter a stable state during random writing, and at the same time ensure that there are sufficient free blocks on the solid-state drive; when starting forced garbage collection, the recovery speed is controlled by a second preset threshold to ensure performance stability.
[0082] Embodiment 2:
[0083] Figure 3 A schematic diagram of a garbage collection system for a solid-state hard disk that quickly enters a steady state provided in Embodiment 2 of the present invention.
[0084] Reference Figure 3 , the system includes:
[0085] There is a module for writing data to a nand flash memory block when there is an open data block being written at the same time;
[0086] The startup module is used to use the open data block as the write destination block for garbage collection when the solid-state drive starts garbage collection;
[0087] The calculation module is used to obtain valid data of user data and garbage collection, and calculate the write ratio;
[0088] The alternating writing module is used to write the user data and the valid data of the garbage collection alternately into the writing destination block of the garbage collection according to the writing ratio.
[0089] Furthermore, the calculation module is specifically used for:
[0090] Get the number of free physical pages remaining in the garbage collection write destination block and the number of valid physical pages on the garbage collection original block;
[0091] According to the number of remaining free physical pages and the number of valid physical pages, a write ratio of the write amount of valid data of garbage collection to the write amount of user data is calculated.
[0092] The embodiment of the present invention provides a garbage collection method and system for a solid-state hard disk to quickly enter a steady state, including: in the process of writing data to a NAND flash memory block, there is an open data block being written at the same time; when the solid-state hard disk starts garbage collection, the open data block is used as a writing target block for garbage collection; user data and valid data of garbage collection are obtained, and a writing ratio is calculated; user data and valid data of garbage collection are alternately written into the writing target block of garbage collection according to the writing ratio; the stability of the solid-state hard disk performance is improved, the efficiency of garbage collection and the life of the solid-state hard disk are improved, and the user experience is improved.
[0093] An embodiment of the present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the steps of the garbage collection method for enabling a solid-state hard disk to quickly enter a steady state provided in the above embodiment are implemented.
[0094] An embodiment of the present invention also provides a computer-readable medium having a non-volatile program code executable by a processor, wherein a computer program is stored on the computer-readable medium, and when the computer program is executed by the processor, the steps of the garbage collection method for quickly entering a steady state of a solid-state hard disk in the above embodiment are executed.
[0095] The computer program product provided in the embodiment of the present invention includes a computer-readable storage medium storing program code. The instructions included in the program code can be used to execute the method described in the previous method embodiment. The specific implementation can be found in the method embodiment and will not be repeated here.
[0096] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the system and device described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.
[0097] In addition, in the description of the embodiments of the present invention, unless otherwise clearly specified and limited, the terms "installed", "connected", and "connected" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection or an indirect connection through an intermediate medium, or it can be the internal communication of two components. For ordinary technicians in this field, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.
[0098] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc., which can store program codes.
[0099] In the description of the present invention, it should be noted that the terms "center", "upper", "lower", "left", "right", "vertical", "horizontal", "inner", "outer", etc., indicating the orientation or positional relationship, are based on the orientation or positional relationship shown in the drawings, and are only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as limiting the present invention. In addition, the terms "first", "second", and "third" are used for descriptive purposes only, and cannot be understood as indicating or implying relative importance.
[0100] Finally, it should be noted that the above-described embodiments are only specific implementations of the present invention, which are used to illustrate the technical solutions of the present invention, rather than to limit them. The protection scope of the present invention is not limited thereto. Although the present invention is described in detail with reference to the above-described embodiments, ordinary technicians in the field should understand that any technician familiar with the technical field can still modify the technical solutions recorded in the above-described embodiments within the technical scope disclosed by the present invention, or can easily think of changes, or make equivalent replacements for some of the technical features therein; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be based on the protection scope of the claims.
Claims
1. A garbage collection method for a solid state hard disk to quickly enter a steady state, characterized in that: The method comprises: During the process of writing data to the nand flash memory block, there is an open data block being written at the same time; When garbage collection is started on the solid state drive, the open data block is used as a write destination block for garbage collection; Obtain valid data of user data and garbage collection, and calculate the write ratio; The user data and the valid data of the garbage collection are alternately written into the writing destination block of the garbage collection according to the writing ratio.
2. The garbage collection method for a solid state hard disk to quickly enter a steady state according to claim 1, characterized in that: Calculate the write ratio, including: Obtaining the number of free physical pages remaining in the write destination block of the garbage collection and the number of valid physical pages on the garbage collection original block; The write ratio of the write amount of the garbage collected valid data to the write amount of the user data is calculated according to the number of the remaining free physical pages and the number of the valid physical pages.
3. The garbage collection method for a solid state hard disk to quickly enter a steady state according to claim 2, characterized in that: Calculating the write ratio of the write amount of the valid data of the garbage collection and the write amount of the user data according to the number of the remaining free physical pages and the number of the valid physical pages, including: When the number of the remaining free physical pages is greater than the number of the valid physical pages, obtaining a difference between the number of the remaining free physical pages and the number of the valid physical pages; Calculating the write ratio according to the difference and the number of valid physical pages; When the number of the remaining free physical pages is less than a first preset threshold, the write ratio is 1.
4. The garbage collection method for a solid state hard disk to quickly enter a steady state according to claim 3, characterized in that: Calculating the write ratio according to the difference and the number of valid physical pages includes: The write ratio is calculated according to the following formula: MoveRatio=(FreePageCnt-SrcValidPageCnt) / SrcValidPageCnt =A / SrcValidPageCnt Wherein, MoveRatio is the write ratio, A is the difference, FreePageCnt is the number of remaining free physical pages, and SrcValidPageCnt is the number of valid physical pages.
5. The garbage collection method for a solid state hard disk to quickly enter a steady state according to claim 1, characterized in that: The method further comprises: When the writing destination block of the garbage collection is full, the garbage collection source block is released.
6. The garbage collection method for a solid state hard disk to quickly enter a steady state according to claim 1, characterized in that: The method further comprises: When the background monitoring finds that the nand flash memory block cannot read or write data, the garbage collection block is forced to start; The valid data of the physical page on the forced garbage collection block is recycled in batches through a second preset threshold.
7. A garbage collection system for a solid state hard disk that quickly enters a steady state, characterized in that: The system comprises: There is a module for writing data to a nand flash memory block when there is an open data block being written at the same time; A startup module, used for using the open data block as a write destination block for garbage collection when the solid state drive starts garbage collection; The calculation module is used to obtain valid data of user data and garbage collection, and calculate the write ratio; The alternating writing module is used to write the user data and the valid data of the garbage collection alternately into the writing destination block of the garbage collection according to the writing ratio.
8. The garbage collection system for a solid state hard disk that quickly enters a steady state according to claim 7, characterized in that: The calculation module is specifically used for: Obtaining the number of free physical pages remaining in the write destination block of the garbage collection and the number of valid physical pages on the garbage collection original block; The write ratio of the write amount of the garbage collected valid data to the write amount of the user data is calculated according to the number of the remaining free physical pages and the number of the valid physical pages.
9. An electronic device comprising a memory and a processor, wherein the memory stores a computer program that can be run on the processor, wherein: When the processor executes the computer program, the method according to any one of claims 1 to 6 is implemented.
10. A computer readable medium having a non-volatile program code executable by a processor, characterized in that: The program code enables the processor to execute the method according to any one of claims 1 to 6.
Citation Information
Cited By
Garbage collection method, electronic equipment and storage medium
CN121300715A