Articles

Hosts, VMs, vCPU, vRAM and virtual devices

How a hypervisor exposes CPUs, memory and devices to a VM, and what is really emulated.

Reading: 4 minServer & Virtualization

Article cover: Hosts, VMs, vCPU, vRAM and virtual devices

A guest operating system reports a processor count, a memory size, disks and network cards as if it were a physical machine. Every one of those answers is a line in the virtual machine’s definition, which the hypervisor translates into real resources at run time; getting that translation right is most of the work.

The model: a declaration, presented as a machine

The host owns real CPUs, memory and devices. The hypervisor keeps them and gives each virtual machine a view of them: a number of virtual processors, a memory size, and a set of virtual devices. The guest boots against that view and never touches the host’s hardware.

        physical host: CPUs   memory   NIC   storage adapters   disks
                                 │
                                 ▼
        ┌──────────────────────────────────────────────────────────┐
        │  hypervisor (VMM)                                         │
        │  · schedules each vCPU on a real core                     │
        │  · maps guest memory onto host memory                     │
        │  · presents each device (emulated | virtio | pass-through)│
        └───────────────────────────┬──────────────────────────────┘
                                    │  the VM definition
                                    │  (vcpu count, memory size,
                                    │   disks, interfaces, firmware)
                                    ▼
        ┌──────────────────────────────────────────────────────────┐
        │  one virtual machine                                      │
        │  guest OS sees: vCPU 0..N-1 | vRAM | disk | NIC | chipset │
        └──────────────────────────────────────────────────────────┘

Everything in the lower box is a choice the hypervisor made on the guest’s behalf.

The definition file: a machine is declared before it runs

Before a virtual machine is a process, it is a description. In libvirt it is a domain: XML that sets the maximum number of virtual CPUs “allocated for the guest OS”, the memory “for the guest at boot time”, and a devices section whose elements “are all used to describe devices provided to the guest domain”. Proxmox VE records the same decisions in its own configuration: sockets and cores, memory, disk bus, network device. The machine is declared first, the declaration is what an administrator edits, and the guest’s inside view changes only when its own operating system notices.

The declaration can be looser than a physical build: <vcpu> accepts a current attribute for “fewer than the maximum number of virtual CPUs”, and behind the devices sits a device model — libvirt records the “fully qualified path to the device model emulator binary” — because for many devices the hypervisor runs an emulator rather than handing over hardware.

vCPU: processors the guest sees, threads the host schedules

A vCPU is not a core. It is an object the hypervisor creates and the host scheduler places on real hardware, as it places the threads of any other program. Proxmox VE asks for sockets and cores: “This CPU can then contain one or many cores”, and for each virtual CPU “QEMU will create a new thread of execution on the host system”. Four vCPUs are, on the host, four threads that “the host system will balance the QEMU execution threads between your server cores”, while the guest counts the processors it was told it has and runs its own scheduler on top. Two schedulers run in series, and the guest cannot see the lower one.

So the count is a plan, not a reward. Adding virtual CPUs gives an improvement “heavily dependent on the use of the VM”: a workload that cannot use a second thread gains nothing from seven more, and each extra vCPU costs a host thread to schedule.

vRAM: memory the guest is told it has

Memory is declared as a size, and the size is a target rather than a wire. libvirt’s <memory> is the “maximum allocation of memory for the guest at boot time”; <currentMemory> is the “actual allocation”, which “can be less than the maximum allocation”. With ballooning, the “passing around of memory between host and guest is” handled by a driver inside the guest that releases or reclaims pages; Hyper-V’s Dynamic Memory “automatically adjusts memory allocation based on actual workload demands”. The definition says what the guest is told it has; the host must still back it with physical pages. A size comfortable inside the guest can be why the host, not the guest, is under pressure.

Devices: emulated, paravirtualized, passed through

Every device a guest sees was chosen from three strategies that trade performance, portability and isolation differently.

An emulated device is a simulation of familiar hardware, chosen so an unmodified guest already has a driver. Hyper-V’s IDE controllers “are emulated controllers”, and the IDE design “goes back to the 1984 PC/AT disk controller”; Proxmox VE emulates an LSI 53C895A SCSI controller and, by default, an Intel E1000 network card. Emulation is the compatibility path, and it is slow: the simulated controller is itself a limit — Hyper-V recommends IDE only for the OS disk.

A paravirtualized device (virtio) is one the guest is told about and drives with a purpose-built driver. Hyper-V’s SCSI path “isn’t emulated”, and Proxmox recommends the VirtIO SCSI or VirtIO Block controller “for performance reasons”. Less to simulate means better throughput, but the guest must have the driver: an old operating system without one cannot use the fast device.

A pass-through device is given to the guest closer to the real hardware. A pass-through disk maps the VM “directly to a physical disk or logical unit number (LUN) instead of a VHD file”, which “reduces the CPU usage of storage I/O”, at the price of portability: such disks are “more difficult to migrate between machines than VHD files”. Firmware is part of the presentation too — a generation 2 Hyper-V machine is given “UEFI firmware, Secure Boot capabilities” and a “Virtual TPM 2.0” — and where the bytes actually live is a separate matter, because Hyper-V “supports a wide range of physical storage architectures”.

Where the abstractions leak

Three mistakes recur, and all three treat a declaration as a physical fact.

Assigning vCPUs the workload cannot use. Since each vCPU is a host thread and two schedulers run in series, only the count the load can keep busy helps; above that it is overhead.

Confusing memory assigned with memory available. The declared size is a target; the host must still hold the pages.

Trusting a legacy emulated device. The storage path runs through four stages — guest storage stack, host virtualization layer, host storage stack, physical disk — and an emulated controller chosen for compatibility can be the slow one.

Level and prerequisites

L3 — the guest’s view of declared resources: vCPUs, memory and devices are declared, presented and translated, not wired. Prerequisites: the layer vocabulary and what a guest does not see, then CPU cores, threads, RAM and memory pressure (all L1). The operational consequences of these choices — allocation and oversubscription, CPU pinning and NUMA affinity, PCIe and GPU pass-through, and live migration — are L4 and are not developed here.

Where to go next

  • Server & Virtualization — the area this sheet belongs to.
  • Named as L4 only: allocation and oversubscription, CPU affinity and NUMA tuning, PCIe and GPU passthrough, live migration.

References

Nodrius Field Kit — cover

Get the Nodrius Field Kit

Enter your email and we'll send you the complete Field Kit: eight technical resources in one download.

Your email address is sent to Nodrius and used to deliver the Field Kit to you by email. Marketing messages are separate and optional: the checkbox does not affect your download, and you are only added to our updates list if you tick it. Privacy Policy.

Privacy & cookies

This site does not use cookies, analytics or tracking, and it does not profile you. There is nothing technical to switch off, so Accept and Reject change nothing about how the site works: either choice lets you browse everything normally.

The only difference is what your browser remembers: two entries in local storage — your choice here, so this notice is not shown again, and a marker that the Field Kit offer has already been made — so the offer is presented once and not on every page. They contain no identifier, they are not shared with anyone, and the site sets no cookie for either.

What we do with your data
How your email address is used when you ask for a Resource, how long it is kept and which rights you have — in the Privacy Policy.
What the site stores in your browser
Two entries in local storage — your choice on this notice and whether the Field Kit offer has been shown — and no cookies, no session storage, no third-party content: in the Cookie Policy.