Method, device and storage medium for dynamically adjusting memory of virtual machine

By acquiring and analyzing the memory usage information of the host machine and virtual machine, the adjustment queue and priority are determined, and dynamic memory adjustment is performed using the vsock and Balloon devices. This solves the problem of memory resource allocation mismatch in Balloon driver technology and improves the real-time performance and performance of the virtual machine system.

CN117971489BActive Publication Date: 2026-06-23CHINA UNITED NETWORK COMM GRP CO LTD +2

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
CHINA UNITED NETWORK COMM GRP CO LTD
Filing Date
2024-02-21
Publication Date
2026-06-23

Smart Images

  • Figure CN117971489B_ABST
    Figure CN117971489B_ABST
Patent Text Reader

Abstract

The application provides a dynamic adjustment method, device and equipment of virtual machine memory and a storage medium, and relates to the technical field of computers.The method comprises the following steps: obtaining memory usage information of a host computer and memory usage information of each virtual machine of the host computer; determining a memory state of each virtual machine and an adjustment queue corresponding to each virtual machine according to the memory usage information of each virtual machine, wherein the memory state is sufficient memory or insufficient memory, and the adjustment queue is a sufficient memory queue or an insufficient memory queue; determining an adjustment priority of each virtual machine in the adjustment queue according to the memory usage information of each virtual machine; and controlling the virtual machine in the sufficient memory queue to release memory for the host computer and the virtual machine in the insufficient memory queue according to the adjustment priority and the memory usage information of the host computer.The method of the application considers the real-time demand of each member in the virtual machine system for memory, and realizes fine and intelligent dynamic adjustment of virtual machine memory.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and in particular to a method, apparatus, device and storage medium for dynamically adjusting virtual machine memory. Background Technology

[0002] Virtualization is a technology that improves the utilization of computer resources by combining or partitioning existing computer resources, such as CPU, memory, and disk space. Multiple virtual machines can be built on a single physical machine. The physical machine on which the virtual machines are built is the host machine for the virtual machines. The virtual machines can occupy or share the hardware resources of the host machine.

[0003] Existing methods to improve virtual machine memory utilization include: providing a Balloon driver for the virtual machine, which can mark the free resources in the virtual machine and lend its free resources to other virtual machines when needed (called inflation), and reclaim the borrowed resources when it detects that it needs to use them (called deflation).

[0004] However, the existing Balloon driver technology is not sensitive enough to changes in actual memory usage, has poor real-time performance when adjusting memory resources, and fails to take into account the memory requirements of the host machine and each virtual machine. This results in a mismatch between memory resource allocation and demand, leading to problems such as decreased computer performance or even memory overflow. Summary of the Invention

[0005] This application provides a method, apparatus, device, and storage medium for dynamically adjusting virtual machine memory, in order to solve the problems of mismatch between virtual machine memory resource allocation and actual needs, and poor real-time performance.

[0006] In a first aspect, this application provides a method for dynamically adjusting virtual machine memory, the method comprising:

[0007] Obtain the memory usage information of the host machine and the memory usage information of each virtual machine on the host machine, wherein the memory usage information includes the maximum available memory and the actual memory used;

[0008] Based on the memory usage information of each virtual machine, the memory status of each virtual machine is determined, and the adjustment queue corresponding to each virtual machine is determined, wherein the memory status is sufficient memory or insufficient memory, and the adjustment queue is a sufficient memory queue or an insufficient memory queue.

[0009] Based on the memory usage information of each virtual machine, determine the adjustment priority of each virtual machine in the adjustment queue;

[0010] Based on the adjustment priority and the host machine's memory usage information, the virtual machines in the memory-sufficient queue are controlled to release memory for the host machine and the virtual machines in the memory-insufficient queue.

[0011] Optionally, determining the adjustment priority of each virtual machine in the adjustment queue based on the memory usage information of each virtual machine includes:

[0012] Based on the memory usage information of each virtual machine, determine the free memory of each virtual machine;

[0013] Based on the free memory of each virtual machine, the different adjustment queues are sorted respectively, wherein the memory sufficient queue is sorted from largest to smallest free memory of each virtual machine, and the memory insufficient queue is sorted from smallest to largest free memory of each virtual machine.

[0014] Based on the sorted adjustment queue, the adjustment priority of each virtual machine in the adjustment queue is determined, wherein the adjustment priority of each virtual machine is consistent with the order in which the adjustment queue is sorted.

[0015] Optionally, after determining the adjustment priority of each virtual machine in the sorted adjustment queue, the method further includes:

[0016] Obtain memory pressure events reported by the virtual machines on the host machine, wherein the memory pressure events are used to indicate that the memory status of the virtual machines is insufficient;

[0017] The adjustment queue corresponding to the virtual machine is determined to be the out-of-memory queue, and the adjustment priority of the virtual machine is set to the highest priority.

[0018] Optionally, controlling each virtual machine in the memory-sufficient queue to release memory for the host machine and each virtual machine in the memory-insufficient queue according to the adjusted priority includes:

[0019] Based on the host machine's memory usage information, determine the host machine's memory status;

[0020] If the host machine has insufficient memory, then determine whether the freeable memory of the memory-sufficient queue meets the memory requirements of the host machine;

[0021] If the available memory in the memory-sufficient queue meets the memory requirements of the host machine, then according to the preset memory granularity and the adjustment priority, the virtual machines in the memory-sufficient queue are sequentially controlled to release memory of the preset memory granularity until the host machine has sufficient memory.

[0022] If the freeable memory of the memory-sufficient queue does not meet the memory requirements of the host machine, then a memory decompression procedure is executed.

[0023] If the host machine has sufficient memory, then according to the adjustment priority, each virtual machine in the sufficient memory queue is controlled to release memory for each virtual machine in the insufficient memory queue.

[0024] Optionally, controlling the virtual machines in the sufficient memory queue to release memory for the virtual machines in the insufficient memory queue according to the adjusted priority includes:

