A virtual machine memory allocation method, device, equipment and storage medium

By setting memory compression thresholds and bloat thresholds in the cloud platform, combining virtual machine memory reservation and balloon technology, dynamically adjusting virtual machine memory, solving the problems of low operating efficiency and poor stability of virtual machines, and achieving more efficient memory utilization.

CN115454578BActive Publication Date: 2025-08-29ZHENGZHOU INSPUR DATA TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211259553.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-10-14
Publication Date
2025-08-29
Estimated Expiration
2042-10-14

AI Technical Summary

Technical Problem

The existing technology cannot dynamically adjust the virtual machine memory in the cloud platform, resulting in low operating efficiency and poor stability of the virtual machine, especially in the case of excessive memory of the host, the impact is more significant.

Method used

By setting memory compression thresholds and bloating thresholds, combining virtual machine memory reservation technology and memory balloon technology, the virtual machine manager is used to dynamically adjust the virtual machine memory to achieve dynamic adjustments in the case of excessive virtual machine memory on the cloud platform.

Benefits of technology

It improves the operating efficiency and stability of the virtual machine, makes full use of the host's physical memory, improves the cluster memory utilization rate, and reduces costs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115454578B_ABST
    Figure CN115454578B_ABST
Patent Text Reader

Abstract

The present application discloses a virtual machine memory allocation method, apparatus, device and storage medium, relating to the field of cloud computing technology, including: when a virtual machine manager in a host machine of a cloud platform cluster receives a detection request sent by a monitoring agent process, the memory usage rate of the virtual machine in the host machine is detected to obtain a first memory usage rate; whether the first memory usage rate is greater than a memory compression threshold, if so, whether the maximum memory value of the virtual machine when the memory balloon mechanism is not triggered is less than the memory value initially allocated when the virtual machine is created, if so, the memory of the virtual machine is expanded; if the first memory usage rate is not greater than the memory compression threshold, whether the first memory usage rate is less than the memory expansion threshold, if so, whether the maximum memory value is greater than the reserved memory value of the virtual machine, if so, the memory of the virtual machine is compressed. The present application realizes virtual machine memory over-allocation and dynamic adjustment of virtual machine memory in a cluster.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of cloud computing technology, and in particular to a virtual machine memory allocation method, apparatus, device, and storage medium. Background Art

[0002] As cloud computing technology is widely used in people's daily lives, improving the utilization of cloud platform resources has always been a goal pursued by mainstream cloud vendors.

[0003] Currently, to modify the amount of host machine memory occupied by a virtual machine, it is necessary to first shut down the virtual machine, then modify the memory configuration parameters at startup and restart the virtual machine. However, a virtual machine memory modification method based on memory ballooning technology can dynamically adjust the host machine's memory resources occupied by the virtual machine while it is running. Memory ballooning technology can easily and dynamically adjust the virtual machine's memory size to fully utilize host machine resources. When host machine resources are limited, the hypervisor (virtual machine monitor) can send a command request to the virtual machine to inflate the virtual machine's memory balloon through the memory balloon mechanism, freeing up some memory for use by other virtual machine processes. When virtual machine memory resources are limited, the virtual machine's memory balloon can also be compressed, allowing the host machine to return some free memory to the virtual machine, ensuring the normal operation of the virtual machine business. However, the above-mentioned method based on memory balloon technology requires users to manually input the memory size modification, and can only modify the memory size of a single virtual machine at a time. Therefore, it is not applicable when a cloud platform cluster contains a large number of virtual machines. In addition, it is impossible to dynamically adjust the memory usage of the virtual machine when the host machine's memory is over-allocated, resulting in low operating efficiency of the virtual machines in the cloud platform. In addition, it also has a certain impact on the stability of the virtual machine operation when the host machine's memory is over-allocated. Summary of the Invention

[0004] In view of this, the purpose of this application is to provide a virtual machine memory allocation method, device, equipment and storage medium, which can realize dynamic adjustment of the memory of virtual machines in the cluster when the virtual machine memory of the cloud platform is over-allocated, ensuring that the host machine can operate normally while the virtual machine can operate efficiently and stably, and at the same time, it can make more full use of the physical memory of the host machine to improve the memory utilization of the host machine in the cluster, thereby achieving the purpose of reducing costs and increasing efficiency. The specific scheme is as follows:

[0005] In a first aspect, the present application discloses a virtual machine memory allocation method, comprising:

[0006] When a virtual machine manager of a host machine in the cloud platform cluster receives a detection request sent by the monitoring agent process, the virtual machine manager detects the memory usage of each virtual machine in the host machine to obtain a first memory usage;

[0007] Determine whether the first memory usage is greater than a memory compression threshold, and if so, determine whether a maximum memory value of the virtual machine when the memory balloon mechanism is not triggered is less than a memory value initially allocated when the virtual machine is created;

[0008] If the maximum memory value is less than the initially allocated memory value, the memory of the virtual machine is expanded;

[0009] If the first memory usage rate is not greater than the memory compression threshold, determining whether the first memory usage rate is less than a preset memory expansion threshold;

