CN107168766B - Virtual machine memory management method and device and virtual machine manager - Google Patents

Virtual machine memory management method and device and virtual machine manager Download PDF

Info

Publication number
CN107168766B
CN107168766B CN201610130620.6A CN201610130620A CN107168766B CN 107168766 B CN107168766 B CN 107168766B CN 201610130620 A CN201610130620 A CN 201610130620A CN 107168766 B CN107168766 B CN 107168766B
Authority
CN
China
Prior art keywords
memory
virtual machine
virtual
balloon
page
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.)
Active
Application number
CN201610130620.6A
Other languages
Chinese (zh)
Other versions
CN107168766A (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.)
Sangfor Technologies Co Ltd
Original Assignee
Sangfor Technologies 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 Sangfor Technologies Co Ltd filed Critical Sangfor Technologies Co Ltd
Priority to CN201610130620.6A priority Critical patent/CN107168766B/en
Publication of CN107168766A publication Critical patent/CN107168766A/en
Application granted granted Critical
Publication of CN107168766B publication Critical patent/CN107168766B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

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
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/08Addressing or allocation; Relocation in hierarchically structured memory systems, e.g. virtual memory systems
    • G06F12/0802Addressing of a memory level in which the access to the desired data or data block requires associative addressing means, e.g. caches
    • G06F12/0877Cache access modes
    • G06F12/0882Page mode
    • 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
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2212/00Indexing scheme relating to accessing, addressing or allocation within memory systems or architectures
    • G06F2212/10Providing a specific technical effect
    • G06F2212/1008Correctness of operation, e.g. memory ordering
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2212/00Indexing scheme relating to accessing, addressing or allocation within memory systems or architectures
    • G06F2212/15Use in a specific computing environment
    • G06F2212/152Virtualized environment, e.g. logically partitioned system

Abstract

The invention relates to a virtual machine memory management method and device and a virtual machine manager, wherein the method comprises the following steps: sending a memory balloon expansion instruction to the virtual machine, wherein the memory balloon expansion instruction carries the amount of memory to be recovered, so that the virtual machine increases the volume of the memory balloon according to the amount of memory to be recovered; receiving a memory occupation notification, acquiring a virtual memory page identifier occupied when the volume of a memory balloon carried in the memory occupation notification is increased, and recovering a first physical memory page corresponding to the occupied virtual memory page identifier; sending a memory balloon contraction instruction to enable the virtual machine to reduce the volume of the increased memory balloon to zero so as to enable the memory space corresponding to the recovered first physical memory page to form a memory cavity; and receiving an access request for the virtual memory page in the memory hole, and allocating a second physical memory page to the virtual memory page requested to be accessed according to the access request. The influence on the system performance due to memory recovery is avoided, the memory is guaranteed to return in time, and the applicability is improved.

Description

