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.

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.
To specify preferences for resource allocation in case of contention, use the shares property of ResourceAllocationInfo. The shares property is a nested data object of type SharesInfo, which specifies a relative priority for resolving resource contention between virtual machines. The SharesInfo data object has two properties, level and shares:
  • 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.

Note: Both the custom shares values and the calculated shares values prioritize virtual machines only among their siblings running in the same resource pool. For a system of virtual machines running only in the default root resource pool, determining priority is fairly simple. For data centers with nested resource pools, a virtual machine's priority in the larger context of all running virtual machines depends also on the priority of its parent resource pool.

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.