[0010] If the first memory usage rate is less than the preset memory expansion threshold, it is determined whether the maximum memory value is greater than the reserved memory value of the virtual machine; if so, the memory of the virtual machine is compressed.

[0011] Optionally, the virtual machine memory allocation method further includes:

[0012] Deploy the environment of the cloud platform cluster and determine the memory over-allocation ratio for the virtual machine;

[0013] The memory size of the host machine is obtained to obtain the host machine memory value, and the memory of the virtual machine is over-allocated according to the memory over-allocation ratio and the host machine memory value to obtain the virtual machine whose memory size is the initially allocated memory value.

[0014] Optionally, the expanding the memory of the virtual machine includes:

[0015] Obtain the memory value currently used by the virtual machine to obtain the actual memory value used by the virtual machine;

[0016] A memory increment value when the virtual machine triggers a memory expansion is calculated according to the actual memory used by the virtual machine, the memory compression threshold, the memory expansion threshold and the maximum memory value, and the memory expansion processing of the virtual machine is performed using the memory increment value.

[0017] Optionally, the compressing the memory of the virtual machine includes:

[0018] A memory compression value when the virtual machine triggers memory compression is calculated based on the actual memory used by the virtual machine, the memory compression threshold, the memory expansion threshold and the maximum memory value, and the memory compression value is used to compress the memory of the virtual machine.

[0019] Optionally, the virtual machine memory allocation method further includes:

[0020] Detecting the memory usage of the host machine in the cloud platform cluster through the cloud platform monitoring system to obtain a second memory usage rate;

[0021] Determining whether the second memory usage exceeds a host memory usage threshold for triggering the memory balloon mechanism;

[0022] If the second memory usage exceeds the host memory usage threshold, the step of determining whether the first memory usage is greater than a memory compression threshold is triggered.

[0023] Optionally, detecting the memory usage of the host machine in the cloud platform cluster by the cloud platform monitoring system to obtain the second memory usage includes:

[0024] The cloud platform monitoring system detects the memory usage of the host machine in the cloud platform cluster according to a preset time period to obtain a second memory usage.

[0025] Optionally, the virtual machine memory allocation method further includes:

[0026] Obtain the current physical memory of the host machine and the current memory usage of the virtual machine to obtain the current host machine memory value and the current virtual machine memory usage;

[0027] Determine whether the current host machine memory value is greater than a first threshold or whether the current virtual machine memory usage is greater than a second threshold;

[0028] If the current host machine memory value is greater than a first threshold or the current virtual machine memory usage is greater than a second threshold, a corresponding alarm signal is generated to remind the user that the host machine and the virtual machine are at risk of memory exhaustion.

[0029] In a second aspect, the present application discloses a virtual machine memory allocation device, comprising:

[0030] a memory usage detection module, configured to detect the memory usage of each virtual machine in the host machine in the cloud platform cluster when the virtual machine manager of the host machine receives a detection request sent by the monitoring agent process, and obtain a first memory usage;

[0031] A first determining module, configured to determine whether the first memory usage rate is greater than a memory compression threshold;

[0032] a second judgment module, configured to, if the first memory usage rate is greater than the memory compression threshold, determine whether a maximum memory value of the virtual machine when the memory balloon mechanism is not triggered is less than a memory value initially allocated when the virtual machine is created;

[0033] an expansion processing module, configured to expand the memory of the virtual machine if the maximum memory value is less than the initially allocated memory value;

[0034] a third determining module, configured to determine whether the first memory usage rate is less than a preset memory expansion threshold if the first memory usage rate is not greater than the memory compression threshold;

[0035] a fourth determination module, configured to determine whether the maximum memory value is greater than the reserved memory value of the virtual machine if the first memory usage rate is less than the preset memory expansion threshold;

[0036] A compression processing module is used to compress the memory of the virtual machine if the maximum memory value is greater than the reserved memory value of the virtual machine.

[0037] In a third aspect, the present application discloses an electronic device comprising a processor and a memory; wherein the processor implements the aforementioned virtual machine memory allocation method when executing a computer program stored in the memory.

[0038] In a fourth aspect, the present application discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, the aforementioned virtual machine memory allocation method is implemented.

[0039] It can be seen that when the virtual machine manager of the host machine in the cloud platform cluster receives a detection request sent by the monitoring agent process, the present application detects the memory usage of each virtual machine in the host machine to obtain a first memory usage; determines whether the first memory usage is greater than the memory compression threshold, and if so, determines whether the maximum memory value of the virtual machine when the memory balloon mechanism is not triggered is less than the memory value initially allocated when the virtual machine is created; if the maximum memory value is less than the initially allocated memory value, the memory of the virtual machine is expanded; if the first memory usage is not greater than the memory compression threshold, determines whether the first memory usage is less than the preset memory expansion threshold; if the first memory usage is less than the preset memory expansion threshold, determines whether the maximum memory value is greater than the reserved memory value of the virtual machine, and if so, compresses the memory of the virtual machine. This application sets thresholds and is based on virtual machine memory reservation technology and memory balloon technology, as well as combined with the cloud platform's virtual machine manager to achieve dynamic adjustment of the memory of virtual machines in the cluster when the cloud platform's virtual machine memory is over-allocated, ensuring that the host machine can operate normally while the virtual machines can run efficiently and stably. At the same time, it can make more effective use of the host machine's physical memory to improve the memory utilization of the host machines in the cluster, thereby achieving the goal of reducing costs and increasing efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0040] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are merely embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without any creative work.

