Method and storage device for locating valid data in garbage collection
Patent Information
- Application Number
- CN202611136418.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-29
- Publication Date
- 2026-10-30
AI Technical Summary
[0004]然而,上述方案在数据顺序写或随机写范围不大的情况下效率较低,因为这种情况下,除了从闪存颗粒读取P2L表所需的时间开销(tR)外,还会引入大量的软件处理开销用于执行获取L2P表、以及数据对比等操作
[0024]与现有技术相比,本发明实施例通过记录待回收物理块对应的逻辑地址范围,并根据逻辑地址范围所指示的逻辑地址跨度与预设阈值的比较关系决定采用物理到逻辑映射表(P2L表)和逻辑到物理映射表(L2P表)混合的查询方式还是采用仅逻辑到物理映射表(L2P表)的查询方式来定位有效数据,由于预设阈值是基于读取逻辑地址范围内的物理到逻辑映射表(P2L表)所需的时间开销与在逻辑地址范围查询逻辑到物理映射表(L2P表)所需的时间开销的比较结果来确定,因此,所选出的方式能够更快速地获取L2P映射,从而更快速地定位出待回收物理块中的有效数据,有助于提升垃圾回收效率。同时,还可以通过以压缩表形式缓存连续的L2P映射,以便在有限的缓存空间中存储更多的映射关系,有助于进一步加快查表速度并优化缓存空间利用率。
Smart Images

