PAD12
q
Picture
Breno Leitao
Advisory Software Engineer brenohl@br.ibm.com
© 2014 IBM Corporation
Introduction
Learn best practices on Kernel-based Virtual Machine.
Agenda:
Command line management
Storage
Network
CPU
Snapshots
General tips
© 2014 IBM Corporation ● Systems Technical University ● 28 – 30 October | Atibaia, Sao Paulo, Brazil
Terminology
© 2014 IBM Corporation ● Systems Technical University ● 28 – 30 October | Atibaia, Sao Paulo, Brazil
General Understanding
IBM PowerKVM is the KVM ported to IBM POWER processors.
© 2014 IBM Corporation ● Systems Technical University ● 28 – 30 October | Atibaia, Sao Paulo, Brazil
4
General Understanding
IBM PowerKVM management screen (GUI)
© 2014 IBM Corporation ● Systems Technical University ● 28 – 30 October | Atibaia, Sao Paulo, Brazil
5
Command line
Using command line provides you more control over you environment.
Images and other files are at /var/lib/libvirt
Network
Storage
Every configuration is an XML file
# virsh edit/dump-xml
© 2014 IBM Corporation ● Systems Technical University ● 28 – 30 October | Atibaia, Sao Paulo, Brazil
6
Command line: How to handle the VM more properly
Examples:
• Create amount of disk
– # qemu-img create -f qcow2 /var/lib/libvirt/images/ubuntu.qcow2
50G
– # virsh vol-create-as disks ubuntu 50G --format qcow2
• Virt-install:
– # virt-install --name=ubuntu1410 --cdrom=/root/utopic-serverppc64el.iso --memory=4096 --disk 10G --network=default
• Keep the machine up after a reboot
– #virsh autostart <VM name>
• Edit VM configuration:
– # virsh edit <VM name>
• Log into the console:
– # virsh console <VM name>
© 2014 IBM Corporation ● Systems Technical University ● 28 – 30 October | Atibaia, Sao Paulo, Brazil
7
Storage (Disk)
Use Logical disk for performance.
Use File system images for storage virtualization.
Many other types of pool:
NFS
SCSI
ISCSI
ZFS VM File system
VM Image
Hypervisor File system
Hypervisor Disk
VM FS
VM Disk
Hypervisor Disk
© 2014 IBM Corporation ● Systems Technical University ● 28 – 30 October | Atibaia, Sao Paulo, Brazil
8
Storage (Images)
Qcow2
– Copy on Write file format.
– Supports backing file:
• Have a base file and all changes on the base files are written in a different file.
– Usually small than raw format
– Create snapshot
Raw
– File system as a file
– Can be mounted as a file system
– The image file will be as big as the VM file system
You can convert from one type to another using qemu-image too.
$ virsh vol-create-as disks qcow_image 10G --format qcow2
Vol qcow_image created
$ virsh vol-create-as disks raw 10G --format raw
Vol raw created
$ ls /tmp/pool/qcow_image -lah
-rw------- 1 brenohl brenohl 193K Oct 28 11:13
/tmp/pool/qcow_image
QCOW2
$ ls /tmp/pool/raw -lah
-rw------- 1 brenohl brenohl 10G Oct 28 11:15 /tmp/pool/raw
© 2014 IBM Corporation ● Systems Technical University ● 28 – 30 October | Atibaia, Sao Paulo, Brazil
RAW
Network Storage
© 2014 IBM Corporation ● Systems Technical University ● 28 – 30 October | Atibaia, Sao Paulo, Brazil
Networking
Interfaces
All the host network interfaces are managed by virsh.
Easily create or assign NIC to a guest.
Create and handle bridges.
Network transactions and network commits.
Net
Used to create bridges automatically
Many type of network pools.
Isolated
Forward
NAT
Bridged
Route
Passthrough hostdev
<network>
<name>nat_pool</name>
<uuid>11f69826-6dec-47fc-ae46-efa0f9b714f4</uuid>
<forward mode='nat'/>
<bridge name='virbr1' stp='on' delay='0'/>
<mac address='52:52:00:d1:19:b5'/>
<ip address='192.168.22.1' netmask='255.255.255.0'>
<dhcp>
<range start='192.168.22.2' end='192.168.22.254'/>
</dhcp>
</ip>
</network>
© 2014 IBM Corporation ● Systems Technical University ● 28 – 30 October | Atibaia, Sao Paulo, Brazil
Networking
Bridging is usually the best way to configure your network if you are not able to passthrough.
# virsh net-info default
Name default
UUID 11f69826-6de
Active: yes
Persistent: yes
Autostart: yes
Bridge: virbr1
© 2014 IBM Corporation ● Systems Technical University ● 28 – 30 October | Atibaia, Sao Paulo, Brazil
Snapshots
Always use snapshot when you reach a point you want to 'save'. You run the snapshot command live:
No Downtime at saving or backing up.
Very fast and easy to be done
Demo how to create a snapshot and how to recover it.
$ virsh help snapshot
Snapshot (help keyword 'snapshot'): snapshot-create Create a snapshot from XML snapshot-create-as Create a snapshot from a set of args snapshot-current Get or set the current snapshot snapshot-delete Delete a domain snapshot snapshot-dumpxml Dump XML for a domain snapshot snapshotedit edit XML for a snapshot snapshotinfo snapshotlist snapshot information
List snapshots for a domain snapshot-parent Get the name of the parent of a snapshot snapshot-revert Revert a domain to a snapshot
$ virsh help snapshot-list
© 2014 IBM Corporation ● Systems Technical University ● 28 – 30 October | Atibaia, Sao Paulo, Brazil
Creating snapshot
© 2014 IBM Corporation ● Systems Technical University ● 28 – 30 October | Atibaia, Sao Paulo, Brazil
Reverting snapshot
© 2014 IBM Corporation ● Systems Technical University ● 28 – 30 October | Atibaia, Sao Paulo, Brazil
VirtIO
The VirtIO API is a high performance API that para-virtualized devices use to gain speed and efficiency.
Virtio-scsi
Virtio-blk
Virtio-console
Virtio_net
The guest OS needs to have the drivers installed:
At the moment, only Ubuntu versions have them.
© 2014 IBM Corporation ● Systems Technical University ● 28 – 30 October | Atibaia, Sao Paulo, Brazil
16
CPU overcommitment
Guest usually does not run on 100% of the CPU all the time
CPUs run in burst mode
CPU overcommitment is usually a good thing to do.
The overcommitment rate depends on the workload, but usually 20-50% of overcommitment is a good number
Best practice: Target system use at 80% or lower
© 2014 IBM Corporation ● Systems Technical University ● 28 – 30 October | Atibaia, Sao Paulo, Brazil
17
CPU Micro Threading
Versus
© 2014 IBM Corporation ● Systems Technical University ● 28 – 30 October | Atibaia, Sao Paulo, Brazil
18
Enabling CPU Micro Threading
1) Ensure that all guests are not running.
2) Set the number of subcores to 1:
# ppc64_cpu --subcores-per-core=1
3) Enable SMT on the host:
# ppc64_cpu --smt=on
4) Set the number of subcores to 4:
# ppc64_cpu --subcores-per-core=4
5) Turn the SMT off on the host:
# ppc64_smt --smt=off
© 2014 IBM Corporation ● Systems Technical University ● 28 – 30 October | Atibaia, Sao Paulo, Brazil
19
CPU Pinning
CPU pinning allows a guest virtual machine to be pinned to a given CPU or set of
CPUs. It means that the hypervisor will schedule only vCPUs in those CPUs that the guest is pinned to. By default, the guest can be scheduled on any CPU.
<vcpu placement=’static’ cpuset=’0,8’>8</vcpu>
CPU Sharing
CPU sharing defines the amount of CPU time a VM will have
Usually a VM has sharing time of 1024. If your VM is configured to have 2048, it is going to have twice the CPU time compared to a default VM in an overcommitment scenario.
<cputune>
<shares>256</shares>
</cputune>
© 2014 IBM Corporation ● Systems Technical University ● 28 – 30 October | Atibaia, Sao Paulo, Brazil
Kernel Same page Merge (KSM)
KSM is a kernel feature in KVM that shares memory pages between various processes, over-committing the memory.
How to enable:
# systemctl start ksmtuned
Monitoring:
# cat /sys/kernel/mm/ksm/page_shared
# cat /sys/kernel/mm/ksm/page_sharing
# cat /sys/kernel/mm/ksm/sleep_milisecs
# cat /sys/kernel/mm/ksm/full_scans
If you configure KSM to act too aggressively, KSM might use an entire processor thread.
© 2014 IBM Corporation ● Systems Technical University ● 28 – 30 October | Atibaia, Sao Paulo, Brazil
Huge Pages
The bigger pages (huge page) you have in the hypervisor, the less page your system needs, turning the memory management easier when looking for contiguous memory.
Configuration:
<memoryBacking>
<hugepages/>
</memoryBacking>
Memory balloning
Memory ballooning is a technique that allows the guest memory to be increased or decreased cooperatively, depending on the amount of free memory available on the guests and hypervisor.
Configuration
<memballoon model=’ virtio’>
© 2014 IBM Corporation ● Systems Technical University ● 28 – 30 October | Atibaia, Sao Paulo, Brazil
Memory ballooning demo
© 2014 IBM Corporation ● Systems Technical University ● 28 – 30 October | Atibaia, Sao Paulo, Brazil
23
Network Time Protocol (NTP)
Set the same time on guest and hypervisor.
© 2014 IBM Corporation ● Systems Technical University ● 28 – 30 October | Atibaia, Sao Paulo, Brazil
24
Disk Hot Plug
Attaching disks to the virtual machine
On the guest, you need to re scan the SCSI bus, usually calling rescan-scsi bus command
© 2014 IBM Corporation ● Systems Technical University ● 28 – 30 October | Atibaia, Sao Paulo, Brazil
25
USB Passthrough
Assign a USB device to the guest
XML configuration on VM (USB) XML configuration on VM (PCI)
© 2014 IBM Corporation ● Systems Technical University ● 28 – 30 October | Atibaia, Sao Paulo, Brazil
26
IPMI tips
Uses an updated IPMI package on the client
IPMI is based on UDP, so, avoid networks that lose packets.
© 2014 IBM Corporation ● Systems Technical University ● 28 – 30 October | Atibaia, Sao Paulo, Brazil
27
Thank you!
© 2014 IBM Corporation ● Systems Technical University ● 28 – 30 October | Atibaia, Sao Paulo, Brazil
KVM vs PowerVM
© 2014 IBM Corporation ● Systems Technical University ● 28 – 30 October | Atibaia, Sao Paulo, Brazil