[0041] Figure 1 This is a flow chart of a virtual machine memory allocation method disclosed in this application;

[0042] Figure 2 A schematic diagram of the relationship between a specific monitoring system and a host machine disclosed in this application;

[0043] Figure 3 This is a flowchart of a specific virtual machine memory allocation method disclosed in this application;

[0044] Figure 4 This is a flow chart of a virtual machine memory allocation method disclosed in this application;

[0045] Figure 5 This is a structural diagram of a virtual machine memory allocation device disclosed in this application;

[0046] Figure 6 This is a structural diagram of an electronic device disclosed in this application. DETAILED DESCRIPTION

[0047] The following will be combined with the drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.

[0048] The present application discloses a method for allocating memory to a virtual machine. Figure 1 As shown, the method includes:

[0049] Step S11: When the virtual machine manager of the host machine in the cloud platform cluster receives a detection request sent by the monitoring agent process, it detects the memory usage of each virtual machine in the host machine to obtain a first memory usage.

[0050] In this embodiment, when a virtual machine manager (VMM) in a host machine in a cloud platform cluster receives a detection request from a monitor-agent process, it first detects the memory usage of each virtual machine in the host machine to obtain the corresponding virtual machine memory usage, i.e., the first memory usage. The time at which the virtual machine manager receives the detection request from the monitor-agent process can be set according to actual needs, such as every five minutes.

[0051] See also Figure 2 As shown, Figure 2 The figure shows the relationship between the cloud platform's monitoring system, host machine, and virtual machine. The monitoring agent process in the monitoring system can periodically send triggers to the virtual machine to adjust the memory time, and then call the virtual machine memory task mask_m. The host machine can periodically report its own memory usage to the control system.

[0052] Step S12: determining whether the first memory usage rate is greater than a memory compression threshold; if so, determining whether the maximum memory value of the virtual machine when the memory balloon mechanism is not triggered is less than the memory value initially allocated when the virtual machine is created.

[0053] In this embodiment, after detecting the memory usage of each virtual machine in the host machine to obtain a first memory usage, a further determination is made as to whether the first memory usage is greater than a preset memory compression threshold. If the first memory usage is greater than the memory compression threshold, a further determination is made as to whether the maximum memory value of the virtual machine when the memory balloon mechanism is not triggered is less than the memory value initially allocated when the virtual machine is created. The memory compression threshold refers to the threshold for triggering virtual machine memory compression, i.e., the lower watermark of the virtual machine's memory usage; and the maximum memory value refers to the maximum memory value that the virtual machine can request from the system when the memory balloon mechanism is not triggered.

[0054] It should be pointed out that the present application requires the use of memory balloon mechanism technology to over-allocate the memory of the virtual machine in the cloud platform in advance, which may specifically include: deploying the environment of the cloud platform cluster and determining the memory over-allocation ratio for the virtual machine; obtaining the memory size of the host machine, obtaining the host machine memory value, and over-allocating the memory of the virtual machine according to the memory over-allocation ratio and the host machine memory value, so as to obtain the virtual machine whose memory size is the initially allocated memory value. For example, after the cluster environment is deployed, the user virtual machine is distributed. If the memory over-allocation ratio of the virtual machine is m:1, and m≥1, then when the host machine's memory is 100G, the memory that can be allocated to the virtual machine is 100*mG, that is, the memory that can be allocated to the virtual machine is m times the memory of the host machine. Furthermore, all virtual machines distributed by the host machines in the cluster can be over-allocated in memory, and the host machine node memory over-allocation to the virtual machine is saturated. It should be pointed out that memory reservation is configured when creating the virtual machine, and the memory reservation value is the minimum memory value to ensure the normal operation of the virtual machine.

[0055] Step S13: If the maximum memory value is smaller than the initially allocated memory value, the memory of the virtual machine is expanded.

[0056] In this embodiment, if the maximum memory value of the virtual machine when the memory balloon mechanism is not triggered is less than the memory value initially allocated when the virtual machine is created, it indicates that the memory allocated to the virtual machine is too small and more memory needs to be requested from the system, i.e., memory inflation processing is performed.

[0057] Step S14: If the first memory usage is not greater than the memory compression threshold, determine whether the first memory usage is less than a preset memory expansion threshold.

[0058] In this embodiment, if the first memory usage is not greater than the memory compression threshold, a further determination is made as to whether the first memory usage is less than a preset memory expansion threshold, where the memory expansion threshold is a threshold that triggers virtual machine memory expansion, i.e., an upper limit of virtual machine memory usage.

[0059] Step S15: If the first memory usage rate is less than the preset memory expansion threshold, determine whether the maximum memory value is greater than the reserved memory value of the virtual machine; if so, compress the memory of the virtual machine.

