Explore

How virtualization works

by Froga

Opens up the hypervisor: why a guest cannot hold full privilege, the four CPU techniques, two-level memory translation, memory reclamation and virtual CPUs. You will be able to compare the techniques and predict their costs. About 14 minutes.

You're previewing this room. Log in or create a free account to answer the questions and track your progress.
Study material

What this room is about. This room opens up the hypervisor and shows how it lets a guest believe it owns the whole machine. It follows the CPU first, from sensitive instructions through trap and emulate, binary translation, para-virtualization and hardware assist, and then memory: two levels of address translation, overcommitment and the ways of taking memory back. It continues the course story, from one physical server towards the cloud.

Why it matters. A guest operating system is written to assume it has full control: it turns interrupts off, edits page tables and owns every device. If it really did, one guest could freeze the host or read another guest's memory. The hypervisor has to keep control and still look invisible, at close to full speed. Knowing which technique does this, and where its cost shows up, explains why some workloads run slowly and why memory can safely be promised twice over.

Words you will meet.

  • Sensitive instruction: an instruction whose effect depends on or changes the state of the whole machine, so the hypervisor must control it when a guest uses it.
  • Trap and emulate: let the guest run at reduced privilege, catch each privileged instruction as a processor fault (a trap), and have the hypervisor perform a safe version of it.
  • Binary translation: the hypervisor rewrites the guest's code before it runs, replacing sensitive instructions with safe ones.
  • Para-virtualization: the guest kernel is modified to ask the hypervisor for privileged work through hypercalls instead of issuing sensitive instructions.
  • Hardware assist: processor support (Intel VT-x, AMD-V, since 2005) with a mode built for virtualization, so privileged operations trap automatically.
  • Shadow and nested page tables: two ways to translate a guest address to a real one: the hypervisor keeps a combined table in software (shadow), or the processor walks both levels itself (nested).
  • Ballooning: a driver inside the guest takes memory when the host runs short, so the guest itself chooses which pages to give up.

By the end you should be able to:

  • Explain why a guest kernel cannot be allowed full privilege, and what the hypervisor does after a trap.
  • Explain why x86 was hard to virtualize before 2005.
  • Compare trap and emulate, binary translation, para-virtualization and hardware assist by where each one pays its cost.
  • Describe how guest virtual, guest physical and host physical addresses are connected, and what shadow and nested page tables change.
  • Judge which memory reclamation technique suits a situation, and predict what happens when a VM gets more virtual CPUs than its workload can use.

How to use it. Each question has its own study text above it, so read that first and then answer; the answers and explanations show at the end of the room.

What is a trap in virtualization?

multiple choice

AA security feature that locks a guest out of the host after repeated failed logins
BA processor fault that hands control from the guest to the hypervisor
CA snapshot of the guest's memory that the hypervisor saves before it shuts a guest down
DA queue where the hypervisor holds guest requests until the physical disk is free
Log in to answer

Ready to test yourself?

Sign up free to answer, score points, and build your streak.