[0025] According to the order of adjustment priority from high to low, each virtual machine in the insufficient memory queue is obtained as a virtual machine to be deflated.

[0026] According to the adjustment priority, a corresponding target inflation virtual machine is matched for the virtual machine to be deflated, and the target inflation virtual machine is controlled to release memory for the virtual machine to be deflated;

[0027] The target inflatable virtual machine is a virtual machine in the memory-sufficient queue.

[0028] Optionally, the step of matching a corresponding target inflation virtual machine to the virtual machine to be deflated according to the adjusted priority, and controlling the target inflation virtual machine to release memory for the virtual machine to be deflated, includes:

[0029] According to the order of adjustment priority from high to low, virtual machines are obtained one by one from the memory-sufficient queue as the target inflatable virtual machines;

[0030] Determine whether the releasable memory of the target inflatable virtual machine can meet the memory requirements of the virtual machine to be deflated;

[0031] If so, then according to the memory requirement, control the target inflatable virtual machine to release memory for the virtual machine to be deflated;

[0032] If not, then according to the releasable memory, control the target inflatable virtual machine to release memory for the virtual machine to be deflated, and continue to acquire new target inflatable virtual machines to release memory for the virtual machine to be deflated, until the released memory meets the memory requirements of the virtual machine to be deflated.

[0033] Optionally, the step of matching a corresponding target inflation virtual machine to the virtual machine to be deflated according to the adjusted priority, and controlling the target inflation virtual machine to release memory for the virtual machine to be deflated, includes:

[0034] According to the order of adjustment priority from high to low, control the virtual machines in the memory-sufficient queue to release memory with a preset memory granularity one by one until the released memory meets the memory requirements of the virtual machine to be deflated.

[0035] If, after traversing the memory-sufficient queue, the released memory does not meet the memory requirements of the virtual machine to be deflated, then, following the order of adjustment priority from high to low, the virtual machines in the memory-sufficient queue are controlled to release memory with a preset memory granularity one by one until the released memory meets the memory requirements of the virtual machine to be deflated.

[0036] Optionally, the step of matching a corresponding target inflation virtual machine to the virtual machine to be deflated according to the adjusted priority, and controlling the target inflation virtual machine to release memory for the virtual machine to be deflated, includes:

[0037] Based on the memory usage information of each virtual machine in the memory-sufficient queue, determine the memory release weight of each virtual machine in the memory-sufficient queue;

[0038] Based on the memory release weight of each virtual machine and the memory requirement of the virtual machine to be de-energized, the target memory to be released for each virtual machine is determined.

[0039] Based on the target memory release for each virtual machine, control each virtual machine to release memory for the virtual machine to be degassed.

[0040] Secondly, this application provides a dynamic adjustment system for virtual machine memory, the system comprising: a host machine, virtual machines, agents, and a scheduler; each agent runs on one of the virtual machines; the scheduler runs in the Libvirt process of the host machine; the scheduler communicates with each agent through a vsock device; the scheduler controls the virtual machines in the memory-sufficient queue to release memory for the host machine and the virtual machines in the memory-insufficient queue through a balloon device running on the virtual machines.

[0041] The agent is used to obtain the memory usage information of the virtual machine and report the memory usage information to the scheduler, wherein the memory usage information includes the maximum available memory and the actual memory used;

[0042] The scheduler is used to execute the method as described in the first aspect.

[0043] Thirdly, this application provides a device for dynamically adjusting virtual machine memory, comprising:

[0044] A communication module is used to obtain the memory usage information of the host machine and the memory usage information of each virtual machine on the host machine, wherein the memory usage information includes the maximum available memory and the actual memory used;

[0045] The computation module is used to determine the memory status of each virtual machine based on the memory usage information of each virtual machine, and to determine the adjustment queue corresponding to each virtual machine, wherein the memory status is sufficient memory or insufficient memory, and the adjustment queue is a sufficient memory queue or an insufficient memory queue; and to determine the adjustment priority of each virtual machine in the adjustment queue based on the memory usage information of each virtual machine.

[0046] The control module is used to control the virtual machines in the memory-sufficient queue to release memory for the host machine and the virtual machines in the memory-insufficient queue according to the adjustment priority.

[0047] Fourthly, this application provides a device for dynamically adjusting virtual machine memory, comprising: a memory and at least one processor;

[0048] The memory is used to store computer programs;

[0049] The at least one processor is used to run a computer program stored in the memory to implement the method as described in the first aspect.

[0050] Fifthly, this application provides a computer-readable storage medium having a computer program stored thereon;

[0051] When the computer program is executed by a processor, it implements the method described in the first aspect.

[0052] The method, apparatus, device, and storage medium for dynamically adjusting virtual machine memory provided in this application obtain the memory usage information of the host machine and the memory usage information of each virtual machine on the host machine, wherein the memory usage information includes the maximum available memory and the actual memory used; based on the memory usage information of each virtual machine, determine the memory status of each virtual machine and determine the adjustment queue corresponding to each virtual machine, wherein the memory status is sufficient memory or insufficient memory, and the adjustment queue is a sufficient memory queue or an insufficient memory queue; based on the memory usage information of each virtual machine, determine the adjustment priority of each virtual machine in the adjustment queue; based on the adjustment priority and the memory usage information of the host machine, control the virtual machines in the sufficient memory queue to release memory for the host machine and the virtual machines in the insufficient memory queue. This method comprehensively considers the current actual situation of the host machine and each virtual machine on the host machine when making memory adjustment decisions, making the dynamic adjustment of virtual machine memory more precise and intelligent, and meeting the real-time memory needs of each member in the virtual machine system. Attached Figure Description

[0053] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.

[0054] Figure 1 A schematic diagram of a dynamic adjustment system for virtual machine memory provided in this application;

[0055] Figure 2 Flowchart of the method for dynamically adjusting virtual machine memory provided in this application Figure 1 ;

[0056] Figures 3a to 3b Flowchart of the method for dynamically adjusting virtual machine memory provided in this application Figure 2 ;

