[OSC] Day8:Virtualization

Virtualization


Fundamental idea: Virtual Machines
  • Abstract hardware of a single computer into several different execution environments.
  • Similar to layered approach, but layer creates virtual system(virtual machine, or VM) on which operation systems or applications can run several components
  • The base is hardware, and there is a VMM, on the top is different server on different OS
We have already seen that an OS virtualises(Why?)
Virtual Memory
Virtual file system
However, a VM virtualises an entire physical machine:
Providing the illusion that software has full control over the hardware
As implication, you can run multiple instances of an OS(or different OS) on the same physical machine

Components

Host -underlying hardware system
Virtual machine manager(VMM) or hypervisor - creates and runs virtual machines by providing an interface that is identical to the host(Except in the case of paravirtualization)
Guest -process provided with virtual copy of the host(usually an operating system)

Main properties

  • Isolation: each VM is independent, so failures do not affect the host
  • Encapsulation: state can be captured into a file(checking pointing, migration. It is easier than migrating processes. We merely have to move the memory image that contains OS tables)
  • Interposition: All guest actions go through the monitor(VMM), which can inspect, modify, deny operations
  • Fewer physical machines saves money on hardware and electricity
  • Run legacy applications

Requirements for virtualisation

  • Safety: the hypervisor should have full control of the virtualised resources(Resources sharing)
  • Fidelity: the behaviour of a program on a VM should be identical to that of the same program running on bare hardware. What if we run privileged instructions?(Virtualisation Technology(VT) - hardware support)
  • Efficiency: much of the code in the VM should run without intervention by the hypervisor(Overheads)
It is not like java VM. A java VM is very different from the physical machine that runs it. A hardware-level VM reflects underlying processor architecture
It is not like simulator or emulator. Simulators generally have very high overhead. A hardware-level VM utilises the underlying physical processor directly

Approaches to virtualisation

Full Virtualisation: It tries to trick the guest into believing that is has the entire system
Paravirtualisation: VM does not simulate hardware. It offers a set of hypercalls which allows the guest to send explicit requests to the hypervisor(as a system call offers kernel services to applications)
Process-level virtualisation: The aim is to simply allow a process that was written for a different OS to run. For instance, “Wine” in Linux to run Windows applications, “Cygwin” to run Linux shell on Windows.

Types of hypervisors

There are two main types of VMMs:
  • Natives(Type 1): Technically, it is like an OS, since it is the only program running in the most privileged mode. Its job is to support multiple copies of the actual hardware.
  • Hosted(Type 2): It relies on a OS to allocate and schedule resources, very much like a regular process
  • Both VMMs act as real hardware
  • enter image description here

Native Virtual Machines(Type 1 Hypervisors)

Hypervisor installs directly on hardware
The hypervisor is the real kernel
(Unmodified) OS runs in the user mode:
  • It seems to be in kernel model: virtual kernel mode
  • Privileged instructions need to be processed by the hypervisor
  • Hardware VT technology will be necessary
    Paravirtualisation-based VMs are typically based on type 1 hypervisors.
    Examples: VMware ESX Server, Xen, Microsoft Viridian (2008)

Hosted Virtual Machines(Type 2 Hypervisors)

Installs and runs VMs as an application on an existing OS.
Relies on host scheduling. Therefore, it may not be suitable for intensive VM workloads.
I/O path is slow because it requires world switch.
Process-level virtualisation will rely on type 2 hypervisors. It needs an OS.
Examples: VMware Player/Workstation/Server, Microsoft Virtual PC/Server, Parallels Desktop
A hypervisor must virtualise:
  • Privileged instructions (Exceptions and interruptions)
  • CPU
  • Memory
  • I/O devices

What do we need to Virtualise?

Virtualising Privileged Instructions
It is not safe to let guest kernel run in kernel mode
So a VM needs two modes: virtual user mode and virtual kernel mode. Both of which run in real user mode!
What happens when the guest OS executes an instruction that is allowed only when the CPU really is in kernel mode?(e.g. map virtual pages to physical pages)
  • Type 1 hypervisors: In CPUs without Virtual Techonology (VT), the instruction fails, and the OS crashes.
How does switch from virtual user mode to virtual kernel mode occur?
  • Attempting a privileged instruction in user mode causes an error -> trap
  • VMM gains control, analyses error, executes operation as attempted by guest
  • Returns control to guest in user mode
  • Known as trap-and-emulate
  • enter image description here

评论

此博客中的热门博文

[MLE] W2 Multivariate linear regression

[MLE] W1 Introduction

[AIM] MetaHeuristics