Flash memory garbage collection method and device, computer device and readable storage medium
By dynamically adjusting the number of pages to be recycled in flash memory garbage collection operations and optimizing the flash memory garbage collection method based on the write bandwidth ratio, the problem of unbalanced write bandwidth and efficiency is solved, and efficient data writing and recycling are achieved.
Patent Information
- Application Number
- CN202211698249.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-28
- Publication Date
- 2025-11-04
- Estimated Expiration
- 2042-12-28
AI Technical Summary
In existing technologies, when setting the number of operation pages, it is difficult to balance data write bandwidth and garbage collection efficiency in flash memory garbage collection operations, resulting in low write bandwidth or frequent alternation, leading to low efficiency.
By dynamically adjusting the number of pages recycled during garbage collection operations, based on the ratio of the highest write bandwidth to the average write bandwidth, the consistency between write efficiency and bandwidth is ensured.
This achieves a balance between data writing efficiency and bandwidth during flash memory writing, avoiding the problem of low efficiency caused by a fixed number of recycled pages, and improving the overall data writing efficiency.
Smart Images

Figure CN116166571B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of data processing, and in particular to a flash memory garbage collection method and device, computer equipment and a readable storage medium. BACKGROUND
[0002] Before writing data to a flash memory (NAND FLASH), a block-based garbage collection operation needs to be performed, that is, valid data in a plurality of blocks in the flash memory is transferred to a new block, and after the transfer, the data in the plurality of blocks is erased, and then new data can be written to the plurality of blocks with erased data.
[0003] With the continuous increase in the capacity of the flash memory and the continuous improvement in the real-time requirements of data, the current flash memory writing is completed by cross-operations of page-based data writing and garbage collection, that is, a plurality of page data writing operations and a plurality of page garbage collection operations are alternately performed.
[0004] Further, if a garbage collection operation needs to be performed on a plurality of pages, it will result in a low data writing bandwidth; and if a garbage collection operation is performed on a small number of pages, it will result in frequent alternation of garbage collection and data writing, and low garbage collection efficiency.
[0005] Therefore, how to set the number of operation pages corresponding to the garbage collection operation to make the data writing bandwidth and the garbage collection efficiency both high has become a problem to be solved. SUMMARY
[0006] In view of this, the present application provides a flash memory garbage collection method and device, computer equipment and a readable storage medium, for solving the problem of how to set the number of operation pages corresponding to the garbage collection operation.
[0007] In a first aspect, the present application embodiment provides a flash memory garbage collection method, comprising:
[0008] In the process of writing target data to the flash memory, if the current garbage collection condition is met, the first target data writing amount in the first time period is obtained, wherein the first time period belongs to the interval time before the current garbage collection condition is met and after the previous garbage collection condition is met;
[0009] Based on the first target data writing amount, the highest writing bandwidth and the average writing bandwidth are determined;
[0010] If the highest writing bandwidth is higher than the average writing bandwidth, the number of recovery pages when the previous garbage collection operation is performed is increased, and the current garbage collection operation is performed based on the increased number of recovery pages.
[0011] Optionally, in a feasible manner provided by the present application embodiment, further comprising:
[0012] If the maximum write bandwidth is lower than or equal to the average write bandwidth, the number of reclaimed pages in the previous garbage collection operation is reduced, and the current garbage collection operation is performed based on the reduced number of reclaimed pages.
[0013] Optionally, in an available manner provided by the embodiment of the present application, the method further comprises:
[0014] determining the total number of pages of the block corresponding to the current garbage collection operation and the number of pages of valid data in the block;
[0015] calculating the ratio of the number of pages of valid data to the total number of pages, and obtaining the lower limit of the reclaimed page interval based on the ratio, wherein the reclaimed page interval represents the range of variation of the number of reclaimed pages;
[0016] determining the maximum data packet interval specified by the communication protocol corresponding to the flash memory;
[0017] obtaining the upper limit of the reclaimed page interval based on the maximum data packet interval and the time of reclaiming the data of one page of the flash memory.
[0018] Optionally, in an available manner provided by the embodiment of the present application, the first time length includes a plurality of second time lengths of equal length, and the first target data write amount includes partial write amounts corresponding to each second time length; the method further comprises:
[0019] recording the second target data write amount at each time instant in real time during the process of writing the target data into the flash memory;
[0020] The method of determining the maximum write bandwidth and the average write bandwidth based on the first target data write amount comprises:
[0021] calculating the quotient of the partial write amount with the maximum value and a third time length to obtain the maximum write bandwidth, wherein the third time length is less than or equal to the second time length;
[0022] obtaining the average write bandwidth based on the sum of the second target data write amounts within the third time length before the current garbage collection condition is met.
[0023] Optionally, in an available manner provided by the embodiment of the present application, if the maximum write bandwidth is higher than the average write bandwidth, the number of reclaimed pages in the previous garbage collection operation is increased, and the current garbage collection operation is performed based on the increased number of reclaimed pages, which comprises:
[0024] If the maximum write bandwidth is higher than the average write bandwidth, the variation of the number of reclaimed pages in the previous two garbage collection operations is calculated;
[0025] The changed amount and the sum of the recycled page numbers at the time of the previous garbage collection operation are taken as increased recycled page numbers, and the garbage collection operation is performed based on the increased recycled page numbers.
[0026] Optionally, in an available manner provided by the embodiment of the present application, the method further comprises:
[0027] If the garbage collection condition is satisfied for the first time, the garbage collection operation is performed based on the preset recycled page numbers.
[0028] In a second aspect, the embodiment of the present application provides a garbage collection device of a flash memory, comprising:
[0029] The obtaining module is configured to, in the process of writing the target data into the flash memory, if the garbage collection condition is satisfied, obtain a first target data writing amount in a first time length, wherein the first time length belongs to an interval time before the garbage collection condition is satisfied this time and after the garbage collection condition is satisfied last time.
[0030] The determining module is configured to determine a highest writing bandwidth and an average writing bandwidth based on the first target data writing amount.
[0031] The first recycling module is configured to, if the highest writing bandwidth is higher than the average writing bandwidth, increase the recycled page numbers at the time of the previous garbage collection operation, and perform the garbage collection operation based on the increased recycled page numbers.
[0032] Optionally, in an available manner provided by the embodiment of the present application, the method further comprises:
[0033] The second recycling module is configured to, if the highest writing bandwidth is lower than or equal to the average writing bandwidth, decrease the recycled page numbers at the time of the previous garbage collection operation, and perform the garbage collection operation based on the decreased recycled page numbers.
[0034] In a third aspect, the embodiment of the present application provides a computer device, comprising a memory and a processor, the memory stores a computer program, and the computer program performs the garbage collection method of the flash memory in any one of the first aspect when running on the processor.
[0035] In a fourth aspect, the embodiment of the present application provides a computer readable storage medium, the computer readable storage medium stores a computer program, and the computer program performs the garbage collection method of the flash memory in any one of the first aspect when running on the processor.
[0036] In the flash memory garbage collection provided by the application, if the current garbage collection condition is met during the process of writing target data into the flash memory, the computer device acquires the first target data writing amount in the first time length; then, based on the first target data writing amount, the highest writing bandwidth and the average writing bandwidth are determined; finally, if the highest writing bandwidth is higher than the average writing bandwidth, it indicates that the current target data writing efficiency is low and the time of occupying the writing channel during garbage collection is too long, so the number of reclaimed pages during the previous garbage collection operation is increased, and the current garbage collection operation is performed based on the increased number of reclaimed pages. Based on this, the application dynamically adjusts the number of reclaimed pages during the execution of the garbage collection operation, so that the average writing bandwidth during the process of writing the target data into the flash memory can be consistent with the highest writing bandwidth, and then the target data will be written into the flash memory at the highest efficiency during the writing process. Moreover, because the number of reclaimed pages of the garbage collection operation will be dynamically adjusted, the situation of low garbage collection efficiency when the number of reclaimed pages is fixed can be avoided. BRIEF DESCRIPTION OF DRAWINGS
[0037] In order to more clearly illustrate the technical solutions of the present application, the following will briefly introduce the drawings needed to be used in the embodiments. It should be understood that the following drawings only show some embodiments of the present application, and therefore should not be regarded as limiting the scope of protection of the present application. In each drawing, similar components are marked with similar reference numerals.
[0038] Figure 1 A flowchart of a first flash memory garbage collection method provided by the embodiment of the present application is shown;
[0039] Figure 2 A flowchart of a second flash memory garbage collection method provided by the embodiment of the present application is shown;
[0040] Figure 3 A flowchart of a third flash memory garbage collection method provided by the embodiment of the present application is shown;
[0041] Figure 4 A structural diagram of a flash memory garbage collection device provided by the embodiment of the present application is shown. DETAILED DESCRIPTION
[0042] The technical solutions in the embodiments of the present application will be described clearly and completely below in combination with the drawings in the embodiments of the present application. Obviously, the described embodiments are only some of the embodiments of the present application, not all the embodiments.
[0043] The components of the embodiments of the present application generally described and illustrated in the drawings herein could be arranged and designed in a wide variety of different configurations. Therefore, the following detailed description of the embodiments of the present application, as provided in the drawings, is not intended to limit the scope of the application, but is merely representative of selected embodiments of the application. All other embodiments not explicitly described or shown herein are intended to be within the scope of the present application, as the skilled artisan will recognize from the embodiments of the present application.
[0044] Hereinafter, the terms "include", "have", and their conjugates, used in various embodiments of the present application, merely indicate the presence of the features, numbers, steps, operations, elements, components, or combinations thereof, and do not exclude the possibilities of the presence or addition of one or more other features, numbers, steps, operations, elements, components, or combinations thereof.
[0045] In addition, the terms "first", "second", "third", and the like are used only to distinguish descriptions, and are not to be understood as indicating or implying relative importance.
[0046] Unless otherwise defined, all terms (including technical and scientific terms) used herein have the same meaning as commonly understood by one of ordinary skill in the art to which various embodiments of the present application belong. The terms, such as those defined in a generally used dictionary, are to be interpreted as having the same meaning as those in the context of the relevant technical field and are not to be interpreted as having ideal or overly formal meanings, unless clearly defined in various embodiments of the present application.
[0047] Embodiment 1
[0048] Referring to Figure 1 , a flowchart of a first flash memory garbage collection method provided by an embodiment of the present application is shown, and the flash memory garbage collection method provided by the embodiment of the present application includes:
[0049] In step S110, in the process of writing target data into the flash memory, if the garbage collection condition is met, the first target data write amount in the first time length is obtained, wherein the first time length belongs to the interval time before the current garbage collection condition is met and after the previous garbage collection condition is met.
[0050] It can be understood that when the garbage collection condition is met, the computer device will perform the garbage collection operation, that is, the data transfer and erasure of the plurality of pages of the flash memory.
[0051] It can also be understood that if a garbage collection operation needs to be performed on a larger number of pages, the time of the garbage collection operation occupying the data write channel will be longer, and then the target data write bandwidth will decrease. Conversely, if a garbage collection operation needs to be performed on a smaller number of pages, the time of occupying the data write channel is shorter, so the target data write bandwidth will increase.
[0052] But it can be imagined that if each garbage collection operation is only performed on a smaller number of pages, it will lead to frequent alternation of target data writing and garbage collection operation, and then it will also lead to the impact on the writing efficiency / bandwidth of the target data.
[0053] In view of this situation, the embodiment of the present application determines the data write amount of the target data in the interval time (i.e. the time when the previous garbage collection condition is met to the time when the current garbage collection condition is met) based on the interval time of the previous and subsequent garbage collection operations, and then adjusts the number of recycled pages corresponding to the current garbage collection operation in the subsequent step based on the data write amount of the interval time.
[0054] In addition, it should be noted that the embodiment of the present application does not use the target data write amount in the entire interval time to adjust the number of recycled pages in the subsequent step, but uses the target data write amount in part of the interval time, i.e. the target data write amount in the first time length. As in a feasible way, the first time length is 10 seconds before the current garbage collection condition is met.
[0055] In addition, it should be noted that the garbage collection condition in the embodiment of the present application is content that can be set according to actual situation.
[0056] Step S120, determining the highest write bandwidth and the average write bandwidth based on the first target data write amount.
[0057] It can be understood that the highest write bandwidth refers to the maximum value of the data write amount at each time in the interval time. And the average write bandwidth refers to the average data write amount at each time in the interval time.
[0058] It can also be understood that if the average write bandwidth of the target data in the interval time between the previous and subsequent garbage collection operations is higher than or equal to the highest write bandwidth, it indicates that the time of the garbage collection operation occupying the data write channel is very appropriate, so the target data can be written with the highest efficiency / bandwidth. And if the average write bandwidth is lower than the highest write bandwidth, it indicates that the number of recycled pages corresponding to the garbage collection operation is too large, and then the time of the garbage collection operation occupying the data write channel is longer.
[0059] If the maximum write bandwidth is higher than the average write bandwidth, the number of reclaimed pages in the previous garbage collection operation is increased, and the current garbage collection operation is performed based on the increased number of reclaimed pages.
[0060] It can be understood that in the existing flash memory write process, the number of reclaimed pages in each garbage collection operation is usually consistent. In the embodiment of the present application, the number of reclaimed pages in each garbage collection operation is dynamically adjusted. Specifically, when the maximum write bandwidth is higher than the average write bandwidth, the number of reclaimed pages is increased in the embodiment of the present application, so that the current garbage collection operation will transfer and erase more pages of data.
[0061] For example, if the previous garbage collection operation is performed to transfer and erase 5 pages of data, and when the current garbage collection condition is met, if the maximum write bandwidth is higher than the average write bandwidth, the current garbage collection operation will transfer and erase 6 pages of data. If the next garbage collection condition is met, and the maximum write bandwidth is still higher than the average write bandwidth, the next garbage collection operation will transfer and erase 7 pages of data.
[0062] It can also be understood that if the maximum write bandwidth is lower than or equal to the average write bandwidth, it indicates that the current data write efficiency has reached the peak, so in one feasible manner provided by the embodiment of the present application, if the maximum write bandwidth is lower than or equal to the average write bandwidth, the number of reclaimed pages corresponding to the current garbage collection operation is the same as the number of reclaimed pages corresponding to the previous garbage collection operation, that is, the number of reclaimed pages remains unchanged.
[0063] In another feasible manner provided by the embodiment of the present application, the number of reclaimed pages corresponding to the current garbage collection operation can be reduced based on the number of reclaimed pages corresponding to the previous garbage collection operation. Figure 2 FIG. 2 shows a flowchart of a second garbage collection method of a flash memory provided by the embodiment of the present application, that is, in this feasible manner, the method further includes:
[0064] If the maximum write bandwidth is lower than or equal to the average write bandwidth, the number of reclaimed pages in the previous garbage collection operation is reduced, and the current garbage collection operation is performed based on the reduced number of reclaimed pages.
[0065] It can be understood that if the maximum write bandwidth is lower than or equal to the average write bandwidth, it indicates that the data write efficiency is the highest, so at this time, the number of reclaimed pages can be appropriately increased, so that the current garbage collection operation is performed on more pages of data for transfer and erasure, thereby improving the garbage collection efficiency.
[0066] Based on this, the embodiment of the present application adjusts the number of reclaimed pages in the garbage collection operation dynamically, so that the average write bandwidth in the process of writing target data into the flash memory is consistent with the highest write bandwidth, and the target data is written into the flash memory at the highest efficiency; and because the number of reclaimed pages in the garbage collection operation is dynamically adjusted, the situation of too low garbage collection efficiency when the number of reclaimed pages is fixed is avoided.
[0067] Optionally, in an available manner provided by the embodiment of the present application, the method further comprises:
[0068] determining the total number of pages of the block corresponding to the garbage collection operation and the number of pages of valid data in the block;
[0069] calculating the ratio of the number of pages of valid data to the total number of pages, and obtaining the lower limit of the reclaimed page interval based on the ratio, wherein the reclaimed page interval represents the range of the number of reclaimed pages;
[0070] determining the maximum data packet interval specified by the communication protocol corresponding to the flash memory;
[0071] obtaining the upper limit of the reclaimed page interval based on the maximum data packet interval and the time required to reclaim one page of data in the flash memory.
[0072] That is, the embodiment of the present application determines the range of the number of reclaimed pages (i.e. the reclaimed page interval) using the reclaimed block corresponding to the garbage collection operation. It should be noted that the number of reclaimed pages in the embodiment of the present application will be increased or decreased within an interval, so as to ensure that the garbage collection efficiency and the target data write efficiency can be guaranteed.
[0073] Specifically, after determining the reclaimed block (i.e. the block written with target data), the embodiment of the present application determines each page in the reclaimed block that stores valid data, and then determines the lower limit of the reclaimed page interval according to the ratio of the number of pages storing valid data to the total number of pages of the reclaimed block.
[0074] Meanwhile, the embodiment of the present application also determines the upper limit of the reclaimed page interval based on the maximum data packet interval specified by the communication protocol corresponding to the flash memory and the time required to reclaim one page of garbage data.
[0075] Exemplarily, in an example, the calculation process of the aforementioned lower limit and upper limit is as follows:
[0076] Suppose the valid page number in the block corresponding to the garbage collection operation is 900, and the total page number of the block is 1000, then 100 free pages, i.e. the erased pages, should be obtained after the garbage collection operation of the block is completed. Further, the block can be divided into 100 segments at most, and each segment recycles (900 / 100) = 9 pages. Therefore, the lower limit of the interval is 9.
[0077] Further, suppose the time consumption of recycling one page is 2 milliseconds, and the maximum data packet interval specified by the communication protocol corresponding to the flash memory is 250 ms, then (250 / 2) = 125 pages, so the upper limit of the interval is 125.
[0078] Optionally, in a feasible manner provided by the embodiment of the application, the first time length can be divided into a plurality of second time lengths, and the first target data write amount can include a plurality of partial write amounts corresponding to the second time lengths. Figure 3 Fig. 3 shows a flowchart of a third garbage collection method of a flash memory provided by the embodiment of the application, i.e. in this feasible manner, the first time length includes a plurality of second time lengths of equal length, and the first target data write amount includes partial write amounts corresponding to the second time lengths.
[0079] Further, the method further includes:
[0080] Step S150, recording the second target data write amount at each time instant in real time in the process of writing the target data into the flash memory.
[0081] Further, the step S120 specifically includes:
[0082] Step S121, calculating the quotient of the partial write amount with the maximum value and a third time length to obtain the highest write bandwidth, wherein the third time length is less than or equal to the second time length.
[0083] Step S122, obtaining the average write bandwidth based on the sum of the second target data write amounts in the third time length before the garbage collection condition is met.
[0084] That is, the embodiment of the application completes the calculation of the highest write bandwidth and the average write bandwidth based on the real-time recorded data write amount. Specifically, the server in the embodiment of the application first determines the partial write amount corresponding to each second time length based on the real-time recorded data write amount at each time instant. In an example, the first time length is 10 seconds, and the second time length is 1 second.
[0085] Then, the maximum data write amount is selected from the data write amounts corresponding to the second time lengths, and the quotient of the maximum data write amount and a third time length is calculated to obtain the highest write bandwidth. In an example, the third time length is 100 milliseconds.
[0086] Finally, the average write bandwidth is obtained by using the data write amount corresponding to the third time length with the time when the current garbage collection condition is met as the end time. For example, if the time when the current garbage collection condition is met is the fifth second, the third time length with the time when the current garbage collection condition is met as the end time is [4.9s, 5s], that is, the data write amount in the first 100 milliseconds (that is, the last 100 milliseconds) of the fifth second is used as the average write bandwidth.
[0087] In addition, it can be understood that the third time length is not limited to 100 ms in the embodiment of the application, and can be adjusted to other time lengths, such as 200 ms or 300 ms, according to actual conditions.
[0088] It can also be understood that the second time length of 1 s is a preferred mode provided by the embodiment of the application, which is set by the applicant based on the usage range of the micro control unit timer and the single write data amount of the actual video recording device.
[0089] Optionally, the step S130 specifically includes the following steps in a feasible mode provided by the embodiment of the application:
[0090] If the highest write bandwidth is higher than the average write bandwidth, the change amount of the recycled page numbers in the previous two garbage collection operations is calculated;
[0091] The change amount and the sum of the recycled page numbers in the previous garbage collection operation are used as the increased recycled page number, and the current garbage collection operation is performed based on the increased recycled page number.
[0092] That is, the change amount of the recycled page numbers in the past two garbage collection operations is used to correspondingly adjust the recycled page number of the current garbage collection operation in the embodiment of the application. For example, if the Nth garbage collection operation is performed on 3 pages of data, the N+1th garbage collection operation is performed on 5 pages of data, and then, if the N+2th garbage collection condition is met and the highest write bandwidth is higher than the average write bandwidth, the N+2th garbage collection operation is performed on 7 pages of data because the change amount of the recycled page numbers in the Nth garbage collection operation and the N+1th garbage collection operation is 2.
[0093] It can be easily thought that if the recycled page number needs to be reduced when the highest write bandwidth is lower than or equal to the average write bandwidth, the N+2th garbage collection operation is performed on 3 pages of data, that is, the recycled page number of the current garbage collection operation is the difference between the recycled page number of the previous garbage collection operation and the change amount of the recycled page numbers in the previous two garbage collection operations.
[0094] Based on this, the embodiment of the application makes the adjustment range of the recycled page number stable when the recycled page number is adjusted, so that the write speed changes in a relatively smooth manner.
[0095] Optionally, in an implementation provided by the embodiment of the application, the method further comprises:
[0096] If the garbage collection condition is satisfied for the first time, the garbage collection operation is performed based on a preset number of pages to be collected.
[0097] That is, if the garbage collection condition is satisfied for the first time in the process of writing the target data into the flash memory, the garbage collection operation is completed based on a preset number of pages to be collected.
[0098] Embodiment 2
[0099] Corresponding to the garbage collection method of the flash memory provided by the embodiment 1 of the application, the embodiment 2 of the application further provides a garbage collection device of the flash memory, which is described with reference to Figure 4 The garbage collection device 200 of the flash memory provided by the embodiment of the application comprises:
[0100] The acquisition module 210 is configured to, in the process of writing the target data into the flash memory, if the garbage collection condition is satisfied, acquire a first target data writing amount in a first time length, wherein the first time length belongs to an interval time before the garbage collection condition is satisfied this time and after the garbage collection condition is satisfied last time.
[0101] The determination module 220 is configured to determine a highest writing bandwidth and an average writing bandwidth based on the first target data writing amount.
[0102] The first collection module 230 is configured to, if the highest writing bandwidth is higher than the average writing bandwidth, increase a number of pages to be collected when the garbage collection operation is performed last time, and perform the garbage collection operation this time based on the increased number of pages to be collected.
[0103] Optionally, in an implementation provided by the embodiment of the application, the method further comprises:
[0104] The second collection module is configured to, if the highest writing bandwidth is lower than or equal to the average writing bandwidth, decrease the number of pages to be collected when the garbage collection operation is performed last time, and perform the garbage collection operation this time based on the decreased number of pages to be collected.
[0105] Optionally, in an implementation provided by the embodiment of the application, the method further comprises:
[0106] The page number determination module is configured to determine a total number of pages of a block corresponding to the garbage collection operation this time and a number of pages of valid data in the block.
[0107] a lower limit determining module configured to calculate a ratio of the number of valid pages to the total number of pages, and obtain a lower limit of a page number interval based on the ratio, wherein the page number interval represents a range of variation of the number of pages to be reclaimed;
[0108] a interval determining module configured to determine a maximum data packet interval specified by a communication protocol corresponding to the flash memory;
[0109] an upper limit determining module configured to obtain an upper limit of the page number interval based on the maximum data packet interval and a time for reclaiming data in one page of the flash memory.
[0110] Optionally, in an available manner provided by the embodiment of the present application, the first time length comprises a plurality of equal second time lengths, and the first target data write amount comprises partial write amounts corresponding to the second time lengths respectively; the device further comprises:
[0111] a recording module configured to record the second target data write amount at each time instant in real time during the process of writing the target data into the flash memory;
[0112] the determining module comprises:
[0113] a first bandwidth calculating module configured to calculate a quotient of the partial write amount with the maximum value and a third time length to obtain a highest write bandwidth, wherein the third time length is less than or equal to the second time length;
[0114] a second bandwidth calculating module configured to obtain an average write bandwidth based on a sum of the second target data write amounts within the third time length before the current garbage collection condition is satisfied.
[0115] Optionally, in an available manner provided by the embodiment of the present application, the first reclaiming module comprises:
[0116] a change amount calculating sub-module configured to calculate a change amount of the number of reclaimed pages when the previous two garbage collection operations are performed, if the highest write bandwidth is higher than the average write bandwidth;
[0117] an increasing sub-module configured to take the change amount and the number of reclaimed pages when the previous garbage collection operation is performed as an increased number of reclaimed pages, and perform the current garbage collection operation based on the increased number of reclaimed pages.
[0118] Optionally, in an available manner provided by the embodiment of the present application, the device further comprises:
[0119] a third reclaiming module configured to perform the current garbage collection operation based on a preset number of reclaimed pages, if the current is the first time that the garbage collection condition is satisfied.
[0120] The flash memory garbage collection device 200 provided by the embodiments of the present application can realize each process of the flash memory garbage collection method corresponding to the embodiment 1, and achieve the same technical effects. To avoid repetition, details are not described herein.
[0121] The embodiments of the present application further provide a computer device, comprising a memory and a processor, the memory stores a computer program, and the computer program performs the flash memory garbage collection method as described in the embodiment 1 when running on the processor.
[0122] The embodiments of the present application further provide a computer readable storage medium, the computer readable storage medium stores a computer program, and the computer program performs the flash memory garbage collection method as described in the embodiment 1 when running on the processor.
[0123] In several embodiments provided in the present application, it should be understood that the disclosed apparatus and method can also be implemented by other means. The apparatus embodiments described above are only schematic, for example, the flowcharts and block diagrams in the drawings show the possible implementation architectures, functions and operations of the apparatus, method and computer program product according to the embodiments of the present application. In this regard, each block in the flowcharts or block diagrams can represent a module, a program segment or a part of code, which contains one or more executable instructions for implementing the specified logical functions. It should also be noted that, in alternative implementation, the functions noted in the blocks can occur in different orders from that noted in the drawings. For example, two consecutive blocks can actually be executed in parallel, and sometimes they can be executed in reverse order, depending on the functions involved. It should also be noted that each block in the structural diagram and / or flowchart, and the combination of blocks in the structural diagram and / or flowchart, can be implemented by a dedicated hardware-based system for implementing the specified functions or actions, or can be implemented by a combination of dedicated hardware and computer instructions.
[0124] In addition, each functional module or unit in the embodiments of the present application can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part.
[0125] If the functions are implemented in the form of software function modules and sold or used as independent products, they can be stored in a computer readable storage medium. Based on this understanding, the technical solutions of the present application or the parts of the present application that essentially contribute to the prior art or the parts of the technical solutions can be embodied in the form of software products. The computer software product is stored in a storage medium and includes a plurality of instructions for causing a computer device (which can be a smart phone, a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the method described in the various embodiments of the present application. The aforementioned storage medium includes a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and various media that can store program codes.
[0126] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art can easily think of changes or replacements within the technical scope disclosed by the present application, which should be covered within the protection scope of the present application.
Claims
1. A method for garbage collection of flash memory, characterized in that, include: During the process of writing target data into flash memory, if the current garbage collection condition is met, the first target data write volume within the first time period is obtained. The first time period is the interval between the current garbage collection condition being met and the previous garbage collection condition being met. The first time period includes multiple second time periods of equal length. The first target data write volume includes the partial write volume corresponding to each of the second time periods. During the process of writing the target data into flash memory, the second target data write volume at each moment is recorded in real time. Based on the first target data write volume, the maximum write bandwidth and average write bandwidth are determined, including: calculating the quotient of the largest part of the write volume and the third time period to obtain the maximum write bandwidth, wherein the third time period is less than or equal to the second time period, and obtaining the average write bandwidth based on the sum of the second target data write volume within the third time period before the current garbage collection condition is met; If the highest write bandwidth is higher than the average write bandwidth, the number of pages reclaimed during the previous garbage collection operation will be increased, and the current garbage collection operation will be performed based on the increased number of pages reclaimed.
2. The flash memory garbage collection method according to claim 1, characterized in that, Also includes: If the highest write bandwidth is lower than or equal to the average write bandwidth, the number of pages reclaimed during the previous garbage collection operation is reduced, and the current garbage collection operation is performed based on the reduced number of pages reclaimed.
3. The flash memory garbage collection method according to claim 2, characterized in that, Also includes: Determine the total number of pages in the block corresponding to this garbage collection operation, and the number of pages containing valid data in the block; Calculate the ratio of the number of pages of valid data to the total number of pages, and obtain the lower limit of the interval of recycled pages based on the ratio, wherein the interval of recycled pages represents the range of variation of the number of recycled pages; Determine the maximum data packet interval specified by the communication protocol corresponding to the flash memory; Based on the maximum data packet interval and the time required to reclaim one page of data in the flash memory, the upper limit of the range of pages to be reclaimed is obtained.
4. The flash memory garbage collection method according to claim 1, characterized in that, If the highest write bandwidth is higher than the average write bandwidth, then the number of pages reclaimed during the previous garbage collection operation is increased, and the current garbage collection operation is performed based on the increased number of pages reclaimed, including: If the highest write bandwidth is higher than the average write bandwidth, then calculate the change in the number of pages reclaimed during the first two garbage collection operations. The sum of the change and the number of pages recycled during the previous garbage collection operation is used as the increased number of pages recycled, and the current garbage collection operation is performed based on the increased number of pages recycled.
5. The flash memory garbage collection method according to claim 1, characterized in that, Also includes: If this is the first time the garbage collection conditions have been met, then the garbage collection operation will be performed based on the preset number of pages to be collected.
6. A flash memory waste recycling device, characterized in that, include: The acquisition module is used to acquire the first target data write volume within a first time period if the garbage collection condition is met during the process of writing target data to flash memory. The first time period is the interval between the current garbage collection condition being met and the previous garbage collection condition being met. The first time period includes multiple second time periods of equal length. The first target data write volume includes the partial write volume corresponding to each of the second time periods. During the process of writing the target data to flash memory, the second target data write volume at each moment is recorded in real time. The determination module is used to determine the maximum write bandwidth and the average write bandwidth based on the first target data write volume, including: calculating the quotient of the largest part of the write volume and the third time period to obtain the maximum write bandwidth, wherein the third time period is less than or equal to the second time period, and obtaining the average write bandwidth based on the sum of the second target data write volume within the third time period before the current garbage collection condition is met; The first recycling module is configured to, if the highest write bandwidth is higher than the average write bandwidth, increase the number of pages recycled in the previous garbage collection operation and perform the current garbage collection operation based on the increased number of pages recycled.
7. The flash memory waste recycling device according to claim 6, characterized in that, Also includes: The second recycling module is used to reduce the number of pages recycled in the previous garbage collection operation if the highest write bandwidth is lower than or equal to the average write bandwidth, and to perform the current garbage collection operation based on the reduced number of pages recycled.
8. A computer device, characterized in that, The device includes a memory and a processor, wherein the memory stores a computer program that, when executed on the processor, performs a flash memory garbage collection method as described in any one of claims 1-5.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed on a processor, performs the flash memory garbage collection method as described in any one of claims 1-5.
Citation Information
Patent Citations
Solid state disk read-write request parallel processing method
CN110515859A
Method and Apparatus for Providing Improved Garbage Collection Process In Solid State Drive
US20150019797A1