[go: up one dir, main page]

CN107368353A - A kind of method and apparatus for realizing virutal machine memory heat addition - Google Patents

A kind of method and apparatus for realizing virutal machine memory heat addition Download PDF

Info

Publication number
CN107368353A
CN107368353A CN201710636247.6A CN201710636247A CN107368353A CN 107368353 A CN107368353 A CN 107368353A CN 201710636247 A CN201710636247 A CN 201710636247A CN 107368353 A CN107368353 A CN 107368353A
Authority
CN
China
Prior art keywords
memory
virtual machine
hot
information
addition
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN201710636247.6A
Other languages
Chinese (zh)
Other versions
CN107368353B (en
Inventor
周胜利
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Zhengzhou Yunhai Information Technology Co Ltd
Original Assignee
Zhengzhou Yunhai Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Zhengzhou Yunhai Information Technology Co Ltd filed Critical Zhengzhou Yunhai Information Technology Co Ltd
Priority to CN201710636247.6A priority Critical patent/CN107368353B/en
Publication of CN107368353A publication Critical patent/CN107368353A/en
Application granted granted Critical
Publication of CN107368353B publication Critical patent/CN107368353B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45533Hypervisors; Virtual machine monitors
    • G06F9/45558Hypervisor-specific management and integration aspects
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45533Hypervisors; Virtual machine monitors
    • G06F9/45558Hypervisor-specific management and integration aspects
    • G06F2009/45583Memory management, e.g. access or allocation

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)
  • Memory System Of A Hierarchy Structure (AREA)

Abstract

The embodiment of the invention discloses a kind of method and apparatus for realizing virutal machine memory heat addition, methods described includes:Virutal machine memory heat addition is carried out according to the memory size of each node in virtual machine;After virutal machine memory heat is added successfully, the memory information and the current memory information of the virtual machine that are preserved in database are updated by the source code for changing virtual machine manager, to keep the consistent of the current memory information of the memory information and virtual machine preserved in the database.The embodiment of the present invention can effectively increase the application scenarios of virtual machine (vm) migration function, reduce migration limitation.

Description

一种实现虚拟机内存热添加的方法和装置A method and device for realizing hot addition of virtual machine memory

技术领域technical field

本发明涉及虚拟机技术,尤指一种实现虚拟机内存热添加的方法和装置。The invention relates to virtual machine technology, in particular to a method and device for realizing hot addition of virtual machine memory.

背景技术Background technique

传统服务器要升级配置,往往是需要停机的;在虚拟化环境下,实现在线升级配置从技术上和操作上都要更为容易一些,从而让客户在服务器负载超出预估需要升级配置时,依然能够保证服务的可用性。Linux内核已经实现了内存热插的支持,当一个linux系统不管运行在物理环境或者虚拟环境时只要宿主能提供内存热插拔机制,linux内核就能相应的增加或者减少内存。结合开源模拟器qemu内存和CPU热插拔的技术,可以实现生产环境下不中断业务的在线系统升级。若直接调用开源模拟器qemu提供的应用程序编程接口(Application Programming Interface,API),来进行内存热插,C函数库libvirt感知不到每次添加,无法对虚拟机(Virtual Machine,VM)进行打快照以及进行迁移。To upgrade the configuration of a traditional server, it often needs to be shut down; in a virtualized environment, it is easier to upgrade the configuration online, both technically and operationally, so that customers can still upgrade the configuration when the server load exceeds the estimate. Ability to guarantee service availability. The Linux kernel has implemented memory hot-swapping support. When a Linux system runs in a physical or virtual environment, as long as the host can provide a memory hot-swapping mechanism, the Linux kernel can increase or decrease memory accordingly. Combined with the technology of the open source emulator qemu memory and CPU hot swap, it can realize the online system upgrade without interrupting the business in the production environment. If the application programming interface (Application Programming Interface, API) provided by the open source emulator qemu is directly called to perform memory hot plugging, the C function library libvirt cannot perceive each addition, and cannot open a virtual machine (Virtual Machine, VM). snapshot and migrate.

发明内容Contents of the invention

为了解决上述技术问题,本发明实施例提供了一种实现虚拟机内存热添加的方法和装置,可以通过。In order to solve the above-mentioned technical problems, the embodiments of the present invention provide a method and an apparatus for realizing hot addition of memory of a virtual machine, which can be adopted.

为了达到本发明目的,一方面,本发明实施例提供了一种实现虚拟机内存热添加的方法,包括:In order to achieve the purpose of the present invention, on the one hand, the embodiment of the present invention provides a method for realizing hot addition of virtual machine memory, including:

根据虚拟机中各个节点的内存大小进行虚拟机内存热添加;在所述虚拟机内存热添加成功后,通过修改虚拟机管理器的源码对数据库中保存的内存信息和所述虚拟机的当前内存信息进行更新,以保持所述数据库中保存的内存信息和所述虚拟机的当前内存信息的一致。According to the memory size of each node in the virtual machine, perform hot addition of virtual machine memory; after the hot addition of virtual machine memory is successful, the memory information stored in the database and the current memory of the virtual machine are compared by modifying the source code of the virtual machine manager The information is updated to keep the memory information stored in the database consistent with the current memory information of the virtual machine.

