Flexible memory management for virtual machines
A virtual machine monitor (VMM) of a computing system may provide flexible memory management for guest virtual machines (guest VMs). The VMM may allocate a flexible amount of memory that is accessible to a guest VM. A guest VM may be configured, such as by VMM, to utilize a larger fixed amount of guest memory. A memory access error may be generated when guest VM accesses a memory location outside of the flexible memory. The VMM may receive the memory access error and allocate additional memory including at least the memory location to the flexible memory. The memory location may then be accessed without triggering a failure.
1 . A method comprising:
allocating, by a virtual machine monitor executing at a host computing system, an amount of memory for a guest virtual machine, the amount of memory being less than a maximum amount of memory the guest virtual machine is configured to utilize, wherein the host computing system provides an execution environment for the guest virtual machine; and
after starting a boot process of the guest virtual machine:
monitoring, by the virtual machine monitor, memory pressure of the guest virtual machine;
responsive to an attempt to access a memory location of the guest virtual machine that is unallocated, receiving, by the virtual machine monitor, a memory access error that includes an indication of the memory location that was attempted to be accessed;
responsive to determining, by the virtual machine monitor, that an amount of available memory of the host computing system satisfies a threshold amount of available memory:
responsive to receiving the memory access error and based on the memory pressure, allocating, by the virtual machine monitor, additional memory for the guest virtual machine by reducing an amount of memory allocated to a virtual balloon, wherein the additional memory includes the memory location, and wherein the amount of memory allocated to the guest virtual machine is inversely proportional to the amount of memory allocated to the virtual balloon, wherein the additional memory is not allocated where the amount of available memory of the host computing system does not satisfy the threshold amount of available memory; and
accessing, by the virtual machine monitor, the memory location.
2 . The method of claim 1 , wherein accessing the memory location completes an instruction being executed by the guest virtual machine that triggered the memory access error.
3 . The method of claim 1 , wherein the virtual machine monitor determines whether the amount of available memory of the host computing system satisfies the threshold amount of available memory before any adjustment of the amount of memory allocated to the virtual balloon.
4 . The method of claim 1 , further comprising:
responsive to determining, based on the memory pressure, that the amount of memory allocated to the guest virtual machine can be reduced, increasing, by the virtual machine monitor, the amount of memory allocated to the virtual balloon.
5 . The method of claim 4 , further comprising:
responsive to the virtual machine monitor adjusting the amount of memory allocated to the virtual balloon, receiving an updated memory pressure, and
selectively adjusting, based on the updated memory pressure, the amount of memory allocated to the guest virtual machine.
6 . The method of claim 1 , wherein receiving the memory access error comprises intercepting, by the virtual machine monitor, the memory access error before the memory access error is received by the guest virtual machine.
7 . The method of claim 1 , wherein monitoring, by the virtual machine monitor, the memory pressure of the guest virtual machine further comprises:
periodically retrieving pressure stall information from an operating system of the host computing system.
8 . A computing system comprising:
a memory that stores instructions; and
one or more processors that execute the instructions to:
allocate an amount of memory for a guest virtual machine, the amount of memory being less than a maximum amount of memory the guest virtual machine is configured to utilize, wherein the computing system provides an execution environment for the guest virtual machine; and
after starting a boot process of the guest virtual machine:
monitor memory pressure of the guest virtual machine;
responsive to an attempt to access a memory location of the guest virtual machine that is unallocated, receive a memory access error that includes an indication of the memory location that was attempted to be accessed;
determine an amount of available memory of the computing system;
responsive to receiving the memory access error and based on the memory pressure and the amount of available memory of the computing system satisfying a threshold amount of available memory:
allocate additional memory for the guest virtual machine by at least reducing an amount of memory allocated to a virtual balloon, wherein the additional memory includes the memory location, and wherein the amount of memory allocated to the guest virtual machine is inversely proportional to the amount of memory allocated to the virtual balloon; and
access the memory location; and
responsive to receiving the memory access error and based on the memory pressure and the amount of available memory of the computing system not satisfying the threshold amount of available memory:
refrain from reducing the memory allocated to the virtual balloon.
9 . The computing system of claim 8 , wherein accessing the memory location completes an instruction being executed by the guest virtual machine that triggered the memory access error.
10 . The computing system of claim 8 , wherein the one or more processors further execute the instructions to determine whether the amount of available memory of the computing system satisfies the threshold amount of available memory before any adjustment of the amount of memory allocated to the virtual balloon.
11 . The computing system of claim 8 , wherein responsive to determining, based on the memory pressure, that the amount of memory allocated to the guest virtual machine can be reduced, the one or more processors further execute the instructions to increase the amount of memory allocated to the virtual balloon.
12 . The computing system of claim 8 , wherein responsive to adjusting the amount of memory allocated to the virtual balloon, the one or more processors further execute the instructions to:
receive, an updated memory pressure, and
selectively adjust, based on the updated memory pressure, the amount of memory allocated to the guest virtual machine.
13 . A non-transitory computer-readable storage medium comprising instructions, that when executed by one or more processors of a computing system, cause the one or more processors to:
allocate an amount of memory for a guest virtual machine, the amount of memory being less than a maximum amount of memory the guest virtual machine is configured to utilize, wherein the computing system provides an execution environment for the guest virtual machine; and
after starting a boot process of the guest virtual machine:
monitor memory pressure of the guest virtual machine;
responsive to an attempt to access a memory location of the guest virtual machine that is unallocated, receive a memory access error that includes an indication of the memory location that was attempted to be accessed;
determine an amount of available memory of the computing system;
responsive to receiving the memory access error and based on the memory pressure and the amount of available memory of the computing system satisfying a threshold amount of available memory:
allocate additional memory for the guest virtual machine by at least reducing an amount of memory allocated to a virtual balloon, wherein the additional memory includes the memory location, and wherein the amount of memory allocated to the guest virtual machine is inversely proportional to the amount of memory allocated to the virtual balloon; and
access the memory location; and
responsive to receiving the memory access error and based on the memory pressure and the amount of available memory of the computing system not satisfying the threshold amount of available memory:
refrain from reducing the memory allocated to the virtual balloon.
14 . The non-transitory computer-readable storage medium of claim 13 , wherein responsive to determining, based on the memory pressure, that the amount of memory allocated to the guest virtual machine can be reduced, the one or more processors further execute the instructions to:
increase the amount of memory allocated to the virtual balloon;
responsive to adjusting the amount of memory allocated to the virtual balloon, receive an updated memory pressure, and
selectively adjust, based on the updated memory pressure, the amount of memory allocated to the guest virtual machine.
15 . The non-transitory computer-readable storage medium of claim 13 , wherein accessing the memory location completes an instruction being executed by the guest virtual machine that triggered the memory access error.