0

I am trying to run multiple virtual machines on the same host using QEMU with KVM acceleration. I am also trying to get each virtual machine to run on a specific CPU cure. For example, I want to allocate two cores for VM0 and have it run exclusively on core 0 and core 1.

My current approach was to start qemu the following way and for each VM I want to start I call the command below. For example, if I want to start five VMs I would call qemu-system-x86_64 five times.

  taskset -c 0,1 \
  sudo qemu-system-x86_64 \
    -nographic -monitor none -serial stdio \
    -machine accel=kvm,type=q35 \
    -cpu host \
    -smp 2 \
    -m 2G \
    -snapshot \
    -device virtio-net-pci,netdev=net0 \
    -netdev user,id=net0 \
    -drive if=virtio,format=raw,file="base.img" \
    -drive if=virtio,format=raw,file="seed.img" \

I have two questions. First, is there a way to assign a CPU core to a VM using QEMU rather than taskset? I tried looking for a core mask or something of the sort in the QEMU documentation, but couldn't find anything. I am worried that any other processes that qemu-system-x86_64 spawns will also inherit the assigned cores and will share these cores with the VM. Maybe I don't understand QEMU properly, but I imagine that when you start the VM it can use the number of cores you assigned to it and because of taskset they will be pinned to the specified cores. But I think that QEMU also does a bunch of virtual machine monitor (VMM) stuff in the back. I don't really want those things to be pinned to the taskset cores and want the OS to schedule them freely. Is this what is actually happening?

Second, is this the best way to start multiple VMs with QEMU? Is there a coordinated way that you can tell QEMU to spawn 5 VMs or do you just have to manually call qemu-system-x86_64 each time? Does calling qemu-system-x86_64 every time lead to poor performance? Again, I am not sure if each call to qemu-system-x86_64 is spawning its own VMM stuff behind the scenes and this stuff is getting duplicated with each call, possibly consuming more resources than needed. Is there perhaps a QEMU daemon, like a central hypervisor, that does all that management behind the scenes and makes it so that each call qemu-system-x86_64 only handles stuff pertinent to that specific VM?

MUAS
  • 519
  • 1
  • 7
  • 20
  • 1
    If you want something less low-level than just running QEMU directly, have a look at virt-manager or something else based on libvirt. That is the "management layer" that has the support for things like running multiple VMs, pinning VMs to particular host CPUs, etc. If you run QEMU directly you have to do all that by hand, which can get a bit tedious. – Peter Maydell Sep 01 '23 at 16:13

0 Answers0