[0060] In this embodiment, if the above-mentioned first memory usage rate is less than the preset memory expansion threshold, it is further determined whether the maximum memory value of the above-mentioned virtual machine when the memory balloon mechanism is not triggered is greater than the reserved memory value of the virtual machine. If the maximum memory value of the above-mentioned virtual machine when the memory balloon mechanism is not triggered is greater than the reserved memory value of the virtual machine, it indicates that the memory allocated to the virtual machine at this time is too large and it is necessary to apply to the system to release some memory, that is, perform memory compression processing.

[0061] It should be noted that, in this embodiment, the step of determining whether the first memory usage is greater than the memory compression threshold can be triggered not only after the memory usage of each virtual machine in the host machine is detected to obtain the first memory usage, but can also be triggered by the following conditions, which can specifically include: detecting the memory usage of the host machines in the cloud platform cluster through the cloud platform monitoring system to obtain a second memory usage; determining whether the second memory usage exceeds the host memory usage threshold for triggering the memory balloon mechanism; and if the second memory usage exceeds the host memory usage threshold, triggering the step of determining whether the first memory usage is greater than the memory compression threshold. That is, the cloud platform monitoring system can detect the memory usage of the host machines in the cloud platform cluster to obtain the corresponding second memory usage, and then determine whether the second memory usage exceeds the host memory usage threshold T1 for triggering the memory balloon mechanism. If the second memory usage exceeds the host memory usage threshold, the step of determining whether the first memory usage is greater than the memory compression threshold can be directly triggered, thereby determining whether the virtual machine needs to perform corresponding expansion or compression processing.

[0062] Specifically, detecting the memory usage of the host machines in the cloud platform cluster using the cloud platform monitoring system to obtain the second memory usage includes detecting the memory usage of the host machines in the cloud platform cluster using the cloud platform monitoring system at a preset time period to obtain the second memory usage. That is, the memory usage of the host machines in the cloud platform cluster can be regularly detected at a preset time period.

[0063] Furthermore, in this embodiment, the virtual machine memory allocation method specifically also includes: obtaining the current physical memory of the host machine and the current memory usage of the virtual machine to obtain the current host machine memory value and the current virtual machine memory usage; judging whether the current host machine memory value is greater than a first threshold or whether the current virtual machine memory usage is greater than a second threshold; if the current host machine memory value is greater than the first threshold or the current virtual machine memory usage is greater than the second threshold, generating a corresponding alarm signal to remind the user that the host machine and the virtual machine are at risk of memory exhaustion. For example, the physical memory of the current host machine and the memory usage of the current virtual machine are first obtained at preset time intervals to obtain the corresponding current host machine memory value and current virtual machine memory usage. Then, it is determined whether the current host machine memory value is greater than a first threshold or whether the current virtual machine memory usage is greater than a second threshold. If the current host machine memory value is greater than the first threshold or the current virtual machine memory usage is greater than the second threshold, it indicates that the current host machine and virtual machine are at risk of memory exhaustion. At this time, a corresponding alarm signal can be generated to prompt the user. For example, when the physical memory of the host machine reaches a certain threshold Te (such as 90%) or the memory usage of the virtual machine has reached a certain threshold Tve of its specification (such as 90%), a serious alarm is reported to prompt the user that the physical memory of the host machine or the virtual machine memory is at risk of exhaustion. Furthermore, the user can take corresponding measures to prevent memory exhaustion, such as expanding the memory of the virtual machine by adding a disk. The determination of the threshold can also be dynamically adjusted according to user needs and the performance of the server or operating system corresponding to the host machine and virtual machine.

[0064] In addition, it should be pointed out that in order to prevent the virtual machine memory usage from changing significantly over a period of time when the virtual machine memory usage is dynamically adjusted, a smoothing adjustment algorithm can be used for optimization.

[0065] It can be seen that in the embodiment of the present application, when the virtual machine manager of the host machine in the cloud platform cluster receives a detection request sent by the monitoring agent process, the memory usage rate of each virtual machine in the host machine is detected to obtain a first memory usage rate; whether the first memory usage rate is greater than the memory compression threshold is determined, and if so, whether the maximum memory value of the virtual machine when the memory balloon mechanism is not triggered is less than the memory value initially allocated when the virtual machine is created; if the maximum memory value is less than the initially allocated memory value, the memory of the virtual machine is expanded; if the first memory usage rate is not greater than the memory compression threshold, whether the first memory usage rate is less than the preset memory expansion threshold is determined; if the first memory usage rate is less than the preset memory expansion threshold, whether the maximum memory value is greater than the reserved memory value of the virtual machine is determined, and if so, the memory of the virtual machine is compressed. The embodiment of the present application sets a threshold value and is based on virtual machine memory reservation technology and memory balloon technology, as well as combined with the virtual machine manager of the cloud platform. This allows dynamic adjustment of the memory of the virtual machines in the cluster when the memory of the cloud platform virtual machines is over-allocated, ensuring that the virtual machines can run efficiently and stably while the host machine operates normally. At the same time, it can make more effective use of the physical memory of the host machine to improve the memory utilization of the host machines in the cluster, thereby achieving the purpose of reducing costs and increasing efficiency.

