A virtual disk defragmentation method and computing device

By using a cardinality tree in the virtual disk to determine the data blocks to be migrated and copy it, the performance reduction problem caused by virtual disk fragmentation is solved, and efficient defragmentation and performance improvement is achieved.

CN118642652BActive Publication Date: 2025-04-04XFUSION DIGITAL TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202410714181.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-06-03
Publication Date
2025-04-04
Estimated Expiration
2044-06-03

AI Technical Summary

Technical Problem

File fragmentation in virtual disks results in reduced read and write performance, requiring defragmentation to improve performance and save storage space.

Method used

By introducing a cardinality tree in the original virtual disk, the offset of the allocated data blocks is saved in order, the cardinality tree is traversed to determine the data blocks to be migrated, and copy them to the continuous data blocks of the target virtual disk.

Benefits of technology

Reduces the complexity and time of defragmentation, improves the efficiency of defragmentation, and reduces the fragmentation rate, thereby improving the read and write performance of virtual disks and saving storage space.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118642652B_ABST
    Figure CN118642652B_ABST
Patent Text Reader

Abstract

The embodiment of the present application provides a virtual disk defragmentation method and computing device, the method comprising: when the original virtual disk meets the preset defragmentation triggering condition, traversing the original radix tree to determine the first address of the data block to be migrated and the number of the data blocks to be migrated; wherein the original virtual disk is the virtual disk to be defragmented; the original radix tree is the radix tree stored in the original virtual disk; the original radix tree is used to sequentially store the data block numbers of each data block to be migrated in the original virtual disk; based on the first address of the data block to be migrated and the number of the data blocks to be migrated, the data blocks to be migrated are sequentially copied to the continuous data blocks of the target virtual disk; wherein the target virtual disk is a newly created virtual disk. The embodiment of the present application can improve the defragmentation efficiency of the virtual disk.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the server field, and in particular to a virtual disk defragmentation method and computing device. Background Art

[0002] Virtual disk file fragmentation refers to the situation where files in a virtual disk are not stored continuously in the physical storage space. When files in a virtual disk are frequently read, written, modified, or deleted, the data in the file will be stored in different locations on the virtual disk, resulting in fragmentation.

[0003] Fragmentation will affect the read and write performance of the virtual disk, thus affecting the running of programs in the virtual machine and the speed of opening files, resulting in reduced performance of the virtual machine. Therefore, it is necessary to defragment the disk files to improve the read and write performance of the virtual disk and save virtual disk storage space. Summary of the invention

[0004] The embodiments of the present application provide a virtual disk defragmentation method and computing device for quickly completing defragmentation to reduce the fragmentation rate, thereby improving the read and write performance of the virtual disk and saving virtual disk storage space.

[0005] In a first aspect, an embodiment of the present application provides a method for defragmenting a virtual disk, the method comprising:

[0006] When the original virtual disk meets the preset defragmentation triggering condition, traverse the original radix tree to determine the first address of the data block to be migrated and the number of the data blocks to be migrated;

[0007] The original virtual disk is the virtual disk to be defragmented;

[0008] The original radix tree is a radix tree stored in the original virtual disk; the original radix tree is used to sequentially store the data block numbers of each data block to be migrated in the original virtual disk;

[0009] Based on the first address of the data block to be migrated and the number of the data blocks to be migrated, the data blocks to be migrated are copied to the continuous data blocks of the target virtual disk in sequence; wherein the target virtual disk is a newly created virtual disk. The beneficial effect of this embodiment: since the radix tree in the original virtual disk sequentially stores the data block numbers of the data blocks allocated in the original virtual disk in the original virtual disk, when performing defragmentation, it is only necessary to traverse the radix tree once to determine the data blocks to be migrated and the number of the data blocks to be migrated in the original virtual disk, and then migrate the data in the data blocks to the newly created target virtual disk, which greatly reduces the complexity of defragmentation, shortens the defragmentation time, and improves the defragmentation efficiency.

[0010] In a possible implementation, traversing the original radix tree to determine the first address of the data block to be migrated and the number of the data blocks to be migrated includes:

[0011] Based on the preset algorithm, starting from the root node of the original cardinality tree, traverse the child nodes of each node in turn;

[0012] When a preset termination condition is met, determine that the data blocks corresponding to the data block numbers pointed to by all leaf nodes whose values ​​are not empty are the data blocks to be migrated, and determine the number of data blocks to be migrated with consecutive data block numbers;

[0013] Among them, the preset termination condition is that the value of the leaf node on the original radix tree is empty or the original radix tree is traversed.

[0014] The beneficial effects of this implementation method are as follows: since the radix tree in the original virtual disk sequentially stores the data block numbers of the data blocks allocated in the original virtual disk, when the radix tree of the original virtual disk is traversed by a preset algorithm, the data blocks to be migrated are also determined in sequence and do not need to be re-sorted. The complexity of this algorithm is lower than that of the algorithm that requires sorting, and the time required is relatively shorter. The data blocks that need to be migrated in the original virtual disk can be quickly determined, thereby improving the efficiency of defragmentation.

[0015] In a possible implementation, the preset algorithm is a depth-first algorithm.

[0016] The beneficial effect of this implementation is that based on the structural characteristics of the radix tree in the original virtual disk, the data blocks to be migrated can be determined more quickly by using the depth-first algorithm for traversal, thereby improving the efficiency of defragmentation.

[0017] In a possible implementation, based on the first address of the data block to be migrated and the number of the data blocks to be migrated, sequentially copying the data blocks to be migrated to the continuous data blocks of the target virtual disk includes:

[0018] Configure the copy coroutine based on the first address of each data block to be migrated and the number of data blocks to be migrated;

[0019] The copy coroutine is started, and based on the data block numbers sequentially stored in the original radix tree, the data blocks to be migrated in the original virtual disk are read in sequence, and the data blocks to be migrated are written in sequence into the continuous data blocks in the target virtual disk.

[0020] Beneficial effects of this implementation method: There are generally multiple data blocks to be migrated in the original virtual disk. Copying through the copy coroutine can improve the copy efficiency and save the time of defragmentation.

[0021] In a possible implementation, the method further includes:

[0022] An initialized radix tree is set in the target virtual disk; wherein the initialized radix tree is determined based on a preset tree height and the number of bits of the data block number; the preset tree height represents the number of levels of the radix tree;

[0023] The data block number of each data block in the target virtual disk is inserted into the initialized radix tree to obtain the target radix tree.

[0024] The beneficial effects of this implementation method: If a radix tree is also constructed in the target virtual disk, when the data in the subsequent target virtual disk is continuously modified, deleted, written, etc. to meet the defragmentation triggering conditions, fast defragmentation can also be performed through the method of the embodiment of the present application, thereby improving the defragmentation efficiency.