与现有技术相比,本发明实施例根据虚拟机中各个节点的内存大小进行虚拟机内存热添加;在所述虚拟机内存热添加成功后,通过修改虚拟机管理器的源码对数据库中保存的内存信息和所述虚拟机的当前内存信息进行更新,以保持所述数据库中保存的内存信息和所述虚拟机的当前内存信息的一致。本发明实施例能够有效地增加虚拟机迁移功能的应用场景,减少了迁移限制。Compared with the prior art, the embodiment of the present invention performs virtual machine memory hot addition according to the memory size of each node in the virtual machine; after the virtual machine memory hot addition succeeds, the source code of the virtual machine manager is modified to save The memory information of the virtual machine and the current memory information of the virtual machine are updated to keep the memory information saved in the database consistent with the current memory information of the virtual machine. The embodiment of the present invention can effectively increase the application scenarios of the virtual machine migration function, and reduce migration restrictions.

进一步地,所述虚拟机是使用开源模拟器qemu创建的;Further, the virtual machine is created using an open source simulator qemu;

所述虚拟机管理器为虚拟化工具libvirt。The virtual machine manager is a virtualization tool libvirt.

进一步地,所述根据虚拟机中各个节点的内存大小进行虚拟机内存热添加包括:Further, the hot adding of virtual machine memory according to the memory size of each node in the virtual machine includes:

获取所述虚拟机的非统一内存访问numa节点拓扑信息;Obtain the non-uniform memory access numa node topology information of the virtual machine;

如果根据所述numa节点拓扑信息获知所述虚拟机中只有一个numa节点,则直接进行内存热添加;如果根据所述numa节点拓扑信息获知所述虚拟机中有多个numa节点,则获取内存最小的numa节点,并对所述内存最小的numa节点进行内存热添加。If it is learned that there is only one numa node in the virtual machine according to the numa node topology information, then directly perform memory hot addition; if it is learned that there are multiple numa nodes in the virtual machine according to the numa node topology information, then obtain the minimum memory numa nodes, and hot add memory to the numa node with the smallest memory.

进一步地,所述通过修改虚拟机管理器的源码对数据库中保存的内存信息和所述虚拟机的当前内存信息进行更新包括:Further, updating the memory information stored in the database and the current memory information of the virtual machine by modifying the source code of the virtual machine manager includes:

通过调用基于内核的kvm虚拟化接口对所述虚拟机进行管理;The virtual machine is managed by calling a kernel-based kvm virtualization interface;

通过修改虚拟化工具libvirt源码,对可扩展标记语言XML中的memory信息进行更新。By modifying the source code of the virtualization tool libvirt, the memory information in the Extensible Markup Language XML is updated.

进一步地,所述进行虚拟机内存热添加包括:Further, the hot adding of virtual machine memory includes:

所述Libvirt通过socket将内存热添加事件发送给qemu;The Libvirt sends the memory hot-add event to qemu through the socket;

所述qemu根据所述内存热添加事件执行内存热添加;The qemu performs memory hot-add according to the memory hot-add event;

在执行所述内存热添加之后,还包括:After performing the memory hot-add, it also includes:

如果所述内存热添加执行失败,则通过libvirt返回处理结果;如果所述内存热添加执行成功,则进行对所述虚拟机的XML中的memory信息进行更新。If the execution of the memory hot addition fails, a processing result is returned through libvirt; if the execution of the memory hot addition is successful, the memory information in the XML of the virtual machine is updated.

另一方面,本发明实施例还提供了一种实现虚拟机内存热添加的装置,包括:On the other hand, the embodiment of the present invention also provides an apparatus for implementing virtual machine memory hot addition, including:

管理模块,用于根据虚拟机中各个节点的内存大小进行虚拟机内存热添加;在所述虚拟机内存热添加成功后,通过修改虚拟机管理器的源码对数据库中保存的内存信息和所述虚拟机的当前内存信息进行更新,以保持所述数据库中保存的内存信息和所述虚拟机的当前内存信息的一致。The management module is used to perform virtual machine memory hot addition according to the memory size of each node in the virtual machine; after the virtual machine memory hot addition is successful, the memory information stored in the database and the memory information stored in the database are modified by modifying the source code of the virtual machine manager. The current memory information of the virtual machine is updated to keep the memory information stored in the database consistent with the current memory information of the virtual machine.

进一步地,所述装置还包括:Further, the device also includes:

所述虚拟机是使用开源模拟器qemu创建的;The virtual machine is created using the open source emulator qemu;

所述虚拟机管理器为虚拟化工具libvirt。The virtual machine manager is a virtualization tool libvirt.

进一步地,所述装置还包括:Further, the device also includes:

获取模块,用于获取所述虚拟机的非统一内存访问numa节点拓扑信息;An acquisition module, configured to acquire the non-uniform memory access numa node topology information of the virtual machine;

执行模块,用于如果根据所述numa节点拓扑信息获知所述虚拟机中只有一个numa节点,则直接进行内存热添加;如果根据所述numa节点拓扑信息获知所述虚拟机中有多个numa节点,则获取内存最小的numa节点,并对所述内存最小的numa节点进行内存热添加。An execution module, configured to directly perform memory hot-add if it is learned that there is only one numa node in the virtual machine according to the numa node topology information; if it is learned that there are multiple numa nodes in the virtual machine according to the numa node topology information , the numa node with the smallest memory is obtained, and memory hot-add is performed on the numa node with the smallest memory.

进一步地,所述管理模块还用于:Further, the management module is also used for:

通过调用基于内核的kvm虚拟化接口对所述虚拟机进行管理;The virtual machine is managed by calling a kernel-based kvm virtualization interface;

通过修改虚拟化工具libvirt源码,对可扩展标记语言XML中的memory信息进行更新。By modifying the source code of the virtualization tool libvirt, the memory information in the Extensible Markup Language XML is updated.