[0066] The present application embodiment discloses a specific virtual machine memory allocation method, see Figure 3 As shown, the method includes:

[0067] Step S21: When the virtual machine manager of the host machine in the cloud platform cluster receives a detection request sent by the monitoring agent process, it detects the memory usage of each virtual machine in the host machine to obtain a first memory usage.

[0068] Step S22: determining whether the first memory usage rate is greater than a memory compression threshold; if so, determining whether the maximum memory value of the virtual machine when the memory balloon mechanism is not triggered is less than the memory value initially allocated when the virtual machine is created.

[0069] Step S23: If the maximum memory value is less than the initially allocated memory value, the memory value currently used by the virtual machine is obtained to obtain the actual memory value used by the virtual machine.

[0070] In this embodiment, if the maximum memory value is smaller than the initially allocated memory value, the memory value currently used by the virtual machine is acquired to obtain the actual memory value used by the virtual machine.

[0071] Step S24: Calculate the memory increment value when the virtual machine triggers a memory expansion according to the actual memory value used by the virtual machine, the memory compression threshold, the memory expansion threshold and the maximum memory value, and use the memory increment value to expand the memory of the virtual machine.

[0072] In this embodiment, after obtaining the currently used memory value of the virtual machine to obtain the actual used memory value of the virtual machine, the memory increment value when the virtual machine triggers a memory expansion can be calculated using the following formula:

[0073] b1=2*M2 / (T2+T3)-M1;

[0074] Among them, b1 is the memory increment value when the virtual machine triggers a memory expansion; M2 is the actual memory value used by the virtual machine; M1 is the maximum memory value; T2 is the memory compression threshold; T3 is the memory expansion threshold.

[0075] Furthermore, after obtaining the memory increment value, the memory of the virtual machine may be expanded, for example, by adding a memory of size b1 on the basis of the current virtual machine memory.

[0076] It should be noted that before performing expansion and compression operations on the virtual machine, it is necessary to impose corresponding constraints on the relevant memory parameters of the virtual machine, such as:

[0077] 2*M2 / M0>T2+T3>2*M2 / M, M2≤M1≤M, 1-T3 <T2<T3;

[0078] Here, M0 is the minimum memory value required to ensure the normal operation of the virtual machine; and M is the memory value initially allocated when the virtual machine is created.

[0079] Step S25: If the first memory usage is not greater than the memory compression threshold, determine whether the first memory usage is less than a preset memory expansion threshold.

[0080] Step S26: If the first memory usage rate is less than the preset memory expansion threshold, determine whether the maximum memory value is greater than the reserved memory value of the virtual machine; if so, calculate the memory compression value when the virtual machine triggers a memory compression based on the actual memory value used by the virtual machine, the memory compression threshold, the memory expansion threshold and the maximum memory value, and use the memory compression value to compress the memory of the virtual machine.

[0081] In this embodiment, if the first memory usage rate is less than the preset memory expansion threshold, it is further determined whether the maximum memory value is greater than the reserved memory value of the virtual machine. If the maximum memory value is greater than the reserved memory value of the virtual machine, the memory compression value when the virtual machine triggers a memory compression can be calculated using the following formula:

[0082] b2=M1-2*M2 / (T2+T3);

[0083] Wherein, b2 is the memory compression value.

[0084] Then we can calculate the expected memory usage of the virtual machine after compression and expansion:

[0085] a1=a2=(T2+T3) / 2.

[0086] For details, see Figure 4 As shown, on the one hand, the monitoring agent process (i.e., Monitor-agent) of the cloud platform regularly detects the memory usage of each host in the cluster. If the physical memory usage of the host exceeds T1 (host memory usage threshold), it triggers the automatic adjustment of the virtual machine memory mechanism, that is, determines whether the memory usage of the virtual machine is greater than T2 and subsequent processes. On the other hand, the VM monitoring agent process in the cloud platform regularly checks the health of VMs. If the VM's memory usage is greater than T2, it further determines whether M1 is less than M. If so, the VM's memory is expanded, for example, by running the command virshqemu-monitor-command uuid--hmp--cmd balloon(M1+b1)(or M). If the VM's memory usage is not greater than T2, it further determines whether it is less than T3. If so, it determines whether M1 is greater than M0. If so, the VM's memory is compressed, for example, by running the command virshqemu-monitor-command uuid--hmp--cmd balloon(M1-b2)(or M0). Furthermore, if the VM's memory usage exceeds the threshold T3 and the available memory after VM memory expansion exceeds M, or if the host's memory usage is greater than or equal to Te, a monitoring alarm is generated to alert users of memory resource shortages on the host or VM, preventing resource constraints from impacting normal user services.

[0087] Step S27: Obtain the physical memory of the current host machine and the memory usage of the current virtual machine to obtain the current host machine memory value and the current virtual machine memory usage.

[0088] Step S28: Determine whether the current host machine memory value is greater than a first threshold or whether the current virtual machine memory usage is greater than a second threshold.

[0089] Step S29: If the current host machine memory value is greater than a first threshold or the current virtual machine memory usage is greater than a second threshold, a corresponding alarm signal is generated to remind the user that the host machine and the virtual machine are at risk of memory exhaustion.

