introduction to virtualization (part 5)

18
Review and Intro to KVM

Upload: kiru-sengal

Post on 15-Apr-2017

88 views

Category:

Engineering


1 download

TRANSCRIPT

Page 1: Introduction to virtualization (Part 5)

Review and Intro to KVM

Page 2: Introduction to virtualization (Part 5)

Remember:

Operating System Kernel 1

System Call Interface

Operating System Kernel K

System Call Interface

Hardware (CPU, MEM, IO)

… …

Type 1 Hypervisor Operating System Kernel

Process in Hypervisor Kernel Process in Hypervisor Kernel

Page 3: Introduction to virtualization (Part 5)

Remember

• These need to be virtualized:– Memory

– CPU

– IO devices

Page 4: Introduction to virtualization (Part 5)

Operating Systems Manage Hardware

• Which part of operating systems manage these:– Memory – CPU

– IO devices

Highly coupled with OS kernel proper

Somewhat independent from the main part of O.S. kernel, whereby the drivers are more like “plugins” that could be swapped in or out

Page 5: Introduction to virtualization (Part 5)

Component-Wise Virtualization

• Therefore, it is clear that the “kernel proper” can be virtualized independently from the IO device drivers.

• Hereon, call these entities (kernel proper, or IO device drivers) “virtualizable components”

• So, how do we virtualize these components?

Page 6: Introduction to virtualization (Part 5)

Full vs. Para Virtualization

• Full virtualization:– When the component is NOT specially made for

virtualization, but rather is software equal to what that component would look like if it were part of a regular host

• Para virtualization:– When the component IS specially made for

virtualization, that is, it knows about the VM layer

Page 7: Introduction to virtualization (Part 5)

Example:

• Our main Linux host deployment uses a combination of full and paravirtualization:– The guest kernel proper is fully virtualization (via

QEMU/KVM)– The IO drivers are paravirtualized using special

“virtio” device drivers

Page 8: Introduction to virtualization (Part 5)

Comparison• Full virtualization:– Advantages:

• Need no modification of component to run within VM infrastructure

– Disadvantages:• Was historically slower than para (and this is still the case for

IO components)

• Para virtualization– Advantages:

• Coupling between Virtualization layer and component can provide perf benefits (e.g. virtio for IO devices!)

– Disadvantage:• This coupling requires special code in component and

hypervisor

Page 9: Introduction to virtualization (Part 5)

Ways of Fully Virtualizing Kernel Proper

• Binary Translation (historically done this way)– Example: QEMU hypervisor

• Hardware assisted full virtualization– Use special CPU instruction set and features to

achieve extremely high performance!• QEMU+KVM

• How do these really work? Another day.

Page 10: Introduction to virtualization (Part 5)

Paravirtualized Kernel Proper

• The guest kernel is actually modified!• It makes “hypercalls” into the hypervisor– These are somewhat similar to “system calls”

between a process and a kernel (but at the guest kernel – host kernel interface)

• E.g., Xen

Page 11: Introduction to virtualization (Part 5)

Paravirtualized (Two levels of calls)

Hypervisor

Guest Kernel 1 Guest Kernel 2

System calls

Process 1 Process 2 Process 1 Process 2

Hypercalls

Page 12: Introduction to virtualization (Part 5)

Intro KVM

• Kernel Virtual Machine• Exists as 2 kernel loadable modules (i.e. “.ko” files) ,

where one is generic, and the other one is specific to amd vs. intel

• Is not a Hypervisor by itself, but instead “accelerates” QEMU by provide it assistance

• Requires:– Special CPU features– BIOS enabling virt flags

Page 13: Introduction to virtualization (Part 5)

QEMU-KVM Stack

Page 14: Introduction to virtualization (Part 5)

What is LIBVIRT?

• Often confused as part of KVM• But rather, it is a management layer and

simplification layer built on top of a concrete virtualization technology.

• There are drivers for different virtualization technologies, e.g. KVM, LXC, etc. etc.

• A daemon “libvirtd” runs in userspace alongside, for example, qemu processes (the VMs) to help manage our Libvirt-Qemu-KVM stack

Page 15: Introduction to virtualization (Part 5)

Why do we use Libvirt with our QEMU-KVM stack?

• Starting a VM (as a qemu or qemu-kvm process) using the actual qemu is very hard

• Many many command line flags… !• Too many things to configure• E.g., https://linux.die.net/man/1/qemu-kvm• Live look at a box….• Libvirt, adds a configuration layer on top of qemu-

kvm that simplifies the knobs and switches we need to configure

Page 16: Introduction to virtualization (Part 5)

Example of Config Simplification

• On a physical kernel/computer, the layout of:– Sockets– Cores– Logical Cores

• QEMU tries to emulate this an offers 3 settings when you boot a VM:– numSockets– numCoresPerSocket– numLogicalCoresPerSocket

Page 17: Introduction to virtualization (Part 5)

Example cont…• Libvirt takes these 3 QEMU cpu configs and only

exposes a numVCPUs param• It then passes through reasonable best practice

values for the 3 QEMU configurations aforementioned:

• NOTE: It really does not matter what the layout of sockets/cores/lcores in the VM are, because these do not map cleanly to physical buses or caches

Zoomed in (inside guest OS):

lcore lcore

Page 18: Introduction to virtualization (Part 5)

Our Full KVM Stack

• Tools like virt-manager, virt-install, virsh are used to access Libvirt API.

• XMLs define each VM (called “domains” in libvirt”)• QCOW images define the contents of hard disk

• In other words, in our stackDomain XML + QCOW == A virtual machine