Management mechanism for garbage collection operations
By setting the garbage collection start threshold and adjustment factor in flash memory, the garbage collection operations are dynamically managed, which solves the problem of unstable response time caused by frequent garbage collection and improves write performance.
Patent Information
- Application Number
- CN202110558077.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Priority Date
- 2021-02-18
- Filing Date
- 2021-05-21
- Publication Date
- 2025-08-26
- Estimated Expiration
- 2041-05-21
AI Technical Summary
The invalid data of flash memory increases during overwrite operations, resulting in frequent garbage collection operations, affecting the unstable response time of host commands, and reducing write performance.
By setting the garbage collection start threshold and adjustment factor, dynamically adjusting the start time and write ratio of the garbage collection operation, combining the effective page percentage of the source block and the candidate source block, and managing the garbage collection operation in a refined manner.
It stabilizes the response time of flash memory to host commands, avoids frequent start and end of garbage collection operations, and maintains the stability of write performance.
Smart Images

Figure CN114968830B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to flash memory, and more particularly to a method and controller for managing garbage collection operations on the flash memory, and a related storage device. Background Art
[0002] Flash memory inherently doesn't support overwrite operations. When new data is needed to replace old data already stored in flash memory, the new data is written to a new location, and the data in the old location becomes invalid. Therefore, when the need to overwrite old data occurs repeatedly, the amount of invalid data increases. To ensure that there is sufficient storage space in the flash memory to store data, invalid data must be erased. Generally speaking, flash memory relies on garbage collection (GC) operations to free up space occupied by invalid data.
[0003] The garbage collection operation selects a source block from the flash memory and copies only valid pages (i.e., pages with valid data) from the source block to the destination block. Once all valid pages have been copied to the destination block, the source block is erased, becoming a spare block for data writing.
[0004] Because garbage collection operations are internal to flash memory devices, the memory controller must simultaneously transmit valid data based on garbage collection operations and process writes of user data based on host commands. This means that once garbage collection occurs, write operations issued by host commands are restricted, resulting in unstable response times to host commands and, consequently, reduced write performance of the flash memory. Therefore, a mechanism for managing garbage collection operations is needed in the art. Summary of the Invention
[0005] As previously mentioned, one objective of the present invention is to provide a mechanism for managing garbage collection operations on flash memory. In one embodiment, the present invention determines when to initiate a garbage collection operation based on a garbage collection initiation threshold and adjusts the garbage collection write ratio to host commands based on the current number of spare blocks. In this embodiment, the initiation of a garbage collection operation depends on whether the current number of spare blocks in the flash memory is less than the garbage collection initiation threshold, rather than on the target number of spare blocks maintained by the Flash Translation Layer (FTL). This prevents frequent initiation and termination of garbage collection operations, which could excessively impact the response time to host commands. Furthermore, an embodiment of the present invention determines a base garbage collection write ratio based on the overall valid page percentage of a source block and one or more candidate source blocks. In this embodiment, one or more candidate source blocks are considered and variations in valid page percentages between different source blocks are smoothed. Consequently, variations in the base garbage collection write ratio and the garbage collection write ratio can be more gradual, thereby stabilizing the flash memory's response time to host commands. Embodiments of the present invention also estimate the flash memory's overall spare area in smaller units. In such embodiments, the flash memory's spare area can be estimated in smaller units (e.g., 4K bytes) rather than blocks. Because spare area changes are reflected in smaller units, the "garbage collection operation to host command" write ratio, which is closely related to spare area size, can be adjusted in a more refined manner, thereby reducing the impact on host command response time.
[0006] An embodiment of the present invention provides a method for managing garbage collection operations on a flash memory. The method includes: setting a garbage collection initiation threshold, wherein the garbage collection initiation threshold indicates a predetermined number of spare blocks, the predetermined number of spare blocks being greater than a target number of spare blocks maintained by a flash translation layer of the flash memory; determining whether to initiate a garbage collection operation based on a current number of spare blocks in the flash memory and the garbage collection initiation threshold; and performing the garbage collection operation on a source block in the flash memory when the current number of spare blocks is less than or equal to the garbage collection initiation threshold.
[0007] One embodiment of the present invention provides a controller for controlling the operation of a flash memory and managing garbage collection operations on the flash memory. The controller includes: a storage unit and a processing unit. The storage unit is used to store information. The processing unit is used to perform the following operations based on program code and information stored in the storage unit or the flash memory: setting a garbage collection start threshold, wherein the garbage collection start threshold indicates a predetermined number of spare blocks, and the predetermined number of spare blocks is higher than a target number of spare blocks maintained by a flash translation layer of the flash memory; determining whether to start a garbage collection operation based on a current number of spare blocks in the flash memory and the garbage collection start threshold; and performing the garbage collection operation on a source block in the flash memory when the current number of spare blocks is less than or equal to the garbage collection start threshold.
[0008] One embodiment of the present invention provides a storage device. The storage device includes: a flash memory and a controller. The flash memory is used to provide storage space. The controller is used to control the operation of the flash memory and manage garbage collection operations on the flash memory. The controller includes: a storage unit and a processing unit. The storage unit is used to store information. The processing unit is used to perform the following operations based on program code and information stored in the storage unit or the flash memory: setting a garbage collection start threshold, wherein the garbage collection start threshold indicates a predetermined number of spare blocks, and the predetermined number of spare blocks is higher than a target number of spare blocks maintained by a flash translation layer of the flash memory; determining whether to start a garbage collection operation based on a current number of spare blocks in the flash memory and the garbage collection start threshold; and performing the garbage collection operation on a source block in the flash memory when the current number of spare blocks is less than or equal to the garbage collection start threshold. BRIEF DESCRIPTION OF THE DRAWINGS
[0009] Figure 1 A schematic diagram illustrating the structure of a storage device according to an embodiment of the present invention is shown.
[0010] Figure 2 FIG. 4 illustrates the relationship between the current number of spare blocks, the target number of spare blocks, the adjustment factor, and the garbage collection triggering threshold in the first embodiment of the present invention.
[0011] Figure 3 A flow chart of a method for managing garbage collection operations in a first embodiment of the present invention is shown.
[0012] Figure 4FIG. 4 illustrates the relationship between the current number of spare blocks, the target number of spare blocks, the adjustment factor, and the garbage collection triggering threshold in a second embodiment of the present invention.
[0013] Figure 5 FIG. 4 illustrates the relationship between the current number of spare blocks, the target number of spare blocks, the adjustment factor, and the garbage collection triggering threshold in a third embodiment of the present invention.
[0014] Figure 6 A flow chart of a method for managing garbage collection operations in a third embodiment of the present invention is shown.
[0015] Figures 7A to 7D FIG. 4 illustrates how to determine the overall valid page percentage according to various embodiments of the present invention.
[0016] Figure 8 Flowcharts of methods for managing garbage collection operations in the fourth, fifth, and sixth embodiments of the present invention are shown.
[0017] Figure 9 FIG. 4 illustrates spare areas in different blocks of a flash memory according to an embodiment of the present invention.
[0018] Figure 10 A flow chart of a method for managing garbage collection operations according to a seventh embodiment of the present invention is shown. DETAILED DESCRIPTION
[0019] In the following text, many specific details are described to provide the reader with a thorough understanding of the embodiments of the present invention. However, those skilled in the art will understand how to implement the present invention without one or more specific details, or using other methods, components, materials, etc. In other cases, well-known structures, materials, or operations are not shown or described in detail to avoid obscuring the core concepts of the present invention.
[0020] References to "one embodiment" in this specification mean that the specific features, structures, or characteristics described in that embodiment may be included in at least one embodiment of the present invention. Therefore, the phrase "in one embodiment" appearing throughout this specification does not necessarily refer to the same embodiment. Furthermore, the specific features, structures, or characteristics described above may be combined in any suitable manner in one or more embodiments.
[0021] Overview
[0022] Figure 1Schematic diagram of the architecture of an electronic device 10 according to an embodiment of the present invention. As shown in the figure, the electronic device 10 includes a host device 50 and a storage device 100. The host device 50 may include: at least one processor 52 for controlling the operation of the host device 50. In different embodiments, the host device 50 may be (but not limited to): a smart phone, a tablet computer, a wearable device, a personal computer, a notebook computer, a digital camera, a digital video recorder, a game console, a car navigation system, a printer, a scanner or a server. In addition, in different embodiments, the memory device 100 may be (but not limited to): a portable storage device (such as a memory card that complies with the SD / MMC, CF, MS, XD or UFS standards), a solid state drive (SSD) and various embedded storage devices (such as an embedded storage device that complies with the UFS or EMMC specifications).
[0023] In various embodiments of the present invention, the storage device 100 may include a controller such as a memory controller 110 and may also include a non-volatile (NV) memory 120. The NV memory 120 is used to store information. The NV memory 120 may include one or more NV memory elements, for example, multiple NV memory elements 122_1-122_N. Furthermore, the NV memory 120 may be a flash memory, and the NV memory elements 122_1-122_N may each be a plurality of flash memory chips or a plurality of flash memory bare dies, but the present invention is not limited thereto. In addition, the NV memory 120 may include memory cells having a two-dimensional structure, or may include memory cells having a three-dimensional structure.
[0024] like Figure 1As shown, the memory controller 110 may include processing circuits such as a microprocessor 112, storage elements such as a read-only memory (ROM) 112M, a control logic circuit 114, a garbage collection operation management engine 115, a volatile memory 116, and a transmission interface circuit 118. At least a portion (e.g., some or all) of these elements may be interconnected via a bus. The volatile memory 116 is implemented by a random-access memory (RAM). For example, the volatile memory 116 may be a static RAM (SRAM). The volatile memory 116 may be used to provide internal storage space for the memory controller 110, for example, to temporarily store information. In addition, the ROM 112M of this embodiment is used to store program code 112C, and the microprocessor 112 is used to execute the program code 112C, thereby controlling access to the NV memory 120. In another embodiment, the program code 112C may be stored in the NV memory 120.
[0025] The memory controller 110 controls the reading, writing, and erasing of the NV memory 120 via the control logic circuit 114. Furthermore, the memory controller 110 can simultaneously write user data based on host commands from the host control device 50, and write valid data based on valid data collected from the NV memory 120 by garbage collection. The control logic circuit 114 can further control the NV memory 120, including an error correction code (ECC) circuit (not shown) to perform data protection and / or correction, but the present invention is not limited thereto. The transmission interface circuit 118 complies with a specific data transmission standard (e.g., the Serial Advanced Technology Attachment (SATA) standard, the Universal Serial Bus (USB) standard, the Peripheral Component Interconnect Express (PCIE) standard, the Embedded Multimedia Card (eMMC) standard, or the Universal Flash Storage (UFS) standard), and can communicate with the host control device 50 according to the specific communication standard.
[0026] Generally speaking, the host control device 50 can indirectly access the storage device 100 by sending host commands and corresponding logical addresses to the memory controller 110. The memory controller 110 receives the host commands and logical addresses, converts the host commands into memory operation commands, and further uses the memory operation commands to control the NV memory 120 to perform read, write, or erase operations on memory cells or data pages with specific physical addresses within the NV memory 120, where the physical addresses correspond to the logical addresses. When the memory controller 110 performs an erase operation on any NV memory element 122_k within the NV memory elements 122_1-122_N, at least one block within the NV memory element 122_k may be erased. In addition, each block of the NV memory element 122_k may include multiple pages, and access operations (e.g., read or write) may be performed on one or more pages.
[0027] Garbage collection operation startup timing and ratio adjustment
[0028] An embodiment of the present invention provides a method mechanism for determining when to initiate a garbage collection operation on the NV memory 120, and determining how the memory controller 110 processes the writing of valid data and user data simultaneously within a certain period of time, with reference to the write ratio of "garbage collection operation to host command".
[0029] Typically, the Flash Translation Layer (FTL) function implemented on the memory controller 110 maintains a minimum number of spare blocks in the NV memory 120, i.e., a target number of spare blocks, to ensure that the memory controller 110 always has enough spare blocks to mobilize, for example, for bad block replacement. If it detects that the current number of spare blocks is less than the target number of spare blocks, conventional memory controllers typically initiate garbage collection operations. Under such mechanisms, if the current number of spare blocks approaches the target number of spare blocks, the memory controller may frequently initiate and terminate garbage collection operations, which may cause drastic changes in the response time to host commands, thereby affecting the write performance of the flash memory.
[0030] In view of this, the memory controller 110 of the present invention sets a garbage collection activation threshold value that is different from the target number of spare blocks maintained by the FTL of the storage device 100. In the present invention, the memory controller 110 determines whether to initiate a garbage collection operation based on a comparison between the current number of spare blocks and the garbage collection activation threshold value. According to an embodiment of the present invention, the garbage collection activation threshold value is higher than the target number of spare blocks maintained by the FTL. Therefore, the memory controller 110 can initiate a garbage collection operation even if the current number of spare blocks in the NV memory 120 is still higher than the target number of spare blocks.
[0031] Furthermore, because the memory controller 110 needs to simultaneously process valid data writes based on garbage collection operations and user data writes based on host commands, the memory controller 110 determines a "garbage collection operation to host command" write ratio (GHWR) and performs garbage collection operations based on this "garbage collection operation to host command" write ratio (GHWR). The "garbage collection operation to host command" write ratio (GHWR) represents the ratio of the amount of valid data written based on garbage collection operations to the amount of user data written in host commands sent by the master device 50 within a certain period of time. This balance is achieved between maintaining the number of spare blocks and stabilizing the write performance of the storage device 100.
[0032] In an embodiment of the present invention, the memory controller 110 determines a garbage collection write ratio (GHWR) based on a basic garbage collection write ratio (BR) and an adjustment factor (K), where GHWR = K*BR. The basic garbage collection write ratio (BR) is determined based on the valid page percentage (P) of the source block. The basic garbage collection write ratio (BR) can be calculated using the following formula: BR = P / (1-P). The valid page percentage (P) of the source block represents the ratio of valid pages to all pages in the source block. The basic garbage collection write ratio (BR) reflects the minimum write volume based on garbage collection operations and indicates how much valid data must be moved by garbage collection operations to balance writes with host commands, thereby stabilizing the current number of spare blocks in the NV memory 120.
[0033] The adjustment factor K is determined based on the current number of spare blocks (CN) and is negatively correlated with the current number of spare blocks (CN). Due to the adjustment factor K, as the current number of spare blocks decreases, the garbage collection write ratio (GHWR) increases. Therefore, if the number of spare blocks in the NV memory 120 is insufficient, the memory controller 110 will perform more garbage collection writes, writing more valid data to the target block. On the other hand, if the number of spare blocks in the NV memory 120 is sufficient, the memory controller 110 will perform more host-command-based user data writes.
[0034] Please refer to Figure 2 , the figure illustrates the relationship between the current number CN of spare blocks, the target number TG of spare blocks, the garbage collection start threshold TH and the adjustment factor K in the first embodiment of the present invention. In the first embodiment, when the current number CN of spare blocks decreases to below the garbage collection start threshold TH, the memory controller 110 will start the garbage collection operation. If the current number CN of spare blocks is equal to the garbage collection start threshold TH, the adjustment factor K will be set to zero. Before the current number CN of spare blocks reaches the target number TG of spare blocks, the write ratio GHWR of "garbage collection operation to host command" continues to be lower than the basic ratio BR of "garbage collection operation to host command". Therefore, the memory controller 110 will not perform too much valid data write based on the garbage collection operation, which causes the current number of spare blocks to slowly decrease CN.
[0035] Once the current number of spare blocks, CN, decreases to the target number of spare blocks, TG, the adjustment factor, K, increases to 1. At this point, the write ratio, GHWR, of "garbage collection operations to host commands" equals the basic ratio, BR, of "garbage collection operations to host commands," meeting the minimum write requirement for garbage collection operations. When the current number of spare blocks, CN, decreases to less than the target number of spare blocks, TG, the adjustment factor, K, increases to 1, meaning the write ratio, GHWR, of "garbage collection operations to host commands" increases to a greater value than the basic ratio, BR, of "garbage collection operations to host commands." At this point, the memory controller 110 executes more valid data writes based on garbage collection operations, thereby freeing up storage area occupied by more invalid pages and significantly increasing the number of spare blocks.
[0036] Figure 3The relevant process of performing garbage collection operations on the flash memory in the first embodiment of the present invention is illustrated. In step 310, the memory controller 110 determines whether the current number CN of spare blocks in the NV memory 120 is lower than the garbage collection start threshold TH. The garbage collection start threshold TH is a predetermined number of spare blocks and is set to be lower than the target number of spare blocks TG maintained by the FTL. If the memory controller 110 confirms that the current number CN of spare blocks in the NV memory 120 is less than the garbage collection start threshold TH, the process enters step 320; otherwise, the process stays at step 310. In step 320, the memory controller 110 calculates the basic ratio BR of "garbage collection operation to host command" based on the valid page percentage P of the source block. In step 330, the memory controller 110 determines the adjustment factor K based on the current number CN of spare blocks. The adjustment factor K has the following relationship with the current number CN of spare blocks: Figure 2 The negative correlation shown. In step 340, the memory controller 110 determines the write ratio GHWR of "garbage collection operation to host command" based on the adjustment factor K and the basic ratio BR of "garbage collection operation to host command". In step 350, the memory controller 110 performs a garbage collection write operation (i.e., writes user data according to the host command sent by the main control device 50) while also performing a garbage collection write operation (i.e., based on the garbage collection operation, moves valid data to the destination block). In step 360, the memory controller 110 ends the garbage collection operation. In some embodiments, the memory controller 110 may also check whether the destination block currently being written by the garbage collection operation has been filled (for example, data has been written to each page) before ending the garbage collection operation. If the destination block has not been filled, the process can return to step 320 to continue executing the garbage collection operation.
[0037] Please refer to Figure 4 , which illustrates the relationship between the current number CN of spare blocks, the target number TG of spare blocks, the garbage collection start threshold TH, and the adjustment factor K in the second embodiment of the present invention. In the second embodiment, once the current number CN of spare blocks is lower than the garbage collection start threshold TH, the memory controller 110 will decide to start the garbage collection operation. Similarly, there is a negative correlation between the adjustment factor K and the current number CN of spare blocks. The difference between the first embodiment and the second embodiment of the present invention is that when the garbage collection operation starts, the adjustment factor K is a non-zero value (i.e., greater than 0 and less than 1). In addition, since the management process of the garbage collection operation in the second embodiment is similar to that in the first embodiment, a detailed flow chart is not shown here for the sake of simplicity and conciseness of the specification.
[0038] Please refer to Figure 5 This figure illustrates the relationship between the current number of spare blocks (CN), the target number of spare blocks (TG), the garbage collection start threshold (TH2), the garbage collection termination threshold (TH1), and the adjustment factor (K) in a third embodiment of the present invention. In the third embodiment of the present invention, when the current number of spare blocks (CN) decreases below the garbage collection start threshold (TH2), the memory controller 110 decides to initiate a garbage collection operation. At this point, the adjustment factor (K) will be a non-zero value (i.e., greater than 0 and less than 1). Therefore, the memory controller 110 will not perform excessive garbage collection-based valid data writes. As the current number of spare blocks (CN) decreases, the adjustment factor (K) increases. Once the current number of spare blocks (CN) equals the target number of spare blocks (TG), the adjustment factor (K) will be 1. After the current number of spare blocks (CN) is less than the target number of spare blocks (TG), the adjustment factor (K) will be greater than 1, further causing the memory controller 110 to perform more garbage collection-based valid data writes. On the other hand, the memory controller 110 will only decide to terminate the garbage collection operation when the current number of spare blocks increases to the garbage collection termination threshold (TH1). At this point, the adjustment factor (K) will be zero. The difference between this embodiment and the previous embodiment is that the memory controller 110 relies on the garbage collection termination threshold value TH1 that is higher than the garbage collection start threshold value TH2 to determine whether to terminate the garbage collection operation, and relies on the garbage collection start threshold value TH2 to determine whether to start the garbage collection operation.
[0039] Figure 6 A flow chart of a method for managing garbage collection operations on a flash memory in a third embodiment of the present invention is shown. In step 610, the memory controller 110 determines whether the current number CN of spare blocks in the NV memory 120 is lower than the garbage collection start threshold TH2. If the memory controller 110 confirms that the current number CN of spare blocks in the NV memory 120 is less than the garbage collection start threshold TH2, the process proceeds to step 620; otherwise, the process stays at step 610. In step 620, the memory controller 110 calculates the basic ratio BR of "garbage collection operations to host commands" based on the valid page percentage P of the source block. In step 630, the memory controller 110 calculates the basic ratio BR of "garbage collection operations to host commands" based on the valid page percentage P of the source block. Figure 5The relationship shown in FIG6A is used to determine the adjustment factor K based on the current number of spare blocks, CN. In step 640, the memory controller 110 determines the write ratio, GHWR, of "garbage collection operations to host commands" based on the adjustment factor K and the basic ratio, BR, of "garbage collection operations to host commands." In step 650, while executing a host write operation (i.e., writing user data according to a host command sent by the master device 50), the memory controller 110 simultaneously performs a garbage collection write operation (i.e., writing valid data collected by the garbage collection operation to the destination block) based on the write ratio, GHWR, of "garbage collection operations to host commands." In step 660, the memory controller 110 determines whether the current number, CN, of spare blocks is greater than the garbage collection termination threshold, TH1. If so, the process proceeds to step 670 to terminate the garbage collection operation; otherwise, the process returns to step 620 to continue executing the garbage collection operation. In step 670, the memory controller 110 terminates the garbage collection operation. In one embodiment, the memory controller 110 may further check whether the target block currently being written to by the garbage collection operation is completely full (e.g., each page has been written with data) before terminating the garbage collection operation. If the target block is not completely full, the process may return to step 620 to continue executing the garbage collection operation.
[0040] In summary, an embodiment of the present invention provides a method for determining the timing of starting garbage collection and the write ratio of "garbage collection operation to host command". Among them, the present invention sets the garbage collection start threshold TH (or TH2) to be higher than the target number of spare blocks TG, and dynamically adjusts the write ratio GHWR of "garbage collection operation to host command" according to the current number of spare blocks CN. When the garbage collection operation is just started, the memory controller 110 will not perform too much valid data writing based on the garbage collection operation. Until the current number of spare blocks CN is lower than the target number of spare blocks TG, the memory controller 110 will perform more valid data writing based on the garbage collection operation. In view of this, the present invention can prevent the garbage collection operation from being frequently started and terminated, thereby making the response time to the host command more stable.
[0041] Determination of basic ratio
[0042] Embodiments of the present invention provide a mechanism for determining a base ratio of garbage collection operations to host commands. According to various embodiments of the present invention, the base ratio of garbage collection operations to host commands is calculated based on a total valid page percentage. The total valid page percentage is determined based on the number of valid pages in the source block from which valid data is currently being removed by the garbage collection operation, as well as the number of valid pages in one or more candidate source blocks.
[0043] Generally speaking, the valid page percentage of a source block is related to the amount of valid data written to the destination block by the memory controller during garbage collection operations. Therefore, when performing garbage collection operations on different source blocks, the base ratio of "garbage collection operations to the host" and the write ratio of "garbage collection operations to the host" will change. Once the source block is switched from one to another, the response time to host commands may fluctuate significantly, and the flash memory's write performance may degrade.
[0044] In order to solve such a problem, an embodiment of the present invention also considers one or more candidate source blocks when calculating the valid page percentage. Specifically, the memory controller 110 can select one or more candidate source blocks at the same time when determining the source block for the garbage collection operation. The source block can be selected by the flash memory controller 110 according to a specific strategy. For example, a block with the most invalid pages can be selected as the source block. Based on such a strategy, the memory controller 110 can also select candidate source blocks from those blocks with the second, third,... and Nth most invalid pages. In other words, those blocks with more invalid pages than other blocks can be selected as candidate source blocks. Please note that this strategy is not a limitation of the substantive scope of the present invention. According to various embodiments of the present invention, other factors can be considered when selecting one or more candidate source blocks.
[0045] Once the source block and the candidate source blocks are selected, the memory controller 110 may determine the overall valid page percentage P in different ways based on the number of valid pages in the source block and the candidate source blocks according to various embodiments of the present invention.
[0046] In the fourth embodiment of the present invention, the total valid page percentage P can be calculated by averaging the valid page percentage p0 of source block b0 and the valid page percentages p1-pk of candidate source blocks b1-bk, where k is the number of candidate source blocks and can be any integer greater than 1. Accordingly, the memory controller 110 determines the total valid page percentage P according to the following formula:
[0047] P=(p0+p1+…+pk) / (k+1)
[0048] exist Figure 7AIn the fifth embodiment of the present invention, the overall valid page percentage P is determined by calculating the weighted average of the valid page percentage p0 of source block b0 and the valid page percentages p1-pk of candidate source blocks b1-bk. In such an embodiment, the memory controller 110 further determines the weight w0 of source block b0 and the weights w1-wk of candidate source blocks b1-bk. In a preferred embodiment, the weight w0 can be greater than the weights w1-wk, and the sum of the weights w0-wk is 1. Accordingly, the memory controller 110 determines the overall valid page percentage P according to the following formula:
[0049] P=w0*p0+w1*p1+…+wk*pk
[0050] In this embodiment, the weight of a block is related to the number of invalid pages in the block. For example, if the number of invalid pages n1-n3 in candidate source blocks b1-b3 has the relationship n1>n2>n3, then the weights w1-w3 of candidate source blocks b1-b3 will have the relationship w1>w2>w3. In addition, if the memory controller 110 has completed the operation of moving the valid page data of source block b0 to the destination block and continues to move the valid page data of source block b1 to the destination block, the memory controller 110 can reselect a candidate source block. At this time, the reselected candidate source block can be the same as or different from the previously selected candidate source blocks b2-bk. This is because other mechanisms running on the memory controller 110 may cause the number of invalid pages in the block to continue to change. In addition, if the memory controller 110 has completed the operation of moving the valid page data of source block b0 to the destination block, the memory controller 110 can reselect a block instead of using the first-ranked block b1 in the candidate source blocks as the subsequent source block.
[0051] In the sixth embodiment of the present invention, the total valid page percentage P can be determined by performing a moving average calculation on the number of valid pages in source block b0 and candidate source blocks b1-b3. Please note that the number of candidate source blocks here is not a limitation of the present invention.
[0052] Please refer to Figures 7B to 7D For further understanding. As shown in the figure, Figure 7BThe source block b0 and candidate source blocks b1-b3 are shown, where the shaded cells in the block represent invalid pages and the white cells in the block represent valid pages. The moving window MW selects a predetermined number of pages (e.g., G pages) that have not been processed by the garbage collection operation from the source block b0 and the candidate source blocks b1-b3. Specifically, the selection range of the moving window MW starts at page i in the source block b0 and ends at page w in the candidate source block b3. Therefore, the memory controller 110 determines the overall valid page percentage P based on the ratio of the number of valid pages in the moving window MW to the total number of pages G in the moving window MW. As shown Figure 7B As shown, the overall valid page percentage P is:
[0053] P=(6+17+18+12) / 24*3
[0054] In one embodiment, the memory controller 110 may re-determine the total valid page percentage P of the source block b0 and the candidate source blocks b1-b3 at any time point during the garbage collection operation. Figure 7C As shown, after pages i through (i+3) in source block b0 have been garbage collected (i.e., the data in pages i, (i+2), and (i+3) of source block b0 has been moved to the destination block), the memory controller 110 can re-determine the overall valid page percentage P. At this point, the moving window MV moves downward to select unprocessed pages. The selection range begins at page (i+4) in source block b0 and ends at page (w+4) in candidate source block b3. Therefore, the memory controller 110 re-determines the overall valid page percentage P based on the number of valid pages among the G pages selected by the moving window MV.
[0055] According to various embodiments of the present invention, the memory controller 110 can reselect candidate source blocks while re-determining the overall valid page percentage P. Figure 7D More details in . After the garbage collection operation has processed several pages in the source block b0, the memory controller 110 can re-determine the overall valid page percentage P. Figure 7DAs shown, the memory controller 110 can reselect candidate source blocks (i.e., blocks b4-b6) and re-determine the overall valid page percentage P based on the number of valid pages in the G pages selected by the moving window MV from source block b0 and candidate source blocks b4-b6. In one embodiment, when determining the overall valid page percentage P of the pages selected by the moving window MW, the memory controller 110 can also assign certain weights to the number of valid pages in different blocks and calculate the overall valid page percentage P accordingly. For example, the number of valid pages in source block b0 is assigned weight w0, and the number of valid pages in candidate source blocks b4-b6 is assigned weights w1-w3.
[0056] Once the memory controller 110 calculates the overall valid page percentage P, it can perform garbage collection operations accordingly. The memory controller 110 can determine an adjustment factor K based on the current number CN of spare blocks in the NV memory 120. Furthermore, the memory controller 110 can calculate a basic ratio BR of "garbage collection operations to host commands" based on the overall valid page percentage P. Finally, the memory controller 110 determines the aforementioned "garbage collection operations to host commands" write ratio GHWR based on the adjustment factor K and the basic ratio BR of "garbage collection operations to host commands." Based on the "garbage collection operations to host commands" write ratio GHWR, the memory controller 110 simultaneously performs garbage collection write operations and host command write operations.
[0057] Figure 8 A flow chart of a method for managing garbage collection operations on flash memory in the fourth, fifth and sixth embodiments of the present invention is depicted. In step 810, the memory controller 110 selects a source block and at least one candidate source block from the NV memory 120 based on a specific strategy, such as the number of invalid pages in the block. In step 820, the memory controller determines the overall valid page percentage P based on the number of valid pages in the source block and at least one candidate source block. According to the aforementioned embodiment, the overall valid page percentage P can be obtained through a general average, a weighted average or a moving average calculation. In step 830, the memory controller 110 calculates the basic ratio BR of "garbage collection operations to host commands" based on the overall valid page percentage P, where BR=P / (1-P). In step 840, the memory controller 110 determines an adjustment factor K based on the current number of spare blocks. There is a negative correlation between the adjustment factor K and the current number of spare blocks, and can have the following relationship: Figure 2 、 4Or the relationship shown in 5. In step 850, the memory controller 110 determines the write ratio GHWR of "garbage collection operation to host command" based on the adjustment factor K and the basic ratio BR of "garbage collection operation to host command". The write ratio GHWR of "garbage collection operation to host command" can be determined by the following formula: GHWR = K*BR. In step 860, the memory controller 110 performs a garbage collection write operation (i.e., writes the valid data collected by the garbage collection operation to the target block) according to the write ratio GHWR of "garbage collection operation to host command" while performing a host write operation (i.e., writes user data according to the host command sent by the main control device 50). In step 870, the memory controller 110 determines whether the target block currently being written by the garbage collection operation has been completely filled (i.e., whether each page has been written with data). If yes, the process ends and the memory controller 110 ends the garbage collection operation. Otherwise, the process proceeds to step 880, where the memory controller 110 further determines whether the current source block has been completely read (i.e., whether the data of each valid page has been moved to the destination block). If yes, the process returns to step 810 to reselect the source block and one or more candidate source blocks. Otherwise, the process returns to step 860 to continue the garbage collection operation.
[0058] In the above-described embodiment, the present invention relies on selecting one or more candidate source blocks and calculating the overall valid page percentage to mitigate variations in valid page percentages between different source blocks. Consequently, when switching from one source block to another, drastic fluctuations in the base ratio (BR) of "garbage collection operations to host commands" and the write ratio (GHWR) of "garbage collection operations to host commands" can be avoided. Consequently, the present invention can maintain a stable response time to host commands, avoiding degradation of the flash memory's write performance during garbage collection operations.
[0059] Estimation of spare area and determination of adjustment factor
[0060] Embodiments of the present invention provide a mechanism for estimating the spare area of a flash memory. In such an embodiment, the memory controller 110 estimates the total spare area of the NV memory 120 in smaller units, rather than in blocks. According to various embodiments of the present invention, there are several sizes of spare areas to be evaluated, such as spare area (A) in one or more target blocks where user data is written in host commands, spare area (B) in one or more destination blocks where valid data is written in garbage collection operations, spare area (C) in source blocks where valid data is read in garbage collection operations, and spare area (D) in spare blocks in the NV memory 120. The present invention estimates the total spare area of the NV memory 120 based on these spare areas.
[0061] Please refer to Figure 9 Details disclosed. First, the spare area (A) represents the logical block addresses of one or more target blocks that have not yet been used or written. These one or more target blocks are the blocks to which user data in a host command is currently being written. Second, the spare area (B) represents the logical block addresses of one or more destination blocks that have not yet been used or written. These one or more destination blocks are blocks to which valid data collected by a garbage collection operation is currently being written, or is about to be written. In some embodiments, the one or more target blocks to which user data is currently being written may be the same as the one or more destination blocks to which valid data is currently being written, or is about to be written. Therefore, the spare area (A) may be the same as the spare area (B). In some embodiments, user data in a host command may be written to more than one target block simultaneously. Therefore, the spare area (A) is the sum of the spare areas of each target block to which user data is currently being written. In some embodiments, valid data in a garbage collection operation may be written to more than one destination block simultaneously. Therefore, the spare area (B) is the sum of the spare areas of each destination block to which valid data is currently being written, or is about to be written.
[0062] Furthermore, the spare area (C) represents the logical block addresses of the source block that have been read by the garbage collection operation (i.e., the amount of data that has been moved to the destination block). The garbage collection operation reads valid data from the source block. Since the spare area (C) cannot be used to write new data until the source block is erased, the spare area (C) is calculated by estimating the amount of data in the source block that has been copied / read by the garbage collection operation and the percentage of valid pages in the source block. In other words, the spare area (C) is determined by the following formula: Moved_D / P. Moved_D is the amount of data in the source block that has been copied / read by the garbage collection operation, and P is the percentage of valid pages in the source block. In some embodiments, the garbage collection operation may read more than one source block simultaneously. Therefore, the spare area (C) is the sum of the spare areas of each source block currently reading valid data by the garbage collection operation. Fourth, the spare area (D) represents the logical block address of the spare block in the NV memory 120.
[0063] According to various embodiments of the present invention, the memory controller 110 may estimate the total spare area of the NV memory 120 using one of the following summations:
[0064] 1) Spare area (A) + spare area (D)
[0065] 2) Spare area (A) + spare area (B) + spare area (D)
[0066] 3) Spare area (A) + spare area (B) + spare area (C) + spare area (D)
[0067] 4) Spare area (B) + spare area (C) + spare area (D)
[0068] 5) Spare area (A) + spare area (C) + spare area (D)
[0069] Once the memory controller 110 calculates the total spare area of the NV memory 120, it can perform garbage collection operations accordingly. Based on the calculated total spare area of the NV memory 120, the memory controller 110 can determine an adjustment factor, K. Based on this, the memory controller 110 determines a garbage collection write ratio, GHWR, based on the adjustment factor K and the base ratio, BR, of "garbage collection operations to host commands." Thus, while executing host write operations, the memory controller 110 simultaneously performs garbage collection write operations based on the write ratio, GHWR.
[0070] In extreme cases, the total spare area can be estimated in units of 4K bytes. This is much smaller than the units used in conventional technology to estimate the spare area: 128K or 256K bytes (i.e., block size). Since changes in the spare area are reflected in smaller units, changes in the adjustment factor K are also more subtle, allowing the write ratio GHWR of "garbage collection operations to host commands" to be adjusted more finely. In addition, the present invention can track changes in the spare areas (e.g., spare area (A), spare area (B), and spare area (C)) after each write operation based on host commands and / or garbage collection occurs. Therefore, the total spare area can more quickly reflect changes in the spare areas within the flash memory. The memory controller 110 can re-determine the adjustment factor K and the write ratio GHWR of "garbage collection operations to host commands" at any point in time during the execution of the garbage collection operation.
[0071] In a preferred embodiment of the present invention, the memory controller 110 may decide to initiate a garbage collection operation if the current number of spare blocks in the NV memory 120 is less than or equal to a garbage collection operation initiation threshold value that is higher than the target number of spare blocks maintained by the FTL of the NV memory 120. In another embodiment, the memory controller 110 may decide to initiate a garbage collection operation only when the current number of spare blocks is less than or equal to the target number of spare blocks.
[0072] Figure 10 A flow chart of a method for managing garbage collection operations in a flash memory according to a seventh embodiment of the present invention is shown. In step 1010, the memory controller 110 selects a source block for a garbage collection operation from the NV memory 120. In step 1020, the memory controller 110 determines a valid page percentage P based on the number of valid pages in the source block. In step 1030, the memory controller 110 calculates a basic ratio of "garbage collection operations to host commands," BR, based on the valid page percentage P. The basic ratio of "garbage collection operations to host commands," BR, can be determined as follows: BR = P / (1-P). In step 1040, the memory controller 110 estimates the total spare area in the NV memory 120. According to various embodiments of the present invention, the memory controller 110 may include spare areas in various blocks, such as one or more target blocks of host commands, destination blocks of garbage collection operations, source blocks of garbage collection operations, and spare blocks in the NV memory 120, in its calculations. In step 1050, the memory controller 110 determines an adjustment factor K based on the total spare area. The adjustment factor K and the size of the total spare area may have a relationship as follows: Figure 2 、 45. In step 1060, the memory controller determines a write ratio GHWR of "garbage collection operations to host commands" based on the adjustment factor K and the basic ratio BR of "garbage collection operations to host commands," wherein the write ratio GHWR of "garbage collection operations to host commands" can be determined as follows: GHWR = K * BR. In step 1070, while executing a host write operation (i.e., writing user data according to a host command sent by the master device 50), the memory controller 110 performs a garbage collection operation (i.e., writing valid data collected in the garbage collection operation to the destination block) based on the write ratio GHWR of "garbage collection operations to host commands." In step 1080, the memory controller 110 determines whether the destination block currently being written to by the garbage collection operation is completely full (e.g., every page has been written). If so, the process ends and the memory controller 110 ends the garbage collection operation. Otherwise, the process proceeds to step 1090, where the memory controller 110 determines whether the current source block has been completely read (i.e., the data of each valid page has been moved to the destination block). If so, the process returns to step 1010 to reselect the source block. Otherwise, the process returns to step 1070 to continue the garbage collection operation.
[0073] In the above embodiment, the memory controller 110 estimates the total spare area of the flash memory in smaller units. Therefore, the adjustment factor K can reflect subtle changes in the flash memory spare area, thereby adjusting the "garbage collection operation to host command" write ratio (GHWR) in a more refined manner, thereby avoiding drastic changes in the response time to host commands. Furthermore, because the estimated total spare area can more accurately reflect the available space in the flash memory (i.e., estimated in smaller units) and is timely (i.e., re-estimated after each write operation), the garbage collection operations performed by the memory controller 110 can be more responsive to the available space in the flash memory.
[0074] The embodiments of the present invention may be implemented using hardware, software, firmware, and combinations thereof. Software firmware stored in a memory may be used to implement the embodiments of the present invention through an appropriate instruction execution system. Hardware may be implemented using any of the following technologies or combinations thereof: individual arithmetic logic having logic gates that can perform logic functions based on data signals, an application-specific integrated circuit (ASIC) having suitable combinational logic gates, a programmable gate array (PGA), or a field programmable gate array (FPGA).
[0075] The processes and blocks in the flowcharts within the specification illustrate the architecture, functions, and operations that can be implemented by the systems, methods, and computer software products of various embodiments of the present invention. In this regard, each block in the flowchart or function block diagram can represent a module, section, or portion of a program code that includes one or more executable instructions for implementing a specified logical function. In addition, each block in the function block diagram and / or flowchart, as well as the combination of blocks, can essentially be implemented by a dedicated hardware system that performs a specified function or action, or by a combination of dedicated hardware and computer program instructions. These computer program instructions can also be stored in a computer-readable medium that can enable a computer or other programmable data processing device to operate in a specific manner so that the instructions stored in the computer-readable medium implement the functions / actions specified by the blocks in the flowchart and / or function block diagram.
[0076] The above description is only a preferred embodiment of the present invention. All equivalent changes and modifications made according to the scope of the patent application of the present invention should fall within the scope of the present invention.
Claims
1. A method for managing garbage collection operations on a flash memory, comprising: Set a garbage collection start threshold, where The garbage collection activation threshold indicates a predetermined number of spare blocks, the predetermined number of spare blocks being higher than a target number of spare blocks maintained by a flash translation layer of the flash memory; determining whether to initiate a garbage collection operation based on a current number of spare blocks in the flash memory and the garbage collection activation threshold; as well as When the current number of spare blocks is less than or equal to the garbage collection activation threshold, performing the garbage collection operation on a source block in the flash memory includes: Calculating a basic ratio of garbage collection operations to host commands according to a valid page percentage of the source block; determining an adjustment factor according to the current number of spare blocks; determining a write ratio of garbage collection operations to host commands based on a product of the basic ratio of garbage collection operations to host commands and the adjustment factor, wherein the write ratio of garbage collection operations to host commands indicates a ratio between an amount of valid data written based on garbage collection operations and an amount of user data written based on host commands; as well as When executing user data writing based on host commands, executing valid data writing based on garbage collection operations according to a write ratio of the garbage collection operations to the host commands; When the current number of spare blocks in the flash memory is lower than the garbage collection start threshold and greater than the target number of spare blocks, the adjustment factor is set to a value greater than 0 and less than 1; and when the current number of spare blocks in the flash memory is lower than the target number of spare blocks, the adjustment factor is set to a value greater than 1.
2. The method according to claim 1, wherein The adjustment factor is negatively correlated with the current number of spare blocks.
3. The method according to claim 1, wherein When the current number of spare blocks in the flash memory is equal to the garbage collection activation threshold, the adjustment factor is set to 0; and when the current number of spare blocks in the flash memory is equal to the target number of spare blocks, the adjustment factor is set to 1.
4. The method according to claim 1, wherein When the current number of spare blocks in the flash memory is equal to the garbage collection start threshold, the adjustment factor is set to a value between 0 and 1; and when the current number of spare blocks in the flash memory is equal to the target number of spare blocks, the adjustment factor is set to 1.
5. The method according to claim 1, wherein Also includes: Setting a garbage collection termination threshold higher than the garbage collection start threshold; and When the current number of spare blocks in the flash memory is higher than the garbage collection termination threshold, the garbage collection operation is terminated.
6. The method according to claim 5, wherein When the current number of spare blocks in the flash memory is equal to the garbage collection termination threshold, the adjustment factor is set to 0; when the current number of spare blocks in the flash memory is equal to the garbage collection start threshold, the adjustment factor is set to a value between 0 and 1; and when the current number of spare blocks in the flash memory is equal to the target number of spare blocks, the adjustment factor is set to 1.
7. A controller for controlling the operation of a flash memory and managing garbage collection operations on the flash memory, comprising: a storage unit for storing information; and a processing unit configured to perform the following operations according to the program code and information stored in the storage unit or the flash memory: Set a garbage collection start threshold, where The garbage collection activation threshold indicates a predetermined number of spare blocks, the predetermined number of spare blocks being higher than a target number of spare blocks maintained by a flash translation layer of the flash memory; determining whether to initiate a garbage collection operation based on a current number of spare blocks in the flash memory and the garbage collection activation threshold; as well as When the current number of spare blocks is less than or equal to the garbage collection activation threshold, performing the garbage collection operation on a source block in the flash memory includes: Calculating a basic ratio of garbage collection operations to host commands according to a valid page percentage of the source block; determining an adjustment factor according to the current number of spare blocks; determining a write ratio of garbage collection operations to host commands based on a product of the basic ratio of garbage collection operations to host commands and the adjustment factor, wherein the write ratio of garbage collection operations to host commands indicates a ratio between an amount of valid data written based on garbage collection operations and an amount of user data written based on host commands; as well as When executing user data writing based on host commands, executing valid data writing based on garbage collection operations according to a write ratio of the garbage collection operations to the host commands; When the current number of spare blocks in the flash memory is lower than the garbage collection start threshold and greater than the target number of spare blocks, the adjustment factor is set to a value greater than 0 and less than 1; and when the current number of spare blocks in the flash memory is lower than the target number of spare blocks, the adjustment factor is set to a value greater than 1.
8. The controller according to claim 7, wherein: The controller controls the adjustment factor and the current number of spare blocks so that the two are negatively correlated.
9. The controller according to claim 7, wherein: The controller sets the adjustment factor to 0 when the current number of spare blocks in the flash memory is equal to the garbage collection activation threshold; and sets the adjustment factor to 1 when the current number of spare blocks in the flash memory is equal to the target number of spare blocks.
10. The controller according to claim 7, wherein: When the current number of spare blocks in the flash memory is equal to the garbage collection start threshold, the controller sets the adjustment factor to a value between 0 and 1; and when the current number of spare blocks in the flash memory is equal to the target number of spare blocks, the controller sets the adjustment factor to 1.
11. The controller according to claim 7, wherein: The controller further sets a garbage collection termination threshold value that is higher than the garbage collection start threshold value; and when the current number of spare blocks in the flash memory is higher than the garbage collection termination threshold value, the controller terminates the garbage collection operation.
12. The controller according to claim 11, wherein When the current number of spare blocks in the flash memory is equal to the garbage collection termination threshold, the controller sets the adjustment factor to 0; when the current number of spare blocks in the flash memory is equal to the garbage collection start threshold, the controller sets the adjustment factor to a value between 0 and 1; and when the current number of spare blocks in the flash memory is equal to the target number of spare blocks, the controller sets the adjustment factor to 1.
13. A storage device comprising: A flash memory for providing storage space; A controller, coupled to the flash memory, for operating the flash memory and managing garbage collection operations on the flash memory, comprising: a storage unit for storing information; and a processing unit configured to perform the following operations according to the program code and information stored in the storage unit or the flash memory: Set a garbage collection start threshold, where The garbage collection activation threshold indicates a predetermined number of spare blocks, the predetermined number of spare blocks being higher than a target number of spare blocks maintained by a flash translation layer of the flash memory; determining whether to initiate a garbage collection operation based on a current number of spare blocks in the flash memory and the garbage collection activation threshold; as well as When the current number of spare blocks is less than or equal to the garbage collection activation threshold, performing the garbage collection operation on a source block in the flash memory includes: Calculating a basic ratio of garbage collection operations to host commands according to a valid page percentage of the source block; determining an adjustment factor according to the current number of spare blocks; determining a write ratio of garbage collection operations to host commands based on a product of the basic ratio of garbage collection operations to host commands and the adjustment factor, wherein the write ratio of garbage collection operations to host commands indicates a ratio between an amount of valid data written based on garbage collection operations and an amount of user data written based on host commands; as well as When executing user data writing based on host commands, executing valid data writing based on garbage collection operations according to a write ratio of the garbage collection operations to the host commands; When the current number of spare blocks in the flash memory is lower than the garbage collection start threshold and greater than the target number of spare blocks, the adjustment factor is set to a value greater than 0 and less than 1; and when the current number of spare blocks in the flash memory is lower than the target number of spare blocks, the adjustment factor is set to a value greater than 1.
Citation Information
Patent Citations
Dynamic and static data for a system having non-volatile memory
TW201245959A
Memory storage device and operation method thereof
TW202011186A