[0090] Among them, for more specific processing procedures of the above steps S21, S22, S25, S27 to S29, reference can be made to the corresponding contents disclosed in the aforementioned embodiments, which will not be repeated here.

[0091] It can be seen that the embodiment of the present application is based on the virtual machine memory reservation technology to ensure the minimum memory that can be allocated to the virtual machine, thereby ensuring the normal operation of the virtual machine; based on the virtual machine memory balloon technology, and dynamically adjusting the allocatable memory of the virtual machine according to the preset threshold, it ensures that the cloud host memory resources are sufficient and the physical machine memory resources are fully utilized; combined with the operation and maintenance monitoring system, and triggering the virtual machine memory dynamic adjustment mechanism according to certain rules; through certain monitoring rules, the host machine and virtual machine in the cloud platform are monitored for resources and alarms are reported.

[0092] As can be seen from the above, the embodiment of the present application realizes cloud platform virtual machine memory over-allocation and can realize dynamic adjustment of virtual machine memory in the cluster according to preset thresholds by combining the cloud platform virtual machine monitoring system and based on virtual machine memory balloon technology and memory reservation technology, thereby ensuring that the cloud platform host service can operate normally while the virtual machine can also operate efficiently and stably, while meeting the user's memory needs, making better use of the host machine's physical memory resources, and providing an alarm reporting mechanism for the host machine's physical resource shortage, thereby ensuring the smooth and healthy operation of the cloud platform in multiple dimensions.

[0093] Correspondingly, the embodiment of the present application also discloses a virtual machine memory allocation device, see Figure 5 As shown, the device includes:

[0094] The memory usage detection module 11 is configured to detect the memory usage of each virtual machine in the host machine in the cloud platform cluster when the virtual machine manager of the host machine receives a detection request sent by the monitoring agent process, and obtain a first memory usage;

[0095] A first judging module 12 is configured to judge whether the first memory usage rate is greater than a memory compression threshold;

[0096] A second judgment module 13 is configured to, if the first memory usage rate is greater than the memory compression threshold, determine whether a maximum memory value of the virtual machine when the memory balloon mechanism is not triggered is less than a memory value initially allocated when the virtual machine is created;

[0097] an expansion processing module 14, configured to expand the memory of the virtual machine if the maximum memory value is less than the initially allocated memory value;

[0098] a third determining module 15, configured to determine whether the first memory usage rate is less than a preset memory expansion threshold if the first memory usage rate is not greater than the memory compression threshold;

[0099] a fourth determining module 16, configured to determine whether the maximum memory value is greater than the reserved memory value of the virtual machine if the first memory usage rate is less than the preset memory expansion threshold;

[0100] The compression processing module 17 is configured to compress the memory of the virtual machine if the maximum memory value is greater than the reserved memory value of the virtual machine.

[0101] Among them, the specific work processes of the above modules can refer to the corresponding contents disclosed in the aforementioned embodiments, which will not be repeated here.

[0102] It can be seen that in an embodiment of the present application, when the virtual machine manager of the host machine in the cloud platform cluster receives a detection request sent by the monitoring agent process, the memory usage of each virtual machine in the host machine is detected to obtain a first memory usage; whether the first memory usage is greater than the memory compression threshold is determined, and if so, whether the maximum memory value of the virtual machine when the memory balloon mechanism is not triggered is less than the memory value initially allocated when the virtual machine is created; if the maximum memory value is less than the initially allocated memory value, the memory of the virtual machine is expanded; if the first memory usage is not greater than the memory compression threshold, whether the first memory usage is less than the preset memory expansion threshold is determined; if the first memory usage is less than the preset memory expansion threshold, whether the maximum memory value is greater than the reserved memory value of the virtual machine is determined, and if so, the memory of the virtual machine is compressed. The embodiment of the present application sets a threshold value and is based on virtual machine memory reservation technology and memory balloon technology, as well as combined with the virtual machine manager of the cloud platform. This allows dynamic adjustment of the memory of the virtual machines in the cluster when the memory of the cloud platform virtual machines is over-allocated, ensuring that the virtual machines can run efficiently and stably while the host machine operates normally. At the same time, it can make more effective use of the physical memory of the host machine to improve the memory utilization of the host machines in the cluster, thereby achieving the purpose of reducing costs and increasing efficiency.

[0103] In some specific embodiments, the virtual machine memory allocation device may further include:

[0104] A cluster environment deployment unit, configured to deploy the environment of the cloud platform cluster;

[0105] A memory over-allocation ratio determining unit, configured to determine a memory over-allocation ratio for the virtual machine;

[0106] A memory size acquisition unit, configured to acquire the memory size of the host machine and obtain a host machine memory value;

[0107] A memory over-allocation unit is used to over-allocate the memory of the virtual machine according to the memory over-allocation ratio and the host machine memory value to obtain the virtual machine whose memory size is the initially allocated memory value.

[0108] In some specific embodiments, the expansion processing module 14 may specifically include:

