Configuring Resource Allocation Constraints for Virtual Machines
The host hypervisor allocates physical resources as backing for the virtual resources needed by guest operating systems. You can specify resource allocation preferences that guide and constrain the hypervisor when allocating resources to running virtual machines.
To specify allocation preferences for CPU and memory, use the cpuAllocation and memoryAllocation properties of VirtualMachineConfigSpec. Both properties are data objects of type ResourceAllocationInfo objects. The ResourceAllocationInfo object has properties to specify upper and lower allocation limits, and properties to specify relative priorities when virtual machines contend for resources.
![](images/GUID-7217E771-DE5F-40A7-AC09-404AA0742D33-high.png)
To specify boundaries for resource allocation, use these properties of ResourceAllocationInfo:
- reservation – Lower limit for resource allocation to the virtual machine. If the hypervisor cannot reserve this amount, it does not start the virtual machine. If the running virtual machine uses less than its reserved amount, other running virtual machines can use a part of the reserved resources temporarily.
- limit – Upper
limit for CPU or memory resources assigned to this virtual machine. The virtual
machine does not exceed this limit, even if unused resources are available. This
property is typically used to limit the impact of the virtual machine on other
running virtual machines. If the property is set to -1, the configured virtual
memory size or the configured number of virtual cores limits the resource
allocation.Note: Although the number of virtual CPU cores limits the compute resource allocated, the virtual bandwidth allocated also depends on the speed of the physical CPU cores assigned as backing.
- level – An enum type with four potential values: high, normal, low, and custom. If you specify the value custom, you must also specify the shares property. If you specify any other value for level, the shares property is ignored.
- shares – In a situation of resource contention, the shares value is compared against the shares values of other virtual machines, and resources are allocated first to the virtual machine with the highest shares value.
The most direct way to specify resource priority is to set the shares values manually. This is most useful in environments where all virtual machines use custom shares values. In a mixed environment, the configuration settings do not compare directly, which can lead to unexpected results.
A more sophisticated way of specifying priority is to specify high, normal, or low for the level property. These settings cause the host to calculate the shares of a virtual machine in a way that factors in the configured memory size or the configured virtual CPU cores of the virtual machine. The result gives more priority shares to virtual machines with larger configurations.
For a detailed examination of resource pools and how they affect priority shares calculations, see Resource Management. The Resource Management Guide includes a detailed discussion of resource allocation in the vSphere environment.