[0057] Figure 4 A schematic diagram of the structure of a virtual machine memory dynamic adjustment device provided in this application;

[0058] Figure 5 This application provides a schematic diagram of the structure of a device for dynamically adjusting virtual machine memory.

[0059] The accompanying drawings illustrate specific embodiments of this application, which will be described in more detail below. These drawings and descriptions are not intended to limit the scope of the concept in any way, but rather to illustrate the concept of this application to those skilled in the art through reference to particular embodiments. Detailed Implementation

[0060] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application.

[0061] Virtualization is a technology that improves the utilization of computer resources by combining or partitioning existing computer resources, such as CPU, memory, and disk space. Multiple virtual machines can be built on a single physical machine. The physical machine on which the virtual machines are built is the host machine for the virtual machines. The virtual machines can occupy or share the hardware resources of the host machine.

[0062] Existing methods to improve virtual machine memory utilization include: providing a balloon driver for the virtual machine, which can mark the free resources in the virtual machine and lend its free resources to other virtual machines when needed (called inflation), and reclaim the borrowed resources when it detects that it needs to use them (called deflation).

[0063] However, the existing Balloon driver technology is not sensitive enough to changes in actual memory usage, has poor real-time performance when adjusting memory resources, and fails to take into account the memory requirements of the host machine and each virtual machine. This results in a mismatch between memory resource allocation and demand, leading to problems such as decreased computer performance or even memory overflow.

[0064] The method for dynamically adjusting virtual machine memory provided in this application aims to solve the above-mentioned technical problems in the prior art.

[0065] The technical solution of this application and how the technical solution of this application solves the above-mentioned technical problems are described in detail below with specific embodiments. These specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments. The embodiments of this application will now be described with reference to the accompanying drawings.

[0066] Figure 1 This is a schematic diagram of an overall system for dynamically adjusting virtual machine memory, as provided in this application. Figure 1 As shown, the system includes: a host machine, virtual machines, agents, and a scheduler; wherein each agent runs on one of the virtual machines; the scheduler runs in the virtualization management process of the host machine, the virtualization management process being the libvirt process, libvirt being an open-source application programming interface, daemon, and management tool for managing virtualization platforms, which can be used with any tool that supports an existing list of virtual machine hypervisors without needing to learn hypervisor-specific tools; the scheduler communicates with each agent through a network device, the network device being a vsock device, a network device provided by the Linux kernel that can provide high-performance, low-latency, and reliable network communication between the host machine and the virtual machines, providing a communication framework and programming interface for the virtual machines and the host machine; the scheduler controls the virtual machines in the memory-sufficient queue to release memory for the host machine and the virtual machines in the memory-insufficient queue through balloon devices (i.e., Balloon devices, Balloon devices being virtual devices managed by the Balloon driver) running on the virtual machines, the balloon devices can read the memory adjustment instructions written by the scheduler and release memory for the host machine and the virtual machines in the memory-insufficient queue according to the instructions.

[0067] The agent is used to obtain the memory usage information of the virtual machine and report the memory usage information to the scheduler, wherein the memory usage information includes the maximum available memory and the actual memory used.

[0068] The scheduler is configured to acquire the memory usage information of the host machine and the memory usage information of each virtual machine on the host machine; determine the memory status of each virtual machine based on the memory usage information of each virtual machine; and determine the adjustment queue corresponding to each virtual machine, wherein the memory status is either sufficient memory or insufficient memory, and the adjustment queue is either a sufficient memory queue or a insufficient memory queue; determine the adjustment priority of each virtual machine in the adjustment queue based on the memory usage information of each virtual machine; and control the virtual machines in the sufficient memory queue to release memory for the host machine and the virtual machines in the insufficient memory queue based on the adjustment priority and the memory usage information of the host machine.

[0069] Understandably, by transmitting memory usage information through the vsock device and dynamically adjusting the virtual machine's memory through the scheduler running in the libvirt process on the host machine, the latency required for the memory adjustment process is reduced, making the virtual machine memory adjustment action more real-time.

[0070] Taking the method of dynamically adjusting virtual machine memory in this embodiment, executed by the scheduler, as an example, Figure 2 A flowchart illustrating the method for dynamically adjusting virtual machine memory provided in this application embodiment. Figure 1 ;like Figure 2 As shown in the embodiments of this application, the method for dynamically adjusting virtual machine memory includes:

[0071] S201: Obtain the memory usage information of the host machine and the memory usage information of each virtual machine on the host machine.

[0072] The memory usage information includes the maximum available memory and the actual memory used. The memory usage information of each virtual machine is obtained by the agent of each virtual machine according to a first preset period and reported through the vosck device.

[0073] Specifically, the scheduler running in the libvirtd process obtains the host machine's memory usage information through the operating system interface; and obtains the memory usage information of each virtual machine through the vsock device.

[0074] S202: Based on the memory usage information of each virtual machine, determine the memory status of each virtual machine and determine the adjustment queue corresponding to each virtual machine.

[0075] The memory status is either sufficient or insufficient memory; the adjustment queue is either a sufficient memory queue or an insufficient memory queue.

[0076] Specifically, the scheduler determines the memory status of each virtual machine based on its memory usage information. For example, it can determine the current free memory of the virtual machine based on its maximum available memory and actual memory usage, obtain a preset minimum available memory and the virtual machine's base running memory, and determine whether the current free memory of the virtual machine is greater than the sum of the minimum available memory and the base running memory. If so, the virtual machine is determined to have sufficient memory, and its identifier is placed in the sufficient memory queue. If not, the virtual machine is determined to have insufficient memory, and its identifier is placed in the insufficient memory queue.

[0077] S203: Determine the adjustment priority of each virtual machine in the adjustment queue based on the memory usage information of each virtual machine.

[0078] The adjustment priority is used to indicate the priority of the virtual machine in the adjustment queue for participating in dynamic memory adjustment.