[0025] In a possible implementation, inserting the data block number of each data block in the target virtual disk into the initialized radix tree includes:

[0026] Determine the data block number of each data block in the target virtual disk, and determine the index value corresponding to the data block number of the data block in the target virtual disk at each level in the radix tree of the target virtual disk; wherein the index value is used to indicate the position of the data block number at each level in the radix tree;

[0027] According to the index value, search the radix tree of the target virtual disk from top to bottom for the node corresponding to the index value of each layer;

[0028] If it is determined that the node corresponding to the index value in the hierarchy does not exist, a node corresponding to the index value is created in the hierarchy and linked to the node in the previous level until a leaf node is constructed; wherein the leaf node points to the data block number of the data block in the target virtual disk.

[0029] The beneficial effect of this implementation method is that the offset can be quickly inserted into the radix tree through the hierarchical index insertion method, thereby improving the efficiency of fragmentation.

[0030] In a possible implementation, when a data block in the target virtual disk is released, the data block number corresponding to the released data block on the target radix tree is deleted.

[0031] The beneficial effects of this implementation method are as follows: when a data block is released, the offset of the data block on the radix tree is deleted, so that the offsets saved on the radix tree are all allocated valid data blocks. In this way, when defragmenting, there is no need to determine whether the data block corresponding to the offset on the radix tree is valid, which can effectively reduce the complexity of defragmentation and save defragmentation time.

[0032] In a possible implementation manner, the target radix tree is independently stored in a target data block of the target virtual disk.

[0033] The beneficial effect of this implementation is that by deploying the radix tree in a separate data block, it is possible to prevent data in the target virtual disk from being damaged when it is frequently modified, thereby improving the data security in the radix tree.

[0034] In a possible implementation, the preset defragmentation trigger condition includes:

[0035] The fragmentation rate reaches the preset threshold;

[0036] The fragmentation rate is determined based on the total number of fragments and the total number of data blocks in the original virtual disk;

[0037] or,

[0038] The preset defragmentation time has been reached.

[0039] The beneficial effects of this implementation method are as follows: by setting a suitable defragmentation time interval and triggering defragmentation at a regular interval, the fragmentation rate can be effectively reduced, thereby saving storage space, and defragmentation will not take up too much time, thereby reducing the computing power resources occupied by defragmentation; and by monitoring the fragmentation rate, it can be determined in a timely manner whether defragmentation is to be performed, thereby effectively reducing the performance degradation caused by file fragmentation and improving the overall performance of the virtual machine.

[0040] In a second aspect, an embodiment of the present application further provides a computing device, the computing device comprising: a processor, the processor being connected to a memory;

[0041] Memory is used to store computer executable instructions;

[0042] The processor executes the computer-executable instructions stored in the memory to enable the computing device to implement the virtual disk defragmentation method of any one of the first aspects.

[0043] In a third aspect, an embodiment of the present application provides a computer program product, including a computer program / instructions, which, when executed by a processor, implements the steps of any one of the methods provided in the first aspect.

[0044] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, on which a computer program / instruction is stored. When the computer program / instruction is executed by a processor, the steps of any one of the methods provided in the first aspect are implemented.

[0045] Among them, the technical effects brought about by any implementation method in the second to fourth aspects can refer to the technical effects brought about by the first aspect, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0046] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the related technologies, the following is a brief introduction to the drawings required for use in the embodiments or the related technical descriptions. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.

[0047] Figure 1 A schematic diagram of the structure of a qcow2 file provided in an embodiment of the present application;

[0048] Figure 2 A schematic diagram of the relationship between an L1 table, an L2 table and a data block provided in an embodiment of the present application;

[0049] Figure 3 A flowchart of a virtual disk defragmentation method provided in an embodiment of the present application;

[0050] Figure 4 A schematic diagram of the structure of a radix tree of an original virtual disk provided in an embodiment of the present application;

[0051] Figure 5 A schematic diagram of the structure of a radix tree of a target virtual disk provided in an embodiment of the present application;

[0052] Figure 6 A schematic diagram of the structure of a virtual disk defragmentation device provided in an embodiment of the present application;

[0053] Figure 7 A structural diagram of a computing device is provided for an embodiment of the present application. DETAILED DESCRIPTION

[0054] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments made by ordinary technicians in this field under the enlightenment of the embodiments belong to the scope of protection of the present application.

[0055] The terms "first", "second", "third", "fourth", etc. (if any) in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0056] First, the terms involved in the embodiments of the present application are explained:

[0057] Virtual machine (VM): is a type of virtual computer system with complete functions that runs in an isolated environment. A virtual machine simulates a complete set of computer hardware through software, including the central processing unit (CPU), memory, storage devices, and network devices. The virtual machine has an independent operating system, and users can operate the virtual machine like a physical machine.

[0058] Disk: refers to a storage device that uses magnetic recording technology to store data. Disk is the main storage medium of computers. It can store a large amount of binary data and keep the data intact after a power outage. The disk used in early computers was a floppy disk (floppy disk for short), and the commonly used disk today is a hard disk (hard disk for short).

[0059] qcow2 (qemu copy-on-write 2) image: qcow2 image format is one of the disk image formats supported by the virtual operating system emulator (quick emulator, QEMU), which supports advanced features such as snapshots and encryption. The qcow2 file is a variable-size file that occupies very little actual space when initially created, and its size gradually grows as data is written. It uses copy-on-write technology. When a data block needs to be modified, it does not modify the original data directly, but first copies the original data and then modifies it. This allows multiple qcow2 files to share the same part of the same base image, thereby saving storage space. qcow2 is a very flexible and powerful virtual hard disk file format.

[0060] Radix tree: also known as base tree or compressed prefix tree, is a data structure used to store and retrieve strings. In a radix tree, nodes with the same prefix are merged into a common node. By compressing nodes with the same prefix, storage space is reduced and retrieval efficiency is improved.

[0061] A qcow2 file is usually composed of multiple fixed-size units, which are called clusters, also known as data blocks, data units, etc. The default size of each data block is generally 64K, and the maximum size is 2M. For example, Figure 1 A schematic diagram of the structure of a qcow2 file provided in an embodiment of the present application. Figure 1 As shown, the first data block (cluster) of the qcow2 file in the virtual disk stores metadata in the Header structure, such as the qcow2 file header, file version number, and file size, which are used to describe the relevant information of the file; the second data block stores the L1 table, and the third data block stores the L2 table. Subsequent data blocks increase as the stored data increases.

