
Linux and KVM, Part 6: Performance, Device Leakage, Security, and Live Migration
🌐 Machine-translated from Russian. Show original
In this part:
Processor#
CPU model. host-passthrough gives the VM all host processor instructions — maximum speed. If VMs will migrate between different servers — use the common model (host-model or named one, for example EPYC, Skylake-Server).
Core binding (CPU pinning) for heavy VMs (DBMS, 1C):
lscpu -e # ядра, NUMA-узлы и потоки
virsh vcpupin db01 0 4
virsh vcpupin db01 1 5
virsh emulatorpin db01 0-1
To secure it permanently — the section <cputune> in virsh edit. Rules: keep the VM in one NUMA node, do not give it the cores on which the host runs, and do not share the "threads" of one kernel among different heavy VMs.
Memory#
- Hugepages (2 MB or 1 GB pages) reduce overhead for large VMs:
echo 'vm.nr_hugepages = 8192' | sudo tee /etc/sysctl.d/90-hugepages.conf # 8192 × 2 МБ = 16 ГБ
sudo sysctl --system
<memoryBacking><hugepages/></memoryBacking>
- Ballooning allows the host to take unused memory from the VM — convenient for test benches but not for databases.
- KSM (Identical Page Merging) saves memory for many identical VMs but consumes the processor and theoretically opens attacks through third-party channels — enable it consciously.
Discs#
virtio-scsiinstead ofvirtio-blk— if you need many drives and TRIM.- IOThreads offload the main VM flow during intensive input-output:
<iothreads>2</iothreads>
...
<driver name='qemu' type='raw' cache='none' io='native' iothread='1'/>
- For DBMS — raw or LVM,
cache='none', a separate volume for transaction logs.
Check the effect, don't take the word for it: fio inside the VM, virsh domstats db01, perf kvm stat on the host.
Device passthrough (PCI passthrough)#
The VM transmits the entire physical device: a graphics card for AI models, a 10G network card, an HBA controller.
- Enable VT-d / IOMMU in the BIOS.
- Kernel parameter. In
/etc/default/grub:GRUB_CMDLINE_LINUX_DEFAULT="intel_iommu=on iommu=pt"(AMD:amd_iommu=on iommu=pt), thensudo update-grub && sudo reboot. - Find the device:
lspci -nnand check the IOMMU groups (find /sys/kernel/iommu_groups/ -type l). - Add the device to Cockpit (Host devices) or
virt-xml db01 --add-device --hostdev 0000:41:00.0.
For network cards with SR-IOV , one physical card is divided into dozens of virtual functions — each VM gets its own.
Host security#
- The host is only a hypervisor. No websites, databases, or file balls on it itself.
- sVirt + AppArmor are enabled in Ubuntu by default: the process of each VM is isolated. Don't disable them "to make it work" — look for the reason in
journalctlanddmesg. - Management (SSH, Cockpit, IPMI) — on a separate network or VLAN, access via VPN.
- Host updates on schedule, reboot with VM stoppage or migration. Ubuntu Pro adds Livepatch — kernel update without reboot (part 7).
- VM disk encryption: LUKS inside the VM or an encrypted volume on the host.
- More details in the series "Information Security and Anti-Fraud."
Live migration#
Moving a running VM to another host without stopping — for hardware maintenance.
Conditions: identical (or compatible) CPU models for VMs, host access to each other via SSH, identical bridges (br0) and pools.
With shared storage (NFS, iSCSI, Ceph):
virsh migrate --live --persistent --undefinesource --verbose \
db01 qemu+ssh://kvm02/system
Without shared storage — the disk is also copied:
virsh migrate --live --persistent --undefinesource --copy-storage-all --verbose \
db01 qemu+ssh://kvm02/system
In older versions of libvirt, a disk file of the same size must be created in advance on the target host (qemu-img create). Disk copy migration congestion the network — a dedicated 10 Gbps network is better.
Cluster: when one host is not enough#
| Solution | What is | Cost of |
|---|---|---|
| Proxmox VE cluster + Ceph | web interface, HA, migration, backups | free, subscription — optional |
| oVirt / Oracle Linux Virtualization Manager | managing multiple KVM hosts | free |
| OpenStack | a private cloud with self-service | free, but you need a team |
| Pacemaker + Corosync | HA for VM libvirt "DIY" | free, difficult |
For a small company, a reasonable path is 2–3 hosts + Proxmox VE with shared storage or Ceph and a separate backup server. If there are two hosts, a third quorum vote is needed (QDevice on a small PC or VM).
The last part is about money: Linux and KVM, part 7: free or paid — subscriptions, support, commercial backups, and clouds.
Comments · 0
No comments yet.Sign in to comment, rate and see all comments.