kvm: linux-based virtualization - columbia...
TRANSCRIPT
KVM: Linux-based Virtualization
Columbia University Advanced OS/Virtualization course
Copyright © 2007 Qumranet, Inc. All rights reserved.
Agenda
Quick viewFeaturesKVM Execution loopMemory managementLinux IntegrationParavirtualizationI/O
Power managementNon-x86Real timeXennerCommunityConclusions
Copyright © 2007 Qumranet, Inc. All rights reserved.3
At a glance
KVM – the Kernel-based Virtual Machine – is a Linux kernel module that turns Linux into a hypervisorRequires hardware virtualization extensionsSupports multiple architectures: x86 (32- and 64- bit) s390 (mainframes), PowerPC, ia64 (Itanium)Competitive performance and feature setAdvanced memory managementTightly integrated into Linux
Copyright © 2007 Qumranet, Inc. All rights reserved.
The KVM approach
Reuse Linux code as much as possibleFocus on virtualization, leave other things to respective developersIntegrate well into existing infrastructure, codebase, and mindsetBenefit from semi-related advances in Linux
Copyright © 2007 Qumranet, Inc. All rights reserved.
VMware
Hypervisor
Driver Driver Driver
Hardware
ConsoleVM
UserVM
UserVM
UserVM
Copyright © 2007 Qumranet, Inc. All rights reserved.
Domain 0
Xen
Hypervisor
Driver Driver
Driver
Hardware
UserVM
UserVM
UserVM
Copyright © 2007 Qumranet, Inc. All rights reserved.
KVM
Linux
Driver Driver Driver
Hardware
UserVM
UserVM
UserVM
KVM
OrdinaryLinux
Process
OrdinaryLinux
Process
OrdinaryLinux
Process
Modules
Copyright © 2007 Qumranet, Inc. All rights reserved.
KVM model enefits
Reuse scheduler, memory management, bringupReuse Linux driver portfolioReuse I/O stackReuse management stack
Copyright © 2007 Qumranet, Inc. All rights reserved.9
KVM Process Model
kernel
task task guest task task guest
Copyright © 2007 Qumranet, Inc. All rights reserved.10
KVM Execution Model
Three modes for thread execution instead of the traditional two:
User modeKernel modeGuest mode
A virtual CPU is implemented using a Linux threadThe Linux scheduler is responsible for scheduling a virtual cpu, as it is a normal thread
Copyright © 2007 Qumranet, Inc. All rights reserved.11
KVM Execution Model
Native GuestExecution
Kernelexit handler
Userspaceexit handler
Switch toGuest Mode
ioctl()
Userspace Kernel Guest
Copyright © 2007 Qumranet, Inc. All rights reserved.12
KVM Execution Model
Guest code executes nativelyApart from trap'n'emulate instructions
Performance critical or security critical operations handled in kernel
Mode transitionsShadow MMU
I/O emulation and management handled in userspace
Qemu-derived code baseOther users welcome
Copyright © 2007 Qumranet, Inc. All rights reserved.13
KVM Memory Model
KernelAddressSpace
UserAddressSpace
Guest physicaladdress space
VMM userspacecode and data
Copyright © 2007 Qumranet, Inc. All rights reserved.14
KVM Memory Model
Guest physical memory is just a chunk of host virtual memory, so it can be
SwappedSharedBacked by large pagesBacked by a disk fileCOW'ed
The rest of the host virtual memory is free for use by the VMM
Low bandwidth device emulationManagement code
Copyright © 2007 Qumranet, Inc. All rights reserved.15
Linux Integration
Preemption (and voluntary sleep) hooks: preempt notifiersSwapping and other virtual memory management: mmu notifiers
Copyright © 2007 Qumranet, Inc. All rights reserved.16
Preempt Notifiers
Linux may choose to suspend a vcpu's executionKVM runs with some guest state loaded while in kernel mode (FPU, etc.)Need to restore state when switching back to user modeSolution: 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 worldsLow vmexit latencyPreemptibility, sleeping when paging in
Copyright © 2007 Qumranet, Inc. All rights reserved.17
Preempt notifiers
Guest
VMM process in host kernel
Scheduler
External interruptor trap
Other process
Restorehoststate
Restoregueststate
Contextswitch
Contextswitch
Copyright © 2007 Qumranet, Inc. All rights reserved.18
MMU Notifiers
Linux doesn't know about the KVM MMUSo 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 notifierfor tlb flushesfor accessed/dirty bit checks
With MMU notifiers, the KVM shadow MMU follows changes to the Linux view of the process memory map
Copyright © 2007 Qumranet, Inc. All rights reserved.19
Paravirtualization
Yesterday's hot topicNeeded for decent MMU performance without two-dimensional pagingIntrusive
KVM has modular paravirtualization supportTurn on and off as needed by hardwareStill needs hardware virtualization extensions
Supported areasHypercall-based, batched mmu operationsClock
Copyright © 2007 Qumranet, Inc. All rights reserved.20
Virtio
Most devices emulated in userspaceWith fairly low performance
Paravirtualized I/O is the traditional way to accelerate I/OVirtio is a framework and set of drivers:
A hypervisor-independent, domain-independent, bus-independent protocol for transferring buffersA binding layer for attaching virtio to a bus (e.g. pci)Domain specific guest drivers (networking, storage, etc.)Hypervisor specific host support
Copyright © 2007 Qumranet, Inc. All rights reserved.21
Power management
A good example of how Linux integration helpsAn especially icky area in operating systems
KVM hasAutomatic frequency scaling
with several governorsSuspend/resume support
with running virtual machines
All with a small amount of glue code
Copyright © 2007 Qumranet, Inc. All rights reserved.22
Other cpu architectures
s390 (aka System Z, aka mainframe)KVM support recently integrated
ia64 (aka Itanium)ditto
PowerPC embeddedIn developmentComing soon to a cell phone near you
Copyright © 2007 Qumranet, Inc. All rights reserved.23
Real time
Linux has (unmerged) hard real time supportKVM does not interfere with the real time properties of real time LinuxCan run virtual machines alongside hard real time processes
Run a GUI in a container alongside an industrial controllerOr a cell phoneOr, soak up unused cycles on real-time financials servers
Copyright © 2007 Qumranet, Inc. All rights reserved.24
Xenner
An independent application that uses KVMEmulates the Xen hypervisor ABI
Much, much smaller than Xen
Used to run unmodified Xen guests on KVM
Copyright © 2007 Qumranet, Inc. All rights reserved.25
Community
Main contributorsAMD, IBM, Intel, Qumranet, Red Hat
Typical open source projectMailing lists, IRC
Annual Developer's ForumThis year at Napa, California in June
Will love to see you contribute
Copyright © 2007 Qumranet, Inc. All rights reserved.26
Conclusions
Simple model - no excess baggageFully featuredGood performanceCatching up from behind – but at a tremendous pace
Participate athttp://kvm.qumranet.com
Thank You