A virtual machine incremental image access method and system

By adding a shared master disk image caching mechanism to the host user space, the problem of low read request efficiency in the incremental image scheme is solved, the virtual machine disk access efficiency is improved, and the overhead of user space kernel switching is reduced.

CN115658093BActive Publication Date: 2026-11-27MASSCLOUDS +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202211365808.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-10-31
Publication Date
2026-11-27
Estimated Expiration
2042-10-31

AI Technical Summary

Technical Problem

Existing incremental image solutions suffer from low read request efficiency in virtual machines, especially when there are a large number of virtual machines sharing a master disk, which becomes a major bottleneck. Existing hardware upgrade methods increase costs.

Method used

A shared master disk image caching mechanism is added to the host machine's user space. By caching recently accessed data blocks, the direct access of virtual machine read requests to the master disk image file is reduced, thereby improving read and write efficiency.

Benefits of technology

By adding a shared master disk image cache in the host user space, the overhead of user space kernel switching is reduced, the efficiency of virtual machine disk access is improved, and the boot storm problem is alleviated.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115658093B_ABST
    Figure CN115658093B_ABST
Patent Text Reader

Abstract

The application provides a virtual machine incremental image access method, which comprises the following steps: obtaining an access read request of a virtual machine driver accessing a disk; caching a master disk image file to a memory area pre-opened in a host computer user state; if a first target data block of the access read request does not exist in a virtual machine self-disk image file, obtaining the first target data block from the memory area master disk image cache file according to the access read request. Through the shared master disk image cache mechanism increased in the host computer user state, the efficiency of reading and writing the disk by the virtual machine is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of computer technology, and in particular relates to a method and system for incremental access to virtual machine images. Background Technology

[0002] The statements in this section are merely background information related to the present invention and do not necessarily constitute prior art.

[0003] Incremental image creation is a very effective way to save disk space for virtual machine images. For mainstream open-source virtualization solutions like QEMU / KVM, the qcow2 disk format supports incremental images based on the parent disk. However, in practice, this technique is less efficient than raw format, especially when there are a large number of virtual machines sharing the parent disk.

[0004] Existing methods include upgrading the rotational speed of the mechanical hard drive or replacing it with a high-speed SSD, thus improving efficiency through hardware upgrades. However, while this method is simple, it increases costs.

[0005] Figure 1 Currently, virtual machines access image disks by sending access requests to the QEMU process through the virtio-blk driver. For write requests, data is written to the corresponding virtual machine disk image file. For read requests, a mapping table stored in the virtual machine disk image file is used for further judgment. If the target is a data block newly created or modified by the virtual machine, it is read directly from the current disk image file; otherwise, the target needs to be searched for and read from the parent disk image file. Typically, read requests are far more frequent than write requests, and since the virtual machine's own disk image file only stores incremental data, most read requests still need to be completed by manipulating the parent disk image file. Therefore, the efficiency of read operations on the parent disk image file is the main bottleneck. Summary of the Invention

[0006] To overcome the shortcomings of the prior art, the present invention provides a virtual machine incremental image access method and system, which improves the efficiency of virtual machine disk reading and writing by adding a shared master disk image caching mechanism in the host user space.

[0007] To achieve the above objectives, one or more embodiments of the present invention provide the following technical solution: a method for incremental access to virtual machine images, comprising:

[0008] Obtain read access requests from the virtual machine driver to access the disk;

[0009] The master disk image file is cached in a memory area pre-allocated in the host machine's user space;

[0010] If the virtual machine's own disk image file does not contain the first target data block of the access read request, then the first target data block is obtained from the memory area master disk image cache file according to the access read request.

[0011] A second aspect of the present invention provides a virtual machine incremental image access system, comprising:

[0012] Virtual machine: Used to send access requests for image files to the virtual machine disk;

[0013] The virtio-blk driver is used to send virtual machine access requests to the virtual machine disk and execute the access requests on the virtual machine disk.

[0014] Virtual machine disk: Used to receive image file access requests sent by virtual machines and determine whether the target data block requested exists in the image file of the virtual machine disk;

[0015] Host cache: Used to cache the master disk image file, receive access requests from virtual machines, and return the target data block of the access request to the virtual machine.

[0016] The above one or more technical solutions have the following beneficial effects:

[0017] In this invention, for virtual machines using an incremental image scheme, a shared master disk image cache mechanism is added in the host user space. The virtual machine's access read requests are directly read from the master disk image cache, without having to access the file content through a system call each time. This reduces the overhead of user-space kernel switching, improves the virtual machine's disk access efficiency, and alleviates the boot storm problem.

[0018] Advantages of additional aspects of the invention will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of the invention. Attached Figure Description

[0019] The accompanying drawings, which form part of this invention, are used to provide a further understanding of the invention. The illustrative embodiments of the invention and their descriptions are used to explain the invention and do not constitute an improper limitation of the invention.

[0020] Figure 1 Flowchart of the method for accessing the image disk for existing virtual machines;

