Garbage collection method, device and computing device for flash memory

CN123011125APending Publication Date: 2026-10-30CHENGDU HUAWEI TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510472643.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-15
Publication Date
2026-10-30

AI Technical Summary

Technical Problem

如果频繁的进行垃圾回收,会严重影响闪存存储器的性能和寿命

Benefits of technology

[0058]第五方面,本申请提供了一种计算机存储介质,计算机存储介质中存储有指令,当指令在计算机上运行时,使得计算机执行第一方面中所提供的方法,或执行第二方面所提供的方法。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123011125A_ABST
    Figure CN123011125A_ABST
Patent Text Reader

Abstract

Provided are a garbage collection method, device and computing equipment of a flash memory. In an embodiment, when there is a target block in the flash memory that needs to be garbage collected, the flash memory determines the valid time length of different valid data in the target block, the valid time length being used to indicate the length of time from when the valid data is valid to when the valid data is invalidated; the flash memory migrates the valid data to a free block having free space according to the valid time length, wherein valid time lengths in different ranges are migrated to different free blocks; and the flash memory performs data erasure on the target block. In this way, the valid time length of each piece of data can be accurately controlled, the timing of garbage collection of the flash memory can be accurately controlled, and the frequency of garbage collection can be reduced, i.e., the write amplification of the flash memory can be reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of storage technology, and in particular to a method, apparatus and computing device for garbage collection of flash memory. Background Technology

[0002] Flash memory is based on flash memory. Compared with traditional hard disk drives (HDDs), flash memory has significant advantages such as high speed and high reliability. With the continuous development of flash memory technology, the cost has been decreasing year by year, and it has been increasingly widely used in enterprise-level storage and data centers in recent years.

[0003] As data is continuously written to and deleted from flash memory, invalid data will accumulate. Garbage collection (GC) is necessary to reclaim the storage space occupied by this invalid data. However, garbage collection introduces additional write operations, known as write amplification. Frequent garbage collection can severely impact the performance and lifespan of flash memory.

[0004] Therefore, how to reduce write amplification in flash memory has become an urgent problem to be solved. Summary of the Invention

[0005] This application provides a method, apparatus, and computing device for garbage collection of flash memory, which can precisely control the effective duration of each piece of data, thereby reducing the frequency of garbage collection, i.e., reducing write amplification of flash memory.

[0006] In a first aspect, this application provides a garbage collection method for flash memory, the method comprising:

[0007] When there is a target block in the flash memory that needs to be garbage collected, the flash memory determines the validity duration of different valid data in the target block. The validity duration is used to indicate the length of time that the valid data has been invalidated.

[0008] Flash memory migrates valid data to free blocks with available space based on the validity period. Valid data with different validity periods are migrated to different free blocks.

[0009] Flash memory erases data from the target block.

[0010] When performing garbage collection on a block, valid data must be migrated out before the block can be erased. If data with varying lifespans are mixed together in the same block, a situation may arise where a large amount of data in the same block is still valid, while only a small amount is invalid. In this case, a large amount of data needs to be migrated to other blocks, and this migration process is also a data writing process, thus causing "write amplification." According to the above solution, whenever there is a target block in the flash memory that needs to be garbage collected, the flash memory can determine the validity period of the valid data and then aggregate the valid data with different validity periods into different blocks.

[0011] In other words, after garbage collection, the effective durations of multiple data items stored in the same block will not differ significantly (but rather will be the same or similar). In other words, they will become invalid data at the same or similar time points in the future. Therefore, when these blocks need to be garbage collected again later, it is very likely that a large portion (or even all) of the data in these blocks will have become invalid. The invalid data no longer needs to be migrated, thus avoiding write amplification. Therefore, this scheme reduces write amplification in flash memory caused by garbage collection.

[0012] In one possible implementation, at least one target block in the flash memory requires garbage collection.

[0013] In this way, multiple valid data can be migrated to different free blocks according to their respective valid durations, thereby ensuring that the valid durations of valid data in the free blocks are similar or the same, reducing write amplification of the flash memory.

[0014] In one possible implementation, the method also includes:

[0015] The receiving host sends multiple data items and indication information for each of the multiple data items. The indication information is used to indicate the target duration during which each data item becomes invalid. The indication information for each data item is generated by the host.

[0016] In this way, the host-generated indication information can determine the remaining effective duration of each data at different times, thereby migrating the effective data according to the effective duration, so that the effective duration of the effective data in the free block can be similar or the same, thereby reducing write amplification of the flash memory.

[0017] In one possible implementation, the validity duration of different valid data in the target block is determined, including:

[0018] The validity period of different valid data is determined based on the indication information of different valid data.

[0019] In this way, the host-generated indication information can determine the remaining effective duration of each data at different times, thereby migrating the effective data according to the effective duration, so that the effective duration of the effective data in the free block can be similar or the same, thereby reducing write amplification of the flash memory.

[0020] In one possible implementation, the method also includes:

[0021] Based on the indication information of each data point in the multiple data sets, each data point is written into multiple target blocks. Data with target durations in different ranges are stored in different target blocks.

[0022] This ensures that the target duration indicated by the data within the target block is within the same range, enabling data within the same block to fail at the same or similar time, reducing data migration, and thus reducing write amplification of the flash memory.

[0023] In one possible implementation, the indicator information is the point in time when the data becomes invalid.

[0024] In one possible implementation, the method also includes:

[0025] When the indication information of the target data indicates that the target data is valid for a long time, the target data is set to a sealed state. The sealed state is used to indicate that the data can only be read and cannot be erased or migrated. Multiple data include the target data.

[0026] Among them, "target data is valid for a long time" means that the target duration or validity duration of the target data is greater than the preset duration threshold.

[0027] This reduces data migration, thereby reducing write amplification in flash memory.

[0028] In one possible implementation, valid data also has the attribute of hotness or coldness, and multiple valid data with the same hotness or coldness include different valid durations.

[0029] Secondly, embodiments of this application provide a data migration method for a flash memory, characterized in that the method includes:

[0030] When valid data in flash memory needs to be migrated, the validity period of the valid data is determined. The validity period is used to indicate the length of time since the valid data was invalidated.

[0031] Based on the validity duration of the valid data, the first block is determined from multiple blocks, and the validity duration of the second data in the first block is the same as or similar to the validity duration of the valid data.

[0032] Migrate valid data from the target block to the first block;

[0033] Erase the data in the target block.

[0034] The phrase "the effective duration of the second data is similar to the effective duration of the effective data" means that the difference between the effective duration of the second data and the effective duration of the effective data is less than a preset difference threshold.

[0035] This scheme ensures that whenever valid data needs to be migrated from the flash memory, the flash memory determines the validity period of the valid data and selects a first block from multiple blocks. The validity period of the second data in this first block is the same as that of the valid data. Then, the flash memory migrates the valid data from the target block to the first block. Since all data in the first block has the same validity period, the invalidation time of the data in the first block is also the same. Even if the first block needs garbage collection due to invalid data, no data migration is required, reducing write amplification in the flash memory.

[0036] Thirdly, embodiments of this application provide a garbage collection device for a flash memory, the device comprising:

[0037] The determination module is used to determine the validity duration of different valid data in the target block when there is a target block in the flash memory that needs to be garbage collected. The validity duration is used to indicate the length of time that the valid data has been invalidated.

[0038] The migration module is used to migrate valid data from the flash memory to free blocks with available space based on the valid duration. Valid data with different valid durations are migrated to different free blocks.

[0039] The erase module is used to erase data from the target block.

[0040] In one possible implementation, at least one target block in the flash memory requires garbage collection.

[0041] In one possible implementation, the device further includes:

[0042] The receiving module is used to receive multiple data sent by the host and the validity period of each data. The validity period of each data is generated by the host.

[0043] In one possible implementation, the determining module is used to determine the validity duration of different valid data based on the indication information of different valid data.

[0044] In one possible implementation, the device further includes:

[0045] The write module is used to write each piece of data into multiple target blocks according to the indication information of each piece of data in multiple data sets. The target blocks are different for data with target durations in different ranges.

[0046] In one possible implementation, the indication information is the time point at which the data becomes invalid data.

[0047] In one possible implementation, the device further includes:

[0048] When the indication information of the target data indicates that the target data is valid for a long time, the target data is set to a sealed state. The sealed state is used to indicate that the data can only be read and cannot be erased or migrated. The multiple data include the target data.

[0049] In one possible implementation, the valid data also has a hot / cold attribute, and multiple valid data with the same hot / cold attribute include different valid durations.

[0050] Fourthly, embodiments of this application provide a data migration apparatus for a flash memory, the apparatus comprising:

[0051] The first determining module is used to determine the validity duration of valid data when valid data in flash memory needs to be migrated. The validity duration is used to indicate the length of time since the valid data was invalidated.

[0052] The second determining module is used to determine the first block from multiple blocks based on the validity duration of the valid data, wherein the validity duration of the second data in the first block is the same as the validity duration of the valid data.

[0053] The migration module is used to migrate valid data from the target block to the first block;

[0054] The erase module is used to erase data from the target block.

[0055] Fifthly, this application provides a computing device, comprising: at least one memory for storing a program; and at least one processor for executing the program stored in the memory, wherein when the program stored in the memory is executed, the processor is configured to execute the method provided in the first aspect or the method provided in the second aspect.

[0056] In a sixth aspect, this application provides a computing device, characterized in that the device executes computer program instructions to perform the method provided in the first aspect. For example, the device may be a chip or a processor.

[0057] In one example, the device may include a processor that may be coupled to memory, read instructions from the memory and execute the methods provided in the first aspect or the methods provided in the second aspect according to those instructions. The memory may be integrated into the chip or processor, or it may be independent of the chip or processor.

[0058] Fifthly, this application provides a computer storage medium storing instructions that, when executed on a computer, cause the computer to perform the method provided in the first aspect or the method provided in the second aspect.

[0059] Sixthly, this application provides a computer program product containing instructions that, when executed on a computer, cause the computer to perform the method provided in the first aspect or the method provided in the second aspect.

[0060] Any of the devices, computer storage media, or computer program products provided above are used to execute the methods provided above. Therefore, the beneficial effects they can achieve can be referred to the beneficial effects of the corresponding solutions in the corresponding methods provided above, and will not be repeated here. Attached Figure Description

[0061] Figure 1 This is an exemplary schematic diagram of waste recycling in the prior art provided in this application embodiment;

[0062] Figure 2 This is a schematic diagram of the structure of a flash memory provided in an embodiment of this application;

[0063] Figure 3 This is a schematic diagram of the architecture of a garbage collection system for a flash memory provided in an embodiment of this application;

[0064] Figure 4 This is a schematic flowchart of a garbage collection method for a flash memory provided in an embodiment of this application;

[0065] Figure 5 This is a schematic diagram of a target duration management state machine provided in an embodiment of this application;

[0066] Figure 6 This is a flowchart illustrating a data processing method during waste recycling provided in an embodiment of this application;

[0067] Figure 7 This is an exemplary schematic diagram of a data migration method provided in an embodiment of this application;

[0068] Figure 8 This is an exemplary schematic diagram of another data migration method provided in the embodiments of this application;

