question about CPU allocation and usage

Discussions related to using VirtualBox on Windows hosts.
Post Reply
ljwobker
Posts: 5
Joined: 4. Dec 2014, 03:34

question about CPU allocation and usage

Post by ljwobker »

Host machine is windows7, i7-4600U, 2 cores/4 threads @ 2.1Ghz, 12GB of memory.
Guest machine is (in this case) Ubuntu 14.04.1.

I've followed the advice given here and allocated only 2 CPUs to the guest, but when I run CPU intensive applications (such as compiling code with jobserver working) I've noticed that the guest CPU shows two cores, both running at/near 100% during the build. However, on the host machine the CPU utilization is only reported as ~50%.

This implies, at least to a casual observer, that the guest machine is only getting access to half the processing power of the host. But if you change the number of CPUs to four, the guest machine now sees all four, and the host machine now runs at near 100% CPU during builds.

That said, the compile times on my (somewhat limited) build aren't substantially faster - if that many cycles are indeed being wasted, where are they going?
loukingjr
Volunteer
Posts: 8851
Joined: 30. Apr 2009, 09:45
Primary OS: Mac OS X other
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: just about all that run

Re: question about CPU allocation and usage

Post by loukingjr »

If you aren't doing much on the host you could try assigning 3 cores to the guest and see if compile times are faster.
OSX, Linux and Windows Hosts & Guests
There are three groups of people. Those that can count and those that can't.
scottgus1
Site Moderator
Posts: 20945
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Windows, Linux

Re: question about CPU allocation and usage

Post by scottgus1 »

ljwobker wrote:Host machine is windows7, i7-4600U, 2 cores/4 threads . . . if you change the number of CPUs to four . . . the compile times on my (somewhat limited) build aren't substantially faster
It sounds like you are proving the scuttlebutt around here that hyperthreading doesn't help when counting cores for guests. Hyperthreading is supposed to allow two dissimilar threads to get through the core at the same time if they use different parts of the core guts. If the two threads being assigned to two hyperthreading channels on one core are too similar, one thread will have to wait for the other to get done before it can run through, since they both need the same parts of the core to calculate.

Quite likely the processing being done by your program is rather similar on each thread, so hyperthreading can't really work as good as it claims it can, and your times aren't getting much better.
loukingjr
Volunteer
Posts: 8851
Joined: 30. Apr 2009, 09:45
Primary OS: Mac OS X other
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: just about all that run

Re: question about CPU allocation and usage

Post by loukingjr »

Just to add, unless the OS and/or the application that's being run is optimized to multi-core/hyperthreading it really isn't much of an advantage. It's similar to the 32bit vs 64bit argument.

An exaggerated analogy woud be, adding 2+2 on an Intel i7 is not going to be all that much slower than on a Cray if at all.
OSX, Linux and Windows Hosts & Guests
There are three groups of people. Those that can count and those that can't.
mpack
Site Moderator
Posts: 39134
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Mostly XP

Re: question about CPU allocation and usage

Post by mpack »

Basically, it's a marketing scam. It's like Ford saying "hey, we put two engines in a car, it now has twice the horsepower!" - so the buyer will expect the car to go twice as fast, right? There's so many things wrong with that logic that it's hard to know where to start.

Returning to CPUs: my understanding is that every time context is switched between host and VM, the CPU context has to be saved and restored, which is relatively slow. If you allocate multiple CPUs then multiple contexts need to be swapped. If the app isn't actually designed for multiprocessing then it won't benefit, but it still has the switching overhead. Result: the VM gets slower as you add CPUs, not faster.
Post Reply