Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

VirtualBox, and possibly other VM software, allows the user to specify the number of CPUs exposed to the VM. In my particular case, I have a dual core CPU, with Windows 7 64-bit running natively, and Ubuntu 9.04 64-bit as the VM.

The help file suggests not setting this above the number of physical cores available. This makes sense. So, is it best allocating 1 or 2 CPU cores? Does this depend entirely on the native CPU load?

share|improve this question
up vote 3 down vote accepted

It entirely depends on what the guest OS is doing. In my personal experience a VM is running a single program (build server, trac server, SVN, etc) so there is no reason to set it above one.

A possible case may be if it's an end user on say a University that is using the guest OS as a throwaway (i.e. TAs) then maybe set it to higher than one.

share|improve this answer
So, in other words: for a temporary system, you may as well max out the CPU core quota; but for "normal" or typical use, set it to one core (so not to interfere too much with the performance of the host OS)? – sblair Aug 12 '09 at 21:04

You should never assign all your cores as vCPUs in a virtual machine.

If a VM requests any CPU time, VMWare has to allocate either all the vCPUs, or none of the vCPUs.

What this means is, on a 4-core system if you allocate all 4 cores, then only either the host, or the guest, can be allocated processor time, not both at the same time.

This will absolutally ruin performance in both environments.

Feel free to allocate an odd-number of cores (say, 3). It feels odd, but it's a totally legitimate option.

Generally I never allocate more than (n/2) vCPUs (in your case, 2) - but I'm normally allocating cores on servers with between 12 and 32 cores where you can allocate huge numbers of vCPUs without major impact.

share|improve this answer
this is the only answer thus far written with any degree of authority. thanks for sharing your experiences. – G-Wiz Apr 12 '12 at 15:57
-1: Not consistent with my experience. The VM is a process whose CPU time can be scheduled in the same manner as any other process on the host. You can adjust the priority of the VM process(es) on the host, and the system will balance the loads appropriately. – bwDraco May 1 '13 at 2:10
(continued) Let's say you have a 16-core server. An example configuration would be 4 VMs, each configured for 8 cores. While this may seem to be too many virtual cores, it allows individual VMs to scale better on heavier workloads. Should the combined utilization exceed the number of physical cores, the host will balance the loads accordingly. That's how virtualization can increase throughput and reduce costs--by making the most of the host hardware. – bwDraco May 1 '13 at 2:12
@DragonLord - this answer is over 2 years old on a question that's almost 4 years old, and might be based on outdated information. I am referring to "Strict Co-Scheduling" from ESX but I do not recall how old that information is, and I haven't kept up to date with how CPU scheduling has changed in the last few years. – Mark Henderson May 1 '13 at 2:58
@MarkHenderson VMware ESX stopped using strict co-scheduling since ESX 3 (2006?). It uses relaxed (or dynamic) co-scheduling, as does Hyper-V. – projectshave Feb 3 '14 at 17:51

The number of cores exposed to guest CPUs does not affect performance as much as you would like. It merely adjusts the amount of cores the guest CPU "sees".

Depending on how the emulator is set up, it could literally half the performance of the virtual machine, do nothing, or only impact the way the guest OS/applications split up their thread scheduling.

It's best to leave it to the default. If you encounter performance issues on the host PC, then you can simply adjust the process priority with the Windows Task Manager.

share|improve this answer

I'd trust the OS's scheduler and just set the VM to the # of physical cores, unless you Know that you always want the host to have a potentially idle core while you're busy in the VM.

share|improve this answer

This depends on what you want to do on the virtual machine as well as on the physical machine. If you need to use the virtual machine while the host operating system is being used for some other activity, it may be better to use two processor cores for the VM so that the host has two remaining if the VM is under full load. On the other hand, if you are working primarily on the VM, you can use all processor cores.

However, unless the guest can be expected to use all four cores at once, you can safely use all of them while continuing to work on the host OS. Remember that you can always adjust the priority of the VM process while it's running on the host operating system, and the system will balance the loads accordingly.

share|improve this answer
This is based on my experience with VirtualBox. As I am not familiar with VMware products, I may be wrong; if so, I'll delete this answer. – bwDraco Apr 21 '11 at 13:20

As Nate mentioned, as long as your VM will mostly serve running a single-threaded process, there is little reason to allocate more than one core.

However, if you plan to use it in a way that can benefit from more cores (multi-threaded program, many parallel programs, ..), the story is more complicated. I previously assumed that using half of your CPU's for your VM was a good idea. Turns out this is not always optimal.

The only way to make sure is to run benchmarks.. I don't know why, but in my Core2 Quad system (which has VT-x support, nested paging, ..), actually using 1 out of the 4 cores performs better than using 2 or more cores! I see this simply in start-up times of the VM, but also during compilation benchmarks.

With other hardware results are different. I also have an i7 with 8 cores, and performance seems to scale much better with the number of cores there (using 4 there happily).

My tip: benchmark a new hardware first.

share|improve this answer

yes, I'd also say that it depends. But I'll say what I prefer to do. At work I have a quad core CPU. So for my virtual image (win7), I've allocated two CPUs. That way, I can use both the host machine and the virtual machine at the same time, and they each have equal CPU resources.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .