Method for releasing data block and storage device
By configuring the write allocation unit to align with the super data block and targeted release of invalid data blocks under the rewrite command, the problem of insufficient storage space for storage devices during high-intensity writing is solved, and efficient data block release and write performance stability is achieved.
Patent Information
- Application Number
- CN202510873500.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-27
- Publication Date
- 2025-07-25
- Estimated Expiration
- 2045-06-27
AI Technical Summary
When existing storage devices write high-intensity data, the garbage collection mechanism cannot meet the needs, resulting in a decrease in the number of available blocks in the memory card, triggering the write protection mechanism, and interrupting video recording.
By configuring the write allocation unit size to align with the super data block capacity, check whether the write command is a rewrite command, perform targeted rewrite processing and instantly release invalid data blocks, reducing the frequency of the start-up of the garbage collection mechanism.
Ensure that each super data block can be completely released, avoid fragmentation of storage space, improve write performance and release efficiency, and avoid triggering of write protection mechanisms.
Smart Images

Figure CN120371546A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of storage technologies, and in particular, to a method for releasing data blocks and a storage device. Background Art
[0002] In the field of high-resolution video recording, storage devices need to have a high continuous write speed to meet the requirements of high-quality video recording. The VPG 400 (Video Performance Guarantee) standard is used to specify the minimum continuous write speed that a memory card needs to achieve when recording high-resolution videos. This standard requires that the storage device can ensure a continuous write speed of at least 400 MB / s when recording videos. This speed standard can meet the requirements of high-quality video recording and ensure that there will be no data write bottleneck during the recording process.
[0003] The storage space of a storage device is composed of multiple super blocks. To meet the write requirements of the above standard, the storage device needs to continuously provide available super blocks for data writing. However, in the prior art, the write performance of memory cards is limited by their storage space management mechanism. During the data writing and deletion processes of the storage device, invalid data blocks will be generated, which need to be released through garbage collection (GC) or a rewrite mechanism to provide available storage space for data writing. Although the release speed of the rewrite mechanism is better than that of the GC mechanism, not all super blocks can be released through the rewrite mechanism. For these data blocks, only the GC mechanism can be used for release. However, when the host continuously writes data intensively, the efficiency of garbage collection may not be able to meet the data write requirements. If the garbage collection speed cannot keep up with the host write speed, the number of available blocks inside the memory card will gradually decrease, and eventually, it may cause the memory card to be unable to receive new write data, thereby triggering the write protection mechanism and interrupting the video recording process. Summary of the Invention
[0004] The technical problem to be solved by the present invention is: to provide a method for releasing data blocks and a storage device, which can release all super blocks through a rewrite mechanism to reduce the startup frequency of the garbage collection mechanism, thereby avoiding triggering the write protection mechanism.
[0005] To solve the above technical problem, a technical solution adopted by the present invention is: A method for releasing data blocks, comprising: Obtaining the capacity size of super blocks in a storage device; Configuring the size of a write allocation unit to be the capacity size of the super blocks; Receive a write command from the host and detect whether the write command belongs to a rewrite command; If so, perform a rewrite process on the super data block according to the current write data issued based on the write allocation unit in the write command to obtain an invalid data block, and perform a release process on the invalid data block.
[0006] To solve the above technical problems, another technical solution adopted by the present invention is: A storage device includes a control chip and a storage chip. The storage chip stores a computer program, and when the computer program is executed by the control chip, each step in the above method for releasing a data block is implemented.
[0007] The beneficial effects of the present invention are as follows: Since the rewrite mechanism invalidates data according to the write allocation unit (a continuous area composed of the smallest units of multiple write commands), and a super data block may store data of multiple write allocation units, if only the data of one write allocation unit is invalidated, an entire super data block cannot be completely released. Therefore, the size of the write allocation unit is configured to be the same as the capacity of the super data block, achieving spatial alignment between the write allocation unit and the super data block, so that the data of one write allocation unit can completely occupy the entire data block space. When receiving a write command from the host, by detecting whether the write command belongs to a rewrite command, an immediate release mechanism is adopted for the invalid data block obtained after the rewrite process. Through the spatial alignment between the write allocation unit and the super data block, the present invention enables the data of one write allocation unit to completely occupy the entire data block space, avoiding the fragmentation problem caused by cross-block storage, thereby ensuring that the rewrite mechanism can completely release a super data block when releasing a data block, and further ensuring that each data block can be released through rewriting, reducing the startup frequency of the garbage collection mechanism, and avoiding triggering the write protection mechanism. Description of the Drawings
[0008] Figure 1 A schematic diagram showing the distribution of a write allocation unit in a super data block provided by the prior art; Figure 2 Another schematic diagram showing the distribution of a write allocation unit in a super data block provided by the prior art; Figure 3 A flowchart of a method for releasing a data block provided by the present invention; Figure 4 A schematic diagram of a storage structure provided by the present invention; Figure 5 A schematic diagram showing the distribution of a write allocation unit in a super data block provided by the present invention; Figure 6 A schematic diagram showing the distribution of rewritten data provided by the present invention; Figure 7 Another schematic diagram of the distribution of overwritten data provided by the present invention; Figure 8 A schematic diagram of the distribution of write allocation units in a super data block provided by the present invention; Figure 9 Another schematic diagram of the distribution of write allocation units in a super data block provided by the present invention; Figure 10 A schematic diagram of the structure of a storage device provided by the present invention. Detailed implementation manners
[0009] To describe in detail the technical content, achieved objectives and effects of the present invention, the following is described in conjunction with the implementation manners and with reference to the accompanying drawings.
[0010] An embodiment of the present invention provides a method for releasing a data block, including: Obtaining the capacity size of a super data block in a storage device; Configuring the size of a write allocation unit to be the capacity size of the super data block; Receiving a write command from a host and detecting whether the write command belongs to a rewrite command; If so, performing a rewrite process on the super data block according to the current write data issued based on the write allocation unit in the write command to obtain an invalid data block, and performing a release process on the invalid data block.
[0011] As can be seen from the above description, the beneficial effects of the present invention are as follows: Since the rewrite mechanism invalidates data according to the write allocation unit, and a super data block may store data of multiple write allocation units, if only the data of one write allocation unit is invalidated, an entire super data block cannot be completely released. Therefore, by configuring the size of the write allocation unit to be the capacity size of the super data block, the spatial alignment between the write allocation unit and the super data block is achieved, so that the data of one write allocation unit can completely occupy the entire data block space. When receiving a write command from the host, by detecting whether the write command belongs to a rewrite command, an immediate release mechanism is adopted for the invalid data block obtained after the rewrite process. Through the spatial alignment between the write allocation unit and the super data block, the present invention enables the data of one write allocation unit to completely occupy the entire data block space, avoiding the fragmentation problem caused by cross-block storage, thereby ensuring that the rewrite mechanism can completely release a super data block when releasing the data block, and further ensuring that each data block can be released through rewriting, reducing the startup frequency of the garbage collection mechanism, and avoiding triggering the write protection mechanism.
[0012] Further, obtaining the capacity size of a super data block in a storage device includes: Obtaining the device model of the storage device; Determine the storage structure of the storage device based on the device model; Determine the capacity size for storing user data in the super data block based on the storage structure.
[0013] As can be seen from the above description, obtain the device model of the storage device, then determine its storage structure, and accurately determine the capacity size for storing user data in the super data block based on this storage structure. This method provides accurate basic data for subsequent spatial alignment of the write allocation unit with the super data block, ensuring that the write allocation unit can completely occupy the entire super data block space.
[0014] Further, configuring the size of the write allocation unit to the capacity size of the super data block includes: Obtain multiple configurable parameters for the size of the write allocation unit; Determine a target configuration parameter among the multiple configurable parameters that is less than the capacity size and the difference from the capacity size is less than a preset value; Configure the size of the write allocation unit to the target configuration parameter.
[0015] As can be seen from the above description, by obtaining the configurable parameters of the write allocation unit, the configuration benchmark for different storage device types is determined. In actual situations, the size of the write allocation unit can only be configured to predefined parameters, so the selection of the size of the write allocation unit is limited and it is impossible to fully achieve the same size as the super data block. Therefore, when configuring the size of the write allocation unit, select the configurable parameter that is less than and closest to the data block size as the target configuration parameter, so that the size of the write allocation unit is as close as possible to the size of a super data block. This not only ensures that the write performance meets industry standards but also minimizes storage space fragmentation caused by the mismatch between the write allocation unit and the data block size.
[0016] Further, obtain the historical logical block address of the historical write command received before the write command; Detect whether the current logical block address of the write command is the same as the historical logical block address; If so, determine that the write command belongs to a rewrite command; Otherwise, determine that the write command does not belong to a rewrite command.
[0017] As described above, the logical block address refers to the logical address used by the operating system and application programs to access the storage device. Each time the host issues a write command, the logical block address is carried. If the current write command and the historical write command carry the same logical block address to complete the data write operation, it indicates that the current write command belongs to a rewrite command, that is, the purpose of the current write command is to rewrite and release the data block of the historical write command. This mechanism can quickly determine whether the current write command is for data block writing or data block release.
[0018] Further, the process of obtaining the invalid data block by rewriting the super data block according to the current write data sent based on the write allocation unit in the write command includes: Writing the current write data sent based on the write allocation unit in the write command into the free data block in the super data block to obtain a valid data block; Updating the mapping entry of the current logical block address to the valid data block, so that the original data block mapped before the update is data invalidated to obtain an invalid data block.
[0019] As described above, if the data block of the historical write command is to be released, the data in the data block needs to be rewritten to other data blocks first. After rewriting, the mapping entry of the logical block address must be updated to the data block written later, so that the data block written earlier is invalidated, thus realizing the release process of the data block.
[0020] Further, writing the current write data sent based on the write allocation unit in the write command into the free data block in the super data block to obtain a valid data block includes: Writing the current write data sent based on the write allocation unit in the write command into a preset cache to obtain target write data, and the preset cache only allows writing the current write data of the size of one write allocation unit; After completely writing the target write data in the preset cache into the free data block, detecting whether there is a free data page in the free data block; If so, filling a write completion flag to the end of the target write data to obtain a valid data block.
[0021] As can be seen from the above description, first, by limiting the preset cache to only accept the data volume of a single write allocation unit, it is ensured that the data scale of each cache operation strictly corresponds to the minimum management unit of the storage device, avoiding the data fragmentation problem caused by cross-unit writing at the physical level. Second, after the overall migration of the cached data to the free data block is completed, by detecting the physical storage state of the free data page, a write completion mark is appended at the end of the data. This mark is used to determine the end of the current data block writing, thereby serving as the physical identifier of the effective data block boundary and effectively blocking the cross-block storage caused by accidental superposition writing of subsequent data.
[0022] Further, obtaining an effective data block by filling the write completion mark at the end of the target write data includes: Detecting whether the current data page in the free data block where the target write data is written is completely full; If so, filling the write completion mark into the next free data page after the current data page to obtain an effective data block; Otherwise, filling the write completion mark into the blank address of the current data page where the target write data is not written and the next free data page after the current data page to obtain an effective data block.
[0023] As can be seen from the above description, first, it is detected whether the data page written with the target write data is completely full. If it is full, the mark is filled into the subsequent free data page. This processing method forms a clear block termination identifier through the write completion mark. When the data page is not full, by filling the mark at the blank address of the current page and the next page at the same time, filling the mark at the blank address of the current page to isolate the free data page from the data page that has the target write data but is not full, and filling the mark at the next page to form a clear block termination identifier, preventing subsequent data from being written into the free data page of this data block, so as to ensure that only the data of one write allocation unit can be written into a super data block, effectively solving the problem in the traditional overwriting method that the entire super data block cannot be completely released due to containing the data of multiple write allocation units.
[0024] Further, it further includes: If the effective data block is marked as the recovery target block for garbage collection operation, marking the data page in the effective data block where the write completion mark is written as a stop data page; When data is moved in the recovery target block, if the stop data page is read, ending the garbage collection operation.
[0025] As described above, when the valid data block is selected as the target block for recycling, the presence of the write completion flag indicates that the content after this data page belongs to blank pages, that is, no processing is required. Therefore, the flag stop data page can directly identify the boundary of data validity. During the data migration process of the garbage collection operation, once the stop data page is read, it means that the subsequent pages do not need to be processed anymore, thus immediately ending the recycling operation. This mechanism reduces the unnecessary amount of data migration, improves the release efficiency of the garbage collection mechanism, and ensures that in the scenario of continuous high-intensity writing, the garbage collection mechanism can quickly release space to maintain the continuous writing ability of the storage device.
[0026] Further, it also includes: If a write interruption request is received when writing the current write data sent based on the write allocation unit in the write command to the preset cache, then when receiving the next write command from the host, it is detected whether the next write data sent based on the write allocation unit in the next write command is continuous with the current write data that has been written to the preset cache; If so, the next write data is written to the preset cache to obtain the target write data, and the step of detecting whether there is an idle data page in the idle data block after completely writing the target write data in the preset cache to the idle data block is executed; Otherwise, the current write data that has been written to the preset cache is used as the target write data, and the step of detecting whether there is an idle data page in the idle data block after completely writing the target write data in the preset cache to the idle data block is executed.
[0027] As described above, when a write interruption occurs, the data of one write allocation unit has not been completely written to the preset cache. Therefore, by detecting the write correlation between the next write data and the cached data, two processing paths are distinguished: if the next write data is continuous with the cached data, the next write data is appended to the cache to form a complete data unit, avoiding data fragmentation caused by the interruption; if the next write data is not continuous with the cached data, it means that the next write data is new data. Therefore, the current cached data is directly submitted to be written to the data block and marked, so that the current cached data and the next write data can be written to different data blocks respectively, thereby isolating the current cached data and the next write data. This processing mechanism not only ensures that each super data block stores only the data of one write allocation unit, but also effectively solves the problem of data continuity management in the interruption recovery scenario.
[0028] Further, it also includes: If the write command does not belong to the overwrite command, write the current write data into the free data block in the super data block to obtain a valid data block, and map the current logical block address to the valid data block to obtain a mapping table entry.
[0029] As can be seen from the above description, if the write command does not belong to the overwrite command, it indicates that the current write command is to implement data block writing. Therefore, after writing the data into the free data block and recording the mapping relationship of the logical block address, there is no need to perform invalid release of the data block, thus ensuring the normal writing function of the data block. At the same time, since the current write data is issued based on the write allocation unit, the data written into a free data block only includes the data of one write allocation unit, which can minimize the storage space fragmentation caused by the mismatch between the write allocation unit and the data block size, facilitating the subsequent release of the data block.
[0030] Another embodiment of the present invention provides a storage device, including a control chip and a storage chip. The storage chip stores a computer program, and when the computer program is executed by the control chip, each step in the above method for releasing a data block is implemented.
[0031] The above method for releasing a data block and the storage device according to the present invention can be applied to storage devices that require high-performance writing. When the host (which can be a video shooting device) performs high-speed writing (i.e., enters the VPG mode), it issues data in units of the pre-configured write allocation unit (AU). Therefore, the super data block in the storage device completes the write operation in units of AU. Based on this, in existing storage devices, if the super data block is released through the overwrite mechanism, the following two types of overwrite releases will occur based on the distribution of AU in the super Block: The first case is as Figure 1 shown, where multiple AUs simultaneously occupy one super Block. In this case, if only the data of one AU is overwritten, a super Block cannot be completely released. For example, if AU 0 is overwritten, the data of AU 0 is invalidated, but since the data of AU1 and AU2 is still valid, super Block A still cannot be released. The second case is as Figure 2As shown, one AU occupies multiple super Blocks. In this case, there may be some super Blocks that cannot be fully released. For example, when AU 0 is overwritten, super Block A that is fully occupied by the data of AU 0 will be fully released, while the data of AU 1 in super Block B is still valid, so super Block B cannot be released. When AU 1 or AU 3 is overwritten, super Block B and super Block C cannot be released because there is still valid data of other AUs. It can be seen that the existing overwriting mechanism cannot release the super data block containing the data of multiple write allocation units through one overwriting. For such super data blocks, only the data migration of the garbage collection mechanism can be used to complete the release. However, the garbage collection mechanism requires data migration operations, and the release speed of its data blocks cannot keep up with the usage speed of data blocks in the high-speed write mode, resulting in no free data blocks available in the storage device, and then triggering write protection, affecting the use of the host. Therefore, the present invention provides a method for releasing data blocks and a storage device, which can release all super data blocks only through the overwriting mechanism, thereby reducing the startup frequency of the garbage collection mechanism and avoiding triggering the write protection mechanism. The following is an explanation through specific embodiments: Please refer to Figures 3 to 7 , Embodiment 1 of the present invention is: As Figure 3 shown, a method for releasing data blocks specifically includes the following S1-S4: S1. Obtain the capacity size of the super data block in the storage device. Specifically, only the size of one super data block is obtained in step S1.
[0032] Among them, S1 is specifically: obtain the device model of the storage device, determine the storage structure based on the device model, and determine the capacity size for storing user data in the super data block based on the storage structure. Specifically, taking YMTC X3 9070 512GB (the model of a three-dimensional flash product) as an example, as Figure 4 shown, the storage structure of this product is specifically: one super Block contains 1392 SLC super pages, each super page contains 4 dies, each die contains 6 planes, each plane stores 16KB of data, and one plane in 6 super pages stores RAID data, Figure 4In the following, P represents "plane", and the shaded part represents the stored RAID (Redundant Array of Independent Disks) data. From this, it can be obtained that the capacity corresponding to one super block is 1392×4×6×16KB = 534528KB. Among them, the capacity occupied by RAID is 1392 / 6×16KB = 2712KB. Therefore, the capacity actually available for storing user data is 531816KB, which is equivalent to 519.351MB. This means that the amount of user data that can be stored in one super block in this product is 519.351MB.
[0033] S2. Configure the size of the write allocation unit to the capacity size of the super data block.
[0034] It should be noted that the size of the write allocation unit is configured through the firmware. After the size of the write allocation unit is configured in the firmware, the firmware will be uploaded to the host, thereby completing S2. After the firmware configuration is completed, the size of the write allocation unit cannot be changed or modified again.
[0035] In an ideal situation, if the size of the write allocation unit is configured to the capacity size of the super data block, the storage situation of the data block is as Figure 5 shown. One AU occupies one super Block. In this case, as long as the data of one AU is rewritten, one super Block can be completely released. For example, if AU 0 is rewritten, the data of AU 0 is invalidated, and there is no other valid data stored in super BlockA, so super BlockA can be released. However, in actual situations, there is a limited selection of the size of the write allocation unit, and it cannot be exactly the same as the capacity size of the super data block. Therefore, the write allocation unit needs to be approximately the size of a super data block.
[0036] Specifically, S2 includes the following S21 - S23: S21. Obtain multiple configurable parameters for the size of the write allocation unit.
[0037] In some embodiments, the configurable parameters of the write allocation unit are recorded in the write performance standard of the storage device.
[0038] S22. Determine the target configuration parameter among the multiple configurable parameters that is less than the capacity size and the difference from the capacity size is less than a preset value.
[0039] S23. Configure the size of the write allocation unit to the target configuration parameter.
[0040] In some embodiments, the preset value is 10% of the size of the super data block. For example, if the size of the super data block is 519.351 MB, then the preset value is 51.9351.
[0041] Applying the above step S2 to a specific scenario, the write performance standard of the storage device is specifically the VPG standard. In the VPG standard, the configurable parameters of the write allocation unit are 128 MB, 256 MB, and 512 MB respectively. Based on this, if the capacity of a super data block obtained in S1 is 519.351 MB, then the target configuration parameter that is less than 519.351 MB and the difference from 519.351 MB is less than 51.9351 among the configurable parameters is 512 MB. Therefore, the size of the write allocation unit is configured to 512 MB.
[0042] S3. Receive a write command from the host and detect whether the write command belongs to a rewrite command.
[0043] It should be noted that the minimum unit of a host write command is RU, and AU is a continuous area composed of multiple minimum units (RU). In the VPG mode, the host issues write commands in units of the pre-configured AU.
[0044] Specifically, detecting whether the write command in S3 belongs to a rewrite command includes: S31. Obtain the historical logical block address of the historical write command received before the write command.
[0045] S32. Detect whether the current logical block address of the write command is the same as the historical logical block address. If so, determine that the write command belongs to a rewrite command; otherwise, determine that the write command does not belong to a rewrite command.
[0046] It should be noted that each time the host issues a write command, it will carry the LBA (Logical Block Address). When there are two consecutive LBAs that are the same among multiple write commands sequentially issued by the host, it means that the data corresponding to the LBA is rewritten. Among them, after each piece of data is written into the data block, the FTL (Flash Translation Layer) will establish an entry between the LBA and the physical location to be written. For example Figure 6As shown, assume that the data of LBA 0 - 100 is written into super Block A, and at this time the entry points to super Block A. If the data of LBA0 - 100 is written again later, and at this time the data of LBA0 - 100 is written into super Block B, then the entry of super Block A points to super Block B. Based on this, when detecting whether the write command is a rewrite command, it is only necessary to determine whether the LBA is consistent with the previous write command by detecting whether the entry of the LBA maps to a certain data block.
[0047] S4. If so, perform a rewrite process on the super data block according to the current write data sent based on the write allocation unit in the write command to obtain an invalid data block, and perform a release process on the invalid data block.
[0048] Specifically, S4 includes the following S41 - S42: S41. Write the current write data sent based on the write allocation unit in the write command into the free data block in the super data block to obtain a valid data block.
[0049] S42. Update the mapping entry of the current logical block address to the valid data block, so that the original data block mapped by the mapping entry before the update is invalidated to obtain an invalid data block.
[0050] The method further includes: S5. If the write command does not belong to the rewrite command, write the current write data into the free data block in the super data block to obtain a valid data block, and map the current logical block address to the valid data block to obtain a mapping entry.
[0051] Apply the above steps S4 and S5 to a specific scenario, such as Figure 7As shown in the figure, the host first issues the first write command. The logical block address range in the first write command is LBA0 - 100. The data in the range of LBA0 - 100 is written into the idle super Block A, and the entry of LBA0 - 100 points to super Block A. Then the host issues the second write command. The logical block address range in the second write command is LBA100 - 200. The data in the range of LBA100 - 200 is written into the idle super Block B, and the entry of LBA100 - 200 points to super Block B. And so on. When writing to the idle super Block N, the host issues the Nth write command. The logical block address range in the Nth write command is LBA0 - 100. At this time, the logical block address of the Nth write command is the same as that of the first write command. However, when the Nth write command is executed, since super Block A has been written and is no longer an idle data block, and the data written again must be an erased data block, the data in the range of LBA0 - 100 is written into the idle super Block N. The entry of LBA0 - 100 points from super Block A to super Block N, and the data in super Block A is invalidated, that is, super Block A becomes an invalid data block. The invalid data block can be released and used again. In this scenario, the Nth write command is the overwrite command, and the first write command and the second write command are not overwrite commands.
[0052] To more intuitively understand the difference in the effects of the data block release method of the present invention and the existing data block release method in actual applications, statistical data on the number of data blocks released by the existing data block release method and the data block release method of the present invention under the garbage collection mechanism and the overwrite mechanism are obtained through 4 rounds of experiments, as shown in Table 1.
[0053] Table 1 Statistical data on the number of data blocks released
[0054] Based on Table 1, when the total number of released data blocks is roughly the same, since some data blocks cannot be released through the overwrite mechanism in the existing data block release method, the proportion of the number of data blocks released under the garbage collection mechanism is significantly more than that of the data release method of the present invention. And the proportion of the number of data blocks released by the data block release method of the present invention under the overwrite mechanism is significantly more than that of the existing data block release method, that is, it is realized that the release of some data blocks can be achieved without going through the garbage collection mechanism, reducing the startup frequency of the garbage collection mechanism, thus greatly simplifying the process of releasing data blocks and effectively improving the efficiency of releasing data blocks.
[0055] Please refer to Figure 8 , Embodiment 2 of the present invention is as follows: A method for releasing a data block, which is different from Embodiment 1 in that: the specific implementation manner of step S41 is defined. Since in an actual scenario, the size of a super data block is larger than the size of a write allocation unit, after the data of a write allocation unit is completely written, there will still be a part of the space left in the super data block. To ensure that only the data of one write allocation unit is written into a super data block, special filling processing needs to be performed on the remaining space after the data of a write allocation unit is written, so as to avoid writing other data into the remaining space.
[0056] Specifically, S41 includes S411 - S413: S411. Write the current write data sent based on the write allocation unit in the write command into a preset cache to obtain target write data, and the preset cache only allows writing the current write data of the size of one write allocation unit.
[0057] In some embodiments, the data sent by the host is first stored in a preset cache. In a specific application scenario, if the data of AU 0 is stored in the current preset cache, when a new write command sent by the host is for the data of AU 1, the write command of AU 1 will be temporarily suspended, and only after the data of AU 0 in the preset cache is emptied can the data of AU 1 be stored, so as to ensure that the preset cache only writes the current write data of the size of one write allocation unit.
[0058] S412. After completely writing the target write data in the preset cache into the free data block, detect whether there are free data pages in the free data block.
[0059] S413. If so, fill a write completion mark to the end of the target write data to obtain a valid data block.
[0060] Specifically, step S413 includes the following S4131 - S4133: S4131. Detect whether the current data page in the free data block where the target write data is written is completely full.
[0061] S4132. If so, fill the write completion mark into the next free data page after the current data page to obtain a valid data block; S4133. Otherwise, fill the write completion mark into the blank addresses in the current data page where the target write data is not written and the next free data page after the current data page to obtain a valid data block.
[0062] Apply the above steps S412 and S413 to a specific scenario, such as Figure 8 As shown in the figure: 1. Write the target write data of an AU 0 in the preset cache into super Block A. The write range of the target write data in super Block A includes super page0-N, and the data pages super page0-N in the write range are all fully written. Therefore, fill the write completion mark in the data page super pageN+1 after the current data page super pageN. The write completion mark is the dummy data of CLOSE LAA (fill data for closing the logical address). 2. Write the target write data of an AU 1 in the preset cache into super Block B. The write range of the target write data in super Block B includes superpage0-N, but the data page super pageN in the write range of data pages super page0-N is not fully written. Therefore, fill the dummy data of CLOSE LAA in the blank address of the current data page super pageN, and fill the dummy data of CLOSE LAA in the data page super pageN+1 after the current data page super pageN. The data filling process of AU 3 is the same as that of AU 2. After filling the dummy data of CLOSE LAA in the data block, no other data will be written. Therefore, the data of a new write command will be written into the next data block. In the current scenario, the sizes of super Block A, super Block B, and super Block C are the same, and the sizes of AU 0, AU 1, and AU3 are different. The specific size relationship of the write allocation units is: AU 0>AU 1>AU3.
[0063] In this embodiment, the method further includes the following S601-S602: S601. If the valid data block is marked as the recovery target block for the garbage collection operation, mark the data page with the write completion mark in the valid data block as the stop data page.
[0064] S602. When data is moved in the recovery target block, if the stop data page is read, end the garbage collection operation.
[0065] If there is a data block that has completed writing data to the allocation unit AU and filling the dummy data, but has not been released through overwriting. The garbage collection mechanism may select this data block super Block as the source super Block. When moving this source super Block, if this kind of CLOSE LAA dummy data is read, the garbage collection mechanism will set the page (data page) filled with CLOSE LAA dummy data as the page to stop, and there is no need to read and write data further, and the task of moving this source super Block can end in advance.
[0066] Please refer to Figure 9 , the third embodiment of the present invention is: A method for releasing a data block, which is different from the first or second embodiment in that: a write interruption request is received during the execution of step S411.
[0067] Specifically, the method includes: S701. If a write interruption request is received when writing the current write data issued based on the write allocation unit in the write command to a preset cache, then when receiving the next write command from the host, detect whether the next write data issued based on the write allocation unit in the next write command and the current write data that has been written to the preset cache belong to continuous writing. If so, execute S702; otherwise, execute S703.
[0068] In some embodiments, detecting whether the next write data issued based on the write allocation unit in the next write command and the current write data that has been written to the preset cache belong to continuous writing is specifically: obtaining the current LBA of the current write command and the next LBA of the next write command, and detecting whether the next LBA belongs to the range of the current LBA. If so, the next write data and the current write data belong to continuous writing; otherwise, the next write data and the current write data do not belong to continuous writing.
[0069] S702. Then write the next write data to the preset cache to obtain the target write data, and execute S412 - S413.
[0070] S703. Take the current write data that has been written to the preset cache as the target write data, and execute S412 - S413.
[0071] Applying the above steps S701 and S703 to a specific scenario, such as Figure 9As shown, assume that the data of AU0 is currently being written into a preset cache, but a write interruption request is received when the data of AU0 is halfway through being written. Then, when a new write command is received, it is detected that the LBA of the new write command does not fall within the range of the previous write command AU0. At this time, the remaining data of AU0 in the preset cache will be flushed down to super Block A first, and the data pages super pageM and super pageM+1 that are not fully written will be filled with dummy data to close super Block A. After the preset cache is emptied, the data of AU1 in the new write command is flushed down to super Block B through the preset cache. In addition, if it is detected that the LBA of the new write command falls within the range of the previous write command AU0, the data in the new write command will be written into the preset cache, and the data of the new and previous write commands will be flushed down to super Block A through the preset cache.
[0072] Please refer to Figure 10 , Embodiment 4 of the present invention is: A storage device includes a control chip and a storage chip. The storage chip stores a computer program. When the computer program is executed by the control chip, it implements each step in a method for releasing data blocks in the above-mentioned Embodiments 1 to 3.
[0073] In summary, the present invention provides a method for releasing data blocks and a storage device. By spatially aligning the size of the write allocation unit with the capacity size of the super data block, it effectively solves the problem of storage space fragmentation caused by the mismatch between the write allocation unit and the data block size in the traditional overwriting method. By configuring the size of the write allocation unit as a configurable parameter that is less than and closest to the size of the super data block, it not only meets the write performance standard but also minimizes fragmentation to the greatest extent. During the write process, by detecting whether the write command is an overwriting command, the invalid data blocks after overwriting are instantaneously released in a targeted manner, avoiding cross-block storage, ensuring that each data block can be completely released, reducing the startup frequency of the garbage collection mechanism, and avoiding triggering the write protection mechanism. In addition, through the mechanism of the preset cache and the write completion mark, the data write process is further optimized, avoiding data fragmentation and cross-block storage problems. At the same time, in the garbage collection operation, by marking and stopping the data pages, the unnecessary data transfer amount is reduced, and the release efficiency of the garbage collection is improved. In the write interruption scenario, by detecting the continuity of the written data, the cache data is reasonably processed to ensure the integrity and continuity of the data. The solution of the present invention not only improves the write performance and space utilization rate of the storage device but also enhances the release efficiency of the data blocks and the stability of the write performance.
[0074] In the above embodiments provided in the present application, it should be understood that the disclosed methods, devices, computer-readable storage media, and electronic devices can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of the modules is only a logical function division. In actual implementation, there may be other division methods. For example, multiple components or modules can be combined or integrated into another device, or some features can be ignored or not executed. Another point is that the displayed or discussed couplings or direct couplings or communication connections to each other can be through some interfaces. The indirect couplings or communication connections of the devices or components or modules can be in electrical, mechanical, or other forms.
[0075] The components described as separate components may or may not be physically separated. The components displayed as components may or may not be physical modules, that is, they can be located in one place or distributed to multiple network modules. Some or all of the components can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0076] In addition, in each embodiment of the present invention, the functional modules can be integrated in a processing module, or each component can exist physically alone, or two or more modules can be integrated in one module. The above-mentioned integrated modules can be implemented in the form of hardware or in the form of software functional modules.
[0077] If the above-mentioned integrated module is implemented in the form of a software functional module and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of this technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in each embodiment of the present invention. And the aforementioned storage media include: USB flash drives, mobile hard disks, read-only memories (ROM, Read-Only Memory), random access memories (RAM, Random Access Memory), magnetic disks, or optical discs and other various media that can store program codes.
[0078] It should be noted that, for the foregoing method embodiments, for the sake of simplicity of description, they are all expressed as a series of action combinations. However, those skilled in the art should know that the present invention is not limited by the described action sequence, because according to the present invention, some steps can be performed in other sequences or simultaneously. Secondly, those skilled in the art should also know that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily essential to the present invention.
[0079] In the above embodiments, the descriptions of the respective embodiments have their own focuses. For the parts not detailed in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0080] The above are only the embodiments of the present invention, and do not limit the patent scope of the present invention accordingly. Any equivalent transformation made by using the content of the specification and drawings of the present invention, or directly or indirectly applied in the related technical fields, shall be equally included in the patent protection scope of the present invention.
Claims
1. A method for releasing data blocks, characterized in that, Including: Obtaining the capacity size of the super data block in the storage device; Configuring the size of the write allocation unit to the capacity size of the super data block; Receiving a write command from the host and detecting whether the write command belongs to a rewrite command; If so, performing a rewrite process on the super data block according to the current write data issued based on the write allocation unit in the write command to obtain an invalid data block, and performing a release process on the invalid data block.
2. The method for releasing a data block according to claim 1, wherein Obtaining the capacity size of the super data block in the storage device includes: Obtaining the device model of the storage device; Determining the storage structure of the storage device based on the device model; Determining the capacity size for storing user data in the super data block based on the storage structure.
3. The method for releasing a data block according to claim 2, wherein Configuring the size of the write allocation unit to the capacity size of the super data block includes: Obtaining multiple configurable parameters for the size of the write allocation unit; Determining a target configuration parameter among the multiple configurable parameters that is less than the capacity size and the difference from the capacity size is less than a preset value; Configuring the size of the write allocation unit to the target configuration parameter.
4. A method for releasing a data block according to claim 1, characterized in that Detecting whether the write command belongs to a rewrite command includes: Obtaining the historical logical block address of the historical write command received before the write command; Detecting whether the current logical block address of the write command is the same as the historical logical block address; If so, determining that the write command belongs to a rewrite command; Otherwise, determining that the write command does not belong to a rewrite command.
5. A method for releasing a data block according to claim 4, characterized in that Performing a rewrite process on the super data block according to the current write data issued based on the write allocation unit in the write command to obtain an invalid data block includes: Writing the current write data issued based on the write allocation unit in the write command into the free data block in the super data block to obtain a valid data block; Updating the mapping table entry of the current logical block address to the valid data block, so that the original data block mapped before the update is invalidated to obtain an invalid data block.
6. The method for releasing a data block according to claim 5, wherein Writing the current write data issued based on the write allocation unit in the write command into the free data block in the super data block to obtain a valid data block includes: Writing the current write data issued based on the write allocation unit in the write command into a preset cache to obtain target write data, and the preset cache only allows writing the current write data of the size of one write allocation unit; After completely writing the target write data in the preset cache into the free data block, detecting whether there is a free data page in the free data block; If so, filling a write completion mark at the end of the target write data to obtain a valid data block.
7. A method for releasing a data block according to claim 6, wherein Filling a write completion mark at the end of the target write data to obtain a valid data block includes: Detecting whether the current data page in the free data block where the target write data is written is completely full; If so, filling the write completion mark into the next free data page after the current data page to obtain a valid data block; Otherwise, fill the write completion marks into the blank addresses of the current data page that have not been written with the target write data and the next free data page after the current data page to obtain valid data blocks.
8. A method for releasing a data block according to claim 6, wherein, Further included: If the valid data block is marked as the reclaim target block for the garbage collection operation, mark the data page in the valid data block with the write completion mark as the stop data page; When data migration is performed on the reclaim target block, if the stop data page is read, end the garbage collection operation.
9. A method for releasing a data block according to claim 6, wherein Further included: If a write interrupt request is received when writing the current write data issued based on the write allocation unit in the write command into the preset cache, when receiving the next write command from the host, detect whether the next write data issued based on the write allocation unit in the next write command is continuous with the current write data that has been written into the preset cache; If so, write the next write data into the preset cache to obtain the target write data, and execute the step of detecting whether there is a free data page in the free data block after completely writing the target write data in the preset cache into the free data block; Otherwise, use the current write data that has been written into the preset cache as the target write data, and execute the step of detecting whether there is a free data page in the free data block after completely writing the target write data in the preset cache into the free data block.
10. A method for releasing a data block according to claim 5, characterized in that, Further included: If the write command does not belong to the overwrite command, write the current write data into the free data block in the super data block to obtain a valid data block, and map the current logical block address to the valid data block to obtain a mapping table entry.
11. A storage device, comprising a control chip and a storage chip, wherein the storage chip stores a computer program, characterized in that, When the computer program is executed by the control chip, it realizes each step in a method for releasing data blocks as described in any one of claims 1 to 10.
Citation Information
Patent Citations
Data storage method and device based on address redirection
CN115390751A
Super block-based write management in non-volatile memory devices
CN116737060A
Storage device and method of reclaiming space of the same
KR1020170110904A
Data processing method and apparatus of solid state disk
US20170160940A1
Optimizing allocation unit sizes for heterogeneous storage systems
US20240339159A1