2

i have question about KVM i could not find any satisfying answer in the net about.

Lets say i want to create 3 virtual machines on a host with 2 CPUs. I am assigning 1 cpu to 1 virtual machines. The other 2 virtual machines should be sharing 1 cpu. If it is possible i want to give 1 vm 30 % and the other one 70% of the cpu.

I know this does not make much sense but i am curious and want to test is :-)

I know that hypervisors like onapp can do that. But how do they do it?

hukachaka
  • 63
  • 1
  • 6

1 Answers1

3

KVM represents each virtual CPU as a thread in the host Linux system, actually as a thread in the QEMU process. So scheduling of guest VCPUs is controlled by the Linux scheduler.

On Linux, you can use taskset to force specific threads onto specific CPUs. So that will let you assign one VCPU to one physical CPU and two VCPUs to another. See, for example, https://groups.google.com/forum/#!topic/linuxkernelnewbies/qs5IiIA4xnw.

As far as controlling what percent of the CPU each VM gets, Linux has several scheduling policies available, but I'm not familiar with them. Any information you can find on how to control scheduling of Linux processes will apply to KVM.

The answers to this question may help: https://serverfault.com/questions/313333/kvm-and-virtual-to-physical-cpu-mapping. (Also that forum may be a better place for this question, since this one is intended for programming questions.)

If you search for "KVM virtual CPU scheduling" and "Linux CPU scheduling" (without the quotes), you should find plenty of additional information.

prl
  • 11,716
  • 2
  • 13
  • 31
  • Thank you very much. This helps me a lot :-) found much more things now :+1: – hukachaka Dec 04 '17 at 07:39
  • Can we adjust the sharing dynamically by the overhead of each VM? some VMs are just executing halt again and again so is there any mechanism to `steal` the CPU and assign it to another VM for a period of time? – tristone Sep 30 '22 at 06:42