VMware

VMware ESX Server 2.0

Features | Documentation | Knowledge Base | Discussion Forums

previous Prev   Contents   Last   Next next

Managing Virtual Machine CPU Resources

Managing Virtual Machine CPU Resources

You can manage CPU resources from the VMware Management Interface or from the service console.

Managing CPU Resources from the Management Interface

Managing CPU Resources from the Management Interface

You may also view and change settings from the virtual machine details pages in the VMware Management Interface.

  1. On the server's Status Monitor page, click the name of an individual virtual machine. The details page for that virtual machine appears.
  2. Click the CPU tab.

  3. Click Edit. The CPU Resource Settings page appears.

  4. Enter the desired settings, then click OK.

You must log in as root in order to change resource management settings using either the management interface or procfs.

Managing CPU Resources from the Service Console

Managing CPU Resources from the Service Console

You can also manage CPU resources by editing the virtual machine configuration (.vmx) file or using procfs.

Editing the Virtual Machine Configuration File

Editing the Virtual Machine Configuration File

The following configuration options enable you to manage CPU resources.

sched.cpu.shares = <n>
This configuration file option specifies the initial share allocation for a virtual machine to <n> shares. The valid range of numerical values for <n> is 1 to 100000. You may also use the special values low, normal and high. These values are automatically converted into numbers, through the configuration options CpuSharesPerVcpuLow, CpuSharesPerVcpuNormal and CpuSharesPerVcpuHigh, described in the next section, Using procfs.

If the number of CPU shares is not specified, the default allocation is normal, that by default, is set to 1000 shares per virtual CPU. The default allocation for a uniprocessor virtual machine is 1000 shares, or 2000 shares for a dual-virtual CPU (SMP) virtual machine.

sched.cpu.min = <min>
This configuration file option specifies a minimum CPU reservation <min>, as a percentage, for a virtual machine. The valid range of values for <minPercent> is 0 (the default minimum) to the number representing the total physical CPU resources. Note that the minimum may be greater than 100 for SMP virtual machines that are guaranteed more than one full physical CPU.

Note: If ESX Server is unable to guarantee a virtual machine's specified minimum percentage(s), you cannot power on that virtual machine. For example, if you have two uniprocessor (UP) virtual machines, each has a CPU minimum of 80%, and both are bound to the same processor, then ESX Server does not allow you to power on both virtual machines. The total CPU percentage is 160%, greater than a single processor.

sched.cpu.max = <max>
This configuration file option specifies a maximum CPU percentage <maxPercent> for a virtual machine. The valid range of values for <maxPercent> is 0 to the number representing the total physical CPU resources. Note that the maximum may be greater than 100 for SMP virtual machines that are guaranteed more than one full physical CPU. The default maximum is 100 times the number of virtual CPUs in the virtual machine; 100 percent for uniprocessor virtual machines and 200 percent for dual-virtual CPU virtual machines.

Note: A virtual machine will never use more CPU time than the specified maximum percentage.

sched.cpu.affinity = <set>
This configuration file option specifies the initial processor affinity set for a virtual machine. If <set> is all or default, then the affinity set contains all available processors. The specified set may also be a comma-separated list of CPU numbers such as 0,2,3.

Note: For SMP virtual machines, the affinity set applies to all virtual CPUs on the virtual machine.

Using procfs

Using procfs

You can also use procfs to manage CPU resources. Use the following command:

echo <new_value> > <proc_filename>

in the service console, where <new_value> is the value you wish to set and <proc_filename> is the full path name of the configuration option's proc entry. See Examples for additional information.

Note: For SMP virtual machines, you can use the <id> of any of the virtual CPUs to view or change configuration options for that virtual machine.

/proc/vmware/vm/<id>/cpu/min
Reading from this file reports the minimum CPU percentage allocated to the virtual machine identified by <id>.

Specifying a percentage <minPercent>, to this file changes the minimum percentage allocated to the virtual machine identified by <id> to <minPercent>. The valid range of values for <minPercent> is 0 to 100 multiplied by the number of virtual CPUs; that is, 100 percent for uniprocessor virtual machines, and 200 percent for dual-virtual CPU virtual machines.

Note: If there is not enough unreserved CPU time available in the system to satisfy a demand for an increase in min, then the reservation will not be changed.