[0021] Figure 2 This is a flowchart of the method for a virtual machine to access a mirror disk in Embodiment 1 of the present invention. Detailed Implementation

[0022] It should be noted that the following detailed descriptions are exemplary and intended to provide further illustration of the invention. Unless otherwise specified, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention pertains.

[0023] It should be noted that the terminology used herein is for the purpose of describing particular implementations only and is not intended to limit the exemplary implementations of the present invention.

[0024] Where there is no conflict, the embodiments and features in the embodiments of the present invention can be combined with each other.

[0025] Example 1

[0026] like Figure 2 As shown, this embodiment discloses a virtual machine incremental image access method, in which two types of independently running processes collaborate. The first type is the QEMU process, with one QEMU process corresponding to each virtual machine, handling IO requests for its assigned virtual machine. The second type is the proxy process, which is responsible for exchanging data blocks between the master image file and the master image cache. The intermediary for the collaboration between the two types of processes is the master image cache, which caches the most recently accessed data blocks of the master image file. From the perspective of the master image cache, the QEMU process is the consumer, while the proxy process is the producer. The two logical processes are relatively independent and parallel logical processes mediated by the master image cache.

[0027] Specifically, it includes two processes: A is the process of the virtual machine accessing its own image file and the parent image cache; B is the process of the agent process filling the cached items in the parent image cache that have not been found. The two processes cooperate through the newly added parent image cache as an intermediary.

[0028] A.1 The virtual machine issues a disk access request through the virtio-blk driver. If it is a write request, proceed directly to A.2; if it is a read request, further judgment is made based on the mapping table saved in the virtual machine disk image file. If the target is a data block that has been newly created or modified by this virtual machine, proceed to A.2; otherwise, proceed to A.3.

[0029] The A.2virtio-blk driver executes disk access requests. If it's a read request, it reads the data block from the target location in its own disk image file and returns it to the virtual machine; if it's a write request, it writes the data block to the target location. At this point, the current processing is complete, and the system awaits the next access request from the virtual machine.

[0030] A.3 The virtio-blk driver of the qemu process attempts to read the target data block from the master disk image cache. If the cache is hit, the data block is returned directly, and the process ends; if the cache is not hit, the least recently used item in the cache is cleared as a waiting item, the qemu process enters a waiting state, and proceeds to B.1.

[0031] Process B:

[0032] B.1 Wake up the agent process.

[0033] B.2 The agent process reads the target data from the master disk image file through system calls of the host operating system.

[0034] B.3 The agent process fills the wait entries in the master image cache with the read target data, and then wakes up the process waiting for that cache entry (i.e., the qemu process that entered the wait in A.3). The virtio-blk driver of the qemu process retrieves the data block from the master image cache and returns it to the virtual machine, and the process ends.

[0035] It's important to note that the master image cache only caches data blocks that have been accessed. The implementation mechanism of the master image cache involves creating a shared cache within the host operating system. Because it's shared, all QEMU processes can access it; therefore, it's not a private cache for any single QEMU process.

[0036] It's important to note that the cache is pre-loaded onto the file. This can be roughly represented as "reader" -> "cache" -> "file". Here, the "reader" is the QEMU process. Initially, the cache is empty. If a reader tries to read a data block from the cache, it will fail to do so—this is a "miss"—and the reader must wait. Another process (the agent process) is then awakened and responsible for filling the cache with the "missed" data block from the file. Then, the reader is awakened and can read the target data block. Once this process begins, the cache quickly fills up, always maintaining the most recently accessed data blocks. These blocks are also likely to be accessed by other virtual machine QEMU processes, resulting in a high cache hit rate and reducing the frequency of direct file access. Furthermore, the cache capacity is always very limited relative to the file capacity. Therefore, if the cache is full, when filling with a new data block, the oldest and least frequently used block must be evicted first to free up space.

[0037] Example 2

[0038] The purpose of this embodiment is to provide a virtual machine incremental image access system, characterized by including:

[0039] Virtual machine: Used to send access requests for image files to the virtual machine disk;

[0040] The virtio-blk driver is used to send virtual machine access requests to the virtual machine disk and execute the access requests on the virtual machine disk.

[0041] Virtual machine disk: Used to receive image file access requests sent by virtual machines and determine whether the target data block requested exists in the image file of the virtual machine disk;

[0042] Host cache: Used to cache the master disk image file, receive access requests from virtual machines, and return the target data block of the access request to the virtual machine.

[0043] In this embodiment, it also includes: a virtual machine disk: which is further used to write the target data block corresponding to the write request at the target location when the image file access request sent by the virtual machine is a write request.

[0044] Virtual machine disk: When the image file access request sent by the virtual machine is a read request, it is used to determine whether the target data block corresponding to the access read request exists in the virtual machine disk according to the mapping table stored in the virtual machine disk. If it exists, the target data corresponding to the access read request is returned to the virtual machine.

[0045] Host cache: Used to receive read requests from virtual machines. If the host cache contains the target data block corresponding to the read request, the target data block corresponding to the read request will be returned to the virtual machine.