[0069] Figure 9 This is a schematic diagram of the structure of a garbage collection device for a flash memory provided in an embodiment of this application;

[0070] Figure 10 This is a schematic diagram of the structure of a data migration device for a flash memory provided in an embodiment of this application;

[0071] Figure 11 This is a schematic diagram of the structure of a computing device provided in an embodiment of this application. Detailed Implementation

[0072] The technical solutions of the embodiments of this application will now be described with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. All other embodiments obtained based on the embodiments of this application are within the scope of protection of this application.

[0073] Erasure Unit / Block: An eraser unit / block is the smallest eraser unit in a flash memory. The smallest write unit in a flash memory is a page, and an eraser unit comprises multiple pages. In this embodiment of the invention, the flash memory is a memory that uses flash memory as its storage medium, such as a flash memory storage device, or a mobile phone (using UFS standard flash memory), game console, music player, e-reader, television, set-top box, in-vehicle system, etc. For simplicity, since the principle is the same, the following description uses a flash memory as an example.

[0074] As data is continuously written to and deleted from flash memory, invalid data will accumulate. However, flash memory has limited storage space, necessitating garbage collection (GC).

[0075] In one technology, the multi-stream specification in the Non-Volatile Memory Express (NVMe) protocol can group and aggregate blocks with similar "hotness" attributes during write operations. However, this grouping and aggregation only occurs during write operations. During subsequent garbage collection, valid blocks need to be migrated, but the migration process does not consider the data's "hotness" or expected lifespan. This results in data of varying "hotness" being mixed together due to GC. Therefore, invalid block migrations occur before the second garbage collection, leading to write amplification in flash memory.

[0076] For example, the erase unit containing data A1 and A4, and data A and A5, requires secondary garbage collection. Although data A1, A4, A2, and A5 are about to expire, they are not actually invalid; that is, data A1, A4, A2, and A5 are actually cold data. Therefore, data A1, A4, A2, and A5 need to be migrated. However, the multi-stream specification only considers classification and aggregation during data writing. Therefore, during the migration of data A1, A4, A2, and A5, the "hotness" attribute of data A1 and A4 cannot be considered, meaning the migration of data A1, A4, A2, and A5 has a randomness. Figure 1 In part (a) shown, data A1 and data A4 are written to erase unit 1. Erase unit 1 also stores data B1 and data B4, which are hot data. Data A2 and data A5 are migrated to erase unit 2, which also stores data B2 and data B5, which are warm data. Figure 1 As shown in section (b), shortly after data A1 and data A4 are written to erase unit 1, data A1, data A4, data A2, and data A5 become invalid. Therefore, a second garbage collection is required for erase unit 1 and erase unit 2. Data B1, data B4, data B2, and data B5 are not yet invalid; therefore, data B1, data B4, data B2, and data B5 need to be migrated. Figure 1 As shown in section (c), data B1, B4, B2, and B5 are migrated to erase unit 4. However, after migrating data B1, B4, B2, and B5 to erase unit 4, data B1 and B4 become warm data, while data B2 and B5 become invalid data. In order to enable garbage collection in erase unit 4, data B1 and B4 need to be migrated again. In the above garbage collection process, because the data's "warmth" attribute was not considered, data B1 and B4 were migrated multiple times. Furthermore, migrating data B1 and B4 to erase unit 4 is an invalid migration, increasing write amplification of the flash memory. Thus, the migration of data B1 and B4 is actually an invalid migration, increasing write amplification of the flash memory.

[0077] The Flexible Data Placement (FDP) technology in the NVMe protocol manages data by grouping it, focusing only on whether blocks belong to the same data type. Therefore, it cannot precisely control the target duration of each data item, leading to a certain degree of invalid migration. For example, the host device may only be temporarily storing data that is about to expire or be overwritten. However, if garbage collection is triggered due to the failure of other data, this temporary data needs to be migrated, resulting in invalid migration and consequently write amplification of the flash memory.

[0078] Based on this, embodiments of this application provide a method, apparatus, and computing device for garbage collection of flash memory. In this method,

[0079] When performing garbage collection on a block, valid data must be migrated out before the block can be erased. If data with varying lifespans are mixed together in the same block, a situation may arise where a large amount of data in the same block is still valid, while only a small amount is invalid. In this case, a large amount of data needs to be migrated to other blocks, and this migration process is also a data writing process, thus causing "write amplification." According to the above scheme, whenever there is a target block in the flash memory that needs garbage collection, the flash memory can determine the validity period of the valid data and aggregate valid data with validity periods within different ranges into different blocks. In other words, after garbage collection, for multiple data stored in the same block, their validity periods will not differ significantly (but will be the same or close). In other words, they will become invalid data at the same or similar time points in the future. Therefore, when these blocks need to be garbage collected again later, it is very likely that a large amount (or even all) of the data in these blocks will have become invalid, and the invalid data no longer needs to be migrated, thus avoiding write amplification. Therefore, this scheme reduces the write amplification of flash memory caused by garbage collection.

[0080] The technical solution of this application is described below. First, the structure of the flash memory involved in the embodiments of this application is introduced.

[0081] Figure 2 This is a schematic diagram of the structure of a flash memory provided in an embodiment of this application. Figure 2As shown, the flash memory provided in this embodiment includes a controller 101 and multiple flash memory chips 102. The controller 101 is implemented through a control chip. The controller 101 is used to execute write data requests to write data to the flash memory chips 102, or execute read data requests to read data from the flash memory chips 102, etc. Write data requests and read data requests can be collectively referred to as I / O requests. The flash memory typically includes one or more flash memory chips 102. Each flash memory chip 102 includes several erase units. While flash memory reads or writes are performed in units of pages, erase operations can only be performed in units of erase units, such as blocks. An erase unit includes multiple pages. An erase operation means setting all bits of the block to "1". Before erasing, the controller 101 needs to copy the valid data in the erase unit to blank pages in other blocks. The valid data in the erase unit refers to the unmodified data stored in the block; this data may be read in the future and therefore cannot be erased. Invalid data in an erase cell refers to data stored in that block that has been modified. Modification here means that updated data has been stored in the flash memory, meaning the previously stored data has become old data and will generally not be read by the user in the future. For example, controller 101 receives a write data request, which includes the logical address of the data. Controller 101 writes data continuously into one or more erase cells. Writing continuously into one or more erase cells means that controller 101 finds a blank erase cell, writes data into the blank erase cell, until the blank erase cell is filled. When the size of the data exceeds the capacity of the erase cell,

[0082] The controller 101 then searches for the next blank erase unit and continues writing. When an erase unit is not full, the controller 101 continues to write data with the same (or similar) validity period to the remaining blank pages of that erase unit, based on the validity period of the data.

[0083] In the embodiments of this application, such as Figure 3 As shown, after the flash memory is connected to the host, the host can store data in the flash memory. The flash memory can receive write requests from the host, which carry the data to be written to the flash chip and the data's validity period. The controller controls the data writing to the flash chip and manages the write duration to determine if it exceeds the data's validity period. Thus, the controller controls the garbage collection in the erase unit based on the data's validity period.

[0084] The above is an introduction to the application scenarios of this application. The following describes the method embodiments of this application.

[0085] Figure 4 This is a schematic flowchart of a garbage collection method for a flash memory provided in an embodiment of this application. Figure 4 As shown, the transmission method provided in this application embodiment includes steps S401 to S406. This method is executed by a flash memory, specifically by the controller of the flash memory.

[0086] S401, the flash memory receives multiple data items sent by the host and indication information for each data item. The indication information is related to a target duration during which each data item becomes invalid.

[0087] When the host has data that needs to be stored in the flash memory, it generates an indication message for each piece of data, specifying the duration each piece of data will take to become invalid. Then, based on the multiple pieces of data and their respective indication messages, the host generates a write request and sends it to the flash memory. This allows the flash memory to determine the multiple pieces of data and their respective indication messages based on the write request. When the flash memory is a solid-state drive (SSD), the host here refers to the computer device managing the SSD (or, more specifically, the CPU of the computer device). When the flash memory is in a mobile phone, the host is the device managing the flash media, specifically, the phone's CPU.

[0088] In some embodiments, the indication information for data is determined based on the type and source of the data. For example, if the data is log data, which typically needs to be retained for a relatively long time, then the target duration for log data is longer (assuming the current time is 10:14:09 on April 15, 2025, and the target duration for log data is 10 hours, then the time indicated by the indication information is 20:14:09 on April 15, 2025). If the data is temporarily cached, which usually expires quickly, then the target duration for temporarily cached data is shorter (again, assuming the current time is 10:14:09 on April 15, 2025, and the target duration for log data is 30 minutes, then the time indicated by the indication information is 10:44:09 on April 15, 2025). The host can also determine the validity period of the data based on the application that generated the data. There are various ways to determine the validity period; the above is only an example, and the specific implementation should be based on actual needs.

[0089] In some embodiments, the indication information includes the time when the data becomes invalid. As one possible implementation, upon receiving the indication information, the flash memory can calculate the target duration of the data based on the time when it becomes invalid, thereby managing the data.

[0090] S402, the flash memory writes data into the block according to the instruction information of each data.

[0091] Before writing data to a block, a flash memory can determine which block the data needs to be written to based on the data's indication information.

[0092] In some embodiments, data with target durations within the same range, as indicated by the instruction information, are written into the same block. Alternatively, data with the same target duration are written into the same block.

[0093] In other embodiments, there are blocks in the flash memory that have already been partially written with data. In this case, the flash memory can determine the block corresponding to the data to be written from multiple blocks based on the validity duration of the data already written in the block and the target duration of the data to be written. The validity duration of the data already written in this block is the same as the target duration of the data to be written.

[0094] The validity period of the data is determined based on the target duration of the data. In some embodiments, after the flash memory writes data into a block, it manages the data according to the data's indication information. The flash memory can determine the validity period of the data based on the target duration and the current time. As a possible implementation, the flash memory can associate the data's storage location with the indication information as its own metadata storage, thereby enabling the flash memory to determine the validity period of the data based on the target duration and thus manage the data.

[0095] S403, when there is a target block in the flash memory that needs to be garbage collected, the flash memory determines the validity period of different valid data in the target block.

[0096] When a target block in the flash memory needs to be garbage collected, the flash memory needs to determine whether there is valid data in the target block. If the target block does not contain valid data, it is directly reclaimed. If the target block still stores valid data, the validity period of the valid data in the target block is determined. As one possible implementation, the flash memory determines the metadata of the valid data based on its logical address. Based on the metadata of the valid data, the target duration of the valid data is determined. Based on the target duration and the current time, the validity period of the valid data is determined.

[0097] Thus, whenever a block needs garbage collection, the effective duration of the valid data in the block needs to be determined, thereby enabling precise data management and reducing write amplification of flash memory.

[0098] S404, the flash memory migrates the valid data to a free block with available space according to the valid duration, wherein valid data with different valid durations are migrated to different free blocks.

[0099] A free block is a block that does not store any data. When there is valid data in the target block, the flash memory can migrate the valid data to the free block according to the validity period. Valid data with different validity periods are migrated to different free blocks, or valid data with the same validity period are migrated to the same free block.