Virtual machine memory management method and device and virtual machine manager
Technical Field
The present invention relates to the field of virtualization technologies, and in particular, to a method and an apparatus for managing a memory of a virtual machine, and a virtual machine manager.
Background
In the field of virtualization technology, it is common to implement on-demand allocation of memory resources of virtual machines by a memory over-allocation technology (memory over-allocation refers to that the sum of configured memories of a plurality of virtual machines currently running on a physical host is greater than the physical memory of the physical host). In this way, the internal memory of the virtual machine cannot be directly accessed, but the Hypervisor (a virtual machine manager, a device running on the physical host and implementing a virtualization function) allocates and recovers the physical memory for the virtual machine according to the requirement of the virtual machine on the memory, so as to implement the on-demand allocation of the physical memory.
The balloon technology is a popular virtual machine memory super-allocation technology in the field of virtualization technology. However, in the conventional memory balloon technology, the virtual machine operating system considers that the portion of physical memory corresponding to the memory space in the memory balloon is occupied, and determines that the available memory is insufficient to perform some special operations, for example, the swap partition is started to be used, thereby adversely affecting the system performance.
In addition, because the recovery and the return of the memory in the traditional method are controlled by the Hypervisor, the Hypervisor needs to dynamically balance the recovery and the return of all the memories of the virtual machines, and the control strategy of the Hypervisor is more complex as the number of the virtual machines is larger, so that the method cannot be applied to a large-scale deployment scene. In addition, under the condition that the memory is returned by monitoring the memory use condition of the virtual machine according to the Hypervisor, the monitoring has hysteresis and the memory returning speed is limited, so that the situation that the system is blocked or crashed due to insufficient memory is easily caused because the operating system of the virtual machine suddenly uses a larger memory and the memory is not returned in time.
Disclosure of Invention
In view of the foregoing, it is desirable to provide a method and an apparatus for managing a virtual machine memory, and a virtual machine manager, which are capable of returning a memory in time without affecting the operating performance of a virtual machine operating system due to memory recovery and have high applicability.
A virtual machine memory management method is applied to a virtual machine manager and comprises the following steps:
sending a memory balloon expansion instruction to a virtual machine, wherein the memory balloon expansion instruction carries the memory amount to be recovered, so that the virtual machine increases the volume of the memory balloon according to the memory amount to be recovered to occupy a virtual memory page;
receiving a memory occupation notification sent by a virtual machine, acquiring a virtual memory page identifier occupied when the volume of a memory balloon carried in the memory occupation notification is increased, and recovering a first physical memory page corresponding to the occupied virtual memory page identifier;
sending a memory balloon contraction instruction to the virtual machine, so that the virtual machine reduces the volume of the increased memory balloon to zero, and a memory space corresponding to the recovered first physical memory page in the virtual machine forms a memory cavity;
and receiving an access request sent by a virtual machine to the virtual memory page in the memory hole, and allocating a second physical memory page to the virtual memory page requested to be accessed according to the access request.
In one embodiment, the step of recovering the first physical memory page corresponding to the occupied virtual memory page identifier includes:
correspondingly marking the occupied virtual memory page identification through a bitmap;
and receiving a memory occupation stop notice sent by the virtual machine, and recovering the first physical memory page with continuous addresses corresponding to the marked virtual memory page identification at one time.
A virtual machine memory management method is applied to a virtual machine and comprises the following steps:
receiving a memory balloon expansion instruction sent by a virtual machine manager, wherein the memory balloon expansion instruction carries the amount of memory to be recovered, and increasing the volume of the memory balloon according to the amount of the memory to be recovered;
sending a memory occupation notification to a virtual machine manager, wherein the memory occupation notification carries a virtual memory page identifier occupied when the memory balloon volume is increased, so that the virtual machine manager recovers a corresponding first physical memory page according to the occupied virtual memory page identifier;
receiving a memory balloon contraction instruction sent by a virtual machine manager, and reducing the volume of a memory balloon to zero according to the memory balloon contraction instruction so as to enable a memory space corresponding to a recovered first physical memory page to form a memory cavity;
and sending an access request for the virtual memory page in the memory hole to the virtual machine manager, so that the virtual machine manager allocates a second physical memory page to the virtual memory page requested to be accessed according to the access request.
In one embodiment, before the step of reducing the volume of the memory balloon to zero according to the memory balloon contraction instruction, the method further includes:
the memory page auto-zero mechanism is closed by the virtualization plug-in.
In one embodiment, the method further comprises:
when the memory balloon volume is increased according to the memory amount to be recovered, checking the residual physical memory amount corresponding to the virtual machine, and when the residual physical memory amount reaches a preset safety threshold value, stopping increasing the memory balloon volume.
A virtual machine manager, the virtual machine manager comprising:
the instruction sending module is used for sending a memory balloon expansion instruction to the virtual machine, wherein the memory balloon expansion instruction carries the memory amount to be recovered, so that the virtual machine increases the volume of the memory balloon according to the memory amount to be recovered to occupy a virtual memory page;
the memory recovery module is used for receiving a memory occupation notification sent by the virtual machine, acquiring a virtual memory page identifier occupied when the volume of a memory balloon carried in the memory occupation notification is increased, and recovering a first physical memory page corresponding to the occupied virtual memory page identifier;
the instruction sending module is further configured to send a memory balloon contraction instruction to the virtual machine, so that the virtual machine reduces the volume of the increased memory balloon to zero, and a memory space corresponding to the recovered first physical memory page in the virtual machine forms a memory cavity;
and the memory returning module is used for receiving an access request sent by the virtual machine to the virtual memory page in the memory cavity, and allocating a second physical memory page to the virtual memory page requested to be accessed according to the access request.
In one embodiment, the memory recovery module is further configured to mark the occupied virtual memory page identifier correspondingly through a bitmap; and receiving a memory occupation stop notice sent by the virtual machine, and recovering the first physical memory page with continuous addresses corresponding to the marked virtual memory page identification at one time.
A virtual machine memory management apparatus, the apparatus comprising:
the volume increasing module is used for receiving a memory balloon expansion instruction sent by the virtual machine manager, wherein the memory balloon expansion instruction carries the amount of memory to be recovered, and the volume of the memory balloon is increased according to the amount of the memory to be recovered;
the sending module is used for sending a memory occupation notification to the virtual machine manager, wherein the memory occupation notification carries a virtual memory page identifier occupied when the memory balloon volume is increased, so that the virtual machine manager can recover a corresponding first physical memory page according to the occupied virtual memory page identifier;
the volume shrinkage module is used for receiving a memory balloon shrinkage instruction sent by the virtual machine manager, and reducing the volume of the memory balloon to zero according to the memory balloon shrinkage instruction so as to enable a memory space corresponding to the recovered first physical memory page to form a memory cavity;
the sending module is further configured to send an access request for the virtual memory page in the memory cavity to the virtual machine manager, so that the virtual machine manager allocates a second physical memory page to the virtual memory page requested to be accessed according to the access request.
In one embodiment, the apparatus further comprises:
and the automatic zero setting closing module is used for closing the automatic zero setting mechanism of the memory page through the virtualization plug-in.
In one embodiment, the apparatus further comprises:
and the residual memory checking module is used for checking the residual physical memory amount corresponding to the virtual machine when the memory balloon volume is increased according to the memory amount to be recovered, and informing the volume increasing module to stop increasing the memory balloon volume when the residual physical memory amount reaches a preset safety threshold value.
According to the virtual machine memory management method and device and the virtual machine manager, the memory balloon is expanded through the memory balloon expansion instruction to occupy the virtual memory pages, the first physical memory pages corresponding to the occupied virtual memory page identifiers are recovered, the volume of the increased memory balloon is reduced to zero through the memory balloon contraction instruction, the memory space corresponding to the recovered first physical memory pages in the virtual machine forms a memory cavity, and when an access request sent by the virtual machine to the virtual memory pages in the memory cavity is received, the virtual memory pages requested to be accessed are allocated with the second physical memory pages. By establishing the memory hole mode, when the physical memory is recycled, the virtual machine cannot feel that the memory is occupied, so that the influence on the system performance caused by the fact that the virtual machine mistakenly considers that the memory is insufficient and performs some special operations is avoided. In addition, when the memory is returned, the virtual machine manager is not required to monitor the memory use conditions of all the virtual machines uniformly, the automatic return of the memory as required is realized, the memory is ensured to be returned in time, the applicability is improved, and the method and the device are suitable for large-scale deployment scenes.
Drawings
FIG. 1 is a flowchart illustrating a method for managing memory of a virtual machine according to an embodiment;
FIGS. 2A-2B are schematic diagrams of memory holes in one embodiment;
FIG. 3 is a flowchart illustrating a physical memory page reclamation method in one embodiment;
FIG. 4 is a flowchart illustrating a method for managing memory of a virtual machine according to another embodiment;
FIG. 5 is a block diagram that illustrates a virtual machine manager, according to one embodiment;
FIG. 6 is a block diagram illustrating an embodiment of a VM memory management device;
FIG. 7 is a block diagram of an embodiment of a VM memory management device;
fig. 8 is a schematic structural diagram of a virtual machine memory management apparatus according to another embodiment.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention will be described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
As shown in fig. 1, in an embodiment, a method for managing a virtual machine memory is provided, where the method is applied to a virtual machine manager, where the virtual machine manager may be configured to monitor and manage a virtual machine physical memory allocation situation, and the virtual machine manager runs in a physical host running a plurality of virtual machines, and the method specifically includes the following steps:
step 102, sending a memory balloon expansion instruction to the virtual machine, wherein the memory balloon expansion instruction carries the amount of memory to be recovered, so that the virtual machine increases the volume of the memory balloon according to the amount of memory to be recovered to occupy a virtual memory page.
In this embodiment, the virtual machine manager sends a memory balloon expansion instruction to the virtual machine, where the memory balloon expansion instruction carries an amount of memory to be recovered. After receiving the memory balloon expansion instruction, the virtual machine calls a balloon driver which is pre-installed in an operating system of the virtual machine, and the balloon driver increases the memory balloon to a corresponding volume according to the memory amount to be recovered, wherein when the volume of the memory balloon is increased, the memory pages in the memory balloon are occupied virtual memory pages.
Step 104, receiving a memory occupation notification sent by the virtual machine, acquiring a virtual memory page identifier occupied when the volume of the memory balloon carried in the memory occupation notification is increased, and recovering a first physical memory page corresponding to the occupied virtual memory page identifier.
In this embodiment, when the balloon driver in the virtual machine increases the volume of the memory balloon to occupy the virtual memory page, the balloon driver sends a memory occupancy notification to the virtual machine manager, where the memory occupancy notification carries the virtual memory page identifier corresponding to the virtual memory page occupied when the volume of the memory balloon is increased, so as to notify the virtual machine manager of which virtual memory is occupied.
Further, the virtual machine manager acquires the occupied virtual memory page identifier carried in the memory occupancy notification, and recovers the first physical memory page corresponding to the occupied virtual memory page identifier. Specifically, the virtual machine manager may release the mapping relationship from the virtual memory page corresponding to the occupied virtual memory page identifier to the physical memory page, so as to recover the corresponding first physical memory page.
It should be noted that the balloon driver in the virtual machine may send the memory occupancy notification to the virtual machine manager while increasing the volume of the memory balloon, for example, when the volume of the memory balloon occupies a preset number of memory pages, the balloon driver sends the memory occupancy notification to the virtual machine manager, where the memory occupancy notification carries virtual memory page identifiers corresponding to the occupied preset number of virtual memory pages, and it can be understood that the preset number may be at least one page. In addition, the balloon driver in the virtual machine may also send a memory occupancy notification to the virtual machine manager after stopping increasing the memory balloon volume, where the memory occupancy notification carries the total virtual memory page identifier occupied in the memory balloon. The embodiment of the present invention is not limited when the virtual machine sends the memory occupation notification to the virtual machine manager.
Step 106, sending a memory balloon contraction instruction to the virtual machine, so that the virtual machine reduces the volume of the increased memory balloon to zero, so that a memory space corresponding to the recovered first physical memory page in the virtual machine forms a memory cavity.
In this embodiment, after the virtual machine manager recovers the corresponding first physical memory page, the virtual machine manager further sends a memory balloon contraction instruction to the virtual machine. And the virtual machine reduces the volume of the increased memory balloon to zero according to the memory balloon contraction instruction. Thus, the memory space of the first physical memory page recycled in step 104 corresponding to the virtual machine forms a memory hole.
Explaining the method for establishing the memory hole with reference to fig. 2A to 2B, as shown in fig. 2A, fig. 2A shows a memory usage situation of a virtual machine in which 8G memory is preconfigured, M1 is 7G free memory, M2 is 1G used memory, balloon driver of the virtual machine receives a memory balloon expansion instruction of a virtual machine manager, the memory balloon expands to occupy the entire memory space of M1, the virtual machine manager recovers 7G memory occupied by the memory balloon, and then sends a balloon contraction instruction to the virtual machine, the balloon driver contracts the memory balloon volume to zero, and then the memory space previously occupied by the memory balloon corresponding to the recovered first physical memory page forms a hole memory, as shown in fig. 2B, M3 in fig. 2B is the formed 7G hole memory.
A memory hole is a memory space, and a memory page in the memory space appears to a virtual machine as an available and unoccupied memory, but in reality, a physical memory page corresponding to a virtual machine memory page in the memory space has been recovered by a virtual machine manager, so the memory space is a memory hole. It can be appreciated that because the memory balloon shrinks to zero, the virtual machine does not perceive that the portion of memory in the memory hole is occupied, i.e., the virtual machine considers the portion of memory in the memory hole to be available. However, the physical memory pages corresponding to the virtual memory pages in the memory holes are already recycled, so the recycled physical memory pages can be allocated to other virtual machines in need by the virtual machine manager.
Step 108, receiving an access request sent by the virtual machine to the virtual memory page in the memory cavity, and allocating a second physical memory page to the virtual memory page requested to be accessed according to the access request.
Further, when a program running in the virtual machine operating system needs to access a virtual memory page in the memory hole, the virtual machine may send an access request for the virtual memory page in the memory hole to the virtual machine manager, and after the virtual machine manager receives the access request for the virtual memory page in the memory hole, the virtual machine manager may allocate a second physical memory page to the virtual memory page requested to be accessed according to the access request. Specifically, the virtual machine manager may determine, according to the access request, the number of virtual memory pages requested to be accessed, and further allocate a corresponding second physical memory page from the remaining idle physical memory pages, that is, establish a mapping relationship of physical memory pages for the virtual memory pages requested to be accessed, that is, implement allocation of the second physical memory page. For example, if the number of the virtual memory pages requested to be accessed is 2G, the virtual machine manager allocates a corresponding second physical memory page from the remaining idle physical memory pages according to the access request, that is, allocates the 2G physical memory pages correspondingly, and further establishes a mapping relationship between the virtual memory page requested to be accessed and the allocated second physical memory page.
In this embodiment, a memory balloon expansion instruction is sent to the virtual machine, so that a first physical memory page corresponding to a virtual memory page identifier occupied by the memory balloon during expansion is recovered, a memory space corresponding to the recovered first physical memory page in the virtual machine forms a memory cavity by sending a memory balloon contraction instruction to the virtual machine, and when a program in the virtual machine requests to access a virtual memory page in the memory cavity, a second physical memory page is allocated to the virtual memory page requested to be accessed. By establishing the memory hole mode, when the physical memory is recycled, the virtual machine cannot feel that the memory is occupied, so that the influence on the system performance caused by the fact that the virtual machine mistakenly considers that the memory is insufficient and performs some special operations is avoided. In addition, when the memory is returned, the virtual machine manager is not required to monitor the memory use conditions of all the virtual machines uniformly, the automatic return of the memory as required is realized, the memory is ensured to be returned in time, the applicability is improved, and the method and the device are suitable for large-scale deployment scenes.
As shown in fig. 3, in an embodiment, the step of reclaiming the first physical memory page corresponding to the occupied virtual memory page identifier (physical memory page reclaiming step for short) includes:
step 302, correspondingly marking the occupied virtual memory page identifier through a bitmap.
Step 304, receiving a memory occupation stop notification sent by the virtual machine, and performing one-time recovery on the first physical memory page with continuous addresses corresponding to the marked virtual memory page identifier.
In this embodiment, after obtaining the virtual memory page identifier occupied when the volume of the memory balloon carried in the memory occupancy notification sent by the virtual machine is increased, the occupied virtual memory page identifier is further correspondingly marked by a Bitmap (Bitmap).
After stopping increasing the balloon volume, the virtual machine sends a memory occupation stop notification to the virtual machine manager, and the virtual machine manager judges which virtual memory pages correspond to the continuous first physical memory page addresses according to the marks of the virtual memory page identifiers on the bitmap, and recycles the continuous first physical memory pages. The one-time recycling means that the virtual machine manager only calls an Application Programming Interface (API) once to recycle the part of the first physical memory pages with consecutive addresses together.
It can be understood that the virtual machine manager needs to call the API interface to recover the physical memory page when recovering the physical memory page, where the API interface is called only once to recover the first physical memory page with continuous addresses, and compared with a conventional method in which an occupied memory page identifier is obtained and the API interface is called once to perform a corresponding physical memory page (i.e., the physical memory page is recovered page by page in the conventional method), the number of times of calling the API interface is greatly reduced, thereby improving the recovery efficiency of the physical memory page.
As shown in fig. 4, in an embodiment, a method for managing a memory of a virtual machine is provided, which is described by taking the method as an example of being applied to a virtual machine, where the method is applicable to various types of operating systems in the virtual machine, and the virtual machine runs in a physical host, and the method specifically includes the following steps:
step 402, receiving a memory balloon expansion instruction sent by a virtual machine manager, wherein the memory balloon expansion instruction carries the amount of memory to be recovered, and increasing the volume of the memory balloon according to the amount of memory to be recovered.
In this embodiment, the virtual machine manager sends a memory balloon expansion instruction to the virtual machine, where the memory balloon expansion instruction carries an amount of memory to be recovered. After receiving the memory balloon expansion instruction, the virtual machine calls a balloon driver which is pre-installed in an operating system of the virtual machine, and the balloon driver increases the memory balloon to a corresponding volume according to the memory amount to be recovered, wherein when the volume of the memory balloon is increased, the memory pages in the memory balloon are occupied virtual memory pages.
Step 404, sending a memory occupancy notification to the virtual machine manager, where the memory occupancy notification carries the virtual memory page identifier occupied when the memory balloon volume is increased, so that the virtual machine manager recovers the corresponding first physical memory page according to the occupied virtual memory page identifier.
In this embodiment, when the balloon driver in the virtual machine increases the volume of the memory balloon to occupy the virtual memory page, the balloon driver sends a memory occupancy notification to the virtual machine manager, where the memory occupancy notification carries the virtual memory page identifier corresponding to the virtual memory page occupied when the volume of the memory balloon is increased, so as to notify the virtual machine manager of which memory is occupied.
Further, the virtual machine manager acquires the occupied virtual memory page identifier carried in the memory occupancy notification, and recovers the physical memory page corresponding to the occupied virtual memory page identifier. Specifically, the virtual machine manager may release the mapping relationship from the virtual memory page corresponding to the occupied virtual memory page identifier to the physical memory page, so as to recover the corresponding physical memory page.
It should be noted that the balloon driver in the virtual machine may send the memory occupancy notification to the virtual machine manager while increasing the volume of the memory balloon, for example, by increasing the volume of the memory balloon to occupy a preset number of memory pages, send the memory occupancy notification to the virtual machine manager, where the memory occupancy notification carries virtual memory page identifiers corresponding to the occupied preset number of virtual memory pages, it can be understood that the preset number may be at least one page. In addition, the balloon driver in the virtual machine may also send a memory occupancy notification to the virtual machine manager after stopping increasing the memory balloon volume, where the memory occupancy notification carries the total virtual memory page identifier occupied in the memory balloon. The embodiment of the present invention is not limited when the virtual machine sends the memory occupation notification to the virtual machine manager.
Step 406, receiving a memory balloon contraction instruction sent by the virtual machine manager, and reducing the volume of the memory balloon to zero according to the memory balloon contraction instruction, so that a memory cavity is formed in a memory space corresponding to the recovered first physical memory page.
In this embodiment, after the virtual machine manager recovers the corresponding physical memory page, the virtual machine manager further sends a memory balloon contraction instruction to the virtual machine. And the virtual machine reduces the volume of the increased memory balloon to zero according to the memory balloon contraction instruction. Thus, the physical memory page recycled in step 104 forms a memory hole in the corresponding memory space of the virtual machine.
The memory hole is a memory space, and a memory page in the memory space appears to the virtual machine as an available and unoccupied memory, but in reality, a physical memory page corresponding to a virtual machine memory page in the memory space has been recovered by the virtual machine manager, so the memory space is used as the memory hole. It can be appreciated that because the memory balloon shrinks to zero, the virtual machine does not perceive that the portion of memory in the memory hole is occupied, i.e., the virtual machine considers the portion of memory in the memory hole to be available. However, the physical memory pages corresponding to the virtual memory pages in the memory holes are already recycled, so the recycled physical memory pages can be allocated to other virtual machines in need by the virtual machine manager.
Step 408, sending an access request for the virtual memory page in the memory cavity to the virtual machine manager, so that the virtual machine manager allocates a second physical memory page to the virtual memory page requested to be accessed according to the access request.
Further, when a program running in the virtual machine operating system needs to access a virtual memory page in the memory hole, the virtual machine may send an access request for the virtual memory page in the memory hole to the virtual machine manager, and after receiving the access request for the virtual memory page in the memory hole, the virtual machine manager may allocate a physical memory page for the virtual memory page requested to be accessed according to the access request. Specifically, the virtual machine manager may determine, according to the access request, the number of virtual memory pages requested to be accessed, and further allocate a corresponding second physical memory page from the remaining idle physical memory pages, that is, establish a mapping relationship of physical memory pages for the virtual memory pages requested to be accessed, that is, implement allocation of the second physical memory page.
In one embodiment, before the step of reducing the volume of the memory balloon to zero according to the memory balloon contraction instruction, the method further comprises the step of closing an automatic zero mechanism of the memory page through the virtualization plug-in.
In this embodiment, before the volume of the memory balloon is reduced to zero according to the memory balloon contraction instruction (i.e., before the step of establishing the memory hole), for some operating systems having the memory page auto-zero mechanism, the memory page auto-zero mechanism needs to be turned off. Specifically, the virtual machine may close the memory page auto-zero mechanism through a virtualization plug-in preinstalled in the virtual machine. Taking a windows system as an example, a zero-page thread in the windows system can be suspended through a virtualization plug-in, so that the closing of an automatic memory page zeroing mechanism is realized. It will be appreciated that this step may be omitted for operating systems where there is no memory page auto-zero mechanism.
It can be understood that, when the memory balloon shrinks to zero to form a memory hole, the memory in the memory hole is available to the virtual machine, so the virtual machine may consider that there is a memory release, and then the virtual machine may execute the memory page auto-zero mechanism to perform an auto-zero operation, where the auto-zero operation may cause the physical memory page that has been recycled to be remapped again, and cause the physical memory page that has been recycled to be returned due to the auto-zero operation. Therefore, the memory page auto-zero mechanism needs to be closed before the memory hole is established.
Further, the memory page auto-zero mechanism in the virtual machine operating system may be closed when the virtual machine operating system is started, or the step of closing the memory page auto-zero mechanism may be executed at any step before the memory hole is established. The embodiment of the present invention is not limited to this, and it is only required to close the automatic memory page zeroing mechanism before the memory hole is established, so that the automatic memory page zeroing mechanism does not interfere with and destroy the memory hole.
In one embodiment, the method for virtual machine memory management further includes the following steps: when the memory balloon volume is increased according to the memory amount to be recovered, checking the residual physical memory amount corresponding to the virtual machine, and when the residual physical memory amount reaches a preset safety threshold value, stopping increasing the memory balloon volume.
In this embodiment, a security check mechanism is added to a balloon driver of a virtual machine, and a security threshold is preset, when the balloon driver increases the volume of the memory balloon according to the amount of memory to be recovered, the balloon driver checks the number of remaining virtual machine memory pages through the security check mechanism, that is, checks the amount of remaining virtual memory, and determines, according to a mapping relationship between the virtual memory pages and the physical memory pages, the amount of remaining physical memory corresponding to the amount of remaining virtual memory, that is, determines the amount of remaining physical memory corresponding to the virtual machine. And when the remaining physical memory amount corresponding to the virtual machine reaches a preset safety threshold value, stopping increasing the memory balloon volume.
Further, the virtual machine may send a notification to the virtual machine manager through the balloon driver that the memory occupancy stopped.
It is understood that the safety threshold may be set differently according to actual conditions.
In this embodiment, by adding a security check mechanism to the balloon driver, when the volume of the memory balloon is increased, it is checked whether the remaining physical memory amount corresponding to the number of remaining virtual machine memory pages exceeds a preset security threshold, and when the remaining physical memory amount reaches the preset security threshold, the increase of the volume of the memory balloon is stopped. The method and the device avoid the memory exhaustion of the virtual machine operating system caused by the overlarge amount of the memory required to be recovered according to the virtual machine manager, avoid the situation that the operating system is blocked or crashed due to the memory recovery, and realize that the normal work of the operating system is not influenced when the memory is recovered.
As shown in fig. 5, in one embodiment, there is provided a virtual machine manager comprising:
the instruction sending module 502 is configured to send a memory balloon expansion instruction to the virtual machine, where the memory balloon expansion instruction carries a memory amount to be recovered, so that the virtual machine increases the volume of the memory balloon according to the memory amount to be recovered to occupy a virtual memory page.
The memory recovery module 504 is configured to receive a memory occupancy notification sent by the virtual machine, acquire a virtual memory page identifier occupied when the volume of the memory balloon carried in the memory occupancy notification is increased, and recover a first physical memory page corresponding to the occupied virtual memory page identifier.
The instruction sending module 502 is further configured to send a memory balloon contraction instruction to the virtual machine, so that the virtual machine reduces the volume of the increased memory balloon to zero, so that a memory space corresponding to the recovered first physical memory page in the virtual machine forms a memory cavity.
A memory returning module 506, configured to receive an access request sent by a virtual machine to a virtual memory page in a memory cavity, and allocate a second physical memory page to the virtual memory page requested to be accessed according to the access request.
In an embodiment, the memory recovery module 504 is further configured to correspondingly mark the occupied virtual memory page identifier through a bitmap; and receiving a memory occupation stop notice sent by the virtual machine, and recovering the first physical memory page with continuous addresses corresponding to the marked virtual memory page identification at one time.
As shown in fig. 6, in one embodiment, there is provided a virtual machine memory management apparatus, including:
the volume increasing module 602 is configured to receive a memory balloon expansion instruction sent by the virtual machine manager, where the memory balloon expansion instruction carries an amount of memory to be recovered, and increase the volume of the memory balloon according to the amount of memory to be recovered.
A sending module 604, configured to send a memory occupancy notification to the virtual machine manager, where the memory occupancy notification carries a virtual memory page identifier occupied when the volume of the memory balloon is increased, so that the virtual machine manager retrieves the corresponding first physical memory page according to the occupied virtual memory page identifier.
The volume shrinking module 606 is configured to receive a memory balloon shrinking instruction sent by the virtual machine manager, and shrink the volume of the memory balloon to zero according to the memory balloon shrinking instruction, so that a memory cavity is formed in a memory space corresponding to the recovered first physical memory page.
The sending module 604 is further configured to send an access request for a virtual memory page in the memory cavity to the virtual machine manager, so that the virtual machine manager allocates a second physical memory page to the virtual memory page requested to be accessed according to the access request.
As shown in fig. 7, in one embodiment, the apparatus further comprises:
an auto-zero closing module 605, configured to close the auto-zero mechanism of the memory page through the virtualization plug-in.
As shown in fig. 8, in one embodiment, the apparatus further comprises:
the remaining memory checking module 603 is configured to check the remaining physical memory amount corresponding to the virtual machine when the memory balloon volume is increased according to the memory amount to be recovered, and notify the volume increasing module 602 to stop increasing the memory balloon volume when the remaining physical memory amount reaches a preset security threshold.
The technical features of the embodiments described above may be arbitrarily combined, and for the sake of brevity, all possible combinations of the technical features in the embodiments described above are not described, but should be considered as being within the scope of the present specification as long as there is no contradiction between the combinations of the technical features.
The above-mentioned embodiments only express several embodiments of the present invention, and the description thereof is more specific and detailed, but not construed as limiting the scope of the invention. It should be noted that, for a person skilled in the art, several variations and modifications can be made without departing from the inventive concept, which falls within the scope of the present invention. Therefore, the protection scope of the present patent shall be subject to the appended claims.