[0079] Specifically, the scheduler determines the adjustment priority of each virtual machine in the two adjustment queues according to the memory information of each virtual machine and a preset priority determination rule. For example, the priority determination rule can be to sort the two adjustment queues according to the free memory size of each virtual machine, and determine the adjustment priority of each virtual machine according to the order in which each virtual machine is sorted in its queue. This application embodiment does not limit the specific content of the priority determination rule.

[0080] S204: Based on the adjustment priority, control the virtual machines in the memory sufficient queue to release memory for the host machine and the virtual machines in the memory insufficient queue.

[0081] Specifically, the scheduler determines the timing and order in which each virtual machine in the insufficient memory queue and each virtual machine in the sufficient memory queue participates in dynamic memory adjustment based on the adjusted priority and the preset priority scheduling algorithm. Then, according to the timing and order, the scheduler controls the virtual machines in the sufficient memory queue to release memory for the host machine and the virtual machines in the insufficient memory queue through the balloon device. This application embodiment does not limit the specific content of the priority scheduling algorithm.

[0082] The method for dynamically adjusting virtual machine memory provided in this application obtains memory usage information of the host machine and each virtual machine on the host machine, determines the memory state of each virtual machine, and places each virtual machine into an adjustment queue corresponding to its memory state. Based on the memory state of each virtual machine, the adjustment priority of each virtual machine in each adjustment queue is determined, and according to the determined adjustment priority, the virtual machines in the memory-sufficient queue are controlled to release memory for the host machine and the virtual machines in the memory-insufficient queue. The method dynamically adjusts the memory of each virtual machine based on its actual memory needs and current memory usage, enabling the scheduler to comprehensively consider the actual situation of the host machine and each virtual machine on the host machine when making memory adjustment decisions, resulting in more precise and intelligent dynamic adjustment of virtual machine memory.

[0083] Taking the method of dynamically adjusting virtual machine memory in this embodiment, executed by the scheduler, as an example, Figures 3a to 3b A flowchart illustrating the method for dynamically adjusting virtual machine memory provided in this application embodiment. Figure 2 ;like Figures 3a to 3b As shown in the embodiments of this application, the method for dynamically adjusting virtual machine memory includes:

[0084] S301: Obtain the memory usage information of the host machine and the memory usage information of each virtual machine on the host machine.

[0085] The memory usage information includes the maximum available memory and the actual memory used.

[0086] The implementation method of step S301 is similar to that of step S201, and will not be described again in this embodiment.

[0087] S302: Based on the memory usage information of each virtual machine, determine the memory status of each virtual machine and determine the adjustment queue corresponding to each virtual machine.

[0088] Wherein, the memory status is either sufficient memory or insufficient memory, and the adjustment queue is either a sufficient memory queue or an insufficient memory queue;

[0089] The implementation method of step S302 is similar to that of step S202, and will not be described again in this embodiment.

[0090] S303: Determine the free memory of each virtual machine based on the memory usage information of each virtual machine.

[0091] Specifically, the scheduler obtains the maximum available memory and the actual memory used for each virtual machine, and uses the difference between the maximum available memory and the actual memory used as the free memory for each virtual machine.

[0092] S304: Sort the different adjustment queues according to the free memory of each virtual machine.

[0093] The memory-sufficient queue is sorted in descending order of the free memory of each virtual machine; the memory-insufficient queue is sorted in ascending order of the free memory of each virtual machine.

[0094] Specifically, the scheduler sorts the memory-sufficient queue and the memory-insufficient queue according to the relative size of each virtual machine's free memory in its respective queue.

[0095] S305: Determine the adjustment priority of each virtual machine in the sorted adjustment queue.

[0096] The adjustment priority of each virtual machine is consistent with the order in which the adjustment queue is sorted.

[0097] Specifically, the scheduler defines the adjustment priority of each virtual machine in the two adjustment queues according to the rule that the adjustment priority decreases step by step from the front end of the queue to the back end of the queue.

[0098] S306: Obtain the memory pressure event reported by the virtual machine on the host machine.

[0099] The memory pressure event is used to indicate that the virtual machine's memory status is insufficient.

[0100] Specifically, each virtual machine's agent obtains the virtual machine's memory usage information according to a second preset period (the second preset period is shorter than the first preset period) to determine the virtual machine's current free memory; and obtains a preset minimum available memory for the virtual machine through the vsock device; each virtual machine's agent, based on the virtual machine's memory usage information, the preset minimum available memory for the virtual machine, and the virtual machine's base running memory, determines whether the virtual machine's current free memory is greater than the sum of the virtual machine's minimum available memory and the base running memory; if not, the virtual machine's memory status is determined to be insufficient, a memory pressure event for the virtual machine is generated, and it is reported through the vsock device; the scheduler obtains the memory pressure event reported by the virtual machine agents by listening to the vsock device.

[0101] Understandably, by using a virtual machine agent to determine the memory status of a virtual machine at a shorter second preset period, the scheduler can obtain memory pressure events reported by the virtual machine agent in real time, set the adjustment priority of the virtual machine corresponding to the memory pressure event to the highest priority, improve the real-time performance of virtual machine memory adjustment, avoid memory overflow caused by memory adjustment lag, and improve the security of the virtual machine system.

[0102] S307: Determine that the adjustment queue corresponding to the virtual machine is the insufficient memory queue, and set the adjustment priority of the virtual machine to the highest priority.

[0103] Specifically, the scheduler places the virtual machine identifier corresponding to the memory pressure event at the front of the insufficient memory queue and sets the adjustment priority of the virtual machine to the highest priority.

[0104] S308: Determine the memory status of the host machine based on the host machine's memory usage information.

[0105] Specifically, the scheduler determines the host machine's memory status based on the host machine's memory usage information. For example, it can obtain the host machine's actual used memory and maximum available memory through the operating system interface, determine the host machine's current free memory, obtain the preset minimum available memory and basic running memory of the host machine, and determine whether the host machine's current free memory is greater than the sum of the host machine's minimum available memory and the basic running memory. If so, the host machine's memory status is determined to be sufficient; if not, the host machine's memory status is determined to be insufficient.

