Boot a VM with CPU and memory pinning

Boot a VM with CPU and memory pinning

This example demonstrates booting VM with CPU and memory pinning.

To boot VM with CPU and memory pining:

  1. Create a new flavor with specific division of vCPUs and RAM between the NUMA nodes:

    . openrc admin admin
    nova flavor-create m1.numa_2 9992 1024 5 4
    
  2. Add numa_nodes and other specific options to the flavor:

    nova flavor-key m1.numa_2 set hw:numa_nodes=2 hw:numa_cpus.0=0,2 \
         hw:numa_cpus.1=1,3 hw:numa_mem.0=324 hw:numa_mem.1=700
    nova flavor-show m1.numa_2 | grep extra
    

    Example of system response:

    | extra_specs  | {"hw:numa_cpus.0": "0,2", "hw:numa_cpus.1": "1,3", \
    "hw:numa_nodes": "2", "hw:numa_mem.1": "700", "hw:numa_mem.0": "324"} |
    
  3. Create a new image or use an existing image.

    Note

    You need an Ubuntu image or the default Cirros image.

    To create a new Ubuntu image:

    glance --os-image-api-version 1 image-create --name ubuntu \
           --location https://cloud-images.ubuntu.com/trusty/current/\
           trusty-server-cloudimg-amd64-disk1.img \
           --disk-format qcow2 --container-format bare
    
  4. To enable SSH connections:

    1. Add a new rule to the security group:

      nova secgroup-add-rule default tcp 22 22 0.0.0.0/0
      
    2. Create a new SSH key pair or use the existing key pair. To create a new ssh key pair, run:

      ssh-keygen
      
    3. Add the key pair to Nova:

      nova keypair-add --pub_key ~/.ssh/id_rsa.pub my_kp
      
  5. Boot a new instance using the created flavor:

    nova boot --flavor m1.numa_2 --image ubuntu --key-name my_kp inst2
    
  6. Verify if free memory has been changed after booting the VM:

    numactl -H
    

    Example of system response:

    available: 2 nodes (0-1)
    node 0 cpus: 0 1
    node 0 size: 3856 MB
    node 0 free: 293 MB           # was 718 MB
    node 1 cpus: 2 3
    node 1 size: 3937 MB
    node 1 free: 81 MB            # was 337 MB
    node distances:
    node   0   1
      0:  10  20
      1:  20  10
    
  7. Retrieve the instance’s IP:

    nova show inst2 | awk '/network/ {print $5}'
    

    Example of system response:

    10.0.0.3
    
  8. Connect to the VM using SSH:

    ssh ubuntu@10.0.0.3
    
  9. Install numactl:

    sudo apt-get install numactl
    
  10. Verify the NUMA topology on the VM:

    numactl -H
    

    Example of system response:

    available: 2 nodes (0-1)
    node 0 cpus: 0 2
    node 0 size: 303 MB
    node 0 free: 92 MB
    node 1 cpus: 1 3
    node 1 size: 689 MB
    node 1 free: 629 MB
    node distances:
    node   0   1
      0:  10  20
      1:  20  10
    

    You can see that the NUMA topology has two NUMA nodes. Total RAM size is about 1GB:

    • node-0 CPUs are 0 and 2
    • node-1 CPUs are 1 and 3, node-1 RAM is about 324 MB
    • node-2 RAM is about 700 as specified in the m1.numa_2 flavor