Quad Core host with hyper-threading, how many processors to configure in VirtualBox?
I have a quad-core i7 processor with hyperthreading (8 logical cores), when I configured a virtual machine to use 8 processors, VirtualBox gave me a warning saying that I only have four cores (which is true) and that this may cause a performance issue. But hyper-threading is a hardware feature, so the OS sees 8 cores and it sends instructions to all 8. What if setting it to 4 caused the VM to use 2 cores (4 threads) instead of 4 simultaneous threads (on all 4 cores)? Does the warning I got take into account that my machine has hyper-threading?
Based on the benchmark done by Kristian Wedberg I would say you should use all logical cores you have.
Also I did my own benchmark using same CPU (i7, 4 CPU with HT) which confirmed performance boost for multi-threaded applications. If guest PC (Win. 8.1 x64) used all 8 cores, then host PC (Ubuntu x64) also used all 8 cores.
I compared also performance in single-threaded applications. In both cases I measured same values so there is no penalty using more than physical (but up to logical) number of CPUs.
Here you can see that 1 CPU full load in guest PC will result to 1 CPU load in host PC.
I found that even though it is possible (and arguably faster) in VirtualBox (my experience was with version 5.1.0) to allocate vCPUs to a VM based on logical processors, one may run into problems inside the guest OS when running at high load. In my case a Windows 2012 R2 VM with 12 vCPUs on a 8 core Ubuntu 16.04 host (that reports 16 logical processors) would BSOD during high CPU load with the DPC_WATCHDOG_VIOLATION error message. A minidump analysis using osronline.com showed e1g6032e.sys (the Intel 100/1000 network driver native to Windows) to be the cause of the violation.
This leads me to believe that timing inside the guest OS is negatively impacted when allocating vCPUs based on logical processor capacity and running the VM at high load for prolonged periods. In my case, 100% CPU load inside the Windows VM for a few minutes would result in the BSOD. After reducing the vCPU count to 8 (which corresponds to the physical core count of the host), the Windows VM does not BSOD anymore under similar high load situations. The online documentation from VirtualBox says one should do this, but does not offer any reasons.
In my environment there were also two other Ubuntu VMs running, each with 8 vCPUs of their own. The load on them was however minimal at the time of the Windows VM's BSOD problems.
Does the warning I got take into account that my machine has hyper-threading?
Yes. If you set the number of cores in a VM to greater than the number you physically have, the task scheduling process in Virtual Box over commits the CPU resources, leading to major performance issues.
As to distributing the load across cores, that is the host OS's job, and should behave in the correct manor.