Claims (8)

1. A virtual machine memory management method is applied to a virtual machine manager and comprises the following steps:
sending a memory balloon expansion instruction to a virtual machine, wherein the memory balloon expansion instruction carries the memory amount to be recovered, so that the virtual machine increases the volume of the memory balloon according to the memory amount to be recovered to occupy a virtual memory page;
receiving a memory occupation notification sent by the virtual machine, acquiring a virtual memory page identifier occupied when the volume of the memory balloon carried in the memory occupation notification is increased, and recovering a first physical memory page corresponding to the occupied virtual memory page identifier;
sending a memory balloon contraction instruction to the virtual machine, enabling the virtual machine to suspend a zero-page thread in an operating system through a virtualization plug-in to close an automatic memory page zeroing mechanism, and reducing the volume of the increased memory balloon to zero so that a memory space corresponding to a first physical memory page recycled in the virtual machine forms a memory cavity;
and receiving an access request sent by the virtual machine to the virtual memory page in the memory hole, and allocating a second physical memory page to the virtual memory page requested to be accessed according to the access request.
2. The method according to claim 1, wherein the step of reclaiming the first physical memory page corresponding to the occupied virtual memory page identifier includes:
correspondingly marking the occupied virtual memory page identification through a bitmap;
and receiving a memory occupation stop notification sent by the virtual machine, and performing one-time recovery on a first physical memory page with continuous addresses corresponding to the marked virtual memory page identifier.
3. A virtual machine memory management method is applied to a virtual machine and comprises the following steps:
receiving a memory balloon expansion instruction sent by a virtual machine manager, wherein the memory balloon expansion instruction carries the amount of memory to be recovered, and increasing the volume of the memory balloon according to the amount of the memory to be recovered;
sending a memory occupation notification to the virtual machine manager, wherein the memory occupation notification carries a virtual memory page identifier occupied when the memory balloon volume is increased, so that the virtual machine manager recovers a corresponding first physical memory page according to the occupied virtual memory page identifier;
receiving a memory balloon contraction instruction sent by the virtual machine manager, suspending a zero-page thread in an operating system through a virtualization plug-in to close a memory page automatic zero setting mechanism, and reducing the volume of a memory balloon to zero according to the memory balloon contraction instruction so as to enable a memory space corresponding to the recovered first physical memory page to form a memory cavity;
sending an access request for a virtual memory page in the memory hole to the virtual machine manager, so that the virtual machine manager allocates a second physical memory page to the virtual memory page requested to be accessed according to the access request.
4. The method of claim 3, further comprising:
and when the memory balloon volume is increased according to the memory amount to be recovered, checking the residual physical memory amount corresponding to the virtual machine, and when the residual physical memory amount reaches a preset safety threshold value, stopping increasing the memory balloon volume.
5. A virtual machine manager, the virtual machine manager comprising:
the instruction sending module is used for sending a memory balloon expansion instruction to a virtual machine, wherein the memory balloon expansion instruction carries the memory amount to be recovered, so that the virtual machine increases the volume of the memory balloon according to the memory amount to be recovered to occupy a virtual memory page;
a memory recovery module, configured to receive a memory occupation notification sent by the virtual machine, acquire a virtual memory page identifier occupied when the volume of the memory balloon carried in the memory occupation notification is increased, and recover a first physical memory page corresponding to the occupied virtual memory page identifier;
the instruction sending module is further configured to send a memory balloon contraction instruction to the virtual machine, so that the virtual machine suspends a zero-page thread in an operating system through a virtualization plug-in to close an automatic memory page zeroing mechanism, and reduce the volume of the increased memory balloon to zero, so that a memory space corresponding to a first physical memory page recycled in the virtual machine forms a memory cavity;
and a memory returning module, configured to receive an access request sent by the virtual machine for a virtual memory page in the memory cavity, and allocate a second physical memory page to the virtual memory page requested to be accessed according to the access request.
6. The virtual machine manager according to claim 5, wherein the memory recovery module is further configured to mark the occupied virtual memory page identifier correspondingly through a bitmap; and receiving a memory occupation stop notification sent by the virtual machine, and performing one-time recovery on a first physical memory page with continuous addresses corresponding to the marked virtual memory page identifier.
7. An apparatus for virtual machine memory management, the apparatus comprising:
the volume increasing module is used for receiving a memory balloon expansion instruction sent by a virtual machine manager, wherein the memory balloon expansion instruction carries the amount of memory to be recovered, and the volume of the memory balloon is increased according to the amount of the memory to be recovered;
a sending module, configured to send a memory occupancy notification to the virtual machine manager, where the memory occupancy notification carries a virtual memory page identifier occupied when the volume of the memory balloon is increased, so that the virtual machine manager recovers a corresponding first physical memory page according to the occupied virtual memory page identifier;
the volume shrinkage module is used for receiving a memory balloon shrinkage instruction sent by the virtual machine manager, suspending a zero-page thread in an operating system through a virtualization plug-in to close an automatic memory page zeroing mechanism, and reducing the volume of the memory balloon to zero according to the memory balloon shrinkage instruction so as to enable a memory space corresponding to the recovered first physical memory page to form a memory cavity;
the sending module is further configured to send an access request for a virtual memory page in the memory cavity to the virtual machine manager, so that the virtual machine manager allocates a physical memory page for the virtual memory page requested to be accessed according to the access request.
8. The apparatus of claim 7, further comprising:
and the remaining memory checking module is configured to check the remaining physical memory amount corresponding to the virtual machine when the memory balloon volume is increased according to the memory amount to be recovered, and notify the volume increasing module to stop increasing the memory balloon volume when the remaining physical memory amount reaches a preset safety threshold.
CN201610130620.6A 2016-03-08 2016-03-08 Virtual machine memory management method and device and virtual machine manager Active CN107168766B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201610130620.6A CN107168766B (en) 2016-03-08 2016-03-08 Virtual machine memory management method and device and virtual machine manager

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201610130620.6A CN107168766B (en) 2016-03-08 2016-03-08 Virtual machine memory management method and device and virtual machine manager