[0100] For example, target blocks A, B, and C require garbage collection, and each block contains valid data: valid data A1, A2, B1, B2, C1, and C2, respectively. The validity duration of valid data A1 is 8 minutes, A2 is 16 minutes, B1 is 8.2 minutes, B2 is 16.3 minutes, C1 is 8.6 minutes, and C2 is 40 minutes. The validity durations of valid data A1, B1, and C1 are all within the range of 8-9 minutes; therefore, they are migrated to the same free block. The validity durations of valid data A2 and B2 are both within the range of 16-17 minutes; therefore, they are also migrated to the same free block. The effective duration of valid data C2 differs significantly from that of other data, so valid data C2 is migrated to a separate free block. The range of effective durations can be set according to actual needs, and this embodiment does not impose specific limitations.

[0101] Therefore, when performing garbage collection on a block, valid data must be migrated out before the block can be erased. If data with varying lifespans are mixed together in the same block, a situation may arise where a large amount of data in the same block is still valid, while only a small amount is invalid. In this case, a large amount of data needs to be migrated to other blocks, and this migration process is also a data writing process, thus causing "write amplification." According to the above scheme, whenever there is a target block in the flash memory that needs garbage collection, the flash memory can determine the validity period of the valid data and aggregate valid data with validity periods within different ranges into different blocks. That is, after garbage collection, for multiple data stored in the same block, their validity periods will not differ significantly (but rather be the same or close). In other words, they will become invalid data at the same or similar time points in the future. Therefore, when these blocks need to be garbage collected again later, it is very likely that a large amount (or even all) of the data in these blocks will have become invalid, and the invalid data no longer needs to be migrated, thus avoiding write amplification. Therefore, this scheme reduces the write amplification of flash memory caused by garbage collection.

[0102] S405, based on the validity duration of the valid data, determine a first block from multiple blocks, wherein the validity duration of the second data in the first block is the same as or similar to the validity duration of the valid data.

[0103] S406, migrate valid data from the target block to the first block.

[0104] A flash memory may contain data in multiple blocks, but there may be free space within these blocks. Therefore, the flash memory can determine a first block from the multiple blocks based on the validity duration of the valid data. The valid data is then migrated to the first block. Specifically, the flash memory determines the validity duration of the valid data based on the target duration of the valid data and the current time. The flash memory also determines the validity duration of the second data based on the target duration of the second data and the current time. The validity durations of the valid data and the second data are compared. If the validity durations of the valid data and the second data are the same, the valid data is migrated from the target block (which can also be the target block referred to in the above embodiment) to the first block.

[0105] The phrase "the effective duration of the second data is similar to the effective duration of the effective data" means that the difference between the effective duration of the second data and the effective duration of the effective data is less than a preset difference threshold.

[0106] Thus, whenever valid data needs to be migrated from the flash memory, the flash memory can determine the validity period of the valid data and then select the first block from multiple blocks in the flash memory. The validity period of the second data in the first block is the same as that of the valid data. Then, the flash memory migrates the valid data from the target block (i.e., the second block) to the first block. In this way, all data in the first block has the same validity period, meaning the invalidation time of the data in the first block is the same. Even if the first block needs garbage collection due to invalid data, no data migration is required, reducing write amplification in the flash memory.

[0107] S406, the flash memory erases data from the target block.

[0108] Once the valid data in the target block has been migrated, the flash memory erases the data in the target block.

[0109] In some embodiments, after data is written to the flash memory chip, garbage collection of the flash memory chip is controlled according to the target duration of the data, thereby reducing garbage collection and achieving write amplification optimization. For example, Figure 5 As shown, embodiments of this application may further include the following steps:

[0110] S501, determine whether the duration of writing data to the block is greater than the target duration of the data; if so, execute S502.

[0111] S502 performs garbage collection on the block containing the data.

[0112] If the time it takes to write data to a block exceeds the target duration for the data, garbage collection is performed on the block containing the data. This allows garbage collection to be avoided until the data becomes invalid, thus reducing the frequency of garbage collection and optimizing write amplification in flash memory.

[0113] S503, determine whether the data is copied data. If yes, execute S504; otherwise, execute S505.

[0114] Overwriting refers to the process of migrating data from one block to another. In some cases, if the time it takes to write data to the flash memory chip is less than the target time, but the data still needs to be migrated, then the data needs to be rewritten to another block.

[0115] S504, Modify the target duration of the data.

[0116] S505, determine whether the target duration of the data is greater than the period threshold. If so, execute S506.

[0117] S506 controls the data to be in a sealed state so that the flash memory chip cannot reclaim the block containing the data.

[0118] S507 releases data when it is no longer in use.

[0119] like Figure 6 As shown, the controller is equipped with a management state machine for target duration. A target duration for the data can be created when it is first written to the flash memory chip. The target duration can be modified when the data is overwritten. If the target duration of the data exceeds a period threshold, the controller can put the data into a sealed state, where the host can only read the data, but the flash memory chip cannot perform garbage collection on it. When it is determined that the data is no longer needed, the controller releases the data, making it both readable and garbage collectable.

[0120] It should be noted that steps S501 and S503 are not in any particular order; the specific order depends on the actual application.

[0121] As one possible implementation, the controller can determine that the data is no longer in use based on instructions such as the TRIM command.

[0122] During the data sealing process, the data can only be read and cannot be migrated or erased. Data can only be released when it is determined that it is no longer needed, and then the block containing the data is garbage collected. This prevents the data from being migrated during the garbage collection of other blocks, enabling precise control over the timing of garbage collection and reducing write amplification of flash memory.

