Virtual Machinesالآلات الافتراضية
مقدمة الفصل
ماذا ستتعلم في هذا الفصل
- The history and benefits of virtual machines.
- The various virtual machine technologies: Type 0, Type 1 and Type 2 hypervisors, paravirtualization, programming-environment virtualization, emulation and application containment.
- The methods used to implement virtualization: trap-and-emulate, binary translation, hardware assistance.
- Live migration as an OS component built on VMM features.
أقسام الفصل
- 1Overview: host, VMM, guestنظرة عامة: المضيف والمدير والضيف
- 2Implementations of VMMsأنواع مديري الآلات الافتراضية
- 3History of virtualizationتاريخ الافتراضية
- 4Benefits and featuresالمزايا والخصائص
- 5Building blocks: VCPU and trap-and-emulateاللبنات: المعالج الافتراضي والحجز والمحاكاة
- 6Binary translation and hardware assistanceالترجمة الثنائية ودعم العتاد
- 7VM lifecycle and hypervisor types 0, 1, 2دورة حياة الآلة الافتراضية والأنواع 0 و1 و2
- 8Paravirtualization, programming environments, emulation, containmentالافتراضية الجزئية وبيئات البرمجة والمحاكاة والاحتواء
- 9Live migrationالترحيل الحي
تلميح: استخدم أسهم لوحة المفاتيح للتنقل بين الشرائح.
Virtual machines: overviewنظرة عامة
Overview: host, VMM, guest
Abstract hardware of a single computer into several different execution environments — like the layered approach, but the layer creates a virtual system (virtual machine, VM) on which operating systems or applications can run.
The underlying hardware system.
Creates and runs virtual machines by providing an interface that is identical to the host (except in the case of paravirtualization).
A process provided with a virtual copy of the host — usually an operating system.
- A single physical machine can run multiple operating systems concurrently, each in its own virtual machine.
Implementations of VMMsأنواع المديرين
| Typeالنوع | What it is (slides 6–7)ما هو | Examplesأمثلة |
|---|---|---|
| Type 0 hypervisor |
| IBM LPARs, Oracle LDOMs |
| Type 1 hypervisor | Operating-system-like software built to provide virtualization | VMware ESX, Joyent SmartOS, Citrix XenServer |
| Type 1 (general-purpose OS) | General-purpose OSs that provide standard functions as well as VMM functions | Windows Server with HyperV, RedHat Linux with KVM |
| Type 2 hypervisor | Applications on standard OSs that provide VMM features to guest OSs | VMware Workstation and Fusion, Parallels Desktop, Oracle VirtualBox |
| Paravirtualization | Guest OS modified to cooperate with the VMM to optimize performance | لا تذكر الشرائح شيئًا هنا. |
| Programming-environment virtualization |
| Oracle Java, Microsoft .Net |
| Emulators | Run applications written for one hardware environment on a very different one (e.g., a different CPU) | لا تذكر الشرائح شيئًا هنا. |
| Application containment |
| Oracle Solaris Zones, BSD Jails, IBM AIX WPARs |
Historyالتاريخ
- First appeared in IBM mainframes in 1972; allowed multiple users to share a batch-oriented system.
التعريف الرسمي في ثلاث نقاط.
- 1Essentially identical environment
A VMM provides an environment for programs that is essentially identical to the original machine.
- 2Minor performance decreases
Programs running within that environment show only minor performance decreases.
- 3Complete control
The VMM is in complete control of system resources.
- Late 1990s: Intel CPUs fast enough to virtualize general-purpose PCs; Xen and VMware created technologies still used today.
Benefits and featuresالمزايا
- Protection: host protected from VMs, VMs protected from each other (a virus less likely to spread); sharing via a shared file system volume or network communication.
- Freeze, suspend, running VM → move or copy somewhere else and resume; snapshot a state and restore it (some VMMs allow multiple snapshots); clone by copying and running both.
- Great for OS research, better system development efficiency; run multiple, different OSes on a single machine; consolidation, app dev.
Create an OS + application VM, provide it to customers, and use it to create multiple instances of that combination.
Move a running VM from one host to another — no interruption of user access.
All those features together: using APIs, programs tell cloud infrastructure (servers, networking, storage) to create new guests, VMs, virtual desktops.
VCPU and trap-and-emulateالحجز والمحاكاة
Implemented by most VMMs to represent the state of the CPU per guest as the guest believes it to be; loaded and stored when the guest is context switched onto the CPU.
- The guest executes in user mode; the VM needs virtual user mode and virtual kernel mode, both running in real user mode.
Trap-and-emulate (slide 13)
- 1
The guest attempts a privileged instruction in user mode → an error → trap.
- 2
The VMM gains control and analyzes the error.
- 3
The VMM executes the operation as attempted by the guest.
- 4
The VMM returns control to the guest in user mode.
- User-mode guest code runs at the same speed as if not a guest; kernel-mode guest code runs slower — especially with multiple guests.
Binary translationالترجمة الثنائية
- Some CPUs (earlier Intel x86) have no clean separation between privileged and nonprivileged instructions: x86 popf replaces all flags in privileged mode but only some in user mode — no trap is generated, so trap-and-emulate fails for such special instructions.
Binary translation (slide 16)
- 1
If the guest VCPU is in user mode, the guest runs instructions natively.
- 2
If the guest VCPU is in kernel mode, the VMM examines every instruction the guest is about to execute, reading a few instructions ahead of the program counter.
- 3
Non-special instructions run natively.
- 4
Special instructions are translated into a new set of instructions that perform an equivalent task (e.g., changing the flags in the VCPU).
- VMware uses caching — translate once and reuse the cached translation (slide 17).
- Booting Windows XP as a guest: 950,000 translations × 3 µs = 3 seconds (5%) slowdown over native.
Hardware assistanceدعم العتاد
- All virtualization needs some HW support; more support → more feature rich, stable, better guest performance.
- Intel VT-x (2005) and AMD AMD-V (2006): CPUs with these instructions remove the need for binary translation.
- They define more CPU modes — "guest" and "host"; in guest mode the guest OS thinks it is running natively.
- Access to a virtualized device or privileged instructions cause a trap to the VMM; the CPU maintains the VCPU and context switches it as needed.
- HW support also for nested page tables, DMA and interrupts over time.
VM lifecycle and Type 0دورة الحياة والنوع 0
VM lifecycle and hypervisor types 0, 1, 2
A VM's lifecycle (slide 20)
- 1
Created by the VMM.
- 2
Resources assigned (number of cores, amount of memory, networking details, storage details) — dedicated in Type 0; dedicated, shared or mixed in other types.
- 3
When no longer needed, the VM can be deleted, freeing resources.
- Simpler and faster than a physical machine install — but can lead to virtual machine sprawl (history and state difficult to track).
Type 0 hypervisor (slide 21)
- Old idea under names like "partitions", "domains"; a HW feature implemented by firmware (the VMM is in firmware).
- Smaller feature set; each guest has dedicated HW; I/O a challenge (a control partition may provide shared I/O).
- Can provide virtualization-within-virtualization.
Type 1 and Type 2 hypervisorsالنوعان 1 و2
VM lifecycle and hypervisor types 0, 1, 2
Type 1النوع 1
- Commonly found in company datacenters — "datacenter operating systems"
- Special-purpose OSs that run natively on HW, creating, running and managing guest OSes
- Run in kernel mode; guests generally don't know they are in a VM
- Implement device drivers for host HW; CPU and memory management
- Variation: a general-purpose OS with VMM functionality (KVM, Hyper-V) — typically less feature rich
Type 2النوع 2
- Very little OS involvement in virtualization
- The VMM is simply another process, run and managed by the host
- Tends to have poorer overall performance (can't use some HW features)
- Benefit: requires no changes to the host OS
Paravirtualization and programming environmentsالافتراضية الجزئية
Paravirtualization, programming environments, emulation, containment
Does not fit the definition of virtualization — the VMM does not present an exact duplication of the hardware — but the VMM provides services that the guest must be modified to use, leading to increased performance; less needed as HW support grows.
Xen (slides 26–27)
- Clean and simple device abstractions; efficient I/O; each device has a circular buffer shared by guest and VMM via shared memory.
- No nested page tables: each guest has its own read-only tables and uses a hypercall (call to hypervisor) when page-table changes are needed.
- Allowed virtualization of older x86 CPUs without binary translation; on modern CPUs Xen no longer requires guest modification → no longer paravirtualization.
Not really virtualization: a language runs within a custom-built virtualized environment — e.g., Java programs run in the JVM no matter the underlying system; virtualization here means providing APIs for the language; similar to interpreted languages.
Emulation and application containmentالمحاكاة والاحتواء
Paravirtualization, programming environments, emulation, containment
Virtualizationالافتراضية
- Requires the underlying CPU to be the same as the guest was compiled for
Emulationالمحاكاة
- Allows the guest to run on a different CPU
- Translates all guest instructions from the guest CPU to the native CPU
- An order of magnitude slower than native code
- Popular in gaming (old consoles emulated on new)
Segregation of apps, resource management, easy start/stop/move without full-fledged virtualization: e.g., Oracle zones create a virtual layer between the OS and apps; only one kernel running — the host OS; each zone has its own applications, networking stack, addresses, ports and user accounts; CPU and memory are divided between zones.
Live migrationالترحيل الحي
A running guest can be moved between systems without interrupting user access to the guest or its apps — useful for resource management, maintenance downtime windows, etc.
Steps (slides 32–33)
- 1
The source VMM establishes a connection with the target VMM.
- 2
The target creates a new guest (a new VCPU, etc.).
- 3
The source sends all read-only guest memory pages.
- 4
The source sends all read-write pages, marking them as clean.
- 5
The source repeats step 4, because some pages were modified meanwhile and are now dirty.
- 6
When the 4–5 cycle becomes very short, the source freezes the guest, sends the VCPU's final state, other state details and the final dirty pages, and tells the target to start running the guest.
- 7
Once the target acknowledges the guest is running, the source terminates the guest.
الخلاصة
أنهيت الدرس
الخطوة التالية: ثبّت المعلومات بالبطاقات، ثم اختبر نفسك بالأسئلة.
ما راجعته في هذا الدرس
- Overview: host, VMM, guestنظرة عامة: المضيف والمدير والضيف
- Implementations of VMMsأنواع مديري الآلات الافتراضية
- History of virtualizationتاريخ الافتراضية
- Benefits and featuresالمزايا والخصائص
- Building blocks: VCPU and trap-and-emulateاللبنات: المعالج الافتراضي والحجز والمحاكاة
- Binary translation and hardware assistanceالترجمة الثنائية ودعم العتاد
- VM lifecycle and hypervisor types 0, 1, 2دورة حياة الآلة الافتراضية والأنواع 0 و1 و2
- Paravirtualization, programming environments, emulation, containmentالافتراضية الجزئية وبيئات البرمجة والمحاكاة والاحتواء
- Live migrationالترحيل الحي