Publications (2)

Publication Number Publication Date
CN107168766A CN107168766A (en) 2017-09-15
CN107168766B true CN107168766B (en) 2020-02-28

Family

ID=59848492

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201610130620.6A Active CN107168766B (en) 2016-03-08 2016-03-08 Virtual machine memory management method and device and virtual machine manager

Country Status (1)

Country Link
CN (1) CN107168766B (en)

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109324893B (en) * 2018-08-07 2021-08-31 华为技术有限公司 Method and device for allocating memory
CN110399205B (en) * 2019-07-29 2022-09-06 中国科学技术大学 Dynamic virtual machine memory adjusting method based on state perception
US11550729B2 (en) 2020-10-28 2023-01-10 Red Hat, Inc. Memory ballooning related memory allocation techniques for virtual machines
CN115269188A (en) * 2022-07-28 2022-11-01 江苏安超云软件有限公司 Virtual machine intelligent memory recovery method and device, electronic equipment and storage medium

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101971146A (en) * 2007-09-07 2011-02-09 甲骨文国际公司 System and method to improve memory usage in virtual machines running as hypervisor guests
CN102023863A (en) * 2010-12-13 2011-04-20 中兴通讯股份有限公司 Method and device for switching editions
CN102779074A (en) * 2012-06-18 2012-11-14 中国人民解放军国防科学技术大学 Internal memory resource distribution method based on internal memory hole mechanism

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101971146A (en) * 2007-09-07 2011-02-09 甲骨文国际公司 System and method to improve memory usage in virtual machines running as hypervisor guests
CN102023863A (en) * 2010-12-13 2011-04-20 中兴通讯股份有限公司 Method and device for switching editions
CN102779074A (en) * 2012-06-18 2012-11-14 中国人民解放军国防科学技术大学 Internal memory resource distribution method based on internal memory hole mechanism

