Garbage collection method, device, readable storage medium and electronic device
By judging the target effective data unit continuity and the same data page, and using multiple plane read operations to read the continuous effective data unit sequence into the cache at one time, solving the problem of inefficient garbage collection in the prior art, and improving the writing speed and overall efficiency of flash memory.
Patent Information
- Application Number
- CN202110110989.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-01-27
- Publication Date
- 2025-08-12
- Estimated Expiration
- 2041-01-27
AI Technical Summary
In the prior art, the inefficiency caused by moving effective data units one by one during the garbage collection process is significantly affected by the performance of the memory card in particular during the H2 full disk test.
By making continuity judgment on the target effective data unit and the same data page judgment, a continuous sequence of valid data units is determined, and it is read into the cache at one time using multiple plane reading.
It significantly improves the writing speed of flash memory to collect data, and thus improves the efficiency of garbage collection.
Smart Images

Figure CN112905496B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of memory data management, and in particular to a garbage collection method, device, readable storage medium and electronic device. Background Art
[0002] After using the eMMC (Embedded Multi Media Card) firmware for a period of time, the card's available storage cells decrease, leading to a shortage of free blocks. Consequently, the card will perform garbage collection (GC). During garbage collection, valid data units in the block to be recycled need to be moved to new blocks for storage. The current approach involves reading valid data units one by one in 4KB increments, using 4KB as the minimum unit. When the buffer contains a page of data, the data is moved to the new block. While this straightforward garbage collection method provides a simple and direct way to garbage collect data, when using the H2testw tool to perform an H2 full disk test on a memory card, the majority of valid data units are contiguous, significantly slowing down the garbage collection process and reducing the efficiency of the H2 full disk test. Summary of the Invention
[0003] The technical problem to be solved by the present invention is to provide a method, device, readable storage medium and electronic device for garbage collection, which can improve the efficiency of garbage collection.
[0004] In order to solve the above technical problems, the technical solution adopted by the present invention is:
[0005] A garbage collection method comprises the steps of:
[0006] Receive garbage collection requests and read valid data units on the data blocks to be recovered;
[0007] For the read target valid data unit, determining valid data units that are in the same data page as the target valid data unit and that are consecutive starting from the position of the target valid data unit, to obtain a valid data unit sequence;
[0008] The valid data unit sequence is read into the cache through a multi-plane read method.
[0009] In order to solve the above technical problems, another technical solution adopted by the present invention is:
[0010] A garbage recycling device, comprising:
[0011] A receiving module, used for receiving garbage collection requests;
[0012] A judgment module is configured to determine, for a read target valid data unit, valid data units that are in the same data page as the target valid data unit and are continuous starting from the position of the target valid data unit, to obtain a valid data unit sequence;
[0013] A reading module is used to read the valid data unit sequence into the cache through a multi-plane reading method.
[0014] In order to solve the above technical problems, another technical solution adopted by the present invention is:
[0015] A computer-readable storage medium stores a computer program, which implements the various steps of the above-mentioned garbage collection method when executed by a processor.
[0016] In order to solve the above technical problems, another technical solution adopted by the present invention is:
[0017] An electronic device includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, each step in the above-mentioned garbage collection method is implemented.
[0018] The beneficial effect of the present invention is that after receiving a garbage collection request, it determines the continuous valid data units that are in the same data page as the target valid data unit and start at the position of the target valid data unit, and reads the continuous valid data unit sequence composed of multiple valid data units into the cache through a multi-plane read method through a read operation. Compared with the existing reading method of reading only one valid data unit per read operation, the present invention can read out the continuous valid data units at one time through a multi-plane read operation and write them into the target data block at the same time, which significantly improves the writing speed of the flash memory for the data to be recovered, thereby improving the efficiency of garbage collection. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] Figure 1 A flowchart of a garbage collection method according to an embodiment of the present invention;
[0020] Figure 2 A schematic diagram of reading valid data units in a garbage collection method according to an embodiment of the present invention;
[0021] Figure 3 A flowchart of another step of a garbage collection method according to an embodiment of the present invention;
[0022] Figure 4 This is a graph showing the results of a H2 full disk test in the prior art;
[0023] Figure 5 This is a graph showing the H2 full disk test results of a garbage collection method according to an embodiment of the present invention;
[0024] Figure 6 This is another structural schematic diagram of a garbage collection device according to an embodiment of the present invention;
[0025] Figure 7 The figure is a schematic structural diagram of an electronic device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0026] To illustrate the technical content, achieved objectives and effects of the present invention in detail, the following description is given in conjunction with the embodiments and accompanying drawings.
[0027] Please refer to Figure 1 , an embodiment of the present invention provides a method for garbage collection, comprising the steps of:
[0028] Receive garbage collection requests and read valid data units on the data blocks to be recovered;
[0029] For the read target valid data unit, determining valid data units that are in the same data page as the target valid data unit and that are consecutive starting from the position of the target valid data unit, to obtain a valid data unit sequence;
[0030] The valid data unit sequence is read into the cache through a multi-plane read method.
[0031] From the above description, it can be seen that the beneficial effect of the present invention is that: after receiving a garbage collection request, the valid data units that are in the same data page as the target valid data unit and start from the position of the target valid data unit are determined, and the continuous valid data unit sequence composed of multiple valid data units is read into the cache through a multi-plane read method through a read operation. Compared with the existing reading method of reading only one valid data unit per read operation, the present invention can read out the continuous valid data units at one time through a multi-plane read operation and write them into the target data block at the same time, which significantly improves the writing speed of the flash memory for the data to be recovered, thereby improving the efficiency of garbage collection.
[0032] Further, the determining of the valid data units that are in the same data page as the target valid data unit and that are continuous starting from the position of the target valid data unit includes:
[0033] During each read operation, a continuity judgment and a same data page judgment are performed on the target valid data unit to determine whether the target valid data unit currently being read is continuous with the target valid data unit to be read next and belongs to the same data page. If they are continuous and belong to the same data page, the target valid data unit currently being read is added to the valid data unit sequence, and the target valid data unit to be read next is set as the target valid data unit currently being read, and the steps of performing the continuity judgment and the same data page judgment on the target valid data unit are returned to be executed until a valid data unit that is not continuous with the target valid data unit currently being read or does not belong to the same data page appears;
[0034] If they are not continuous or do not belong to the same data page, the valid data unit currently read is added to the valid data unit sequence.
[0035] From the above description, it can be seen that by performing continuity judgment and same data page judgment on the target valid data unit, and when the target valid data unit currently being read is continuous with the target valid data unit to be read next time and belongs to the same data page, the target valid data unit to be read next time is added to the valid data unit sequence to achieve continuous reading, thereby improving the reading efficiency of the flash memory for the data to be recovered.
[0036] Furthermore, the continuity judgment includes:
[0037] If the difference between the physical position of the currently read target valid data unit and the physical position of the next target valid data unit to be read is 1, the currently read target valid data unit and the next target valid data unit to be read are consecutive units.
[0038] From the above description, it can be seen that by comparing the physical position of the target valid data unit currently being read with the physical position of the target valid data unit to be read next time, when the difference between the two is 1, it means that the two valid data units are continuous valid data units, which simply and effectively judges the continuity of the valid data units and improves the efficiency of continuity judgment.
[0039] Furthermore, the same data page determination includes:
[0040] Dividing the physical position of the currently read target valid data unit by the number of data units included in a data page to obtain a first data page value of the currently read target valid data unit;
[0041] Dividing the physical position of the target valid data unit to be read next time by the number of data units included in a data page to obtain a second data page value of the target valid data unit to be read next time;
[0042] If the first data page value and the second data page value are the same, the target valid data unit currently being read and the target valid data unit to be read next time belong to the same data page.
[0043] From the above description, it can be seen that by comparing the first data page value of the target valid data unit currently being read with the second data page value of the target valid data unit to be read next time, when the first data page value is equal to the second data page value, it means that the two valid data units are valid data units on the same data page, so that during multi-plane read operations, multiple consecutive valid data units on the same data page can be read out through one read operation, thereby improving the reading efficiency of the flash memory for recovered data.
[0044] Furthermore, before the continuity judgment and the same data page judgment of the target valid data unit are performed, the method further includes the following steps:
[0045] Determine whether the sum of the number of valid data units in the cache and the number of valid data units in the valid data unit sequence reaches the preset capacity of the cache; if so, read the valid data unit sequence into the cache through multi-plane reading; if not, perform continuity judgment and same data page judgment on the target valid data unit.
[0046] From the above description, it can be seen that by judging whether the sum of the number of valid data units in the cache and the number of valid data units in the valid data unit sequence reaches the preset capacity of the cache, the length of the valid unit sequence is limited, thereby avoiding the situation where the number of valid data units exceeding the operable range is read during garbage collection, making it impossible to perform normal garbage collection operations for the valid data units exceeding the operable range, thereby improving the stability of garbage collection.
[0047] Furthermore, the preset capacity is the parallelism of the data units on the flash memory.
[0048] From the above description, it can be seen that by adaptively increasing the preset capacity of the cache according to the parallelism of valid data units on different flash memory devices, multi-plane read operations can operate on valid data units within the maximum operable range, thereby improving the stability of garbage collection.
[0049] Please refer to Figure 6 Another embodiment of the present invention provides a garbage collection device, comprising:
[0050] A receiving module, used for receiving garbage collection requests;
[0051] A judgment module is configured to determine, for a read target valid data unit, valid data units that are in the same data page as the target valid data unit and are continuous starting from the position of the target valid data unit, to obtain a valid data unit sequence;
[0052] A reading module is used to read the valid data unit sequence into the cache through a multi-plane reading method.
[0053] Another embodiment of the present invention provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the computer program implements the steps in the above-mentioned garbage collection method.
[0054] Please refer to Figure 7 Another embodiment of the present invention provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements each step of the above-mentioned garbage collection method when executing the computer program.
[0055] The garbage collection method, device, computer-readable storage medium, and electronic device of the present invention can be applied to various types of flash memory devices for garbage collection, and are described below through specific implementations:
[0056] Example 1
[0057] Please refer to Figure 1 , a garbage collection method comprising the steps of:
[0058] S1. Receive a garbage collection request and read the valid data units on the data block to be recovered;
[0059] The location information of all valid data units on the data block is recorded in the valid data table. During reading, the valid data units are read out according to the valid data table. The valid data table is a special address parameter table. Before GC relocation, all data on multiple blocks is scanned, and a table is created to record the addresses of valid data in this table. The relocated data is read according to this table until the destination TLC block is full. The amount of valid data scanned exceeds the amount of data that can be written to the destination block. When the destination block is full, the valid data table is invalidated, and the remaining valid data that has not been relocated and other blocks are scanned again to form a new valid data table, and then relocated to the next destination block.
[0060] S2. For the read target valid data unit, determine the valid data units that are in the same data page as the target valid data unit and that are consecutive starting from the position of the target valid data unit, to obtain a valid data unit sequence;
[0061] Specifically, during each read operation, a continuity judgment and a same data page judgment are performed on the target valid data unit to determine whether the target valid data unit currently being read is continuous with the target valid data unit to be read next and belongs to the same data page. If they are continuous and belong to the same data page, the target valid data unit currently being read is added to the valid data unit sequence, and the target valid data unit to be read next is set as the target valid data unit currently being read, and the process of performing the continuity judgment and the same data page judgment on the target valid data unit is returned to execution until a valid data unit that is not continuous with the target valid data unit currently being read or does not belong to the same data page appears.
[0062] If they are not continuous or do not belong to the same data page, the valid data unit currently read is added to the valid data unit sequence;
[0063] S3. Read the valid data unit sequence into the cache through a multi-plane read method;
[0064] Continuity judgment includes:
[0065] Performing continuity judgment on the target valid data unit, if the difference between the physical position of the target valid data unit currently read and the physical position of the target valid data unit to be read next is 1, then the target valid data unit currently read and the target valid data unit to be read next are continuous units;
[0066] The same data page judgment includes:
[0067] Performing a same data page determination on the target valid data unit, dividing the physical position of the currently read target valid data unit by the number of data units included in a data page to obtain a first data page value of the currently read target valid data unit;
[0068] Dividing the physical position of the target valid data unit to be read next time by the number of data units included in a data page to obtain a second data page value of the target valid data unit to be read next time;
[0069] If the first data page value and the second data page value are the same, the target valid data unit currently being read and the target valid data unit to be read next time belong to the same data page;
[0070] For details, please refer to Figure 2, suppose a flash memory has two planes, plane0 and plane1. Each page of plane0 and plane1 contains four 4K data units. For example, page0 in plane0 contains 0, 1, 2 and 3, a total of four 4K data units, and page0 in plane1 contains 4, 5, 6 and 7, a total of four 4K units. Among them, all eight 4K belong to page0;
[0071] For example Figure 2 The valid data shown is read for valid data units. For example, the target valid data unit currently being read is the 4K data unit at physical position 0 on page 0 in plane 0, and the target valid data unit to be read next time is the 4K data unit at physical position 1 on page 0 in plane 0. According to continuity judgment, the difference between physical position 0 and physical position 1 is 1. Therefore, the 4K data unit at physical position 0 on page 0 in plane 0 and the 4K data unit at physical position 1 on page 0 in plane 0 are two consecutive valid 4K data units.
[0072] The target valid data unit currently being read is the 4KB data unit at physical position 0 on page 0 in plane 0. That is, the physical position of the target valid data unit currently being read is 0, and the data units contained in page 0 are 8 4KB. Dividing 0 by 8 gives a result of 0, and the remainder is 8. Therefore, the first data page value of the 4KB data unit at physical position 0 on page 0 in plane 0 is 0.
[0073] The target valid data unit to be read next time is the 4KB data unit with physical position 1 on page 0 in plane 0. That is, the physical position of the target valid data unit to be read next time is 1, and the data units contained in page 0 are 8 4KB. Dividing 1 by 8 gives a result of 0, and the remainder is 8. Therefore, the first data page value of the 4KB data unit with physical position 1 on page 0 in plane 0 is 0.
[0074] Since the first data page value of the 4KB data unit at physical position 0 on page 0 in plane 0 and the first data page value of the 4KB data unit at physical position 1 on page 0 in plane 0 are both 0, the 4KB data unit at physical position 0 on page 0 in plane 0 and the 4KB data unit at physical position 1 on page 0 in plane 0 are both on page 0;
[0075] Therefore, the 4k data unit at physical position 0 on page 0 in plane 0 is added to the valid data unit sequence, resulting in a valid data unit sequence of 0;
[0076] Similarly, when the 4K data at physical position 7 on page 0 in plane 1 is read, the next target valid data unit to be read is the 4K data unit at physical position 8 on page 1 in plane 0. According to the continuity judgment, the difference between physical position 7 and physical position 8 is 1, so the 4K data unit at physical position 7 on page 0 in plane 1 and the 4K data unit at physical position 8 on page 1 in plane 0 are two consecutive 4K units.
[0077] The continuity of the 4K data unit at physical position 7 on page0 in plane1 is judged. That is, 7 is divided by 8, the result is 0, and the remainder is 8. Therefore, the first data page value of the 4K data unit at physical position 7 on page0 in plane1 is 0; 8 is divided by 8, the result is 1, and the remainder is 0. Therefore, the first data page value of the 4K data unit at physical position 8 on page1 in plane0 is 1. Since the first data page value is 0 and the second data page value is 1, the two are not equal. The final valid data unit sequence is 0, 1, 2, 3, 4, 5, 6 and 7.
[0078] Among them, such as Figure 2 As shown in the figure, the data unit at physical position 3 on page0 in plane0 and the data unit at physical position 4 on page0 in plane1 both belong to page0, but to different planes. If a single-plane operation is used, physical positions 3 and 4 cannot be read out continuously. The multi-plane operation mode can operate on each plane of the flash memory at the same time, and the busy time in the middle of the multi-plane operation is very short. The multi-plane operation is more efficient than the single-plane operation. Therefore, the multi-plane read mode can continuously read out the two consecutive valid data units at physical position 3 and physical position 4 belonging to the same page. That is, a total of 8 4KB of valid data 0-7 can be read into the cache at one time through a multi-plane read operation.
[0079] Example 2
[0080] This embodiment differs from the first embodiment in that, before determining the continuity and the same data page of the target valid data unit, the following steps are further included:
[0081] Determine whether the sum of the number of valid data units in the cache and the number of valid data units in the valid data unit sequence reaches a preset capacity of the cache; if so, read the valid data unit sequence into the cache through a multi-plane read method; if not, perform continuity determination and same data page determination on the target valid data unit;
[0082] The preset capacity refers to the maximum amount of data that can be executed in a multi-plane operation in the flash memory. For example, if the flash memory has two planes, a multi-plane operation can operate on two pages at a time, that is, a maximum of 32k of data can be operated.
[0083] Get the parallelism of the data units on the flash memory. Since a page contains 8 and 4KB data units, the parallelism value is 8, that is, the preset capacity of the cache is 8;
[0084] Please refer to Figure 3 , set the judgment value of cnt to 7, and set cnt to 0 when performing the first read. For example, the target valid data unit read for the first time is the 4K data unit at physical position 8 on page 1 in plane0. At this time, cnt=0, so the 4K data unit at physical position 8 on page 1 in plane0 is subjected to the continuity judgment and the same data page judgment as described in the first embodiment, and the valid data unit sequences are 8 and 9; when the preset capacity judgment is performed on the 4K data unit at physical position 10 on page 1 in plane0, at this time, cnt=2 is less than 7, so the 4K data at physical position 10 on page 1 in plane0 is subjected to continuity judgment and the same data page judgment. Since physical position 10 and physical position 14 are not continuous, the valid data at the current physical position 10 is added to the data unit sequence and cnt is increased by 1, and the current valid data unit sequences 8, 9 and 10 are read into the cache;
[0085] Next, the preset capacity is determined for the 4KB data unit at physical location 14 on page 1 in plane 1. At this time, cnt = 3, so continuity and same data page determinations are performed, resulting in a valid data unit sequence of 14 and cnt incremented by 1. Since the 4KB data unit at physical location 15 on page 1 in plane 1 and the 4KB data unit at physical location 16 on page 2 in plane 0 do not belong to the same page, the valid data at the current physical location 15 is added to the data unit sequence, cnt incremented by 1, and the current valid data unit sequences 14 and 15 are read into the cache.
[0086] By analogy, when the target valid data unit currently being read is the 4K data unit at physical position 18 on page2 in plane0, cnt=7 at this time, so continuity judgment and same data page judgment are performed, physical position 18 is continuous with physical position 19, so the valid data at the current physical position 15 is added to the data unit sequence and cnt is increased by 1. At this time, the valid data unit is the 4K data unit at physical position 19 on page2 in plane0. Since cnt=8 is greater than the preset value 7 at this time, no judgment is performed, and the current valid data unit sequence 16, 17 and 18 are read into the cache, and the cnt value is cleared for the next read.
[0087] Please refer to Figure 4 , is the H2 full disk test speed result before optimization;
[0088] Please refer to Figure 5 , is the speed result of H2 full disk test after optimization;
[0089] contrast Figure 4 and Figure 5 It can be seen that the effective data unit sequence is obtained by determining the effective data units that are in the same data page as the target effective data unit and are continuous starting from the position of the target effective data unit; and the effective data unit sequence is read into the cache through multi-plane reading and then written to the target block at one time. The optimization method can make the write speed reach 20.9MByte / s, while the write speed before optimization is 16.8MByte / s.
[0090] Example 3
[0091] Please refer to Figure 6 , a garbage collection device, comprising:
[0092] A receiving module, used for receiving garbage collection requests;
[0093] A judgment module is configured to determine, for a read target valid data unit, valid data units that are in the same data page as the target valid data unit and are continuous starting from the position of the target valid data unit, to obtain a valid data unit sequence;
[0094] A reading module is used to read the valid data unit sequence into the cache through a multi-plane reading method.
[0095] Example 4
[0096] A computer-readable storage medium stores a computer program, which, when executed by a processor, implements each step of a garbage collection method in any one of the first or second embodiments above.
[0097] Example 5
[0098] Please refer to Figure 7 , an electronic device, including a memory, a processor and a computer program stored in the memory and capable of running on the processor, wherein when the processor executes the computer program, each step of a garbage collection method in any one of the above-mentioned embodiments one or two is implemented.
[0099] In summary, the present invention provides a garbage collection method, device, readable storage medium and electronic device. When reading the valid data unit to be recovered, it first determines whether the target valid data unit currently read reaches the preset capacity of the cache. If it does not reach the preset capacity of the cache, it then performs continuity judgment and judgment on the same data page on the target valid data unit currently read. It can determine the valid data units that are in the same data page as the target valid data unit and start from the position of the target valid data unit within the range of the preset capacity, and read the continuous valid data unit sequence composed of multiple valid data units into the cache through a multi-plane read method through a read operation, thereby ensuring that the continuous valid data units are read out at one time through a multi-plane read operation within the maximum allowable operational range and then written into the target data block at the same time, significantly improving the writing speed of the flash memory for data to be recovered, thereby improving the efficiency of garbage collection.
[0100] In the above embodiments provided in the present application, it should be understood that the disclosed methods, devices, computer-readable storage media, and electronic devices can be implemented in other ways. For example, the device embodiments described above are merely schematic. For example, the division of the modules is merely a logical function division. In actual implementation, there may be other division methods, such as multiple components or modules can be combined or integrated into another device, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or components or modules, which can be electrical, mechanical or other forms.
[0101] The components described as separate parts may or may not be physically separate, and the components shown as components may or may not be physical modules, that is, they may be located in one place or distributed across multiple network modules. Some or all of these components may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0102] In addition, the functional modules in various embodiments of the present invention may be integrated into a single processing module, or each component may exist physically separately, or two or more modules may be integrated into a single module. The aforementioned integrated modules may be implemented in the form of hardware or software functional modules.
[0103] If the integrated module is implemented in the form of a software functional module and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, server, or network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0104] It should be noted that for the aforementioned method embodiments, for ease of description, they are all expressed as a series of action combinations. However, those skilled in the art should be aware that the present invention is not limited by the order of the actions described, because according to the present invention, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in this specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present invention.
[0105] In the above embodiments, the description of each embodiment has its own focus. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0106] The above descriptions are merely embodiments of the present invention and are not intended to limit the patent scope of the present invention. Any equivalent transformations made using the contents of the present invention's description and drawings, or directly or indirectly applied in related technical fields, are also included in the patent protection scope of the present invention.
Claims
1. A method for garbage collection, characterized in that: Including steps: Receive garbage collection requests and read valid data units on the data blocks to be recovered; For the read target valid data unit, determining valid data units that are in the same data page as the target valid data unit and that are consecutive starting from the position of the target valid data unit, to obtain a valid data unit sequence; Reading the valid data unit sequence into the cache through a multi-plane read method; The determining of the valid data units that are in the same data page as the target valid data unit and that are consecutive starting from the position of the target valid data unit comprises: Determine whether the sum of the number of valid data units in the cache and the number of valid data units in the valid data unit sequence reaches the preset capacity of the cache; if so, read the valid data unit sequence into the cache through multi-plane reading; if not, perform continuity judgment and same data page judgment on the target valid data unit.
2. A method for garbage collection according to claim 1, characterized in that: The determining of the valid data units that are in the same data page as the target valid data unit and that are consecutive starting from the position of the target valid data unit comprises: During each read operation, a continuity judgment and a same data page judgment are performed on the target valid data unit to determine whether the target valid data unit currently being read is continuous with the target valid data unit to be read next and belongs to the same data page. If they are continuous and belong to the same data page, the target valid data unit currently being read is added to the valid data unit sequence, and the target valid data unit to be read next is set as the target valid data unit currently being read, and the steps of performing the continuity judgment and the same data page judgment on the target valid data unit are returned to be executed until a valid data unit that is not continuous with the target valid data unit currently being read or does not belong to the same data page appears; If they are not continuous or do not belong to the same data page, the valid data unit currently read is added to the valid data unit sequence.
3. A method for garbage collection according to claim 2, characterized in that: The continuity judgment includes: If the difference between the physical position of the currently read target valid data unit and the physical position of the next target valid data unit to be read is 1, the currently read target valid data unit and the next target valid data unit to be read are consecutive units.
4. A method for garbage collection according to claim 2, characterized in that: The same data page determination includes: Dividing the physical position of the currently read target valid data unit by the number of data units included in a data page to obtain a first data page value of the currently read target valid data unit; Dividing the physical position of the target valid data unit to be read next time by the number of data units included in a data page to obtain a second data page value of the target valid data unit to be read next time; If the first data page value and the second data page value are the same, the target valid data unit currently being read and the target valid data unit to be read next time belong to the same data page.
5. A method for garbage collection according to claim 1, characterized in that: The preset capacity is the parallelism of the data units on the flash memory.
6. A garbage collection device, characterized in that: include: A receiving module is used to receive garbage collection requests and read valid data units on the data blocks to be collected; A judgment module is configured to determine, for a read target valid data unit, valid data units that are in the same data page as the target valid data unit and are continuous starting from the position of the target valid data unit, to obtain a valid data unit sequence; A reading module, configured to read the valid data unit sequence into a cache through a multi-plane read method; The determining of the valid data units that are in the same data page as the target valid data unit and that are consecutive starting from the position of the target valid data unit comprises: Determine whether the sum of the number of valid data units in the cache and the number of valid data units in the valid data unit sequence reaches the preset capacity of the cache; if so, read the valid data unit sequence into the cache through multi-plane reading; if not, perform continuity judgment and same data page judgment on the target valid data unit.
7. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the garbage collection method according to any one of claims 1 to 5 are implemented.
8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the processor implements the steps of the garbage collection method according to any one of claims 1 to 5.
Citation Information
Patent Citations
Sequential reading method of multi-plane storage medium and related device
CN110990301A