VMware Communities
JamesBriant
Contributor
Contributor

"Starving" the Host OS

I understand that if a process in the VM is pegged at 100% on all CPUs, then the Host OS will be slow. But this is to be expected. When my real XP machine is pegged at 100%, other processes on it are slow. So that is not what I am asking about.

Its been suggested to me that having too many virtual CPUs can "starve"

the Host OS. That is, just having 2 virtual CPUs on my MBP that has two cores, can slow my machine down when I am running XP full screen, simply because the host is "starved". It was suggested that having just 1 virtual CPU would allow XP to run faster because the Host OS will always have 1 core to get work done.

Why? If the virtual machine has 2 CPUs, and needs, e.g. file IO from the Host OS, then the VM will block waiting for the IO, allowing the Host to do its work.

Or, is it the case that regular priority VM threads have a higher priority than Host threads or Host IOPs?

0 Kudos
4 Replies
JamesBriant
Contributor
Contributor

I have tested the hypothesis, despite not believing it, and it turns out to be true. With only 1 Virtual CPU, my VM is over three times faster for a simple operation that I do all the time (scrolling thru large files), than with 2 Virtual CPUS. Even operations which I know to be multithreaded (context-sensitive code completion) work faster and are more responsive with just 1 VCPU.

WTF?

0 Kudos
Mikero
Community Manager
Community Manager

The reason for this is that the Mac has to contend with Windows for CPU time when 2 cores are allocated to Windows.

Because Windows has 2 cores, the Mac has to wait until there's a free cycle to get it's request heard by the CPU.

Because those 'requests' are doing things that help running 2 operating systems at once, the result is the Mac doesn't have the resources needed to complete whatever cpu tasks it needs to at a speed which is reasonable, so it has to wait until the CPU has a free slot.

-
Michael Roy - Product Marketing Engineer: VCF
0 Kudos
JamesBriant
Contributor
Contributor

But why does it have to wait? How is the vmware process any different from any other process? Does preemptive multitasking just not work? I write realtime, multithreaded applications on various platforms with varying compute power (ARM chips, to 4 socket Nehalems, to 500 Node clusters), so I'm looking for some exact details.

For example, why is scrolling slower (3x slower) with 2 VCPU?

XP reads memory. Composes glyphs. Writes to GDI surface. VM Display driver prepares buffer and executes transfer to Host.

At this point, the VM can either a) wait for the GDI draw to complete or b) carry on multi tasking.

If a) then the VM is not taking cycles from the Host as it is waiting for an IOP to complete.

If b) then the VM should continue scrolling, asynchronously, and the scrolling should continue at the same rate with either 1 VCPU or 2 VCPU, the only difference being that actual display happens less frequently (we do this all the time in games where the render thread is decoupled from the logic thread).

So what am I missing?

0 Kudos
ehendrix
Enthusiast
Enthusiast

Hey James,

My understanding of this is that it mainly has to do that when you assign multiple vCPUs, any timeslice given to the VM has to be provided covering each vCPU with a physical CPU or core.

In other words, in have a dual-core CPU and thus 2 "cpus" and I assign 2 vCPUs to my VM. Whenever my Fusion is given a timeslice from the host, Fusion is ensuring it is getting 2 CPUs at the same time which means 100% of my available CPU power. During this timeslice that Fusion then has, Windows itself might not fully need that power. But since the OS is not made to run in a virtual environment it is from the point of view that it always has all CPUs available all the time. And while Fusion has both CPUs locked although possible not using it I have nothing left for OSX.

So:

Core1 Core2

OSX OSX OSX processes have both cores for use.

Fusion is requesting timeslice

Fusion OSX One core is still doing something for another OSX process, the other core has been grabbed by Fusion

Fusion is waiting to get the 2nd core.

Fusion Fusion Now both cores are assigned to Fusion and Fusion can tell the VM it has the CPUs.

VM VM This is the 1st time now that the VM can do something, the whole time before it wasn't able to do anything.

Note that now both cores are fully used thus nothing in OSX can actually run.

OSX OSX Timeslice for Fusion was done and now other processes in OSX can do something.

In the preferred world, Fusion would not need to wait to get 2 cores but instead only request to get the power from both cores when they are actually needed by the VM but this is not the case. There are other OSs out there that understand virtualization and are built knowing that the CPUs they have are virtual. They thus also do not require all CPUs to be available to them anytime they have a timeslice and they also try to optimize their load so that they minimize the number of CPUs they need and give back to the hypervisor any CPUs that are done doing any work before the timeslice is over. AIX is one of those OSs.

Hope this helps somewhat in explaining it. Now, if you have a 4-core system then you could provide 2-cores to the VM since that will still leave 2 cores for OSX to perform work. Note, that requests from your VM will most likely result in processes in OSX having to do work so if they do not need to wait for CPU from the VM but instead can already go and do the work.

0 Kudos