Also Published As

Publication number Publication date
CN107168766A (en) 2017-09-15

Similar Documents

Publication Publication Date Title
CN107168766B (en) Virtual machine memory management method and device and virtual machine manager
US20180173620A1 (en) Data erasure method for solid state drive, and apparatus
US8954963B2 (en) Method and apparatus for resetting a physical I/O adapter without stopping a guest OS running on a virtual machine
CN106970810B (en) Firmware burning method and system
US11188347B2 (en) Virtual function driver loading method and server using global and local identifiers corresponding to locations of the virtual functions
EP3637288B1 (en) Method, apparatus and systems for accessing secure world
EP3306870A1 (en) Network configuration method, network system and device
CN111385296B (en) Business process restarting method, device, storage medium and system
JP2009230596A (en) User data protection method for server device, server device, and computer program
US11675615B2 (en) Zero copy message reception for applications
EP4187386A1 (en) Interprocess communication method and apparatus
US10757129B2 (en) Software security verification method, device, and system
CN110019475B (en) Data persistence processing method, device and system
WO2020113478A1 (en) Address information processing method and apparatus, electronic device, and storage medium
CN106598696B (en) Method and device for data interaction between virtual machines
CN105808319B (en) Method, device and system for controlling memory balloon
AU2011348864B2 (en) Method for managing a memory of a computer system, memory management unit and computer system
CN109062781B (en) Message buffer management method and device
CN111522659A (en) Space using method and device
CN110677378B (en) Control method of MAC address, intelligent terminal and storage medium
CN108718316B (en) Method and system for realizing secure migration of virtual machine password information
CN106445658B (en) Method and apparatus for running transformed guest systems under a hypervisor
CN115269188A (en) Virtual machine intelligent memory recovery method and device, electronic equipment and storage medium
CN113225296A (en) Authority management method and device
US11972293B2 (en) Data structure, memory means and device

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
CB02 Change of applicant information
CB02 Change of applicant information

Address after: Nanshan District Xueyuan Road in Shenzhen city of Guangdong province 518000 No. 1001 Nanshan Chi Park building A1 layer

Applicant after: SINFOR Polytron Technologies Inc

Address before: Nanshan District Xueyuan Road in Shenzhen city of Guangdong province 518000 No. 1001 Nanshan Chi Park building A1 layer

Applicant before: Shenxinfu Electronics Science and Technology Co., Ltd., Shenzhen

GR01 Patent grant
GR01 Patent grant