[0062] In a virtualized environment, the operating system (guest operating system) in the virtual machine can only see the virtual disk, but the actual read and write operations are performed on the data blocks (guest cluster) on the virtual disk. Virtual disks are usually managed in clusters (which can be translated as: clusters, data blocks, data units, etc.). The read and write operations of the virtual disk by the virtual machine operating system are actually reading and writing data blocks on the virtual disk. The mapping relationship from the virtual disk (guest cluster) to the physical disk (host cluster) is generally managed through a secondary table, called the L1 table and the L2 table. For example, Figure 1 The L1 table and L2 table in the qcow2 file format. The L1 table is a first-level index table in the qcow2 file format. It is variable in size, continuous, and can occupy multiple data block clusters. Each entry in the L1 table records the location information of the corresponding logical block in the L2 table to quickly locate and access data; while the L2 table is a second-level index table in the qcow2 file format. Each entry in the L2 table records the location information of the corresponding physical block in the actual storage medium (such as a physical disk).

[0063] For example, Figure 2 A schematic diagram of the relationship between an L1 table, an L2 table and a data block provided in an embodiment of the present application. Figure 2As shown, each entry in the L1 table corresponds to an L2 table, and the entry in the L1 table records the location information of the L2 table. Each entry in the L2 table corresponds to a data block, and the entry in the L2 table records the location information of the data block corresponding to the actual storage medium. Based on this, the mapping relationship between the virtual disk and the physical disk can be determined according to the L1 table and the L2 table.

[0064] The above-mentioned location information is generally represented by an offset value (translated as: offset). The offset indicates the number of bytes or blocks that need to be skipped from the starting position of the data storage to reach the location of the data block cluster. The offset can be used to accurately locate and access a specific data block.

[0065] Virtual disk files in qcow2 format support dynamic growth. During the operation of the virtual machine, the space occupied by the virtual disk on the host machine will become larger and larger. Even if many useless files are deleted in the client, these spaces are not reclaimed by the host machine. After this cycle, the continuous positions in the virtual disk may become discontinuous in the distribution of the qcow2 file, that is, fragmentation will occur. When the fragmented files are read by the system, the system needs to address and read data at different disk locations, which increases the number of head movements and seek time, resulting in a decrease in the data reading speed, which will affect the running of programs in the virtual machine and the speed of opening files, causing the performance of the virtual machine to decrease. So far, how to quickly organize virtual disk fragments to reduce the performance degradation of the virtual machine has become a problem to be solved.

[0066] In a related technology, a data structure composed of data block clusters in a qcow2 file to be defragmented (original virtual disk) is regarded as a one-dimensional array. When defragmenting, the one-dimensional array is traversed from the beginning to search for data blocks whose data block type is allocated, until the next data block type is unallocated data block, the traversal ends, the number of consecutive data blocks whose type is allocated in this round of traversal is recorded, and a coroutine is started for copying; then, the traversal continues from the position where the previous traversal ends to search for data blocks whose data block type is allocated, until the next data block type is unallocated data block, the number of consecutive data blocks whose type is allocated in this round of traversal is recorded, and a coroutine is started for copying; this is repeated until the end of the one-dimensional array is traversed, and the data blocks are completely migrated to the new qcow2 file (target virtual disk) to complete the defragmentation. In this method, it is necessary to traverse the one-dimensional array. When the amount of data in the one-dimensional array is relatively large, the traversal will take a long time, resulting in low efficiency of defragmentation. Moreover, this method only queries the data type in the array when defragmenting, which requires relatively more additional computing power resources and leads to relatively large performance loss. Especially when the array is very large or the query is very frequent, the performance impact is more obvious.

[0067] In another related technology, the L1 table in the qcow2 file (original virtual disk) to be organized is traversed, and the corresponding L2 table is found according to the non-zero value in the L1 table, and then a mapping table of non-zero values ​​between the L1 table and the L2 table is established according to the non-zero value in the L2 table, and then the offset value (offset) of the data block in the mapping table is sorted from small to large according to the location size of the virtual disk, and then the data block corresponding to the offset value is copied to the new qcow2 file (target virtual disk) in sequence according to the sorting. In this method, after traversing the L1 table and the L2 table to obtain the data blocks to be copied, it is necessary to sort them according to the offset to determine the copy order. The algorithm complexity is relatively high, and the complex algorithm also introduces additional time consumption; moreover, this method also performs data type query when defragmenting, which will also consume additional computing resources and cause relatively more performance loss.

[0068] In order to solve the above problems, an embodiment of the present application provides a method for defragmenting a virtual disk. The solution introduces a radix tree in the original virtual disk to be defragmented. The radix tree stores the offsets of the allocated valid data blocks in order. On this basis, when defragmenting, it is only necessary to traverse the radix tree once to determine the data blocks that need to be migrated. Since the offsets of the allocated data blocks are stored in order on the radix tree, there is no need to sort them after traversal. This solution can reduce the complexity of the algorithm and improve the overall efficiency of defragmentation. In addition, compared with arrays and linear lists, radix trees also allow fast positioning operations, and are more efficient in finding and accessing the offsets of data blocks, thereby shortening the defragmentation time and improving the defragmentation efficiency.

[0069] The execution subject of the method provided in the embodiment of the present application may be a device for defragmenting a virtual disk, for example, a computing device, and illustratively, the computing device may be a server. Specifically, the execution subject is a processor on the computing device.

[0070] The following is a detailed description of the virtual disk defragmentation method with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The following will describe the embodiments of the present application in conjunction with the accompanying drawings.

[0071] Figure 3 The present invention provides a flow chart of a virtual disk defragmentation method. Figure 3 As shown, the virtual disk defragmentation method provided in the embodiment of the present application may include:

[0072] S301 : When the original virtual disk meets a preset defragmentation triggering condition, traverse the original radix tree to determine the first address of the data block to be migrated and the number of the data blocks to be migrated.

[0073] Among them, the original virtual disk is the virtual disk to be defragmented; the original radix tree is the radix tree stored in the original virtual disk; the original radix tree is used to sequentially store the data block numbers of each data block to be migrated in the original virtual disk. The data block number is used to indicate the offset of the data block in the virtual disk, and the offset represents the storage location of the data block. Optionally, the data block number can be represented by the number of bytes or blocks that need to be skipped from the starting position of the data storage to the location of the data block. The data block number of the data block to be migrated can be used to know the offset of the data block to be migrated in the original virtual disk, so that a specific data block in the original virtual disk can be accurately located and accessed.

[0074] Optionally, regarding the original radix tree in the original virtual disk, the computing device can be set according to actual needs. For example, according to the data size of the original virtual disk, according to the number of bits of the offset of the data block in the original virtual disk, and other information, a suitable tree height can be set to determine the radix n of the radix tree, so as to construct a suitable radix tree for storing the data block numbers of each data block to be migrated in the original virtual disk. For example, if the offset of each data block in the original virtual disk generally does not exceed 2^32, the number of bits of the data block number of the data block in the original virtual disk can be set to 32. In addition, in order to save storage space and search efficiency, the tree height can be selected to be 4. According to the initialization relationship between the tree height and the radix n: tree height h = number of bits of the data block number / radix n, the radix n can be determined to be 8, and each internal node in the radix tree has a maximum of 2^n child nodes. Based on this, it can be determined that when the tree height is 4 and the number of bits of the data block number is 32, each node of the constructed radix tree has a maximum of 2^8 child nodes.

