Memory garbage collection method and device, storage medium and electronic equipment
By obtaining the target L2P table during memory garbage collection and performing one-time data validity calculation, the problem of frequent reading of L2P tables is solved, and the garbage collection efficiency is improved.
Patent Information
- Application Number
- CN202510066517.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-16
- Publication Date
- 2025-02-18
AI Technical Summary
During the garbage collection process of memory, frequent reading of L2P tables results in a long time GC and reduces GC performance.
By obtaining the corresponding target logical position of the current physical location index in the target source block, obtaining the corresponding target L2P table, and performing data validity calculations on all physical locations in the target L2P table at one time to obtain the target source block and the target L2P All valid physical locations corresponding to the table.
Reduces the number of reads to L2P tables and improves garbage collection efficiency.
Smart Images

Figure CN119473172A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of memory data processing technology, and in particular to a memory garbage recovery method, device, storage medium and electronic equipment. Background Art
[0002] During the memory GC (Garbage Collection) process, valid data in the source block needs to be moved to the target block in sequence. When executing GC, it is first necessary to confirm which data in the source block is valid. Currently, when looking for valid data in the source block, it is usually necessary to query the L2P (Logical to Physical) table to see whether the data at each location in the source block is valid before moving it.
[0003] However, the physical locations on the source block are usually not continuous, and different physical locations may be on different L2P tables. In addition, due to the memory size, the number of L2P tables that can be placed in the memory is limited. If multiple discontinuous physical locations correspond to the same L2P table, it is necessary to read the same L2P table frequently, causing GC to take a long time and reduce GC performance. Summary of the invention
[0004] The technical problem to be solved by the present invention is to provide a memory garbage collection method, device, storage medium and electronic equipment to improve the memory GC efficiency.
[0005] In order to solve the above technical problems, the technical solution adopted by the present invention is: A memory garbage collection method, comprising: Obtain a target logical position corresponding to the current physical position index in the target source block, and obtain a corresponding target L2P table according to the target logical position; Performing data validity calculation on all physical locations in the target L2P table to obtain all target valid physical locations on the target source block; Move all data at the target valid physical location to the target block.
[0006] In order to solve the above technical problems, another technical solution adopted by the present invention is: A storage garbage collection device, comprising: An acquisition module, used to acquire a target logical position corresponding to the current physical position index in the target source block, and acquire a corresponding target L2P table according to the target logical position; A calculation module, used for performing data validity calculation on all physical locations in the target L2P table to obtain all target valid physical locations on the target source block; The moving module is used to move the data of all the target valid physical locations to the target block.
[0007] In order to solve the above technical problems, another technical solution adopted by the present invention is: A computer-readable storage medium stores a computer program, which implements the steps of the above-mentioned memory garbage collection method when executed by a processor.
[0008] In order to solve the above technical problems, another technical solution adopted by the present invention is: An electronic device comprises 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 memory garbage collection method is implemented.
[0009] The beneficial effects of the present invention are as follows: the target logical position corresponding to the target source block and the target L2P table corresponding to the target logical position are obtained through the current physical position index, and data validity calculation is performed on all physical positions in the target L2P table at one time to obtain all valid physical positions on the target source block corresponding to the target L2P table, so that there is no need to frequently process the target L2P table in the future, and only one reading of the target L2P table is required, thereby reducing the number of times the L2P table is read and improving garbage collection efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0010] Figure 1 A flowchart of a method for memory garbage collection according to an embodiment of the present invention; Figure 2 A schematic diagram of obtaining a target L2P table of a memory garbage collection method according to an embodiment of the present invention; Figure 3 A schematic diagram of data validity calculation of a memory garbage collection method according to an embodiment of the present invention; Figure 4 Another data validity calculation diagram of a memory garbage collection method according to an embodiment of the present invention; Figure 5 A schematic diagram of effective data migration of a memory garbage collection method according to an embodiment of the present invention; Figure 6 Another schematic diagram of effective data movement in a memory garbage collection method according to an embodiment of the present invention; Figure 7 It is a structural schematic diagram of a storage garbage collection device in an embodiment of the present invention; Figure 8 The figure is a schematic diagram of the structure of an electronic device in an embodiment of the present invention. DETAILED DESCRIPTION
[0011] In order to explain the technical content, achieved objectives and effects of the present invention in detail, the following is an explanation in combination with the implementation modes and the accompanying drawings.
[0012] A memory garbage collection method, comprising: Obtain a target logical position corresponding to the current physical position index in the target source block, and obtain a corresponding target L2P table according to the target logical position; Performing data validity calculation on all physical locations in the target L2P table to obtain all target valid physical locations on the target source block; Move all data at the target valid physical location to the target block.
[0013] From the above description, it can be seen that the beneficial effects of the present invention are: obtaining the corresponding target logical position in the target source block and the target L2P table corresponding to the target logical position through the current physical position index, and performing data validity calculation on all physical positions in the target L2P table at one time to obtain all valid physical positions on the target source block corresponding to the target L2P table, so that there is no need to frequently process the target L2P table subsequently, and only one read of the target L2P table is required, thereby reducing the number of times the L2P table is read and improving garbage collection efficiency.
[0014] Further, the obtaining of all target valid physical locations on the target source block includes: Marking the target L2P table as queried; After acquiring the corresponding target L2P table according to the target logical position, the following step further includes: Determine whether the target L2P table has been queried, and if so, obtain the next physical location index of the current physical location index; The logical position corresponding to the next physical position index in the target source block is obtained as the target logical position.
[0015] As can be seen from the above description, by marking the processed target L2P table as queried, when the same target L2P table is queried again later, it can be determined that the target L2P table has been processed, so that the target L2P table can be skipped.
[0016] Further, the obtaining the next physical location index of the current physical location index includes: If the current physical position index is equal to the total physical position length of the target source block, the next source block of the target source block is processed and the current physical position index is set to zero.
[0017] From the above description, it can be seen that if the current physical position index is equal to the total physical position length of the target source block, it means that the physical positions in the current target source block have all been processed, so that each physical position in the next source block can be processed by increasing the source block index value and setting the physical position index to zero.
[0018] Further, the step of moving the data of all the target valid physical locations to the target block includes: Determine whether all source blocks have been processed. If so, move the data at the target valid physical location on each source block to the target block.
[0019] From the above description, it can be seen that after the determination of valid data on all source blocks is completed, the data on all valid physical locations are moved at one time to improve the garbage collection efficiency.
[0020] Further, the step of moving the data at the target valid physical location on each source block to the target block includes: Acquire the logical position corresponding to each of the target valid physical positions, and sort the target valid physical positions according to the size of the logical positions; The data of each target valid physical location is moved to the target block in sequence according to the sorting.
[0021] From the above description, it can be seen that the order of migration is based on the query result on the L2P table, so the logical positions of the adjacent data to be migrated are relatively close. For example, in the same L2P table, the valid data with close logical positions can be sorted as concentrated as possible, so that in subsequent operations such as read / write / GC / Trim, the number of times the L2P table is read can be reduced, thereby improving the read and write performance.
[0022] Further, the step of moving the data of all the target valid physical locations to the target block includes: It is determined whether the amount of valid data to be moved has reached the amount of valid data that can be accommodated by the target block. If so, the moving process is terminated.
[0023] From the above description, it can be seen that the migration process is terminated when the amount of valid data moved has reached the amount of valid data that the target block can accommodate, to avoid continuing data migration when the target block has reached the upper limit of its capacity, resulting in problems such as partial data anomalies.
[0024] Further, the performing data validity calculation on all physical locations in the target L2P table includes: Obtain the recorded value and offset value of the target physical position to be calculated; Dividing the recorded value by the offset value to obtain a quotient value and a remainder value; If the quotient value is the same as the sequence number of the target source block, and the remainder value is the same as the target physical location, then the target physical location is valid.
[0025] From the above description, it can be seen that by obtaining the record value and offset value of the target physical position to be calculated, and calculating the result according to the record value and the offset value, it is possible to quickly and effectively determine whether the data of the target physical position is valid based on the calculation result.
[0026] Another embodiment of the present invention provides a memory garbage collection device, comprising: An acquisition module, used to acquire a target logical position corresponding to the current physical position index in the target source block, and acquire a corresponding target L2P table according to the target logical position; A calculation module, used for performing data validity calculation on all physical locations in the target L2P table to obtain all target valid physical locations on the target source block; The moving module is used to move the data of all the target valid physical locations to the target block.
[0027] Another 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 processor, the computer program implements the steps in the above-mentioned memory garbage collection method.
[0028] 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 the steps in the above-mentioned memory garbage collection method when executing the computer program.
[0029] The memory garbage collection method, device, storage medium and electronic device provided by the present invention can be applied to different types of memories to improve the efficiency of storage garbage collection, which is described below through specific implementation methods: Embodiment 1 Please refer to Figure 1 , a memory garbage collection method, comprising: S1. Obtain the target logical position corresponding to the current physical position index in the target source block, and obtain the corresponding target L2P table according to the target logical position. When the corresponding target L2P table is obtained, it is necessary to determine whether the target L2P table has been queried. If so, execute step S11; if not, execute step S2; S11, obtaining the next physical location index of the current physical location index, and obtaining the logical location corresponding to the next physical location index in the target source block as the target logical location; Please refer to Figure 2For example, in the initial state, set the source block index = 0, the physical position index = 0, and assume that the L2P table has 1024 units; then query the 0th physical position on source block 0, and the corresponding logical position of the 0th physical position is 2. By calculation: 2 / 1024=0, it means that the L2P table corresponding to the logical position = 2 is L2P table #0. After completing the query of L2P table #0, increase the physical position index by one, that is, the current physical position index = 1, query the 1st physical position on source block 0, and the corresponding logical position of the 1st physical position is 1025. By calculation: 1025 / 1024=1, it means that the L2P table corresponding to the logical position = 1025 is L2P table #1. After completing the query of L2P table #1, the physical location index is increased by one, that is, the current physical location index = 2, and the second physical location is queried. The corresponding logical location of the second physical location is 0, and its corresponding L2P table is L2P table #0. Since L2P table #0 has completed the query, the third physical location is queried. Since the L2P table corresponding to the third physical location is L2P table #1, which has also completed the query, the next physical location is queried, and so on, until the sixth physical location, and its corresponding L2P table is L2P table #4; that is, in this embodiment, each L2P is read only once. In the prior art, when processing the second physical location on source block 0, it is still necessary to query L2P table #0 to determine the validity of the data at the second physical location on source block 0, resulting in low garbage collection efficiency. Among them, a complete L2P table may include multiple sub-L2P tables. For example, L2P table 1 may include L2P table #0, L2P table #1, L2P table #2 and L2P table #3, etc. L2P table #0, L2P table #1, L2P table #2 and L2P table #3 respectively represent the indexes of different positions on L2P table 1.
[0030] At the same time, if the current physical position index is equal to the total physical position length of the target source block, the next source block of the target source block is processed and the current physical position index is set to zero; Figure 2 As shown, for example, if the total physical position length on source block 0 is 16 (including physical positions 0-15), when the current physical position index = 16, the next source block is processed, that is, source block index = 1, physical position index = 0.
[0031] After traversing the L2P table through the above steps, data validity calculation is performed on all physical locations in the L2P table, instead of reading the corresponding L2P table in sequence according to the traversed physical locations to judge the data validity. This can avoid the problem of frequently reading L2P table #0 and L2P table #1 during garbage collection, so that L2P table #0 and L2P table #1 only need to be read once; compared with the prior art that needs to frequently read L2P table #0 and L2P table #1, the garbage collection efficiency is greatly improved.
[0032] S2. Perform data validity calculation on all physical locations in the target L2P table to obtain all target valid physical locations on the target source block. The specific calculation method is as follows: Get the record value and offset value of the target physical location to be calculated; divide the record value by the offset value to obtain the quotient and remainder value; if the quotient is the same as the serial number of the target source block, and the remainder value is the same as the target physical location, the target physical location is valid. Among them, the valid data of the source block can be queried by querying the logical position corresponding to each physical position of the source block; calculate the corresponding L2P table based on the logical position, read the L2P table into the memory of the chip, and query whether the physical position corresponding to the offset position of the L2P table matches the physical position of the current query source block. If they are consistent, it means that the data at this physical location is the latest and valid data. If they are inconsistent, it means that the data at this physical location is invalid. The following is an example: like Figure 3 As shown, in source block = 10 (fblock), the logical position corresponding to the 0th physical position of the source block = 2, and its corresponding L2P table is L2P table #0. The value recorded in offset unit 2 in L2P table #0 is queried = 160, and the offset position is 16; perform calculation: 160 / 16=10(fblock), 160%16=0(physical position), which is expressed as: the 0th physical position on source block 10; that is, the calculation result is consistent with the physical position of source block = 10, therefore, the data corresponding to the 0th physical position on source block 10 is valid data, and the data at the 0th physical position needs to be moved to the target block later.
[0033] like Figure 4 As shown, in source block = 10 (fblock), the logical position corresponding to the second physical position of the source block = 0, and its corresponding L2P table is L2P table #0. The value recorded in offset unit 0 in L2P table #0 is queried = 300, and the offset position is 16; perform calculation: 300 / 16=18 (fblock), 300%16=12 (physical position), which is expressed as: the 12th physical position on source block 18; that is, the calculation result is inconsistent with the physical position of source block = 10, therefore, the data corresponding to the second physical position on source block 10 is not valid data and does not need to be moved.
[0034] Through the above calculation method, all valid physical addresses of the target L2P table can be calculated. For example, the physical locations of the source blocks in L2P table #0 can be found, and the valid data can be moved to the target block. When the target L2P table completes the query of valid data, the target L2P table needs to be marked as queried; for example, the bitmap array searched by L2P is set to a size of (total L2P+7) / 8 bytes, initialized to 0; for example, after the target L2P table #0 completes the query of valid data, the bitmap corresponding to the target L2P table #0 is set to 1, indicating that the target L2P table #0 has been queried; at the same time, the initialization step is performed before executing step S1, or when executing in the initial state.
[0035] S3. Move all data at the target valid physical location to the target block. Specifically: S31, determine whether all source blocks have been processed, if so, move the data of the target valid physical position on each source block to the target block. The move is performed in the order of logical positions, specifically: obtain the logical position corresponding to each target valid physical position, and sort the target valid physical positions according to the size of the logical position; and move the data of each target valid physical position to the target block in sequence according to the sorting.
[0036] S31, judging whether the amount of effective data to be moved has reached the amount of effective data that can be accommodated by the target block, if so, ending the moving process. And when all source blocks have been moved, ending the moving process.
[0037] In other optional implementations, valid data can also be moved based on a source block as a unit or based on the query result of an L2P table; for example: if the physical locations of all source blocks have been queried, or the amount of valid data moved has reached the amount of valid data that the target block can accommodate, the process ends; if not, the logical location corresponding to the physical location index in the source block corresponding to the source block index is queried, and the queried L2P table index is calculated, and the bitmaparray searched in L2P is first queried. If it is 1, it means that this physical location has been found from the L2P table, and if it is 0, it means that this physical location has not been found from the L2P table, and then step S2 is executed.
[0038] like Figure 5 As shown, data is moved in units of one source block; assuming Figure 5If each physical location on the source block is valid, the corresponding logical location of each physical location is obtained according to the correspondence between the physical location and the logical location recorded in the P2L (Physical to Logical) table in the source block, and each physical location is moved to the target block in turn according to the logical location.
[0039] like Figure 6 As shown, multiple source blocks are moved for data; assuming Figure 6 Each physical position on each source block is valid, then the corresponding logical position of each physical position is obtained according to the correspondence between the physical position and the logical position recorded in the P2L table in each source block, and each physical position in the three source blocks is moved to the target block in sequence according to the logical position. Sorting based on the order of logical position can concentrate the valid data with close logical positions as much as possible. In subsequent operations such as read / write / GC / Trim, the number of times the L2P table is read can be reduced because the logical position of the data is concentrated, and the operation performance is improved. That is, the method in this embodiment can take L2P as a unit, and after processing all the physical positions on L2P that match the source block at one time, they are moved to the target block, reducing the number of times the L2P table is read, and the valid data with close logical positions can be sorted as much as possible, thereby improving the performance of subsequent read and write operations.
[0040] Embodiment 2 Please refer to Figure 7 , a memory garbage collection device, comprising: An acquisition module is used to acquire a target logical position corresponding to the current physical position index in the target source block, and acquire a corresponding target L2P table according to the target logical position; A calculation module, used to perform data validity calculation on all physical locations in the target L2P table to obtain all target valid physical locations on the target source block; The moving module is used to move the data of all target valid physical locations to the target block.
[0041] Embodiment 3 A computer-readable storage medium stores a computer program, which implements the various steps of the memory garbage collection method described in the first embodiment when the computer program is executed by a processor.
[0042] Embodiment 4 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 of the memory garbage collection method described in the first embodiment is implemented.
[0043] In summary, the memory garbage collection method, device, storage medium and electronic device provided by the present invention obtain the corresponding target logical position in the target source block and the target L2P table corresponding to the target logical position through the current physical position index, and perform data validity calculation on all physical positions in the target L2P table at one time to obtain all valid physical positions on the target source block corresponding to the target L2P table, so that there is no need to frequently process the target L2P table in the future, and only needs to read the target L2P table once, thereby reducing the number of times the L2P table is read and improving the garbage collection efficiency. At the same time, when moving valid data blocks, it is possible to process all physical positions on the L2P that match the source block in units of L2P at one time and then move them to the target block, reducing the number of times the L2P table is read, and valid data with close logical positions are sorted as much as possible to improve the performance of subsequent read and write operations.
[0044] In the above embodiments provided in the present application, it should be understood that the disclosed methods, systems, computer-readable storage media, and electronic devices can be implemented in other ways. For example, the system embodiments described above are only schematic. For example, the division of the modules is only a logical function division. There may be other division methods in actual implementation, such as multiple components or modules can be combined or integrated into another system or 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.
[0045] The components described as separate components may or may not be physically separated, and the components shown as components may or may not be physical modules, that is, they may be located in one place or distributed on multiple network modules. Some or all of the components may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0046] In addition, each functional module in each embodiment of the present invention may be integrated into one processing module, or each component may exist physically separately, or two or more modules may be integrated into one module. The above integrated modules may be implemented in the form of hardware or in the form of software functional modules.
[0047] If the integrated module is implemented in the form of a software function 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, in essence, 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, including several instructions for a computer device (which can be a personal computer, a server, or a 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: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc. Various media that can store program codes.
[0048] It should be noted that, for the convenience of description, the aforementioned method embodiments are all described as a series of action combinations, but those skilled in the art should be aware that the present invention is not limited by the described action sequence, because according to the present invention, certain steps can be performed in other sequences or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present invention.
[0049] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0050] 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 specification 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 memory garbage collection method, characterized in that: include: Obtain a target logical position corresponding to the current physical position index in the target source block, and obtain a corresponding target L2P table according to the target logical position; Performing data validity calculation on all physical locations in the target L2P table to obtain all target valid physical locations on the target source block; Move all data at the target valid physical location to the target block.
2. A memory garbage collection method according to claim 1, characterized in that: The obtaining of all target valid physical locations on the target source block comprises: Marking the target L2P table as queried; After acquiring the corresponding target L2P table according to the target logical position, the following step further includes: Determine whether the target L2P table has been queried, and if so, obtain the next physical location index of the current physical location index; The logical position corresponding to the next physical position index in the target source block is obtained as the target logical position.
3. A memory garbage collection method according to claim 2, characterized in that: The obtaining the next physical location index of the current physical location index comprises: If the current physical position index is equal to the total physical position length of the target source block, the next source block of the target source block is processed and the current physical position index is set to zero.
4. A memory garbage collection method according to claim 1, characterized in that: The moving of data at all target valid physical locations to the target block comprises: Determine whether all source blocks have been processed. If so, move the data at the target valid physical location on each source block to the target block.
5. A memory garbage collection method according to claim 4, characterized in that: The step of moving the data at the target valid physical location on each source block to the target block comprises: Acquire the logical position corresponding to each of the target valid physical positions, and sort the target valid physical positions according to the size of the logical positions; The data of each target valid physical location is moved to the target block in sequence according to the sorting.
6. A memory garbage collection method according to claim 1, 4 or 5, characterized in that: The moving of data at all target valid physical locations to the target block comprises: It is determined whether the amount of valid data to be moved has reached the amount of valid data that can be accommodated by the target block. If so, the moving process is terminated.
7. A memory garbage collection method according to claim 1, characterized in that: The data validity calculation for all physical locations in the target L2P table includes: Obtain the recorded value and offset value of the target physical position to be calculated; Dividing the recorded value by the offset value to obtain a quotient value and a remainder value; If the quotient value is the same as the sequence number of the target source block, and the remainder value is the same as the target physical location, then the target physical location is valid.
8. A storage garbage collection device, characterized in that: include: An acquisition module, used to acquire a target logical position corresponding to the current physical position index in the target source block, and acquire a corresponding target L2P table according to the target logical position; A calculation module, used for performing data validity calculation on all physical locations in the target L2P table to obtain all target valid physical locations on the target source block; The moving module is used to move the data of all the target valid physical locations to the target block.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, each step of a memory garbage collection method as described in any one of claims 1 to 7 is implemented.
10. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the processor implements the various steps in a memory garbage collection method as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Flash memory-based garbage disposal method, solid-state hard disk, and storage device
CN109542800A
Garbage collection method and solid state disk
CN115630001A