Q. How does dynamic memory in Hyper-V in Windows 2008 R2 SP1 work?

John Savill

June 17, 2010

2 Min Read
ITPro Today logo in a gray background | ITPro Today

A. Windows Server 2008 R2 SP1will introduce a much sought after feature for Hyper-V, namely dynamic memory for virtual machines (VMs). In versions before SP1, a VM is assigned a fixed amount of memory that's allocated when the VM is turned on. With SP1, you can set an initial amount of memory for each VM and a maximum amount of memory that the VM can grow to. This is achieved through two technologies.

Dynamic memory addition is used to add more memory to a VM if it's deemed necessary and physical RAM is available in the Hyper-V host. Dynamic memory addition is supported for Windows Vista, Windows Server 2003, and later OSs. Note that while I'm saying dynamic memory addition, this isn't actually using the memory hot-add capability in the OS. Instead, the memory is added via a kernel enlightenment for the supported guest OSs that handle the addition of memory. If the guest OS doesn't support dynamic memory addition, it won't recognize the additional memory and may cause a problem, so don't use it.

When reclaiming memory, things are more complicated—dynamically removing RAM is far more complex and has a far more limited set of supporting OSs. So instead of removing memory from the VM, a kernel level device driver, known as a balloon driver, is used to request memory from the guest OS based on a target size set by the hypervisor.

For example, suppose the hypervisor wants to reclaim 200MB of memory from a VM, the hypervisor instructs the balloon driver to inflate to 200MB, which will cause the driver to request 200MB of memory from the guest OS kernel. When the memory is allocated to the balloon driver, the balloon driver notifies the hypervisor of the memory pages it has been allocated. Then the hypervisor can just release that memory from the VM assignment, because it can no longer be used by the rest of the guest OS. The following image illustrates this process.

From the guest's perspective, the amount of total physical RAM will show the high watermark of the memory allocated to the VM since it was booted. You can't see the balloon size from within the guest—you have to use performance counters in the parent partition.

One interesting data point on the Hyper-V approach is that Hyper-V actually tracks how much memory the VM should have to perform optimally and shows what percentage of it the VM has. This ideal memory is not just based on what the VM is trying to write to—it considers how the memory is being used, such as the amount used for caching.

About the Author

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like