[0075] It should be noted that the data blocks to be migrated in the embodiment of the present application are valid data blocks that are allocated or used. Each data block to be migrated has a different position in the original virtual disk, and its corresponding offset is also different, and the corresponding data block number is also different. The larger the offset, the larger the data block number, indicating that it is farther from the starting position of the data storage in the original virtual disk. According to the distance, the allocated data blocks can be sorted so that the data block numbers of the allocated data blocks are stored in the radix tree in order.

[0076] For example, Figure 4 A schematic diagram of the structure of a radix tree of an original virtual disk provided in an embodiment of the present application. Figure 4As shown, the height of the radix tree is 4. Corresponding to the hierarchical structure, the radix tree has 4 levels, namely the first level, the second level, the third level and the fourth level. Starting from the root node of the radix tree, each node can have 2^8 child nodes. The nodes of the fourth level are leaf nodes of the radix tree. Each leaf node points to a corresponding data block, and each data block has a corresponding data block number for indicating the offset. The data block numbers of the allocated data blocks in the original virtual disk are saved in the radix tree of the original virtual disk in order of the size of the data block numbers. As shown in the figure, the data blocks with data block numbers of 0x00000000, 0x000000001, 0x000000fe, 0x000000ff, 0xfffffe00, and 0xfffffefe are allocated data blocks, and their corresponding data block numbers are stored in sequence on the original radix tree of the original virtual disk, while data blocks a, b, c, and d are unallocated data blocks. Their existence makes the data blocks with data block numbers of 0x00000000, 0x000000001, 0x000000fe, 0x000000ff, 0xfffffe00, and 0xfffffefe not continuous, resulting in file fragmentation.

[0077] In an embodiment of the present application, when the original virtual disk to be defragmented meets the preset defragmentation triggering condition, the computing device will execute the defragmentation process to defragment the original virtual disk to be defragmented, so as to reduce the fragmentation rate of the original virtual disk, thereby improving the read and write performance of the virtual disk. Exemplarily, the computing device can first traverse the radix tree in the original virtual disk to be defragmented, and determine the first address of the data block to be migrated and the number of the data blocks to be migrated in the original virtual disk by traversing, so as to prepare for subsequent data migration.

[0078] In a possible implementation, traversing the original radix tree to determine the first address of the data block to be migrated and the number of the data blocks to be migrated may include:

[0079] S1. Based on the preset algorithm, starting from the root node of the original radix tree, traverse the child nodes of each node in turn.

[0080] S2. When a preset termination condition is met, determine that the data blocks corresponding to the data block numbers pointed to by all leaf nodes whose values ​​are not empty are the data blocks to be migrated, and determine the number of data blocks with consecutive data block numbers to be migrated.

[0081] Among them, the preset termination condition is that the value of the leaf node on the original radix tree is empty or the original radix tree is traversed.

[0082] In a possible implementation, the preset algorithm is a depth-first algorithm.

[0083] Exemplarily, a depth-first search (DFS) is an algorithm for traversing or searching a tree or graph data structure. In the depth-first algorithm, starting from the starting node, traverse downward along a path until a leaf node is reached or it is impossible to continue traversing downward, then backtrack to the previous node and continue exploring other paths. In an embodiment of the present application, on the radix tree of the original virtual disk, each leaf node whose value is not empty points to a data block number, and each data block number indicates an offset, and according to the offset, the corresponding data block can be located and found. Therefore, the computing device can use a depth-first algorithm, starting from the root node of the radix tree of the original virtual disk to be sorted, and traverse the child nodes of each node in turn until the value of the leaf node on the original radix tree is empty or the original radix tree is traversed, and the data blocks corresponding to the data block numbers pointed to by all the leaf nodes whose values ​​are not empty are determined as the data blocks to be migrated in this round of traversal. In the next round of traversal, the traversal continues from the position after the previous round of traversal is terminated until the value of the next leaf node is empty or the radix tree is traversed, and the process is repeated until the radix tree in the original virtual disk is traversed. Among them, when the value of the leaf node is empty, it indicates that the data block corresponding to the data block number pointed to by the leaf node is not used, that is, there is a fragmentation point. Therefore, the data blocks before the leaf node value is not empty are continuous. From then on, after determining the data blocks to be migrated, the number of data blocks with continuous data block numbers to be migrated can also be determined.

[0084] To traverse Figure 4Taking the original radix tree shown as an example, when traversing, starting from the root node root, traverse the child nodes of each node in turn. After traversing to the leaf node 01 of the fourth layer, there is a leaf node with an empty value. At this time, it can be determined that after the first round of traversal, the traversed data block numbers 0x00000000 and 0x000000001 are the data blocks to be migrated in this round of traversal, and the number of data blocks to be migrated in this round of traversal is 2; then, continue to traverse from the leaf node with an empty value until traversing to a leaf node with an empty value again. It can be determined that after the second round of traversal, the traversed data block numbers are 0x00000000 and 0x000000001. The two data blocks with data block numbers of 0x000000fe and 0x000000ff are the data blocks to be migrated in this round of traversal, and the number of data blocks to be migrated in this round of traversal is also 2; by analogy, it can be determined that after the third round of traversal, the data block with data block number 0xfffffe00 is the data block to be migrated in this round of traversal, and the number of data blocks to be migrated in the third round of traversal is 1. After the fourth round of traversal, the data block with data block number 0xfffffefe is the data block to be migrated in this round of traversal, and the number of data blocks to be migrated in the fourth round of traversal is 1. Among them, each different data block has its corresponding first address. After determining the data block to be migrated, the first address of the data block can also be determined.

[0085] Since the radix tree in the original virtual disk stores the data block numbers of the data blocks to be migrated in the original virtual disk in order, when the radix tree of the original virtual disk is traversed by the depth-first algorithm, the data blocks to be migrated are determined in order and do not need to be re-sorted. The complexity of this algorithm is lower than that of the algorithm that requires sorting, and the time required is relatively shorter. Based on the radix tree in the original virtual disk, the data blocks that need to be migrated in the original virtual disk can be quickly determined, thereby improving the efficiency of defragmentation.

[0086] It should be noted that the embodiments of the present application do not limit the specific content of the preset defragmentation trigger condition. For example, the preset defragmentation trigger condition can be set to perform defragmentation regularly, or to perform defragmentation when the fragmentation rate reaches a certain level, and so on.