进一步地,所述管理模块还用于:Further, the management module is also used for:

所述Libvirt通过socket将内存热添加事件发送给qemu;The Libvirt sends the memory hot-add event to qemu through the socket;

所述qemu根据所述内存热添加事件执行内存热添加;The qemu performs memory hot-add according to the memory hot-add event;

在执行所述内存热添加之后,还包括:After performing the memory hot-add, it also includes:

如果所述内存热添加执行失败,则通过libvirt返回处理结果;如果所述内存热添加执行成功,则进行对所述虚拟机的XML中的memory信息进行更新。If the execution of the memory hot addition fails, a processing result is returned through libvirt; if the execution of the memory hot addition is successful, the memory information in the XML of the virtual machine is updated.

本发明的其它特征和优点将在随后的说明书中阐述,并且,部分地从说明书中变得显而易见,或者通过实施本发明而了解。本发明的目的和其他优点可通过在说明书、权利要求书以及附图中所特别指出的结构来实现和获得。Additional features and advantages of the invention will be set forth in the description which follows, and in part will be apparent from the description, or may be learned by practice of the invention. The objectives and other advantages of the invention may be realized and attained by the structure particularly pointed out in the written description and claims hereof as well as the appended drawings.

附图说明Description of drawings

附图用来提供对本发明技术方案的进一步理解,并且构成说明书的一部分,与本申请的实施例一起用于解释本发明的技术方案,并不构成对本发明技术方案的限制。The accompanying drawings are used to provide a further understanding of the technical solution of the present invention, and constitute a part of the description, and are used together with the embodiments of the application to explain the technical solution of the present invention, and do not constitute a limitation to the technical solution of the present invention.

图1为本发明实施例的实现虚拟机内存热添加的方法的流程图;FIG. 1 is a flow chart of a method for implementing hot addition of virtual machine memory according to an embodiment of the present invention;

图2为本发明实施例的实现虚拟机内存热添加的方法的原理图;FIG. 2 is a schematic diagram of a method for realizing hot addition of virtual machine memory according to an embodiment of the present invention;

图3为本发明实施例的实现虚拟机内存热添加的装置的结构图。FIG. 3 is a structural diagram of an apparatus for realizing hot addition of memory of a virtual machine according to an embodiment of the present invention.

具体实施方式detailed description

为使本发明的目的、技术方案和优点更加清楚明白,下文中将结合附图对本发明的实施例进行详细说明。需要说明的是,在不冲突的情况下,本申请中的实施例及实施例中的特征可以相互任意组合。In order to make the purpose, technical solution and advantages of the present invention more clear, the embodiments of the present invention will be described in detail below in conjunction with the accompanying drawings. It should be noted that, in the case of no conflict, the embodiments in the present application and the features in the embodiments can be combined arbitrarily with each other.

在附图的流程图示出的步骤可以在诸如一组计算机可执行指令的计算机系统中执行。并且,虽然在流程图中示出了逻辑顺序,但是在某些情况下,可以以不同于此处的顺序执行所示出或描述的步骤。The steps shown in the flowcharts of the figures may be performed in a computer system, such as a set of computer-executable instructions. Also, although a logical order is shown in the flowcharts, in some cases the steps shown or described may be performed in an order different from that shown or described herein.

如图1所示,是本发明实施例实现虚拟机内存热添加的方法的流程图,本实施例包括以下步骤:As shown in Figure 1, it is a flow chart of a method for implementing virtual machine memory hot addition in an embodiment of the present invention. This embodiment includes the following steps:

步骤100:根据虚拟机中各个节点的内存大小进行虚拟机内存热添加;Step 100: performing virtual machine memory hot addition according to the memory size of each node in the virtual machine;

步骤101:在所述虚拟机内存热添加成功后,通过修改虚拟机管理器的源码对数据库中保存的内存信息和所述虚拟机的当前内存信息进行更新,以保持所述数据库中保存的内存信息和所述虚拟机的当前内存信息的一致。Step 101: After the virtual machine memory hot addition is successful, update the memory information stored in the database and the current memory information of the virtual machine by modifying the source code of the virtual machine manager, so as to keep the memory stored in the database The information is consistent with the current memory information of the virtual machine.

具体地,本发明实施例就是一种基于qemu与libvirt的虚拟化产品实现虚拟机内存热添加、支持迁移与快照的方法。调用开源模拟器qemu提供的API,来进行内存热插,要对虚拟机VM进行打快照以及进行迁移,需要调用libvirt的API来进行每次热插的实现。进行内存热插,要使C函数库libvirt感知到每次添加,在可扩展标记语言(eXtensible MarkupLanguage,XML)中就要有体现。Specifically, the embodiment of the present invention is a virtualization product based on qemu and libvirt to realize hot addition of virtual machine memory, support migration and snapshot method. Call the API provided by the open source emulator qemu to perform memory hot plugging. To take a snapshot and migrate the virtual machine VM, you need to call the API of libvirt to implement each hot plugging. For memory hot plugging, the C function library libvirt must be aware of each addition, which must be reflected in the eXtensible Markup Language (XML).

一般情形下,qemu中的虚拟机都是通过Libvirt创建的,要支持内存热插拔,在创建虚拟机时需指定最大存储器maxMemory配置,并且需指定至少一个非统一内存访问(numa)节点,它是虚拟机中的numa节点,不是宿主机中的节点。当存在多个numa节点,在进行内存热插时,就会涉及到将内存添加到哪个node节点上的问题,以及如何保持各个node节点之间内存大小的一致。In general, virtual machines in qemu are created through Libvirt. To support memory hot swap, you need to specify the maximum memory maxMemory configuration when creating a virtual machine, and you need to specify at least one non-uniform memory access (numa) node, which It is the numa node in the virtual machine, not the node in the host machine. When there are multiple numa nodes, when performing memory hot plugging, it will involve the issue of which node to add memory to, and how to keep the memory size consistent between each node.

