Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm a relative late comer to the virtualistion party, so you'll have to forgive me if this seems like an obvious question.

If I have a server with 12 cores available, does each KVM guest have access to all 12 cores? I understand KVM makes use of the Linux scheduler, but that's where my understanding of "what happens next" ends.

My reason for asking is, the 10 or so distinct tasks we are intending to run in KVM guests (for purposes of isolation to facilitate upgrades) won't utilise a single core 100% of the time, so on that basis it seems wasteful to have to allocate 1 virtual CPU to each guest - we'll be out of cores from the get-go with a "full", idle server to show for it.

Put another way, assuming my description above, does 1 virtual CPU actually equate to 12 physical cores in terms of processing power? Or is that not how it works?

Many thanks

Steve

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

A virtual CPU equates to 1 physical core, but when your VM attempts to process something, it can potentially run on any of the cores that happen to be available at that moment. The scheduler handles this, and the VM is not aware of it. You can assign multiple vCPUs to a VM which allows it to run concurrently across several cores.

Cores are shared between all VMs as needed, so you could have a 4-core system, and 10 VMs running on it with 2 vCPUs assigned to each. VMs share all the cores in your system quite efficiently as determined by the scheduler. This is one of the main benefits of virtualization - making the most use of under-subscribed resources to power multiple OS instances.

If your VMs are so busy that they have to contend for CPU time, the outcome is that VMs may have to wait for CPU time. Again, this is transparent to the VM and handled by the scheduler.

I'm not familiar with KVM but all of the above is generic behavior for most virtualization systems.

share|improve this answer
    
Warning: Do your research before blindly assigning tons of vCpu's. You might end up oversubscribing, wich leads to CPU blocking. –  pauska Sep 20 '11 at 8:17
    
Ohya. I didn't include that because I wasn't sure it was true for KVM. This is where if you assign 4 vCPUs, the scheduler had to wait for 4 cores to be free, before allowing any CPU time to a VM even if it only needs one core for the current operation? –  Chris Thorpe Sep 20 '11 at 8:30
    
I'd be surprised if there is no overhead with KVM if you assign every VM lots of vCpus.. but hey, I'm a vmware guy :-) –  pauska Sep 20 '11 at 8:39
    
Great help, thanks guys :-) –  Steve Sep 20 '11 at 22:56
add comment

a virtual CPU is a thread in the qemu-kvm process. qemu-kvm is of course multithreaded.
unless you pin processes to specific CPUs, the system scheduler will allocate the threads CPU time from the available cores, meaning, any vCPU can end up getting CPU cycles from any physical core, unless specifically pinned to specific core(s)

share|improve this answer
    
Thanks, one question: does it bring performance benefits if we assign a vCPU to a CPU Core? –  Zim3r Sep 18 '12 at 9:20
    
If you specifically spread loads manually, you will probably underutilize the resources, but if done right, this can help increase performance. Especially if you also do the pinning according to numa nodes –  dyasny Sep 18 '12 at 9:23
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.