I'm running virtualbox on windows 10 with an i5-9300H, which is 4 cores and 8 threads. On virtual box setup, the its only recommending 4 CPUs though it allows up to 8. I believe the virtual cpus are simulated, although my question is, if increase the number of CPUs to 6, will it affect performance of host or guest? I'm running lubuntu 20.10 as guest for doing Linux From Scratch project, so to compile the kernel, I believe more cores the better(please correct me if I'm wrong).

  • 1
    You won’t damage anything. So I suggest you just try to find out what works best. With compiling, this is relatively easy. Just time it and compare. – Daniel B Nov 25 '20 at 10:43

No, in VirtualBox virtual CPUs are not simulated. CPU emulation is terribly inefficient, a modern OS would be unusable on an emulated CPU. Your CPU actually has built-in support for virtualization, ie. running code as if it wasn't a virtual machine, but in an environment controlled by host's code. So when you're setting how many cores are available to the VM, you're actually giving it access to real logical cores of your CPU.

VirtualBox is recommending assigning only 4 logical cores, because there are only 4 physical cores in your CPU. Assigning more logical cores than physical cores would supposedly offer worse performance than 4 cores only. Whether that's actually a case or not for your use case, you have to test yourself. The answer may depend on the architecture of your CPU, host's scheduler, guest's scheduler and possibly other factors.

Having more cores is usually better than having less identical cores, unless this leads to the scheduling machinery working sub-optimally (for example if it makes wrong assumptions about what's optimal for that CPU configuration). There are known cases where disabling SMT (splitting physical cores into multiple logical cores) may improve performance.

  • So, why does I see 8cpus when I run htop command on lubuntu directly on the same computer and only 4 cpus when running a vitrual machine with 4 physical cpus assigned in virtual box? – ASWIN VENU Nov 25 '20 at 11:13
  • Your question contains the answer. You have assigned 4 cores to the VM, therefore the VM sees 4 cores. That's what that setting does. – gronostaj Nov 25 '20 at 11:23
  • Yeah but why does the fact that that one core has two threads don't show on VM, but on natively running OS? – ASWIN VENU Nov 25 '20 at 11:25
  • 2
    You're assigning logical cores, not physical cores. That's why the slider goes up to 8 even though you have 4 physical cores. – gronostaj Nov 25 '20 at 11:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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