[0123] In some embodiments, the "hot" or "cold" attribute of data can be determined based on the effective duration / target duration of the data. Data with effective durations within the same range are considered to have the same "hot" or "cold" attribute. For example, data with an effective duration of 30 minutes to 1 hour is considered "hot" data, data with an effective duration of 10 minutes to 30 minutes is considered "warm" data, and data with an effective duration of less than 10 minutes is considered "cold" data. Data D1 has an effective duration of 30.1 minutes, data D2 has an effective duration of 30.5 minutes, data D3 has an effective duration of 30.8 minutes, data D4 has an effective duration of 8.6 minutes, data D5 has an effective duration of 40 seconds, and data D6 has an effective duration of 19 minutes. Among data D1 to D5, data D1 to D3 are hot data, data D4 and D5 are cold data, and data D6 is warm data.

[0124] For example, such as Figure 7 As shown in part (a), block 1 comprises four data units storing data A1, A4, A7, and A9, where data A1 and A4 are cold data, and data A7 and A9 are hot data. Block 2 comprises four data units storing data A2, A5, A8, and A0, where data A2, A5, A8, and A0 are hot data. Block 3 comprises four data units storing data A3 and A6, where data A3 and A6 are warm data. Block 4 contains no data. Figure 7 As shown in section (b), when data A1 and A4 become invalid, data A7 and A9 are hot data, data A3 and A6 are cold data, and data A2, A5, A8, and A0 are warm data. In this case, data A7 and A9 need to be migrated. Normally, data A7 and A9 would be migrated to block 3. However, since the target durations of data A3 and A6 are different from those of data A7 and A9, to avoid data A3 and A6 becoming invalid after migrating them to block 3, as follows... Figure 7 As shown in section (c), the controller can migrate data A7 and data A9 to block 4, and then perform garbage collection on the data units in block 1. Thus, as... Figure 7As shown in sections (d) and (e), when data A3 and data A6 become invalid data, data A7 and data A9 can be migrated again to perform garbage collection on the data units in block 3, reducing the frequency of data migration and optimizing the write amplification of flash memory.

[0125] Another example, such as Figure 8 Part (a) shown includes four data units: Block 1 stores data A1, A2, A5, and A6, where A1 and A2 are cold data, and A5 and A6 are hot data. Block 2 stores four data units: A3, A4, A7, and A8, where A3 and A4 are cold data, and A7 and A8 are hot data. Block 3 does not store any data. Block 4 contains four data units: A9 and A0, which are warm data. Assume that... Figure 7 As shown in section (b), when data A1, A2, A3, and A4 become invalid, data A5 and A6 are hot data, data A7 and A8 are warm data, and data A9 and A0 are cold data. Since data A1, A2, A3, and A4 become invalid, they need to be garbage collected. Data 5 and A6 are hot data, data A7 and A8 are warm data, and data 5 and 6 are about to become warm data. Therefore, the controller migrates data A5, A6, A7, and A8 to block 3, and then garbage collects the data units in blocks 1 and 2. Figure 7 As shown in sections (d) and (e), when data A9 and data A0 become invalid, garbage collection can be performed on the data units in block 4 without migrating any data. Thus, migrating data with similar popularity attributes to the same block reduces the frequency of data migration and optimizes write amplification in flash memory.

[0126] In some embodiments, the flash memory chip includes a block group, which includes multiple blocks, and the block group is used to write data of the same target duration.

[0127] Based on the same concept as the embodiments of the method in this application, this application also provides a garbage collection device for flash memory. The garbage collection device for flash memory includes several modules, each module being used to execute various steps in the garbage collection method for flash memory provided in this application. The division of modules is not limited here. Those skilled in the art will clearly understand that in practical applications, the various steps in the garbage collection method for flash memory provided in this application can be assigned to different modules as needed, that is, the internal structure of the device can be divided into different modules to complete all or part of the functions described above. The modules in the embodiments can be integrated into one processing unit, or each unit can exist physically separately, or two or more modules can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit. Furthermore, the specific names of the modules are only for easy differentiation and are not intended to limit the scope of protection of this application. The specific working process of the modules in the above device can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.

[0128] For example, the garbage collection device for the flash memory is used to perform the garbage collection method for the flash memory provided in the embodiments of this application. Figure 9 This is a schematic diagram of the structure of the garbage collection device for the flash memory provided in the embodiments of this application. Figure 9 As shown in the embodiment of this application, the flash memory garbage collection device includes:

[0129] The determination module 901 is used to determine the validity duration of different valid data in the target block when there is a target block in the flash memory that needs to be garbage collected. The validity duration is used to indicate the length of time that the valid data has been invalidated.

[0130] The migration module 902 is used to migrate valid data in the flash memory to free blocks with available space according to the valid duration. Valid data with valid durations in different ranges are migrated to different free blocks.

[0131] The erasure module 903 is used to erase data on the target block.

[0132] According to the embodiments of this application, when performing garbage collection on a block, valid data needs to be migrated out before the block can be erased. If data with varying lifespans are mixed together in the same block, a situation may arise where a large amount of data in the same block is still valid, while only a small amount is invalid. In this case, a large amount of data needs to be migrated to other blocks, and this migration process is also a data writing process, thus leading to "write amplification." However, according to the above solution, whenever there is a target block in the flash memory that needs garbage collection, the flash memory can, after determining the validity period of the valid data, aggregate valid data with validity periods within different ranges into different blocks.

[0133] In other words, after garbage collection, the effective durations of multiple data items stored in the same block will not differ significantly (but rather will be the same or similar). In other words, they will become invalid data at the same or similar time points in the future. Therefore, when these blocks need to be garbage collected again later, it is very likely that a large portion (or even all) of the data in these blocks will have become invalid. The invalid data no longer needs to be migrated, thus avoiding write amplification. Therefore, this scheme reduces write amplification in flash memory caused by garbage collection.

