Lecture 11
Lecture 11
System
Professor Mangal Sain
Lecture 11
Advanced Topics
Lecture 11 – Part 1
Virtual Machines
OBJECTIVES
Virtual Machines
BUILDING BLOCKS
No trap is generated
BINARY TRANSLATION (CONT.)
Other similar problem instructions we will call special
instructions
Caused trap-and-emulate method considered impossible until
1998
Binary translation solves the problem
Basics are simple, but implementation very complex
1. If guest VCPU is in user mode, guest can run instructions
natively
2. If guest VCPU in kernel mode (guest believes it is in kernel
mode)
1. VMM examines every instruction guest is about to execute by
reading a few instructions ahead of program counter
2. Non-special-instructions run natively
When guest on CPU -> VMM makes that guest’s NPTs the active system
page tables
Guest tries to change page table -> VMM makes equivalent change to
NPTs and its own page tables
Can cause many more TLB misses -> much slower performance
BUILDING BLOCKS – HARDWARE ASSISTANCE
All virtualization needs some HW support
More support -> more feature rich, stable, better performance
of guests
Intel added new VT-x instructions in 2005 and AMD the
AMD-V instructions in 2006
CPUs with these instructions remove need for binary translation
Generally define more CPU modes – “guest” and “host”
VMM can enable host mode, define characteristics of each guest VM,
switch to guest mode and guest(s) on CPU(s)
In guest mode, guest OS thinks it is running natively, sees devices
(as defined by VMM for that guest)
Access to virtualized device, priv instructions cause trap to VMM
Virtual Machines
TYPES OF VMS – TYPE 2 HYPERVISOR
Less interesting from an OS perspective
Very little OS involvement in virtualization
VMM is simply another process, run and managed by
host
Even the host doesn’t know they are a VMM running guests
Tend to have poorer overall performance because can’t
take advantage of some HW features
But also a benefit because require no changes to host OS
Student could have Type 2 hypervisor on native host, run
multiple guests, all on standard host OS such as Windows,
Linux, MacOS
TYPES OF VMS – PARAVIRTUALIZATION
Does not fit the definition of virtualization – VMM not
presenting an exact duplication of underlying
hardware
But still useful!
VMM provides services that guest must be modified to use
Leads to increased performance
Less needed as hardware support for VMs grows
Xen, leader in paravirtualized space, adds several
techniques
For example, clean and simple device abstractions
Efficient I/O
Good communication between guest and VMM about device I/O
Each device has circular buffer shared by guest and VMM via
shared memory
XEN I/O VIA SHARED CIRCULAR BUFFER
TYPES OF VMS – PARAVIRTUALIZATION (CONT.)
Xen, leader in paravirtualized space, adds several
techniques (Cont.)
Memory management does not include nested page
tables
Each guest has own read-only tables
Guest uses hypercall (call to hypervisor) when page-table
changes needed
Paravirtualization allowed virtualization of older
x86 CPUs (and others) without binary translation
Guest had to be modified to use run on
paravirtualized VMM
But on modern CPUs Xen no longer requires guest
modification -> no longer paravirtualization
TYPES OF VMS – PROGRAMMING ENVIRONMENT VIRTUALIZATION
Also not-really-virtualization but using same techniques,
providing similar features
Programming language is designed to run within custom-
built virtualized environment
For example Oracle Java has many features that depend on
running in Java Virtual Machine (JVM)
In this case virtualization is defined as providing APIs that
define a set of features made available to a language and
programs written in that language to provide an improved
execution environment
JVM compiled to run on many systems (including some
smart phones even)
Programs written in Java run in the JVM no matter the
underlying system
Similar to interpreted languages
TYPES OF VMS – EMULATION
Another (older) way for running one operating system on a different
operating system
Virtualization requires underlying CPU to be same as guest was
compiled for
Emulation allows guest to run on different CPU
Necessary to translate all guest instructions from guest CPU to native
CPU
Emulation, not virtualization
Useful when host system has one architecture, guest compiled for other
architecture
Company replacing outdated servers with new servers containing
different CPU architecture, but still want to run old applications
Performance challenge – order of magnitude slower than native code
New machines faster than older machines so can reduce slowdown
Very popular – especially in gaming where old consoles emulated on new
TYPES OF VMS – APPLICATION CONTAINMENT
Some goals of virtualization are segregation of apps,
performance and resource management, easy start, stop,
move, and management of them
Can do those things without full-fledged virtualization
If applications compiled for the host operating system, don’t
need full virtualization to meet these goals
Oracle containers / zones for example create virtual
layer between OS and apps
Only one kernel running – host OS
OS and devices are virtualized, providing resources within
zone with impression that they are only processes on system
Each zone has its own applications; networking stack,
addresses, and ports; user accounts, etc
CPU and memory resources divided between zones
Zone can have its own scheduler to use those resources
SOLARIS 10 WITH TWO ZONES
OS COMPONENT – CPU SCHEDULING
Even single-CPU systems act like multiprocessor
ones when virtualized
One or more virtual CPUs per guest
Generally VMM has one or more physical CPUs
and number of threads to run on them
Guests configured with certain number of VCPUs
Can be adjusted throughout life of VM
When enough CPUs for all guests -> VMM can allocate
dedicated CPUs, each guest much like native operating
system managing its CPUs
Usually not enough CPUs -> CPU overcommitment
VMM can use standard scheduling algorithms to put threads
on CPUs
Some add fairness aspect
OS COMPONENT – CPU SCHEDULING (CONT.)