[0109] A memory value obtaining unit, configured to obtain a memory value currently used by the virtual machine, and obtain an actual memory value used by the virtual machine;

[0110] an incremental value calculation unit, configured to calculate a memory incremental value when the virtual machine triggers a memory expansion according to the actual memory value used by the virtual machine, the memory compression threshold, the memory expansion threshold, and the maximum memory value;

[0111] An expansion processing unit is used to expand the memory of the virtual machine using the memory increment value.

[0112] In some specific embodiments, the compression processing module 17 may specifically include:

[0113] a compression value calculation unit, configured to calculate a memory compression value when the virtual machine triggers a memory compression according to the actual memory usage of the virtual machine, the memory compression threshold, the memory expansion threshold, and the maximum memory value;

[0114] A compression processing unit is used to compress the memory of the virtual machine using the memory compression value.

[0115] In some specific embodiments, the virtual machine memory allocation device may further include:

[0116] A first memory usage detection unit is configured to detect the memory usage of the host machine in the cloud platform cluster through a cloud platform monitoring system to obtain a second memory usage;

[0117] a first determining unit, configured to determine whether the second memory usage exceeds a host memory usage threshold for triggering the memory balloon mechanism;

[0118] A triggering unit is configured to trigger the step of determining whether the first memory usage is greater than a memory compression threshold if the second memory usage exceeds the host memory usage threshold.

[0119] In some specific embodiments, the first memory usage detection unit may specifically include:

[0120] The second memory usage detection unit is used to detect the memory usage of the host machine in the cloud platform cluster through the cloud platform monitoring system and according to a preset time period to obtain a second memory usage.

[0121] In some specific embodiments, the virtual machine memory allocation device may further include:

[0122] A memory usage acquisition unit is used to acquire the physical memory of the current host machine and the memory usage of the current virtual machine, and obtain the current host machine memory value and the current virtual machine memory usage;

[0123] A second judgment unit is used to judge whether the current host machine memory value is greater than a first threshold or whether the current virtual machine memory usage is greater than a second threshold;

[0124] The alarm signal generating unit is used to generate a corresponding alarm signal if the current host machine memory value is greater than a first threshold or the current virtual machine memory usage is greater than a second threshold, so as to prompt the user that the host machine and the virtual machine are at risk of memory exhaustion.

[0125] Furthermore, the embodiment of the present application also discloses an electronic device, Figure 6 This is a structural diagram of an electronic device 20 according to an exemplary embodiment. The content in the diagram should not be considered as any limitation to the scope of application of the present application.

[0126] Figure 6 This is a schematic diagram of the structure of an electronic device 20 provided in an embodiment of the present application. The electronic device 20 may specifically include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. The memory 22 is used to store a computer program, which is loaded and executed by the processor 21 to implement the relevant steps of the virtual machine memory allocation method disclosed in any of the aforementioned embodiments. Furthermore, the electronic device 20 in this embodiment may specifically be an electronic computer.

[0127] In this embodiment, the power supply 23 is used to provide operating voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and the external device. The communication protocol it follows is any communication protocol that can be applied to the technical solution of this application and is not specifically limited here; the input and output interface 25 is used to obtain external input data or output data to the outside world. Its specific interface type can be selected according to specific application needs and is not specifically limited here.

[0128] In addition, the memory 22, as a carrier for resource storage, can be a read-only memory, random access memory, disk or CD, etc. The resources stored thereon can include an operating system 221, a computer program 222, etc., and the storage method can be temporary storage or permanent storage.

[0129] The operating system 221 is used to manage and control the hardware devices on the electronic device 20 and the computer program 222, which can be Windows Server, Netware, Unix, Linux, etc. In addition to including a computer program that can be used to implement the virtual machine memory allocation method executed by the electronic device 20 disclosed in any of the aforementioned embodiments, the computer program 222 can further include a computer program that can be used to perform other specific tasks.

[0130] Furthermore, this application also discloses a computer-readable storage medium for storing a computer program; wherein, when executed by a processor, the computer program implements the aforementioned virtual machine memory allocation method. The specific steps of this method can be referred to the corresponding contents disclosed in the aforementioned embodiments and will not be repeated here.

[0131] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from the other embodiments. Reference can be made to the descriptions of the identical or similar parts between the various embodiments. For the devices disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the descriptions are relatively simple, and the relevant parts can be referred to the descriptions of the methods.

[0132] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the above description has generally described the components and steps of each example according to their functions. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0133] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), internal memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.

[0134] Finally, it should be noted that, in this document, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of additional identical elements in the process, method, article, or device comprising the element.

[0135] The above is a detailed introduction to a virtual machine memory allocation method, device, equipment and storage medium provided by the present application. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea; at the same time, for general technical personnel in this field, based on the ideas of the present application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.

Claims

