Hypervisors and virtualization architecture
Clear, exam-focused notes on hypervisors and virtualization architecture: definitions, types, mechanisms (trap-and-emulate, binary translation, hardware assist), memory and I/O virtualization, diagrams to draw, formulas, worked examples, common mistakes and exam tips.
Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.
Why it matters
Virtualization and the hypervisor are the foundation of cloud infrastructure: engineers use them to run many isolated virtual machines (VMs) on a single physical server, control resources, migrate workloads, and implement multi-tenant security. Understanding hypervisor architecture helps you reason about performance, scalability, and where failures or security breaches can occur.
Key ideas
Host (or physical host) — the physical machine with CPU, memory, storage and network.
Guest — an operating system running inside a VM; its view of hardware is virtualized.
VM image — a file (or set of files) that contains a VM's disk contents and metadata.
Virtual device — a software-emulated hardware device (e.g., NIC, disk controller) presented to a guest.
Types of hypervisors (precise definitions):
- Type-1 hypervisor (bare-metal) — the hypervisor runs directly on the host hardware and manages guests without a separate host OS. Draw: physical hardware at bottom, hypervisor layer above it, multiple guest OS boxes on top of hypervisor. Label CPU, memory, network, storage flows through hypervisor.
- Type-2 hypervisor (hosted) — the hypervisor runs as an application on a normal host OS, which itself runs on the hardware. Draw: hardware, host OS, hypervisor application, then guests. Note: I/O often handled via host OS drivers.
Virtualization techniques (definitions and how they work):
- Full virtualization — guests run unmodified; the hypervisor supplies virtual hardware and handles sensitive operations using trapping and/or binary translation. On architectures without hardware assist, not all sensitive instructions necessarily trap; binary translation or paravirtualization is used to ensure correctness. With hardware assist, the CPU provides trapping and control mechanisms.
- Paravirtualization — the guest OS is modified to replace sensitive operations with explicit calls (hypercalls) to the hypervisor. This requires guest-source access or special kernel support.
- Binary translation — dynamic translation of guest kernel code: the hypervisor rewrites guest code at runtime so that sensitive instructions (including those that do not trap) are replaced by safe sequences that call the hypervisor. Steps universities ask for: (1) detect sensitive instruction sequences (including non-trapping ones) in a translation block, (2) translate them to hypervisor-safe sequences, (3) cache translated blocks, (4) execute translated code.
- Trap-and-emulate — run guest in less-privileged CPU mode so that privileged instructions cause a trap (exception) to the hypervisor; the hypervisor inspects the instruction and emulates its effect. Assumption: CPU will generate traps for all sensitive privileged instructions when run at lower privilege. Note: On pre-VT-x/AMD-V x86, some sensitive but unprivileged instructions do not trap, so pure trap-and-emulate is insufficient; hypervisors used binary translation or paravirtualization.
- Hardware-assisted virtualization — CPUs add modes/features (Intel VT-x, AMD-V) to avoid complex binary translation by providing a lower-privilege VMX non-root/guest mode and VM-exit/VM-entry mechanisms. The hypervisor uses special instructions to switch between guest and host. (State that details of VM-exit behaviour vary by CPU; verify exact bit names if required.)
CPU privilege rings and why they matter: modern CPUs have multiple privilege levels (commonly called rings). The kernel expects ring 0. Hypervisors run in a more privileged mode than guest kernel (or trap guest kernel actions), so the hypervisor can protect the host. For Type-2, the host OS still controls hardware but the hypervisor uses the host OS for device access.
Memory virtualization: two-level translation model used in many systems:
- Guest virtual address (GVA) -> Guest physical address (GPA) by the guest page tables.
- GPA -> Host physical address (HPA) by the hypervisor (or hardware via nested page tables / SLAT).
- Second-Level Address Translation (SLAT) or nested page tables allow the MMU to walk both tables in hardware to reduce hypervisor traps. Draw: GVA -> (guest page table) -> GPA -> (nested/host page table) -> HPA. Without SLAT, hypervisors commonly maintain shadow page tables mapping GVA->HPA to avoid trapping on every access, at the cost of more VM-exits on guest page table updates.
I/O virtualization and device passthrough:
- Emulated device — hypervisor implements device behavior in software.
- Paravirtualized driver (virtio) — guest uses a driver optimized for hypervisor communication to reduce overhead.
- Device passthrough (PCI passthrough / SR-IOV) — physical device or virtual functions assigned directly to the guest for near-native performance; requires hardware support and careful isolation, typically an IOMMU (e.g., Intel VT-d, AMD-Vi) for safe DMA remapping.
Resource management concepts: CPU scheduling, memory ballooning (guest cooperation to release memory to the hypervisor), overcommit (allocating more virtual resources than physical), live migration (moving a running VM between hosts), snapshotting (capturing VM disk+state). Mention trade-offs: overcommit increases density but may cause performance collapse under load.
Formulas
VM_density = floor(Host_memory_available / (VM_memory_allocated + per_VM_overhead)) — Host_memory_available: bytes (SI: B), VM_memory_allocated: bytes, per_VM_overhead: bytes; use when planning how many VMs fit in RAM.
Overhead_percent = (T_virtual - T_native) / T_native * 100 — T_virtual and T_native: execution time in seconds (s); gives CPU/runtime overhead of virtualization.
Effective_CPU_share = (vCPUs_assigned / Total_vCPUs_on_host) * Host_CPU_capacity — Host_CPU_capacity: cycles per second (Hz) or cores; use when estimating proportional CPU allocation under fair-share scheduling. Assumes all vCPUs are runnable; for realistic estimates use runnable/active vCPUs in the denominator.
Memory_efficiency = Useful_guest_memory / (Guest_memory_allocated + hypervisor_memory_overhead) — dimensionless ratio; use to reason about memory waste.
(These are simple engineering formulas used for capacity planning and overhead measurement.)
Worked examples
VM density (numerical).
- Problem: A host has 384 GiB RAM available for VMs. Each VM needs 6 GiB RAM and hypervisor overhead per VM is 128 MiB. How many VMs fit? Show steps.
- Formula:
VM_density = floor(Host_memory_available / (VM_memory_allocated + per_VM_overhead)). - Convert to MiB: 384 GiB = 384*1024 = 393216 MiB; 6 GiB = 6144 MiB; overhead = 128 MiB.
- Denominator: 6144 + 128 = 6272 MiB per VM.
- Division: 393216 / 6272 ≈ 62.7 -> floor -> 62 VMs.
- Remaining RAM: 393216 - 62*6272 = 393216 - 388864 = 4352 MiB = 4.25 GiB leftover.
Overhead percent (numerical).
- Problem: An application runs in 12.0 s natively and 13.8 s inside a VM. Compute virtualization overhead percent.
- Formula:
Overhead_percent = (T_virtual - T_native) / T_native * 100. - Calculation: (13.8 - 12.0) / 12.0 * 100 = 1.8 / 12.0 * 100 = 0.15 * 100 = 15% overhead.
Address translation trace (theory / small numeric trace). Provide the steps you would write in an answer:
- Given: Guest virtual address GVA -> guest page table maps to GPA 0x2000; hypervisor page table maps GPA 0x2000 -> HPA 0xA0000. The CPU performs memory access to GVA:
- Step 1: MMU consults guest page tables (or guest-level translation) to get GPA 0x2000.
- Step 2: Hardware/SLAT or hypervisor consults host page tables to translate GPA 0x2000 to HPA 0xA0000.
- Step 3: The physical memory at HPA 0xA0000 is returned to the guest access. If nested page tables exist, hardware does both steps in one combined walk; without SLAT, hypervisors typically use shadow page tables so the hardware walks a GVA->HPA mapping, but maintaining shadows causes extra VM-exits on guest page table updates.
- Final answer: Effective physical address accessed = HPA 0xA0000.
Common mistakes
- Believing virtualization always reduces performance drastically; overhead depends on workload, use of paravirtualized drivers, and hardware assist.
- Ignoring device I/O paths: thinking CPU-only virtualization costs dominate when heavy I/O without virtio/SR-IOV will be the real bottleneck.
- Misunderstanding rings: guest kernel expects ring 0; hypervisor must control privileged execution, usually by running guests at lower privilege and intercepting or by hardware virtualization modes.
- Forgetting to convert units (GiB vs GB vs MiB) in capacity planning problems.
For your exam
Kinds of questions you will get:
- Definitions and short notes: define hypervisor, Type-1 vs Type-2, paravirtualization, SLAT.
- Diagrams: draw and label Type-1 and Type-2 architectures; show two-level memory translation (GVA -> GPA -> HPA).
- Derivations/explanations: step-by-step trap-and-emulate flow; how binary translation works; why SLAT reduces VM-exit frequency.
- Numericals: capacity planning (how many VMs fit), overhead percent calculations, memory leftover.
- Comparative essays: compare full virtualization, paravirtualization, hardware-assisted virtualization — advantages, disadvantages, assumptions.
What a full-marks answer includes:
- Precise definitions with bold terms (as above), correct diagrams with labels, explicit assumptions (e.g., "assume CPU supports trapping of privileged instructions"), step-by-step sequences for mechanisms (trap, translate, emulate or binary translate), unit-correct numerical calculations, and trade-off discussion (performance vs portability vs complexity).
Quick check
- What is a hypervisor in one sentence?
- Name two advantages of paravirtualization compared to binary translation.
- In nested page tables, what two translations are performed for a guest memory access? Answers: 1) A hypervisor (VMM) is software that creates and runs multiple virtual machines by virtualizing hardware resources and controlling privileged access. 2) Lower runtime overhead and fewer traps (better performance) — but requires guest modification. 3) Guest virtual address -> guest physical address (guest page table), then guest physical -> host physical address (host/nested page table).
Finished this topic? Mark it so your progress, study plan and readiness keep up.
Stuck on something here?