Modifying the number of virtual CPUs

Modify the number of virtual CPUs or the maximum number of available virtual CPUs for a defined virtual server.

About this task

The number of virtual CPUs that you can assign to a virtual server is limited by the maximum number of available virtual CPUs. Both numbers are configured with the vcpu element and can be modified during operation.

To display the number of virtual CPUs, use the virsh vcpucount command. For example, issue:
# virsh vcpucount vserv1
maximum      config         5
maximum      live           5
current      config         3
current      live           3
where
maximum config
Specifies the maximum number of virtual CPUs that can be made available for the virtual server after the next restart.
maximum live
Specifies the maximum number of virtual CPUs that can be made available for the running or paused virtual server.
current config
Specifies the actual number of virtual CPUs which will be available for the virtual server with the next restart.
current live
Specifies the actual number of virtual CPUs which are available for the running or paused virtual server.
You can modify the following values:
maximum config
The maximum value can be modified only in combination with a virtual server restart.

The maximum number of available virtual CPUs is not limited. If no value is specified, the maximum number of available virtual CPUs is 1.

current config
The current value can be modified in combination with a virtual server restart. It is limited by the maximum number of available virtual CPUs. Consider to set the surplus virtual CPUs offline until the next restart.
current live
You can increase the actual number of virtual CPUs for a running or paused virtual server. This number is limited by the maximum number of available CPUs.

Additional virtual CPUs are provided in the halted state. Depending on the guest setup, the virtual server user has to bring them online.

Procedure

Use the virsh setvcpus command to modify the number of virtual CPUs or the maximum number of available virtual CPUs for a defined virtual server.

  • Modify maximum config:

    To modify the maximum number of available virtual CPUs with the next virtual server restart, use the --maximum and the --config options:

    # virsh setvcpus <VS> <max-number-of-CPUs> --maximum --config

    This modification takes effect after the termination of the virtual server and a subsequent restart. Please note that a virtual server reboot does not modify the libvirt-internal configuration.

  • Modify current config:
    To increase or reduce the number of virtual CPUs with the next virtual server restart, use the --config option:
    # virsh setvcpus <VS> <number-of-CPUs> --config

    The virtual CPUs are not removed until the next virtual server reboot. Until then, the virtual server user might set the corresponding number of virtual CPUs offline.

  • Modify current live:

    To increase the number of virtual CPUs of a running or paused virtual server, use the --live option:

    # virsh setvcpus <VS> <number-of-CPUs> --live

    The virtual server user has to bring the additional virtual CPUs online.

    <VS>
    Is the name of the virtual server as specified in its domain configuration-XML file.
    <max-number-of-CPUs>
    Is the maximum number of available virtual CPUs for the virtual server after the next restart.
    <number-of-CPUs>
    Is the number of virtual CPUs assigned to the virtual server.

Example

  • Change the maximum number of available virtual CPUs with the next virtual server restart.
    # virsh vcpucount vserv1
    maximum      config         5
    maximum      live           5
    current      config         4
    current      live           4
    
    # virsh setvcpus vserv1 6 --maximum --config
    
    # virsh vcpucount vserv1
    maximum      config         6
    maximum      live           5
    current      config         4
    current      live           4
  • You cannot remove virtual CPUs from a running virtual server.
    1. This example removes two virtual CPUs from the virtual server vserv1 with the next virtual server restart:
      # virsh vcpucount vserv1
      maximum      config         5
      maximum      live           5
      current      config         4
      current      live           4
      
      # virsh setvcpus vserv1 2 --config
      
      # virsh vcpucount vserv1
      maximum      config         5
      maximum      live           5
      current      config         2
      current      live           4
    2. To set the CPUs offline until the next virtual server restart, the virtual server user might set the virtual CPUs offline:
      [root@guest:] # chcpu -d 2
      CPU 2 disabled
      [root@guest:] # chcpu -d 3
      CPU 3 disabled
  • Add virtual CPUs to a running virtual server.
    1. This example adds a virtual CPU to the virtual server vserv1:
      # virsh vcpucount vserv1
      maximum      config         5
      maximum      live           5
      current      config         3
      current      live           3
      
      # virsh setvcpus vserv1 4 --live
      
      # virsh vcpucount vserv1
      maximum      config         5
      maximum      live           5
      current      config         3
      current      live           4
    2. To set the additional CPU online, the virtual server user might enter:
      [root@guest:] # chcpu -e 3
      CPU 3 enabled