A cloud platform virtual machine memory scaling method and device and storage medium
By configuring Memtool to manage memory in the virtual machine operating system and utilizing the guest physical memory address allocated by the kernel, the problem of the complicated virtual machine memory scaling process is solved, and efficient memory resource management and utilization are achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- JINAN INSPUR DATA TECH CO LTD
- Filing Date
- 2022-07-30
- Publication Date
- 2026-05-29
AI Technical Summary
In existing technologies, the process of scaling virtual machine memory is complex and makes it difficult to efficiently manage the allocation of memory resources between the virtual machine and the host machine.
By configuring Memtool to manage memory in the virtual machine operating system, and utilizing the guest physical memory address allocated by the kernel, the virtual machine memory can be scaled down and restored, avoiding modifications to the kernel. Memtool can also virtually occupy the guest physical memory address to release it for the host machine to use.
It enables efficient management of virtual machine memory scaling down and recovery without modifying the kernel, simplifying the memory resource allocation process and improving memory utilization efficiency.
Smart Images

Figure CN115309504B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of memory reduction technology, and in particular to a method, apparatus and storage medium for reducing virtual machine memory on a cloud platform. Background Technology
[0002] Virtual machine software allows you to create multiple virtual machines on a physical computer. These virtual machines function just like real computers; for example, they can install operating systems, applications, and access network resources. A virtual machine is an application running on a physical computer, but from the perspective of the application running within it, the virtual machine is a real computer.
[0003] With the rapid development of virtual machine technology, more and more technologies related to virtual machines are emerging. Memory scaling and device passthrough technologies are specifically designed for virtual machine memory. Memory scaling technology refers to the ability to free up virtual machine memory for use by the host machine (referred to as the host machine in this article), or to allocate host machine memory to the virtual machine, thereby achieving virtual machine memory scaling. Currently, virtual machine scaling is mostly achieved by modifying the virtual machine memory page table, a complex process. Summary of the Invention
[0004] In order to solve the above-mentioned technical problems, or at least partially solve the above-mentioned technical problems, the present invention provides a method, apparatus and storage medium for reducing the memory size of a cloud platform virtual machine.
[0005] In a first aspect, the present invention provides a method for shrinking virtual machine memory on a cloud platform, comprising: configuring Memtool in the operating system of the virtual machine; when the virtual machine is capable of shrinking and receives a shrinking instruction, Memtool requests from the kernel the target guest physical memory address of the shrinking capacity indicated by the shrinking instruction, wherein the target guest physical memory address is the guest physical memory address of contiguous or non-contiguous free memory in the virtual machine; in addition to actually occupying the guest physical memory address, Memtool virtually occupies the allocated target guest physical memory address; when Memtool runs, it only uses the actually occupied guest physical memory address, while the virtually occupied target guest physical memory address is free; the target guest physical memory address is converted to the corresponding target host physical memory address, and the target host physical memory address is released to the host machine for use.
[0006] Furthermore, during virtual machine memory recovery, the target host physical memory address is reassigned to the corresponding virtual machine. The virtual machine whose memory needs to be recovered is matched according to the target host physical memory address. A memory recovery command is sent to the Memtool of the virtual machine whose memory needs to be recovered. Memtool then releases the target guest physical memory address occupied by the virtual machine to the virtual machine kernel.
[0007] Furthermore, before reassigning the target host machine's physical memory address from the host machine to the corresponding virtual machine, the host machine rewrites the memory in the target host machine's physical memory address.
[0008] Furthermore, the methods for determining whether a virtual machine can be scaled down include: Memtool responding to the scaling down command collects the current memory usage of the virtual machine's kernel and applications to obtain the virtual machine's own free memory capacity; Memtool obtains the scaling down capacity from the scaling down command; Memtool compares whether the scaling down capacity is greater than the free memory capacity of each virtual machine. If it is greater, the virtual machine Memtool reports that the virtual machine does not meet the scaling down conditions and cannot be scaled down; if it is less, Memtool requests the target guest physical memory address of the scaling down capacity indicated by the scaling down command from the kernel.
[0009] Furthermore, the process of converting the target guest physical memory address to the corresponding target host physical memory address includes: Memtool reporting its own and the memory usage of the kernel and applications in the virtual machine to the virtual machine monitor, wherein Memtool's own memory usage includes Memtool's virtual usage of the target guest physical memory address and Memtool's actual usage of the guest physical memory address; the virtual machine monitor, based on the pre-configured mapping relationship between the guest physical memory address space and the host physical memory address space, obtains the target host physical memory address from the target guest physical memory address.
[0010] Furthermore, it monitors the memory usage of the services running on the host machine. If the memory usage of the services running on the host machine is consistently higher than a first threshold within a set first duration, it automatically triggers a shrinkage command to be sent to the Memtool of the virtual machine whose memory is being shrunk.
[0011] Furthermore, if the percentage of memory used by the services running on the host machine remains below the second percentage threshold for a set second duration, a memory recovery command will be automatically sent to the Memtool of the virtual machine whose memory has been reduced.
[0012] Furthermore, the system monitors the memory usage of the virtual machine kernel and applications that have been scaled down. If the memory usage ratio remains above the third threshold for a set third duration, a memory recovery command is automatically sent to the virtual machine's Memtool.
[0013] Secondly, the present invention provides a cloud platform virtual machine memory reduction device, comprising: a processing unit, a bus unit, and a storage unit, wherein the storage unit includes physical memory, the bus unit connects the storage unit and the processing unit, the storage unit stores a computer program, and the computer program, when executed by the processing unit, implements the cloud platform virtual machine memory reduction method.
[0014] Thirdly, the present invention provides a storage medium for implementing a method for shrinking the memory of a cloud platform virtual machine, wherein the storage medium stores a computer program, and the computer program implements the method for shrinking the memory of a cloud platform virtual machine when executed by a processor.
[0015] The technical solutions provided in the embodiments of the present invention have the following advantages compared with the prior art:
[0016] This invention discloses a method for shrinking virtual machine memory on a cloud platform. By virtually occupying the guest physical memory address of the virtual machine using Memtool, the method achieves two objectives. First, by allocating guest physical memory addresses to Memtool through the kernel, the virtual machine memory can be shrunk. Since kernel memory allocation is a basic kernel function, this application does not require any modification to the kernel itself or the guest physical memory addresses that the kernel can allocate. Memory shrinking can be achieved simply by building Memtool. Second, by virtually occupying guest physical memory addresses through Memtool, the method effectively uses Memtool's memory occupation to manage the guest physical memory addresses released to the host machine by each virtual machine during shrinking.
[0017] When the virtual machine memory is restored, Memtool releases the guest physical memory address to the kernel. The mapping relationship between the guest physical memory address released by Memtool and the host physical memory address remains unchanged. Attached Figure Description
[0018] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.
[0019] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0020] Figure 1 A flowchart of the shrinkage process in a cloud platform virtual machine memory shrinkage method provided in an embodiment of the present invention;
[0021] Figure 2 This is a flowchart provided by an embodiment of the present invention, showing how Memtool requests the target guest physical memory address of the shrinkage capacity indicated by the shrinkage instruction from the kernel when the virtual machine is capable of shrinking and receives a shrinkage instruction.
[0022] Figure 3 This is a flowchart illustrating how the physical memory address of the target client machine is converted to the corresponding physical memory address of the target host machine, and how the physical memory address of the target host machine is released to the host machine for use, as provided in this embodiment of the invention.
[0023] Figure 4 A flowchart illustrating the recovery process in a cloud platform virtual machine memory reduction method provided in this embodiment of the invention;
[0024] Figure 5 A schematic diagram of a cloud platform virtual machine memory reduction device provided for an embodiment of the invention;
[0025] Figure 6 This is a schematic diagram of the architecture of a cloud platform virtual machine memory reduction method provided in an embodiment of the present invention. Detailed Implementation
[0026] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0027] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0028] Hpervisor: The software layer for computing virtualization, also known as the virtualization layer or Virtual Machine Monitor (VMM), is responsible for all hardware resource access of the virtual machine operating system.
[0029] Virtual memory: Memory management in operating systems is complex, and virtual memory is the most important component. Virtual memory serves two purposes: firstly, it expands memory space, giving processes "more memory"; secondly, it provides each process with a consistent, private address space, making it appear as if the process has exclusive access to main memory. In operating systems running within virtual machines, virtual memory is virtualized using virtualization technology.
[0030] In a virtualized environment, the host machine's physical memory is used simultaneously by multiple virtual machine operating systems. However, there is only one physical memory, which cannot meet the requirement that each virtual machine's physical address starts from zero. In this case, a virtual machine monitor (VM) is needed to implement memory virtualization. The VM monitor has control over the host machine's actual physical memory and needs to allocate and manage the physical memory of each virtual machine. The VM monitor provides the virtual machines with a guest physical address (GPA). The virtual machine operating system uses the GPA as its physical memory address. When a virtual machine uses the host machine's physical memory, the VM monitor translates the GPA into the host physical address (HPA) through a mapping relationship, and then uses the corresponding physical memory based on the HPA.
[0031] Memory virtualization technology employs a method to perform GPA and HPA address space translation as follows: For any given virtual machine, a mapping between its GPA and HPA is maintained. The virtual machine operating system operates the guest page table to maintain the translation from guest virtual addresses to guest physical addresses used in the virtual machine. The virtual machine memory management is responsible for maintaining the dynamic mapping relationship between guest physical addresses and host physical addresses. After these two layers of translation, the guest virtual addresses used by the virtual machine are all translated into host physical addresses that can be executed by the physical processor.
[0032] Example 1
[0033] See Figure 1 As shown, the present invention provides a method for reducing the memory size of a cloud platform virtual machine, comprising:
[0034] S100 configures Memtool, which can virtually occupy memory, within the virtual machine's operating system. Besides actually occupying the guest machine's physical memory address, Memtool can also virtually occupy the target guest machine's physical memory address. During runtime, Memtool only utilizes the actually occupied guest machine physical memory address, not the memory virtually occupied by Memtool, thus keeping the host machine's physical memory address corresponding to the target guest machine physical memory address virtually occupied by Memtool free. When the virtual machine is running normally, Memtool virtually occupies a very small amount of memory. See also... Figure 6 As shown, Memtool is able to communicate with the virtual machine monitor.
[0035] S200: When the virtual machine is capable of scaling down and receives a scaling-down instruction, Memtool requests from the kernel the target guest physical memory address for the scaling-down capacity indicated by the scaling-down instruction. The target guest physical memory address is the guest physical memory address of contiguous or non-contiguous free memory within the virtual machine.
[0036] In the specific implementation process, please refer to Figure 2 As shown, step S200 includes:
[0037] S201, each virtual machine's Memtool responds to the shrink command by collecting the current memory usage of the virtual machine's kernel and applications, and obtaining the virtual machine's own free memory capacity. When the virtual machine monitor sends a memory shrink command to each virtual machine's Memtool, each virtual machine's Memtool responds to the shrink command by collecting the current memory usage of the virtual machine's kernel and applications, and obtaining the virtual machine's own free memory capacity.
[0038] In practice, when the services running on the host machine require more memory, the virtual machine is automatically or manually scaled down, and a memory scaling-down command is sent to each virtual machine's Memtool via the virtual machine monitor. In one embodiment, the memory usage percentage of the services running on the host machine is monitored. If the memory usage percentage of the services running on the host machine consistently exceeds a first percentage threshold for a set first duration, the virtual machine monitor is automatically triggered to send a scaling-down command to each virtual machine's Memtool. In another embodiment, the virtual machine monitor is manually controlled to send scaling-down commands to each virtual machine's Memtool or the target virtual machine's Memtool.
[0039] The scaling-down instruction includes a preset scaling-down capacity. In one embodiment, the virtual machine monitor generates a corresponding scaling-down instruction according to the preset scaling-down capacity configuration. In another embodiment, the virtual machine monitor dynamically configures the scaling-down capacity based on the free memory capacity of each virtual machine, specifically including: the virtual machine monitor obtains the free memory capacity of each virtual machine, calculates the proportion of the free memory capacity of each virtual machine to the total free memory capacity, obtains the total scaling-down capacity to be released according to business operation requirements, and weights the total scaling-down capacity to the proportion to obtain the individual scaling-down capacity of each virtual machine.
[0040] S202, each virtual machine's Memtool obtains the shrinkage capacity from the shrinkage command and compares the shrinkage capacity with the free memory capacity of its own virtual machine. If a virtual machine's Memtool detects that the free memory capacity of the virtual machine is less than the shrinkage capacity, S203 is executed; if a virtual machine's Memtool detects that the free memory capacity of the virtual machine is greater than the shrinkage capacity, S204 is executed.
[0041] S203, Memtool reports to the virtual machine monitor that the virtual machine does not meet the scaling-down conditions and cannot be scaled down.
[0042] S204, the target guest physical memory address of the shrinking capacity indicated by the Memtool shrinking instruction. In practice, Memtool requests the target guest physical memory address from the kernel, and the kernel allocates the guest physical memory addresses of contiguous or non-contiguous free memory totaling the shrinking capacity to Memtool as the target guest physical memory address.
[0043] S205 After the target guest physical memory address is allocated, Memtool will virtually occupy the allocated target guest physical memory address so that the virtual machine kernel cannot allocate the virtually occupied target guest physical memory address to other processes.
[0044] S300: The target client's physical memory address is translated to obtain the corresponding target host's physical memory address, and the target host's physical memory address is released to the host for use.
[0045] In the specific implementation process, please refer to Figure 3 As shown, S300 includes:
[0046] S301, Memtool reports its own and the virtual machine's kernel and application memory usage to the virtual machine monitor. Memtool's own memory usage includes both its virtual memory usage on the target guest machine and its actual memory usage on the guest machine.
[0047] S302, the virtual machine monitor obtains the corresponding host machine physical memory address based on the target guest physical memory address virtually occupied by Memtool in each virtual machine, and uses the obtained host machine physical memory address as the target host machine physical memory address. In specific implementation, the virtual machine monitor obtains the virtually occupied target guest physical memory address based on the virtual occupancy status of the target guest physical memory address reported by Memtool. The virtual machine monitor then uses a preset mapping relationship between guest physical memory addresses and host physical memory addresses to obtain the corresponding host machine physical memory address as the target host machine physical memory address.
[0048] In step S303, the virtual machine monitor releases the target host's physical memory address back to the host machine. Before the virtual machine memory is restored, the host machine can use the target host's physical memory address obtained by shrinking the virtual machine's memory for business processing.
[0049] See Figure 4 As shown, the cloud platform virtual machine memory reduction method provided by the present invention further includes:
[0050] S10: Before the virtual machine monitor reassigns the target host physical memory address from the host to the corresponding virtual machine, the host machine rewrites the memory in the target host physical memory address to ensure the security of memory data.
[0051] S20, during virtual machine memory recovery, the target host physical memory address is reassigned to the corresponding virtual machine, and a memory recovery command is sent to the virtual machine. In practice, the virtual machine monitor reassigns the target host physical memory address from the host machine to the corresponding virtual machine, matches the virtual machine whose memory needs to be recovered based on the target host physical memory address, and after the target host physical memory address is reassigned to the virtual machine whose memory needs to be recovered, the virtual machine monitor sends a memory recovery command to the virtual machine's Memtool.
[0052] S30, the virtual machine's Memtool receives and responds to the memory recovery command, releasing the target guest physical memory address it occupies to the kernel, so that the kernel can allocate the guest virtual memory address corresponding to the target guest physical memory address released by Memtool to other processes.
[0053] In practice, the virtual machine can automatically restore memory when the services running on the host machine do not require more memory, or manually when the virtual machine is configured to restore memory, or automatically send memory restoration commands to the virtual machine's Memtool through the virtual machine monitor based on the increased memory requirements of the virtual machine's services.
[0054] In one embodiment, if the percentage of memory occupied by the services running on the host machine is consistently lower than a second percentage threshold for a set second duration, the virtual machine monitor is automatically triggered to send a memory recovery command to the Memtool of the virtual machine whose memory has been reduced.
[0055] In one embodiment, when manually configuring the target virtual machine's memory recovery, a memory recovery command is manually sent to the Memtool of the virtual machine whose memory has been scaled down via the virtual machine monitor.
[0056] In one embodiment, the virtual machine monitor monitors the memory usage of the virtual machine kernel and applications. When the memory usage ratio consistently exceeds a third threshold for a set third duration, the virtual machine monitor automatically sends a memory recovery command to the virtual machine's Memtool. This achieves the effect of restoring memory for some busy virtual machines, balancing the needs of both the virtual machine and the host machine.
[0057] Example 2
[0058] See Figure 5 As shown, the present invention provides a cloud platform virtual machine memory reduction device, comprising: a processing unit, a bus unit, and a storage unit, wherein the storage unit includes physical memory, the bus unit connects the storage unit and the processing unit, the storage unit stores a computer program, and when the computer program is executed by the processing unit, it implements the cloud platform virtual machine memory reduction method.
[0059] Example 3
[0060] This invention provides a storage medium for implementing a cloud platform virtual machine memory reduction method. The storage medium stores a computer program, which, when executed by a processor, implements the cloud platform virtual machine memory reduction method.
[0061] In the embodiments provided by this invention, it should be understood that the disclosed structures and methods can be implemented in other ways. For example, the structural embodiments described above are merely illustrative. For instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection through some interfaces, structures, or units, and may be electrical, mechanical, or other forms.
[0062] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0063] Furthermore, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0064] The above description is merely a specific embodiment of the present invention, enabling those skilled in the art to understand or implement the invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the invention. Therefore, the present invention is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features claimed herein.
Claims
1. A method for reducing virtual machine memory size on a cloud platform, characterized in that, include: Configure Memtool in the virtual machine's operating system; The virtual machine monitor generates corresponding shrinkage instructions according to the preset shrinkage capacity configuration. The virtual machine monitor dynamically configures the shrinkage capacity based on the free memory capacity of each virtual machine. This includes: Memtool feeding back the memory usage of itself and the kernel and applications in the virtual machine to the virtual machine monitor; the virtual machine monitor obtaining the free memory capacity of each virtual machine; calculating the proportion of the free memory capacity of each virtual machine to the total free memory capacity; obtaining the total shrinkage capacity to be released based on business operation requirements; and weighting the total shrinkage capacity by the proportion to obtain the shrinkage capacity of each virtual machine. When a virtual machine is capable of scaling down and receives a scaling-down command, Memtool requests the target guest physical memory address of the scaling-down capacity indicated by the command from the kernel. This target guest physical memory address is a guest physical memory address within the virtual machine that is either contiguous or non-contiguous free memory. In addition to actually occupying the guest physical memory address, Memtool virtually occupies the allocated target guest physical memory address. During runtime, Memtool only utilizes the actually occupied guest physical memory address, while the virtually occupied target guest physical memory address remains free. The method for determining whether a virtual machine can scale down includes: Memtool responding to the scaling-down command by collecting the current memory usage of the virtual machine's kernel and applications to obtain the virtual machine's free memory capacity; Memtool obtaining the scaling-down capacity from the scaling-down command; and Memtool comparing the scaling-down capacity with the free memory capacity of each virtual machine. If it is greater, Memtool reports that the virtual machine does not meet the scaling-down conditions and cannot scale down. If it is less, Memtool requests the target guest physical memory address of the scaling-down capacity indicated by the command from the kernel. The target client's physical memory address is translated to obtain the corresponding target host's physical memory address, and then the target host's physical memory address is released to the host for use.
2. The cloud platform virtual machine memory reduction method according to claim 1, characterized in that, When restoring virtual machine memory, the physical memory address of the target host machine is reassigned to the corresponding virtual machine. The virtual machine whose memory needs to be restored is matched according to the physical memory address of the target host machine. A memory restoration command is sent to the Memtool of the virtual machine whose memory needs to be restored. Memtool releases the physical memory address of the target guest machine occupied by the virtual machine to the kernel of the virtual machine.
3. The cloud platform virtual machine memory reduction method according to claim 1, characterized in that, Before reassigning the target host machine's physical memory address from the host machine to the corresponding virtual machine, the host machine rewrites the memory in the target host machine's physical memory address.
4. The cloud platform virtual machine memory reduction method according to claim 1, characterized in that, The process of converting the target guest physical memory address to the corresponding target host physical memory address includes: Memtool reporting its own and the memory usage of the kernel and applications in the virtual machine to the virtual machine monitor, wherein Memtool's own memory usage includes Memtool's virtual usage of the target guest physical memory address and Memtool's actual usage of the guest physical memory address; the virtual machine monitor, based on the mapping relationship between the pre-configured guest physical memory address space and the host physical memory address space, obtains the target host physical memory address from the target guest physical memory address.
5. The cloud platform virtual machine memory reduction method according to claim 1, characterized in that, The system monitors the memory usage of services running on the host machine. If the memory usage of services running on the host machine consistently exceeds a first threshold within a set first duration, it automatically triggers a shrinkage command to be sent to the Memtool of the virtual machine whose memory is being shrunk.
6. The cloud platform virtual machine memory reduction method according to claim 1, characterized in that, If the memory usage of the services running on the host machine remains below the second threshold for a set second duration, a memory recovery command will be automatically sent to the Memtool of the virtual machine whose memory has been reduced.
7. The cloud platform virtual machine memory reduction method according to claim 1, characterized in that, Monitor the memory usage of the virtual machine kernel and applications that have been scaled down. If the memory usage ratio is consistently higher than the third percentage threshold for a set third duration, automatically trigger a memory recovery command to be sent to the virtual machine's Memtool.
8. A cloud platform virtual machine memory reduction device, characterized in that, include: The system includes a processing unit, a bus unit, and a storage unit, wherein the storage unit includes physical memory, the bus unit connects the storage unit and the processing unit, the storage unit stores a computer program, and when the computer program is executed by the processing unit, it implements the cloud platform virtual machine memory reduction method as described in any one of claims 1-7.
9. A storage medium for implementing a method for reducing the memory size of a cloud platform virtual machine, the storage medium storing a computer program, characterized in that, When the computer program is executed by the processor, it implements the cloud platform virtual machine memory reduction method as described in any one of claims 1-7.