A method, apparatus, electronic device, and storage medium for reclaiming disk space.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-29
- Publication Date
- 2026-08-14
AI Technical Summary
在正常工作中,SSD无法事先知道那些被‘删除’的数据页已经是‘无效’,必须到系统要求在相同的地方写入数据时才知道那些数据可以被擦除,这样就无法在最适当的时机做出最好的优化,既影响GC的效率(间接影响性能),又影响SSD的寿命
[0067]In this application, the cache disk controller obtains data block invalidation instructions from the file system layer. These instructions include the sector address and sector length of the backend storage disk. Based on the sector address and length, a corresponding invalidation key is generated. The B+tree in the cache disk is traversed; if the invalidation key exists in a node of the B+tree, the invalidated data block corresponding to the invalidation key on the cache disk is reclaimed. This method can proactively "notify" the front-end cache disk which data blocks have become invalid under normal operating conditions, allowing the garbage collection driver to reclaim invalid data blocks in advance. This avoids copying data defined as invalid by the operating system to free blocks in order to merge free space, thus reducing the amount of data that needs to be copied during garbage collection and improving the efficiency of reclaiming invalid data from free disk space.
Smart Images

Figure CN116069681B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of distributed storage optimization technology, specifically to a disk space reclamation method, apparatus, electronic device, and storage medium. Background Technology
[0002] Bcache is a block device-level caching system in the Linux kernel. It constructs a cache from multiple (>=1) high-speed block devices (typically solid-state drives) as multiple low-speed block devices (typically hard disk drives). The SSDs are the high-speed hard drives (solid-state drives), and sda-sdn is the low-speed hard drive (hard disk drive). The SSDs act as cache disks, providing caching services for the backend low-speed hard drives. Bcache writes application-layer I / O data to the cache devices (high-speed block devices), and then writes the data from the cache devices back to the backend low-speed block devices, thereby achieving higher write performance.
[0003] In Bcache, the cache disk typically uses a high-speed SSD, while the backend storage disk uses an HDD. However, the characteristics of SSDs dictate that they cannot function like regular HDDs. When a file is deleted in the operating system, the system doesn't actually delete the file's data; it merely marks the addresses occupied by that data as 'empty,' meaning they can be overwritten. But this is only an operation at the file system level; the hard drive itself doesn't know which addresses are 'invalid' unless the system instructs it to write new data to those addresses. This works fine on HDDs because they allow overwriting, but problems arise with SSDs. SSDs don't allow overwriting; they must erase before writing. To obtain 'free' flash memory for writing, the SSD must perform garbage collection (GC). During normal operation, the SSD cannot know in advance which 'deleted' data pages are 'invalid' until the system requests data to be written to the same locations. This prevents optimal optimization at the most appropriate time, impacting both GC efficiency (indirectly affecting performance) and the SSD's lifespan.
[0004] Therefore, how to efficiently reclaim invalid storage space in the cache disk of Bcache is an urgent problem to be solved. Summary of the Invention
[0005] This application provides a disk space reclamation method, apparatus, electronic device, and storage medium that can efficiently reclaim invalid space in the cache disk of Bcache.
[0006] To achieve the above objectives, this application provides the following solution.
[0007] In a first aspect, this application provides a disk space reclamation method, the method comprising the following steps:
[0008] Obtain a data block invalidation instruction issued by the file system layer; wherein, the data block invalidation instruction includes the sector address and sector length of the backend storage disk;
[0009] Based on the sector address and the sector length, a corresponding invalidation key value is generated;
[0010] Traverse the b+tree in the cache disk. If the invalid key value exists in a node of the b+tree, then reclaim the invalid data block on the cache disk corresponding to the invalid key value.
[0011] Furthermore, before obtaining the data block invalidation instruction issued by the file system layer, the following steps are included;
[0012] Based on the data correspondence between the backend storage disk and the cache disk, a B+ tree is constructed in the cache disk;
[0013] Retrieve failure notification commands from the file system layer;
[0014] Based on the attributes of the failure notification instruction, it is determined that the failure notification instruction is a data block failure instruction.
[0015] Furthermore, before obtaining the data block invalidation instruction issued by the file system layer, the following steps are included;
[0016] Based on the data correspondence between the backend storage disk and the cache disk, a B+ tree is constructed in the cache disk;
[0017] Retrieve failure notification commands from the file system layer;
[0018] Based on the attributes of the failure notification instruction, it is determined that the failure notification instruction is a data block failure instruction.
[0019] Furthermore, determining that the failure notification instruction is a data block failure instruction based on its attributes includes the following steps:
[0020] Identify the target node on the b+tree and set it as a command attribute checkpoint;
[0021] Using the command attribute checkpoint, check whether the attribute of the failure notification instruction is REQ_OP_DISCARD;
[0022] If so, the failure notification instruction is determined to be a data block failure instruction.
[0023] Furthermore, the step of traversing the b+tree in the cache disk, and if the invalid key value exists in a node of the b+tree, then the invalid data block corresponding to the invalid key value on the cache disk is reclaimed, including the following steps:
[0024] Obtain the root node of the b+tree, and traverse all nodes of the b+tree from the root node;
[0025] If the invalid key exists in a node of the b+tree, then obtain the address of the data block corresponding to the invalid key on the cache disk;
[0026] Garbage collection is performed on the data blocks existing at the specified data block address.
[0027] Furthermore, the method also includes:
[0028] If the invalid key value does not exist in the node of the b+tree, then garbage collection will not be performed on the stored data block in the cache disk.
[0029] Furthermore, the garbage collection of the data blocks existing at the data block address includes the following steps:
[0030] Based on the address of the first invalid data block located on the backend cache disk corresponding to the invalid key value, obtain the address of the second invalid data block located on the cache device;
[0031] Based on the address of the second failed data block, an updated failure key value is generated;
[0032] If the updated invalid key value exists on the b+tree, then the invalid data block address corresponding to the invalid key value is merged with the original data block address on the b+tree;
[0033] Encapsulate the merged second data block address into a bio command;
[0034] Based on the bio command, the garbage collection mechanism is invoked to reclaim the failed data block corresponding to the address of the second failed data block.
[0035] Before encapsulating the merged second data block address into a bio command, the following steps are included:
[0036] When the timer expires and triggers, it is determined whether the b+tree is empty.
[0037] If the b+tree is empty, then no garbage collection operation will be performed on the data on the cache disk.
[0038] Furthermore, before encapsulating the merged second data block address into a bio command, the following steps are included:
[0039] When the timer expires and triggers, it is determined whether the b+tree is empty.
[0040] If the b+tree is empty, then no garbage collection operation will be performed on the data on the cache disk.
[0041] Secondly, this application provides a disk space reclamation device, the device comprising:
[0042] The failure instruction acquisition module is used to acquire data block failure instructions issued by the file system layer; wherein, the data block failure instruction includes the sector address and sector length of the backend storage disk;
[0043] The key value acquisition module is used to generate a corresponding invalid key value based on the sector address and the sector length;
[0044] The recycling module is used to traverse the b+tree in the cache disk. If the invalid key value exists in a node of the b+tree, the invalid data block corresponding to the invalid key value on the cache disk is recycled.
[0045] Furthermore, the failure instruction acquisition module also includes:
[0046] The b+tree construction submodule is used to construct a b+tree in the cache disk based on the data correspondence between the backend storage disk and the cache disk.
[0047] The failure notification instruction acquisition submodule is used to acquire failure notification instructions issued by the file system layer.
[0048] The determination submodule is used to determine whether the failure notification instruction is a data block failure instruction based on the attributes of the failure notification instruction.
[0049] Furthermore, the judgment submodule includes:
[0050] A checkpoint setting unit is used to determine a target node on the b+tree and set it as a command attribute checkpoint.
[0051] An attribute determination unit is used to check whether the attribute of the failure notification instruction is REQ_OP_DISCARD using the command attribute checkpoint.
[0052] The determination unit is used to determine if the failure notification instruction is a data block failure instruction.
[0053] Furthermore, the recycling module includes:
[0054] The traversal submodule is used to obtain the root node of the b+tree and traverse all nodes of the b+tree from the root node;
[0055] The address resolution submodule is used to obtain the address of the data block corresponding to the invalid key value on the cache disk if the invalid key value exists in the node of the b+tree.
[0056] The garbage collection submodule is used to perform garbage collection on the data blocks existing at the address of the data block.
[0057] Furthermore, the waste recycling submodule includes:
[0058] The address acquisition unit is used to acquire the address of the second invalid data block located on the cache device based on the address of the first invalid data block located on the backend cache disk corresponding to the invalid key value;
[0059] A key-value update unit is used to generate an updated failure key-value based on the address of the second failed data block;
[0060] The merging unit is used to merge the address of the invalid data block corresponding to the invalid key value with the original data block address on the b+tree if the updated invalid key value exists on the b+tree.
[0061] The encapsulation unit is used to encapsulate the merged second data block address into a bio command.
[0062] The calling unit is used to invoke the garbage collection mechanism to reclaim the failed data block corresponding to the address of the second failed data block based on the bio command.
[0063] Furthermore, the packaging unit also includes:
[0064] An empty set determination unit is used to determine whether the b+tree is empty when the timer expires and triggers.
[0065] The first operation unit is configured to not perform garbage collection on the data on the cache disk if the b+tree is empty.
[0066] The beneficial effects of the technical solution provided in this application include:
[0067] In this application, the cache disk controller obtains data block invalidation instructions from the file system layer. These instructions include the sector address and sector length of the backend storage disk. Based on the sector address and length, a corresponding invalidation key is generated. The B+tree in the cache disk is traversed; if the invalidation key exists in a node of the B+tree, the invalidated data block corresponding to the invalidation key on the cache disk is reclaimed. This method can proactively "notify" the front-end cache disk which data blocks have become invalid under normal operating conditions, allowing the garbage collection driver to reclaim invalid data blocks in advance. This avoids copying data defined as invalid by the operating system to free blocks in order to merge free space, thus reducing the amount of data that needs to be copied during garbage collection and improving the efficiency of reclaiming invalid data from free disk space. Attached Figure Description
[0068] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0069] Figure 1 This is a flowchart illustrating the disk space reclamation steps provided in the embodiments of this application;
[0070] Figure 2 This is a flowchart illustrating the disk space reclamation steps provided in another embodiment of this application. Detailed Implementation
[0071] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0072] The embodiments of this application will be further described in detail below with reference to the accompanying drawings.
[0073] See Figure 1 As shown in the figure, this application embodiment provides a disk space reclamation method, which includes the following steps:
[0074] S1. Obtain the data block invalidation command issued by the file system layer;
[0075] A file system is a mechanism for organizing and managing files on a storage device. It's understandable that different methods of organizing and managing files on a storage device will result in different types of file systems.
[0076] Bcache is a block device caching system in the Linux kernel. Its basic function is to use solid-state drives (SSDs) as cache devices for hard disk drives (HDDs) (back-end devices). Bcache is a cache memory at the block device layer of the Linux operating system kernel. Cache memory is a high-speed buffer memory, a small but very fast memory located between the CPU and main DRAM, typically composed of static memory. The function of cache is to improve the CPU's data input / output speed.
[0077] The use case for this Bcache caching system is to use an SSD as a cache layer on top of a slower HDD, thereby improving the HDD's I / O speed. One cache disk (SSD) can simultaneously provide caching for multiple backend disks (HDDs). Since it's a cache, caching strategies are naturally considered. Bcache supports three caching strategies: writeback: all data is first written to the cache disk, then waits for the system to write the data back to the backend data disk; writethrough: direct write strategy (default strategy), data is written to both the cache disk and the backend data disk simultaneously; writeaway: data is written directly to the backend disk.
[0078] Specifically, the backend disk controller constructs a B+ tree in the cache disk based on the data correspondence between the backend storage disk and the cache disk; obtains the failure notification command issued by the file system layer; and determines the failure notification command as a data block failure command based on the attributes of the failure notification command.
[0079] S2. Generate the corresponding failure key value based on the sector address and sector length;
[0080] Understandably, when reading and writing data to and from a back-end storage disk using a disk drive, data is processed in sectors. On the back-end storage disk, the DOS operating system allocates disk space for files in units of "clusters." A cluster on a back-end storage disk typically consists of multiple sectors, depending on the type of disk, the DOS version, and the size of the hard drive partition. Each cluster can only be occupied by one file; even if the file contains only a few bytes, two or more files are never allowed to share a cluster, otherwise, data corruption will occur. This mechanism, using clusters as the smallest allocation unit, makes data management on the back-end storage disk relatively easy, but it also leads to wasted disk space, especially when there are many small files. On a large hard drive with a capacity of several gigabytes, this could result in hundreds of megabytes of wasted disk space.
[0081] Disk caching, also known as disk buffering or disk cache, works by first storing downloaded data in memory space allocated to the software by the system (this memory space is called a "memory pool"). When the data stored in the memory pool reaches a certain level, it is then saved to the cached disk. This reduces actual disk read / write operations and effectively protects the disk from damage caused by repeated read / write operations. Disk caching aims to reduce the number of times the CPU reads the backend storage disk through I / O, thereby improving the efficiency of backend storage disk read / write operations.
[0082] Specifically, when the back-end disk controller determines in step S1 that the attribute of the failure notification instruction issued by the file system layer is a data block failure instruction, it parses the sector address and sector length of the failed data block in the back-end storage disk from the data block failure instruction, and then generates a failure key value corresponding to the sector address based on the sector address and sector length.
[0083] S3. Traverse the b+tree in the cache disk. If the invalid key value exists in a node of the b+tree, reclaim the invalid data block corresponding to the invalid key value on the cache disk.
[0084] The backend disk controller obtains the address of the second failed data block on the cache device based on the address of the first failed data block on the backend cache disk corresponding to the failed key value; it generates an updated failed key value based on the address of the second failed data block; if the updated failed key value exists on the b+tree, it merges the address of the failed data block corresponding to the failed key value with the original data block address on the b+tree; it encapsulates the merged second data block address into a bio command; and based on the bio command, it calls the garbage collection mechanism to reclaim the failed data block corresponding to the address of the second failed data block.
[0085] In this application, the cache disk controller obtains data block invalidation instructions from the file system layer. These instructions include the sector address and sector length of the backend storage disk. Based on the sector address and length, a corresponding invalidation key is generated. The B+tree in the cache disk is traversed; if the invalidation key exists in a node of the B+tree, the invalidated data block corresponding to the invalidation key on the cache disk is reclaimed. This method can proactively "notify" the front-end cache disk which data blocks have become invalid under normal operating conditions, allowing the garbage collection driver to reclaim invalid data blocks in advance. This avoids copying data defined as invalid by the operating system to free blocks in order to merge free space, thus reducing the amount of data that needs to be copied during garbage collection and improving the efficiency of reclaiming invalid data from free disk space.
[0086] In one embodiment of the application, the steps preceding step S1 include:
[0087] Based on the data correspondence between the backend storage disk and the cache disk, a B+ tree is constructed in the cache disk; the failure notification command issued by the file system layer is obtained; based on the attributes of the failure notification command, the failure notification command is determined to be a data block failure command.
[0088] Understandably, B+tree, a multi-way search tree, is used in Bcache to maintain the mapping relationship between data on the cache device and the backend device. The B+tree involves four operations: search, traversal, insertion, and sorting. Writing data to the cache device inserts elements into the B+tree; reading data from the cache device searches for elements in the B+tree.
[0089] Because there are corresponding rules between the addresses of data stored in the cache device and the addresses in the backend storage disk, the addresses in the backend storage disk are usually associated with the addresses of data stored in the cache device through mirroring. A B+ tree is then built in the cache disk based on the relationship between the addresses in the backend storage disk and the cache device.
[0090] The cache disk controller obtains the failure notification command issued by the file system layer, determines the target node on the b+tree, and sets it as a command attribute checkpoint. Using the command attribute checkpoint, it checks whether the attribute of the failure notification command is REQ_OP_DISCARD; if so, it determines that the failure notification command is a data block failure command.
[0091] In one embodiment of the application, step S3 includes:
[0092] S301. Obtain the root node of the b+tree and traverse all nodes of the b+tree from the root node.
[0093] S302. If the invalid key value exists in a node of the b+tree, then obtain the address of the data block corresponding to the invalid key value on the cache disk.
[0094] In another embodiment, if the invalid key value does not exist in the node of the b+tree, then the stored data block in the cache disk is not garbage collected.
[0095] S303. Perform garbage collection on the data blocks existing at the data block address.
[0096] The cache disk controller obtains the address of the second invalid data block located on the cache device based on the address of the first invalid data block located on the backend cache disk corresponding to the invalid key value; generates an updated invalid key value based on the address of the second invalid data block; if the updated invalid key value exists on the b+tree, the address of the invalid data block corresponding to the invalid key value is merged with the original data block address on the b+tree; the merged second data block address is encapsulated into a bio command; based on the bio command, the garbage collection mechanism is invoked to reclaim the invalid data block corresponding to the address of the second invalid data block.
[0097] In one embodiment of the application, such as Figure 2 As shown, a disk space reclamation method is proposed, which includes the following steps:
[0098] A1. Construct a new b+tree, denoted as SSD-b+tree;
[0099] A2. Set a timer;
[0100] A3. Select the timing for "notifying" which data blocks on the SSD have expired: Based on the REQ_OP_DISCARD command issued by the file system layer, it can be obtained which blocks on the SSD have expired as "known" by the file system layer. Therefore, a checkpoint is set in the Bcache data writing process to check whether the command attribute issued by the file system is REQ_OP_DISCARD. If not, ignore it; if so, proceed to the method proposed in this invention.
[0101] A4. Copy the REQ_OP_DISCARD attribute command;
[0102] A5. Initialize the tree operation lock; then convert the sector address and sector length of the backend HDD device carried by the REQ_OP_DISCARD command into a KEY in the Bcache; obtain the root node of the b+tree in the Bcache; and start searching from the root node of the b+tree; compare whether the KEY corresponding to the REQ_OP_DISCARD command is on the b+tree. If it is not on the b+tree, i.e., a miss, it means that the HDD failed block data corresponding to the REQ_OP_DISCARD command is not on the SSD, so no reclamation is performed on the SSD. If it is on the b+tree, i.e., a miss, it means that the HDD failed block data corresponding to the REQ_OP_DISCARD command is on the SSD, so the failed data block needs to be reclaimed on the SSD.
[0103] A6. Using the updated KEY, map the HDD disk block address corresponding to the hit REQ_OP_DISCARD command to the SSD disk address; convert the obtained SSD disk address into a new KEY; add the updated KEY to the SSD-b+ tree; traverse the SSD-b+ tree with the new KEY. If the SSD address of the new KEY overlaps with that of the original KEY, merge the two KEYs to merge the SSD data blocks. If the SSD address of the new KEY does not overlap with that of the original KEY, add the KEY to the SSD-b+ tree.
[0104] A7. When the timer expires and triggers, check if the SSD-b+tree is empty. If it is not empty, encapsulate the SSD address corresponding to the KEY on the SSD-b+tree into multiple bio commands. If it is empty, do not perform any operation. Send the encapsulated bio commands to the SSD driver through the block device layer, so that the SSD can call GC to reclaim invalid data blocks according to the encapsulated bio commands.
[0105] In this embodiment, under normal working conditions, the front-end cache disk can be "notified" in advance which data blocks have become invalid, so that the garbage collection driver can reclaim invalid data blocks in the cache disk in advance. This avoids copying data that has been defined as invalid by the operating system into the free blocks in order to merge free space in the cache disk, thereby reducing the amount of data that needs to be copied during garbage collection and improving the efficiency of reclaiming invalid data in the free space of the disk.
[0106] It should be noted that the step numbers in the embodiments of this application do not limit the order of operations in the technical solution of this application.
[0107] Secondly, embodiments of this application provide a disk space reclamation device, which includes:
[0108] The failure instruction acquisition module is used to acquire data block failure instructions issued by the file system layer; wherein, the data block failure instruction includes the sector address and sector length of the backend storage disk;
[0109] The key value acquisition module is used to generate a corresponding invalid key value based on the sector address and the sector length;
[0110] The recycling module is used to traverse the b+tree in the cache disk. If the invalid key value exists in a node of the b+tree, the invalid data block corresponding to the invalid key value on the cache disk is recycled.
[0111] The backend disk controller constructs a B+ tree in the cache disk based on the data correspondence between the backend storage disk and the cache disk; obtains the failure notification command issued by the file system layer; and determines the failure notification command as a data block failure command based on the attributes of the failure notification command.
[0112] When the back-end disk controller determines in step S1 that the attribute of the failure notification instruction issued by the file system layer is a data block failure instruction, it parses the sector address and sector length of the failed data block in the back-end storage disk from the data block failure instruction, and then generates a failure key value corresponding to the sector address based on the sector address and sector length.
[0113] The backend disk controller obtains the address of the second failed data block on the cache device based on the address of the first failed data block on the backend cache disk corresponding to the failed key value; it generates an updated failed key value based on the address of the second failed data block; if the updated failed key value exists on the b+tree, it merges the address of the failed data block corresponding to the failed key value with the original data block address on the b+tree; it encapsulates the merged second data block address into a bio command; and based on the bio command, it calls the garbage collection mechanism to reclaim the failed data block corresponding to the address of the second failed data block.
[0114] In this application, the cache disk controller obtains data block invalidation instructions from the file system layer. These instructions include the sector address and sector length of the backend storage disk. Based on the sector address and length, a corresponding invalidation key is generated. The B+tree in the cache disk is traversed; if the invalidation key exists in a node of the B+tree, the invalidated data block corresponding to the invalidation key on the cache disk is reclaimed. This method can proactively "notify" the front-end cache disk which data blocks have become invalid under normal operating conditions, allowing the garbage collection driver to reclaim invalid data blocks in advance. This avoids copying data defined as invalid by the operating system to free blocks in order to merge free space, thus reducing the amount of data that needs to be copied during garbage collection and improving the efficiency of reclaiming invalid data from free disk space.
[0115] In one implementation, the failure instruction acquisition module further includes:
[0116] The b+tree construction submodule is used to construct a b+tree in the cache disk based on the data correspondence between the backend storage disk and the cache disk.
[0117] The failure notification instruction acquisition submodule is used to acquire failure notification instructions issued by the file system layer.
[0118] The determination submodule is used to determine whether the failure notification instruction is a data block failure instruction based on the attributes of the failure notification instruction.
[0119] In one application implementation, the judgment submodule includes:
[0120] A checkpoint setting unit is used to determine a target node on the b+tree and set it as a command attribute checkpoint.
[0121] An attribute determination unit is used to check whether the attribute of the failure notification instruction is REQ_OP_DISCARD using the command attribute checkpoint.
[0122] The determination unit is used to determine if the failure notification instruction is a data block failure instruction.
[0123] In one application implementation, the recycling module includes:
[0124] The traversal submodule is used to obtain the root node of the b+tree and traverse all nodes of the b+tree from the root node;
[0125] The address resolution submodule is used to obtain the address of the data block corresponding to the invalid key value on the cache disk if the invalid key value exists in the node of the b+tree.
[0126] The garbage collection submodule is used to perform garbage collection on the data blocks existing at the address of the data block.
[0127] In one application implementation, the waste recycling submodule includes:
[0128] The address acquisition unit is used to acquire the address of the second invalid data block located on the cache device based on the address of the first invalid data block located on the backend cache disk corresponding to the invalid key value;
[0129] A key-value update unit is used to generate an updated failure key-value based on the address of the second failed data block;
[0130] The merging unit is used to merge the address of the invalid data block corresponding to the invalid key value with the original data block address on the b+tree if the updated invalid key value exists on the b+tree.
[0131] The encapsulation unit is used to encapsulate the merged second data block address into a bio command.
[0132] The calling unit is used to invoke the garbage collection mechanism to reclaim the failed data block corresponding to the address of the second failed data block based on the bio command.
[0133] In one implementation, the packaging unit further includes:
[0134] An empty set determination unit is used to determine whether the b+tree is empty when the timer expires and triggers.
[0135] The first operation unit is configured to not perform garbage collection on the data on the cache disk if the b+tree is empty.
[0136] It should be noted that the disk space reclamation device provided in this application has similar technical problems, technical means and technical effects to the disk space reclamation method in principle.
[0137] Thirdly, embodiments of this application provide a storage medium storing a computer program, which, when executed by a processor, implements the disk space reclamation method mentioned in the first aspect.
[0138] Fourthly, embodiments of this application provide an electronic device, including a memory and a processor, wherein the memory stores a computer program that runs on the processor, and the processor executes the computer program to implement the disk space reclamation method mentioned in the first aspect.
[0139] It should be noted that in this application, relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes the element.
[0140] The above are merely specific embodiments of this application, enabling those skilled in the art to understand or implement this application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of this application. Therefore, this application is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features claimed herein.
Claims
1. A method for reclaiming disk space, characterized in that, The method includes the following steps: Obtain a data block invalidation instruction issued by the file system layer; wherein, the data block invalidation instruction includes the sector address and sector length of the backend storage disk; Based on the sector address and the sector length, a corresponding invalidation key value is generated; Get the root node of the b+tree in the cache disk, and traverse all nodes of the b+tree from the root node; If the invalid key exists in a node of the b+tree, then obtain the address of the data block corresponding to the invalid key on the cache disk; Based on the address of the first invalid data block located on the backend cache disk corresponding to the invalid key value, obtain the address of the second invalid data block located on the cache device; Based on the address of the second failed data block, an updated failure key value is generated; If the updated invalid key value exists on the b+tree, then the invalid data block address corresponding to the invalid key value is merged with the original data block address on the b+tree; Encapsulate the merged second data block address into a bio command; Based on the bio command, the garbage collection mechanism is invoked to reclaim the failed data block corresponding to the address of the second failed data block.
2. The disk space reclamation method as described in claim 1, characterized in that, Before obtaining the data block invalidation instruction issued by the file system layer, the following steps are included: Based on the data correspondence between the backend storage disk and the cache disk, a B+ tree is constructed in the cache disk; Retrieve failure notification commands from the file system layer; Based on the attributes of the failure notification instruction, it is determined that the failure notification instruction is a data block failure instruction.
3. The disk space reclamation method as described in claim 2, characterized in that, The step of determining that the failure notification instruction is a data block failure instruction based on its attributes includes the following steps: Identify the target node on the b+tree and set it as a command attribute checkpoint; Using the command attribute checkpoint, check whether the attribute of the failure notification instruction is REQ_OP_DISCARD; If so, the failure notification instruction is determined to be a data block failure instruction.
4. The disk space reclamation method as described in claim 1, characterized in that, The method further includes: If the invalid key value does not exist in the node of the b+tree, then garbage collection will not be performed on the stored data block in the cache disk.
5. The disk space reclamation method as described in claim 1, characterized in that, Before encapsulating the merged second data block address into a bio command, the following steps are included: When the timer expires and triggers, it is determined whether the b+tree is empty. If the b+tree is empty, then no garbage collection operation will be performed on the data on the cache disk.
6. A disk space reclamation device, characterized in that, The device includes: The failure instruction acquisition module is used to acquire data block failure instructions issued by the file system layer; wherein, the data block failure instruction includes the sector address and sector length of the backend storage disk; The key value acquisition module is used to generate a corresponding invalid key value based on the sector address and the sector length; The recycling module is used to obtain the root node of the b+tree in the cache disk and traverse all nodes in the b+tree from the root node; if the invalid key value exists in the node of the b+tree, then obtain the address of the data block corresponding to the invalid key value on the cache disk; based on the first invalid data block address located on the backend cache disk corresponding to the invalid key value, obtain the address of the second invalid data block located on the cache device; based on the second invalid data block address, generate an updated invalid key value; if the updated invalid key value exists in the b+tree, then merge the invalid data block address corresponding to the invalid key value with the original data block address on the b+tree; encapsulate the merged second data block address into a bio command; based on the bio command, call the garbage collection mechanism to reclaim the invalid data block corresponding to the second invalid data block address.
7. A terminal device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the method as described in any one of claims 1 to 5.
8. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it implements the method as described in any one of claims 1 to 5.
Citation Information
Patent Citations
SSD management method and device in mixed storage system
CN107015763A
Performance improving method and device for distributed storage equipment and distributed storage equipment
CN111209253A