Garbage recycling method for solid state disk
By monitoring the number of free_vb in a solid state drive in real time and determining whether to establish a source vb pool based on the threshold, the problem of time-consuming in the GC process is solved, and GC efficiency and write performance of the solid state drive are improved.
Patent Information
- Application Number
- CN202411694250.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-25
- Publication Date
- 2025-02-25
AI Technical Summary
During the garbage collection (GC) process of existing solid-state drives, it takes a long time to establish a source vb pool, resulting in low GC efficiency and affecting the write performance of the solid-state drive.
By monitoring the number of free_vb in real time, triggering GC when a certain threshold is reached, and determining whether a source vb pool needs to be established based on the number of new nodes, the number of new ST2 vbs and the number of source vb pool in the source vb pool, reducing the frequency of establishing source vb pool.
It shortens the time-consuming of GC, improves the efficiency of GC, and thus improves the write performance of solid-state drives.
Smart Images

Figure CN119512978A_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 for solid state hard disks. Background Art
[0002] Solid State Disk (Solid State Drive, SSD for short), also known as solid-state drive, is a hard disk made of a solid-state electronic storage chip array.
[0003] In the existing field of solid-state storage technology, the data in a vb (virtual block) consists of valid data and invalid data. The garbage collection (GC) mechanism is to move the valid data in the source vb to the target vb, thereby releasing the redundant invalid data in the source vb for use in a new round of hostwrite. If the GC takes a long time, it will affect the write efficiency, that is, the write performance of the solid-state drive can be improved by improving the GC efficiency.
[0004] In solid-state storage technology, there are generally four states of vb: Free: vb that is currently idle and not in use; Stage 0 (ST0): From Free state to ST0 vb after Erase, at this time, vb is not full; Stage 1 (ST1): ST0 vb will be converted to ST1 vb after program (indicates writing data to nand, nand is nand flash, refers to the medium for storing data); this data is full, but the table (each data will have its corresponding L2P mapping relationship, table is a collection of such mapping relationships) has not been written; Stage 2 (ST2): The data is full and the table is written. It is the end point of vb and will not return to Free until after GC.
[0005] In the existing GC strategy, a source vb pool is created every time GC is performed, and then a source vb is selected from the sourcevb pool. When creating a source vb pool, the vbs in the vb group of ST2 need to be sorted from small to large according to the vc (Valid Count, indicating the number of valid data) value; usually in a solid-state drive, there are a large number of vbs, and the corresponding selection and sorting are also time-consuming, so each time a source vb pool is created, it takes a lot of time.
[0006] In the field of solid-state storage, the data op (Over-Provisioning) of a hard disk is generally 7% of the physical capacity of the hard disk; when the host continues to write, in steady state, the invalid data in each vb accounts for 7% of the total (calculated based on the size of the OP); then 14 rounds of GC are required to release an empty vb (7% * 14 = 98%); at this time, the speed at which host write consumes vb must be balanced with GC, that is, host write consumes a vb after 14 rounds of GC. For GC, it takes 14 rounds of GC to generate a new vb data. Correspondingly, the vb group of ST2 does not change significantly at this time, but in each of the 14 rounds of GC, a source vb pool needs to be established, which is undoubtedly a waste of time.
[0007] In the GC process, the time consumption of each link will affect the time consumption of the entire GC; therefore, if the time consumption of certain links can be reduced or lowered, the efficiency of GC will be improved accordingly, thereby improving the write performance of the SSD. Summary of the invention
[0008] The present application solves the problem in the prior art that long GC time consumption affects the write performance of the solid-state hard disk by providing a garbage collection method for the solid-state hard disk, effectively improves the GC efficiency, and thus improves the write performance of the solid-state hard disk.
[0009] The present invention provides a method for garbage collection of a solid state drive, comprising the following steps: S1: monitors free_vb in real time and triggers GC when the threshold is reached; S2: According to the number of newly added nodes, the number of newly added ST2 vbs, and the amount of vbs in the source vb pool, if the number of newly added nodes ≥ thres1 or the number of newly added ST2 vbs ≥ thres2 or the amount of vbs in the source vb pool is exhausted, execute S3, otherwise execute S4; S3: Create source vb pool; S4: select source vb from source vb pool; S5: Create target_vb to store valid nodes in source vb; S6: Record the data of the valid node from the source vb selected in step S4; S7: Move the data of the valid node to target_vb; S8: After GC Write is completed, the L2P mapping relationship is updated; S9: after the L2P mapping relationship is updated, source vb is released; S10: Update vb_list.
[0010] In one of the embodiments of the present application, the number of newly added nodes, the number of newly added ST2 vbs, and the amount of vbs in the source vb pool in step S2 are all calculated from the last time the source vb pool was established.
[0011] In one of the embodiments of the present application, it is recommended that thres1 and thres2 in step S2 be set to 3 vb sizes.
[0012] In one embodiment of the present application, in step S3, all vbs in the source vb pool need to be sorted from small to large according to vc, in preparation for selecting vb.
[0013] In one of the embodiments of the present application, after the source vb pool is established in step S3, the number of newly added nodes and the number of newly added ST2 vbs are cleared, and the parameter recording the vb amount in the source vb pool is reassigned.
[0014] In one of the embodiments of the present application, in step S4, if there are vbs with vc=0, these vbs with vc=0 are freed; if not, 8 vbs are selected as source_vb of GC.
[0015] In one embodiment of the present application, in step S6, a valid node is confirmed through load_p21 and search_st3, and lca / pca related information of the valid node is saved.
[0016] In one embodiment of the present application, in step S7, the valid data migration process is divided into GCRead and GC Write; in GC Read, the data of the valid node obtained in S6 is read to buf; after Read is completed, the valid node read is written to target_vb through GC Write.
[0017] One or more technical solutions provided in the embodiments of the present application have at least the following technical effects or advantages: 1. This garbage collection method controls the timing of establishing a source vb pool through a threshold, reduces the frequency of establishing a source vb pool, shortens GC time, improves GC efficiency, and thus improves the write performance of the solid-state drive. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] In order to more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the following is a brief introduction to the drawings required for the specific embodiments or the description of the prior art. In all the drawings, similar elements or parts are generally identified by similar reference numerals. In the drawings, the elements or parts are not necessarily drawn according to the actual scale.
[0019] Figure 1 A flowchart of a garbage collection method for a solid state hard disk in an embodiment of the present application; Figure 2 This is a schematic diagram of the time consumption of three rounds of GC using the original GC method; Figure 3 This is a schematic diagram of the time consumption of performing three rounds of GC using the GC method in this embodiment. DETAILED DESCRIPTION
[0020] The present invention is further explained below in conjunction with specific implementation methods. It should be understood that these implementation methods are only used to illustrate the present invention and are not used to limit the scope of the present invention. After reading the present invention, various equivalent forms of modifications to the present invention by those skilled in the art all fall within the scope defined by the claims attached to this application.
[0021] It should be noted that similar reference numerals and letters denote similar items in the following drawings, and therefore, once an item is defined in one drawing, further definition and explanation thereof is not required in subsequent drawings.
[0022] The embodiment of the present application improves the timing of establishing a source vb pool in the scenario in the prior art, so as to reduce the frequency of establishing a source vb pool when performing GC, thereby reducing the time consumption of GC and improving GC efficiency.
[0023] The technical solution in the embodiment of the present application is to solve the above problems, and the overall idea is as follows: Example: like Figure 1 As shown, a garbage collection method for a solid state drive includes the following steps: S1: monitor free_vb in real time. When the number of free_vb decreases to gc_thres, GC is triggered. S2: According to the number of newly added nodes, the number of newly added ST2 vbs, and the amount of vbs in the source vb pool, if the number of newly added nodes ≥ thres1 or the number of newly added ST2 vbs ≥ thres2 or the amount of vbs in the source vb pool is exhausted, execute S3, otherwise execute S4; The number of newly added nodes, the number of newly added ST2 vbs, and the number of vbs in the source vb pool are all calculated from the last time the source vbpool was established, where: Number of newly added nodes: This value can be taken when new data is generated by host write or when the L2P (Logicaladdress to physical address) table changes, but do not take the L2P changes generated by GC into account; thres1 represents the threshold of the amount of new data generated by host write.
[0024] Number of newly added ST2 vbs: This value can be recorded when the vb of host write changes from ST1 to ST2. What needs to be recorded is the new data or ST2 vb generated by host write, so do not include the target vb generated by GC in the record of transferring to ST2. thres2 indicates the threshold of newly generated ST2 vb by host write.
[0025] The amount of vb in the source vb pool: This value can be used to record the number of sorted sourcevb pools after the source vb pool is established, and its corresponding amount can be reduced each time the source vb is released.
[0026] S3: Create source vb pool: Create a large pool containing all vbs in STAGE2 VB GRP (a collection of Stage 2 vbs), and sort them from small to large according to vc in preparation for selecting vbs.
[0027] Clear the number of newly added nodes and the number of newly added ST2 vbs, and reassign the parameters that record the vb quantity in the source vb pool.
[0028] If the source vb pool is not established in this step, the above values continue to be recorded; thus, what is recorded in step S2 is the change from the last GC when the source vb pool was established to the current GC.
[0029] S4: Select source vb: Select source vb for GC; if there are vbs with vc=0, directly free them (free refers to the vbs in Stage 2, which enter the free state (can be used for host write) after GC), and a round of GC can free up to 32 vbs; if there are no vbs, select 8 vbs from the established source vb pool in sequence as the source_vb of GC.
[0030] S5: Create target_vb: Create a target_vb to store the valid nodes in source vb.
[0031] S6: Record valid data of source vb: After selecting source vb, you need to confirm which valid nodes exist in source_vb.
[0032] The process is divided into two parts: load_p2l and search_st3; through these two steps, the valid node is confirmed and the lca / pca related information of the valid node is saved.
[0033] When saving data (PCA) in each vb, the corresponding LCA of the data is also saved. p2l_group is used to store the LCA corresponding to the PCA in the vb. According to the offset of LCA in p2l_group, its corresponding source_PCA can be obtained; then through search_st3, the corresponding PCA of the LCA in the L2P table can be obtained. If the PCA is the same as the source_PCA, it is a valid node, otherwise it is considered invalid (st3 stores the latest L2P table, if they are different, it means that the node is old data).
[0034] Load_p2l: reads the p2l_group in vb from nand (to cache); Search_st3: Search the entire L2P table to find the latest PCA based on the LCA in p2l_group, and then compare it with the PCA in p2l_group to determine whether its data is valid.
[0035] S7: Move valid data: Move valid nodes in src_vb to target_vb.
[0036] This process is divided into GC Read and GC Write. In GC Read, the data of the valid node obtained in S6 is read to buf (read buf, a cache space that temporarily stores the read data). After Read is completed, the valid node read is written to target_vb through GCWrite.
[0037] S8: insert gcsa: After GC Write is completed, the latest L2P mapping relationship is updated to ST3.
[0038] Among them, after garbage collection (GC), that is, after the valid data in the source vb is moved to the target vb, its L2P (Logical address to physical address) mapping relationship also changes; after garbage collection (GC), the new L2P mapping relationship needs to be updated, which is what insert gcsa does. That is, gcsa (garbage collection sorted arry) means that the data mapping relationship needs to be sorted and updated after GC.
[0039] S9: Release source vb: After the L2P table is updated, source_vb is freed for host write use.
[0040] S10: Update vb_list: update the corresponding information in vb_list.
[0041] vb_list refers to a list of vb states; source vb is originally in stage 2 state. After GC, the valid data in this vb is moved away and it can be released (free) for continued use by host write. At this time, the vb will enter the free state, and the state of the source vb has changed. vb_list needs to be updated to save it to prevent loss.
[0042] Among them, it should be noted that for step S2-3: the timing of establishing the source vb pool is strongly related to host write; if the amount of data generated by host write is small, the vb group of ST2 has not changed, so there is no need to re-establish the source vb pool during GC; when the amount of data generated by host write is relatively large, it is necessary to re-establish the source vb pool during GC. Therefore, a threshold can be set according to the amount of data generated by host write, and the source vb pool is re-established when the data amount reaches the threshold. If it does not reach the threshold, the previous source vbpool continues to be used.
[0043] Furthermore, it is recommended that thres1 and thres2 be set to 3 vb sizes, that is, the number of nodes corresponding to 3 vb; the size of vb is related to the patch capacity and patch method of the actual disk. The size of vb of each product may be different, but the overall reading, writing, erasing and GC are all in vb.
[0044] If the threshold is set too high, the amount of new data generated by host write will take a long time to reach the threshold, and the source vb pool cannot be re-established during GC. The old pool will always be used, which will cause two problems: when the sourcevb pool is established, it is sorted according to the size of the vc. As GC is executed, the number of vbs with smaller vcs in the front part decreases, and subsequent GCs will use vbs with larger vcs, which will affect the number of invalid nodes released in each round of GC and will also be accompanied by an increase in write amplification; if the latest ST2 vb group is not used in time, the vbs with smaller vcs may be missed.
[0045] If the threshold is set too small, GC will create source vb pool more frequently, reducing GC efficiency.
[0046] As mentioned above, it is recommended to set thres1 and thres2 to 3 vb based on the above situation. The amount of data generated by hostwrite and ST2 vb is not large, and the frequency of GC establishing source vb pool is also reduced.
[0047] Three rounds of GC were performed using the original GC method and the GC method in this embodiment. Figure 2 , 3 As shown, Figure 2 , 3Middle: Create source vb pool (a), select source vb (b), create target vb (c), record valid data in src vb (d), move valid data to target vb (e), insert gcsa (f), release source vb (g), update vb list (h). After reaching the threshold to trigger GC, the first round of GC is set to A, the second round of GC is set to B, and the third round of GC is set to C (vertical axis).
[0048] from Figure 2 , 3 By comparison, assuming that the time consumption of each link in GC is 1s, then: in the original GC method, each round of GC consumes 8s; in this GC method, the first round of GC consumes 8s, and the second round of GC can omit the time of establishing the source vb pool if thres1, thres2 and vb in source vbpool are not exhausted, so it only takes 7s to complete; the third round of GC takes 8s according to the normal process when the above thresholds are triggered.
[0049] It can be seen that by adopting this garbage collection method, the threshold is used to control the timing of establishing the source vb pool, and the frequency of establishing the source vb pool is reduced, the GC time consumption is shortened, and the GC efficiency is improved; the corresponding steady-state performance of the host write will also be improved.
[0050] The embodiment of the present application also provides a solid state drive that adopts the aforementioned garbage collection method.
[0051] Although the embodiments of the present invention have been shown and described above, it is to be understood that the above embodiments are exemplary and are not to be construed as limitations of the present invention. A person skilled in the art may change, modify, replace and vary the above embodiments within the scope of the present invention.
Claims
1. A garbage collection method for a solid state hard disk, characterized in that: The following steps are involved: S1: monitors free_vb in real time and triggers GC when the threshold is reached; S2: According to the number of newly added nodes, the number of newly added ST2 vbs, and the amount of vbs in the source vb pool, if the number of newly added nodes ≥ thres1 or the number of newly added ST2 vbs ≥ thres2 or the amount of vbs in the source vb pool is exhausted, execute S3, otherwise execute S4; S3: Create source vb pool; S4: select source vb from source vb pool; S5: Create target_vb to store valid nodes in source vb; S6: Record the data of the valid node from the source vb selected in step S4; S7: Move the data of the valid node to target_vb; S8: After GC Write is completed, the L2P mapping relationship is updated; S9: after the L2P mapping relationship is updated, source vb is released; S10: Update vb_list.
2. The garbage collection method according to claim 1, characterized in that: The number of newly added nodes, the number of newly added ST2 vbs, and the amount of vbs in the source vb pool in step S2 are all calculated from the last time the source vb pool was established.
3. The garbage collection method according to claim 2, characterized in that: In step S2, thres1 and thres2 are recommended to be set to 3 vb sizes.
4. The garbage collection method according to claim 1, characterized in that: In step S3, all vbs in the source vb pool need to be sorted from small to large according to vc.
5. The garbage collection method according to claim 1, characterized in that: After the source vbpool is established in step S3, the number of newly added nodes and the number of newly added ST2 vbs are cleared, and the parameter recording the vb quantity in the source vb pool is reassigned.
6. The garbage collection method according to claim 1, characterized in that: In the step S4, if there are vbs with vc=0, these vbs with vc=0 are freed; if not, 8 vbs are selected as source_vb of GC.
7. The garbage collection method according to claim 1, characterized in that: In the step S6, a valid node is confirmed through load_p21 and search_st3, and the lca / pca data of the valid node is saved.
8. The garbage collection method according to claim 7, characterized in that: In the step S7, the migration process of the valid node data is divided into GC Read and GC Write; in GC Read, the data of the valid node obtained in the step S6 is read to buf; after Read is completed, the read valid node is written to target_vb through GC Write.
9. A solid state hard disk, characterized in that: A garbage collection method as described in claims 1-8 is adopted.