Method, device and electronic device for dynamic migration of virtual machines
By identifying the virtual machine type in the virtual machine dynamic migration and storing the interrupt controller data structure, the hardware transparent transmission dynamic migration of the virtual machine is realized, solving the problem of insufficient migration efficiency and reliability in the existing technology.
Patent Information
- Application Number
- CN202210877002.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-07-25
- Publication Date
- 2025-02-28
- Estimated Expiration
- 2042-07-25
Smart Images

Figure CN115292000B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of cloud computing virtualization, and in particular to a method, device and electronic device for dynamic migration of a virtual machine. Background Art
[0002] With the development of cloud computing virtualization technology, dynamic migration of virtual machines is the process of moving a virtual machine system from one physical host to another while ensuring the normal operation of the virtual machine service. This process will not have a significant impact on users, allowing administrators to perform offline maintenance or upgrades on the physical host without affecting normal user use.
[0003] In order to ensure that the virtual machine service is available during the migration process and the migration process only takes a very short downtime, dynamic migration actually encapsulates the virtual machine configuration in a file, and then quickly transmits the virtual machine configuration and memory operating status from the source host to the destination host through a high-speed network, so that the source host transfers control to the destination host and allows the virtual machine system to continue running on the destination host, thereby realizing dynamic migration of the virtual machine.
[0004] Currently, the dynamic migration of virtual machines is implemented based on software, and there is a lack of hardware transparent virtual machine migration technology. Summary of the invention
[0005] The present application provides a method, device and electronic device for dynamic migration of a virtual machine, which implements dynamic migration of the virtual machine based on hardware.
[0006] In a first aspect, the present application provides a method for dynamic migration of a virtual machine, the method comprising:
[0007] Determine the type of the virtual machine to be migrated on the source host;
[0008] In response to the type being consistent with a preset type, storing a data structure corresponding to the interrupt controller that meets the condition;
[0009] Adding the data structure to the migration transmission data of the virtual machine to be migrated;
[0010] The virtual machine to be migrated is migrated from the source host to the target host based on the migration transmission data.
[0011] By using the above method, after the types of virtual machines on the source host are classified, the migration transmission data including the data structure is stored, so that the virtual machines can be migrated from the source host to the target host, and the registers of the target host can also be restored.
[0012] In a possible design, in response to the type being consistent with a preset type, the method includes:
[0013] Matching the type of the virtual machine to be migrated with each preset type in the preset type set;
[0014] When a preset type consistent with the type is matched, responding that the type is consistent with the preset type.
[0015] Through the above method, the type of the virtual machine to be migrated is matched with each preset type of the virtual machine. When the virtual machine to be migrated matches a virtual machine consistent with the preset type, it is determined that the virtual machine to be migrated meets the preset type, thereby realizing the screening of virtual machines based on the type of the virtual machine.
[0016] In a possible design, a data structure corresponding to an interrupt controller that meets the conditions is stored, including:
[0017] Extracting the interrupt controller of the type, and extracting the register type of the register in the interrupt controller and the data corresponding to the register;
[0018] The register type is associated with the data to generate a data structure, and the data structure is stored.
[0019] Through the above method, the type of interrupt controller is determined, and the type and data of the register in the interrupt controller are extracted, and the type and data are associated to generate a data structure, and the data structure is stored, ensuring that the virtual machine can be recovered.
[0020] In a possible design, after migrating the virtual machine to be migrated from the source host to the target host based on the migration transmission data, the method includes:
[0021] Controlling the CPU on the target host to start and restore the virtual machine of the interrupt controller of the type;
[0022] Extracting a preset register in the interrupt controller of the type, and reading the preset register;
[0023] The register data is input into a preset register to implement the injection of the register data.
[0024] Through the above method, the server controls the target host to start and restore the virtual machine corresponding to the interrupt controller, and inputs the register data into the register in the interrupt controller to realize the injection of the terminal program.
[0025] In a second aspect, the present application provides a device for dynamic migration of a virtual machine, the device comprising:
[0026] A determination module, used to determine the type of the virtual machine to be migrated on the source host;
[0027] A storage module, configured to store a data structure corresponding to the interrupt controller that meets the conditions in response to the type being consistent with a preset type;
[0028] A matching module, used for adding the data structure to the migration transmission data of the virtual machine to be migrated;
[0029] A migration module is used to migrate the virtual machine to be migrated from the source host to the target host based on the migration transmission data.
[0030] In one possible design, the storage module is specifically used to match the type of the virtual machine to be migrated with each preset type in a preset type set, and when a preset type consistent with the type is matched, responding to the type being consistent with the preset type.
[0031] In one possible design, the storage module is also used to extract the interrupt controller of the type, as well as to extract the register type of the register in the interrupt controller and the data corresponding to the register, associate the register type with the data, generate a data structure, and store the data structure.
[0032] In one possible design, the migration module is specifically used to control the CPU on the target host to start and restore the virtual machine of the interrupt controller of the type, extract the preset register in the interrupt controller of the type, read the preset register, input the register data into the preset register, and realize the injection of register data.
[0033] In a third aspect, the present application provides an electronic device, including:
[0034] Memory, used to store computer programs;
[0035] The processor is used to implement the above-mentioned method steps for dynamic migration of a virtual machine when executing the computer program stored in the memory.
[0036] In a fourth aspect, a computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method steps of a virtual machine dynamic migration are implemented.
[0037] For each aspect from the first to the fourth aspect and the technical effects that may be achieved by each aspect, please refer to the above description of the technical effects that can be achieved by the first aspect or various possible schemes in the first aspect, and no further details will be given here. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] Figure 1A flowchart of the steps of a method for dynamic migration of a virtual machine provided in this application;
[0039] Figure 2 The physical lapic dynamic migration source host flow chart provided for this application;
[0040] Figure 3 The physical lapic dynamic migration target host flow chart provided for this application;
[0041] Figure 4 A schematic diagram of the structure of a device for dynamic migration of a virtual machine provided in this application;
[0042] Figure 5 A schematic diagram of the structure of an electronic device provided in this application. DETAILED DESCRIPTION
[0043] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application will be further described in detail below in conjunction with the accompanying drawings. The specific operating methods in the method embodiments can also be applied to device embodiments or system embodiments. It should be noted that in the description of the present application, "multiple" is understood as "at least two". "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. A is connected to B, which can represent: A is directly connected to B and A is connected to B through C. In addition, in the description of the present application, words such as "first" and "second" are only used to distinguish the purpose of description, and cannot be understood as indicating or implying relative importance, nor can they be understood as indicating or implying order.
[0044] At present, in order to realize the dynamic migration of virtual machines, the method adopted is based on software and APIC simulation. On the high-performance virtual machine of "lapic" transparent transmission, the virtual machine directly uses physical lapic. Since the state of physical lapic is in the physical register, and the software-based and lapic simulation are implemented on the basis of software, there is a lack of a method for dynamic migration of hardware transparent virtual machines.
[0045] In order to solve the above-described problems, the embodiments of the present application provide a method for dynamic migration of virtual machines, which is used for dynamic migration of virtual machines based on hardware transparent transmission. Among them, the method and device described in the embodiments of the present application are based on the same technical concept. Since the principles of the problems solved by the method and the device are similar, the embodiments of the device and the method can refer to each other, and the repeated parts will not be repeated.
[0046] The embodiments of the present application are described in detail below in conjunction with the accompanying drawings.
[0047] Reference Figure 1The present application provides a method for dynamic migration of a virtual machine, which can realize dynamic migration of a virtual machine based on hardware transparent transmission. The implementation process of the method is as follows:
[0048] Step S1: Determine the type of the virtual machine to be migrated on the source host.
[0049] Since the embodiment of the present application is to realize dynamic migration of virtual machines based on hardware transparent transmission, in order to realize the dynamic migration of the above-mentioned virtual machines, first, it is necessary to determine the type of the source host of the virtual machine to be migrated on the source host. The type of the host to be migrated in the embodiment of the present application can be a virtual machine that can add "lapic" transparent transmission. In the embodiment of the present application, the virtual machine to be migrated is a virtual machine that can perform transparent transmission. It should be added that lapic in the present application document is an interrupt controller.
[0050] Step S2: In response to the type being consistent with a preset type, a data structure corresponding to the interrupt controller that meets the conditions is stored.
[0051] The type of the virtual machine to be migrated has been determined above. In order to ensure that the virtual machine to be migrated is a virtual machine of the specified type, it is necessary to match the type of the virtual machine to be migrated with each preset type in the preset type set. If the type matches a consistent preset type, it means that the type is in the preset type; if the type does not match a consistent preset type, it means that the type is not in the preset type.
[0052] When the type is consistent with the preset type, the interrupt controller corresponding to the type will be determined. Each interrupt controller has a register, which is used for reading and / or writing. The register type of the register and the data corresponding to the register are extracted from the interrupt controller. The register type can be: TPR, APR, PPR, RRD, LDR, DFR, ICR, IRR, ISR, TMR, LVTT, etc. The register type can also be other types, which will not be elaborated here.
[0053] After obtaining the type of the register and the data corresponding to the register, the type and the data are associated to generate a data structure, and the data structure is stored. It should be noted that when calling kvm_vcpu_ioctl and KVM_GET_LAPIC, the data structure can be added to the aforementioned calling program, and the implementation of saving the physical lapic data structure can be added to the kvm_apic_get_state function, which is mainly implemented to save all readable physical lapic registers.
[0054] Step S3: adding the data structure to the migration transmission data of the virtual machine to be migrated;
[0055] The above describes the storage of the data structure. During the migration of the virtual machine, KVM and QEMU are combined to realize the migration of the virtual machine. QEMU is an open source simulator and virtual machine supervisor. QEMU can be used as a user-mode simulator, using a dynamic code translation mechanism to execute codes different from the host architecture. QEMU can also be used as a virtual machine supervisor to simulate the entire system and use other VMMs (Xen, KVM, etc.) to use the virtualization support provided by the hardware to create virtual machines with performance close to that of the host. Each virtual machine corresponds to a QEMU process in the host, and the vcpu of the virtual machine corresponds to a thread of the QEMU process, and the vcpu is the cpu of the virtual machine.
[0056] After the data structure is stored, the data structure is added to the migration transmission data of the virtual machine to be migrated, and the saved physical lapic data structure is added when the destination calls kvm_vcpu_ioctl or KVM_SET_LAPIC.
[0057] Based on the above description, the data structure is stored in the migration transmission data. Since the migration transmission data is stored in the KVM, the physical lapic state can be saved and restored.
[0058] Step S4: Migrating the virtual machine to be migrated from the source host to the target host based on the migration transmission data.
[0059] The above describes adding the data structure to the migration transmission data of the virtual machine to be migrated. When the source host dynamically migrates the virtual machine to the target host, the server controls the source host to migrate the migration transmission data to the target host, thereby realizing dynamic migration of the virtual machine based on hardware transparent transmission.
[0060] After receiving the migration transmission data, the target host will start and restore the virtual machine corresponding to the above-mentioned type of interrupt controller. It can also start a new virtual machine of transparent lapic according to the qemu xml configuration and restore the physical lapic.
[0061] In order to inject register data into the register, the target host will close the corresponding CPU interrupt under the host, restore the physical lapic normal register, read the irr / isr register, and re-inject the corresponding interrupt into the register according to the interrupt number. Finally, the server will control the target host to resume the virtual machine operation.
[0062] Specifically, the flow chart of the physical lapic dynamic migration source host is as follows Figure 2 As shown, in Figure 2In the example, the source host has QEMU and KVM. QEMU is a hardware virtualization program. The function kvm_get_apic is called to retrieve kvm_vcpu_ioctl or KVM_GET_LAPIC. When the source host migrates a dynamic virtual machine, the guest exists on the virtual machine and the host exists on the host. In the process of implementing the migration of the virtual machine, it is necessary to ensure that the host interrupt is closed and the CPU is specified to exit to the host. Then, the lapic state is obtained through the program kvm_vcpu_ioctl_get_lapic, including all readable registers of the physical lapic. The physical lapic state is obtained through bm_apic_get_state, and only non-reserved registers are saved. Then, the obtained lapic state, including the physical lapic state, is saved through the program kvm_apic_get_state. The saved lapic state is then migrated to the target host, thereby implementing the migration of the virtual machine from the source host.
[0063] After the source host sends the virtual machine to the target host, the physical lapic dynamic migration target host flow chart is as follows Figure 3 As shown, in Figure 3 In the process, after the QEMU of the target host receives the lapic status data sent by the source host, the program kvm_put_apic_state will read the saved lapic status information, including physical lapic, and then read the lapic status, including the physical lapic registers, to kvm based on the program kvm_apic_put and the program kvm_vcpu_ioctl or KVM_SET_LAPIC when the host interrupt is turned off. The physical lapic status is set through the program bm_apic_set_state, and some readable and writable registers are directly written to kvm. Due to the interrupt request The interrupt request register and the interrupt handling register are read-only registers. Therefore, the corresponding interrupt needs to be re-injected into the interrupt request register and the interrupt handling register. The above has described the injection of the corresponding interrupt into the register. After the program injects the interrupt into the register, it returns to QEMU and completes the subsequent migration and recovery process. After the migration and recovery process on the target host is hosted, the specified CPU is started, and finally the guest in KVM is re-entered through the programs kvm_vcpu_ioctl and KVM_RUN, and the physical lapic is restored to run, thereby achieving the purpose of migrating the virtual machine from the source host to the target host and resuming the operation of the migrated virtual machine on the target host.
[0064] Based on the above method, the data structure is stored based on the type of the virtual machine to be migrated, and the data structure is added to the migration transmission data. The dynamic migration of the virtual machine based on hardware transparent transmission is realized by sending the migration transmission data from the source host to the target host.
[0065] Based on the same inventive concept, an embodiment of the present application also provides a device for dynamic migration of a virtual machine, which is used to implement the function of a method for dynamic migration of a virtual machine, referring to Figure 4 , the device comprises:
[0066] Determination module 401, used to determine the type of the virtual machine to be migrated on the source host;
[0067] A storage module 402, configured to store a data structure corresponding to the interrupt controller that meets the conditions in response to the type being consistent with a preset type;
[0068] A matching module 403, used for adding the data structure to the migration transmission data of the virtual machine to be migrated;
[0069] The migration module 404 is configured to migrate the virtual machine to be migrated from the source host to the target host based on the migration transmission data.
[0070] In one possible design, the storage module 402 is specifically used to match the type of the virtual machine to be migrated with each preset type in a preset type set, and when a preset type consistent with the type is matched, respond to the type being consistent with the preset type.
[0071] In one possible design, the storage module 402 is also used to extract the interrupt controller of the type, as well as to extract the register type of the register in the interrupt controller and the data corresponding to the register, associate the register type with the data, generate a data structure, and store the data structure.
[0072] In one possible design, the migration module 404 is specifically used to control the CPU on the target host to start and restore the virtual machine of the interrupt controller of the type, extract the preset register in the interrupt controller of the type, read the preset register, input the register data into the preset register, and realize the injection of register data.
[0073] Based on the same inventive concept, an electronic device is also provided in an embodiment of the present application, and the electronic device can realize the functions of the aforementioned device for dynamic migration of a virtual machine, referring to Figure 5 , the electronic device comprises:
[0074] At least one processor 501, and a memory 502 connected to the at least one processor 501. The specific connection medium between the processor 501 and the memory 502 is not limited in the embodiment of the present application. Figure 5 In the example, the processor 501 and the memory 502 are connected via a bus 500. The bus 500 is Figure 5 The connections between other components are shown in bold lines, and are not intended to be limiting. The bus 500 can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 5 Only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus. Alternatively, the processor 501 can also be called a controller, and there is no limitation on the name.
[0075] In the embodiment of the present application, the memory 502 stores instructions that can be executed by at least one processor 501. The at least one processor 501 can execute a method for dynamic migration of a virtual machine discussed above by executing the instructions stored in the memory 502. The processor 501 can implement Figure 4 The functions of each module in the device shown.
[0076] Among them, the processor 501 is the control center of the device, and can use various interfaces and lines to connect the various parts of the entire control device. By running or executing instructions stored in the memory 502 and calling data stored in the memory 502, the various functions of the device and processing data, the device can be monitored as a whole.
[0077] In one possible design, the processor 501 may include one or more processing units, and the processor 501 may integrate an application processor and a modem processor, wherein the application processor mainly processes an operating system, a user interface, and application programs, and the modem processor mainly processes wireless communications. It is understandable that the modem processor may not be integrated into the processor 501. In some embodiments, the processor 501 and the memory 502 may be implemented on the same chip, and in some embodiments, they may also be implemented separately on separate chips.
[0078] Processor 501 may be a general-purpose processor, such as a central processing unit (CPU), a digital signal processor, an application-specific integrated circuit, a field programmable gate array or other programmable logic device, a discrete gate or transistor logic device, a discrete hardware component, and may implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of the present application. A general-purpose processor may be a microprocessor or any conventional processor, etc. The steps of a method for dynamic migration of a virtual machine disclosed in the embodiments of the present application may be directly embodied as being executed by a hardware processor, or may be executed by a combination of hardware and software modules in the processor.
[0079] The memory 502 is a non-volatile computer-readable storage medium that can be used to store non-volatile software programs, non-volatile computer executable programs and modules. The memory 502 may include at least one type of storage medium, such as a flash memory, a hard disk, a multimedia card, a card-type memory, a random access memory (Random Access Memory, RAM), a static random access memory (Static Random Access Memory, SRAM), a programmable read-only memory (Programmable Read Only Memory, PROM), a read-only memory (Read Only Memory, ROM), an electrically erasable programmable read-only memory (Electrically Erasable Programmable Read-Only Memory, EEPROM), a magnetic memory, a disk, an optical disk, etc. The memory 502 is any other medium that can be used to carry or store a desired program code in the form of an instruction or data structure and can be accessed by a computer, but is not limited thereto. The memory 502 in the embodiment of the present application can also be a circuit or any other device that can realize a storage function, for storing program instructions and / or data.
[0080] By programming the processor 501, the code corresponding to the method for dynamic migration of a virtual machine described in the above embodiment can be fixed into the chip, so that the chip can execute the code when running. Figure 1 The embodiment shown is a step of dynamic migration of a virtual machine. How to design and program the processor 501 is a technology well known to those skilled in the art and will not be described in detail here.
[0081] Based on the same inventive concept, an embodiment of the present application further provides a storage medium, which stores computer instructions. When the computer instructions are executed on a computer, the computer executes a method for dynamic migration of a virtual machine discussed above.
[0082] In some possible implementations, various aspects of a method for dynamic migration of a virtual machine provided by the present application may also be implemented in the form of a program product, which includes a program code. When the program product is run on an apparatus, the program code is used to enable the control device to execute the steps of a method for dynamic migration of a virtual machine according to various exemplary implementations of the present application described above in this specification.
[0083] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0084] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0085] These computer program instructions may also be stored in a computer readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0086] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0087] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.
Claims
1. A method for dynamic migration of a virtual machine, characterized in that: include: Determine the type of the virtual machine to be migrated on the source host; In response to the type being consistent with the preset type, extracting the interrupt controller of the virtual machine to be migrated, and extracting the register type of the register in the interrupt controller and the data corresponding to the register; Associating the register type with the data to generate a data structure, and storing the data structure; Adding the data structure to the migration transmission data of the virtual machine to be migrated; The virtual machine to be migrated is migrated from the source host to the target host based on the migration transmission data.
2. The method according to claim 1, characterized in that In response to the type being consistent with the preset type, extracting the interrupt controller in the to-be-migrated virtual machine, and extracting the register type of the register in the interrupt controller and the data corresponding to the register, including: Matching the type of the virtual machine to be migrated with each preset type in the preset type set; When a preset type consistent with the type is matched, in response to the type being consistent with the preset type, an interrupt controller in the virtual machine to be migrated is extracted, and a register type of a register in the interrupt controller and data corresponding to the register are extracted.
3. The method according to claim 1, characterized in that After migrating the virtual machine to be migrated from the source host to the target host based on the migration transmission data, the method includes: Controlling the CPU on the target host to start and restore the virtual machine corresponding to the interrupt controller of the register type; Extracting a preset register in an interrupt controller of the register type, and reading the preset register; The data corresponding to the register is input into a preset register to implement the injection of register data.
4. A device for dynamic migration of a virtual machine, characterized in that: The device comprises: A determination module, used to determine the type of the virtual machine to be migrated on the source host; A storage module, configured to extract, in response to the type being consistent with a preset type, an interrupt controller of the virtual machine to be migrated, and to extract a register type of a register in the interrupt controller and data corresponding to the register; Associating the register type with the data to generate a data structure, and storing the data structure; A matching module, used for adding the data structure to the migration transmission data of the virtual machine to be migrated; A migration module is used to migrate the virtual machine to be migrated from the source host to the target host based on the migration transmission data.
5. The device according to claim 4, characterized in that The storage module is specifically used to match the type of the virtual machine to be migrated with each preset type in the preset type set. When a preset type consistent with the type is matched, in response to the type being consistent with the preset type, the interrupt controller in the virtual machine to be migrated is extracted, as well as the register type of the register in the interrupt controller and the data corresponding to the register are extracted.
6. The device according to claim 4, characterized in that The migration module is specifically used to control the CPU on the target host to start and restore the virtual machine corresponding to the interrupt controller of the register type, extract the preset register in the interrupt controller of the register type, read the preset register, input the data corresponding to the register into the preset register, and realize the injection of register data.
7. An electronic device, characterized in that: include: Memory, used to store computer programs; A processor, for implementing the method steps described in any one of claims 1 to 3 when executing the computer program stored in the memory.
8. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method steps described in any one of claims 1 to 3 are implemented.
Citation Information
Patent Citations
Virtual machine instance live migration method
CN114691300A