[0087] In a possible implementation, the preset defragmentation trigger condition includes: the fragmentation rate reaches a preset threshold; wherein the fragmentation rate is determined based on the total number of fragments and the total number of data blocks in the original virtual disk; or, a preset defragmentation time is reached.

[0088] If the preset defragmentation trigger condition is set as the fragmentation rate reaching a preset threshold, the defragmentation method provided in the embodiment of the present application may also include: obtaining the fragmentation rate of the original virtual disk to be defragmented, and if it is determined that the fragmentation rate reaches the preset threshold, determining that the original virtual disk to be defragmented meets the preset defragmentation trigger condition. Among them, the fragmentation rate can be determined by the total number of fragments and the total number of data blocks in the original virtual disk. Optionally, there may be a flag bit at the fragment position to mark that the data block has been released, so as to facilitate the acquisition of the fragmentation rate. Specifically, a special fragmentation analysis tool can be used to directly obtain the fragmentation rate, or the total number of fragments and the total number of data blocks can be obtained by traversing the radix tree in the original virtual disk, and then the fragmentation rate is calculated, etc. The fragmentation rate of the original virtual disk can be obtained in a variety of different ways, and the embodiment of the present application does not limit this. After obtaining the fragmentation rate of the original virtual disk, the computing device further determines whether the fragmentation rate exceeds the preset threshold. If it exceeds the preset threshold, it is determined that the preset defragmentation trigger condition is met and defragmentation is required. By monitoring the fragmentation rate, you can determine in time whether to defragment, thereby effectively improving the overall performance of the virtual machine.

[0089] If the preset defragmentation trigger condition is set to reach the preset defragmentation time, the defragmentation method provided in the embodiment of the present application may also include: monitoring the defragmentation time of the original virtual disk to be defragmented, and when the preset defragmentation time is reached, determining that the original virtual disk to be defragmented meets the preset defragmentation trigger condition. By setting a suitable defragmentation time interval and triggering defragmentation regularly, the fragmentation rate can be effectively reduced, thereby saving storage space, and it will not take too much time when performing defragmentation, thereby reducing the occupation of computing resources due to defragmentation.

[0090] Optionally, after it is determined that the original virtual disk to be defragmented meets a preset defragmentation trigger condition, a qemu-img convert command may be used to start a defragmentation process and perform defragmentation steps.

[0091] S302 : Based on the first addresses of the data blocks to be migrated and the number of the data blocks to be migrated, sequentially copy the data blocks to be migrated to continuous data blocks of the target virtual disk.

[0092] The target virtual disk is a newly created virtual disk. Therefore, in a possible implementation, if there is no pre-created virtual disk, a target virtual disk may be created first. If there is no pre-created virtual disk, when it is determined that defragmentation is required, in addition to determining the data blocks to be migrated in the original virtual disk, a new target virtual disk needs to be created to store the migrated data blocks in the original virtual disk.

[0093] It should be noted that there is no order between the step of creating a target virtual disk and the step of traversing the original radix tree to determine the first address of the data block to be migrated and the number of data blocks to be migrated. They can be executed sequentially or simultaneously, and the embodiments of the present application do not impose any restrictions on this.

[0094] Exemplarily, the computing device copies the data blocks to be migrated in the original virtual disk to the continuous data blocks in the target virtual disk in sequence, so that the discontinuous data blocks in the original virtual disk can become continuous in the target virtual disk, thereby reducing the fragmentation rate and achieving defragmentation.

[0095] In a possible implementation, based on the first address of the data block to be migrated and the number of the data blocks to be migrated, sequentially copying the data blocks to be migrated to the continuous data blocks of the target virtual disk may include:

[0096] S10: configuring a copy coroutine based on the first address of each data block to be migrated and the number of data blocks to be migrated.

[0097] S20, start the copy coroutine, and read the data blocks to be migrated in the original virtual disk in sequence based on the data block numbers sequentially stored in the original radix tree, and write the data blocks to be migrated into continuous data blocks in the target virtual disk in sequence.

[0098] Exemplarily, there are generally multiple data blocks to be migrated in the original virtual disk. In order to improve the copying efficiency, the copying can be performed through the copying coroutine. Specifically, the computing device can configure the copying coroutine according to the first address of the data block to be migrated in the original virtual disk and the number of data blocks to be migrated. After the copying coroutine is configured, the copying coroutine is started, and the copying coroutine is controlled to read the data blocks to be migrated in the original virtual disk in sequence according to the order of the data block numbers stored in the original radix tree of the original virtual disk, and locate the target position of the data blocks to be migrated in the target virtual disk, so as to write the read data blocks to be migrated into the data blocks with continuous positions in the target virtual disk in sequence. In this way, the fragmented data blocks in the original virtual disk become continuous in the organized target virtual disk, thereby reducing the fragmentation rate and improving the read and write performance of the virtual disk.

[0099] Optionally, after the data block indicated by the data block number stored in the radix tree in the original virtual disk is migrated to the target virtual disk, the target virtual disk can also replace the original virtual disk, so that the original virtual disk does not occupy the storage space of the physical disk, thereby saving the physical disk storage space.

[0100] On the basis of the above embodiment, after the data blocks to be migrated in the original virtual disk are copied to the data blocks in the target virtual disk, the data blocks in the target virtual disk have new offsets in the target virtual disk. When the data in the subsequent target virtual disk is continuously modified, deleted, written, etc. to meet the defragmentation triggering conditions, the target virtual disk will also be fragmented, and defragmentation can also be performed in the same way as above. Therefore, in a possible implementation, the virtual disk defragmentation method provided in the embodiment of the present application may also include:

[0101] S100: Setting an initialized radix tree in the target virtual disk, wherein the initialized radix tree is determined based on a preset tree height and the number of bits of the data block number; the preset tree height represents the number of levels of the radix tree.

[0102] S200 , inserting the data block number of each data block in the target virtual disk into the initialized radix tree to obtain a target radix tree.

[0103] Exemplarily, the initialized radix tree is a radix tree whose hierarchical structure is determined but the data block number is not yet stored. The computing device can construct the initialized radix tree in the target virtual disk, and then insert the data block number of the data block in the target virtual disk into the radix tree of the target virtual disk.

[0104] Optionally, the step of setting an initialized radix tree in the target virtual disk can be executed when creating the target virtual disk, or it can be executed after the data blocks to be migrated are copied sequentially to the continuous data blocks of the target virtual disk and before the data block numbers of the data blocks in the target virtual disk are inserted into the radix tree. This application does not impose any restrictions on this.

[0105] In a possible implementation, setting an initialized radix tree in the target virtual disk may include:

[0106] S1001, obtaining a preset tree height and a number of digits of a data block number, and determining the number of child nodes of each node in the radix tree according to the preset tree height and the number of digits of the data block number;

