A method for online reclaiming the space of virtual machine SSD cloud hard disks
By creating a top image and executing fstrim in a small virtual machine, the method addresses the compatibility and performance issues of existing space reclamation methods, allowing efficient SSD space reclamation on existing virtual machines.
Patent Information
- Application Number
- CN202211721741.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-30
- Publication Date
- 2025-07-11
- Estimated Expiration
- 2042-12-30
AI Technical Summary
Existing methods for reclaiming space on SSDs in virtual machines require high version compatibility and user intervention, leading to performance degradation and are not suitable for existing virtual machines using virtio-blk devices.
A method involving creating a top image with a pointer to the reclaimable disk space, switching the virtual machine to this image, copying the read-only disk, executing fstrim in a small virtual machine, and merging the changes back to the original disk, all without user intervention.
Enables space reclamation on existing virtual machines without performance impact, maintaining user experience and compatibility with virtio-blk devices.
Smart Images

Figure CN116069501B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of virtual machine disk space recovery, and more specifically, to a method for online recovery of the space of a virtual machine SSD cloud hard disk. Background Art
[0002] After a virtual machine runs for a long time or performs frequent write / delete operations, it will cause continuous consumption of the underlying SSD storage, but some of the space can actually be recovered; this has a certain impact on the oversubscription of the underlying SSD storage.
[0003] The reason why some of the underlying SSD storage is not recovered is that when a file is deleted inside the virtual machine, it is only deleted at the file system layer, and the underlying SSD storage device of the cloud platform does not know that the storage area corresponding to the file should also be deleted, and it needs to be notified by the upper layer issuing a discard command.
[0004] Existing solutions to the above impacts are as follows:
[0005] 1. Simulate a virtio-blk disk device for the virtual machine, and the fstrim command is executed in cooperation inside the virtual machine.
[0006] 2. Simulate a virtio-scsi disk device for the virtual machine, and the fstrim command is executed in cooperation inside the virtual machine.
[0007] They have the following deficiencies:
[0008] In Solution 1, qemu-4.0 or higher is required, and the kernel inside the virtual machine needs to be 5.0 or higher (Linux) or a new viostor driver needs to be installed (Windows).
[0009] In Solution 2, the requirements for the qemu version and the virtual machine kernel version are low (qemu-2.0 and the virtual machine kernel 3.2 or higher), but it will cause the drive letters inside the virtual machine to change, and virtio-scsi is generally used less. Most virtual machines still use virtio-blk devices, so there is a problem of switching from virtio-blk to virtio-scsi, which cannot be done online for the existing virtual machines using virtio-blk.
[0010] In both of these solutions, the fstrim command needs to be executed inside the virtual machine, so customer cooperation may be required. Moreover, when the virtual machine executes the fstrim command, the disk performance drops significantly, which has a greater impact on the customer experience. Summary of the Invention
[0011] The technical problem to be solved by the present invention is to provide a method for online recycling of virtual machine ssd cloud hard disk space, so as to reduce the waste of space in the cloud platform storage pool and enhance the storage oversubscription ability.
[0012] In order to achieve the above object, the present invention adopts the following technical solutions:
[0013] A method for online recycling of virtual machine ssd cloud hard disk space, comprising the following steps:
[0014] S1: Create a new top image for the virtual machine, and its backend file points to the disk of the space to be recycled;
[0015] S2: Online switch the virtual machine disk to the top image, and the disk of the space to be recycled becomes a read-only disk readonly_disk;
[0016] S3: Copy readonly_disk in the storage pool as readon_disk_copy, and then switch the backend file of the top image to the copied disk readon_disk_copy;
[0017] S4: Start a small virtual machine on the computing node, and the small virtual machine mounts readonly_disk; wherein, the computing node is the host machine where the virtual machine is located or other host machines that can access the readonly_disk image;
[0018] S5: Execute the fstrim command inside the small virtual machine for space recycling.
[0019] Preferably, it further comprises the following steps:
[0020] S6: After the space recycling is completed, destroy the small virtual machine.
[0021] Preferably, it further comprises the following steps:
[0022] S7: Point the top image back to readonly_disk, and then delete readonly_disk_copy.
[0023] Preferably, it further comprises the following steps:
[0024] S8: Merge the content of the top image into readonly_disk.
[0025] Preferably, in S4, the small virtual machine mounts readonly_disk in the virtio-scsi manner.
[0026] The advantages of the present invention over the prior art are:
[0027] 1. Space recycling can be performed on existing virtual machines;
[0028] 2. Due to the fast switching speed and no need for user cooperation, users will not perceive it;
[0029] 3. Disk performance of the virtual machines in use will not be affected during space recycling. Description of the Drawings
[0030] Figure 1 is the overall schematic diagram of the method of the present invention;
[0031] Figure 2 is the schematic diagram of the code for creating a new top image in the present invention;
[0032] Figure 3 is the first - part schematic diagram of the code for online changing the backend file in the present invention;
[0033] Figure 4 is the second - part schematic diagram of the code for online changing the backend file in the present invention;
[0034] Figure 5 is the schematic diagram of the code for creating a new virtual machine and mounting the original disk in the virtio - scsi manner in the present invention;
[0035] Figure 6 is the schematic diagram of the code for executing the fstrim command inside the new virtual machine to perform space recycling on the disk;
[0036] Figure 7 is the schematic diagram of the code for top - image merging;
[0037] Figure 8 is the schematic diagram of the code for backend - image merging;
[0038] Figure 9 is the first - part schematic diagram of the code for canceling the top image;
[0039] Figure 10 is the second - part schematic diagram of the code for canceling the top image. Detailed Embodiments
[0040] The following describes the detailed embodiments of the present invention with reference to the drawings.
[0041] As Figure 1 , the overall solution of the present invention is as follows:
[0042] First, we create a new top image for the virtual machine. The backend file of this image points to the disk of the space to be reclaimed. Then, we switch the virtual machine disk online to this top image. In this way, the newly written content will be written to this top image, and the original disk will become a read-only disk (referred to as readonly_disk later); the time for switching the disk is very short and users won't notice it.
[0043] After switching the disk, we make a copy of the readonly_disk that has become read-only in the storage pool, and then switch the backend file of the top image to the copied disk (referred to as readon_disk_copy later). Similarly, this switching process is also very short and users won't notice it.
[0044] Next, we can start a small virtual machine. This small virtual machine mounts the original readonly_disk in the virtio-scsi mode. After the small virtual machine starts successfully, we execute the fstrim command inside this small virtual machine to reclaim space; after the space reclamation is completed, we destroy this small virtual machine, point the top image back to this readonly_disk again, and then delete readon_disk_copy; finally, we merge the content of the top image into readonly_disk (the read-only attribute disappears after merging and it can be read and written normally at this time); thus, the space reclamation is completed.
[0045] Next, we list a simple embodiment and point out several key operations:
[0046] 1. Create a new top image, as shown in the code of Figure 2 .
[0047] 2. Change its backend file online:
[0048] When accessing data in the virtual machine image, generally an offset is provided based on a position (such as the file header), and then reading and writing are performed in the cluster where the data is actually stored according to this offset; the corresponding relationship between these offsets and clusters is saved in the metadata of the image. Therefore, we can change these metadata to make the offset of the image point to a different cluster; as shown in the code of Figure 3 and Figure 4 .
[0049] 3. Create a new virtual machine and mount the original disk in the virtio-scsi mode, as shown in the code of Figure 5 .
[0050] 4. Execute the fstrim command inside the new virtual machine to reclaim space from the disk, as shown in the code of Figure 6 .
[0051] 5. After swapping back to the original disk and merging with the top image content, the general process is as follows: As mentioned before, the mirror metadata stores the correspondence between data offsets and clusters. Then, those clusters that are not in the target mirror and have been modified in the source mirror can be written to the target mirror. One can choose to merge with the top mirror or merge with the backend mirror, as shown in Figure 7 and Figure 8 respectively.
[0052] 6. Cancel the backend file of the top mirror, as shown in Figure 9 and Figure 10 respectively.
[0053] As described above, the above are only the preferred specific embodiments of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art within the technical scope disclosed by the present invention, according to the technical solution and inventive concept of the present invention, makes equivalent substitutions or changes, and should be covered by the protection scope of the present invention.
Claims
1. A method for online recycling of virtual machine SSD cloud disk space, characterized in that, Including the following steps: S1: Create a new top image for the virtual machine, and its backend file points to the disk of the space to be recycled; S2: Online switch the virtual machine disk to the top image, and the disk of the space to be recycled becomes a read-only disk readonly_disk; S3: Make a copy of readonly_disk in the storage pool as readon_disk_copy, and then switch the backend file of the top image to the copied disk readon_disk_copy; S4: Start a small virtual machine on the computing node, and the small virtual machine mounts readonly_disk; wherein, the computing node is the host machine where the virtual machine is located or other host machines that can access the readonly_disk image; S5: Execute the fstrim command inside the small virtual machine for space recycling.
2. The method for online recycling of virtual machine ssd cloud disk space according to claim 1, characterized in that, It also includes the following steps: S6: After the space recycling is completed, destroy the small virtual machine.
3. The method for online recycling of virtual machine ssd cloud disk space according to claim 2, wherein It also includes the following steps: S7: Point the top image back to readonly_disk, and then delete readonly_disk_copy.
4. The method for online recycling of the virtual machine SSD cloud disk space according to claim 3, wherein It also includes the following steps: S8: Merge the content of the top image into readonly_disk.
5. The method for online recycling of virtual machine SSD cloud disk space according to claim 1, wherein In S4, the small virtual machine mounts readonly_disk in the virtio-scsi manner.
Citation Information
Patent Citations
Storage resource management method and device for storage migration of virtual machine
CN106469117A
Method and apparatus for reclaiming space of magnetic disk image
WO2015051641A1