[0106] S309: If the host machine has insufficient memory, determine whether the freeable memory of the memory-sufficient queue meets the memory requirements of the host machine.

[0107] Wherein, the freeable memory of the memory-sufficient queue is the sum of the freeable memory of each virtual machine in the memory-sufficient queue; the freeable memory of each virtual machine is the difference between the virtual machine's free memory and the sum of the virtual machine's minimum available memory and the virtual machine's base running memory; the host machine's memory requirement is the difference between the sum of the host machine's minimum available memory and base running memory and the host machine's free memory.

[0108] Specifically, if the host machine has insufficient memory, the scheduler obtains the free memory, minimum available memory, and basic running memory of each virtual machine in the memory-sufficient queue; determines the freeable memory of each virtual machine based on the difference between the free memory of each virtual machine and the sum of the minimum available memory and the basic running memory, and uses the sum of the freeable memory of each virtual machine as the freeable memory of the memory-sufficient queue; determines the host machine's memory requirement based on the difference between the sum of the minimum available memory and the basic running memory of the host machine and the free memory of the host machine; determines whether the freeable memory of the memory-sufficient queue is greater than the host machine's memory requirement; if yes, the freeable memory of the memory-sufficient queue meets the host machine's memory requirement; if no, the freeable memory of the memory-sufficient queue does not meet the host machine's memory requirement.

[0109] S310: If the freeable memory in the memory-sufficient queue meets the memory requirements of the host machine, then according to the first preset memory granularity and the adjustment priority, the virtual machines in the memory-sufficient queue are sequentially controlled to release memory of the preset memory granularity until the host machine has sufficient memory.

[0110] Specifically, if the available memory in the memory-sufficient queue meets the host machine's memory requirements, the scheduler controls the virtual machines in the memory-sufficient queue to release memory at a first preset memory granularity one by one according to the adjustment priority from high to low, until the released memory meets the memory requirements of the virtual machine to be released or the memory-sufficient queue is traversed; if, after traversing the memory-sufficient queue, the released memory does not meet the memory requirements of the virtual machine to be released, then the scheduler again controls the virtual machines in the memory-sufficient queue to release memory at a preset memory granularity one by one according to the adjustment priority from high to low, until the released memory meets the memory requirements of the virtual machine to be released.

[0111] S311: If the freeable memory of the memory-sufficient queue does not meet the memory requirements of the host machine, then execute the memory decompression procedure.

[0112] Specifically, if the available memory in the memory-sufficient queue does not meet the memory requirements of the host machine, the scheduler executes a memory decompression procedure. The memory decompression procedure may, for example, be to select some virtual machines on the host machine for virtual machine migration or to send a host machine memory pressure alert to the host machine administrator. This application embodiment does not limit the specific content of the memory decompression procedure.

[0113] S312: If the host machine has sufficient memory, then according to the adjustment priority from high to low, each virtual machine in the insufficient memory queue is obtained as a virtual machine to be deflated.

[0114] Specifically, if the host machine has sufficient memory, the scheduler will retrieve each virtual machine in the insufficient memory queue as a virtual machine to be deflated, one by one from the front to the back of the insufficient memory queue, according to the adjustment priority from high to low. That is, the virtual machine with the highest adjustment priority will be deflated first. After the virtual machine with the highest adjustment priority is deflated, the next highest adjustment priority virtual machine will be deflated until all virtual machines in the sufficient memory queue have been deflated.

[0115] S313: According to the adjustment priority, match the corresponding target inflation virtual machine for the virtual machine to be deflated, and control the target inflation virtual machine to release memory for the virtual machine to be deflated.

[0116] The target inflatable virtual machine is a virtual machine in the memory-sufficient queue.

[0117] According to the adjustment priority, the scheduler matches the virtual machine to be deflated with a corresponding target virtual machine according to the preset matching algorithm, and controls the target virtual machine to release memory for the virtual machine to be deflated.

[0118] Optionally, the scheduler, based on the adjusted priority, matches the virtual machine to be deflated with a corresponding target virtual machine according to a preset matching algorithm, and controls the target virtual machine to release memory for the virtual machine to be deflated. The specific steps for this can be, for example:

[0119] Step 1: According to the order of adjustment priority from high to low, obtain virtual machines one by one from the memory-sufficient queue as the target inflatable virtual machines.

[0120] Step 2: Determine whether the releasable memory of the target inflatable virtual machine can meet the memory requirements of the virtual machine to be deflated.

[0121] Step 3: If so, then according to the memory requirement, control the target inflation virtual machine to release memory for the virtual machine to be deflated.

[0122] Step 4: If not, then according to the releasable memory, control the target inflatable virtual machine to release memory for the virtual machine to be deflated, and continue to acquire new target inflatable virtual machines to release memory for the virtual machine to be deflated, until the released memory meets the memory requirements of the virtual machine to be deflated.

[0123] Understandably, matching virtual machines with higher priority in the two queues to those with sufficient memory is more efficient.

[0124] Optionally, the scheduler, based on the adjusted priority, matches the virtual machine to be deflated with a corresponding target virtual machine according to a preset matching algorithm, and controls the target virtual machine to release memory for the virtual machine to be deflated. The specific steps for this can be, for example:

[0125] Step 1: Following the order of adjustment priority from high to low, control each virtual machine in the memory-sufficient queue to release memory at the second preset memory granularity until the released memory meets the memory requirements of the virtual machine to be released or the memory-sufficient queue is traversed.

[0126] Step 2: If, after traversing the memory-sufficient queue, the released memory does not meet the memory requirements of the virtual machine to be deflated, then, following the order of adjustment priority from high to low, control the virtual machines in the memory-sufficient queue to release memory with a preset memory granularity one by one until the released memory meets the memory requirements of the virtual machine to be deflated.