[0107] S1002, creating an initialization structure of a radix tree according to a preset tree height and the number of child nodes of each node;

[0108] S1003: Create a target virtual disk, where the target virtual disk includes an initialization structure of a radix tree.

[0109] In an implementable manner, a target virtual disk may be created based on a file creation command line, and then an initialization structure of a radix tree is constructed in the target virtual disk to obtain a target virtual disk including a radix tree.

[0110] Exemplarily, the hierarchical structure of the radix tree in the target virtual disk may be the same as or different from the hierarchical structure of the radix tree in the original virtual disk, and the embodiments of the present application do not limit this. When the hierarchical structures of the two are the same, the computing device can directly construct an initialized radix tree similar to the radix tree in the original virtual disk in the target virtual disk; when the hierarchical structures of the two are different, the computing device needs to first obtain the preset tree height and the number of bits of the data block number of the data block in the target virtual disk, and then divide the number of bits of the data block number by the preset tree height to obtain the radix n of the radix tree, and then, according to the fact that each internal node of the radix tree has a maximum of 2^n child nodes, the number of child nodes of each node in the radix tree can be determined; then, according to the preset tree height and the number of child nodes of each node, the initialization structure of the radix tree is constructed in the target virtual disk created based on the file creation command line, and the target virtual disk containing the radix tree can be obtained. For example, the target virtual disk can be created by running the qemu-imgcreate qcow2 command line.

[0111] Among them, the preset tree height can be set by the user. For example, in order to take into account both saving storage space and search efficiency, the tree height can be selected as 4. If the number of bits of the data block number is 32, then according to the tree height h = the number of bits of the data block number / radix n, the radix n can be determined to be 8. Each internal node in the radix tree has a maximum of 2^n child nodes. Based on this, it can be determined that when the tree height is 4 and the number of bits of the data block number is 32, each node of the constructed radix tree has a maximum of 2^8 child nodes. Of course, there can be other settings, and the embodiments of the present application do not limit this.

[0112] Optionally, in order to make the radix tree persistent, the target radix tree of the target virtual disk can be set to be stored independently in the target data block of the target virtual disk. That is, the data block used to store the target radix tree is not used to store other data. By storing the radix tree in a separate data block, the radix tree can be prevented from being damaged when the data in the target virtual disk is frequently modified, and the radix tree can be prevented from being tampered with, thereby improving the data security in the radix tree.

[0113] Further, optionally, the target data block that independently stores the target radix tree of the target virtual disk can be a data block in the target virtual disk whose data block number is less than a preset value. In other words, the target radix tree is placed in a relatively front data block, so that during defragmentation, the data block where the radix tree is located can be quickly located, thereby quickly traversing the radix tree, thereby improving the efficiency of defragmentation. For example, the second cluster (data block) in the target virtual disk can be allocated to store the structure of the radix tree. When the target virtual disk in qcow2 format is first created on the host machine, the second cluster is reserved as a persistent radix tree structure space, and then the radix tree is constructed in the data block when needed.

[0114] In a possible implementation, inserting the data block number of each data block in the target virtual disk into the initialized radix tree may include:

[0115] S2001. Determine the data block number of each data block in the target virtual disk, and determine the index value corresponding to the data block number of the data block in the target virtual disk at each level in the radix tree of the target virtual disk; wherein the index value is used to indicate the position of the data block number at each level in the radix tree.

[0116] S2002. Search the radix tree of the target virtual disk from top to bottom for a node corresponding to the index value of each layer according to the index value.

[0117] S2003. If it is determined that the node corresponding to the index value in the hierarchy does not exist, a node corresponding to the index value is created in the hierarchy and linked to the node in the upper layer until a leaf node is constructed; wherein the leaf node points to the data block number of the data block in the target virtual disk.

[0118] For example, the data block number can be a multi-digit coded identifier. To insert it into the radix tree, it is necessary to determine the index value corresponding to the data block number at each level in the radix tree. In most programming languages ​​and data structures, the index value starts from zero, and the data block number usually starts counting from 1. Therefore, the corresponding index value can be obtained by subtracting 1 from the data block number. If the data block number starts counting from 0, no conversion is required. The data block number itself is the index value, and then the index value of the data block number at each level of the radix tree can be determined according to the hierarchical structure of the radix tree.

[0119] For example, if the data block number of a data block is 0x00020301, and the data block number is counted from zero, if the radix tree has 4 layers, the index value of the data block number on the first layer of the radix tree can be determined as 00, the index value on the second layer can be determined as 02, the index value on the third layer can be determined as 03, and the index value on the fourth layer can be determined as 01. After determining the index value of the data block number on each layer of the radix tree, the computing device searches for the node corresponding to the index value of each layer from top to bottom on the radix tree of the target virtual disk according to the index value. First, it searches in the first layer to see if the node with an index value of 00 already exists. If not, a new node slot

[00] is created and linked to the root node. If it exists, the second layer is searched directly. In the second layer, it searches to see if the node with an index value of 02 already exists. If not, a new node slot

[02] is created and linked to the node slot

[00] of the first layer. If it exists, the node slot

[01] is searched directly. Then search the third layer; continue to search whether the node with index value 03 already exists in the third layer. If not, create a new node slot

[03] and link it to the node slot

[02] of the second layer. If it exists, directly search the fourth layer; search whether the node with index value 01 already exists in the fourth layer. If not, create a new node slot

[01] and link it to the node slot

[03] of the third layer. In this way, the leaf node slot

[01] of the fourth layer points to the data block number 0x00020301 of the data block in the target virtual disk.

[0120] In addition, in order to facilitate identification and indexing, the data block number and index value can also use different base digital representation methods. When using different base digital representation methods, the data block number needs to be converted first. For example, taking the data block number (offset value) of 0x000840FF as an example, its binary can be written as 8-bit clusters: 00000000-00001000-01000000-11111111, and the corresponding index values ​​(index values) from left to right are 0, 8, 3, and 255 respectively. Then, the process of inserting the data block with the data block number 0x000840FF into the radix tree can include:

[0121] a. Check whether the first-level slot[0] node of the radix tree already exists. If not, create a new node slot[0] and link it to the root node. If it exists, search the second level directly.

[0122] b. Check whether the node slot[8] on the second layer already exists. If not, create a new node slot[8] and link it to the node slot[0] on the first layer. If it exists, search the third layer directly.

[0123] c. Check whether the node in slot[3] on the third layer already exists. If not, create a new node slot[3] and link it to the node in slot[8] on the second layer. If it exists, search the node in the fourth layer directly.

[0124] d. Check whether the node in slot

[255] on the fourth layer already exists. If not, create a new node slot

[255] and link it to the node in slot [3] on the third layer. The nodes on the fourth layer generally do not exist and need to be newly created.