本发明实施例采用libvirt在执行完内存热插后,会对XML中的memory和currentmemory进行更新,使数据库中保存的信息和VM的真实内存大小保持一致。The embodiment of the present invention adopts libvirt to update the memory and currentmemory in the XML after executing the memory hot plug, so that the information stored in the database is consistent with the real memory size of the VM.

本发明实施例采用C语言进行虚拟机内存热添加方法的实现,使用开源模拟器qemu来创建虚拟机,使用libvirt来调用kvm虚拟化接口来对虚拟机进行管理,通过修改libvirt源码来对XML中的memory信息进行更新,来保证内存热添加后,libvirt和qemu进程中保存的虚拟机XML数据的一致性,以及VM中各个node节点之间内存大小的均衡。The embodiment of the present invention adopts C language to carry out the realization of virtual machine memory hot adding method, uses open source emulator qemu to create virtual machine, uses libvirt to call kvm virtualization interface to manage virtual machine, by modifying libvirt source code to come to XML The memory information is updated to ensure the consistency of the virtual machine XML data saved in the libvirt and qemu processes after the hot memory addition, and the balance of the memory size among the various node nodes in the VM.

其中,内核级虚拟机(Kernel-based Virtual Machine,KVM)是Linux下x86硬件平台上的全功能虚拟化解决方案。Among them, Kernel-based Virtual Machine (KVM) is a full-featured virtualization solution on the x86 hardware platform under Linux.

所述虚拟机管理器为虚拟化工具libvirt。libvirt是一套免费、开源的支持Linux下主流虚拟化工具的C函数库,其旨在为各种虚拟机监控程序如qemu提供一套方便、可靠的编程接口。The virtual machine manager is a virtualization tool libvirt. libvirt is a set of free and open-source C function libraries that support mainstream virtualization tools under Linux. It aims to provide a set of convenient and reliable programming interfaces for various virtual machine monitoring programs such as qemu.

本发明实施例的方法完善了内存热添加功能,能够有效的增加虚拟机迁移功能的使用场景,减少迁移限制,同时这种方式可以通过软件部分的修改,方便后期虚拟化产品的升级与维护。The method of the embodiment of the present invention improves the memory hot adding function, can effectively increase the usage scenarios of the virtual machine migration function, and reduce migration restrictions. At the same time, this method can facilitate the upgrade and maintenance of virtualization products in the later stage through the modification of the software part.

本发明实施例根据虚拟机中各个节点的内存大小进行虚拟机内存热添加;在所述虚拟机内存热添加成功后,通过修改虚拟机管理器的源码对数据库中保存的内存信息和所述虚拟机的当前内存信息进行更新,以保持所述数据库中保存的内存信息和所述虚拟机的当前内存信息的一致。本发明实施例能够有效地增加虚拟机迁移功能的应用场景,减少了迁移限制。The embodiment of the present invention performs virtual machine memory hot-add according to the memory size of each node in the virtual machine; after the virtual machine memory hot-add is successful, the memory information stored in the database and the virtual The current memory information of the virtual machine is updated to keep the memory information stored in the database consistent with the current memory information of the virtual machine. The embodiment of the present invention can effectively increase the application scenarios of the virtual machine migration function, and reduce migration restrictions.

本发明实施例方法的具体实施过程如下:修改libvirt源码来对XML中的memory信息进行更新,来保证内存热添加后,libvirt和qemu进程中保存的虚拟机XML数据的一致性,以及VM中各个node节点之间内存大小的均衡。The specific implementation process of the method in the embodiment of the present invention is as follows: modify the libvirt source code to update the memory information in the XML to ensure the consistency of the virtual machine XML data stored in the libvirt and qemu processes after the hot addition of memory, and the consistency of each virtual machine XML data in the VM. The balance of memory size between node nodes.

进一步地,根据虚拟机中各个节点的内存大小进行虚拟机内存热添加包括:Further, the hot addition of virtual machine memory according to the memory size of each node in the virtual machine includes:

获取所述虚拟机的非统一内存访问numa节点拓扑信息;Obtain the non-uniform memory access numa node topology information of the virtual machine;

如果根据所述numa节点拓扑信息获知所述虚拟机中只有一个numa节点,则直接进行内存热添加;如果根据所述numa节点拓扑信息获知所述虚拟机中有多个numa节点,则获取内存最小的numa节点,并对所述内存最小的numa节点进行内存热添加。If it is learned that there is only one numa node in the virtual machine according to the numa node topology information, then directly perform memory hot addition; if it is learned that there are multiple numa nodes in the virtual machine according to the numa node topology information, then obtain the minimum memory numa nodes, and hot add memory to the numa node with the smallest memory.

进一步地,所述通过修改虚拟机管理器的源码对数据库中保存的内存信息和所述虚拟机的当前内存信息进行更新包括:Further, updating the memory information stored in the database and the current memory information of the virtual machine by modifying the source code of the virtual machine manager includes:

通过调用基于内核的kvm虚拟化接口对所述虚拟机进行管理;The virtual machine is managed by calling a kernel-based kvm virtualization interface;

通过修改虚拟化工具libvirt源码,对可扩展标记语言XML中的memory信息进行更新。By modifying the source code of the virtualization tool libvirt, the memory information in the Extensible Markup Language XML is updated.

