Garbage collection control method and electronic device
By determining the number of write blocks based on the number of empty data blocks during garbage collection and calculating garbage collection units using a preset write unit, the problem of inconsistent GC progress is solved, achieving a balance between system performance stability and efficiency.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-04
- Publication Date
- 2026-03-24
AI Technical Summary
The existing garbage collection (GC) process suffers from slower-than-expected GC progress when faced with read retry, RAID decode, and page programming failures, increasing workload and requiring a higher GC waterline to retain empty data blocks, which impacts system performance.
The number of write blocks is determined based on the number of empty data blocks generated by the storage unit during garbage collection. The garbage collection unit is calculated with a preset write unit as the target. Garbage collection is performed after each preset write unit of data write operation is completed, balancing the consumption and generation of empty data blocks.
By matching the number of garbage collection blocks with the number of write blocks, the GC progress is ensured to be predictable, avoiding the problem of too many or too few empty data blocks and keeping the system running normally.
Smart Images

Figure CN121051035B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of memory technology, and in particular to a waste recycling control method and electronic device. Background Technology
[0002] Traditional garbage collection (GC) processes control the progress of each GC cycle by setting a GC timer. If the GC execution time exceeds this timer, the GC process ends. However, certain situations, such as read retry, RAID decoding (where writing multiple pages to storage generates a CRC code and writes both the page content and the CRC code to the storage, and retrieving the CRC code to correct errors), and page programming failure handling (where writing to storage may fail due to media limitations or voltage instability, requiring rewriting to improve success rates), increase the workload of GC. This can cause GC progress to fall short of expectations during its execution time. In such cases, a higher GC waterline is needed to retain more empty data blocks to prevent issues caused by insufficient empty data blocks due to slower GC progress. However, retaining more empty data blocks can negatively impact system performance. Summary of the Invention
[0003] The technical problem to be solved by the present invention is to provide a garbage collection control method and electronic device that can balance the consumption and generation of empty data blocks and avoid the problem of too many empty data blocks being retained or too few empty data blocks.
[0004] In a first aspect, the present invention provides a waste recycling control method, comprising:
[0005] The number of write blocks is determined based on the number of empty data blocks generated by the storage unit during garbage collection;
[0006] Obtain a preset write unit, and calculate the garbage collection unit corresponding to the preset write unit with the goal of matching the number of garbage collection blocks with the number of write blocks;
[0007] After each data writing operation of the preset writing unit is completed, garbage collection is completed according to the garbage collection unit.
[0008] In a second aspect, the present invention also provides an electronic device, the electronic device comprising:
[0009] One or more processors;
[0010] Storage device for storing one or more programs;
[0011] When the one or more programs are executed by the one or more processors, the one or more processors implement the garbage collection control method as provided in the first aspect.
[0012] The beneficial effects of this invention are as follows: The number of write blocks is determined based on the number of empty data blocks generated during garbage collection. If the number of empty data blocks generated by garbage collection can be balanced with the number of empty data blocks used for writing data, the normal operation of the system can be guaranteed with a lower garbage collection threshold. Therefore, garbage collection units are calculated with the goal of matching the number of garbage collection blocks with the number of write blocks. Whenever the amount of data written reaches a preset write unit, partial garbage collection is performed according to the garbage collection unit. Only after the garbage collection processing of the corresponding amount of data in the garbage collection unit is completed can the garbage collection process be exited. This ensures that the progress of each partial garbage collection is consistent with expectations, thereby controlling the completion of a complete garbage collection process while matching the speed of empty data block usage and generation during the generation of a fixed amount of host data. Furthermore, since the garbage collection progress is predictable, the problem of insufficient empty data blocks can be avoided without setting a high garbage collection threshold. This invention can balance the consumption and generation of empty data blocks, avoiding the problems of retaining too many or too few empty data blocks. Attached Figure Description
[0013] Figure 1 A flowchart of a waste recycling control method provided by the present invention;
[0014] Figure 2 This is a schematic diagram of T2T data migration according to Embodiment 1 of the present invention;
[0015] Figure 3 This is a schematic diagram of the structure of an electronic device provided by the present invention. Detailed Implementation
[0016] To explain the technical content, objectives, and effects of the present invention in detail, the following description is provided in conjunction with the embodiments and accompanying drawings.
[0017] Before discussing the exemplary embodiments in more detail, it should be noted that some exemplary embodiments are described as processes or methods depicted as flowcharts. Although the flowcharts describe the steps as being processed sequentially, many of these steps may be performed in parallel, concurrently, or simultaneously. Furthermore, the order of the steps may be rearranged. A process may be terminated when its operation is complete, but it may also have additional steps not included in the figures. A process may correspond to a method, function, procedure, subroutine, subprogram, etc.
[0018] Furthermore, the terms "first," "second," etc., may be used herein to describe various directions, actions, steps, or elements, but these directions, actions, steps, or elements are not limited by these terms. These terms are only used to distinguish one direction, action, step, or element from another. For example, without departing from the scope of this application, first information may be referred to as second information, and similarly, second information may be referred to as first information. Both first information and second information are information, but they are not the same information. The terms "first," "second," etc., should not be construed as indicating or implying relative importance or implicitly specifying the number of indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature. In the description of this invention, "a plurality of" means at least two, such as two, three, etc., unless otherwise explicitly specified.
[0019] Please refer to Figure 1 A waste recycling control method, comprising:
[0020] The number of write blocks is determined based on the number of empty data blocks generated by the storage unit during garbage collection;
[0021] Obtain a preset write unit, and calculate the garbage collection unit corresponding to the preset write unit with the goal of matching the number of garbage collection blocks with the number of write blocks;
[0022] After each data writing operation of the preset writing unit is completed, garbage collection is completed according to the garbage collection unit.
[0023] As described above, the beneficial effects of this invention are as follows: The number of write blocks is determined based on the number of empty data blocks generated by the storage unit during garbage collection. If the number of empty data blocks generated by garbage collection can be balanced with the number of empty data blocks used for writing data, the normal operation of the system can be guaranteed with a lower garbage collection threshold. Therefore, garbage collection units are calculated with the goal of matching the number of garbage collection blocks with the number of write blocks. Whenever the amount of data written reaches a preset write unit, partial garbage collection is performed according to the garbage collection unit. Only after the garbage collection processing of the corresponding amount of data in the garbage collection unit is completed can the garbage collection process be exited. This ensures that the progress of each partial garbage collection is consistent with expectations, thereby controlling the completion of a complete garbage collection process while matching the speed of empty data block usage and generation during the generation of a fixed amount of host data. Furthermore, since the garbage collection progress is predictable, the problem of insufficient empty data blocks can be avoided without setting a high garbage collection threshold. This invention can balance the consumption and generation of empty data blocks, avoiding the problems of retaining too many empty data blocks or having too few empty data blocks.
[0024] Further, the step of obtaining a preset write unit and calculating the garbage collection unit corresponding to the preset write unit with the goal of matching the number of garbage collection blocks with the number of write blocks includes:
[0025] Obtain the number of pages per unit in a single data block within the storage unit;
[0026] The number of write pages is determined based on the number of write blocks and the number of unit pages, and the number of garbage collection pages is determined based on the number of garbage collection blocks and the number of unit pages;
[0027] The total number of write operations is calculated based on the number of pages written and the preset write unit.
[0028] The number of garbage recycling pages and the total number of writes are used to calculate the garbage recycling unit.
[0029] As described above, based on the preset write unit, the total number of writes required to complete the write process corresponding to the number of write blocks is calculated in units of pages. If the number of garbage collection blocks needs to match the number of write blocks, then the number of partial garbage collections corresponds to the total number of writes. To complete the recycling of data blocks corresponding to the number of garbage collection blocks within the total number of writes, the determined number of garbage collection blocks is converted into the number of garbage collection pages, thus obtaining the number of pages to be recycled each time partial garbage collection is performed, i.e., the garbage collection unit. In this way, after each data write operation of the preset write unit, garbage collection is performed according to the garbage collection unit, thereby balancing the use and generation of empty data blocks.
[0030] Furthermore, determining the number of write blocks based on the number of empty data blocks generated by the storage unit during garbage collection includes:
[0031] If the number of empty data blocks is greater than or equal to 1, then the number of empty data blocks is used as the number of write blocks;
[0032] If the number of empty data blocks is less than 1, then 1 data block is used as the number of write blocks.
[0033] As described above, due to different garbage collection modes, some garbage collection modes can directly generate empty data blocks, while others cannot. Therefore, for garbage collection modes that can directly generate empty data blocks, the number of empty data blocks generated is used as the number of write blocks; while for garbage collection modes that cannot directly generate empty data blocks, one data block is used as the number of write blocks, and the number of garbage collection cycles required to free up one data block is calculated.
[0034] Further, before determining the number of write blocks based on the number of empty data blocks generated by the storage unit during garbage collection, the process includes:
[0035] If the number of data blocks in the first mode storage unit is greater than or equal to a preset threshold, then the data migration direction during garbage collection is from the data block in the first mode storage unit to the data block in the first mode storage unit.
[0036] If the number of data blocks in the first storage unit mode is less than a preset threshold, the data migration direction during garbage collection is from the data blocks in the second storage unit to the data blocks in the first storage unit.
[0037] As described above, the garbage collection mode to be performed is determined based on the number of data blocks in the first mode storage unit. If the number of data blocks in the first mode storage unit is sufficient, it means that there is no need to generate new first mode storage units, and the data migration direction for garbage collection is to migrate the data blocks in the first mode storage unit to the data blocks in another first mode storage unit. If the number of data blocks in the first mode storage unit is insufficient, it means that there is a need to generate new data blocks in the first mode storage unit, so the data migration direction during garbage collection is from the data blocks in the second mode storage unit to the data blocks in the first mode storage unit.
[0038] Furthermore, it also includes:
[0039] If the data migration direction is from data block of the first mode storage unit to data block of the first mode storage unit, then the number of write blocks is determined to be 1, the average effective data volume of the first mode storage unit is calculated, and the number of garbage collections required to release an empty data block is obtained based on the average effective data volume.
[0040] The number of garbage collection blocks that matches the number of write blocks is obtained based on the number of garbage collections and the number of blocks released in each garbage collection.
[0041] As described above, if data migration is completed between two data blocks in the first-mode storage unit, since the two data blocks have the same mode, an empty data block may not be generated after the data migration is completed. In this case, the average effective data volume of the first-mode storage unit is calculated, that is, the average effective data volume in each data block is predicted. Then, based on the average effective data volume, the number of garbage collections required to release an empty data block is obtained. That is, one garbage collection can complete the migration of one data block. The number of garbage collections required to gather all the effective data together to obtain an empty data block is calculated. Based on the determined number of garbage collections and the number of blocks released by each garbage collection, the number of garbage collection blocks required to complete the garbage collection for an empty data block is obtained. In this way, when writing a data block, garbage collection can also free up a data block, thereby balancing the use and generation of empty data blocks.
[0042] Further, calculating the average effective data volume of the first mode storage unit includes:
[0043] Average effective data volume = total written data volume / maximum data volume of a single data block in the first mode storage unit × number of available data blocks.
[0044] As described above, the average effective data volume is calculated based on the ratio of the total amount of written data to the total maximum amount of data stored in all data blocks in the first mode storage unit. Since the garbage collection process cannot specifically control which data block it is executed on, the ratio of the total amount of written data to the total amount of data stored in the first mode storage unit is considered as the ratio of effective data in each data block in a way that the whole represents the part. This enables the subsequent calculation of the number of garbage collections that need to be performed.
[0045] Furthermore, the step of determining the number of garbage collections required to release an empty data block based on the average effective data volume includes:
[0046] The garbage collection frequency factor is 1 ÷ (1 - percentage of average effective data).
[0047] As described above, when a single garbage collection cannot free up a complete empty data block, the number of garbage collections required to free up an empty data block can be estimated by approximation. Thus, even when it is not possible to directly correlate the empty data blocks generated by garbage collection with the empty data blocks required for writing data, the amount of garbage collection and the amount of data written can be approximately calculated.
[0048] Further, the step of obtaining a preset write unit and calculating the garbage collection unit corresponding to the preset write unit with the goal of matching the number of garbage collection blocks with the number of write blocks includes:
[0049] Waste recycling unit = (P1 × Factor) ÷ (P2 / X);
[0050] In the formula, P1 represents the number of first unit pages of a single data block in the first mode storage unit; P2 represents the number of second unit pages of a single data block in the second mode storage unit; and X represents the preset write unit.
[0051] As described above, a single garbage collection involves moving data from one data block to another. Therefore, multiplying this by the number of executions yields the total number of pages that need to be moved. Data writing involves writing to a second-mode storage unit, so the number of times a second-mode storage unit needs to be filled is the same as the number of partial garbage collections in a single garbage collection process. Dividing the total number of pages that need to be moved by the number of partial garbage collections yields the number of garbage collection units that need to be completed each time partial garbage collection is executed. After each preset number of data write operations is completed, garbage collection is performed according to the garbage collection units, thereby achieving a balance between the generation and use of empty data blocks.
[0052] Furthermore, it also includes:
[0053] If the data migration direction is from the data block of the second mode storage unit to the data block of the first mode storage unit, then the number of write blocks is determined to be the number of empty data blocks n generated after the migration;
[0054] Obtain the number of garbage collection blocks m corresponding to the number of written blocks n;
[0055] Calculate the waste recycling unit = (P1×m) ÷ (P2×n ÷X).
[0056] As described above, if the data migration direction is from the data block of the second-mode storage unit to the data block of the first-mode storage unit, the storage capacities of the two are not the same, so n empty data blocks will be generated. Therefore, every time data is written to n empty data blocks, garbage collection needs to be performed to generate n empty data blocks. Thus, for the writing process, the number of writes required to fill n empty data blocks with the preset write unit is (P2×n÷X). During this number of writes, data needs to be moved to a data block of the first-mode storage unit. Therefore, the amount of data to be garbage collected is P1. Dividing P1 by the number of writes gives the garbage collection unit for each partial garbage collection. That is, after each preset write unit of data writing operation is completed, garbage collection is performed according to the garbage collection unit to achieve a balance between the generation and use of empty data blocks.
[0057] Furthermore, the method also includes:
[0058] When a data write instruction is received, the data to be written is written into the data block of the second mode storage unit.
[0059] As described above, when a data write instruction is received, the data to be written is written to the second-mode storage unit, and then the first-mode storage unit is used through data migration, thereby balancing the system's write efficiency and storage requirements.
[0060] Furthermore, the first mode storage unit is TLC, and the second mode storage unit is SLC.
[0061] As described above, a single TLC block can store a large amount of data, but its read and write speed is relatively slow; a single SLC block can store a smaller amount of data, but its read and write speed is fast. Therefore, data is written to SLC by default during the writing process, which can process the writing process faster. Then, garbage collection is used to balance the use of TLC blocks and SLC blocks, taking into account both the efficiency and stability of the system.
[0062] The present invention also provides an electronic device, the electronic device comprising:
[0063] One or more processors;
[0064] Storage device for storing one or more programs;
[0065] When the one or more programs are executed by the one or more processors, the one or more processors implement the garbage collection control method as described above.
[0066] Example 1
[0067] Please refer to Figures 1 to 2 Embodiment 1 of the present invention is a garbage collection control method applicable to non-volatile storage devices. Existing non-volatile storage devices contain data blocks with different storage unit modes, such as SLC (Single-Level Cell), MLC (Multi-Level Cell), TLC (Triple-Level Cell), and QLC (Quad-Level Cell). In this embodiment, garbage collection of SLC and TLC data blocks is used as an example. Furthermore, the size of each page in both SLC and TLC data blocks is 4KB. Figure 2 As shown, the method in this embodiment includes the following steps:
[0068] S1. Determine the number of write blocks based on the number of empty data blocks generated by the storage unit during garbage collection.
[0069] In one alternative implementation, S1 includes the steps S11 to S12.
[0070] S11. If the number of empty data blocks is greater than or equal to 1, then the number of empty data blocks shall be used as the number of write blocks.
[0071] S12. If the number of empty data blocks is less than 1, then 1 data block is used as the number of write blocks.
[0072] In one alternative implementation, S1 is preceded by S01 and S02.
[0073] S01. If the number of data blocks in the first-mode storage unit is greater than or equal to a preset number threshold, the data migration direction during garbage collection is from the data blocks in the first-mode storage unit to the data blocks in the first-mode storage unit.
[0074] S02. If the number of data blocks in the first storage unit mode is less than the preset number threshold, the data migration direction during garbage collection is from the data blocks in the second-mode storage unit to the data blocks in the first-mode storage unit. In this embodiment, the data migration direction is determined according to the number of TLC data blocks.
[0075] 1. Assume that writing data to fill the entire capacity sequentially requires 100 TLC data blocks (the effective data ratio of each data block is 100%, and being fully filled can meet the usage requirements);
[0076] 2. In actual operation, the file system will write duplicate LBAs (Logical Block Addressing), for example, modify the file content. In this process, the original physical data block is usually not directly overwritten, but new data blocks will be generated, so the effective data in the old data block will decrease (the effective data ratio is not 100%);
[0077] 3. Set the T2T waterline = the preset multiple of the TLC data blocks required to write data to fill the entire capacity sequentially. For example, if the preset multiple is 1.05, then the number of TLC data blocks required in step 1 above × (1.05) = 100 × 1.05 = 105;
[0078] 4. When the number of TLC data blocks ≥ the T2T waterline, it means that the effective data ratio of some TLC data blocks is not 100%, and then T2T GC (garbage collection of TLC, that is, the data migration direction is from the TLC data blocks to the TLC data blocks) will be executed;
[0079] 5. When the number of TLC data blocks < the T2T waterline, S2T GC (garbage collection of SLC, that is, the data migration direction is from the SLC data blocks to the TLC data blocks) will be executed.
[0080] In this way, through the above settings 1 to 5, when the system mimics SLC particles with TLC particles, if the number of TLC particles is sufficient, T2T is executed, and if the number of TLC particles is insufficient, S2T is executed, so as to ensure that there are enough empty data blocks in the system for users to write data.
[0081] S2: Obtain a preset writing unit, and calculate a garbage collection unit corresponding to the preset writing unit with the goal of matching the number of garbage collection blocks with the number of the writing blocks.
[0082] In one alternative implementation, S2 includes the steps S21 to S24.
[0083] S21. Obtain the number of unit pages of a single data block in the storage unit.
[0084] S22. Determine the number of write pages based on the number of write blocks and the number of unit pages, and determine the number of garbage collection pages based on the number of garbage collection blocks and the amount of data per unit page.
[0085] S23. Calculate the total number of writes based on the number of pages to be written and the preset write unit.
[0086] S24. Calculate the garbage collection unit based on the number of garbage collection pages and the total number of writes.
[0087] (1) When the data migration direction is S2T, that is, the source block of the data migration is an SLC data block and the target block is a TLC data block, at least 3 source blocks are released and 1 target block is generated during execution, so 3-1=2 empty data blocks will be generated. In order to avoid the increase in write performance caused by GC, 1 GC is completed in the process of writing 2 data blocks (that is, consuming 2 empty data blocks) to generate 2 empty data blocks. Then the number of blocks written in S1 is the number of empty data blocks that can be generated in one garbage collection, 2.
[0088] In the S2T scenario, S21 to S24 are specifically as follows:
[0089] S21. Obtain the number of first unit pages of a single data block in the first mode storage unit TLC and the number of second unit pages of a single data block in the second mode storage unit SLC.
[0090] S22. Since data is written to the second-mode storage unit, the number of written pages P2×2 is determined based on the number of written blocks and the number of second-mode pages. The correspondence between the number of garbage collection blocks and the number of written blocks is determined based on the characteristics of the source block and the target block. The number of garbage collection blocks is the amount of data that needs to be migrated to generate the number of empty data blocks corresponding to the number of written blocks, i.e., the number of blocks that need to be garbage collected, or the number of new blocks generated during migration. For example, the amount of data that needs to be collected to generate 2 empty data blocks here is the amount of data corresponding to 3 second-mode storage unit data blocks or the amount of data corresponding to 1 first-mode storage unit data block. Therefore, the number of garbage collection pages is P1.
[0091] If the source block is SLC and the target block is QLC, each garbage collection will release 4 SLC blocks, generate 1 QLC block, and produce 3 empty data blocks. The number of pages written is P2×3, and the number of garbage collection blocks is 1 QLC block. The corresponding number of garbage collection pages is P3, which is the number of the third unit page of a single data block in QLC; or the number of garbage collection pages is P2×4, and the two values are equal.
[0092] S23. Calculate the total number of writes (P2×n÷X), where X is the preset write unit.
[0093] S24. Calculate the waste recycling unit = (P1×m) ÷ (P2×n ÷X).
[0094] Assuming an SLC data block contains 900 pages and a TLC data block contains 2700 pages, then the two SLC data blocks together contain 900 × 2 = 1800 pages. Assuming that a partial garbage collection (GC) occurs every time 6 pages of data are written to the SLC data block, then 1800 pages can undergo 1800 / 6 = 300 partial GCs. Each partial GC moves 2700 / 300 = 9 pages of valid data to the target block (TLC).
[0095] In other words, each S2T GC will generate at least two empty data blocks, so one S2T GC must be completed while writing two data blocks. If a partial GC is performed every X pages of host data, then each partial GC requires moving 1.5X pages of valid data to the target block.
[0096] Therefore, when the data migration direction is S2T, the amount of data migrated is P1 / (2P2 / X)=(P1 / 2P2)X, where X is the target data amount; P1 is the number of pages in the TLC data block, and P2 is the number of pages in the SLC data block.
[0097] (2) When the data migration direction is T2T, that is, the source block of the data migration is the data block of TLC and the target block is the data block of TLC, at least 1 source block is released and 1 target block is generated during execution. In a single GC, it is very likely that no empty data block will be released. Therefore, in step S1, the number of blocks to be written is determined to be 1.
[0098] In a T2T scenario, steps S21 to S24 are as follows:
[0099] S21. Obtain the number of first unit pages of a single data block in the first mode storage unit TLC and the number of second unit pages of a single data block in the second mode storage unit SLC;
[0100] S22. Since data is written to the second-mode storage unit, the number of write pages P2 is determined based on the number of write blocks and the number of second-unit pages. Then, the number of garbage collections required for the empty data block corresponding to the number of write blocks is calculated: Factor = 1 ÷ (1 - percentage of average effective data). Since each garbage collection typically recovers one data block, the number of garbage collections equals the number of garbage collection blocks. When one write block is completed, the number of garbage collection blocks also needs to be recovered to generate one empty data block. The number of garbage collection pages (P1 × Factor) is determined based on the number of garbage collection blocks and the number of first-unit pages. Because a single garbage collection may not release an empty data block, the percentage of average effective data in the TLC data block Y is calculated, and the number of garbage collection blocks matching the number of write blocks is calculated using Y.
[0101] S23. Calculate the total number of writes (P2 / X), where X is the preset write unit.
[0102] S24. Calculate the waste recycling unit = (P1 × Factor) ÷ (P2 / X).
[0103] In the above formula, the average effective data volume = total written data volume / maximum data volume of a single data block in the first mode storage unit × number of available data blocks. For example, assuming each TLC data block has 2304 pages, 4 planes, and each plane is 16KB, then the maximum data volume of each TLC data block (in 4KB units) is 2304 × 4 × (16 / 4) = 36864. When a write command occurs, the written data volume (in 4KB units) is accumulated, thus calculating the total written data volume. However, if data within the LBA range is written (i.e., data that has been written before), the written data volume is not accumulated. Finally, the average effective data volume percentage Y is calculated using the following formula: Y = total written data volume / maximum data volume of the TLC data block × number of normal blocks, where both the total written data volume and the maximum data volume of the TLC data block are in 4KB units.
[0104] like Figure 2 As shown, assuming the average effective data volume of a TLC data block is 80%, 1 / (1-80%) = 5, meaning that 5 T2T GC cycles are needed to release one empty data block. Figure 2 In a TLC (Time-to-Limit) data block, 80% of the data is valid and 20% is reclaimable. This is transformed by T2T GC. Figure 2 The four TLC data blocks contain 100% valid data, with one TLC data block completely empty. Figure 2The shaded portion represents the proportion of valid data, while the unshaded portion represents free space or reclaimable data. Therefore, five T2T GC cycles are needed during the writing of one data block (i.e., consuming one empty data block) to ensure the number of empty data blocks does not decrease. In this embodiment, this variable is defined as Factor, i.e., Factor = 1 / (1-Y). Furthermore, if the calculated Factor is not an integer, it is rounded up.
[0105] Assuming an SLC data block contains 900 pages and a TLC data block contains 2700 pages, every time 6 pages of data are written to the SLC data block, there is a chance to perform a partial GC. Therefore, 900 pages can perform 900 / 6=150 partial GCs. Each partial GC moves 2700 / 150×Factor=18×5=90 pages of valid data to the target block (TLC).
[0106] In other words, performing a T2T GC may not release empty data blocks. In this case, we need to calculate the average percentage of valid data in the TLC blocks, Y, and then calculate Factor = 1 / (1-Y) to determine how many T2T GCs are needed to release one empty data block. If a partial GC is performed every X pages of host data written, then each partial GC requires moving 3 × Factor × X pages of valid data to the target block.
[0107] Therefore, when the data migration direction is T2T, the amount of data migrated is P1 / (P2 / X)×Factor=(P1 / P2)X×(1 / (1-Y)), where Y is the average percentage of effective data in the TLC data block.
[0108] S3. After each data writing operation of the preset writing unit is completed, garbage collection is completed according to the garbage collection unit.
[0109] In this embodiment, when a host data write instruction is received, the host data is written into the SLC data block. Whenever the amount of data written reaches a preset target data amount, a data migration operation in garbage collection is performed according to the data migration direction and the amount of data to be migrated, that is, the valid data in the source block that has been marked for deletion is migrated to the target block where there is a free space.
[0110] In this embodiment, whenever the amount of data written reaches the target amount of data, the amount of data to be moved for each partial GC is determined based on the data migration direction and the target amount of data. Only after the processing of these amounts of data is completed can the GC be left, making the GC progress predictable. This avoids the problem of insufficient empty data blocks without setting a high GC waterline.
[0111] Example 2
[0112] Please refer to Figure 3 Embodiment two of the present invention is: an electronic device 300, the electronic device 300 comprising:
[0113] One or more processors 302;
[0114] Memory 301 is used to store one or more programs;
[0115] When the one or more programs are executed by the one or more processors 302, the one or more processors 302 implement the various processes of the garbage collection control method in the above embodiments and achieve the same technical effect. To avoid repetition, they will not be described again here.
[0116] Example 3
[0117] This embodiment is a computer-readable storage medium corresponding to the above embodiments, on which a computer program is stored. When the program is executed by a processor, it implements the various steps of the garbage collection control method in the above embodiments and can achieve the same technical effect, which will not be repeated here.
[0118] In summary, the garbage collection control method and electronic device provided by this invention determine the number of write blocks based on the generation of empty blocks during the garbage collection process. It calculates the number of garbage collection blocks required to complete the write process, aiming to match the number of garbage collection blocks with the number of write blocks. Furthermore, it obtains a preset write unit, maps the garbage collection process corresponding to the number of garbage collection blocks to each write operation of the preset write unit, and calculates the garbage collection unit. Each time data corresponding to the preset write unit is written, the garbage collection unit's amount is executed. This generates new empty blocks at a near-perfect rate while data is being written and occupying empty blocks, thus avoiding the problem of empty block exhaustion. For garbage collection types that can generate empty data blocks, the number of generated empty data blocks is directly used as the number of write blocks for calculation. For garbage collection types that cannot directly generate empty data blocks, the number of garbage collection operations required to free up one data block is calculated approximated to complete the calculation. This invention can balance the consumption and generation of empty data blocks, avoiding the problems of too many or too few empty data blocks.
[0119] In the embodiments provided in this application, it should be understood that the disclosed methods, apparatuses, computer-readable storage media, and electronic devices can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative. For instance, the division of modules is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple components or modules may be combined or integrated into another device, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between devices, components, or modules may be electrical, mechanical, or other forms.
[0120] The components described as separate parts may or may not be physically separate. The components shown as components may or may not be physical modules; that is, they may be located in one place or distributed across multiple network modules. Some or all of the components can be selected to achieve the purpose of this embodiment according to actual needs.
[0121] Furthermore, the functional modules in the various embodiments of the present invention can be integrated into one processing module, or each component can exist physically separately, or two or more modules can be integrated into one module. The integrated modules described above can be implemented in hardware or as software functional modules.
[0122] If the integrated module is implemented as a software functional module and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0123] It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that the present invention is not limited to the described order of actions, because according to the present invention, some steps can be performed in other orders or simultaneously. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are preferred embodiments, and the actions and modules involved are not necessarily essential to the present invention.
[0124] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments.
[0125] The above description is merely an embodiment of the present invention and does not limit the patent scope of the present invention. Any equivalent modifications made based on the content of the present invention specification and drawings, or direct or indirect applications in related technical fields, are similarly included within the patent protection scope of the present invention.
Claims
1. A waste recycling control method, characterized in that, include: The number of write blocks is determined based on the number of empty data blocks generated by the storage unit during garbage collection; Obtain a preset write unit, and calculate the garbage collection unit corresponding to the preset write unit with the goal of matching the number of garbage collection blocks with the number of write blocks; After each data writing operation of the preset writing unit is completed, garbage collection is completed according to the garbage collection unit. Before determining the number of write blocks based on the number of empty data blocks generated by the storage unit during garbage collection, the following steps are included: If the number of data blocks in the first mode storage unit is greater than or equal to a preset threshold, then the data migration direction during garbage collection is from the data block in the first mode storage unit to the data block in the first mode storage unit. If the number of data blocks in the first storage unit mode is less than a preset threshold, the data migration direction during garbage collection is from the data blocks in the second storage unit to the data blocks in the first storage unit. If the data migration direction is from data block of the first mode storage unit to data block of the first mode storage unit, then the number of write blocks is determined to be 1, the average effective data volume of the first mode storage unit is calculated, and the number of garbage collections required to release an empty data block is obtained based on the average effective data volume. The number of garbage collection blocks that matches the number of write blocks is obtained based on the number of garbage collections and the number of blocks released in each garbage collection. The calculation of the average effective data volume of the first mode storage unit includes: Average effective data volume = total written data volume / maximum data volume of a single data block in the first mode storage unit × number of available data blocks; The number of garbage collections required to release an empty data block based on the average effective data volume includes: Waste collection frequency Factor = 1 ÷ (1 - percentage of average valid data); The step of obtaining the preset write unit and calculating the garbage collection unit corresponding to the preset write unit with the goal of matching the number of garbage collection blocks with the number of write blocks includes: Waste recycling unit = (P1 × Factor) ÷ (P2 / X); Also includes: If the data migration direction is from the data block of the second mode storage unit to the data block of the first mode storage unit, then the number of write blocks is determined to be the number of empty data blocks n generated after the migration; Obtain the number of garbage collection blocks m corresponding to the number of written blocks n; Calculate the waste recycling unit = (P1 × m) ÷ (P2 × n ÷ X); In the formula, P1 represents the number of first unit pages of a single data block in the first mode storage unit; P2 represents the number of second unit pages of a single data block in the second mode storage unit; and X represents the preset write unit.
2. The waste recycling control method according to claim 1, characterized in that, The step of obtaining the preset write unit and calculating the garbage collection unit corresponding to the preset write unit with the goal of matching the number of garbage collection blocks with the number of write blocks includes: Obtain the number of pages per unit in a single data block within the storage unit; The number of write pages is determined based on the number of write blocks and the number of unit pages, and the number of garbage collection pages is determined based on the number of garbage collection blocks and the number of unit pages; The total number of write operations is calculated based on the number of pages written and the preset write unit. The number of garbage recycling pages and the total number of writes are used to calculate the garbage recycling unit.
3. The waste recycling control method according to claim 1, characterized in that, The step of determining the number of write blocks based on the number of empty data blocks generated by the storage unit during garbage collection includes: If the number of empty data blocks is greater than or equal to 1, then the number of empty data blocks is used as the number of write blocks; If the number of empty data blocks is less than 1, then 1 data block is used as the number of write blocks.
4. The waste recycling control method according to claim 1, characterized in that, The method further includes: When a data write instruction is received, the data to be written is written into the data block of the first mode storage unit.
5. The waste recycling control method according to claim 1, characterized in that, The first mode storage unit is TLC, and the second mode storage unit is SLC.
6. An electronic device, characterized in that, The electronic device includes: One or more processors; Storage device for storing one or more programs; When the one or more programs are executed by the one or more processors, the one or more processors implement the method as described in any one of claims 1-5.
Citation Information
Patent Citations
Method for managing dynamic internal memory base on discontinuous page
CN101231619A
Method for separating garbage recovering data from user data in solid-state disc
CN108563586A