[0125] e. Let the slot

[255] node on the fourth layer point to the offset value 0x000840FF.

[0126] Since then, the data block number 0x000840FF has been inserted into the radix tree. Regardless of the above method, the data block number can be inserted into the radix tree.

[0127] For example, Figure 5 A schematic diagram of the structure of a radix tree of a target virtual disk provided in an embodiment of the present application. Figure 5 As shown, Figure 4 After the data blocks in the original virtual disk corresponding to the original radix tree are copied to the target virtual disk according to the method of the embodiment of the present application, the data block numbers on the radix tree in the target virtual disk are as follows: Figure 5 are all continuous, and the locations of their corresponding data blocks in the target virtual disk are also continuous. Figure 5 The data blocks a, b, c, and d in the target virtual disk will not occupy the storage resources of the target virtual disk. This can not only reduce the fragmentation rate, save storage space, but also improve the read and write performance of the virtual disk.

[0128] In one possible implementation, in order to ensure that the data blocks pointed to by the data block numbers stored in the radix tree of the target virtual disk are all allocated valid data blocks, when the data blocks in the target virtual disk are released, the data block numbers corresponding to the released data blocks on the target radix tree can be deleted.

[0129] Exemplarily, after defragmentation is completed, if the data on a data block in the target virtual disk is deleted, when the data block is released, the data block will be marked as no longer referenced. At this time, the data block number of the data block on the radix tree can be deleted, so that the data blocks pointed to by the data block numbers stored on the radix tree are all allocated valid data blocks, so that when the target virtual disk also meets the defragmentation trigger conditions, the method of the embodiment of the present application can be used for defragmentation. Among them, when deleting the data block number on the radix tree, you can search according to the index value of each layer, traverse the levels of the radix tree from top to bottom, find the leaf node of the fourth layer to be deleted, and delete it.

[0130] It can be understood that the time complexity of inserting, searching, and deleting in the radix tree is O(k) (k represents the length of the key), while the time complexity of inserting, searching, and deleting in the linear list is O(n) (n represents the length of the linear list). In the defragmentation method of the virtual disk file provided in the embodiment of the present application, since the radix tree in the original virtual disk sequentially stores the data block numbers of each data block allocated in the original virtual disk in the original virtual disk, when defragmenting, it is only necessary to traverse the radix tree once to determine the data blocks to be migrated and the number of data blocks to be migrated in the original virtual disk, and then migrate the data in the data blocks to the new target virtual disk, which greatly reduces the complexity of defragmentation, shortens the defragmentation time, and improves the defragmentation efficiency. In addition, the L2 table after defragmentation is basically concentrated in continuous data blocks, and the efficiency of caching the L2 table on the physical machine will also be higher, which can further improve the read and write performance of the target virtual disk.

[0131] The following is an embodiment of the device of the present application, which can be used to execute the embodiment of the method of the present application. For details not disclosed in the embodiment of the device of the present application, please refer to the embodiment of the method of the present application.

[0132] Figure 6 The present invention provides a schematic diagram of a virtual disk defragmentation device. Figure 6 As shown, the virtual disk defragmentation device 60 provided in the embodiment of the present application includes a processing unit 601 and a copy unit 602 .

[0133] The processing unit 601 is used to traverse the original radix tree to determine the first address of the data block to be migrated and the number of the data blocks to be migrated when the original virtual disk meets the preset defragmentation triggering condition. The original virtual disk is the virtual disk to be defragmented; the original radix tree is the radix tree stored in the original virtual disk; the original radix tree is used to store the data block numbers of each data block to be migrated in the original virtual disk in sequence.

[0134] The copy unit 602 is used to copy the data blocks to be migrated to the continuous data blocks of the target virtual disk in sequence based on the first addresses of the data blocks to be migrated and the number of the data blocks to be migrated; wherein the target virtual disk is a newly created virtual disk.

[0135] In one implementation, the processing unit 601 is specifically configured to:

[0136] Based on the preset algorithm, starting from the root node of the original cardinality tree, traverse the child nodes of each node in turn;

[0137] When a preset termination condition is met, determine that the data blocks corresponding to the data block numbers pointed to by all leaf nodes whose values ​​are not empty are the data blocks to be migrated, and determine the number of data blocks to be migrated with consecutive data block numbers;

[0138] Among them, the preset termination condition is that the value of the leaf node on the original radix tree is empty or the original radix tree is traversed.

[0139] In one implementation, the preset algorithm is a depth-first algorithm.

[0140] In one implementation, the copy unit 602 is specifically configured to:

[0141] Configure the copy coroutine based on the first address of each data block to be migrated and the number of data blocks to be migrated;

[0142] Start the copy coroutine, and read the data blocks to be migrated in the original virtual disk in sequence based on the data block numbers stored in the original radix tree, and write the data blocks to be migrated into the continuous data blocks in the target virtual disk in sequence.

[0143] In one implementation, the copy unit 602 is further specifically configured to:

[0144] An initialized radix tree is set in the target virtual disk; wherein the initialized radix tree is determined based on a preset tree height and the number of bits of the data block number; the preset tree height represents the number of levels of the radix tree;

[0145] The data block number of each data block in the target virtual disk is inserted into the initialized radix tree to obtain the target radix tree.

[0146] In one implementation, the copy unit 602 is further specifically configured to:

[0147] Determine the data block number of each data block in the target virtual disk, and determine the index value corresponding to the data block number of the data block in the target virtual disk at each level in the radix tree of the target virtual disk; wherein the index value is used to indicate the position of the data block number at each level in the radix tree;

[0148] According to the index value, search the radix tree of the target virtual disk from top to bottom for the node corresponding to the index value of each layer;

[0149] If it is determined that the node corresponding to the index value in the hierarchy does not exist, a node corresponding to the index value is created in the hierarchy and linked to the node in the previous level until a leaf node is constructed; wherein the leaf node points to the data block number of the data block in the target virtual disk.

[0150] In one implementation, the copy unit 602 is further specifically configured to:

[0151] When a data block in the target virtual disk is released, the data block number corresponding to the released data block on the target radix tree is deleted.

[0152] In one implementation, the target radix tree is independently stored in a target data block of the target virtual disk.

[0153] In one implementation, the preset defragmentation triggering conditions include:

[0154] The fragmentation rate reaches the preset threshold;

[0155] The fragmentation rate is determined based on the total number of fragments and the total number of data blocks in the original virtual disk;

[0156] Or, the preset defragmentation time is reached.

[0157] The device provided in this embodiment can be used to execute the method of the above embodiment. Its implementation principle and technical effect are similar and will not be described in detail here.

[0158] It should be noted that it should be understood that the division of the various modules of the above device is only a division of logical functions. In actual implementation, they can be fully or partially integrated into one physical entity, or they can be physically separated. And these modules can all be implemented in the form of software called by processing elements; they can also be all implemented in the form of hardware; some modules can also be implemented in the form of software called by processing elements, and some modules can be implemented in the form of hardware. In addition, it can also be stored in the memory of the above device in the form of program code, and the functions of the above data processing modules can be called and executed by a processing element of the above device. The implementation of other modules is similar. In addition, all or part of these modules can be integrated together, or they can be implemented independently. The processing element here can be an integrated circuit with signal processing capabilities. In the implementation process, each step of the above method or each module above can be completed by an integrated logic circuit of hardware in the processor element or instructions in the form of software.

[0159] Figure 7 A schematic diagram of the structure of a computing device is provided for an embodiment of the present application. Figure 7As shown, the computing device 70 includes a processor 701 , and the processor 701 is connected to a memory 702 .

[0160] The memory 702 is used to store computer-executable instructions. The memory 702 may include a high-speed RAM memory, and may also include a non-volatile memory (non-volatile memory), such as at least one disk memory.

[0161] The processor 701 is used to execute the computer-executable instructions stored in the memory 702 to implement the network configuration method described in the aforementioned method embodiment. The processor 701 may be a central processing unit (CPU), or an application specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of the present application.

[0162] The computing device 70 may further include a communication interface 703, so as to communicate and interact with an external device through the communication interface 703. The external device may be, for example, a server or other computing devices.

[0163] In specific implementation, if the communication interface 703, the memory 702 and the processor 701 are implemented independently, the communication interface 703, the memory 702 and the processor 701 can be connected to each other through a bus and communicate with each other. The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus. The bus can be divided into an address bus, a data bus, a control bus, etc., but it does not mean that there is only one bus or one type of bus.

[0164] Optionally, in a specific implementation, if the communication interface 703, the memory 702 and the processor 701 are integrated on a chip, the communication interface 703, the memory 702 and the processor 701 can communicate through an internal interface.

[0165] The computing device provided in this embodiment can execute the technical solution in the above method embodiment, and its beneficial effects are similar, which will not be described again here.

[0166] An embodiment of the present application also provides a computer-readable storage medium, in which computer-executable instructions are stored. When the computer-executable instructions are executed by a processor, they are used to implement the technical solution provided by any of the aforementioned method embodiments.

[0167] An embodiment of the present application also provides a computer program product, including a computer program, which is used to implement the technical solution provided by the aforementioned method embodiment when executed by a processor.

[0168] Those skilled in the art can understand that all or part of the steps of implementing the above-mentioned method embodiments can be completed by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, the steps of the above-mentioned method embodiments are executed; and the aforementioned storage medium includes: ROM, RAM, disk or optical disk and other media that can store program codes.

[0169] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the embodiments of the present application, rather than to limit them. Although the embodiments of the present application have been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein by equivalents. These modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present application.

Claims

1. A virtual disk defragmentation method, characterized in that: The method comprises: When the original virtual disk meets the preset defragmentation triggering condition, traverse the original radix tree to determine the first address of the data block to be migrated and the number of the data blocks to be migrated; Wherein, the original virtual disk is a virtual disk to be defragmented; The original radix tree is a radix tree stored in the original virtual disk; the original radix tree is used to sequentially store the data block numbers of each data block to be migrated in the original virtual disk; Based on the first address of the data block to be migrated and the number of the data blocks to be migrated, the data blocks to be migrated are copied sequentially to the continuous data blocks of the target virtual disk; wherein the target virtual disk is a newly created virtual disk; The original virtual disk is replaced with the target virtual disk.

2. The method according to claim 1, characterized in that Traverse the original radix tree to determine the first address of the data block to be migrated and the number of data blocks to be migrated, including: Based on a preset algorithm, starting from the root node of the original radix tree, traverse the child nodes of each node in turn; When a preset termination condition is met, determine that the data blocks corresponding to the data block numbers pointed to by all leaf nodes whose values ​​are not empty are the data blocks to be migrated, and determine the number of data blocks to be migrated with consecutive data block numbers; The preset termination condition is that the value of the leaf node on the original radix tree is empty or the original radix tree is completely traversed.

3. The method according to claim 2, characterized in that The preset algorithm is a depth-first algorithm.

4. The method according to any one of claims 1 to 3, characterized in that: The step of sequentially copying the data blocks to be migrated to continuous data blocks of the target virtual disk based on the first addresses of the data blocks to be migrated and the number of the data blocks to be migrated includes: Configuring a copy coroutine based on the first address of each of the data blocks to be migrated and the number of the data blocks to be migrated; The copy coroutine is started, and based on the data block numbers sequentially stored in the original radix tree, the data blocks to be migrated in the original virtual disk are read in sequence, and the data blocks to be migrated are written in sequence into continuous data blocks in the target virtual disk.

5. The method according to any one of claims 1 to 3, characterized in that: The method further comprises: An initialized radix tree is set in the target virtual disk; wherein the initialized radix tree is determined based on a preset tree height and the number of bits of a data block number; the preset tree height represents the number of levels of the radix tree; The data block number of each data block in the target virtual disk is inserted into the initialized radix tree to obtain a target radix tree.

6. The method according to claim 5, characterized in that Inserting the data block number of each data block in the target virtual disk into the initialized radix tree includes: Determine the data block number of each data block in the target virtual disk, and determine the index value corresponding to the data block number of the data block in the target virtual disk at each level in the radix tree of the target virtual disk; wherein the index value is used to indicate the position of the data block number at each level in the radix tree; According to the index value, searching the radix tree of the target virtual disk from top to bottom for a node corresponding to the index value of each layer; If it is determined that the node corresponding to the index value in the hierarchy does not exist, a node corresponding to the index value is created in the hierarchy and linked to the node in the previous level until a leaf node is constructed; wherein the leaf node points to the data block number of the data block in the target virtual disk.

7. The method according to claim 5, characterized in that The method further comprises: When a data block in the target virtual disk is released, the data block number corresponding to the released data block on the target radix tree is deleted.

8. The method according to claim 5, characterized in that The target radix tree is independently stored in the target data block of the target virtual disk.

9. The method according to any one of claims 1-3, 6-8, characterized in that: The preset defragmentation triggering conditions include: The fragmentation rate reaches the preset threshold; Wherein, the fragmentation rate is determined based on the total number of fragments and the total number of data blocks in the original virtual disk; or, The preset defragmentation time has been reached.

10. A computing device, characterized in that: The computing device includes a processor connected to a memory; The memory is used to store computer-executable instructions; The processor executes the computer-executable instructions stored in the memory to enable the computing device to implement the method according to any one of claims 1 to 9.

Citation Information

Patent Citations

  • Techniques to enhance database performance

    US20090254594A1