进一步地,所述进行虚拟机内存热添加包括:Further, the hot adding of virtual machine memory includes:

所述Libvirt通过socket将内存热添加事件发送给qemu;The Libvirt sends the memory hot-add event to qemu through the socket;

所述qemu根据所述内存热添加事件执行内存热添加;The qemu performs memory hot-add according to the memory hot-add event;

在执行所述内存热添加之后,还包括:After performing the memory hot-add, it also includes:

如果所述内存热添加执行失败,则通过libvirt返回处理结果;如果所述内存热添加执行成功,则进行对所述虚拟机的XML中的memory信息进行更新。If the execution of the memory hot addition fails, a processing result is returned through libvirt; if the execution of the memory hot addition is successful, the memory information in the XML of the virtual machine is updated.

图2为本发明实施例的实现虚拟机内存热添加的方法的原理图,如图2所示:Fig. 2 is a schematic diagram of a method for realizing hot addition of virtual machine memory according to an embodiment of the present invention, as shown in Fig. 2:

具体地,代码实现主要包括以下步骤:Specifically, the code implementation mainly includes the following steps:

步骤201:获取虚拟机numa拓扑信息,若只有一个numa节点,则直接进行内存热添加;若有多个node,取出内存最小的node节点,对其进行内存热添加。Step 201: Obtain the numa topology information of the virtual machine. If there is only one numa node, perform memory hot-add directly; if there are multiple nodes, take out the node node with the smallest memory, and perform memory hot-add on it.

步骤202:Libvirt通过socket将内存热插事件发送给qemu,qemu执行内存热添加,若执行失败,则直接跳到204步骤;若成功,则继续进行下面步骤203处理。Step 202: Libvirt sends the memory hot-plug event to qemu through the socket, and qemu executes the memory hot-add, if the execution fails, then directly jump to step 204; if successful, then proceed to the following step 203 for processing.

步骤203:对虚拟机xml中的memory信息进行更新,内存热插后的memory=内存热插前的memory+内存热插的memory。Step 203: update the memory information in the virtual machine xml, memory after memory hot plugging=memory before memory hot plugging+memory after memory hot plugging.

步骤204:libvirt返回处理结果。Step 204: libvirt returns the processing result.

本发明实施例提出了一种基于libvirt的实现虚拟机内存热添加的方法,同时支持迁移与快照。通过修改libvirt源码,在每次成功添加内存后对XML中的memory信息进行更新,保持数据库和VM信息的一致,同时实现内存热插后虚拟机的快照和迁移。通过对libvirt源码的再次开发,进一步完善内存热插功能,提高虚拟化产品的竞争力。通过设计合理的内存热添加方法,在不影响原有功能的同时,根据新的需求,进一步完善了内存热添加功能,增加了虚拟机迁移功能的应用场景。The embodiment of the present invention proposes a libvirt-based method for realizing hot addition of virtual machine memory, and supports migration and snapshot at the same time. By modifying the libvirt source code, the memory information in the XML is updated after each memory is successfully added to keep the database and VM information consistent, and at the same time realize the snapshot and migration of the virtual machine after memory hot plugging. Through the re-development of libvirt source code, the memory hot-swapping function is further improved, and the competitiveness of virtualization products is improved. By designing a reasonable memory hot-add method, without affecting the original functions, the memory hot-add function is further improved according to new requirements, and the application scenarios of the virtual machine migration function are added.

图3为本发明实施例实现虚拟机内存热添加的装置的结构图,如图3所示,本发明实施例另一方面提供的一种实现虚拟机内存热添加的装置,包括:FIG. 3 is a structural diagram of a device for implementing hot addition of virtual machine memory according to an embodiment of the present invention. As shown in FIG. 3 , another aspect of the embodiment of the present invention provides a device for implementing hot addition of virtual machine memory, including:

管理模块300,用于根据虚拟机中各个节点的内存大小进行虚拟机内存热添加;在所述虚拟机内存热添加成功后,通过修改虚拟机管理器的源码对数据库中保存的内存信息和所述虚拟机的当前内存信息进行更新,以保持所述数据库中保存的内存信息和所述虚拟机的当前内存信息的一致。The management module 300 is configured to perform virtual machine memory hot-add according to the memory size of each node in the virtual machine; after the virtual machine memory hot-add is successful, modify the source code of the virtual machine manager to modify the memory information stored in the database and all The current memory information of the virtual machine is updated to keep the memory information stored in the database consistent with the current memory information of the virtual machine.

进一步地,所述装置还包括:Further, the device also includes:

所述虚拟机是使用开源模拟器qemu创建的;The virtual machine is created using the open source emulator qemu;

所述虚拟机管理器为虚拟化工具libvirt。The virtual machine manager is a virtualization tool libvirt.

进一步地,所述装置还包括:Further, the device also includes:

获取模块301,用于获取所述虚拟机的非统一内存访问numa节点拓扑信息;An acquisition module 301, configured to acquire the non-uniform memory access numa node topology information of the virtual machine;

执行模块302,用于如果根据所述numa节点拓扑信息获知所述虚拟机中只有一个numa节点,则直接进行内存热添加;如果根据所述numa节点拓扑信息获知所述虚拟机中有多个numa节点,则获取内存最小的numa节点,并对所述内存最小的numa节点进行内存热添加。The execution module 302 is configured to directly perform memory hot-adding if it is learned that there is only one numa node in the virtual machine according to the numa node topology information; if it is learned that there are multiple numa nodes in the virtual machine according to the numa node topology information node, obtain the numa node with the smallest memory, and perform memory hot-add on the numa node with the smallest memory.

进一步地,所述管理模块300还用于:Further, the management module 300 is also used for:

通过调用基于内核的kvm虚拟化接口对所述虚拟机进行管理;The virtual machine is managed by calling a kernel-based kvm virtualization interface;

通过修改虚拟化工具libvirt源码,对可扩展标记语言XML中的memory信息进行更新。By modifying the source code of the virtualization tool libvirt, the memory information in the Extensible Markup Language XML is updated.

进一步地,所述管理模块300还用于:Further, the management module 300 is also used for:

所述Libvirt通过socket将内存热添加事件发送给qemu;The Libvirt sends the memory hot-add event to qemu through the socket;

所述qemu根据所述内存热添加事件执行内存热添加;The qemu performs memory hot-add according to the memory hot-add event;

在执行所述内存热添加之后,还包括:After performing the memory hot-add, it also includes:

如果所述内存热添加执行失败,则通过libvirt返回处理结果;如果所述内存热添加执行成功,则进行对所述虚拟机的XML中的memory信息进行更新。If the execution of the memory hot addition fails, a processing result is returned through libvirt; if the execution of the memory hot addition is successful, the memory information in the XML of the virtual machine is updated.

虽然本发明所揭露的实施方式如上,但所述的内容仅为便于理解本发明而采用的实施方式,并非用以限定本发明。任何本发明所属领域内的技术人员,在不脱离本发明所揭露的精神和范围的前提下,可以在实施的形式及细节上进行任何的修改与变化,但本发明的专利保护范围,仍须以所附的权利要求书所界定的范围为准。Although the embodiments disclosed in the present invention are as above, the described content is only an embodiment adopted for understanding the present invention, and is not intended to limit the present invention. Anyone skilled in the field of the present invention can make any modifications and changes in the form and details of the implementation without departing from the spirit and scope disclosed by the present invention, but the patent protection scope of the present invention must still be The scope defined by the appended claims shall prevail.

Claims (10)

