Garbage collection method and device, solid state disk, host and readable storage medium
By using the use of the moving table and the merger table in the solid -state hard disk to simultaneously manage the waste recycling and user data writing process, the problem that affects the performance of the user's data writing of garbage recycling and achieves more efficient user data writing performance.
Patent Information
- Application Number
- CN202411401059.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-09
- Publication Date
- 2025-01-24
AI Technical Summary
Garbage collection will affect the writing performance of user data in solid-state drives, because the garbage collection process and user data writing process are mutually exclusive and difficult to perform synchronously.
By obtaining the migration table and merging table, determine whether the target is to be moved into the business data before moving the data to be invalid, and the LAA, which is valid in all the targets in the merger table to move The granularity of garbage recovery improves the synchronization of host writing and garbage recycling processes.
In the recovery process, the host is allowed to write data simultaneously to ensure the consistency of data from the data when writing data and moving data, reducing the impact of garbage recycling on user writing performance, and improving the writing performance of user data.
Smart Images

Figure CN119356606A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of solid state hard disks, and in particular to a garbage collection method, a device, a solid state hard disk, a host and a readable storage medium. Background Art
[0002] With the popularity of SSD (Solid State Drive), the requirements for its performance and stable writing are getting higher and higher. Due to the characteristics and strategies of data storage in SSD, that is, the minimum unit of writing is page, and the minimum unit of erasing is block, therefore, when deleting data, the data to be deleted is not physically deleted in the SSD but marked as invalid logically. As the use time increases, the invalid data in the SSD increases.
[0003] When there is too much invalid data in the SSD and insufficient available space, it is necessary to move the valid data in the block to another location and erase the current block, thereby clearing the invalid data in the current block and freeing up the storage space of the current block to store the data written subsequently. This is the GC (Garbage Collection) process.
[0004] When garbage collection is enabled, in order to ensure the validity of the data, the write resources used by the garbage collection process and the user data writing process are usually mutually exclusive. The two processes usually cannot be performed synchronously, so garbage collection will affect the writing performance of user data. Summary of the invention
[0005] The purpose of the present invention is to provide a garbage collection method, device, solid-state hard disk, host and readable storage medium, which reduce the granularity of garbage collection, improve the synchronization of host writing and garbage collection processes, and can reduce the impact of garbage collection on user data writing performance.
[0006] The embodiments of the present invention can be implemented as follows:
[0007] In a first aspect, the present invention provides a garbage collection method, which is applied to a solid state drive, and the method comprises:
[0008] Obtaining a to-be-moved table, wherein the to-be-moved table stores a physical address FAA of each of a plurality of to-be-moved data in a to-be-reclaimed block;
[0009] If the total length of the plurality of data to be moved is greater than or equal to the preset length, determining a plurality of target data to be moved whose total length is equal to the preset length from the plurality of data to be moved;
[0010] The logical address LAA corresponding to the FAA of each target data to be moved is stored in a pre-established merge table, wherein the table to be moved and the merge table are used to determine whether the target data to be moved becomes invalid due to parallel writing of business data before the move;
[0011] When the LAAs of all target data to be moved in the merge table are valid, the target data to be moved are moved, and when there is no data to be moved in the block to be reclaimed, the block to be reclaimed is reclaimed.
[0012] In an optional implementation manner, before the step of obtaining the table to be moved, the step further includes:
[0013] Obtaining the number of free super blocks in the solid state drive;
[0014] If the number of the free super blocks is less than the preset number, determining the used super block containing the largest amount of invalid data in the solid state drive as the block to be recycled;
[0015] Determining valid data in the block to be recycled;
[0016] The valid data is used as the data to be moved and the FAA of the data to be moved is stored in the table to be moved.
[0017] In an optional implementation manner, the block to be recycled includes a plurality of unit data, and the step of determining valid data in the block to be recycled includes:
[0018] For any target unit data among the plurality of unit data, obtaining the FAA of the target unit data;
[0019] Determine a reference LAA corresponding to the FAA of the target unit data from a preset P2L table, wherein the preset P2L table uses FAA as an index and represents a mapping relationship between FAA and LAA;
[0020] Determine a reference FAA corresponding to the reference LAA from a preset L2P table, where the L2P table uses LAA as an index and represents a mapping relationship between LAA and FAA;
[0021] If the FAA of the target unit data is equal to the reference FAA, the target unit data is determined to be valid data, and each valid data in the to-be-reclaimed block is finally determined.
[0022] In an optional implementation, all the target data to be moved are pre-read into the cache, and when the LAAs of all the target data to be moved in the merge table are valid, the step of moving the target data to be moved includes:
[0023] Acquire a write resource, where the write resource is used to achieve mutual exclusion between moving each of the target data to be moved and the write service data;
[0024] If the LAAs of all the target data to be moved in the merge table are valid, the target data to be moved in the cache is stored in a target block in the solid state drive that is different from the block to be reclaimed, so as to achieve the movement of the target data to be moved.
[0025] In an optional implementation, the solid state drive communicates with a host, and the method further includes:
[0026] Receive the to-be-written LAA of the service data sent by the host;
[0027] Determine the FAA to be written corresponding to the LAA to be written from a preset L2P table, where the L2P table uses LAA as an index and represents a mapping relationship between LAA and FAA;
[0028] If the FAA to be written is in the to-be-moved table, deleting the FAA to be written from the to-be-moved table;
[0029] If the LAA to be written is in the merge table, the LAA to be written in the merge table is set to invalid;
[0030] Acquire write resources and write the business data, wherein the write resources are used to achieve mutual exclusion between moving each of the target data to be moved and writing the business data.
[0031] In an optional implementation, the preset length is the total length of multiple pages located on the same die and in the same stripe in any super block of the solid state drive, and the blocks to which the multiple pages of the same stripe belong have the same sequence number and the page sequence number is also the same.
[0032] In a second aspect, the present invention provides a garbage collection device, applied to a solid state hard disk, the device comprising:
[0033] An acquisition module, used for acquiring a to-be-moved table, wherein the to-be-moved table stores a physical address FAA of each of a plurality of to-be-moved data in a to-be-reclaimed block;
[0034] a determination module, configured to determine, from the plurality of data to be moved, a plurality of target data to be moved whose total length is equal to the preset length if the total length of the plurality of data to be moved is greater than or equal to the preset length;
[0035] A merging module, used for storing the logical address LAA corresponding to the FAA of each target data to be moved into a pre-established merging table, wherein the table to be moved and the merging table are used to determine whether the target data to be moved becomes invalid due to parallel writing of business data before moving;
[0036] A moving module is used to move the target data to be moved when the LAAs of all the target data to be moved in the merge table are valid, and to recycle the block to be reclaimed when there is no data to be moved in the block to be reclaimed.
[0037] In a third aspect, the present invention provides a solid-state hard disk, comprising a controller and a memory, wherein the memory is used to store a program, and the controller is used to implement a garbage collection method as described in any one of the aforementioned embodiments when executing the program.
[0038] In a fourth aspect, the present invention provides a host, comprising a solid state drive as described in the aforementioned embodiment.
[0039] In a fifth aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a controller, implements a garbage collection method as described in any one of the aforementioned embodiments.
[0040] Compared with the prior art, the present invention has the following beneficial effects: the present invention obtains a to-be-moved table storing the physical address FAA of each of the multiple to-be-moved data in the to-be-reclaimed block; when the total length of the multiple to-be-moved data in the to-be-moved table is greater than or equal to the preset length, the target to-be-moved data whose total length is equal to the preset length is determined therefrom, and then the logical address LAA corresponding to the FAA of the target to-be-moved data is stored in the merge table; when the LAAs of all the target to-be-moved data in the merge table are valid, the target to-be-moved data is moved; and when there is no to-be-moved data in the to-be-reclaimed block, the to-be-reclaimed block is reclaimed; and whether the target to-be-moved data becomes invalid due to the parallel writing of business data before the move is determined through the to-be-moved table and the merge table; therefore, in the recovery process, the host is allowed to write data synchronously before the data is moved, and the data consistency of the host writing data and reading data when the data is moved can be guaranteed; and the granularity of garbage collection is reduced, the synchronization of the host writing and garbage collection processes is improved, and the impact of garbage collection on the user writing performance is reduced, thereby ultimately improving the writing performance of user data. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] 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.
[0042] Figure 1 This is an example diagram of the NAND flash memory organizational structure provided in this embodiment.
[0043] Figure 2 This is a block diagram of an example of a solid state drive provided in this embodiment.
[0044] Figure 3 This is an example flowchart of the garbage collection method provided in this embodiment.
[0045] Figure 4 An example comparison diagram of garbage collection according to different preset lengths provided for this embodiment.
[0046] Figure 5 This is an example diagram of the target data migration process provided in this embodiment.
[0047] Figure 6 This is an example diagram comparing the serial and parallel execution of the garbage collection process and the business data writing process provided in this embodiment.
[0048] Figure 7 This is an example block diagram of the garbage collection device provided in this embodiment.
[0049] Icons: 10 - solid state drive; 11 - controller; 12 - memory; 13 - host interface; 14 - flash memory controller; 20 - host; 100 - garbage collection device; 110 - acquisition module; 120 - determination module; 130 - merging module; 140 - moving module; 150 - writing module. DETAILED DESCRIPTION
[0050] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Generally, the components of the embodiments of the present invention described and shown in the drawings here can be arranged and designed in various different configurations.
[0051] Therefore, the following detailed description of the embodiments of the present invention provided in the accompanying drawings is not intended to limit the scope of the invention claimed for protection, but merely represents selected embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0052] It should be noted that similar reference numerals and letters denote similar items in the following drawings, and therefore, once an item is defined in one drawing, further definition and explanation thereof is not required in subsequent drawings.
[0053] In the description of the present invention, it should be noted that if the terms "upper", "lower", "inside", "outside", etc. appear to indicate an orientation or position relationship, they are based on the orientation or position relationship shown in the accompanying drawings, or are the orientation or position relationship in which the product of the invention is usually placed when used. They are only for the convenience of describing the present invention and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as a limitation on the present invention.
[0054] In addition, the terms “first”, “second”, etc., if used, are merely used to distinguish between the descriptions and should not be understood as indicating or implying relative importance.
[0055] It should be noted that, in the absence of conflict, the features in the embodiments of the present invention may be combined with each other.
[0056] First, the relevant concepts involved in this embodiment are explained.
[0057] NAND flash memory particles: composed of a large number of specific types of storage units, each of which can store one or more bits of data. These storage units are organized from small to large in the following order: cell, page, block, plane, and die.
[0058] Cell: It is the smallest working unit of flash memory and performs the task of data storage.
[0059] Page: The smallest unit of data that can be written in NAND flash memory.
[0060] Block: The smallest unit of data that can be erased independently in NAND flash memory. In an erase operation, the entire block must be erased together, and partial data within the block cannot be erased separately. A block consists of multiple pages.
[0061] Plane: A plane consists of multiple blocks.
[0062] Die: Also known as a logical unit (LUN, Logical Unit Number). A LUN can have one or more planes.
[0063] Super block: A super block consists of multiple blocks with the same serial number in multiple dies. Figure 1 , Figure 1 This is an example diagram of the NAND flash memory organizational structure provided in this embodiment.
[0064] Figure 1 In the chip, there are 4 dies: die0-die3, each die includes 2 planes: plane0-plane1, each plane includes M blocks: block0-blockM-1, and each block includes N pages: page0-pageN-1.
[0065] Garbage Collection (GC): Due to the physical characteristics of NAND flash memory particles, the minimum unit of writing is page, and the minimum unit of erasing is block. Therefore, when the host deletes data, it is not physically deleted in the SSD but will be logically marked as invalid data. Therefore, as the use time increases, the invalid data in the SSD increases. When there is too much invalid data in the SSD and there is insufficient available space, it is necessary to move the valid data in the block to another location and erase the current block to clear the invalid data, thereby freeing up space and making room for subsequent data writing. This is the process of garbage collection.
[0066] FAA: It is the physical address of the storage unit where data is written into the NAND flash memory, indicating the plane, block, page, offset, etc. to which the data should be written.
[0067] LAA: is the logical address of a storage unit in NAND flash memory.
[0068] P2L table: uses the physical address FAA of the data as the index and represents the mapping relationship between FAA and LAA.
[0069] L2P table: uses the logical address LAA of the data as the index and represents the mapping relationship between LAA and FAA.
[0070] When the garbage collection strategy is enabled, in order to ensure the consistency between the data that needs to be moved by garbage collection and the business data written by the host, one implementation method is: the garbage collection process and the write process are executed in series, and the garbage collection and write processes are executed in sequence, and the two processes cannot be executed at the same time. In this way, garbage collection will occupy the system resources of the host to write business data, which will reduce the performance of random writes and easily cause fluctuations in the performance of business data writing, thereby affecting the performance and latency of random writes.
[0071] In view of this, the present embodiment provides a garbage collection method, device, solid-state drive, host and readable storage medium, which can increase the synchronization between the garbage collection process and the business data process, and reduce the impact of garbage collection on user data writing performance. It will be described in detail below.
[0072] Please refer to Figure 2 , Figure 2 The block diagram of the solid-state drive 10 provided in this embodiment includes a controller 11, a memory 12, a host interface 13 and a flash memory controller 14. The solid-state drive 10 is connected to the host 20 via the host interface 13, the controller 11 is connected to the memory 12, the controller 11 is connected to the memory 12 via the flash memory controller 14, and the memory 12 includes NAND flash memory particles.
[0073] The controller 11 has signal processing capability, and each step of the garbage collection method of the above embodiment can be completed by an integrated logic circuit of hardware or software instructions in the controller 11. The controller 11 can also be responsible for operations such as creation, reading, and updating of management data such as L2P and P2L, and also performs various advanced functions to improve the performance, reliability, and durability of the solid state drive 10.
[0074] The NAND flash memory particles in the memory 12 are used to store a program for implementing the garbage collection method. The program can be stored in the memory 12 in the form of software or firmware.
[0075] The NAND flash memory particles in the memory 12 are also used to store the service data sent by the host 20. Each NAND flash memory particle contains one or more dies, each die contains one or more planes, each plane contains multiple blocks, and each block contains multiple pages. It can be understood by those skilled in the art that based on the different capacity settings of the NAND flash memory particles, dies, planes, blocks and pages, the number of dies contained in each NAND flash memory particle in the solid state drive 10, the number of blocks contained in each die, and the number of pages contained in each block can be different.
[0076] The host 20 communicates with the solid state drive 10 via the host interface 13 to send instructions for reading and writing business data to the solid state drive 10 .
[0077] based on Figure 3 The solid state drive 10 of this embodiment also provides an application Figure 2 For the garbage collection method of SSD 10, please refer to Figure 3 , Figure 3 This is an example flow chart of the garbage collection method provided in this embodiment, which includes the following steps:
[0078] Step S101, obtaining a to-be-moved table, the to-be-moved table storing a physical address FAA of each to-be-moved data in a plurality of to-be-moved data in a to-be-reclaimed block.
[0079] In this embodiment, the data to be moved is the data currently determined to be valid in the data of the block to be recovered. Only when all the data to be moved in the block to be recovered is the block to be recovered. The solid state drive 10 includes multiple super blocks, and the block to be recovered is the super block that needs to be recovered.
[0080] In this embodiment, it takes a while to determine the data to be moved, and during this period of time, the host 20 is allowed to write business data to the solid state drive 10 at the same time. If the FAA of the business data written by the host 20 during this time has been recorded in the table to be moved, it will cause the data corresponding to this FAA in the table to be moved to change from valid to invalid, and invalid data does not need to be moved. At this time, the FAA of the invalid data needs to be deleted from the table to be moved. Therefore, in order to ensure data consistency, when actually moving the data to be moved, it is necessary to determine again whether the FAA of the data to be moved is in the table to be moved.
[0081] Step S102 : if the total length of the plurality of data to be moved is greater than or equal to a preset length, a plurality of target data to be moved whose total length is equal to the preset length is determined from the plurality of data to be moved.
[0082] In this embodiment, the longer the preset length is, the longer it takes to move the data to be moved of the preset length, and the longer the time it occupies the write resources. Since the host 20 cannot continue to write business data due to the inability to obtain write resources when garbage collection is moving data, the impact on the write business data is also greater, and the fluctuation of write performance is also relatively large. In order to reduce the impact time on the write business data and reduce the fluctuation of write performance, the preset length can be set to the total length of multiple pages located on the same die and in the same stripe in any super block of the solid-state drive 10, the sequence number of the block to which multiple pages of the same stripe belong is the same, and the page sequence number is also the same. Please refer to Figure 4 , Figure 4An example comparison diagram of garbage collection according to different preset lengths provided in this embodiment, Figure 4 In the above, the preset length a is the total length of multiple pages in the same stripe in all dies in any super block, and the blocks to which multiple pages in the same stripe belong have the same sequence number and the page sequence number is also the same. The preset length b is the total length of multiple pages in the same die and in the same stripe in any super block, and the blocks to which multiple pages in the same stripe belong have the same sequence number and the page sequence number is also the same. The preset length a is greater than the preset length b. Figure 4 It can be seen that when garbage collection is performed according to the preset length a, longer write resources will be occupied each time, which will cause greater fluctuations in write performance. When garbage collection is performed according to the preset length b, the time for occupying write resources each time is relatively short, and the occupation per unit time is more balanced, and the fluctuation of write performance will be relatively small.
[0083] In this embodiment, if the total length of multiple data to be moved is less than the preset length, it means that the data to be moved that meets the data volume requirement has not been found. At this time, continue to wait for more LAAs of data to be moved to be stored in the to-be-moved table until the total length of multiple data to be moved is greater than or equal to the preset length, and execute steps S102-S103.
[0084] Step S103, storing the logical address LAA corresponding to the FAA of each target data to be moved into a pre-established merge table, the table to be moved and the merge table are used to determine whether the target data to be moved becomes invalid due to parallel writing of business data before moving.
[0085] Step S104, when the LAAs of all target data to be moved in the merge table are valid, the target data to be moved are moved and when there is no data to be moved in the block to be reclaimed, the block to be reclaimed is reclaimed.
[0086] In this embodiment, in order to improve the retrieval efficiency and quickly determine the corresponding LAA based on the FAA, as an implementation method, a hash calculation can be performed based on the FAA to determine the position in the merge table for storing the corresponding LAA.
[0087] In this embodiment, since a series of preparatory work needs to be done before actually moving the target data to be moved, such as reading the target data to be moved from the NAND flash memory particles and temporarily storing it in the cache, applying for write resources, etc., after the target data to be moved is determined and its LAA is written into the merge table until the write resources are applied, the host 20 is allowed to write business data to the solid-state drive 10 at the same time. If the LAA of the business data written by the host 20 during this period has been recorded in the merge table, the data corresponding to this LAA in the merge table will change from valid to invalid, and the invalid data does not need to be moved. At this time, the LAA in the merge table needs to be set to invalid. When actually moving the target data to be moved, it will be checked again whether the LAA of each target data to be moved is valid in the merged table. If the LAA of any target data to be moved is invalid, the move will be abandoned, that is, all target data to be moved will not be moved this time, and steps S102 and S103 will be re-executed. Wait until there is target data to be moved in the table to be moved that meets the preset length, and the block to be recycled will not be recycled until all valid data in the block to be recycled has been moved.
[0088] The above method provided in this embodiment determines whether the target data to be moved becomes invalid due to the parallel writing of business data before the move through the to-be-moved table and the merge table. Therefore, in the recovery process, the host is allowed to write data synchronously before the data is moved, and the data consistency of the host writing data and reading data when the data is moved can be guaranteed. The granularity of garbage collection is reduced, the synchronization of the host writing and garbage collection processes is improved, the impact of garbage collection on user writing performance is reduced, and the writing performance of user data is finally improved.
[0089] In an optional implementation manner, in order to further improve the efficiency of garbage collection, this embodiment provides an implementation method for generating a table to be removed:
[0090] First, obtain the number of free super blocks in the SSD;
[0091] Secondly, if the number of free super blocks is less than the preset number, the used super block containing the largest amount of invalid data in the solid state drive is determined as the block to be recycled;
[0092] In this embodiment, the free super block is a super block to which service data has not been written, and the preset number can be set according to actual needs, for example, the preset number is 8. If the number of free super blocks is greater than or equal to the preset number, it is considered that the condition for garbage collection has not been met, and garbage collection may not be started temporarily.
[0093] In this embodiment, each super block maintains a parameter representing the amount of valid data, and the parameter can be directly read to obtain the amount of valid data. In the process of writing business data, the parameter is continuously added, subtracted and updated according to data writing and erasing. The amount of invalid data in the super block can be known according to the total amount of data and the amount of valid data. The more invalid data a super block contains, the higher the benefit of recycling it. Therefore, the used super block containing the most invalid data is selected as the block to be recycled.
[0094] Third, determine the valid data in the block to be recycled;
[0095] In this embodiment, the block to be recycled includes multiple unit data, each unit data is 4K in size, and a page may include one or more 4K data. For any target unit data in the multiple unit data, the method of determining whether it is valid data is the same, and each valid data in the block to be recycled can be determined in the end.
[0096] This embodiment provides an implementation method for determining whether the target unit data is valid:
[0097] (1) Obtaining the FAA of the target unit data;
[0098] (2) determining a reference LAA corresponding to the FAA of the target unit data from a preset P2L table, where the preset P2L table uses FAA as an index and represents a mapping relationship between FAA and LAA;
[0099] (3) determining a reference FAA corresponding to the reference LAA from a preset L2P table, where the L2P table uses LAA as an index and represents a mapping relationship between LAA and FAA;
[0100] (4) If the FAA of the target unit data is equal to the reference FAA, the target unit data is determined to be valid.
[0101] In this embodiment, if the FAA of the target unit data is not equal to the reference FAA, the target unit data is determined to be invalid and the invalid data does not need to be moved.
[0102] In this embodiment, in order to traverse the unit data in the block to be recycled more conveniently and efficiently, the unit data at the same position in the page with the same sequence number in the block with the same sequence number in each die in the block to be recycled may be traversed each time. For example, the blocks in the to-be-reclaimed block come from 4 dies: die0-die3, each die includes M blocks: block0-blockM-1, each block includes N pages: page0-pageN-1, each page includes 4 4K, that is, 4 unit data, the first traversal is performed on the first 4K in page0 of block0 of each of die0, die1, die2, and die3, the second traversal is performed on the second 4K in page0 of block0 of each of die0, die1, die2, and die3, the third traversal is performed on the third 4K in page0 of block0 of each of die0, die1, die2, and die3, the fourth traversal is performed on the fourth 4K in page0 of block0 of each of die0, die1, die2, and die3, the fifth traversal is performed on the first 4K in page1 of block0 of each of die0, die1, die2, and die3, and the FAA of the to-be-moved data determined in each traversal is stored in the to-be-moved table.
[0103] Fourth, the valid data is used as the data to be moved and the FAA of the data to be moved is stored in the to-be-moved table.
[0104] In an optional implementation, all target data to be moved are pre-read into the cache, and after the logical address LAA corresponding to the FAA of each target data to be moved is stored in a pre-established merge table, the target data to be moved needs to be moved. This embodiment provides an implementation method for moving the target data to be moved:
[0105] (1) Obtaining write resources, where the write resources are used to achieve mutual exclusion between the data to be moved and the write business data of each target;
[0106] (2) If the LAAs of all target data to be moved in the merged table are valid, the target data to be moved in the cache is stored in a target block in the solid-state drive that is different from the block to be reclaimed, so as to achieve the migration of the target data to be moved.
[0107] In this embodiment, the process of actually moving the target data to be moved is also the process of writing the target data to be moved. During this process, the host 20 is not allowed to write business data to the solid-state drive 10. This embodiment uses write resources to achieve mutual exclusion between the two. Only the party that obtains the write resources can perform the desired write data operation. In order to ensure the validity of the actual moving target data to be moved, after obtaining the write resources, it will be judged again whether each target data to be moved is valid. The judgment method is: judge whether the LAA of each target data to be moved in the merged table is valid. If the LAA of all target data to be moved in the merged table is valid, then the target data to be moved is moved, otherwise the operation of moving the target data to be moved is abandoned.
[0108] To more clearly explain the process of moving the target data, please refer to Figure 5 , Figure 5 This is an example diagram of the target data migration process provided in this embodiment. Figure 5 In the block to be recovered, the valid data include data a1 stored in the first 4K (4K_1) of block0, page0 in die0, data a2 stored in the second 4K (4K_2) of block0, page0 in die1, data b1 stored in the second 4K (4K_2) of block0, page1 in die0, and data d2 stored in the fourth 4K (4K_4) of block0, page1 in die1. These valid data are moved to the first, second, third, and fourth 4K of blockX, pageY in die0 in the target block for storage respectively.
[0109] In this embodiment, since the host 20 is allowed to write business data to the solid-state drive 10 before the garbage collection process obtains the write resource, in order to ensure data consistency, this embodiment provides a method for implementing the host 20 writing business data:
[0110] First, receive the LAA to be written of the service data sent by the host;
[0111] Secondly, determine the FAA to be written corresponding to the LAA to be written from the preset L2P table, where the L2P table uses LAA as an index and represents the mapping relationship between LAA and FAA;
[0112] Third, if the FAA to be written is in the to-be-moved table, the FAA to be written is deleted from the to-be-moved table;
[0113] Fourth, if the LAA to be written is in the merged table, the LAA to be written in the merged table is set to invalid;
[0114] Fifth, obtain write resources and write business data. Write resources are used to achieve mutual exclusion between moving each target data to be moved and writing business data.
[0115] It can be seen from the above embodiments that the garbage collection process does not prohibit the business data writing process from being carried out simultaneously from the beginning. This embodiment divides the garbage collection process into three stages: generating a table to be moved, merging and reading the target data to be moved, and moving the target data to be moved. The two stages of generating a table to be moved and merging and reading the target data to be moved before the target data to be moved obtains the write resources allow the business data writing process to be carried out simultaneously. Therefore, compared with the serial execution of the garbage collection process and the business data writing process, the parallelism of the two is improved, the impact of the garbage collection process on the business data writing process is reduced, and the impact on the write performance is reduced.
[0116] For a clearer comparison of the two implementations, see Figure 6 , Figure 6 This is an example diagram comparing the serial and parallel execution of the garbage collection process and the business data writing process provided in this embodiment. Figure 6 In the garbage collection process, the garbage collection process includes establishing a valid data table (i.e. generating a table to be moved), reading data (i.e. merging and reading the target data to be moved), writing data (i.e. moving the target data to be moved), and writing business data (i.e. the writing process of business data). For the serial execution mode, the writing process of business data can only be executed in the two time periods of t1-t2 and t5-t6, while for the parallel execution mode, the writing process of business data can be executed in the two time periods of t1-t4 and t5-t6, and the execution time of the writing process of business data is significantly increased.
[0117] In order to execute the corresponding steps in the above embodiment and each possible implementation method, a method for implementing the garbage collection device 100 is given below. Figure 7 , Figure 7 This is a block diagram of the garbage collection device provided in this embodiment. It should be noted that the basic principles and technical effects of the garbage collection device 100 provided by the present invention are the same as those of the corresponding above-mentioned embodiments. For the sake of brief description, they are not mentioned in this embodiment.
[0118] The garbage collection device 100 includes an acquisition module 110 , a determination module 120 , a merging module 130 , a moving module 140 and a writing module 150 .
[0119] An acquisition module 110 is used to acquire a to-be-moved table, wherein the to-be-moved table stores a physical address FAA of each of a plurality of to-be-moved data in a to-be-reclaimed block;
[0120] The determination module 120 is configured to determine a plurality of target data to be moved whose total length is equal to the preset length from the plurality of data to be moved if the total length of the plurality of data to be moved is greater than or equal to the preset length;
[0121] The merging module 130 is used to store the logical address LAA corresponding to the FAA of each target data to be moved into a pre-established merging table. The table to be moved and the merging table are used to determine whether the target data to be moved becomes invalid due to parallel writing of business data before moving.
[0122] The moving module 140 is used to move the target data to be moved when the LAAs of all the target data to be moved in the merge table are valid, and to recycle the block to be recycled when there is no data to be moved in the block to be recycled.
[0123] In an optional implementation manner, the acquisition module 110 is further configured to:
[0124] Get the number of free super blocks in the solid state drive;
[0125] If the number of free super blocks is less than the preset number, the used super block containing the largest amount of invalid data in the solid state drive is determined as the block to be recycled;
[0126] Determine the valid data in the block to be recycled;
[0127] The valid data is taken as the data to be moved and the FAA of the data to be moved is stored in the to-be-moved table.
[0128] In an optional implementation, the block to be recycled includes a plurality of unit data, and the acquisition module 110 is used to:
[0129] For any target unit data among the multiple unit data, obtaining the FAA of the target unit data;
[0130] Determine a reference LAA corresponding to the FAA of the target unit data from a preset P2L table, where the preset P2L table uses FAA as an index and represents a mapping relationship between FAA and LAA;
[0131] Determine a reference FAA corresponding to the reference LAA from a preset L2P table, where the L2P table uses LAA as an index and represents a mapping relationship between LAA and FAA;
[0132] If the FAA of the target unit data is equal to the reference FAA, the target unit data is determined to be valid data, and each valid data in the block to be recovered is finally determined.
[0133] In an optional implementation, the moving module 140 is specifically used for:
[0134] Acquire write resources, which are used to achieve mutual exclusion between the data to be moved and the write business data of each target;
[0135] If the LAAs of all target data to be moved in the merged table are valid, the target data to be moved in the cache is stored in a target block in the solid-state drive that is different from the block to be reclaimed, so as to achieve the movement of the target data to be moved.
[0136] In an optional implementation, the solid state drive communicates with the host, and the write module 150 is used to:
[0137] Receive the pending LAA of the service data sent by the host;
[0138] Determine the FAA to be written corresponding to the LAA to be written from a preset L2P table, where the L2P table uses LAA as an index and represents a mapping relationship between LAA and FAA;
[0139] If the FAA to be written is in the to-be-moved table, the FAA to be written is deleted from the to-be-moved table;
[0140] If the LAA to be written is in the merged table, the LAA to be written in the merged table is set to invalid;
[0141] Acquire write resources and write business data. Write resources are used to achieve mutual exclusion between moving each target data to be moved and writing business data.
[0142] In an optional embodiment, the preset length in the garbage collection device 100 is the total length of multiple pages located on the same die and in the same stripe in any super block of the solid state drive, the blocks to which multiple pages of the same stripe belong have the same sequence number, and the page sequence numbers are also the same.
[0143] An embodiment of the present invention further provides a host, comprising the solid state hard disk as described in the above embodiment.
[0144] An embodiment of the present invention provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a controller, the garbage collection method in the aforementioned embodiment is implemented.
[0145] In summary, an embodiment of the present invention provides a garbage collection method, device, solid-state hard disk, host and readable storage medium, the method comprising: obtaining a to-be-moved table, the to-be-moved table storing the physical address FAA of each to-be-moved data among multiple to-be-moved data in a to-be-recovered block; if the total length of the multiple to-be-moved data is greater than or equal to a preset length, determining multiple target to-be-moved data with a total length equal to the preset length from the multiple to-be-moved data; storing the logical address LAA corresponding to the FAA of each target to-be-moved data in a pre-established merge table, the to-be-moved table and the merge table are used to determine whether the target to-be-moved data becomes invalid due to parallel writing of business data before moving; when the LAAs of all target to-be-moved data in the merge table are valid, the target to-be-moved data is moved and the to-be-recovered block is recycled when there is no to-be-moved data in the to-be-recovered block. Compared with the prior art, this embodiment has at least the following advantages: (1) It determines whether the target data to be moved becomes invalid due to the parallel writing of business data before the move through the to-be-moved table and the merge table. Therefore, in the recovery process, the host is allowed to write data synchronously before the data is moved, and the data consistency of the host writing data and reading data when the data is moved can be guaranteed, thereby improving the synchronization of the host writing and garbage collection processes; (2) Garbage collection is performed based on the total length of multiple pages located on the same die and in the same stripe in any super block of the solid-state drive as the preset length, thereby reducing the granularity of garbage collection, making the performance per unit time more average and balanced, and effectively reducing the fluctuation of write performance during garbage collection.
[0146] The above are only various embodiments of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art can easily think of changes or substitutions within the technical scope disclosed by the present invention, which should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.
Claims
1. A garbage collection method, characterized in that: Applied to a solid state drive, the method comprises: Obtaining a to-be-moved table, wherein the to-be-moved table stores a physical address FAA of each of a plurality of to-be-moved data in a to-be-reclaimed block; If the total length of the plurality of data to be moved is greater than or equal to the preset length, determining a plurality of target data to be moved whose total length is equal to the preset length from the plurality of data to be moved; The logical address LAA corresponding to the FAA of each target data to be moved is stored in a pre-established merge table, wherein the table to be moved and the merge table are used to determine whether the target data to be moved becomes invalid due to parallel writing of business data before the move; When the LAAs of all target data to be moved in the merge table are valid, the target data to be moved are moved, and when there is no data to be moved in the block to be reclaimed, the block to be reclaimed is reclaimed.
2. The garbage collection method according to claim 1, characterized in that: The step of obtaining the table to be moved also includes: Obtaining the number of free super blocks in the solid state drive; If the number of the free super blocks is less than the preset number, determining the used super block containing the largest amount of invalid data in the solid state drive as the block to be recycled; Determining valid data in the block to be recycled; The valid data is used as the data to be moved and the FAA of the data to be moved is stored in the table to be moved.
3. The garbage collection method according to claim 2, characterized in that: The block to be recycled includes a plurality of unit data, and the step of determining valid data in the block to be recycled includes: For any target unit data among the plurality of unit data, obtaining the FAA of the target unit data; Determine a reference LAA corresponding to the FAA of the target unit data from a preset P2L table, wherein the preset P2L table uses FAA as an index and represents a mapping relationship between FAA and LAA; Determine a reference FAA corresponding to the reference LAA from a preset L2P table, where the L2P table uses LAA as an index and represents a mapping relationship between LAA and FAA; If the FAA of the target unit data is equal to the reference FAA, the target unit data is determined to be valid data, and each valid data in the to-be-reclaimed block is finally determined.
4. The garbage collection method according to claim 1, characterized in that: All the target data to be moved are pre-read into the cache, and when the LAAs of all the target data to be moved in the merged table are valid, the step of moving the target data to be moved includes: Acquire a write resource, where the write resource is used to achieve mutual exclusion between moving each of the target data to be moved and the write service data; If the LAAs of all the target data to be moved in the merge table are valid, the target data to be moved in the cache is stored in a target block in the solid state drive that is different from the block to be reclaimed, so as to achieve the movement of the target data to be moved.
5. The garbage collection method according to claim 1, characterized in that: The solid state drive communicates with the host, and the method further comprises: Receive the to-be-written LAA of the service data sent by the host; Determine the FAA to be written corresponding to the LAA to be written from a preset L2P table, where the L2P table uses LAA as an index and represents a mapping relationship between LAA and FAA; If the FAA to be written is in the to-be-moved table, deleting the FAA to be written from the to-be-moved table; If the LAA to be written is in the merge table, the LAA to be written in the merge table is set to invalid; Acquire write resources and write the business data, wherein the write resources are used to achieve mutual exclusion between moving each of the target data to be moved and writing the business data.
6. The garbage collection method according to claim 1, characterized in that: The preset length is the total length of multiple pages located on the same die and in the same stripe in any super block of the solid state drive, and the blocks to which the multiple pages of the same stripe belong have the same sequence number, and the page sequence number is also the same.
7. A garbage collection device, characterized in that: Applied to a solid state hard disk, the device comprises: An acquisition module, used for acquiring a to-be-moved table, wherein the to-be-moved table stores a physical address FAA of each of a plurality of to-be-moved data in a to-be-reclaimed block; a determination module, configured to determine, from the plurality of data to be moved, a plurality of target data to be moved whose total length is equal to the preset length if the total length of the plurality of data to be moved is greater than or equal to the preset length; A merging module, used for storing the logical address LAA corresponding to the FAA of each target data to be moved into a pre-established merging table, wherein the table to be moved and the merging table are used to determine whether the target data to be moved becomes invalid due to parallel writing of business data before moving; A moving module is used to move the target data to be moved when the LAAs of all the target data to be moved in the merge table are valid, and to recycle the block to be reclaimed when there is no data to be moved in the block to be reclaimed.
8. A solid state hard disk, characterized in that: It comprises a controller and a memory, wherein the memory is used to store a program, and the controller is used to implement the garbage collection method according to any one of claims 1 to 6 when executing the program.
9. A host, characterized in that: Including the solid state drive as described in claim 8.
10. A computer-readable storage medium, characterized in that: A computer program is stored thereon, and when the computer program is executed by the controller, the garbage collection method as described in any one of claims 1-6 is implemented.
Citation Information
Cited By
Garbage collection method, storage device and readable storage medium
CN120066985A