VirtualBox: Is it a bad idea to assign more virtual CPU cores than number of physical CPU cores

Hardware / OS / Software

Host: Linux Mint 18 Cinnamon 64-bit (fully updated); Kernel version 4.4.0-47-generic

Guest: Windows 8.1 Pro 64-bit (fully updated)

Processor: Intel Core i7-4700HQ, (6MB cache, 4 physical cores, or 8 using Hyper-Threading), CPU Benchmark

VirtualBox: Version 5.1.10 r112026 (Qt5.5.1)

Guest Additions: Installed and up-to-date

Benchmark Tool #1: WinRAR version 5.40 final 64-bit

Benchmark Tool #2: VeraCrypt version 1.19 final 64-bit


Preparation

In both cases I waited after boot until the CPU, RAM, disk drive are at stable near zero-point hits.


Method

  1. Cloning the original virtual machine to have two identical ones.
  2. I have, for the second pass, since the reboot disabled Antivirus pointed out at the bottom of this answer and updated WinRAR in both cases from a Beta to the Final version.
  3. I have done the same Preparation as pointed out earlier.
  4. The virtual machine ran in foreground, without any other CPU time hungry application running, I have disabled what I could for the purpose of the test not being influenced.
  5. To include potential caching inside or outside the system, I ran the same test twice consequently. The benefit being almost none.

Results

WinRAR

  1. 4 cores => 7.5 minutes (shorter time is better)

    WinRAR with 4 cores enabled

    WinRAR with 4 cores enabled, 1.5GiB processed in 7.5 minutes.

  2. 8 cores => 4.5 minutes (shorter time is better)

    WinRAR with 8 cores enabled

    WinRAR with 8 cores enabled, 1.5GiB processed in 4.5 minutes.


VeraCrypt

  1. 4 cores => speed 2.6 GiB/s (higher speed is better)

    VeraCrypt with 4 cores enabled

    VeraCrypt with 4 cores enabled, HW-accelerated AES (AES-NI) speed 2.6 GiB/s.

  2. 8 cores => speed 3.9 GiB/s (higher speed is better)

    VeraCrypt with 8 cores enabled

    VeraCrypt with 8 cores enabled, HW-accelerated AES (AES-NI) speed 3.9 GiB/s.


Conclusion

I could run as many tests as necessary. But I figure, if these two, one of which is rather complex compression test, the second being a set of rather complex encryption tests, what would be the point.

Both of the benchmarks show a marked difference. I see no reason to believe, that their results are inaccurate, as I followed a rather rigorous preparation and method, moreover these tests have taken place in RAM to rule out I/O bottleneck. From my standpoint, the warning mentioned in the question may apply to some conditions, but certainly not all of them. Having shared with you these pretty remarkable results, I am certain for you to agree with me, that this warning probably should not be taken so seriously on modern CPUs featuring Hyper-Threading with the latest VirtualBox version. One thing for sure: Don't take me for the word and test it under your own conditions, before you decide to apply this setting permanently.


New benchmark

Host + Guest: Linux Mint 19.2 "Tina" - Cinnamon (64-bit); both with kernel: 5.3.0-24-generic.

Processor: Intel® Core™ i7-7700HQ; 6 MB Cache, up to 3.80 GHz, 4 physical cores, or 8 using Hyper-Threading, CPU Benchmark comparison

VirtualBox: Version 6.1.0 r135406 (Qt5.9.5)

Guest Additions: Installed and up-to-date

Benchmark Tool: VeraCrypt version 1.24 Hotfix1 64-bit final (web page, direct deb download link)


Preparation and Method

Same as previous benchmark.


Results

VeraCrypt AES encryption with 4 cores

⟶ speed 4.8 GiB/s (higher speed is better)

VeraCrypt AES encryption 4 cores = speed 4.8 GiB/s


VeraCrypt AES encryption with 8 cores (Hyper-Threading warning issued)

⟶ speed 7.2 GiB/s (higher speed is better)

VeraCrypt AES encryption 8 cores = speed 7.2 GiB/s

Conclusion

Wonderful 50% performance increase with Hyper-Threading enabled, but only with the AES sadly, I will have to run some more comprehensive test. Will be back in a few days with results.


As an OS designer I completely agree with the result of the measurements. The amount of bullshit produced elsewhere about the subject matter is unbelievable.

See the number of logical cores as the number parallel threads/processes that can be executed by the HW. That is achieved by duplicating e.g. the registers and instruction pointers of a CPU core. The CPU core itself now decides which thread (instruction pointer) to use. It will decide to use the other thread as the instruction of the current thread is not available in the cache and need to be fetched from e.g. memory or L3 cache. This mechanism will create a 10%-30% potential improvement in instructions/seconds or CPU performance.

If you run a single application with one thread, you will not be able to reap this benefit, but if you run two high load applications on e.g. an old HT Pentium, you will be able to reap the benefits. The same is true of course for applications, that have more then one thread. My Linux system has 200 threads, so some benefits dependent on the actual load are always present. All these remarks apply without virtualization.

Virtualbox only limits the number of threads that can run in parallel for each virtual machine (VM), but the host process scheduler will change the logical processor(s) and thus physical processor(s), on which the VM processes run dynamically. If you run a high load applications on a VM, the additional logical cores will give you the same benefit of 10%-30%. The load can be a single multi-threaded application or a set of different applications.

On modern systems with VT-x or AMD-V there is no performance penalty for maxing out the number of logical cores, since there is also no noticeable performance penalty for running more virtual machines at the same time. Your limit is the performance of your CPU chip, so you can't render videos on 3 VMs at the same time without slowing down each VM, because they have to share the same physical CPU.

Your host system might become irresponsive, if you render a video on a VM with all logical cores present, but you would have almost the same problem, if you did run that rendering app on your host. At least in VM you have a choice and you could solve it by limiting the max CPU load to 80%-90% or by reducing the number of cores for this reason.