1.一种实现虚拟机内存热添加的方法,其特征在于,包括:1. A method for realizing hot addition of virtual machine memory, characterized in that, comprising: 根据虚拟机中各个节点的内存大小进行虚拟机内存热添加;在所述虚拟机内存热添加成功后,通过修改虚拟机管理器的源码对数据库中保存的内存信息和所述虚拟机的当前内存信息进行更新,以保持所述数据库中保存的内存信息和所述虚拟机的当前内存信息的一致。According to the memory size of each node in the virtual machine, perform hot addition of virtual machine memory; after the hot addition of virtual machine memory is successful, the memory information stored in the database and the current memory of the virtual machine are compared by modifying the source code of the virtual machine manager The information is updated to keep the memory information stored in the database consistent with the current memory information of the virtual machine. 2.根据权利要求1所述的实现虚拟机内存热添加的方法,其特征在于,2. the method for realizing virtual machine memory hot addition according to claim 1, is characterized in that, 所述虚拟机是使用开源模拟器qemu创建的;The virtual machine is created using the open source emulator qemu; 所述虚拟机管理器为虚拟化工具libvirt。The virtual machine manager is a virtualization tool libvirt. 3.根据权利要求2所述的实现虚拟机内存热添加的方法,其特征在于,所述根据虚拟机中各个节点的内存大小进行虚拟机内存热添加包括:3. The method for realizing hot addition of virtual machine memory according to claim 2, wherein the hot addition of virtual machine memory according to the memory size of each node in the virtual machine comprises: 获取所述虚拟机的非统一内存访问numa节点拓扑信息;Obtain the non-uniform memory access numa node topology information of the virtual machine; 如果根据所述numa节点拓扑信息获知所述虚拟机中只有一个numa节点,则直接进行内存热添加;如果根据所述numa节点拓扑信息获知所述虚拟机中有多个numa节点,则获取内存最小的numa节点,并对所述内存最小的numa节点进行内存热添加。If it is learned that there is only one numa node in the virtual machine according to the numa node topology information, then directly perform memory hot addition; if it is learned that there are multiple numa nodes in the virtual machine according to the numa node topology information, then obtain the minimum memory numa nodes, and hot add memory to the numa node with the smallest memory. 4.根据权利要求3所述的实现虚拟机内存热添加的方法,其特征在于,所述通过修改虚拟机管理器的源码对数据库中保存的内存信息和所述虚拟机的当前内存信息进行更新包括:4. The method for realizing hot addition of virtual machine memory according to claim 3, wherein the memory information stored in the database and the current memory information of the virtual machine are updated by modifying the source code of the virtual machine manager include: 通过调用基于内核的kvm虚拟化接口对所述虚拟机进行管理;The virtual machine is managed by calling a kernel-based kvm virtualization interface; 通过修改虚拟化工具libvirt源码,对可扩展标记语言XML中的memory信息进行更新。By modifying the source code of the virtualization tool libvirt, the memory information in the Extensible Markup Language XML is updated. 5.根据权利要求4所述的实现虚拟机内存热添加的方法,其特征在于,所述进行虚拟机内存热添加包括:5. The method for realizing hot addition of virtual machine memory according to claim 4, wherein said performing hot addition of virtual machine memory comprises: 所述Libvirt通过socket将内存热添加事件发送给qemu;The Libvirt sends the memory hot-add event to qemu through the socket; 所述qemu根据所述内存热添加事件执行内存热添加;The qemu performs memory hot-add according to the memory hot-add event; 在执行所述内存热添加之后,还包括:After performing the memory hot-add, it also includes: 如果所述内存热添加执行失败,则通过libvirt返回处理结果;如果所述内存热添加执行成功,则进行对所述虚拟机的XML中的memory信息进行更新。If the execution of the memory hot addition fails, a processing result is returned through libvirt; if the execution of the memory hot addition is successful, the memory information in the XML of the virtual machine is updated. 6.一种实现虚拟机内存热添加的装置,其特征在于,包括::6. A device for realizing hot addition of virtual machine memory, comprising: 管理模块,用于根据虚拟机中各个节点的内存大小进行虚拟机内存热添加;在所述虚拟机内存热添加成功后,通过修改虚拟机管理器的源码对数据库中保存的内存信息和所述虚拟机的当前内存信息进行更新,以保持所述数据库中保存的内存信息和所述虚拟机的当前内存信息的一致。The management module is used to perform virtual machine memory hot addition according to the memory size of each node in the virtual machine; after the virtual machine memory hot addition is successful, the memory information stored in the database and the memory information stored in the database are modified by modifying the source code of the virtual machine manager. The current memory information of the virtual machine is updated to keep the memory information stored in the database consistent with the current memory information of the virtual machine. 7.根据权利要求6所述的实现虚拟机内存热添加的装置,其特征在于,所述装置还包括:7. The device for realizing hot addition of virtual machine memory according to claim 6, wherein the device further comprises: 所述虚拟机是使用开源模拟器qemu创建的;The virtual machine is created using the open source emulator qemu; 所述虚拟机管理器为虚拟化工具libvirt。The virtual machine manager is a virtualization tool libvirt. 8.根据权利要求7所述的实现虚拟机内存热添加的装置,其特征在于,所述装置还包括:8. The device for realizing hot addition of virtual machine memory according to claim 7, wherein the device further comprises: 获取模块,用于获取所述虚拟机的非统一内存访问numa节点拓扑信息;An acquisition module, configured to acquire the non-uniform memory access numa node topology information of the virtual machine; 执行模块,用于如果根据所述numa节点拓扑信息获知所述虚拟机中只有一个numa节点,则直接进行内存热添加;如果根据所述numa节点拓扑信息获知所述虚拟机中有多个numa节点,则获取内存最小的numa节点,并对所述内存最小的numa节点进行内存热添加。An execution module, configured to directly perform memory hot-add if it is learned that there is only one numa node in the virtual machine according to the numa node topology information; if it is learned that there are multiple numa nodes in the virtual machine according to the numa node topology information , the numa node with the smallest memory is obtained, and memory hot-add is performed on the numa node with the smallest memory. 9.根据权利要求8所述的实现虚拟机内存热添加的装置,其特征在于,所述管理模块还用于:9. The device for realizing hot addition of virtual machine memory according to claim 8, wherein the management module is also used for: 通过调用基于内核的kvm虚拟化接口对所述虚拟机进行管理;The virtual machine is managed by calling a kernel-based kvm virtualization interface; 通过修改虚拟化工具libvirt源码,对可扩展标记语言XML中的memory信息进行更新。By modifying the source code of the virtualization tool libvirt, the memory information in the Extensible Markup Language XML is updated. 10.根据权利要求9所述的实现虚拟机内存热添加的装置,其特征在于,所述管理模块还用于:10. The device for realizing hot addition of virtual machine memory according to claim 9, wherein the management module is also used for: 所述Libvirt通过socket将内存热添加事件发送给qemu;The Libvirt sends the memory hot-add event to qemu through the socket; 所述qemu根据所述内存热添加事件执行内存热添加;The qemu performs memory hot-add according to the memory hot-add event; 在执行所述内存热添加之后,还包括:After performing the memory hot-add, it also includes: 如果所述内存热添加执行失败,则通过libvirt返回处理结果;如果所述内存热添加执行成功,则进行对所述虚拟机的XML中的memory信息进行更新。If the execution of the memory hot addition fails, a processing result is returned through libvirt; if the execution of the memory hot addition is successful, the memory information in the XML of the virtual machine is updated.
CN201710636247.6A 2017-07-26 2017-07-26 A method and device for realizing hot adding of virtual machine memory Active CN107368353B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201710636247.6A CN107368353B (en) 2017-07-26 2017-07-26 A method and device for realizing hot adding of virtual machine memory

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201710636247.6A CN107368353B (en) 2017-07-26 2017-07-26 A method and device for realizing hot adding of virtual machine memory

Publications (2)

Publication Number Publication Date
CN107368353A true CN107368353A (en) 2017-11-21
CN107368353B CN107368353B (en) 2020-12-01

Family

ID=60308707

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710636247.6A Active CN107368353B (en) 2017-07-26 2017-07-26 A method and device for realizing hot adding of virtual machine memory

Country Status (1)

Country Link
CN (1) CN107368353B (en)