[0134] In one possible implementation, at least one target block in the flash memory requires garbage collection.

[0135] In one possible implementation, the device further includes:

[0136] The receiving module is used to receive multiple data sent by the host and the validity period of each data. The validity period of each data is generated by the host.

[0137] In one possible implementation, the determining module is used to determine the validity duration of different valid data based on the indication information of different valid data.

[0138] In one possible implementation, the device further includes:

[0139] The write module is used to write each piece of data into multiple target blocks according to the indication information of each piece of data in multiple data sets. The target blocks are different for data with target durations in different ranges.

[0140] In one possible implementation, the indication information is the time point at which the data becomes invalid data.

[0141] In one possible implementation, the device further includes:

[0142] When the indication information of the target data indicates that the target data is valid for a long time, the target data is set to a sealed state. The sealed state is used to indicate that the data can only be read and cannot be erased or migrated. The multiple data include the target data.

[0143] In one possible implementation, the valid data also has a hot / cold attribute, and multiple valid data with the same hot / cold attribute include different valid durations.

[0144] Figure 10 This is another data migration device for flash memory provided in the embodiments of this application. For example... Figure 10 As shown, the data migration apparatus for flash memory provided in this application embodiment includes:

[0145] The first determining module 1001 is used to determine the validity duration of valid data when valid data in flash memory needs to be migrated. The validity duration is used to indicate the length of time since the valid data was invalidated.

[0146] The second determining module 1002 is used to determine the first block from multiple blocks based on the validity duration of the valid data, wherein the validity duration of the second data in the first block is the same as the validity duration of the valid data.

[0147] Migration module 1003 is used to migrate valid data from the target block to the first block;

[0148] The erasure module 1004 is used to erase data on the target block.

[0149] According to the embodiments of this application, whenever valid data in the flash memory needs to be migrated, the flash memory can determine the validity duration of the valid data and then determine a first block from multiple blocks in the flash memory. The validity duration of the second data in the first block is the same as the validity duration of the valid data. Then, the flash memory migrates the valid data from the target block to the first block. Thus, all data in the first block has the same validity duration, and the invalidation time of the data in the first block is the same. Even if the first block needs garbage collection due to invalid data, no data migration is required, reducing write amplification in the flash memory.

[0150] Based on the same concept as the method embodiments of this application, embodiments of this application also provide a computing device. This computing device includes... Figure 2 The flash memory shown.

[0151] like Figure 11 As shown, the computing device provided in this application embodiment includes a processor 1101, a memory 1102, and a communication interface 1103.

[0152] In this embodiment, the processor 1101 may be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or any conventional processor.

[0153] The memory 1102 may include a large-capacity memory for data or instructions, thereby providing storage space for the operating system and executable program code of the computing device, which may include, but is not limited to: Windows system (an operating system), Linux system (an operating system), HarmonyOS system (an operating system), etc., without limitation.

[0154] For example, and not as a limitation, memory 1102 may include a hard disk drive (HDD), a floppy disk drive, flash memory, optical disk, magneto-optical disk, magnetic tape, or a Universal Serial Bus (USB) drive, or a combination of two or more of these. Where appropriate, memory 1102 may include removable or non-removable (or fixed) media. Where appropriate, memory 1102 may be internal or external to the integrated gateway disaster recovery device. In a particular embodiment, memory 1102 is non-volatile solid-state memory.

[0155] Memory may include read-only memory (ROM), random access memory (RAM), disk storage media devices, optical storage media devices, flash memory devices, and electrical, optical, or other physical / tangible memory storage devices. Therefore, typically, memory may include one or more tangible (non-transitory) computer-readable storage media (e.g., memory devices) encoded with software that may include computer-executable instructions, and when the software is executed (e.g., by one or more processors), it is operable to perform the operations described with reference to the methods according to this application.

[0156] For example, a computer program may be stored on the memory 1102, and the processor 1101 executes the computer program to implement the steps in the above method embodiments. Alternatively, the processor 1101 executes the computer program to implement the functions of each module in the above device embodiments. Exemplarily, the computer program may be divided into one or more modules / units, which may be a series of computer program instruction segments capable of performing a specific function. The one or more modules / units are stored in the memory 1102 and executed by the processor 1101 to complete this application. For example, the computer program may be divided into multiple modules, as in the modules of the device described above.

[0157] The communication interface 1103 is used to send and receive data, for example, to send data processed by the processor 1101 to other computing devices, or to receive data sent by other computing devices.

[0158] Of course, for the sake of simplicity, Figure 11 Only some of the components of the computing device 1100 relevant to this application are shown, omitting components such as buses, input / output interfaces, etc. In addition, the computing device 1100 may include any other suitable components depending on the specific application. Furthermore, the computing device may be a desktop computer, laptop, handheld computer, cloud server, or other computing device. Those skilled in the art will understand that... Figure 11 This is merely an example of computing device 1100 and does not constitute a limitation on the computing device. It may include more or fewer components than illustrated, or combine certain components, or different components. For example, the computing device may also include input devices, output devices, network access devices, buses, etc. For example, the input device may be a microphone array, and may also include, for example, a keyboard, mouse, etc. For example, the output device may output various information to the outside, and may include, for example, a display, speakers, printer, and communication networks and their connected remote output devices, etc.

