Download - KVM: Linux-based Virtualization
![Page 2: KVM: Linux-based Virtualization](https://reader033.vdocuments.net/reader033/viewer/2022052315/554f638eb4c905c8088b4bd9/html5/thumbnails/2.jpg)
2Copyright © 2009 Red Hat, Inc. All rights reserved
Agenda
• Quick view• Features• libvirt• oVirt• KVM Execution loop• Memory management• Linux Integration• Paravirtualization• I/O
• Power Management• Non-x86• Real time• Xenner• Roadmap• Community• Conclusions
![Page 3: KVM: Linux-based Virtualization](https://reader033.vdocuments.net/reader033/viewer/2022052315/554f638eb4c905c8088b4bd9/html5/thumbnails/3.jpg)
3Copyright © 2009 Red Hat, Inc. All rights reserved
At a glance
• KVM – the Kernel-based Virtual Machine – is a Linux kernel module that turns Linux into a hypervisor
• Requires hardware virtualization extensions– paravirtualization where makes sense
• Supports multiple architectures: x86 (32- and 64- bit) s390 (mainframes), PowerPC, ia64 (Itanium)
• Competitive performance and feature set• Advanced memory management• Tightly integrated into Linux
![Page 4: KVM: Linux-based Virtualization](https://reader033.vdocuments.net/reader033/viewer/2022052315/554f638eb4c905c8088b4bd9/html5/thumbnails/4.jpg)
4Copyright © 2009 Red Hat, Inc. All rights reserved
The KVM approach
• A hypervisor needs– A scheduler and memory management– An I/O stack– Device drivers– A management stack– Networking– Platform support code
• Linux has world-class support for all this, so why reinvent the wheel?
• Reuse Linux code as much as possible• Focus on virtualization, leave other things to respective
developers• Benefit from semi-related advances in Linux
![Page 5: KVM: Linux-based Virtualization](https://reader033.vdocuments.net/reader033/viewer/2022052315/554f638eb4c905c8088b4bd9/html5/thumbnails/5.jpg)
5Copyright © 2009 Red Hat, Inc. All rights reserved
Architecture Overview of KVM
● KVM: Kernel-based Virtual Machine – Full virtualization solution for Linux
• Incorporated into the Linux kernel in 2006
• Converts Linux into a hypervisor. Run unmodified OSes as guests.
• KVM architecture provides high “feature-velocity” – leverages the power of Linux
![Page 6: KVM: Linux-based Virtualization](https://reader033.vdocuments.net/reader033/viewer/2022052315/554f638eb4c905c8088b4bd9/html5/thumbnails/6.jpg)
6Copyright © 2009 Red Hat, Inc. All rights reserved
KVM features
• Leverage HW virtualization support– VT-x/AMD-V, EPT/NPT, VT-d/IOMMU
• CPU and memory overcommit• High performance paravirtual i/o• Hotplug (cpu, block, nic)• SMP guests• Live migration• Power Management• NUMA• PCI Device Assignment and SR-IOV• Page sharing• SPICE• KVM autotest
![Page 7: KVM: Linux-based Virtualization](https://reader033.vdocuments.net/reader033/viewer/2022052315/554f638eb4c905c8088b4bd9/html5/thumbnails/7.jpg)
7Copyright © 2009 Red Hat, Inc. All rights reserved
Libvirt Features
• Hypervisor agnositc– Xen, KVM, QEMU, LXC, UML, OpenVZ
• Provisioning, lifecycle management• Storage
– IDE/SCSI/LVM/FC/Multipath/NPIV/NFS
• Networking– Bridging, bonding, vlans, etc
• Secure remote management– TLS, Kerberos
• Many common language bindings– Python, perl, ruby, ocaml, c#, java
• CIM provider• AMQP agent
![Page 8: KVM: Linux-based Virtualization](https://reader033.vdocuments.net/reader033/viewer/2022052315/554f638eb4c905c8088b4bd9/html5/thumbnails/8.jpg)
8Copyright © 2009 Red Hat, Inc. All rights reserved
oVirt features
• Scalable data center virtualization management– Server and desktop
• Small footprint virtualization hosting platform• Web UI for centralized remote mgmt• Directory integration• Hierarchical resource pools• Statistics gathering• Provisioning, SLA, load balancing
![Page 9: KVM: Linux-based Virtualization](https://reader033.vdocuments.net/reader033/viewer/2022052315/554f638eb4c905c8088b4bd9/html5/thumbnails/9.jpg)
9Copyright © 2009 Red Hat, Inc. All rights reserved
KVM Execution Model
• Three modes for thread execution instead of the traditional two:– User mode– Kernel mode– Guest mode
• A virtual CPU is implemented using a Linux thread• The Linux scheduler is responsible for scheduling a
virtual cpu, as it is a normal thread
![Page 10: KVM: Linux-based Virtualization](https://reader033.vdocuments.net/reader033/viewer/2022052315/554f638eb4c905c8088b4bd9/html5/thumbnails/10.jpg)
10Copyright © 2009 Red Hat, Inc. All rights reserved
KVM Execution Model
Native GuestExecution
Kernelexit handler
Userspaceexit handler
Switch toGuest Mode
ioctl()
Userspace Kernel Guest
![Page 11: KVM: Linux-based Virtualization](https://reader033.vdocuments.net/reader033/viewer/2022052315/554f638eb4c905c8088b4bd9/html5/thumbnails/11.jpg)
11Copyright © 2009 Red Hat, Inc. All rights reserved
KVM Execution Model
• Guest code executes natively– Apart from trap'n'emulate instructions
• Performance critical or security critical operations handled in kernel– Mode transitions– Shadow MMU
• I/O emulation and management handled in userspace– Qemu-derived code base– Other users welcome
![Page 12: KVM: Linux-based Virtualization](https://reader033.vdocuments.net/reader033/viewer/2022052315/554f638eb4c905c8088b4bd9/html5/thumbnails/12.jpg)
12Copyright © 2009 Red Hat, Inc. All rights reserved
KVM Memory Model
KernelAddressSpace
UserAddressSpace
Guest physicaladdress space
VMM userspacecode and data
![Page 13: KVM: Linux-based Virtualization](https://reader033.vdocuments.net/reader033/viewer/2022052315/554f638eb4c905c8088b4bd9/html5/thumbnails/13.jpg)
13Copyright © 2009 Red Hat, Inc. All rights reserved
KVM Memory Model
• Guest physical memory is just a chunk of host virtual memory, so it can be– Swapped– Shared– Backed by large pages– Backed by a disk file– COW'ed– NUMA aware
• The rest of the host virtual memory is free for use by the VMM– Low bandwidth device emulation– Management code
![Page 14: KVM: Linux-based Virtualization](https://reader033.vdocuments.net/reader033/viewer/2022052315/554f638eb4c905c8088b4bd9/html5/thumbnails/14.jpg)
14Copyright © 2009 Red Hat, Inc. All rights reserved
Linux Integration
• Preemption (and voluntary sleep) hooks: preempt notifiers
• Swapping and other virtual memory management: mmu notifiers
![Page 15: KVM: Linux-based Virtualization](https://reader033.vdocuments.net/reader033/viewer/2022052315/554f638eb4c905c8088b4bd9/html5/thumbnails/15.jpg)
15Copyright © 2009 Red Hat, Inc. All rights reserved
Preempt Notifiers
• Linux may choose to suspend a vcpu's execution• KVM runs with some guest state loaded while in kernel
mode (FPU, etc.)• Need to restore state when switching back to user
mode• Solution: Linux notifies KVM whenever it preempts a
process that has guest state loaded– ... and when the process is scheduled back in
• Allows the best of both worlds– Low vmexit latency– Preemptibility, sleeping when paging in
![Page 16: KVM: Linux-based Virtualization](https://reader033.vdocuments.net/reader033/viewer/2022052315/554f638eb4c905c8088b4bd9/html5/thumbnails/16.jpg)
16Copyright © 2009 Red Hat, Inc. All rights reserved
MMU Notifiers
• Linux doesn't know about the KVM MMU• So it can't
– Flush shadow page table entries when it swaps out a page (or migrates it, or ...)
– Query the pte accessed bit when determines the recency of a page
• Solution: add a notifier– for tlb flushes– for accessed/dirty bit checks
• With MMU notifiers, the KVM shadow MMU follows changes to the Linux view of the process memory map
![Page 17: KVM: Linux-based Virtualization](https://reader033.vdocuments.net/reader033/viewer/2022052315/554f638eb4c905c8088b4bd9/html5/thumbnails/17.jpg)
17Copyright © 2009 Red Hat, Inc. All rights reserved
Paravirtualization
• Not nearly as critical for CPU/MMU now with hardware assistance– Highly intrusive
• KVM has modular paravirtualization support– Turn on and off as needed by hardware
• Supported areas– Hypercall-based, batched mmu operations– Clock– I/O path (virtio)
![Page 18: KVM: Linux-based Virtualization](https://reader033.vdocuments.net/reader033/viewer/2022052315/554f638eb4c905c8088b4bd9/html5/thumbnails/18.jpg)
18Copyright © 2009 Red Hat, Inc. All rights reserved
Virtio
• Most devices emulated in userspace– With fairly low performance
• Paravirtualized I/O is the traditional way to accelerate I/O
• Virtio is a framework and set of drivers:– A hypervisor-independent, domain-independent,
bus-independent protocol for transferring buffers– A binding layer for attaching virtio to a bus (e.g. pci)– Domain specific guest drivers (networking, storage,
etc.)– Hypervisor specific host support
![Page 19: KVM: Linux-based Virtualization](https://reader033.vdocuments.net/reader033/viewer/2022052315/554f638eb4c905c8088b4bd9/html5/thumbnails/19.jpg)
19Copyright © 2009 Red Hat, Inc. All rights reserved
Power management
• A good example of how Linux integration helps– An especially icky area in operating systems
• KVM has– Automatic frequency scaling
• with several governors
– Suspend/resume support• with running virtual machines
• All with a small amount of glue code
![Page 20: KVM: Linux-based Virtualization](https://reader033.vdocuments.net/reader033/viewer/2022052315/554f638eb4c905c8088b4bd9/html5/thumbnails/20.jpg)
20Copyright © 2009 Red Hat, Inc. All rights reserved
Other cpu architectures
• s390 (aka zSeries, aka mainframe)– KVM support recently integrated
• ia64 (aka Itanium)– ditto
• PowerPC embedded
![Page 21: KVM: Linux-based Virtualization](https://reader033.vdocuments.net/reader033/viewer/2022052315/554f638eb4c905c8088b4bd9/html5/thumbnails/21.jpg)
21Copyright © 2009 Red Hat, Inc. All rights reserved
Real time
• Linux has (unmerged) hard real time support• KVM does not interfere with the real time properties of
real time Linux• Can run virtual machines alongside hard real time
processes– Run a GUI in a container alongside an industrial
controller– Or a cell phone– Or, soak up unused cycles on real-time financials
servers
![Page 22: KVM: Linux-based Virtualization](https://reader033.vdocuments.net/reader033/viewer/2022052315/554f638eb4c905c8088b4bd9/html5/thumbnails/22.jpg)
22Copyright © 2009 Red Hat, Inc. All rights reserved
Xenner
• An independent application that uses KVM• Emulates the Xen hypervisor ABI
– Much, much smaller than Xen• Used to run unmodified Xen guests on KVM
![Page 23: KVM: Linux-based Virtualization](https://reader033.vdocuments.net/reader033/viewer/2022052315/554f638eb4c905c8088b4bd9/html5/thumbnails/23.jpg)
23Copyright © 2009 Red Hat, Inc. All rights reserved
Roadmap
• QEMU improvements and integration– Libmonitor, machine descritption
• qxl/SPICE integration• Scalability work
– Qemu and kvm
• Performance work– Block
• i/o using linux aio
– Network• GRO• Multiqueue virtio• Latency reduction• Zero copy
• Enlightenment
![Page 24: KVM: Linux-based Virtualization](https://reader033.vdocuments.net/reader033/viewer/2022052315/554f638eb4c905c8088b4bd9/html5/thumbnails/24.jpg)
24Copyright © 2009 Red Hat, Inc. All rights reserved
Community
• Main contributors– AMD, IBM, Intel, Red Hat
• Typical open source project– Mailing lists, IRC
• Will love to see you contribute
http://linux-kvm.orghttp://libvirt.orghttp://ovirt.org
![Page 25: KVM: Linux-based Virtualization](https://reader033.vdocuments.net/reader033/viewer/2022052315/554f638eb4c905c8088b4bd9/html5/thumbnails/25.jpg)
25Copyright © 2009 Red Hat, Inc. All rights reserved
Conclusions
• Simple model - no excess baggage• Fully featured• Great performance• Rapidly moving forward
![Page 26: KVM: Linux-based Virtualization](https://reader033.vdocuments.net/reader033/viewer/2022052315/554f638eb4c905c8088b4bd9/html5/thumbnails/26.jpg)