/proc/vmware/vm/<id>/cpu/max
Reading from this file reports the maximum CPU percentage allocated to the virtual machine identified by <id>.

Specifying a percentage <maxPercent>, to this file changes the maximum percentage allocated to the virtual machine identified by <id> to <maxPercent>. The valid range of values for <maxPercent> is 0 to 100 multiplied by the number of virtual CPUs, or 100 percent for uniprocessor virtual machines, and 200 percent for dual-virtual CPU virtual machines.

/proc/vmware/vm/<id>/cpu/shares
Reading from this file reports the number of shares allocated to the virtual machine identified by <id>.

Writing a number <n> to this file changes the number of shares allocated to the virtual machine identified by <id> to <n>. The valid range of numerical values for <n> is 1 to 100000. Or, you may use the special values low, normal and high. These values are automatically converted into numbers, through the configuration options CpuSharesPerVcpuLow, CpuSharesPerVcpuNormal and CpuSharesPerVcpuHigh, described in this section.

/proc/vmware/vm/<id>/cpu/affinity
Reading from this file reports the number of each CPU in the current affinity set for the virtual machine identified by <id>.

Writing a comma-separated list of CPU numbers to this file, such as 0,2,3, changes the affinity set for the virtual machine identified by <id>. Writing all or default to this file changes the affinity set to contain all available processors.

For SMP virtual machines, writing to this file changes the affinity of all virtual CPUs in the virtual machine to the specified affinity set.

/proc/vmware/vm/<vcpuid>/cpu/status
Reading from this file reports current status information for the virtual CPU identified by <vcpuid>, including the specified shares and affinity parameters, as well as the virtual machine name, state (running, ready, waiting), current CPU assignment and cumulative CPU usage in seconds.

/proc/vmware/sched/cpu
Reading from this file reports the status information for all virtual machines in the entire system. Each virtual CPU is displayed on its own line, with information including uptime, time used, and resource management parameters.

/proc/vmware/config/CpuSharesPerVcpuLow
This option specifies the a numerical value for the low value. By default, this number is 500. Since this value is expressed in shares per virtual CPU, the allocation for a uniprocessor virtual machine is 500 shares, or 1000 shares for a dual-virtual CPU (SMP) virtual machine.

/proc/vmware/config/CpuSharesPerVcpuNormal
This option specifies the a numerical value for the normal value. By default, this number is 1000. For a uniprocessor virtual machine, the default allocation is 1000 shares, or 2000 shares for a dual-virtual CPU (SMP) virtual machine.

/proc/vmware/config/CpuSharesPerVcpuHigh
This option specifies the a numerical value for the high value. By default, this number is 2000. For a uniprocessor virtual machine, the default allocation is 2000 shares, or 4000 shares for a dual-virtual CPU (SMP) virtual machine.

Examples

Examples

Suppose that we are interested in the CPU allocation for the virtual machine with ID 103. To query the number of shares allocated to virtual machine 103, simply read the file.

cat /proc/vmware/vm/103/cpu/shares

The number of shares is displayed.

1000

This indicates that virtual machine 103 is currently allocated 1,000 shares. To change the number of shares allocated to virtual machine 103, simply write to the file. Note that you need root privileges in order to change share allocations.

echo 2000 > /proc/vmware/vm/103/cpu/shares

You can also write to the file by specifying low, normal, or high. ESX Server writes the numerical value for these special values.

echo high > /proc/vmware/vm/103/cpu/shares

The change can be confirmed by reading the file again.

cat /proc/vmware/vm/103/cpu/shares

The number of shares is displayed.

2000

To query the affinity set for virtual machine 103, simply read the file:

cat /proc/vmware/vm/103/cpu/affinity

The identifying numbers of the processors in the affinity set are displayed.

0,1

This indicates that virtual machine 103 is allowed to run on CPUs 0 and 1. To restrict virtual machine 103 to run only on CPU 1, simply write to the file. Note that you need root privileges in order to change affinity sets.

echo 1 > /proc/vmware/vm/103/cpu/affinity

The change can be confirmed by reading the file again.

Note: The affinity set must contain at least as many CPUs as virtual CPUs; that is, 1 CPU for a uniprocessor (UP) virtual machine, and 2 CPU for a SMP virtual machine.

previous Prev   Contents   Last   Next next