Figure CN123011751A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of storage technology, and more specifically to a method and storage device for locating valid data in waste recycling. Background Technology
[0002] Solid-state drives (SSDs) are widely used in personal computing, data centers, and various embedded systems due to their high performance and low power consumption. Unlike traditional hard disk drives (HDDs), SSDs are based on flash memory chips, and their write operations must be performed on pre-erased physical blocks. Erasing operations are performed on a block-by-block basis and are significantly more time-consuming than read / write operations. This inherent hardware characteristic necessitates "erasure before write," leading to the introduction of garbage collection (GC) mechanisms.
[0003] In existing garbage collection technologies, a mainstream approach is for the firmware to first read the physical-to-logical mapping table (P2L table) stored in the physical block after determining which physical blocks need to be reclaimed. Then, the firmware obtains the logical-to-physical mapping table (L2P table). By comparing the information in the P2L table with the information in the L2P table, the firmware determines which physical pages in the physical block contain valid data. Finally, the identified valid data is migrated from the physical block to other free blocks, completing the garbage collection process.
[0004] However, the above scheme is less efficient when the range of sequential or random data writes is small. This is because, in addition to the time overhead (tR) required to read the P2L table from the flash memory chip, a large amount of software processing overhead is introduced to perform operations such as obtaining the L2P table and data comparison. Summary of the Invention
[0005] In view of this, embodiments of the present invention provide a method and storage device for locating valid data in waste recycling.
[0006] In a first aspect, embodiments of the present invention provide a method for locating valid data in waste recycling, applied to a storage device, the storage device including a controller and a storage medium coupled to the controller, the method comprising:
[0007] When writing data, the logical address range corresponding to the physical block where the data is written is recorded. The logical address range is used to indicate the start and end logical addresses of the data written in the physical block.
[0008] During garbage collection, it is determined whether the logical address span indicated by the logical address range of the physical block to be collected is less than or equal to a preset threshold. The preset threshold is determined based on the comparison between the time cost required to read the physical-to-logical mapping table and the time cost required to query the logical-to-physical mapping table.
[0009] If the logical address span indicated by the logical address range of the physical block to be reclaimed is less than or equal to a preset threshold, then the valid data in the physical block to be reclaimed is determined by querying the logical-to-physical mapping table.
[0010] In some embodiments, the method further includes: if the logical address span indicated by the logical address range of the physical block to be reclaimed is greater than a preset threshold, then determining valid data by reading the physical-to-logical mapping table of the physical block to be reclaimed and combining the logical-to-physical mapping table.
[0011] In some embodiments, the logical address range is stored in the metadata area of the physical block of the written data.
[0012] In some embodiments, determining the valid data in the physical block to be reclaimed by querying the logic-to-physical mapping table includes:
[0013] Query the logical-to-physical mapping table to obtain the physical address mapped to the logical address;
[0014] Determine whether the physical address points to the physical block to be reclaimed;
[0015] If so, the data corresponding to the logical address is determined to be valid data.
[0016] In some embodiments, the logical-to-physical mapping table is cached in the form of a compressed table, which represents a continuous logical address to physical address mapping relationship through a starting logical address, a starting physical address, and a consecutive count.
[0017] In some embodiments, determining the valid data in the physical block to be reclaimed by querying the logic-to-physical mapping table includes:
[0018] Determine whether the logical address range is a continuous mapping based on the compression table;
[0019] If so, then the data corresponding to the logical address range is directly determined to be valid data.
[0020] In some embodiments, garbage collection is performed when the number of valid data (VFC) of the physical blocks to be reclaimed is less than a set threshold.
[0021] Secondly, embodiments of the present invention provide a storage device, including: a controller coupled to a storage medium, wherein the controller performs the method described above.
[0022] In some embodiments, the controller includes only SRAM cache units.
[0023] Thirdly, embodiments of the present invention provide a controller for a storage device, the controller being coupled to a storage medium and performing the methods described above.
[0024] Compared with existing technologies, this invention records the logical address range corresponding to the physical blocks to be reclaimed. Based on a comparison between the logical address span indicated by the logical address range and a preset threshold, it determines whether to use a mixed query method of physical-to-logical mapping table (P2L table) and logical-to-physical mapping table (L2P table) or a query method using only the logical-to-physical mapping table (L2P table) to locate valid data. Since the preset threshold is determined by comparing the time cost of reading the P2L table within the logical address range with the time cost of querying the L2P table within the logical address range, the selected method can obtain L2P mappings more quickly, thereby locating valid data in the physical blocks to be reclaimed more quickly, which helps improve garbage collection efficiency. Simultaneously, by caching consecutive L2P mappings in a compressed table format, more mapping relationships can be stored in a limited cache space, further accelerating table lookup speed and optimizing cache space utilization. Attached Figure Description
[0025] The above and other objects, features and advantages of the present invention will become clearer from the following description of embodiments of the invention with reference to the accompanying drawings, in which:
[0026] Figure 1 This is a schematic block diagram of the host system;
[0027] Figure 2 This is an embodiment of the invention applied to... Figure 1 A flowchart illustrating a method for locating valid data during garbage collection on a storage device;
[0028] Figure 3 An example of a three-level mapping table is given;
[0029] Figure 4 A flowchart is provided for refreshing the third-level mapping table to the storage medium and loading the third-level mapping table from the storage medium into SRAM;
[0030] Figure 5 This is another embodiment of the invention applied to... Figure 1The flowchart illustrates a method for locating valid data during garbage collection on a storage device. Detailed Implementation
[0031] The present invention is described below based on embodiments, but the invention is not limited to these embodiments. In the detailed description of the embodiments below, certain specific details are described in detail. Those skilled in the art will fully understand the invention even without these detailed descriptions. To avoid obscuring the essence of the invention, well-known methods, processes, and procedures are not described in detail. Furthermore, the accompanying drawings are not necessarily drawn to scale.
[0032] The flowcharts and block diagrams in the accompanying drawings illustrate the possible system framework, functions, and operations of the system, method, and apparatus of the present invention. The blocks in the flowcharts and block diagrams may represent a module, program segment, or simply a piece of code. These modules, program segments, and code are all executable instructions used to implement a specified logical function. It should also be noted that the executable instructions implementing the specified logical function can be recombine to generate new modules and program segments. Therefore, the blocks and their order in the accompanying drawings are only used to better illustrate the processes and steps of the embodiments and should not be construed as limiting the invention itself.
[0033] Terminology Explanation:
[0034] The embodiments of the present invention may be presented in various forms, and some examples will be described below.
[0035] Figure 1 An example diagram of a host system 100 is shown. The host system 100 is, for example, a personal computer, a laptop, or a server.
[0036] The host system 100 includes a host device 110 and a storage device. The storage device may be, for example, a consumer SSD, an enterprise SSD, or a UFS device (a storage device using a UFS interface). The storage device consists of a controller 120 and storage media (e.g., flash memory chips) 130. The host device 110 issues host commands to the storage device, and the controller 120 manages the host data stored in the storage media 130 according to the commands. For example, the host device 110 issues read or write commands to the storage device through the host interface 121, and the controller 120 reads or writes host data from the storage media 130 according to the address range specified in the read or write commands.
[0037] The controller 120 includes a host interface 121, a processor 123, a cache unit 124, and a storage medium interface 128. The host interface 121 of the controller 120 is connected to the host device 110 and is used to cache and transmit host commands and host data. The processor 123 is connected to the host interface 121, the cache unit 124, and the storage medium interface 128; the processor 123 parses host commands and executes corresponding operations. The storage medium interface 128 includes interface circuitry for data transmission between the controller 120 and the storage medium 130.
[0038] Cache unit 124 is a key component of controller 120. Its core function is to act as a temporary high-speed storage area for data and instructions, including but not limited to: temporarily storing data to be written from the host and data to be returned from the storage medium; maintaining critical metadata such as the logical-to-physical mapping table frequently accessed by the translation layer (FTL); and loading and executing various programs (such as programs in the translation layer (FTL)) as working memory. Cache unit 124 typically uses SRAM and / or DRAM (DRAM is usually not part of the controller), but due to manufacturing cost limitations, the capacity of cache unit 124 is very limited.
[0039] In response to the problems raised in the background art, an embodiment of the present invention proposes a method applied to... Figure 1 The method for locating valid data during garbage collection on the storage device shown can form firmware and reside in cache unit 124. Figure 2 A flowchart of the method is provided.
[0040] like Figure 2 As shown, the method first executes step S201: when writing data, the logical address range corresponding to the physical block to which the data is being written is recorded. The logical address range includes the starting logical address (start_lba) and the ending logical address (end_lba) of the data already written within the physical block. If multiple writes occur, the starting and ending logical addresses of the earlier writes are updated based on the starting and ending logical addresses of the subsequent data writes, thereby ensuring that the logical addresses corresponding to all physical pages of data already written within each physical block are included within the logical address range corresponding to the starting and ending logical addresses.
[0041] Next, in step S202, during garbage collection, the logical address range of the physical block to be collected is obtained, and it is determined whether the logical address span indicated by it is less than or equal to a preset threshold (Lba_gap). The preset threshold (Lba_gap) is predetermined based on a comparison between the time cost required to read data from the physical-to-logical mapping table (P2L) and the time cost required to search the logical-to-physical mapping table (L2P) in cache unit 124 via General-Purpose Direct Memory Access (GDMA).
[0042] If the logical address span is greater than the preset threshold, then step S204 is executed, which is to adopt the traditional garbage collection process: first read the physical-to-logical mapping table of the physical block to be collected, and then combine the logical-to-physical mapping table to determine the valid data page.
[0043] If, in step S202, it is determined that the logical address span is less than or equal to the threshold, then step S203 is executed: the valid data in the physical block to be reclaimed is determined by querying the logical-to-physical mapping table. Specifically, the read start and end logical addresses are used as the query range. All data entries within this range are retrieved from the logical-to-physical mapping table. It is determined whether the physical address pointed to by each data entry belongs to the physical block to be reclaimed. If it does, the physical page corresponding to that entry is marked as containing valid data; otherwise, the physical page corresponding to that entry does not contain valid data. Through this process, when the data logical address continuity is good (i.e., the logical address span is small), the overhead of reading the physical-to-logical mapping table is avoided. Instead, valid data is quickly located directly through the logical-to-physical mapping table, thereby improving the efficiency of locating valid data during garbage collection.
[0044] Taking a CPU clock frequency of 500MHz, a bus width of 32 bits, and a flash memory model of B16A (corresponding to a tR of 51us for a TLC physical block, a tR of 42us for an SLC physical block, SLC physical block: 768, TLC physical block: 2304, 4 flash memory chips (dies)) as an example, a P2L physical page size is 16K, there are 6 P2L physical pages on SLC, and 18 P2L physical pages on TLC. The time required to access 4 bytes is 2ns. The corresponding threshold on an SLC physical block can be calculated according to the following equation: SLC: 42*1000*4*6 / 2=504000;
[0045] TLC: 51*1000*4*18 / 2=1836000;
[0046] If Lba_gap is greater than 84000 (i.e. 504000 / 6) on the SLC, the process of obtaining the P2L entry and then querying the L2P table using the P2L entry is executed (i.e. step S204). Otherwise, the process of directly querying the L2P table to determine the valid data is executed (i.e. step S203).
[0047] On TLC, if lba_gap is greater than 102000 (i.e. 1836000 / 18), the process of obtaining P2L entries and then querying the L2P table using P2L entries is executed (i.e. step S204). Otherwise, the process of directly querying the L2P table to determine valid data is executed (i.e. step S203).
[0048] L2P tables can be implemented using two-level or three-level mapping tables. Figure 3 An example of a three-level mapping table is given. In this three-level mapping table, the first-level mapping table L1_Table stores the physical address L2_TPAA of the second-level mapping table L2_Table, the second-level mapping table L2_Table stores the physical address L3_TPAA of the third-level mapping table L3_Table, and the third-level mapping table L3_Table stores the physical address PAA of the physical page. (Reference) Figure 3 As shown, the data management unit TBMT1 of the second-level mapping table stores, for example, 1024 records. Each record records the physical address L3_TPAA of a third-level mapping table. The data management units DBMT1, DBMT2, and DBMT3 of the third-level mapping table also each store, for example, 1024 records. Each record records the physical address PAA of a physical page. When looking up a table, L3_TLAA (which can be obtained by taking the low-order bits of LAA) is used as the offset to find the corresponding PAA in DBMT.
[0049] Figure 4 A flowchart is provided for refreshing the third-level mapping table to the storage medium and loading the third-level mapping table from the storage medium into SRAM. In this process, the refresh and loading are performed in units of DBMT.
[0050] As shown in the figure, steps S401 and S402 refer to the firmware determining whether there are consecutive records in the DBMT when flashing the current DBMT. If so, the start logical address (start_lba), start_pba (start physical address), and consecutive count (seq_cnt) of the consecutive records are recorded in the metadata during the DBMT flashing process. Steps S403 to S405 refer to the process of obtaining the relevant metadata when loading the DBMT from the storage medium, re-establishing the correspondence between start_lba, start_pba, and seq_cnt based on the metadata, and finally, step S406 releases the SRAM occupied by the compressed records.
[0051] Figure 5 This is another embodiment of the invention applied to... Figure 1 The flowchart shows a method for improving garbage collection efficiency on a storage device.
[0052] Step S501 is to determine whether the logical address span end_lba-start_lba of the physical block to be reclaimed is less than or equal to lba_gap. If yes, then proceed to step S508; otherwise, proceed to step S502.
[0053] Steps S502 to S503 involve obtaining the P2L mapping and the corresponding DBMT within the corresponding interval in the DBMT.
[0054] Step S504 is to determine whether the corresponding metadata in the physical block to be reclaimed records seq_cnt. If seq_cnt is recorded, then proceed to step S506; otherwise, proceed to step S505.
[0055] Step S506 is to cache the L2P mapping in the form of seq_cnt.
[0056] Step S505 is to directly store the L2P mapping.
[0057] Step S507 involves comparing the P2L mapping and the L2P mapping to determine the physical pages containing valid data in the physical blocks to be reclaimed.
[0058] Step S508 is to obtain the L2P mapping of the corresponding interval in DBMT based on start_lba and end_lba.
[0059] Step S509 is to determine whether the metadata of the physical block to be reclaimed is recorded as seq_cnt. If it is, then proceed to step S510; otherwise, proceed to step S512.
[0060] Step S510 is to cache the L2P mapping in the form of seq_cnt.
[0061] Step S511 is to obtain a contiguous PAA based on the cached L2P mapping, and mark the physical pages of the contiguous PAA as physical pages containing valid data.
[0062] Step S512 involves storing the L2P mapping of the corresponding interval in SRAM.
[0063] Step S513 obtains the PAA pointing to the physical block to be reclaimed from the L2P mapping in SRAM from step 512, and marks it as a physical page containing valid data.
[0064] In this embodiment, when the DBMT is flushed, if there are consecutive records, the seq_cnt is recorded in the metadata. Then, when locating valid data during garbage collection, if the seq_cnt is obtained from the metadata of the physical block to be reclaimed, it means that the L2P mapping corresponding to the physical block contains consecutive records. The consecutive records contained can be compressed using start_lba, start_pba, and seq_cnt. In this way, the space occupied by the L2P mapping is reduced.
[0065] Accordingly, embodiments of the present invention also provide a computer-readable storage medium for storing readable computer instructions of a software program constructed based on the method provided in the embodiments of the present invention.
[0066] As used herein, the term "module" may refer to, be part of, or include the following: application-specific integrated circuits (ASICs), electronic circuits, processors (shared, dedicated, or grouped) and / or memories (shared, dedicated, or grouped) that execute one or more software or firmware programs, combinational logic circuits, and / or other suitable components that provide the described functionality.
[0067] Those skilled in the art will understand that the various modules or units of the data processing system according to the present invention can be implemented by hardware, firmware, or software. Software includes, for example, coded programs written in various programming languages such as JAVA, C / C++ / C#, and SQL. Although the steps and their order are given in the methods and method diagrams of embodiments of the present invention, the executable instructions that implement the specified logical functions of the steps can be recombined to generate new steps. The order of the steps should not be limited to the order shown in the methods and method diagrams, and can be adjusted at any time according to functional needs. For example, some steps can be executed in parallel or in reverse order.
Claims
1. A method for locating valid data in waste collection, applied to a storage device, the storage device including a controller and a storage medium coupled to the controller, the method comprising: When writing data, the logical address range corresponding to the physical block where the data is written is recorded. The logical address range is used to indicate the start and end logical addresses of the data written in the physical block. When performing garbage collection, it is determined whether the logical address span indicated by the logical address range of the physical block to be collected is less than or equal to a preset threshold. The preset threshold is determined based on the comparison between the time cost required to read the physical-to-logical mapping table and the time cost required to query the logical-to-physical mapping table. If the logical address span indicated by the logical address range is less than or equal to a preset threshold, the valid data in the physical block to be reclaimed is determined by querying the logical-to-physical mapping table.
2. The method according to claim 1, further comprising: If the logical address span indicated by the logical address range is greater than a preset threshold, then valid data is determined by reading the physical-to-logical mapping table and combining it with the logical-to-physical mapping table.
3. The method according to claim 1, wherein, The logical address range is stored in the metadata area of the physical block where the data is written.
4. The method according to claim 1, wherein, The step of determining the valid data in the physical block to be reclaimed by querying the logical-to-physical mapping table includes: Query the logical-to-physical mapping table to obtain the physical address mapped to the logical address; Determine whether the physical address points to the physical block to be reclaimed; If so, the data corresponding to the logical address is determined to be valid data.
5. The method according to claim 1, wherein, The logical-to-physical mapping table is cached in the form of a compressed table. The compressed table represents a continuous logical address to physical address mapping relationship through the starting logical address, the starting physical address, and the consecutive count.
6. The method according to claim 5, wherein, The step of determining the valid data in the physical block to be reclaimed by querying the logical-to-physical mapping table includes: Determine whether the logical address range is a continuous mapping based on the compression table; If so, then the data corresponding to the logical address range is directly determined to be valid data.
7. The method according to claim 1, wherein, Garbage collection is performed when the number of valid data (VFC) of the physical block to be recycled is less than a set threshold.
8. A controller for a storage device, comprising a memory and a processor, the memory storing a computer program, the processor executing the computer program to implement the method as described in any one of claims 1 to 7.
9. The controller according to claim 8, wherein, The controller includes only SRAM as a cache unit.
10. A storage device, characterized in that, Includes the controller of the storage device as described in claim 9.
