The Blown Light Bulb

Information worth to share...


How to use Dynamic Memory in Hyper-V 3

One of the coolest features enhanced in Windows Server 2012 is going to be Hyper-V Dynamic Memory. It allows you to better use existing resources and consolidate more virtual machines in less Hyper-V hosts. This can lead to lower costs, especially in environments that have many idle or low-load virtual machines.

Dynamic Memory lets you distribute virtualization host physical memory across more virtual machines by taking advantage of this dynamic assignment. Virtual machines just require all assigned memory when booting and during high-load, but not during idle periods. This is where Hyper-V reassigns not needed memory allocating it to other virtual machines.

The following capture shows Dynamic Memory setting for a virtual machine, that can be accessed in VM Settings > Memory. It basically lets you set a Maximum RAM and a Minimum RAM which are the maximum memory that a virtual machine can use from the Hyper-V host and the minimum memory that should be assigned when the VM is idle.

Other parameters in that section, Memory buffer and Memory weight, are used by the Hyper-V host to reserve a certain amount of memory and set the appropriate priority to the virtual machine.

But, what happens when you restart the Hyper-V host or a virtual machine and you have set up your VMs with more memory than physically available? 

Windows Server 2012 also introduces Smart Paging feature and it is used to bridge the memory gap between minimum memory and startup memory, and allow virtual machines to restart reliably.  It will temporarily provide additional memory to the virtual machine, but to minimize the performance impact of Smart Paging, Hyper-V uses it only when all of the following occurs:

  • The virtual machine is being restarted.
  • There is no available physical memory.
  • No memory can be reclaimed from other virtual machines running on the host.

…but it is not used when:

  • A virtual machine is being started from an “off state” (instead of a restart).
  • Oversubscribing memory for a running virtual machine is required.
  • A virtual machine is failing over in Hyper-V clusters.

A Smart Paging file is created (by default) in each VMs’ storage location and path can be seen under VM Settings > Management > Smart Paging File Location.

To further reduce the impact of Smart Paging, Hyper-V removes memory from the virtual machine after it completes the start process. It accomplishes this by coordinating with Dynamic Memory components inside the guest operating system (a process sometimes referred to as “ballooning”), so the virtual machine stops using Smart Paging. With this technique, the use of Smart Paging is temporary and is not expected to be longer than 10 minutes.

Dynamic Memory with PowerShell…

Using PowerShell you can take advantage of some of the cmdlets available for managing Hyper-V. If you want to perform what we have exposed previously you can use the following commands:

Get-VM –ComputerName

Set-VMMemory –VMName ‘Your VM name here’ -DynamicMemoryEnabled $true -MaximumBytes 1GB -StartupBytes 1GB -MinimumBytes 512MB

If you want to activate Dynamics Memory in all your VMs you just need to combine the two cmdlets above in one:

Get-VM | Set-VMMemory -DynamicMemoryEnabled $true -MaximumBytes 1GB -StartupBytes 1GB -MinimumBytes 512MB

You can check your VMs memory configuration by running the following command:

Get-VMMemory -VMName ‘Your VM name here’

If you are interested to learn more about Windows Server 2012 I recommend you to read Free Windows Server 2012 Resources Available for Download.