[0046] Cleanup module: When the target data block corresponding to the access read request does not exist in the host machine cache, it is used to clean up the least recently used item in the host machine cache as a waiting item.

[0047] First wake-up module: Used to wake up the agent process when the target data block corresponding to the access read request does not exist in the host machine cache.

[0048] Agent process: Reads the target data block corresponding to the access read request from the master disk image file and fills the read target data block into the wait item in the host machine cache.

[0049] The second wake-up module is used to wake up the qemu process of the waiting item. The virtio-blk driver of the qemu process retrieves the target data block from the master disk image cache and returns it to the virtual machine.

[0050] While the specific embodiments of the present invention have been described above in conjunction with the accompanying drawings, this is not intended to limit the scope of protection of the present invention. Those skilled in the art should understand that various modifications or variations that can be made by those skilled in the art without creative effort based on the technical solutions of the present invention are still within the scope of protection of the present invention.

Claims

1. A method for incremental access to virtual machine images, characterized in that, include: Obtain read access requests from the virtual machine driver to the disk; The master disk image file is cached in a memory area pre-allocated in the host machine's user space; There are two types of independently running processes: the first type is the qemu process, with one qemu process for each virtual machine, which handles IO requests for its virtual machine; the second type is the proxy process, which is responsible for exchanging data blocks between the master disk file and the master disk image cache; the intermediary for the cooperation between the two types of processes is the master disk image cache, which caches the data blocks of the master disk file that have been accessed recently. The master image cache only caches data blocks that have been accessed. The implementation mechanism of the master image cache is to open a shared cache in the host operating system, which can be accessed by all qemu processes. If the first target data block of the access read request exists in the virtual machine's own disk image file, then the first target data block is read directly from the virtual machine's own disk image file according to the access read request; If the virtual machine's own disk image file does not contain the first target data block of the access read request, then the first target data block is obtained from the memory area master disk image cache file according to the access read request, specifically as follows: If the first target data block of the access read request is hit in the memory area master disk image cache file, then the first target data block is returned from the memory area master disk image cache file to the virtual machine; If the first target data block of the access read request is not found in the memory area master disk image cache file, the agent process reads the first target data block from the master disk image file and caches it in the memory area master disk image cache file, and then reads the first target data block from the memory area master disk image cache file to the virtual machine. The agent process reads the first target data from the master disk image file and caches it in the master disk image cache file in memory. Specifically: Clean up the least recently used item in the master disk image cache file in the memory area as a wait item; The agent process is awakened, and the agent process reads the first target data block of the access read request from the master disk image file; Fill the first target data block read by the agent process into the memory area's wait item; The qemu process of the waiting item is awakened, and the virtio-blk driver of the qemu process reads the first target data block of the access read request from the memory area master disk image cache file to the virtual machine.

2. The virtual machine incremental image access method as described in claim 1, characterized in that, The virtual machine driver is the virtio-blk driver of the qemu process.

3. The virtual machine incremental image access method as described in claim 1, characterized in that, Also includes: Obtain the disk access write request from the virtual machine driver; The second target data block is written to the virtual machine disk image file according to the access write request.

4. The virtual machine incremental image access method as described in claim 1, characterized in that, The system uses a mapping table stored in the virtual machine's own disk image file to determine whether the first target data block of the access read request exists in the virtual machine's own disk image file.

5. A virtual machine incremental image access system, employing a virtual machine incremental image access method as described in any one of claims 1-4, characterized in that, include: Virtual machine: Used to send access requests for image files to the virtual machine disk; The virtio-blk driver is used to send virtual machine access requests to the virtual machine disk and execute the access requests on the virtual machine disk. Virtual machine disk: Used to receive image file access requests sent by virtual machines and determine whether the target data block requested exists in the image file of the virtual machine disk; Host cache: Used to cache the master disk image file, receive access requests from virtual machines, and return the target data block of the access request to the virtual machine.

6. The virtual machine incremental image access system as described in claim 5, characterized in that, Virtual machine disk: When the image file access request sent by the virtual machine is a write request, it writes the target data block corresponding to the write request to the target location; when the image file access request sent by the virtual machine is a read request, it determines whether the target data block corresponding to the read request exists in the virtual machine disk according to the mapping table stored in the virtual machine disk. If it exists, it returns the target data corresponding to the read request to the virtual machine. Host cache: Used to receive read requests from virtual machines. If the host cache contains the target data block corresponding to the read request, the target data block corresponding to the read request will be returned to the virtual machine.

7. The virtual machine incremental image access system as described in claim 5, characterized in that, Also includes: Cleanup module: Used to clean up the least recently used item in the host machine's cache as a wait item; First wake-up module: Used to wake up the proxy process when the target data block corresponding to the access read request does not exist in the host machine cache; The proxy process reads the target data block corresponding to the access read request from the master disk image file and fills the read target data block into the wait item in the host machine cache. The second wake-up module is used to wake up the qemu process of the waiting item.