Garbage collection method and solid state drive
By using a combination of index tables and secondary mapping tables in solid-state drives, the need to scan physical blocks is reduced, garbage collection efficiency is improved, and the problems of resource waste and inefficiency in existing technologies are solved, achieving more efficient garbage collection.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- MAXIO TECHNOLOGY (HANGZHOU) CO LTD
- Filing Date
- 2022-11-10
- Publication Date
- 2026-04-14
AI Technical Summary
Existing garbage collection methods require scanning the entire physical block to find valid data, resulting in high overhead and low efficiency, especially when frequently reading cache units, which leads to serious resource waste.
By obtaining the index table within the current user's physical block, and traversing the secondary mapping table one by one to determine whether the physical address belongs to the current user's physical block, only the index table is read and the secondary mapping table is used to determine whether the written data is valid, thus avoiding scanning the entire physical block and reducing frequent operations on cache units.
It improves garbage collection performance, reduces resource consumption, speeds up the garbage collection process, promptly handles coding errors, and enhances the utilization efficiency of user physical blocks.
Smart Images

Figure CN115630001B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of data storage technology, and in particular to a waste recycling method and a solid-state drive. Background Technology
[0002] Solid-state drives (SSDs) are hard drives made with solid-state electronic storage chips, mainly composed of a controller, memory, and cache units. SSDs typically use flash memory (such as NAND flash memory) to store write data, and SRAM or DRAM as cache units.
[0003] When using physical blocks of flash memory to store write data, an FTL (Flash Translation Layer) mapping table is needed to record the mapping relationship between host logical space addresses and flash physical addresses. This mapping table, representing this relationship, is usually stored in the physical blocks. When a user writes data, if the number of available physical blocks is less than a certain threshold, an erase and rewrite operation is required. Since writing data is done in units of pages (physical pages), while erasing is done in units of blocks (physical blocks), when a physical block needs to be erased, garbage collection is first required. This involves moving the valid data from the physical block to a new physical block, and then erasing the physical block to free up space for user write operations. Currently, garbage collection typically involves scanning each 4K cell of a physical block, reading the corresponding logical address, and then using the mapping table to find the corresponding physical address. The validity of the write data is determined by whether the found physical address matches the physical address of the 4K cell itself, and then garbage collection is performed on the write data within that 4K cell. The current garbage collection method requires scanning the entire physical block, which is very costly. In addition, it requires frequently reading the same mapping table into the cache unit, making the garbage collection process cumbersome and inefficient. Summary of the Invention
[0004] In view of the above problems, the purpose of this invention is to provide a garbage collection method and a solid-state drive to solve the problem of high garbage collection overhead caused by scanning the entire physical block to find valid data during garbage collection.
[0005] According to a first aspect of the present invention, a garbage collection method is provided, applied in a solid-state drive (SSD), the SSD including a cache unit and a memory, the memory including a plurality of user physical blocks, wherein the garbage collection method includes:
[0006] Obtain the index table corresponding to all write data within the current user's physical block. The index table includes at least one index value, which indicates the storage location of the secondary mapping table corresponding to the write data.
[0007] Obtain at least one target secondary mapping table based on the index table;
[0008] Iterate through each mapping record in the at least one target secondary mapping table and determine whether the physical address in each mapping record belongs to the current user's physical block;
[0009] The valid write data corresponding to the mapping record whose physical address belongs to the current user's physical block is moved. The valid write data is valid data.
[0010] Optionally, the step of obtaining the index table corresponding to all write data within the current user's physical block may include:
[0011] When processing write operations, the index values corresponding to all write data in each user physical block are recorded to build an index table, and the same index value is recorded only once.
[0012] Optionally, the index table is stored in the cache unit or in a designated user physical block of the memory.
[0013] Optionally, the current user physical block includes multiple 4K cells, which store multiple write data, and the index table is located in a specified 4K cell of the current user physical block.
[0014] Optionally, all logical addresses of the solid-state drive are divided into multiple groups, each group corresponding to an encoded value, and the index value of the written data is the encoded value of the group in which the logical address of the written data is located.
[0015] Optionally, before the step of moving the valid write data corresponding to the mapping record whose physical address belongs to the current user's physical block, the method further includes:
[0016] Determine whether the mapping record of the physical address belonging to the current user's physical block has a mapping relationship in the cache unit;
[0017] If the mapping record does not have a mapping relationship in the cache unit, the write data corresponding to the mapping record is determined to be valid data.
[0018] Optionally, after the step of obtaining at least one target secondary mapping table based on the index table, the method further includes:
[0019] The target secondary mapping table corresponding to each index value is loaded into the cache unit sequentially.
[0020] Optionally, the current user physical block includes multiple 4K cells that store the write data and its corresponding logical address respectively. The mapping record is determined to have a mapping relationship in the cache unit by obtaining the logical address in the 4K cell. The logical address is the logical address corresponding to the mapping record in the target secondary mapping table.
[0021] Optionally, the secondary mapping tables corresponding to all the write data stored in the current user physical block to be garbage collected are stored in the mapping physical block of the memory.
[0022] Optionally, the memory includes multiple physical blocks, and the index table, the secondary mapping table, and the write data are stored in different physical blocks of the memory.
[0023] According to a second aspect of the present invention, a solid-state drive is provided, comprising:
[0024] A processor, connected to a host, is configured to receive write data from the host and perform the garbage collection method described in any of the preceding embodiments;
[0025] A cache unit, connected to the processor, is used to store a first-level mapping table corresponding to the written data, and to store the mapping relationship between the logical address and physical address of the written data; and
[0026] A memory, connected to the processor, is used to store write data, a secondary mapping table, and an index table according to the control of the processor.
[0027] The garbage collection method provided in this application obtains the secondary mapping table corresponding to the write data in the current user physical block by acquiring the index table. For each target secondary mapping table, it checks whether the physical address in each mapping record is located in the current user physical block to preliminarily determine whether the write data needs to be moved for garbage collection. Thus, it only needs to read the index table and then refer to the secondary mapping table to determine whether the write data needs to be moved, without scanning the entire user physical block, resulting in higher garbage collection performance. Moreover, each target secondary mapping table only needs to be traversed once, without frequently swapping it in and out of cache units, saving overhead and speeding up the garbage collection process.
[0028] Furthermore, by dividing the logical addresses of the solid-state drive into multiple groups, each group corresponding to an encoded value, and the index value of the write data being the encoded value of the group containing the logical address of the write data, the index value is recorded simultaneously with the write data being stored in the user's physical block. This allows for the retrieval of all secondary mapping tables corresponding to the write data within that user's physical block. The index value occupies less space, has low overhead for reading the index value, and can quickly find the secondary mapping table corresponding to the write data, thus accelerating the garbage collection process. Since the same index value is recorded only once, the same secondary mapping table only needs to be called once, resulting in higher garbage collection performance. For valid data on the user's physical block that has uncorrectable encoding errors, it can be identified as erroneous data during garbage collection, allowing for timely correction without affecting the relocation of the valid data, thus enabling timely erasure of the physical block. Attached Figure Description
[0029] The above and other objects, features and advantages of the present invention will become more apparent from the following description of embodiments of the invention with reference to the accompanying drawings, in which:
[0030] Figure 1 This diagram illustrates the process of deleting data on a solid-state drive (SSD).
[0031] Figure 2 A flowchart of a waste recycling method according to a first embodiment of the present invention is shown;
[0032] Figure 3 A flowchart of a waste recycling method according to a second embodiment of the present invention is shown;
[0033] Figure 4 A schematic diagram of a cache unit and memory storing data in a solid-state drive according to an embodiment of the present invention is shown;
[0034] Figure 5 A data structure diagram of physical addresses in a secondary mapping table according to an embodiment of the present invention is shown;
[0035] Figure 6 This diagram illustrates the process of recycling valid data in a waste recycling method according to an embodiment of the present invention.
[0036] Figure 7 A schematic block diagram of a solid-state drive according to an embodiment of the present invention is shown. Detailed Implementation
[0037] The invention will now be described in more detail with reference to the accompanying drawings. In the various drawings, the same elements are indicated by similar reference numerals. For clarity, the various parts in the drawings are not drawn to scale. Furthermore, some well-known parts may not be shown.
[0038] The present invention is described below based on embodiments, but the invention is not limited to these embodiments. In the detailed description of the invention below, certain specific details are described in detail. Those skilled in the art will fully understand the invention even without these details. To avoid obscuring the essence of the invention, well-known methods, processes, flows, elements, and circuits are not described in detail.
[0039] Unless the context explicitly requires it, the terms "comprising," "including," and similar terms throughout the specification and claims should be interpreted as encompassing rather than exclusive or exhaustive; that is, meaning "including but not limited to." In the description of this invention, it should be understood that terms such as "first," "second," etc., are used for descriptive purposes only and should not be construed as indicating or implying relative importance. Furthermore, in the description of this invention, unless otherwise stated, "a plurality of" means two or more.
[0040] The specific embodiments of the present invention will be described in further detail below with reference to the accompanying drawings and examples.
[0041] Figure 1 The diagram illustrates the process of deleting data on a solid-state drive.
[0042] like Figure 1 As shown, when a solid-state drive (SSD) stores write data, it uses user physical blocks of flash memory to store the write data, and uses a mapping table to record the mapping relationship between the host logical address (LAA) and the flash physical address (FAA). Each write data LAA pointer (File index) points to the FAA where the actual data (File data) is stored (File 1 index points to data File 1 data, File 2 index points to data File 2 data). When write data is deleted, only the corresponding pointer is deleted; the write data is invalid, but the actual write data in the FAA is not deleted. A new pointer is then assigned to the LAA, and File 1 index can point to other data areas, indicating data transfer. The mapping relationship of the write data changes (if the File 1 index pointer is deleted, then the data File 1 data is considered deleted, but the actual write data in the FAA is not deleted; a new File 1 index pointer is created, pointing to the location of File 3 data, so the write data is actually stored at the location of File 3 data). Therefore, when performing garbage collection, it is necessary to first determine whether the written data is valid, migrate the valid data to a new user physical block, and then erase the current user physical block as a whole.
[0043] Specifically, during garbage collection, a user physical block is selected as the current user physical block: First, all 4K cells of the user physical block storing write data are scanned. The LAA value stored in the meta space of each 4K cell is retrieved sequentially. The validity of the data in the current 4K cell is confirmed according to the mapping table. For example, if the LAA value stored in the meta space of a 4K cell is laa1, and the physical address of this 4K cell is faa1, the corresponding mapping table is looked up based on laa1 to obtain the current actual mapping relationship faa2. If the obtained faa2 is equal to faa1, then the write data in the current 4K cell is valid and needs to be migrated to the new user physical block; if the obtained faa2 is not equal to faa1, then the write data in the current 4K cell is invalid and does not need to be migrated.
[0044] Therefore, garbage collection requires scanning the entire user physical block, traversing each 4K cell, which is very costly. Furthermore, determining the validity of written data based on the mapping table requires retrieving the mapping table for each write, especially when the user physical block stores a large amount of random data. The mapping table of write data earlier in the physical block is loaded into the cache (e.g., SRAM) first. Subsequent queries of other write data load the mapping tables of those writes into SRAM, replacing the original mapping table. When the mapping relationship between later and earlier write data is in the same mapping table, determining the validity of the later write data requires reloading the same replaced mapping table into SRAM. This involves frequent swapping of table data in and out of SRAM, wasting resources and increasing the workload on SRAM. Additionally, if the data at a certain location in the physical block is UNC (uncorrectable error-correcting code), further complicates the process. When an error (an uncorrectable encoding error) occurs, the data within the 4K cell cannot be read, making it impossible to determine the validity of the written data within that 4K cell. Therefore, garbage collection cannot be performed. The system passively waits for the host to read the LAA mapping relationship, which is located within the 4K cell of that UNC. Only then can the UNC processing mechanism decrement the VFC (Valid Frag Count) value by one, until the VFC value equals 0, at which point the user physical block can be erased. Erasing physical blocks with erroneous data is time-consuming, resulting in the user physical block being occupied indefinitely. Therefore, the above garbage collection method has many drawbacks.
[0045] Therefore, this invention proposes a garbage collection method that records the index value associated with the secondary mapping table of the written data when storing write data. These index values form an index table, allowing the corresponding target secondary mapping table to be found simply by reading the index table corresponding to the write data within the current user physical block, without scanning the entire current user physical block. When determining whether the write data is valid based on the secondary mapping table, the same secondary mapping table only needs to be loaded into SRAM once. By traversing the secondary mapping table once, all write data within the same secondary mapping table in the user physical block are uniformly judged, avoiding frequent swapping of the secondary mapping table into and out of SRAM. The following specific embodiments illustrate the garbage collection method of this invention.
[0046] Figure 2 A flowchart of a waste recycling method according to a first embodiment of the present invention is shown.
[0047] The garbage collection method in this embodiment can be applied to solid-state drives (SSDs). An SSD includes a controller, cache units, and memory. The memory, for example, is a flash memory, comprising multiple 4K cells for storing multiple write data items and their corresponding logical addresses (LAAs). Figure 2 As shown, the waste recycling method in this embodiment specifically includes the following steps:
[0048] In step S101, an index table corresponding to all write data within the current user physical block is obtained. The index table includes at least one index value, which indicates the storage location of the secondary mapping table corresponding to the write data.
[0049] In this step, when performing garbage collection on the selected current user physical block, the index table corresponding to the write data within the current user physical block is first obtained. The index table contains at least one index value; when multiple index values are present, they are all distinct. The current user physical block is the user physical block (block) in memory that stores the write data and is currently undergoing garbage collection. Each index value corresponds to a secondary mapping table, and a secondary mapping table can represent the mapping relationship of multiple write data. Therefore, by obtaining the index table, the target secondary mapping table corresponding to all write data within the current user physical block can be obtained. Some write data mapping relationships reside in the same target secondary mapping table; that is, some write data correspond to the same index value, but this index value appears only once in the index table. The current user physical block is represented by blk22 to describe subsequent steps, and the index value is represented, for example, by index.
[0050] In step S102, at least one target secondary mapping table is obtained according to the index table.
[0051] Since the index table includes at least one index value, and each index value corresponds to at least one secondary mapping table for writing data, it is necessary to obtain the target secondary mapping table one by one according to the index value of the stored index table, and perform a traversal operation on each target secondary mapping table.
[0052] In step S103, each mapping record in at least one target secondary mapping table is traversed one by one to determine whether the physical address in each mapping record belongs to the current user's physical block.
[0053] In this step, the target secondary mapping table stores multiple physical addresses (FAAs). For each index value, it's necessary to traverse every mapping record in the target secondary mapping table to obtain the physical address. For each physical address, it's determined whether it resides in the current user physical block, until the entire target secondary mapping table and the entire index table have been traversed. For example, the determination method involves obtaining the block value within each FAA and checking if it matches the block value in blk22. If they differ, the FAA is not in blk22; if they match, the physical address resides in the current user physical block, and the write data within that FAA might be valid. Further, the validity of the write data within the FAA is determined based on the LAA value corresponding to the current FAA. For instance, if all mapping relationships in SRAM are stored in the memory's secondary mapping table, then when the FAA is in blk22, the corresponding write data is valid. If there are still some updated mapping relationships in SRAM, it's also necessary to determine whether the write data is valid based on whether the LAA corresponding to the FAA has a mapping relationship in SRAM.
[0054] In step S104, the valid write data corresponding to the mapping record of the physical address belonging to the current user's physical block is moved, and the valid write data is valid data.
[0055] In this step, when the FAA of a mapping record in the target secondary mapping table is located in the current user physical block, and the written data stored therein is valid data, the written data is moved, and garbage collection is performed. After traversing the entire index table, the migration of valid data in the entire current user physical block is completed, and the current user physical block can be erased, completing the garbage collection operation.
[0056] According to the garbage collection method of this embodiment, the relevant target secondary mapping table is obtained by acquiring the index table corresponding to the write data in the current user physical block. For each target secondary mapping table, the physical address of the mapping record in it is determined according to the mapping relationship to see if it is located in the current user physical block. This allows for a preliminary determination of whether the write data needs to be moved for garbage collection. Thus, the determination can be made by reading the index table and then the secondary mapping table, without scanning the entire user physical block. Moreover, by obtaining the corresponding target secondary mapping table through the index value and determining whether the write data is valid based on the mapping relationship, the garbage collection performance is higher. Furthermore, each target secondary mapping table only needs to be traversed once, without the need to frequently swap it in and out of the cache unit, saving overhead and speeding up the garbage collection process.
[0057] Figure 3 A flowchart of a waste recycling method according to a second embodiment of the present invention is shown, which specifically includes the following steps.
[0058] In step S201, when processing write operations, the index values corresponding to all write data in each user physical block are recorded to build an index table, and the same index value is recorded only once.
[0059] In this step, all write data from the host is stored in the user physical block of the memory, and the mapping relationship of the write data is stored in the mapping physical block of the memory. All logical addresses of the solid-state drive are divided into multiple groups, each group corresponding to a first-level mapping table and an encoded value. The physical addresses of multiple write data items whose logical addresses are in the same group are stored in the same second-level mapping table of the mapping physical block. The physical addresses of multiple second-level mapping tables are then stored one-to-one in multiple first-level mapping tables of the cache unit. The index value of the write data is the encoded value of the group where the logical address of the write data belongs. Therefore, the index value indicates the physical location of the second-level mapping table in the memory. The target second-level mapping table corresponding to the write data can be found through the index value. See details... Figure 4 .
[0060] Figure 4 A schematic diagram illustrating the cache unit and memory storage of a solid-state drive according to an embodiment of the present invention is shown. See also Figure 4Due to memory limitations, DRAM-less solid-state drives (SSDs) cannot store all mapping tables in cache unit 124 (SRAM). Therefore, they typically use two-level or multi-level tables to manage table data. A small portion of the mapping table is cached in cache unit 124, while the rest resides in the mapping physical block 131 of memory 130. For example, cache unit 124 stores the first-level mapping table, mapping physical block 131 of memory 130 stores the second-level mapping table, and user physical block 132 is used to store write data. For the first-level mapping table, all logical addresses (LAAs) in the SSD are first grouped, see [link to relevant documentation]. Figure 4 On the left side, all logical addresses in the solid-state drive are divided into m+1 groups (0 to m) and stored in a first-level mapping table. This first-level mapping table can be viewed as an array L1[index] with m+1 elements, where index = 0, ..., m+1. L1[index] points to a second-level mapping table, meaning the element's value is the physical address of the second-level mapping table stored in the mapped physical block 131. Each second-level mapping table contains multiple mappings between logical addresses and multiple physical addresses, representing the physical addresses (FAAs) where multiple write data are actually stored in the LAA. Assuming each group has x logical addresses, LAA0 to LAA(x-1) is the 0th group, corresponding to a first-level mapping table (each group's first-level mapping table can occupy one or more 4K cells in its corresponding second-level mapping table), with a corresponding encoding value of 0. When the logical address of the write data is located in this group, the corresponding index value is 0. Similarly, LAAx to LAA(2x-1) is the first group, also corresponding to a first-level mapping table. Taking L1[0] as an example, it represents the 0th group. L1[0] points to a certain FAA of the mapped physical block 131. The 4K cells of this FAA store the mapping relationship of LAA 0 to LAA(x-1), that is, the FAAs corresponding to LAA 0 to LAA(x-1) are stored in order. LAA 0 to LAA(x-1) corresponds to L1cache index = 0, that is, the index value of the 0th block is set to 0, and the index value of the first block is set to 1...
[0061] Taking NAND flash memory as an example, NAND flash memory comprises multiple physical blocks, each physical block comprises multiple physical pages, and each physical page comprises multiple 4K (4KB) cells. The numbers within each 4K cell represent the programming order, which in turn represents the order in which physical addresses are written. Therefore, each physical block contains multiple 4K cells. Taking a 4K cell 10 of user physical block 132 as an example, it is divided into a data storage area and an address storage area. The data storage area stores write data, and the address storage area stores LAA (Least Access Address). This address storage area is, for example, called meta.
[0062] Multiple mapping relationships for write data are stored sequentially in cells 20 of cache unit 124. New mapping relationships added during system operation are stored in these cells 20. When the space occupied by the mapping relationships in cache unit 124 reaches a certain threshold, these mapping relationships are written to a designated mapping physical block 131. This mapping physical block is specifically used to store mapping relationships or mapping tables. The latest updated mapping relationships are still stored in a portion of the storage space of cache unit 124 because they cannot be updated in time or have not met the table flushing conditions.
[0063] In this step, when processing a write operation, the write data is stored in the user physical block 132 of the memory. Simultaneously, the index value corresponding to all write data in each user physical block 132 is recorded. Multiple index values form an index table. Furthermore, when recording index values, if the index values corresponding to two write data are the same, they only need to be recorded once. For example, when storing write data in the current user physical block blk22, if it is found that the L1 cache index of the current LAA has already been recorded, no processing is performed; if it is found that the L1 cache index of the current LAA has not been recorded, it is recorded.
[0064] For example, the index table is located in a specified 4K cell of the current user physical block, which is currently garbage collected (user physical block 132). This means the L1 cache index (index table) can be pre-defined in which 4K cells of blk22 are stored, such as the last one or more 4K cells of user physical block 132 where the write data resides. When retrieving the index table, only the last one or more 4K cells of the current user physical block need to be read to obtain the index values corresponding to all write data within that current user physical block. When blk22 is full of write data, the recorded index data is stored in the last one or more 4K cells of blk22, meaning the write data and the index table reside in the same current user physical block. Since many LAAs are often contiguous when writing data to blk22, multiple write data may have the same index value. Since only one record is needed, the index table occupies a small space, requiring only one 4K cell, resulting in minimal memory consumption and minimal overhead from reading these 4K cells.
[0065] Alternatively, the index table can be stored in a cache unit or in a designated physical block of memory. When the index table is stored in a designated physical block of memory, the index table, the secondary mapping table, and the write data are stored in different physical blocks of memory. For example, the recorded index table can be stored in another user physical block instead of blk22, but the location of the index table in the other user physical block needs to be recorded so that the index table corresponding to the current user physical block can be found.
[0066] Furthermore, when garbage collection is performed, the secondary mapping tables corresponding to all the write data stored in the current user physical block to be garbage collected are already stored in the mapping physical block of the memory. This can be achieved, for example, by controlling the read / write time and the table flushing time. Then, when garbage collection is performed, the secondary mapping table corresponding to the index table can cover the latest complete mapping relationship of all the write data.
[0067] In step S202, the index table corresponding to all write data in the current user physical block is read into the cache unit, and multiple different index values in the index table are obtained.
[0068] This step is the same as step S101, and will not be repeated here. When garbage collection selects blk22, the index table recorded in step S201 is first read into the cache unit, and then the next step is executed.
[0069] In step S203, the index table is traversed to read multiple index values one by one and obtain the corresponding target secondary mapping table.
[0070] This step is the same as step S102, and will not be repeated here.
[0071] In step S204, the target secondary mapping tables corresponding to multiple index values are loaded into the cache unit in sequence.
[0072] In this step, the index table is traversed, and the index values are taken one by one. When each index value is used as the current index value being processed, the target secondary mapping table corresponding to the current index value is loaded from the mapping physical block into the cache unit (SRAM). For example, if the current L1 cache index = 100, the secondary mapping table corresponding to L1 cache index = 100 is first loaded from the mapping physical block into the SRAM. After this secondary mapping table is processed, the next secondary mapping table is read into the SRAM.
[0073] In step S205, the secondary mapping table for each target is read.
[0074] In this step, for each index value, its corresponding target secondary mapping table is read, and steps S206-S209 are executed until the entire index table is traversed.
[0075] In step S206, each mapping record in the current target secondary mapping table is read.
[0076] In this step, the mapping records in each target secondary mapping table are traversed. For the current target secondary mapping table, the physical address corresponding to each mapping record in the target secondary mapping table is obtained, and then steps S207-S209 are executed until the entire target secondary mapping table is traversed.
[0077] In step S207, it is determined whether the physical address in each mapping record is located in the current user's physical block. If so, step S208 is executed.
[0078] In this step, for the target secondary mapping table corresponding to the current index value, the table is traversed to retrieve each mapping record. For each mapping record, the physical address is checked to see if it is located within the current user's physical block. This step indicates that the current physical address in the target secondary mapping table is located within the current user's physical block. If so, step S208 is executed to determine if the write data stored at that physical address is valid data; otherwise, the next physical address is retrieved and the check continues. When determining whether a physical address is located within the current user's physical block, for example, the block address contained in the physical address can be obtained, and its consistency with the block address of the current user's physical block can be checked.
[0079] Figure 5 A data structure diagram of physical addresses in a secondary mapping table according to an embodiment of the present invention is shown. Flash memory typically includes multiple DIEs (LUNs), each DIE may include two Planes (Plane0 and Plane1), each Plane includes multiple Blocks, each Block includes multiple Pages, and each Page has multiple page offsets (Frags). The physical address FAA is typically composed of the addresses of these different fields, and the specific physical location of data stored in the flash memory can be located through these different field addresses. Figure 5 As shown, the FAA is usually composed of Block, Page, LUN (i.e., Die) and Frag. That is, the physical address includes the block number (block address), logical unit number (LUN code), physical page address (Page), and page offset (Frag). The block address represents the physical block where the written data is located.
[0080] In this step, all FAAs contained in the retrieved target secondary mapping table are traversed. Based on the block value in the current FAA x, it is determined whether the current FAA x belongs to blk22. If the block value in the current FAA x is not equal to the block value in blk22, then the current FAA x is not in blk22. If the block value in the current FAA x is equal to the block value in blk22, then the current FAA x is in blk22, and further determination of whether the written data is valid is needed based on the LAA value corresponding to the current FAA x.
[0081] In step S208, it is determined whether the mapping record has a mapping relationship in the cache unit. If not, step S209 is executed.
[0082] In this step, for a physical address located in the current user physical block, it is checked whether the logical address corresponding to the physical address has a mapping relationship in the cache unit. Write data within a physical address whose logical address does not have a mapping relationship in the cache unit is considered valid data. The current user physical block includes multiple 4K cells that store multiple write data items and their corresponding logical addresses. The mapping relationship in the cache unit is determined by obtaining the logical address within the 4K cell. Since the mapping relationships of all write data within the current user physical block are stored in the mapping physical block of the memory during garbage collection, the logical address corresponding to the physical address located in the current user physical block and in the secondary mapping table is the logical address stored in the 4K cell represented by the physical address. The logical address corresponding to the mapping record in the secondary mapping table is equal to the physical address within the 4K cell. In other words, the logical address corresponding to the physical address obtained from the secondary mapping table is the same as the logical address stored in the 4K cell of that physical address. The logical address can be obtained using both methods.
[0083] However, during garbage collection, some written data was updated, and the corresponding mapping relationship was only stored in a portion of the cache space of storage unit 124, and had not yet been updated to the flash memory. At this time, it is necessary to determine whether there is a mapping relationship between the logical address and the SRAM. For example, check whether there is a mapping relationship between the logical address of the current physical address (e.g., 1aa33) in SRAM cell 20. If the corresponding faa for 1aa33 is not found in the SRAM mapping table cache, it means that after the mapping relationship between laa33 and its corresponding faa was stored in the mapping physical block, no operation such as deletion or writing new data to invalidate the existing mapping relationship was performed on the logical address laa33. In this case, the current L2P mapping relationship is valid, that is, the written data is valid data, and step S209 needs to be executed. If the SRAM query finds that 1aa33 has a corresponding faa and the corresponding faa is invalid, it means that the written data corresponding to laa33 has been deleted. In this case, the data of faax is invalid and does not need to be migrated. If the query finds the corresponding fa for 1aa33 and the corresponding fa is not equal to fa x, and they belong to different user physical blocks, it means that new data has been written to the logical address laa33 and the new written data exists in other user physical blocks, or it means that the written data corresponding to the logical address laa33 has been moved to other user physical blocks by the user. In this case, the data in the existing mapping relationship faax is invalid and does not need to be migrated.
[0084] In step S209, the write data corresponding to the mapping record is valid data, and data migration is performed.
[0085] In this step, the write data, which is considered valid data, is migrated to a new user physical block. Specifically, the write data stored in the 4K cell corresponding to the fAA x from the previous step is migrated.
[0086] Figure 6 A schematic diagram illustrating the process of garbage collection of valid data in a garbage collection method according to an embodiment of the present invention is shown. Figure 6 To perform garbage collection on the user physical blocks Block x and Block y that store the written data, the first step is to read out the valid data (ABC and DEFG respectively) from the two physical blocks, rewrite it into a new user physical block Block z, and then erase Block x and Block y to obtain two new usable user physical blocks.
[0087] After executing step S209, return to execute steps S206 until step S209 is completed, until the entire secondary mapping table corresponding to the current index value is traversed; then return to execute steps S205-S209 until the entire index table corresponding to the current user physical block is traversed.
[0088] The garbage collection method in this embodiment stores the index values of the write data. When performing garbage collection on the current user physical block, only the corresponding index value is read, without scanning all 4K cells of the entire current user physical block, greatly reducing overhead. Moreover, the index table corresponding to the index value may only occupy one or more 4K cells, so the additional space required to implement this embodiment is minimal and will not affect the write data. Furthermore, directly obtaining the secondary mapping table by looking up the index table to determine the validity of each write data makes the processing method more efficient and faster, reducing read operations on the user physical block. In addition, each mapping record in each secondary mapping table is traversed, and each record's physical address is checked to see if it is located in the current user physical block and if the corresponding write data is valid. Therefore, the same secondary mapping table corresponding to multiple write data stored in the current user physical block only needs to be loaded into SRAM once to uniformly determine whether these multiple write data are valid, avoiding frequent swapping of the mapping table in and out of SRAM and improving data processing performance. Even for valid data that is already in UNC, when determining whether the written data is valid and migrating the valid data, it can proactively detect that the valid data in the UNC cannot be read and cannot be migrated. At this time, the erroneous data can be handled in time through the UNC processing mechanism without passively waiting for the host's read operation. The error can be corrected immediately, the valid data can be moved, and after garbage collection is completed, the entire current user physical block can be immediately erased and reused, improving the utilization efficiency of the user physical block.
[0089] Figure 7A schematic block diagram of a solid-state drive according to an embodiment of the present invention is shown.
[0090] like Figure 7 As shown, the computer system 100 includes a host 110 and a solid-state drive (SSD). The SSD is a memory hard drive made of solid-state electronic storage chips. The SSD includes a controller 120 and a memory 130. The memory 130 is, for example, a flash memory. The controller 120 is connected to the host 110 and is used to exchange write data with the host 110. The memory 130 is, for example, a NAND flash memory chip array. The controller 120 connects the host 110 and the flash memory 130, storing the write data from the host 110 into the flash memory 130. The controller 120 is used to perform the above-described... Figures 2-6 Waste recycling methods.
[0091] The controller 120 includes a host interface 121, a processor 123, a cache unit 124, and a memory controller 128. The host interface 121 of the control system 120 is connected to the host 110 to transmit write data and read / write commands. The processor 123 is connected to the host interface 121, the cache unit 124, and the memory controller 128. The processor 123 is used, for example, to execute the aforementioned garbage collection method. The cache unit 124 is, for example, SRAM, which stores a first-level mapping table or index table corresponding to the write data. The memory controller 128 controls the transmission and storage of write data. The processor 123 is also used to implement the core software layer for memory control, namely the FTL (flash translation layer), enabling the operating system and file system to access the memory like a hard drive. This FTL also has features such as support for bad block management, wear leveling, garbage collection, power-off recovery, and write balancing techniques.
[0092] The memory 130 includes a flash memory chip array comprising multiple physical blocks for storing write data, mapping tables, or index tables. The physical block storing write data is called user physical block 132, while the physical block storing the mapping table is called mapping physical block 131. To improve data read / write performance, the memory controller 128 of the controller 120 can read and write to the flash memory chips of the memory 130 via multiple channels (e.g., CH0 and CH2). Each channel connects to a group of flash memory chips, storing the write data in user physical block 132. The controller 120 is also used to store a secondary mapping table (secondary mapping table) in physical block 131 (mapping physical block) of the memory 130 to prevent data loss and facilitate the recovery and retrieval of mapping table data. The physical blocks can be used not only to store write data and secondary mapping tables but also to store the index values corresponding to the write data to build an index table.
[0093] In summary, the garbage collection method and solid-state drive provided in this application obtain a secondary mapping table corresponding to the write data within the current user physical block by retrieving the index table. For each secondary mapping table, it checks whether the physical address in each mapping record is located within the current user physical block, thus initially determining whether the write data needs to be moved for garbage collection. This allows for the determination to be made simply by reading the index table and then referring to the secondary mapping table, without scanning the entire user physical block. Furthermore, obtaining the corresponding secondary mapping table through the index value and determining whether the write data is valid based on the mapping relationship results in higher garbage collection performance. Each secondary mapping table only needs to be traversed once, eliminating the need for frequent swapping in and out of cache units, saving overhead and accelerating the garbage collection process. This solves the problem of high garbage collection overhead caused by scanning the entire physical block to find valid data during garbage collection.
[0094] Furthermore, by dividing the logical addresses of the solid-state drive into multiple groups, each group corresponding to an encoded value, and the index value of the write data being the encoded value of the group containing the logical address of the write data, all mapping relationships corresponding to the write data within the current user physical block can be found by reading the index value of the write data within the current user physical block. The index value occupies less space, the overhead of reading the index value is small, and the secondary mapping table can be found quickly, accelerating the garbage collection process. Since the same index value is only recorded once, the same secondary table only needs to be called once, resulting in higher garbage collection performance. For valid data on the user physical block that has uncorrectable encoding errors, it can be identified as erroneous data during garbage collection, and thus corrected in time without affecting the migration of the valid data, allowing the user physical block to be erased in a timely manner.
[0095] It should be understood that the above method can be applied not only to solid-state drives (SSDs) but also to other types of storage devices such as eMMC and UFS. Like SSDs, eMMC and UFS storage devices have controllers and cache units, and the controller can implement the above method.
[0096] As described above, these embodiments of the present invention do not exhaustively cover all details, nor do they limit the invention to the specific embodiments described. Clearly, many modifications and variations can be made based on the above description. This specification selects and specifically describes these embodiments to better explain the principles and practical applications of the invention, thereby enabling those skilled in the art to effectively utilize the invention and its modifications. The invention is limited only by the claims and their full scope and equivalents.
Claims
1. A garbage collection method applied to a solid-state drive (SSD), the SSD including cache units and memory, the memory including multiple user physical blocks, wherein, The waste recycling method includes: When processing write operations, the index values corresponding to all write data in each user physical block are recorded to build an index table, and the same index value is recorded only once. The index value indicates the storage location of the secondary mapping table corresponding to the write data. Obtain the index table corresponding to all write data within the current user's physical block, wherein the index table includes at least one index value; Obtain at least one corresponding target secondary mapping table based on the index table; Iterate through each mapping record in the at least one target secondary mapping table and determine whether the physical address in each mapping record belongs to the current user's physical block; Determine whether the mapping record of the physical address belonging to the current user's physical block has a mapping relationship in the cache unit; When the mapping record does not have a mapping relationship in the cache unit, the write data corresponding to the mapping record is determined to be valid data. Move the valid data corresponding to the mapping record whose physical address belongs to the current user's physical block.
2. The waste recycling method according to claim 1, wherein, The index table is stored in the cache unit or in a designated user physical block of the memory.
3. The waste recycling method according to claim 1, wherein, The current user physical block includes multiple 4K cells, which store multiple write data, and the index table is located in a specified 4K cell of the current user physical block.
4. The waste recycling method according to claim 1, wherein, All logical addresses of the solid-state drive are divided into multiple groups, each group corresponding to an encoded value. The index value of the written data is the encoded value of the group in which the logical address of the written data belongs.
5. The waste recycling method according to claim 1, wherein, Following the step of obtaining at least one target secondary mapping table based on the index table, the method further includes: The target secondary mapping table corresponding to each index value is loaded into the cache unit sequentially.
6. The waste recycling method according to claim 1, wherein, The current user physical block includes multiple 4K cells that store the write data and its corresponding logical address respectively. The mapping record is determined to have a mapping relationship in the cache unit by obtaining the logical address in the 4K cell. The logical address is the logical address corresponding to the mapping record in the target secondary mapping table.
7. The waste recycling method according to claim 1, wherein, The secondary mapping tables corresponding to all the write data stored in the current user physical block that are to be garbage collected are stored in the mapping physical block of the memory.
8. The waste recycling method according to claim 1, wherein, The memory comprises multiple physical blocks, and the index table, the secondary mapping table, and the write data are stored in different physical blocks of the memory.
9. A solid-state drive, comprising: A processor, connected to a host, is configured to receive write data from the host and perform the garbage collection method according to any one of claims 1-8; A cache unit, connected to the processor, is used to store a first-level mapping table corresponding to the written data, and to store the mapping relationship between the logical address and the physical address of the written data; as well as A memory, connected to the processor, is used to store write data, a secondary mapping table, and an index table according to the control of the processor.
Citation Information
Patent Citations
Garbage recycling method of solid state discs
CN103744798A
Solid state disk garbage collection method and system, electronic equipment and storage medium
CN112765048A