1. A virtual machine memory allocation method, characterized in that: include: When a virtual machine manager of a host machine in the cloud platform cluster receives a detection request sent by the monitoring agent process, the virtual machine manager detects the memory usage of each virtual machine in the host machine to obtain a first memory usage; Determine whether the first memory usage is greater than a memory compression threshold, and if so, determine whether a maximum memory value of the virtual machine when the memory balloon mechanism is not triggered is less than a memory value initially allocated when the virtual machine is created; If the maximum memory value is less than the initially allocated memory value, the memory of the virtual machine is expanded; If the first memory usage rate is not greater than the memory compression threshold, determining whether the first memory usage rate is less than a preset memory expansion threshold; If the first memory usage rate is less than the preset memory expansion threshold, determining whether the maximum memory value is greater than the reserved memory value of the virtual machine, and if so, compressing the memory of the virtual machine; The memory expansion processing of the virtual machine includes: obtaining the memory value currently used by the virtual machine to obtain the actual memory value used by the virtual machine; calculating the memory increment value when the virtual machine triggers a memory expansion according to the actual memory value used by the virtual machine, the memory compression threshold, the memory expansion threshold and the maximum memory value, and expanding the memory of the virtual machine using the memory increment value; The compressing process of the memory of the virtual machine includes: calculating a memory compression value when the virtual machine triggers memory compression according to the actual memory value used by the virtual machine, the memory compression threshold, the memory expansion threshold and the maximum memory value, and compressing the memory of the virtual machine using the memory compression value.

2. The virtual machine memory allocation method according to claim 1, wherein: Also includes: Deploy the environment of the cloud platform cluster and determine the memory over-allocation ratio for the virtual machine; The memory size of the host machine is obtained to obtain the host machine memory value, and the memory of the virtual machine is over-allocated according to the memory over-allocation ratio and the host machine memory value to obtain the virtual machine whose memory size is the initially allocated memory value.

3. The virtual machine memory allocation method according to claim 1, wherein: Also includes: Detecting the memory usage of the host machine in the cloud platform cluster through the cloud platform monitoring system to obtain a second memory usage rate; Determining whether the second memory usage exceeds a host memory usage threshold for triggering the memory balloon mechanism; If the second memory usage exceeds the host memory usage threshold, the step of determining whether the first memory usage is greater than a memory compression threshold is triggered.

4. The virtual machine memory allocation method according to claim 3, wherein: The detecting the memory usage of the host machine in the cloud platform cluster by the cloud platform monitoring system to obtain the second memory usage includes: The cloud platform monitoring system detects the memory usage of the host machine in the cloud platform cluster according to a preset time period to obtain a second memory usage.

5. The virtual machine memory allocation method according to any one of claims 1 to 4, characterized in that: Also includes: Obtain the current physical memory of the host machine and the current memory usage of the virtual machine to obtain the current host machine memory value and the current virtual machine memory usage; Determine whether the current host machine memory value is greater than a first threshold or whether the current virtual machine memory usage is greater than a second threshold; If the current host machine memory value is greater than a first threshold or the current virtual machine memory usage is greater than a second threshold, a corresponding alarm signal is generated to remind the user that the host machine and the virtual machine are at risk of memory exhaustion.

6. A virtual machine memory allocation device, characterized in that: include: a memory usage detection module, configured to detect the memory usage of each virtual machine in the host machine in the cloud platform cluster when the virtual machine manager of the host machine receives a detection request sent by the monitoring agent process, and obtain a first memory usage; A first determining module, configured to determine whether the first memory usage rate is greater than a memory compression threshold; a second judgment module, configured to, if the first memory usage rate is greater than the memory compression threshold, determine whether a maximum memory value of the virtual machine when the memory balloon mechanism is not triggered is less than a memory value initially allocated when the virtual machine is created; an expansion processing module, configured to expand the memory of the virtual machine if the maximum memory value is less than the initially allocated memory value; a third determining module, configured to determine whether the first memory usage rate is less than a preset memory expansion threshold if the first memory usage rate is not greater than the memory compression threshold; a fourth determination module, configured to determine whether the maximum memory value is greater than the reserved memory value of the virtual machine if the first memory usage rate is less than the preset memory expansion threshold; a compression processing module, configured to compress the memory of the virtual machine if the maximum memory value is greater than the reserved memory value of the virtual machine; The expansion processing module is specifically configured to obtain the memory value currently used by the virtual machine to obtain the actual memory value used by the virtual machine; calculate the memory increment value when the virtual machine triggers a memory expansion according to the actual memory value used by the virtual machine, the memory compression threshold, the memory expansion threshold, and the maximum memory value; and perform memory expansion processing on the virtual machine using the memory increment value; The compression processing module is specifically used to calculate the memory compression value when the virtual machine triggers memory compression based on the actual memory used by the virtual machine, the memory compression threshold, the memory expansion threshold and the maximum memory value, and use the memory compression value to compress the memory of the virtual machine.

7. An electronic device, characterized in that: The method comprises a processor and a memory; wherein, when the processor executes the computer program stored in the memory, the method for allocating memory for a virtual machine according to any one of claims 1 to 5 is implemented.

8. A computer-readable storage medium, characterized in that Used to store computer programs; wherein, when the computer program is executed by a processor, the virtual machine memory allocation method according to any one of claims 1 to 5 is implemented.

Citation Information

Patent Citations

  • Virtual machine memory allocation method and device and terminal

    CN108958891A

  • Virtual machine memory optimization processing method and related device

    CN111651236A