Mapping table garbage collection method, recycling device, storage device and electronic device
By allocating target and spare mapping table blocks in the flash memory device and optimizing the mapping table garbage collection process, the problem of frequent and time-consuming mapping table garbage collection is solved, and the speed of writing data and the utilization efficiency of mapping table blocks are improved.
Patent Information
- Application Number
- CN202510672007.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-23
- Publication Date
- 2025-09-26
- Estimated Expiration
- 2045-05-23
AI Technical Summary
In the prior art, the mapping table garbage collection method and the user data garbage collection method have significant differences in triggering conditions, complexity and performance impact, resulting in frequent and time-consuming mapping table garbage collection, which affects the host's data writing speed.
Allocate target and spare target blocks from unfilled memory map blocks, select appropriate source blocks for map garbage collection, programmatically calculate ratios, and optimize the garbage collection process using greedy, cost-effective, or window algorithms.
It avoids frequent mapping table garbage collection, reduces map GC time, maintains the speed of writing data, and ensures that there are sufficient number of available mapping table blocks.
Smart Images

Figure CN120196558B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of storage technology, and in particular to a mapping table garbage collection method, a mapping table garbage collection device, a storage device and an electronic device. Background Art
[0002] The read and write processes of solid-state storage devices using flash memory (Nand Flash) differ fundamentally from those of traditional HDDs. Flash memory cannot be overwritten (it must be erased before writing). Therefore, when the host requests an update of user data, it is not directly overwritten. Instead, a mapping table is required to record the physical location of the data. When data at the same logical address is overwritten, the physical location recorded in the corresponding mapping table will change. Therefore, during product use, a large amount of mapping table data is stored in dedicated blocks allocated by the controller ("mapping table blocks"). Some of this mapping table data is valid, while others are invalid. When invalid mapping table data becomes excessive, mapping table garbage collection (MAP garbage collection) is performed to clean it up. This involves programming (writing data) the valid mapping table data from the source mapping table block to the target mapping table block. After completion, the source mapping table block is released and can be used again.
[0003] The general map gc process will start mapgc after the number of used mapping table blocks reaches a certain threshold, such as Figure 1 As shown, a source block is selected and the valid mapping table data in it is programmed into the new target mapping table block. After that, the source block is released and the total number of used mapping table blocks is reduced by one. After the target mapping table block is full, the number of used mapping table blocks will reach the set threshold again, and map garbage collection (GC) will be frequently initiated, and the number of available target mapping table blocks will only be maintained at a low level. On the other hand, if the number of valid mapping tables in the selected source block is relatively high, performing a map garbage collection (GC) will take a long time (if the number of valid mapping tables scanned is high, the target mapping table block will be programmed multiple times). If this happens during the write process, the host's data write speed will be greatly reduced due to the bandwidth occupied by map garbage collection (GC).
[0004] Although there are garbage collection methods for user data in the prior art, there are significant differences between mapping table garbage collection and user data garbage collection in terms of triggering conditions, complexity, performance impact, and implementation mechanisms. Therefore, user data garbage collection methods are generally not suitable for mapping table garbage collection. Summary of the Invention
[0005] The purpose of this patent is to provide a mapping table garbage collection method, a mapping table garbage collection device, a storage device and an electronic device that can solve the above technical problems.
[0006] To this end, a first aspect of the present invention provides a mapping table garbage collection method, comprising:
[0007] Allocating a target mapping table block and a spare target mapping table block from a plurality of blocks of a memory mapping table that has not been fully written, wherein the target mapping table block is used to program mapping table data generated from data update, and the spare target mapping table block is used to program valid data on a source block of a mapping table garbage collection;
[0008] Select the source block to be garbage collected for the mapping table;
[0009] Calculate the total number of valid mapping tables in the selected source block;
[0010] Calculating a ratio of the programming target mapping table block to the spare target mapping table block based on the total number of valid mapping tables and the number of valid mapping tables that can be programmed in the target mapping table block;
[0011] Mapping table garbage collection is performed based on the ratio.
[0012] In a specific embodiment, allocating the target mapping table block and the spare target mapping table block from the plurality of blocks of the storage mapping table that are not fully written includes:
[0013] The target mapping table blocks and the spare target mapping table blocks are allocated from a plurality of blocks of the memory mapping table that have not been written.
[0014] In a specific embodiment, selecting a source block to be subjected to mapping table garbage collection includes:
[0015] At least one source block is selected based on the number of valid mapping tables that can still be programmed in the spare target mapping table block, wherein the total amount of valid mapping tables in the selected at least one source block is less than the number of valid mapping tables that can still be programmed.
[0016] In a specific embodiment, selecting at least one source block includes:
[0017] Sort all source blocks based on the number of valid mapping tables in each source block;
[0018] N source blocks containing the least number of valid mapping tables are selected, wherein the total number of valid mapping tables in the N source blocks is less than the number of valid mapping tables that can still be programmed, and N is a natural number greater than or equal to 2.
[0019] In a specific embodiment, the calculating the ratio of the programming target mapping table blocks to the spare target mapping table blocks based on the total number of valid mapping tables includes:
[0020] Determine a number k1 of programming times for the target mapping table block based on the number of valid mapping tables that can be programmed in the allocated target mapping table block and the number of valid mapping tables that can be programmed per page;
[0021] Determine the number of times k2 to program the spare mapping table block based on the total number of valid mapping tables in the selected source block and the number of valid mapping tables that can be programmed per page;
[0022] The ratio of the programming target mapping table block to the spare target mapping table block is calculated as [k1 / k2]:1, where [] represents rounding down.
[0023] In a specific embodiment, performing mapping table garbage collection based on the ratio includes:
[0024] Program [k1 / k2] target mapping table blocks, perform one mapping table garbage collection, and program one spare target mapping table block.
[0025] In a specific embodiment, performing a mapping table garbage collection to program a spare target mapping table block includes:
[0026] The mapping table garbage collection is performed using a greedy algorithm, a cost-effective algorithm or a window algorithm.
[0027] A second aspect of the present invention provides a mapping table garbage collection device, comprising:
[0028] an allocation module, configured to allocate a target mapping table block and a spare target mapping table block from a plurality of blocks of a storage mapping table that has not been fully written, wherein the target mapping table block is used to program mapping table data generated from data update, and the spare target mapping table block is used to program valid data on a source block of a mapping table garbage collection;
[0029] A selection module, used to select source blocks to be garbage collected in the mapping table;
[0030] A first calculation module, configured to calculate the total number of valid mapping tables in the selected source block;
[0031] a second calculation module, configured to calculate a ratio of programming target mapping table blocks to spare target mapping table blocks based on the total number of valid mapping tables;
[0032] A mapping table garbage collection module is configured to perform mapping table garbage collection based on the ratio.
[0033] In a specific embodiment, the allocation module is further configured to allocate the target mapping table blocks and the spare target mapping table blocks from a plurality of blocks of the storage mapping table that have not been written.
[0034] A third aspect of the present invention provides a storage device comprising a controller and a flash memory module, wherein the flash memory module comprises a program, and when the program is executed by the controller, the method described in the first aspect of the present invention is implemented.
[0035] A fourth aspect of the present invention provides an electronic device comprising a host and the storage device according to the third aspect of the present invention.
[0036] Compared with the prior art, the present invention has the following beneficial effects:
[0037] The method of the present invention can avoid frequent map GCs during map GCs, and each map GC entry consumes a short time, thus preventing the write speed from being significantly reduced during the map GC. Furthermore, after completing the map GC, several source blocks can be released, ensuring a sufficient number of available mapping table blocks. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] In order to more clearly illustrate the specific implementation of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for the specific implementation or the description of the prior art.
[0039] Figure 1 is a schematic diagram of mapping table garbage collection according to the prior art;
[0040] Figure 2 is a schematic diagram of a storage device according to an embodiment of the present invention;
[0041] Figure 3 is a flowchart of a mapping table garbage collection method according to one embodiment of the present invention;
[0042] Figure 4 is a schematic diagram of mapping table garbage collection according to one embodiment of the present invention;
[0043] Figure 5 is a flowchart of selecting a source block according to one embodiment of the present invention;
[0044] Figure 6 is a flow chart for calculating a programming ratio according to one embodiment of the present invention;
[0045] Figure 7 2 is a schematic diagram of a mapping table garbage collection device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0046] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention more clear, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention.
[0047] Figure 2 Schematic diagram of a storage device 12 according to an embodiment of the present invention. The storage device 12 includes a flash memory module 125 and a flash memory controller 120, and the flash memory controller 120 is used to access the flash memory module 125. According to this embodiment, the flash memory controller 120 includes a processor, control logic, buffer storage, and interface logic. The processor is used to execute program code to control access to the flash memory module. Typically, the flash memory module includes a plurality of flash memory chips, and each flash memory chip includes a plurality of blocks, and the flash memory controller erases data on the flash memory module in units of blocks. In addition, a block can record a specific number of data pages, wherein the flash memory controller writes data to the flash memory module in units of data pages. In one example, the flash memory module is a 3D NAND-type flash module.
[0048] The flash memory controller, which executes program code via a processor, can utilize its internal components to perform various control operations, such as controlling access operations to the flash memory module (particularly access operations to at least one block or at least one data page) using control logic, performing required buffering operations using a buffer memory, and communicating with the host device 10 using interface logic. The buffer memory is implemented as random access memory (RAM). For example, the buffer memory can be static random access memory (SRAM), but the present invention is not limited thereto.
[0049] In one embodiment, the storage device 12 may be a portable memory device (e.g., a memory card compliant with SD / MMC, CF, MS, or XD standards), and the host 10 may be an electronic device connectable to the storage device, such as a mobile phone, a laptop computer, a desktop computer, a driving recorder, etc. In another embodiment, the storage device 12 may be a solid-state drive or an embedded storage device compliant with Universal Flash Storage (UFS) or Embedded Multi Media Card (EMMC) specifications, and may be installed in an electronic device, such as a mobile phone, a laptop computer, or a desktop computer. In this case, the host 10 may be a processor of the electronic device.
[0050] The first aspect of the present invention provides a mapping table garbage collection method, such as Figure 3 As shown, including:
[0051] S10. Allocate a target mapping table block and a spare target mapping table block from a plurality of blocks of a storage mapping table that has not been fully written, wherein the target mapping table block is used to program mapping table data generated from a data update, and the spare target mapping table block is used to program valid data on a source block of a mapping table garbage collection.
[0052] As those skilled in the art are aware, when storing data, the storage device controller allocates some blocks from all blocks to store user data (referred to as user data blocks) and also allocates some blocks to store related mapping table data (mapping table data blocks). For example, the number of user data blocks can range from thousands to hundreds of thousands, while the number of mapping table data blocks can range from dozens to hundreds. The specific number of blocks depends on the total capacity of the NAND Flash memory, the block size, and the design of the mapping table. Similar to how user data is divided into valid user data and invalid user data, mapping table data also includes valid mapping table data and invalid mapping table data.
[0053] The present invention is different from the prior art in that a mapping table block that is not currently fully written with mapping table data is separately allocated from the mapping table data block as a backup mapping table block, which is specifically used for subsequent programming (taking over) of valid data on the source block of mapping table garbage collection; the present invention is similar to the prior art in that another mapping table block that is not currently fully written with mapping table data is still allocated as a target mapping table block, which is used for programming (taking over) mapping table data generated from user data updates.
[0054] In one example, the number of mapping table data blocks is 10, of which 5 are fully written, for example, mapping table data blocks 0 to 4. Mapping table data blocks 5 to 10 are not fully written, and the controller allocates mapping table data block 5 as a backup mapping table block and allocates mapping table data block 6 as a target mapping table block.
[0055] Those skilled in the art will appreciate that the above example uses numbers 0 to 6 for illustration, but this does not mean that the mapping table data must be stored in increasing order from number 0.
[0056] In addition, in the above example, one mapping table data block is selected as the backup mapping table block and the target mapping table block respectively. However, the present invention is not limited thereto, and multiple blocks can be selected for each.
[0057] In the above example, the backup mapping table blocks are selected from the mapping table blocks that have not been fully written. In a preferred embodiment, the target mapping table blocks and the backup target mapping table blocks are allocated from the multiple blocks of the storage mapping table that have not been written to the mapping table blocks that have not been fully written. Because the "capacity" of the mapping table blocks that have not been written to is larger than that of the partially written data, more source blocks can be used for map garbage collection at one time, thereby releasing a sufficient number of available mapping table blocks.
[0058] S12: Select a source block to be garbage collected from the mapping table.
[0059] In a specific embodiment, the source block to be garbage collected for the mapping table is selected, such as Figure 4 As shown, including:
[0060] Based on the number of valid mapping tables that can still be programmed in the spare target mapping table block, select at least one source block (selected from source blocks 1-N), wherein the total number of valid mapping tables in the selected at least one source block is less than the number of valid mapping tables that can still be programmed.
[0061] Continuing with the above example, block 5 is the backup target mapping table block, and the number of valid mapping tables that can still be programmed is 100 (remaining capacity). Blocks 0-4 are already full and are source blocks, containing 25, 25, 65, and 30 valid mapping tables, respectively. Since each of these is less than 100, any one of these blocks can be selected as a source block for garbage collection. If two blocks are selected, any combination of the two blocks can be selected, as long as the total does not exceed 100. If three blocks are selected, block 3 must be excluded based on the same principle. However, based on the above rules, four blocks cannot be selected.
[0062] In a preferred embodiment, the selecting of at least one source block is as follows: Figure 5 As shown, including:
[0063] S120, sorting all source blocks based on the number of valid mapping tables in each source block;
[0064] Continuing with the above example, we sort in the order of 0, 1, 4, and 3.
[0065] S122. Select N source blocks containing the least number of valid mapping tables, wherein the total number of valid mapping tables in the N source blocks is less than the number of valid mapping tables that can still be programmed, and N is a natural number greater than or equal to 2.
[0066] Continuing with the above example, N=2 can be selected, i.e., No. 0 and No. 1; or N=3 can be selected, i.e., No. 0, No. 1, and No. 4. In a preferred example, a larger N value is selected, i.e., N=3.
[0067] S14. Calculate the total number of valid mapping tables in the selected source block.
[0068] Continuing with the above example, when N=2, the total number of valid mapping tables in source blocks No. 0 and No. 1 is 50; when N=3, the total number of valid mapping tables in source blocks No. 0, No. 1, and No. 4 is 80.
[0069] S16 , calculating the ratio of the programming target mapping table block to the spare target mapping table block based on the total number of valid mapping tables and the number of valid mapping tables that can be programmed in the target mapping table block.
[0070] In a specific embodiment, the ratio of the programming target mapping table block to the spare target mapping table block is calculated based on the total number of valid mapping tables, such as Figure 6 As shown, including:
[0071] S160 , determining a number k1 of programming times for the target mapping table block based on the number of valid mapping tables that can be programmed in the allocated target mapping table block and the number of valid mapping tables that can be programmed per page;
[0072] Assume that the number of valid mapping tables that can be programmed in block 6 is also 100, and each page can be written with 8 mapping table data, so k1=100 / 8.
[0073] S162, determining a number k2 of programming times for the spare mapping table block based on the total number of valid mapping tables in the selected source block and the number of valid mapping tables that can be programmed per page;
[0074] Continuing with the above example, the total number of valid mapping tables for pages 0, 1, and 4 is 80 (when N=3), and 8 mapping table data can be written per page, so k2 = 80 / 8. In another example, the total number of valid mapping tables for pages 0 and 1 is 50 (when N=2), and 8 mapping table data can be written per page, so k2 = 50 / 8.
[0075] S164 , calculating the ratio of the programming target mapping table block to the spare target mapping table block as [k1 / k2]:1, where [] represents rounding down.
[0076] Continuing with the above example, [100 / 80]:1 = 1:1. In the other example above (N=2), [100 / 50]:1 = 2:1.
[0077] S18. Perform mapping table garbage collection based on the ratio.
[0078] In a specific embodiment, performing mapping table garbage collection based on the ratio includes:
[0079] Program [k1 / k2] target mapping table blocks, perform one mapping table garbage collection, and program one spare target mapping table block.
[0080] In the example above where N=3, the target mapping table block is programmed once and the mapping table garbage collection is performed once, i.e., the spare target mapping table block is programmed once. In the example above where N=2, the target mapping table block is programmed twice and the mapping table garbage collection is performed once, i.e., the spare target mapping table block is programmed once.
[0081] In this invention, the concept of proportionally programming the target mapping block and the backup target mapping table block is based on the premise that the map garbage collection (GC) must be completed before the target mapping table block is exhausted. This means that the valid mapping table data in the selected source block must be moved to the backup target mapping table block. This is because programming the target mapping table block is necessary during the user data writing process, while map garbage collection takes additional time and reduces the write speed. It is desirable to maintain a relatively smooth write speed during the data writing process, that is, to spend less time on map garbage collection.
[0082] The method of the present invention can avoid frequent map GCs during map GCs, and each map GC entry consumes a short time, thus preventing the write speed of some user data from being significantly slowed down during a map GC. Furthermore, when multiple source blocks can be selected, several source blocks can be released after the map GC is completed, ensuring a sufficient number of available mapping table blocks.
[0083] In a specific embodiment, performing a mapping table garbage collection to program a spare target mapping table block includes:
[0084] The mapping table garbage collection is performed using a greedy algorithm, a cost-effective algorithm, or a window algorithm. Those skilled in the art can make a selection based on specific needs, and the present invention does not limit this.
[0085] like Figure 7 As shown, the second aspect of the present invention provides a mapping table garbage collection device, comprising:
[0086] an allocation module, configured to allocate a target mapping table block and a spare target mapping table block from a plurality of blocks of a storage mapping table that has not been fully written, wherein the target mapping table block is used to program mapping table data generated from data update, and the spare target mapping table block is used to program valid data on a source block of a mapping table garbage collection;
[0087] A selection module, used to select source blocks to be garbage collected in the mapping table;
[0088] A first calculation module, configured to calculate the total number of valid mapping tables in the selected source block;
[0089] a second calculation module, configured to calculate a ratio of a programming target mapping table block to a spare target mapping table block based on the total number of valid mapping tables and the number of valid mapping tables that can be programmed in the target mapping table block;
[0090] A mapping table garbage collection module is configured to perform mapping table garbage collection based on the ratio.
[0091] In one example, the allocation module is further configured to allocate the target mapping table blocks and the spare target mapping table blocks from a plurality of blocks of the storage mapping table that have not been written.
[0092] A third aspect of the present invention provides a storage device, such as Figure 2 As shown, it includes a controller and a flash memory module, the flash memory module includes a program, and when the program is executed by the controller, the method described in the first aspect of the present invention is implemented.
[0093] A fourth aspect of the present invention provides an electronic device comprising a host and the storage device according to the third aspect of the present invention.
[0094] It should be pointed out that although the various steps in the above embodiments are described in a specific order, those skilled in the art will understand that in order to achieve the effect of the present application, different steps do not have to be performed in such an order. They can be performed simultaneously (in parallel) or in other orders. These adjusted solutions are equivalent to the technical solutions described in this application, and therefore will also fall within the scope of protection of this application.
[0095] The above embodiments are only specific implementation methods 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 has been described in detail with reference to the above embodiments, those skilled in the art should understand that any person skilled in the art can modify or improve the technical solutions described in the above embodiments within the technical scope disclosed by the present invention, or replace some of the technical features therein with equivalents. Such modifications, changes or replacements do not deviate the essence of the corresponding technical solutions 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 should be based on the protection scope of the claims.
Claims
1. A mapping table garbage collection method, characterized in that: include: In addition to allocating target mapping table blocks, a spare target mapping table block is separately allocated from a plurality of blocks of the memory mapping table that has not been fully written, wherein the target mapping table block is specifically used to program mapping table data generated from data update, and the spare target mapping table block is specifically used to program valid data on a source block of mapping table garbage collection; Select the source block to be garbage collected for the mapping table; Calculate the total number of valid mapping tables in the selected source block; Calculating a ratio of the programming target mapping table block to the spare target mapping table block based on the total number of valid mapping tables and the number of valid mapping tables that can be programmed in the target mapping table block; Performing mapping table garbage collection based on the ratio, The calculating of the ratio of the programming target mapping table blocks to the spare target mapping table blocks based on the total number of valid mapping tables includes: Determine a number k1 of programming times for the target mapping table block based on the number of valid mapping tables that can be programmed in the allocated target mapping table block and the number of valid mapping tables that can be programmed per page; Determine the number of times k2 to program the spare mapping table block based on the total number of valid mapping tables in the selected source block and the number of valid mapping tables that can be programmed per page; The ratio of the programming target mapping table block to the backup target mapping table block is calculated as [k1 / k2]:1, where [] represents rounding down. The performing of mapping table garbage collection based on the ratio includes: Program [k1 / k2] target mapping table blocks, perform one mapping table garbage collection, and program one spare target mapping table block.
2. The method according to claim 1, characterized in that The allocating target mapping table blocks and spare target mapping table blocks from a plurality of blocks of the storage mapping table that are not fully written includes: The target mapping table blocks and the spare target mapping table blocks are allocated from a plurality of blocks of the memory mapping table that have not been written.
3. The method according to claim 1 or 2, characterized in that The selecting of the source block to be subjected to mapping table garbage collection includes: At least one source block is selected based on the number of valid mapping tables that can still be programmed in the spare target mapping table block, wherein the total amount of valid mapping tables in the selected at least one source block is less than the number of valid mapping tables that can still be programmed.
4. The method according to claim 1, wherein The process of performing a mapping table garbage collection to program a spare target mapping table block includes: The mapping table garbage collection is performed using a greedy algorithm, a cost-effective algorithm or a window algorithm.
5. A mapping table garbage collection device, characterized in that: include: an allocation module, configured to allocate, from a plurality of blocks of a storage mapping table that has not been fully written, a spare target mapping table block in addition to a target mapping table block, wherein the target mapping table block is specifically used for programming mapping table data generated from data update, and the spare target mapping table block is specifically used for programming valid data on a source block of a mapping table garbage collection; A selection module, used to select source blocks to be garbage collected in the mapping table; A first calculation module, configured to calculate the total number of valid mapping tables in the selected source block; a second calculation module, configured to calculate a ratio of a target mapping table block to a spare target mapping table block based on the total number of valid mapping tables, wherein the second calculation module is further configured to: determine a number of programming times k1 for the target mapping table block based on the number of valid mapping tables that can be programmed in the allocated target mapping table block and the number of valid mapping tables that can be programmed per page; determine a number of programming times k2 for the spare mapping table block based on the total number of valid mapping tables in the selected source block and the number of valid mapping tables that can be programmed per page; and calculate a ratio of the target mapping table block to the spare target mapping table block as [k1 / k2]:1, where [] represents rounding down; A mapping table garbage collection module is configured to perform mapping table garbage collection based on the ratio, wherein the mapping table garbage collection module is further configured to program [k1 / k2] target mapping table blocks, perform one mapping table garbage collection, and program one spare target mapping table block.
6. The device according to claim 5, characterized in that The allocation module is further configured to allocate the target mapping table blocks and the spare target mapping table blocks from a plurality of blocks of the storage mapping table that have not been written.
7. A storage device comprising a controller and a flash memory module, characterized in that: The flash memory module includes a program, and when the program is executed by the controller, the method according to any one of claims 1 to 4 is implemented.
8. An electronic device, characterized in that: The device comprises a host and the storage device according to claim 7.
Citation Information
Patent Citations
Management mechanism for garbage collection operation
CN114968835A
Implementation method and device for improving garbage collection efficiency of mapping table and computer equipment
CN116880766A