Garbage collection method and device, storage control chip and storage medium
By configuring the initial target block and free block in Flash and adopting a preset recycling mechanism, the address discontinuity problem caused by garbage collection and data writing is solved, and the read and write speed of Flash is improved.
Patent Information
- Application Number
- CN202411454963.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-17
- Publication Date
- 2025-03-21
AI Technical Summary
In the prior art, the timing of garbage collection is uncertain, which may be carried out simultaneously with data writing, resulting in the inability to ensure the address continuity of the written data, affecting the reading and writing speed of Flash.
By configuring the initial target block and free block in Flash, it is necessary to ensure that there are at least 2 free blocks after each garbage collection. The preset recycling mechanism is used to transfer the valid data pages in the queue of blocks to be recycled to the target block, and the recycled source block is converted into an idle block.
Ensure that after each garbage collection, there are at least 2 free blocks, ensure the address continuity of written data, and improve the read and write speed of Flash.
Smart Images

Figure CN119669103A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of flash memory technology, and in particular to a garbage collection method, device, storage control chip and storage medium. Background Art
[0002] NAND Flash (hereinafter referred to as Flash) is one of the mainstream storage media at present, and is widely used in various types of storage products, such as USB flash drives, SD cards, solid-state drives, etc. Storage products include Flash, storage control chips and PCBAs, among which the storage control chip uses the Flash Translation Layer (FTL) running inside to achieve reliable management of Flash.
[0003] The flash conversion layer includes mapping, wear leveling, garbage collection (GC), etc. Garbage collection is an important guarantee that Flash has enough capacity to store data. Since the timing of garbage collection is uncertain, data may be written while garbage collection is being executed. It is necessary to ensure that there is at least one block that "plays" the role of cache and GC. Otherwise, the address continuity of the written data cannot be ensured, which affects the read and write speed of Flash. Summary of the invention
[0004] The purpose of the present invention is to overcome the deficiencies in the prior art and provide a garbage collection method, device, storage control chip and storage medium, which can ensure the address continuity of written data and improve the reading and writing speed of Flash.
[0005] A first aspect of the present application provides a garbage collection method, comprising:
[0006] Flash starts garbage collection, wherein the Flash is configured with an initial target block and a free block, the target block is used to recycle data, and the free block is used to serve as the next target block when the target block is full of data;
[0007] Confirming a queue of blocks to be recycled, the sequence of blocks to be recycled includes a number of source blocks, wherein the queue of blocks to be recycled meets a preset recycling condition;
[0008] The target block and the sequence of blocks to be recycled are processed according to a preset recycling mechanism, wherein the preset recycling mechanism includes: based on the queue of blocks to be recycled, transferring the valid data page of the current source block to the current target block, so that the recycled source block is converted into the free block, and processing each source block in turn until the garbage collection is completed.
[0009] In one embodiment, the preset recycling conditions are as follows:
[0010] The number of free blocks to be vacated * the total number of pages < the total number of remaining available pages of the target block + the total number of source blocks in the queue of blocks to be recycled * the total number of pages - the total number of pages to be recycled.
[0011] In one embodiment, the confirming the queue of blocks to be recycled includes:
[0012] Read the Bitmap of the Flash;
[0013] Acquire valid data pages of each source block according to the Bitmap;
[0014] sorting the source blocks based on the total number of valid data pages;
[0015] According to the sorting result, a number of the source blocks are selected to form the queue of blocks to be recycled.
[0016] In one embodiment, after obtaining the valid data page of each source block according to the Bitmap, the method further includes:
[0017] Reading the number of erasures of each of the source blocks;
[0018] The sorting of the source blocks based on the total number of valid data pages comprises:
[0019] The source blocks are sorted based on the total number of valid data pages and the number of erasures.
[0020] A second aspect of the present application provides a garbage collection device, comprising:
[0021] A startup module, used for starting garbage collection of Flash, wherein the Flash is configured with an initial target block and a free block, the target block is used to recycle data, and the free block is used to serve as the next target block when the target block is full of data;
[0022] A locking module, used for confirming a queue of blocks to be recycled, wherein the sequence of blocks to be recycled includes a plurality of source blocks, and wherein the queue of blocks to be recycled satisfies a preset recycling condition;
[0023] A garbage collection module is used to perform processing on the target block and the sequence of blocks to be recovered according to a preset recovery mechanism, wherein the preset recovery mechanism includes: based on the queue of blocks to be recovered, transferring the valid data page of the current source block to the current target block, so that the recovered source block is converted into the free block, and processing each source block in turn until the garbage collection is completed.
[0024] In one embodiment, the preset recycling conditions are as follows:
[0025] The number of free blocks to be vacated * the total number of pages < the total number of remaining available pages of the target block + the total number of source blocks in the queue of blocks to be recycled * the total number of pages - the total number of pages to be recycled.
[0026] In one embodiment, the locking module comprises:
[0027] A first reading unit, used for reading the Bitmap of the Flash;
[0028] An acquisition unit, configured to acquire a valid data page of each source block according to the Bitmap;
[0029] A sorting unit, configured to sort the source blocks based on the total number of valid data pages;
[0030] A selection unit is used to select a number of the source blocks according to the sorting result to form the queue of blocks to be recycled.
[0031] In one embodiment, the locking module further includes:
[0032] A second reading unit, used for reading the number of erasures of each source block;
[0033] The sorting unit is used to sort the source blocks based on the total number of valid data pages, including:
[0034] The source blocks are sorted based on the total number of valid data pages and the number of erasures.
[0035] A third aspect of the present application provides a storage control chip, comprising the garbage collection device as described above.
[0036] A fourth aspect of the present application provides a computer-readable storage medium storing executable code, which, when executed by a processor of an electronic device, causes the processor to execute the garbage collection method as described above.
[0037] The technical solution of the present application includes: Flash starts garbage collection, wherein Flash is configured with an initial target block and a free block, the target block is used to recycle data, and the free block is used to act as the next target block when the target block is full of data; confirm the queue of blocks to be recycled, the sequence of blocks to be recycled includes several source blocks, wherein the queue of blocks to be recycled meets the preset recycling conditions; perform processing on the target block and the sequence of blocks to be recycled according to the preset recycling mechanism, wherein the preset recycling mechanism includes: based on the queue of blocks to be recycled, the valid data page of the current source block is transferred to the current target block, so that the recycled source block is converted into a free block, and each source block is processed in turn until the garbage collection is completed. Through the above technical solution, it can be ensured that after Flash completes garbage collection each time, the number of free blocks is at least 2, the address continuity of the written data can be guaranteed, and the reading and writing speed of Flash can be improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for use in the embodiments are briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present invention and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without creative work.
[0039] Figure 1 is a flow chart of a garbage collection method according to an embodiment of the present application;
[0040] Figure 2 Shown is a schematic structural diagram of a garbage collection device in an embodiment of the present application;
[0041] Figure 3 Shown is a schematic structural diagram of a garbage collection device in another embodiment of the present application;
[0042] Figure 4 FIG. 1 is a schematic diagram of the structure of a storage control chip in an embodiment of the present application;
[0043] Figure 5 Shown is a schematic structural diagram of an electronic device in an embodiment of the present application. DETAILED DESCRIPTION
[0044] In order to facilitate the understanding of the present invention, the present invention will be described more comprehensively with reference to the accompanying drawings. The preferred embodiments of the present invention are shown in the accompanying drawings. However, the present invention can be implemented in many different forms and is not limited to the embodiments described herein. On the contrary, the purpose of providing these embodiments is to make the disclosure of the present invention more thoroughly understood.
[0045] It should be noted that when an element is referred to as being "fixed to" another element, it may be directly on the other element or there may be a central element. When an element is considered to be "connected to" another element, it may be directly connected to the other element or there may be a central element at the same time. The terms "vertical", "horizontal", "left", "right" and similar expressions used herein are for illustrative purposes only and do not represent the only implementation method.
[0046] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art of the present invention. The terms used herein in the specification of the present invention are only for the purpose of describing specific embodiments and are not intended to limit the present invention. The term "and / or" used herein includes any and all combinations of one or more related listed items.
[0047] In the related art, since the timing of garbage collection is uncertain, data writing may be performed while garbage collection is being performed. It is necessary to ensure that there is at least one block that "plays" the role of Cache and the role of GC. Otherwise, the address continuity of the written data cannot be ensured, affecting the reading and writing speed of the Flash.
[0048] Therefore, in order to solve the above technical problems, the present application discloses a garbage collection method, which can ensure the address continuity of written data and improve the reading and writing speed of Flash.
[0049] The technical solution of the present application is described in detail below with reference to the accompanying drawings.
[0050] Figure 1 The figure is a schematic flow chart of a garbage collection method in one embodiment of the present application.
[0051] See also Figure 1 , a garbage collection method, comprising the following steps:
[0052] Step S110 , Flash starts garbage collection, wherein the Flash is configured with an initial target block and a free block, the target block is used to recycle data, and the free block is used to serve as the next target block when the target block is full of data.
[0053] Flash must be erased before writing, and the basic unit of read and write operations is a page, and the basic unit of erase is a block. When writing a page that already has data, it is not directly operated on this page, but a new free page is written, and the original page is marked as an invalid page, and the FTL mapping table is updated to map the logical page to the new physical page. After multiple operations, a block will store both invalid data pages and valid data pages. Flash itself has a limit on the number of blocks. If a large number of blocks in Flash store too many invalid data pages, Flash must start garbage collection and transfer the valid data pages in these blocks that store too many invalid data pages to free blocks to complete the space release of the blocks, ensuring that Flash has a "constant supply" of blocks to provide data storage.
[0054] In this embodiment, before garbage collection is started, the Flash is pre-configured with initial target blocks and free blocks. The target block is used to recycle data, that is, valid data pages will be transferred to the target block during garbage collection. The free block is an erased block that can be written with data and is used to serve as a prepared target block. When the target block is full of data, it "plays" the role of the next target block.
[0055] In this embodiment, the purpose of configuring the initial target block and free block of Flash is to ensure that after the subsequent garbage collection is completed, there are at least two free blocks after each garbage collection is executed, one of which "plays" the role of Cache, and the other free block "plays" the role of GC (i.e., the target block).
[0056] Step S120: confirming a queue of blocks to be recycled, wherein the sequence of blocks to be recycled includes a number of source blocks, wherein the queue of blocks to be recycled meets a preset recycling condition.
[0057] In this embodiment, the recovery condition is preset as shown in formula 1):
[0058] NIB Cnt *Page Cnt <TBPageTotal Cnt +PBQueue Cnt *Page Cnt -PageRecycle Cnt 1)
[0059] Among them, "NIB Cnt " represents the number of free blocks that need to be freed; "Page Cnt " represents the total number of pages of the block. This value is the same regardless of whether it is a free block, a target block, or a source block; "TBPageTotal Cnt " represents the total number of remaining available pages of the target block; "PBQueue Cnt"Represents the total number of source blocks in the queue to be recycled; "PageRecycle Cnt " represents the total number of pages to be recycled.
[0060] In this embodiment, if the confirmed queue of blocks to be recycled can meet the preset recycling conditions, it can ensure that there are at least two free blocks each time the Flash completes garbage collection. Cnt *Page Cnt ", which is equivalent to the total capacity that needs to be freed up; the factor on the right side of formula 2) "TBPageTotal Cnt +PBQueue Cnt *Page Cnt ", which is equivalent to the total capacity available when performing garbage collection; the factor on the right "PageRecycle Cnt ", which is equivalent to the total capacity that needs to be recovered. In this embodiment, before the Flash starts garbage collection, there are already free blocks that serve as the next target block. Therefore, after the garbage collection is completed, only one more free block capacity needs to be freed up to ensure that the Flash has at least 2 free blocks after the garbage collection is completed. Formula 1) "Total capacity available during garbage collection" - "Total capacity to be recovered" > "Total capacity of 1 free block that needs to be freed up" can ensure that there are at least 2 free blocks after the queue of blocks to be recovered completes garbage collection.
[0061] In this embodiment, the queue of blocks to be recycled can be confirmed in the following manner: read the Bitmap of Flash; obtain the valid data page of each source block according to the Bitmap; sort the source blocks based on the total number of valid data pages; and select several source blocks to form the queue of blocks to be recycled according to the sorting result.
[0062] Bitmap is a binary sequence that describes the page status in the current source block. For example, by reading the Flash, the Bitmap of the current source block is obtained as "1110 0111", which means that there are 6 valid data pages and 2 invalid data pages in the source block.
[0063] It should be noted that, since some source blocks have the same valid data pages, the erasure count of each source block can be read to sort the source blocks based on the total number of valid data pages and the erasure count.
[0064] If the total number of valid data pages and the number of erasures in some source blocks are the same, an additional parameter item "ECC error correction bit number" can be added for sorting. The sorting priority of the recovery block queue is: the least valid data pages > the most erasure times > the most ECC error correction bits. If some source blocks are still the same based on the above sorting priority, these source blocks can be sorted in the same order, that is, assuming that the above three parameter items of source block P and source block K are the same, source block P can be placed before or after source block K.
[0065] Step S130, processing the target block and the sequence of blocks to be recycled is performed according to a preset recycling mechanism, wherein the preset recycling mechanism includes: based on the queue of blocks to be recycled, transferring the valid data page of the current source block to the current target block, so that the recycled source block is converted into a free block, and processing each source block in turn until garbage collection is completed.
[0066] It should be noted that after confirming the queue of blocks to be recovered, the target blocks and the queue of blocks to be recovered are processed according to the preset recovery mechanism. In the present embodiment, the preset recovery mechanism includes: based on the queue of blocks to be recovered, the valid data page of the current source block is transferred to the current target block, so that the recovered source block is converted into a free block, and each source block is processed in turn until the garbage collection is completed. According to the principle of the preset recovery mechanism, when all the valid data pages of the source block are transferred to the current target block, only invalid data pages are left in the source block at this time, and the source block can be erased to perform an erase operation, so that the recovered source block is converted into a free block. According to the description of step S110, the free block is used to act as the next target block when the target block is full of data, so that Flash has a "constant" supply of free blocks, ensuring that every time Flash starts garbage collection, there is a free block as a target block to recycle valid data pages.
[0067] In this embodiment, since the sequence of blocks to be recycled meets the preset recycling conditions, after steps S110 to S130, it can be ensured that there are at least 2 free blocks after each garbage collection of Flash, which can ensure the address continuity of the written data and improve the reading and writing speed of the Flash.
[0068] In order to better understand the principle of the technical solution of this application, specific examples are listed below to illustrate the principle.
[0069] Environmental conditions: Assume that after multiple garbage collections, the Flash still has 8 blocks of "remaining space", namely, a free block (1), a target block (1), and source blocks (6, A to F). The total number of pages of each block is 100 pages, of which the free block has no valid data pages, the target block has 95 pages of valid data, and the source blocks A to F have 80 pages, 81 pages, 82 pages, 83 pages, 84 pages, and 85 pages of valid data, respectively.
[0070] Start garbage collection. In this embodiment, the condition for starting garbage collection is to determine whether there is and only one free block in the current state of Flash. If so, Flash needs to start garbage collection. If not (the number of free blocks is greater than or equal to 2), Flash does not need to start garbage collection. The purpose of this setting is that when Flash starts garbage collection, Flash will definitely be accompanied by the writing process of new data. The valid data page of garbage collection is written into the target block, and the newly written data is written into the Cache block. Whether it is a target block or a Cache block, it is an idle block that "plays the role". Therefore, in order to ensure that Flash can normally run garbage collection and new data writing tasks, it is necessary to ensure that Flash always has at least 2 free blocks, one of which acts as a preparation for the target block, and the other free block acts as a Cache block.
[0071] It should be noted that, if it is determined that the Flash does not meet the garbage collection start condition, the Flash is waited and judged cyclically until the Flash meets the garbage collection condition.
[0072] It is now determined that the current Flash has only one free block, and garbage collection needs to be started. Confirm the queue of blocks to be recycled, where the queue of blocks to be recycled meets the preset recycling conditions. In this embodiment, the preset recycling conditions are shown in formula 1). According to the requirements of formula 1), it is necessary to read the valid data pages of the source blocks. In this embodiment, it is executed as follows: read the Bitmap of Flash; obtain the valid data pages of each source block according to the Bitmap; sort each source block based on the total number of valid data pages; select several source blocks according to the sorting results to form a queue of blocks to be recycled.
[0073] The total number of valid data pages for each source block is shown in Table 1.
[0074] Serial number Block number 0 Source Block A 1 Source Block B 2 Source Block C 3 Source Block D 4 Source Block E 5 Source Block F
[0075] Table 1
[0076] According to Table 1, combined with the Bitmap of each source block, we get:
[0077] TBPageTotal Cnt +PBQueue Cnt *Page Cnt -PageRecycle Cnt =5+5*100-
[0078] (80+81+82+83+84+85)=210.
[0079] Since the Flash is configured with initial free blocks, it is only necessary to free up space for one more free block to ensure that the Flash has two free blocks after garbage collection is completed.
[0080] NIB Cnt *Page Cnt =100.
[0081] Due to NIB Cnt *Page Cnt <TBPageTotal Cnt +PBQueue Cnt *Page Cnt -PageRecycle Cnt , determine whether the queue of blocks to be recycled meets the preset recycling conditions. This means that only 100 pages of capacity need to be freed up in this garbage collection, while the total capacity available for the entire garbage collection is 605 pages, and the capacity occupied by the recycled data is 495 pages. As long as "the total capacity available for garbage collection - the capacity occupied by the recycled data" is greater than or equal to "only 100 pages of capacity need to be freed up", it can be guaranteed that there are at least 2 free blocks in the Flash after each garbage collection (this result is understood in conjunction with the garbage collection process below).
[0082] Garbage Collection Process
[0083] First, since there is still 5 pages of space in the target block, the valid data of 5 pages in source block A is transferred to the target block. At this time, the target block is full of data and new data cannot be written, so the free block serves as the target block.
[0084] Then, the remaining 75 pages of valid data in source block A and 25 pages of valid data in source block B are transferred to the target block. Since all the valid data in source block A has been transferred, source block A can be erased to turn it into a free block. At this time, the target block is full of data and new data cannot be written. Therefore, source block A (i.e., the free block at this time) serves as the target block.
[0085] Then, the remaining 56 pages of valid data in source block B and 44 pages of valid data in source block C are transferred to the target block (i.e., source block A). Since all the valid data in source block B has been transferred, source block B can be erased to turn it into a free block. At this time, the target block (i.e., source block A) is full of data and cannot be written with new data, so source block B (i.e., the free block at this time) serves as the target block.
[0086] Then, the remaining 38 pages of valid data in source block C and 62 pages of valid data in source block D are transferred to the target block (i.e., source block B). Since all the valid data in source block C has been transferred, source block C can be erased to turn it into a free block. At this time, the target block (i.e., source block B) is full of data and cannot be written with new data, so source block C (i.e., the free block at this time) serves as the target block.
[0087] Then, the remaining 21 pages of valid data in source block D and 79 pages of valid data in source block E are transferred to the target block (i.e., source block B). Since all the valid data in source block D has been transferred, source block D can be erased to turn it into a free block. At this time, the target block (i.e., source block C) is full of data and cannot be written with new data. Therefore, source block D (i.e., the free block at this time) serves as the target block.
[0088] Finally, the remaining 5 pages of valid data in source block E and 85 pages of valid data in source block F are transferred to the target block (i.e., source block D). Since all valid data in source block E has been transferred, source block E can be erased to turn it into a free block. At this time, the target block (i.e., source block D) is full of data and cannot write new data, so source block E (i.e., the free block at this time) serves as the target block. However, it should be noted that all valid data in source block F has also been transferred, and source block F can also be erased to turn it into a free block.
[0089] Through the above process, the garbage collection process of Flash is completed. From the final result, after garbage collection is completed, Flash has at least 2 free blocks, one of which is source block E and the other is source block F. Source block E serves as the next target block, while source block F can serve as a cache block. The above result is produced because when confirming the queue of blocks to be recycled, the queue of blocks to be recycled meets the preset recycling conditions, so it can be guaranteed that Flash has at least 2 free blocks after garbage collection is completed.
[0090] When Flash starts garbage collection, it will definitely be accompanied by the writing of new data. The valid data page of garbage collection is written into the target block, and the newly written data is written into the cache block. Whether it is the target block or the cache block, it is the idle block that "plays the role". Therefore, in order to ensure that Flash can perform garbage collection and new data writing tasks normally, it is necessary to ensure that Flash always has at least 2 idle blocks, one of which acts as a preparation for the target block, and the other idle block acts as a cache block. At the same time, this can also ensure the address continuity of the newly written data, which is conducive to improving the read and write speed of Flash.
[0091] It should be noted that garbage collection is accompanied by the writing of new data. It does not mean that garbage collection and new data writing are carried out at the same time. Instead, it is an alternating process. A few pages of new data are written first, and then Flash jumps to perform garbage collection. After recycling a few pages of data, Flash jumps again to write new data, and so on.
[0092] Corresponding to the aforementioned method embodiments, the present application also provides a garbage collection device and corresponding embodiments.
[0093] Figure 2 A schematic structural diagram of a garbage collection device in an embodiment of the present application is shown.
[0094] See also Figure 2 , a garbage collection device 200, comprising: a startup module 210, a locking module 220 and a garbage collection module 230. Wherein:
[0095] The startup module 210 is used for Flash to start garbage collection, wherein the Flash is configured with an initial target block and a free block, the target block is used to recycle data, and the free block is used to serve as the next target block when the target block is full of data.
[0096] The locking module 220 is used to confirm the queue of blocks to be recycled, the sequence of blocks to be recycled includes a number of source blocks, and the queue of blocks to be recycled meets a preset recycling condition.
[0097] In this embodiment, the recovery conditions are preset as follows:
[0098] The number of free blocks to be vacated * the total number of pages < the total number of remaining available pages of the target block + the total number of source blocks in the queue of blocks to be recycled * the total number of pages - the total number of pages to be recycled.
[0099] The garbage collection module 230 is used to perform processing on the target block and the sequence of blocks to be recovered according to a preset recovery mechanism, wherein the preset recovery mechanism includes: based on the queue of blocks to be recovered, transferring the valid data page of the current source block to the current target block, so that the recovered source block is converted into a free block, and processing each source block in turn until the garbage collection is completed.
[0100] Figure 3 A schematic structural diagram of a garbage collection device in another embodiment of the present application is shown.
[0101] See also Figure 3 , a garbage collection device 200, comprising: a startup module 210, a locking module 220 and a garbage collection module 230. Wherein:
[0102] For the functions of the startup module 210, the locking module 220 and the garbage collection module 230, please refer to Figure 2 , I will not go into details here.
[0103] The locking module 220 includes: a first reading unit 221 , an acquiring unit 222 , a second reading unit 223 , a sorting unit 224 and a selecting unit 225 .
[0104] The first reading unit 221 is used to read the Bitmap of the Flash.
[0105] The acquisition unit 222 is used to acquire the valid data page of each source block according to the Bitmap.
[0106] The second reading unit 223 is used to read the erasure count of each source block.
[0107] The sorting unit 224 is used to sort the source blocks based on the total number of valid data pages and the number of erase times.
[0108] The selection unit is used to select a number of source blocks according to the sorting result to form a queue of blocks to be recycled.
[0109] like Figure 4 Shown is a structural schematic diagram of a storage control chip in one embodiment of the present application.
[0110] Please refer to 4 , a storage control chip 400 includes the above-mentioned data merging device 200 .
[0111] It should be noted that the storage control chip of this embodiment establishes a mapping relationship between the logical address of each single-bit type block and the physical address of the multi-bit type block, that is, the L2P table stores the mapping relationship after the data is merged. There is no need to overwrite the original mapping relationship (that is, the mapping relationship before the data is merged) with a new mapping relationship every time the data is merged as in the related technology. The present application can minimize the operation of the L2P table, thereby improving the overall quality of the Flash.
[0112] See also Figure 5 Another embodiment of the present application shows a computing electronic device 500 including: a processor 510 and a memory 520.
[0113] The processor 510 can be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc.
[0114] A general purpose processor may be a microprocessor or the processor may be any conventional processor. The memory 510 may include various types of storage units, such as system memory, read-only memory (ROM), and permanent storage.
[0115] Among them, ROM can store static data or instructions required by processor 520 or other modules of the computer. The permanent storage device can be a readable and writable storage device. The permanent storage device can be a non-volatile storage device that does not lose the stored instructions and data even if the computer is powered off. In some embodiments, the permanent storage device uses a large-capacity storage device (such as a magnetic or optical disk, flash memory) as a permanent storage device.
[0116] In some other embodiments, the permanent storage device may be a removable storage device (e.g., a floppy disk, an optical drive). The system memory may be a read-write storage device or a volatile read-write storage device, such as a dynamic random access memory. The system memory may store some or all of the instructions and data required by the processor at run time.
[0117] In addition, the memory 520 may include any combination of computer-readable storage media, including various types of semiconductor memory chips (eg, DRAM, SRAM, SDRAM, flash memory, programmable read-only memory), magnetic disks and / or optical disks.
[0118] In some embodiments, the memory 520 may include a removable storage device that can be read and / or written, such as a laser disc (CD), a read-only digital versatile disc (such as a DVD-ROM, a double-layer DVD-ROM), a read-only Blu-ray disc, an ultra-density optical disc, a flash memory card (such as an SD card, a mini SD card, and a Micro-SD card, etc.), a magnetic floppy disk, etc. The computer-readable storage medium does not contain a carrier wave and an instantaneous electronic signal transmitted wirelessly or by wire. The memory 520 stores executable code, and when the executable code is processed by the processor 510, the processor 510 can execute part or all of the methods described above.
[0119] In addition, the method according to the present application may also be implemented as a computer program or a computer program product, which includes computer program code instructions for executing some or all of the steps in the above method of the present application.
[0120] Alternatively, the present application can also be implemented as a computer-readable storage medium (or non-transitory machine-readable storage medium or machine-readable storage medium) on which executable code (or computer program or computer instruction code) is stored. When the executable code (or computer program or computer instruction code) is executed by a processor of an electronic device (or server, etc.), the processor executes part or all of the steps of the above-mentioned method according to the present application.
[0121] The embodiments of the present application have been described above, and the above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and changes will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The selection of terms used herein is intended to best explain the principles of the embodiments, practical applications, or improvements to the technology in the market, or to enable other persons of ordinary skill in the art to understand the embodiments disclosed herein.
Claims
1. A garbage collection method, characterized in that: include: Flash starts garbage collection, wherein the Flash is configured with an initial target block and a free block, the target block is used to recycle data, and the free block is used to serve as the next target block when the target block is full of data; Confirming a queue of blocks to be recycled, the sequence of blocks to be recycled includes a number of source blocks, wherein the queue of blocks to be recycled meets a preset recycling condition; The target block and the sequence of blocks to be recycled are processed according to a preset recycling mechanism, wherein the preset recycling mechanism includes: based on the queue of blocks to be recycled, transferring the valid data page of the current source block to the current target block, so that the recycled source block is converted into the free block, and processing each source block in turn until the garbage collection is completed.
2. The garbage collection method according to claim 1, characterized in that: The preset recycling conditions are as follows: The number of free blocks to be vacated * the total number of pages < the total number of remaining available pages of the target block + the total number of source blocks in the queue of blocks to be recycled * the total number of pages - the total number of pages to be recycled.
3. The garbage collection method according to claim 1, characterized in that: The confirmed queue of blocks to be recycled includes: Read the Bitmap of the Flash; Acquire valid data pages of each source block according to the Bitmap; sorting the source blocks based on the total number of valid data pages; According to the sorting result, a number of the source blocks are selected to form the queue of blocks to be recycled.
4. The garbage collection method according to claim 3, characterized in that: After obtaining the valid data pages of each source block according to the Bitmap, the method further includes: Reading the number of erasures of each of the source blocks; The sorting of the source blocks based on the total number of valid data pages comprises: The source blocks are sorted based on the total number of valid data pages and the number of erasures.
5. A garbage collection device, characterized in that: include: A startup module, used for starting garbage collection of Flash, wherein the Flash is configured with an initial target block and a free block, the target block is used to recycle data, and the free block is used to serve as the next target block when the target block is full of data; A locking module, used for confirming a queue of blocks to be recycled, wherein the sequence of blocks to be recycled includes a plurality of source blocks, and wherein the queue of blocks to be recycled satisfies a preset recycling condition; A garbage collection module is used to perform processing on the target block and the sequence of blocks to be recovered according to a preset recovery mechanism, wherein the preset recovery mechanism includes: based on the queue of blocks to be recovered, transferring the valid data page of the current source block to the current target block, so that the recovered source block is converted into the free block, and processing each source block in turn until the garbage collection is completed.
6. The garbage collection device according to claim 5, characterized in that: include: The preset recycling conditions are as follows: The number of free blocks to be vacated * the total number of pages < the total number of remaining available pages of the target block + the total number of source blocks in the queue of blocks to be recycled * the total number of pages - the total number of pages to be recycled.
7. The garbage collection device according to claim 5, characterized in that: The locking module comprises: A first reading unit, used for reading the Bitmap of the Flash; An acquisition unit, configured to acquire a valid data page of each source block according to the Bitmap; A sorting unit, configured to sort the source blocks based on the total number of valid data pages; A selection unit is used to select a number of the source blocks according to the sorting result to form the queue of blocks to be recycled.
8. The garbage collection device according to claim 7, characterized in that: The locking module also includes: A second reading unit, used for reading the number of erasures of each source block; The sorting unit is used to sort the source blocks based on the total number of valid data pages, including: The source blocks are sorted based on the total number of valid data pages and the number of erasures.
9. A storage control chip, characterized in that: A garbage recycling device comprising any one of claims 5 to 8.
10. A computer-readable storage medium, characterized in that: An executable code is stored, and when the executable code is executed by a processor of an electronic device, the processor is caused to execute the garbage collection method according to any one of claims 1 to 4.
Citation Information
Patent Citations
Junk recycling method of redundant array of independent solid-state disks based on reserved space
CN107451069A
Method for enhancing solidly stored garbage collection performance
CN107562646A
Garbage collection method and device for solid state disk
CN108763102A
Trash recycling method for solid-state storage equipment and computer equipment
CN108874683A
An optimization method aiming at NAND Flash main control chip Greedy garbage collection
CN109710541A
Cited By
Garbage recycling method and device in distributed storage system, equipment and medium
CN121455838A