[0127] Understandably, this matching method ensures that the memory released by each virtual machine with sufficient memory is more evenly distributed to the virtual machine to be deflated. In other words, the virtual machines with sufficient memory share the memory pressure of the system, avoiding excessive local pressure caused by releasing a large amount of memory from only a few virtual machines.

[0128] Optionally, the scheduler, based on the adjusted priority, matches the virtual machine to be deflated with a corresponding target virtual machine according to a preset matching algorithm, and controls the target virtual machine to release memory for the virtual machine to be deflated. The specific steps for this can be, for example:

[0129] Step 1: Determine the memory release weight of each virtual machine in the memory-sufficient queue based on the memory usage information of each virtual machine in the memory-sufficient queue.

[0130] Optionally, the method for determining the memory release weight of each virtual machine can be, for example, based on at least one of the memory usage information of each virtual machine in the memory-sufficient queue, the pre-determined business priority and memory demand intensity of each virtual machine, and a preset mapping relationship between at least one of different memory usage information, business priority and memory demand intensity and the memory release weight.

[0131] Step 2: Determine the target memory release for each virtual machine based on the memory release weight of each virtual machine and the memory requirement of the virtual machine to be de-energized.

[0132] Step 3: Based on the target memory release for each virtual machine, control each virtual machine to release memory for the virtual machine to be degassed.

[0133] Understandably, by determining the memory release weight of each virtual machine in the memory-sufficient queue according to the pre-set memory weight release method, and controlling each virtual machine in the memory-sufficient queue to release memory according to its corresponding memory release weight, and releasing the target memory for each virtual machine with insufficient memory based on the adjustment priority of the virtual machine with insufficient memory, the amount of memory released by each virtual machine in the memory-sufficient queue can better meet the actual needs of the current application scenario.

[0134] Figure 4 This is a schematic diagram of the structure of the virtual machine memory dynamic adjustment device provided in the embodiments of this application; as shown. Figure 4 As shown, this application provides a device for dynamically adjusting virtual machine memory. The device 400 for dynamically adjusting virtual machine memory includes:

[0135] The communication module 401 is used to obtain the memory usage information of the host machine and the memory usage information of each virtual machine on the host machine, wherein the memory usage information includes the maximum available memory and the actual memory used.

[0136] The calculation module 402 is used to determine the memory status of each virtual machine based on the memory usage information of each virtual machine, and to determine the adjustment queue corresponding to each virtual machine, wherein the memory status is sufficient memory or insufficient memory, and the adjustment queue is a sufficient memory queue or an insufficient memory queue; and to determine the adjustment priority of each virtual machine in the adjustment queue based on the memory usage information of each virtual machine.

[0137] The control module 403 is used to control the virtual machines in the memory-sufficient queue to release memory for the host machine and the virtual machines in the memory-insufficient queue according to the adjustment priority.

[0138] Optionally, the calculation module 402 is specifically used to determine the free memory of each virtual machine based on the memory usage information of each virtual machine; sort different adjustment queues according to the free memory of each virtual machine, wherein the memory sufficient queue is sorted from largest to smallest free memory of each virtual machine, and the memory insufficient queue is sorted from smallest to largest free memory of each virtual machine; and determine the adjustment priority of each virtual machine in the sorted adjustment queues, wherein the adjustment priority of each virtual machine is consistent with the order in which the adjustment queues are sorted.

[0139] Optionally, the communication module 401 is further configured to acquire memory pressure events reported by the virtual machine on the host machine, wherein the memory pressure events are used to indicate that the memory status of the virtual machine is insufficient memory;

[0140] The computing module 402 is also used to determine that the adjustment queue corresponding to the virtual machine is an insufficient memory queue, and to set the adjustment priority of the virtual machine to the highest priority.

[0141] Optionally, the control module 403 is specifically configured to: determine the memory status of the host machine based on the host machine's memory usage information; when the host machine's memory is insufficient, determine whether the available memory in the sufficient memory queue meets the host machine's memory requirements; when the available memory in the sufficient memory queue meets the host machine's memory requirements, sequentially control the virtual machines in the sufficient memory queue to release memory of a preset memory granularity according to a preset memory granularity and the adjustment priority, until the host machine has sufficient memory; when the available memory in the sufficient memory queue does not meet the host machine's memory requirements, execute a memory decompression procedure; and when the host machine has sufficient memory, control each virtual machine in the sufficient memory queue to release memory for each virtual machine in the insufficient memory queue according to the adjustment priority.

[0142] Optionally, the control module 403 is specifically configured to acquire each virtual machine in the insufficient memory queue as a virtual machine to be deflated according to the adjustment priority from high to low; match the virtual machine to be deflated with a corresponding target virtual machine according to the adjustment priority, and control the target virtual machine to release memory for the virtual machine to be deflated; wherein, the target virtual machine is a virtual machine in the sufficient memory queue.

[0143] Optionally, the control module 403 is specifically configured to: acquire virtual machines one by one from the memory-sufficient queue as the target inflatable virtual machines according to the adjustment priority from high to low; determine whether the freeable memory of the target inflatable virtual machine can meet the memory requirements of the virtual machine to be deflated; when the freeable memory of the target inflatable virtual machine can meet the memory requirements of the virtual machine to be deflated, control the target inflatable virtual machine to release memory for the virtual machine to be deflated according to the memory requirements; when the freeable memory of the target inflatable virtual machine does not meet the memory requirements of the virtual machine to be deflated, control the target inflatable virtual machine to release memory for the virtual machine to be deflated according to the freeable memory, and continue to acquire new target inflatable virtual machines to release memory for the virtual machine to be deflated, until the released memory meets the memory requirements of the virtual machine to be deflated.

[0144] Optionally, the control module 403 is specifically configured to control the virtual machines in the memory-sufficient queue to release memory of a preset memory granularity one by one according to the adjustment priority from high to low, until the released memory meets the memory requirements of the virtual machine to be deflated; after traversing the memory-sufficient queue and the released memory does not meet the memory requirements of the virtual machine to be deflated, the control module 403 again controls the virtual machines in the memory-sufficient queue to release memory of a preset memory granularity one by one according to the adjustment priority from high to low, until the released memory meets the memory requirements of the virtual machine to be deflated.