Cited By (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108196958A (en) * 2017-12-29 2018-06-22 北京泽塔云科技股份有限公司 Scheduling of resource distribution method, computer system and super fusion architecture system
CN110633130A (en) * 2019-08-29 2019-12-31 上海仪电(集团)有限公司中央研究院 Virtual memory management method and device based on memory hot plug technology
CN110750336A (en) * 2019-10-29 2020-02-04 北京浪潮数据技术有限公司 OpenStack virtual machine memory hot-expanding method
CN111414236A (en) * 2020-03-23 2020-07-14 佳讯飞鸿(北京)智能科技研究院有限公司 Online adjusting method and device for CPU and memory and virtual electronic equipment
CN112286638A (en) * 2020-11-04 2021-01-29 浪潮云信息技术股份公司 Method for realizing hot plug between CPU and memory of Openstack virtual machine
CN113419811A (en) * 2021-05-20 2021-09-21 曙光信息产业股份有限公司 CPU adding method, device, computer device and readable storage medium
CN118312276A (en) * 2024-04-25 2024-07-09 中电云计算技术有限公司 A cloud-native virtual machine GPU device hot-swap management method and system

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102323899A (en) * 2011-09-05 2012-01-18 浪潮电子信息产业股份有限公司 A fault-tolerant operating system memory management method under NUMA architecture
CN102365625A (en) * 2009-03-26 2012-02-29 微软公司 Virtual non-uniform memory architecture for virtual machines
CN104123233A (en) * 2013-04-26 2014-10-29 华茂云天科技(北京)有限公司 Virtual machine high-capacity memory sharing method
US20150058522A1 (en) * 2013-08-22 2015-02-26 International Business Machines Corporation Detection of hot pages for partition migration
CN106648827A (en) * 2016-09-20 2017-05-10 国云科技股份有限公司 A Method of Adding Virtual Machine Resources Online

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102365625A (en) * 2009-03-26 2012-02-29 微软公司 Virtual non-uniform memory architecture for virtual machines
CN102323899A (en) * 2011-09-05 2012-01-18 浪潮电子信息产业股份有限公司 A fault-tolerant operating system memory management method under NUMA architecture
CN104123233A (en) * 2013-04-26 2014-10-29 华茂云天科技(北京)有限公司 Virtual machine high-capacity memory sharing method
US20150058522A1 (en) * 2013-08-22 2015-02-26 International Business Machines Corporation Detection of hot pages for partition migration
CN106648827A (en) * 2016-09-20 2017-05-10 国云科技股份有限公司 A Method of Adding Virtual Machine Resources Online

Cited By (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108196958A (en) * 2017-12-29 2018-06-22 北京泽塔云科技股份有限公司 Scheduling of resource distribution method, computer system and super fusion architecture system
CN110633130A (en) * 2019-08-29 2019-12-31 上海仪电(集团)有限公司中央研究院 Virtual memory management method and device based on memory hot plug technology
CN110633130B (en) * 2019-08-29 2023-10-31 上海仪电(集团)有限公司中央研究院 Virtual memory management method and device based on memory hot plug technology
CN110750336A (en) * 2019-10-29 2020-02-04 北京浪潮数据技术有限公司 OpenStack virtual machine memory hot-expanding method
CN110750336B (en) * 2019-10-29 2022-06-17 北京浪潮数据技术有限公司 OpenStack virtual machine memory hot-expanding method
CN111414236A (en) * 2020-03-23 2020-07-14 佳讯飞鸿(北京)智能科技研究院有限公司 Online adjusting method and device for CPU and memory and virtual electronic equipment
CN111414236B (en) * 2020-03-23 2024-06-28 佳讯飞鸿(北京)智能科技研究院有限公司 Online adjustment method and device for CPU and memory and virtual electronic equipment
CN112286638A (en) * 2020-11-04 2021-01-29 浪潮云信息技术股份公司 Method for realizing hot plug between CPU and memory of Openstack virtual machine
CN113419811A (en) * 2021-05-20 2021-09-21 曙光信息产业股份有限公司 CPU adding method, device, computer device and readable storage medium
CN118312276A (en) * 2024-04-25 2024-07-09 中电云计算技术有限公司 A cloud-native virtual machine GPU device hot-swap management method and system

Also Published As

Publication number Publication date
CN107368353B (en) 2020-12-01

Similar Documents

Publication Publication Date Title
CN107368353B (en) A method and device for realizing hot adding of virtual machine memory
US10871980B2 (en) Execution of a script based on properties of a virtual device associated with a virtual machine
US11487523B2 (en) Updating machine emulator
CN107534571B (en) Method, system, and computer-readable medium for managing virtual network functions
US7451443B2 (en) Online computer maintenance utilizing a virtual machine monitor
EP2881860B1 (en) Method for implementing an interrupt between virtual processors, related device, and system
US20130227551A1 (en) System and method for hypervisor version migration
CN107423619B (en) Method for constructing WEB operation of intelligent terminal based on virtualization technology
US20150121377A1 (en) Method for implementing inter-virtual processor interrupt, related apparatus, and system
JP2022513382A (en) Methods, devices and computer storage media for achieving function jumps
CN111459609B (en) Virtual machine security protection method, device and electronic device
CN102307208A (en) Virtual machine operation control device and operation control method based on cloud computing
CN104111867B (en) A kind of virtual machine (vm) migration device and method
CN103383650A (en) Management method and system thereof
CN102799465A (en) Virtual interrupt management method and device of distributed virtual system
CN111506389A (en) Virtual machine starting method and device
US20160246628A1 (en) Status indicator for a merge operation associated with a virtual machine
CN107844304B (en) Virtual machine hot upgrading method and device
WO2016177261A1 (en) Method and device for online upgrading module based on kernel virtual machine
WO2025113399A1 (en) Method and apparatus for managing virtual machine, device, and storage medium
US20200174814A1 (en) Systems and methods for upgrading hypervisor locally
CN111190693B (en) Method and device for building cloud platform based on Kunpeng platform
CN101470657A (en) Verification method for BIOS refreshing content
CN112948102A (en) Virtual machine event processing method, device and system
CN104182271A (en) Virtualization implementation method based on SW processor

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant