Oracle VM: How to Implement Hard Partitioning / CPU Pinning on OVM

Probably one of the main reason you might choose to use Oracle VM when compared to other VMs is because of Oracle licensing, which allows you to restrict physical CPUs or cores that can be assigned to a VM for Oracle database licensing purpose.

This tutorial explains how to assign only one CPU to an Oracle virtual machine.

In the following example, the server has 2 physical CPUs with 4 cores each. However, I’ll assign only 1 CPU (4 cores) to be used by the two virtual machine that are running on this Oracle VM server.

1. View Current CPU Assignment on the OVM Server.

Before we restrict 1 physical CPU, let us view the CPU details on the OVM server.

Execute the following command to view the CPU information on the OVM server. As shown below, you can see that this server has 2 CPU (as indicated by nr_nodes), 4 cores in each CPU, with hyper threading enabled. So, this gives total of 16 vCPU.

i.e Physical CPU count x number of cores x hyper threading. i.e 2 x 4 x 2 = 16 vCPU.

# xm info
host                   : ovm1
release                : 2.6.39-300.29.1.el5uek
version                : #1 SMP Thu Feb 14 03:32:54 PST 2013
machine                : x86_64
nr_cpus                : 16
nr_nodes               : 2
cores_per_socket       : 4
threads_per_core       : 2
cpu_mhz                : 2394
..

You can also see the individual details of the cVPU using xenpm command as shown below.

# xenpm get-cpu-topology
CPU     core    socket  node
CPU0     0       1       0
CPU1     0       1       0
CPU2     1       1       0
CPU3     1       1       0
CPU4     9       1       0
CPU5     9       1       0
CPU6     10      1       0
CPU7     10      1       0
CPU8     0       0       1
CPU9     0       0       1
CPU10    1       0       1
CPU11    1       0       1
CPU12    9       0       1
CPU13    9       0       1
CPU14    10      0       1
CPU15    10      0       1

In the following example, I have two VMs running on this OVM server. One of them has the CPU affinity of 0 through 7, and other one has 8 through 15.

# xm vcpu-list
Name      ID  VCPU   CPU State   Time(s) CPU Affinity
11111     7     0     5   -b-      54.5 0-7
11111     7     1     7   -b-      52.8 0-7
11111     7     2     0   -b-      47.6 0-7
11111     7     3     0   -b-      44.3 0-7
11111     7     4     -   --p       0.0 0-7
11111     7     5     -   --p       0.0 0-7
11111     7     6     -   --p       0.0 0-7
11111     7     7     -   --p       0.0 0-7
22222     9     0    10   -b-       6.2 8-15
22222     9     1     9   -b-       3.2 8-15
22222     9     2    15   -b-       1.3 8-15
22222     9     3    12   -b-       1.8 8-15
22222     9     4     -   --p       0.0 8-15
22222     9     5     -   --p       0.0 8-15
22222     9     6     -   --p       0.0 8-15
22222     9     7     -   --p       0.0 8-15
Domain-0  0     0     8   -b-     851.1 any cpu
Domain-0  0     1    11   -b-    1305.8 any cpu
...

So, we have to change the CPU Affinity for the 2nd virutual machine (i.e 22222 ) from 8-15 to 0-7. This way, both the virtual machines uses only vCPUs 0-7, which belongs to one physical CPU.

2. Hard Partition the 1st VM

Even though the first virtual machine has the CPU affinity of 0-7, it was assigned by the Oracle VM dynamically. Since we are restricting both the VMs to 0-7, we have to hard partition both the VMs to vCPU 0-7.

Before CPU pinning (hard partitioning) for virutal machine 1: As you see below, we don’t see an entry for “cpus” in the vm.cfg file.

# grep -i cpus /OVS/Repositories/12345/VirtualMachines/11111/vm.cfg
maxvcpus = 8
vcpus = 4

Do the following to hard partition virtual machine 1. Execute this command on the OVM Manager.

# cd /u01/app/oracle/ovm-manager-3/ovm_utils
# ./ovm_vmcontrol -u admin -p YourPassword -h ovm-manager -v my-first-vm -c vcpuset -s 0-7
Oracle VM VM Control utility 0.6.3.
Connected.
Command : vcpuset
Pinning virtual CPUs
Pinning of virtual CPUs to physical threads  '0-7' 'my-first-vm' completed.

In the above:

  • -u admin – Is the admin username for OVM manager.
  • -p YourPassword – Password for admin username. use the same uid/pwd that you use to login to OVM Manager from the GUI.
  • -h ovm-manager – Hostname of your OVM manager
  • -v my-first-vm – In this example, I gave the virtual machine name for which I’m doing the hard partition.
  • -c vcpuset – Indicates that I want to perform hard partitioning
  • -s 0-7 – Indicates that cVPU values I want to assign for this hard partitioning. Since I want to assign only one physical CPU to my-first-vm, I’ll give 0-7 here (remember that in my example, I have 4 cores in a CPU with hyper threading enabled)

After CPU pinning (hard partitioning) for virtual machine 1: As you see below, we now see the entry for “cpus” here.

# grep -i cpus /OVS/Repositories/12345/VirtualMachines/11111/vm.cfg
cpus = '0-7'
maxvcpus = 8
vcpus = 4

3. Hard Partition the 2nd VM

The second virtual machine currently has the CPU affinity of 8-15. Since we are restricting both the VMs to 0-7, we have to hard partition both the VMs to vCPU 0-7.

Before CPU pinning (hard partitioning) for virutal machine 2: As you see below, we don’t see an entry for “cpus” here.

# grep -i cpus /OVS/Repositories/12345/VirtualMachines/22222/vm.cfg
maxvcpus = 8
vcpus = 4

Do the following to hard partition virtual machine 2. Execute this command on the OVM Manager.

# cd /u01/app/oracle/ovm-manager-3/ovm_utils
# ./ovm_vmcontrol -u admin -p YourPassword -h ovm-manager -v my-second-vm -c vcpuset -s 0-7
Oracle VM VM Control utility 0.6.3.
Connected.
Command : vcpuset
Pinning virtual CPUs
Pinning of virtual CPUs to physical threads  '0-7' 'my-second-vm' completed.

After CPU pinning (hard partitioning) for virtual machine 2: As you see below, we now see the entry for “cpus” here.

# grep -i cpus /OVS/Repositories/12345/VirtualMachines/22222/vm.cfg
cpus = '0-7'
maxvcpus = 8
vcpus = 4

4. Verify the CPU Affinity Again

Now, if you execute the vcpu-list, you’ll notice that both the VMs will have 0 through 7 in the “CPU Affinity” column. This indicates that it is using vCPU 0 through 7, which belongs to a single physical CPU.

# xm vcpu-list
Name     ID  VCPU   CPU State   Time(s) CPU Affinity
11111     7     0     1   -b-      54.6 0-7
11111     7     1     7   -b-      52.8 0-7
11111     7     2     1   -b-      47.6 0-7
11111     7     3     0   -b-      44.4 0-7
11111     7     4     -   --p       0.0 0-7
11111     7     5     -   --p       0.0 0-7
11111     7     6     -   --p       0.0 0-7
11111     7     7     -   --p       0.0 0-7
22222     9     0     3   -b-       6.2 0-7
22222     9     1     0   -b-       3.2 0-7
22222     9     2     0   -b-       1.3 0-7
22222     9     3     1   -b-       1.8 0-7
22222     9     4     -   --p       0.0 0-7
22222     9     5     -   --p       0.0 0-7
22222     9     6     -   --p       0.0 0-7
22222     9     7     -   --p       0.0 0-7
Domain-0  0     0     9   -b-     851.5 any cpu
Domain-0  0     1    14   -b-    1306.2 any cpu
...

Comments on this entry are closed.