[0145] Optionally, the control module 403 is specifically configured to determine the memory release weight of each virtual machine in the memory-sufficient queue based on the memory usage information of each virtual machine in the memory-sufficient queue; determine the target memory release for each virtual machine based on the memory release weight of each virtual machine and the memory requirement of the virtual machine to be de-energized; and control each virtual machine to release memory for the virtual machine to be de-energized based on the target memory release for each virtual machine.

[0146] Figure 5 This is a schematic diagram of the structure of a device for dynamically adjusting virtual machine memory provided in an embodiment of this application, as shown below. Figure 5As shown, the virtual machine memory dynamic adjustment device 500 includes at least one processor 501 and a memory 502; in addition, the virtual machine memory dynamic adjustment device 500 may also have a communication interface 504 for receiving and sending instructions.

[0147] The processor 501, memory 502 and communication interface 504 are connected via bus 503.

[0148] The computer program is stored in memory 502 and configured to be executed by processor 501 to implement this application. Figures 2-3b The method for dynamically adjusting virtual machine memory provided in any corresponding embodiment;

[0149] Figure 5 The virtual machine memory dynamic adjustment device in the illustrated embodiment can be used to execute the technical solution of the above method embodiment. Its implementation principle and technical effect are similar, and will not be repeated here.

[0150] In addition, this embodiment also provides a computer-readable storage medium storing a computer program thereon, which is executed by a processor to implement the virtual machine memory dynamic adjustment method of the above embodiment.

[0151] It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that this application is not limited to the described order of actions, as some steps may be performed in other orders or simultaneously according to this application. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are all optional embodiments, and the actions and modules involved are not necessarily essential to this application.

[0152] It should be further noted that although the steps in the flowchart are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowchart may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the sub-steps or stages of other steps.

[0153] It should be understood that the above-described device embodiments are merely illustrative, and the device of this application can also be implemented in other ways. For example, the division of units / modules in the above embodiments is only a logical functional division, and there may be other division methods in actual implementation. For example, multiple units, modules, or components may be combined, or integrated into another system, or some features may be ignored or not executed.

[0154] Furthermore, unless otherwise specified, the functional units / modules in the various embodiments of this application can be integrated into one unit / module, or each unit / module can exist physically separately, or two or more units / modules can be integrated together. The integrated units / modules described above can be implemented in hardware or as software program modules.

[0155] When integrated units / modules are implemented in hardware, the hardware can be digital circuits, analog circuits, etc. The physical implementation of the hardware structure includes, but is not limited to, transistors, memristors, etc. Unless otherwise specified, the processor can be any suitable hardware processor, such as a CPU, GPU, FPGA, DSP, and ASIC, etc. Unless otherwise specified, the storage unit can be any suitable magnetic or magneto-optical storage medium, such as Resistive Random Access Memory (RRAM), Dynamic Random Access Memory (DRAM), Static Random Access Memory (SRAM), Enhanced Dynamic Random Access Memory (EDRAM), High-Bandwidth Memory (HBM), Hybrid Memory Cube (HMC), etc.

[0156] If the integrated unit / module is implemented as a software program module and sold or used as an independent product, it can be stored in a computer-readable storage device (CMD). Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a memory and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned memory includes various media capable of storing program code, such as a USB flash drive, read-only memory (ROM), random access memory (RAM), portable hard drive, magnetic disk, or optical disk.

[0157] In the above embodiments, the descriptions of each embodiment have their own emphasis. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments. The technical features of the above embodiments can be combined arbitrarily. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as these combinations of technical features do not contradict each other, they should be considered within the scope of this specification.

[0158] Other embodiments of this application will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of this application that follow the general principles of this application and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only.

[0159] It should be understood that this application is not limited to the precise structure described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope.

Claims

1. A method for dynamically adjusting virtual machine memory, characterized in that, The method includes: Obtain the memory usage information of the host machine and the memory usage information of each virtual machine on the host machine, wherein the memory usage information includes the maximum available memory and the actual memory used; Based on the memory usage information of each virtual machine, the memory status of each virtual machine is determined, and the adjustment queue corresponding to each virtual machine is determined, wherein the memory status is sufficient memory or insufficient memory, and the adjustment queue is a sufficient memory queue or an insufficient memory queue. Based on the memory usage information of each virtual machine, the adjustment priority of each virtual machine in the adjustment queue is determined, including: determining the free memory of each virtual machine based on the memory usage information of each virtual machine; sorting different adjustment queues according to the free memory of each virtual machine, wherein the memory-sufficient queue is sorted from largest to smallest free memory of each virtual machine, and the memory-insufficient queue is sorted from smallest to largest free memory of each virtual machine; and determining the adjustment priority of each virtual machine in the sorted adjustment queues, wherein the adjustment priority of each virtual machine is consistent with the order in which the adjustment queues are sorted. Based on the adjustment priority and the host machine's memory usage information, controlling the virtual machines in the sufficient memory queue to release memory for the host machine and the virtual machines in the insufficient memory queue includes: determining the host machine's memory status based on the host machine's memory usage information; if the host machine has insufficient memory, determining whether the available memory in the sufficient memory queue meets the host machine's memory requirements; if the available memory in the sufficient memory queue meets the host machine's memory requirements, sequentially controlling the virtual machines in the sufficient memory queue to release memory of a preset memory granularity according to a preset memory granularity and the adjustment priority, until the host machine has sufficient memory; if the available memory in the sufficient memory queue does not meet the host machine's memory requirements, executing a memory decompression procedure; if the host machine has sufficient memory, controlling each virtual machine in the sufficient memory queue to release memory for each virtual machine in the insufficient memory queue according to the adjustment priority.