[0159] In addition to the methods, apparatus, and computing devices described above, embodiments of this application may also provide a computer program product, comprising computer program instructions. When executed by a processor, these computer program instructions cause the processor to perform the steps of the methods in the various embodiments of this application described in the "Method" section of this specification. The computer program product may be written in any combination of one or more programming languages ​​to perform the operations of the embodiments of this application. The programming languages ​​include object-oriented programming languages ​​such as Java and C++, as well as conventional procedural programming languages ​​such as C or similar languages. The computer program code may be in source code form, object code form, executable file, or some intermediate form. The computer program code may be executed entirely on a user's computing device, partially on a user's computing device, as a standalone software package, partially on a user's computing device and partially on a remote computing device, or entirely on a remote computing device or server.

[0160] Furthermore, embodiments of this application may also provide a computer-readable storage medium storing computer program instructions thereon, which, when executed by a processor, cause the processor to perform the steps of the display control method according to various embodiments of this disclosure as described in the "Method" section above. The computer-readable storage medium may be any combination of one or more readable media. A readable medium may be a readable signal medium or a readable storage medium. A readable storage medium may include, for example, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of readable storage media (a non-exhaustive list) include: an electrical connection having one or more wires, a portable disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. It should be noted that the content contained in the computer-readable medium may be appropriately added to or subtracted according to the requirements of legislation and patent practice in a jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, a computer-readable medium may not include electrical carrier signals and telecommunication signals.

[0161] The method steps in the embodiments of this application can be implemented in hardware or by a processor executing software instructions. The software instructions can consist of corresponding software modules, which can be stored in random access memory (RAM), flash memory, read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), registers, hard disks, portable hard disks, CD-ROMs, or any other form of storage medium known in the art. An exemplary storage medium is coupled to the processor, enabling the processor to read information from and write information to the storage medium. Of course, the storage medium can also be a component of the processor. The processor and the storage medium can reside in an ASIC.

[0162] It is understood that the various numerical designations used in the embodiments of this application are merely for descriptive convenience and are not intended to limit the scope of the embodiments of this application. It should be understood that in the embodiments of this application, the order of the process numbers does not imply the order of execution; the execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application.

[0163] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and not to limit them; although this application has been described in detail with reference to the foregoing embodiments, modifications have been made to the technical solutions described in the foregoing embodiments, or equivalent substitutions have been made to some of the technical features; however, these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the protection scope of the technical solutions of the embodiments of this application.

Claims

1. A method for garbage collection of flash memory, characterized in that, The method includes: When there is a target block in the flash memory that needs to be garbage collected, the flash memory determines the validity duration of different valid data in the target block. The validity duration is used to indicate the length of time that the valid data has been invalidated. The flash memory migrates the valid data to a free block with available space according to the valid duration, wherein valid data with different valid durations are migrated to different free blocks; The flash memory erases the data from the target block.

2. The method according to claim 1, characterized in that, At least one of the target blocks in the flash memory requires garbage collection.

3. The waste recycling method according to claim 1 or 2, characterized in that, The method further includes: The receiving host sends multiple data items and indication information for each of the multiple data items, wherein the indication information is used to indicate the target duration during which each data item becomes invalid data, and the indication information for each data item is generated by the host.

4. The waste recycling method according to claim 3, characterized in that, Determining the effective duration of different valid data in the target block includes: The validity duration of the different valid data is determined based on the indication information of the different valid data.

5. The waste recycling method according to claim 3, characterized in that, The method further includes: Based on the indication information of each of the multiple data, each data is written into multiple target blocks, wherein data with target durations in different ranges are stored in different target blocks.

6. The waste recycling method according to claim 3, characterized in that, The indication information is the time point at which the data becomes invalid.

7. The waste recycling method according to any one of claims 3-6, characterized in that, The method further includes: When the indication information of the target data indicates that the target data is valid for a long time, the target data is set to a sealed state. The sealed state is used to indicate that the data can only be read and cannot be erased or migrated. The multiple data include the target data.

8. The waste recycling method according to any one of claims 1-7, characterized in that, The valid data also has the attribute of hotness or coldness, and multiple valid data with the same hotness or coldness may have different valid durations.

9. A data migration method for a flash memory, characterized in that, The method includes: In cases where valid data in the flash memory needs to be migrated, the validity period of the valid data is determined, and the validity period is used to indicate the length of time since the valid data was invalidated. Based on the validity duration of the valid data, a first block is determined from multiple blocks, wherein the validity duration of the second data in the first block is the same as or similar to the validity duration of the valid data; The valid data is migrated from the target block to the first block; Data erasure is performed on the target block.

10. A waste recycling device for a flash memory, characterized in that, The device includes: The determination module is used to determine the validity duration of different valid data in the target block when there is a target block in the flash memory that needs to be garbage collected. The validity duration is used to indicate the length of time since the valid data was invalidated. A migration module is used to migrate the valid data in the flash memory to a free block with available space according to the valid duration, wherein valid data with different valid durations are migrated to different free blocks; The erasure module is used to erase data from the target block.

11. A waste recycling device for flash memory, characterized in that, The device includes: The first determining module is used to determine the validity duration of the valid data when the valid data in the flash memory needs to be migrated, wherein the validity duration is used to indicate the length of time since the valid data was invalidated. The second determining module is used to determine a first block from multiple blocks based on the validity duration of the valid data, wherein the validity duration of the second data in the first block is the same as or similar to the validity duration of the valid data; A migration module is used to migrate the valid data from the target block to the first block; The erasure module is used to erase data from the target block.

12. A computing device, characterized in that, include: Memory, used to store executable code; A processor, configured to, when executing the executable code, implement the method of any one of claims 1-8, or the method of claim 9.

13. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed in a computer, causes the computer to perform the method described in any one of claims 1-8, or the method described in claim 9.

14. A computer program product containing instructions, characterized in that, When the instructions are executed on a computer, the computer causes the computer to perform the method as described in any one of claims 1-8, or the method as described in claim 9.