Hyper-V Dynamic Memory – virtual machine memory usage and host memory demand do not make sense

hyper-vhyper-v-server-2012

I have a Hyper-V 2012 R2 server running a number of virtual machines with Dynamic Memory enabled. They all exhibit this behaviour, but here is an example:

One of the VM's is a Windows Server 2012 R2 guest, and it's not doing much. Basically sitting there idling. It was doing a lot of work (it had launched a number of processes which allocated a bunch of memory, used some CPU, and then quit), but has now completed.

Task manager inside the VM shows the following memory statistics:

  • In Use: 5.5 GB
  • Available: 302 MB
  • Committed: 5.6/6.9 GB
  • Cached: 299 MB

The "Memory Composition" graph says that 5629 MB is "In Use" by applications, drivers, etc (i.e. it's not being used as file system cache).
I've also run perfmon and the counters there line up with the task manager ones.

Switching to the list of processes in task manager inside the VM, there is nothing using anything close to 5 GB of memory. Summing them all up comes to well under 1 GB.

For more information, Hyper-V manager on the host system shows that this VM has

  • Assigned Memory: 706 MB
  • Memory Demand: 593 MB

This fits with the memory usage I get by summing up the process list in task manager in the VM.

So the question is:

Why does task manager inside my VM think that it is using 5.5 GB, when no processes appear to use this memory, and the Hyper-V host knows that it only needs 593 MB? What has happened?

Best Answer

The Integration Components you installed when you built your VM included a driver which removes memory from the VM when that memory isn't needed. The way it removes it is that it allocates it from the memory manager within the guest OS and then gives it back to Hyper-V. It then looks, from within the VM, like it's "in use" because it has been allocated. This is referred to generally as "ballooning" and most hypervisors can do it, and even some physical systems do this too, using memory compression engines in hardware.