2. The method according to claim 1, characterized in that, After determining the adjustment priority of each virtual machine in the sorted adjustment queue, the method further includes: Obtain memory pressure events reported by the virtual machines on the host machine, wherein the memory pressure events are used to indicate that the memory status of the virtual machines is insufficient; The adjustment queue corresponding to the virtual machine is determined to be the out-of-memory queue, and the adjustment priority of the virtual machine is set to the highest priority.

3. The method according to claim 1, characterized in that, The step of controlling the virtual machines in the memory-sufficient queue to release memory for the virtual machines in the memory-insufficient queue according to the adjusted priority includes: According to the order of adjustment priority from high to low, each virtual machine in the insufficient memory queue is obtained as a virtual machine to be deflated. According to the adjustment priority, a corresponding target inflation virtual machine is matched for the virtual machine to be deflated, and the target inflation virtual machine is controlled to release memory for the virtual machine to be deflated; The target inflatable virtual machine is a virtual machine in the memory-sufficient queue.

4. The method according to claim 3, characterized in that, The step of matching a corresponding target inflation virtual machine to the virtual machine to be deflated according to the adjusted priority, and controlling the target inflation virtual machine to release memory for the virtual machine to be deflated, includes: According to the order of adjustment priority from high to low, virtual machines are obtained one by one from the memory-sufficient queue as the target inflatable virtual machines; Determine whether the releasable memory of the target inflatable virtual machine can meet the memory requirements of the virtual machine to be deflated; If so, then according to the memory requirement, control the target inflatable virtual machine to release memory for the virtual machine to be deflated; If not, then according to the releasable memory, control the target inflatable virtual machine to release memory for the virtual machine to be deflated, and continue to acquire new target inflatable virtual machines to release memory for the virtual machine to be deflated, until the released memory meets the memory requirements of the virtual machine to be deflated.

5. The method according to claim 3, characterized in that, The step of matching a corresponding target inflation virtual machine to the virtual machine to be deflated according to the adjusted priority, and controlling the target inflation virtual machine to release memory for the virtual machine to be deflated, includes: According to the order of adjustment priority from high to low, control the virtual machines in the memory-sufficient queue to release memory with a preset memory granularity one by one until the released memory meets the memory requirements of the virtual machine to be deflated. If, after traversing the memory-sufficient queue, the released memory does not meet the memory requirements of the virtual machine to be deflated, then, following the order of adjustment priority from high to low, the virtual machines in the memory-sufficient queue are controlled to release memory with a preset memory granularity one by one until the released memory meets the memory requirements of the virtual machine to be deflated.

6. The method according to claim 3, characterized in that, The step of matching a corresponding target inflation virtual machine to the virtual machine to be deflated according to the adjusted priority, and controlling the target inflation virtual machine to release memory for the virtual machine to be deflated, includes: Based on the memory usage information of each virtual machine in the memory-sufficient queue, determine the memory release weight of each virtual machine in the memory-sufficient queue; Based on the memory release weight of each virtual machine and the memory requirement of the virtual machine to be de-energized, the target memory to be released for each virtual machine is determined. Based on the target memory release for each virtual machine, control each virtual machine to release memory for the virtual machine to be degassed.

7. A system for dynamically adjusting virtual machine memory, characterized in that, The system includes: a host machine, virtual machines, agents, and a scheduler; each agent runs on one of the virtual machines; the scheduler runs in the Libvirt process of the host machine; the scheduler communicates with each agent via a vsock device; the scheduler controls the virtual machines in the memory-sufficient queue to release memory for the host machine and the virtual machines in the memory-insufficient queue via a balloon device running on the virtual machines; The agent is used to obtain the memory usage information of the virtual machine and report the memory usage information to the scheduler, wherein the memory usage information includes the maximum available memory and the actual memory used; The scheduler is configured to perform the method as described in any one of claims 1-6.

8. A device for dynamically adjusting virtual machine memory, characterized in that, include: A communication module is used to obtain the memory usage information of the host machine and the memory usage information of each virtual machine on the host machine, wherein the memory usage information includes the maximum available memory and the actual memory used; The computation module is used to determine the memory status of each virtual machine and the corresponding adjustment queue for each virtual machine based on the memory usage information of each virtual machine. This includes: determining the free memory of each virtual machine based on its memory usage information; sorting different adjustment queues according to the free memory of each virtual machine, wherein the memory-sufficient queue is sorted from largest to smallest free memory of each virtual machine, and the memory-insufficient queue is sorted from smallest to largest free memory of each virtual machine; determining the adjustment priority of each virtual machine in the sorted adjustment queues, wherein the memory status is either memory-sufficient or memory-insufficient, the adjustment queue is either a memory-sufficient queue or a memory-insufficient queue, and the adjustment priority of each virtual machine is consistent with the order in which the adjustment queues are sorted; and determining the adjustment priority of each virtual machine in the adjustment queues based on its memory usage information. The control module is configured to control virtual machines in the sufficient memory queue to release memory for the host machine and virtual machines in the insufficient memory queue according to the adjustment priority, including: determining the memory status of the host machine based on the host machine's memory usage information; if the host machine has insufficient memory, determining whether the available memory in the sufficient memory queue meets the host machine's memory requirements; if the available memory in the sufficient memory queue meets the host machine's memory requirements, sequentially controlling the virtual machines in the sufficient memory queue to release memory of a preset memory granularity according to a preset memory granularity and the adjustment priority, until the host machine has sufficient memory; if the available memory in the sufficient memory queue does not meet the host machine's memory requirements, executing a memory decompression procedure; if the host machine has sufficient memory, controlling each virtual machine in the sufficient memory queue to release memory for each virtual machine in the insufficient memory queue according to the adjustment priority.

9. A device for dynamically adjusting virtual machine memory, characterized in that, include: Memory and at least one processor; The memory is used to store computer programs; The at least one processor is used to run a computer program stored in the memory to implement the method as described in any one of claims 1-6.

10. A computer-readable storage medium, characterized in that, It contains computer programs; When the computer program is executed by a processor, it implements the method as described in any one of claims 1-6.