Hyper-V Series: Configure Dynamic Memory

Hyper-V Server

New chapter about Hyper-V Series, the articles dedicated to Hyper-V configuration. In this new article, we will talk again about memory and in particular about Dynamic Memory.

Dynamic Memory

Starting from Windows Server 2008 R2 SP1, Microsoft has introduced a new interesting feature to manage better the virtual memory, called Dynamic Memory, that allows to set a minimum and maximum range that the virtual machine can use.

The idea was very easy: why I should waste the resources where are not used? Why I should assign 3GB of vRAM for a File Server also in the late night, where no one use it?

An Operating System, and the software inside too, able to manage dynamic the memory allows to optimize resources and avoid over-provisioning. This, in bundle with Dynamic Optimization solutions, are able to consolidate the virtual machines into a single host where the requests are not too high.

Another good scope behind DM is the possible to create density of Virtual Desktop Infrastructure (VDI) virtual machines, thanks a CPU Ratio of 12:1. The result is set a minimum value to support Windows and a maximum value to support particular workload but the final goal is avoid the usage of unused memory when the static mode is configurated.

Manage Dynamic Memory in Hyper-V

To configure DM in Hyper-V is necessary open the settings of each virtual machine, as showed in figure 1.

Figure 1 – Set Dynamic Memory

The available values are 5:

  • Startup RAM: quantity of memory to allocate when the virtual machine startup or rebooted. This value cannot be less then Minimum RAM.
  • Minimum RAM: quantity of memory to allocate when the virtual machine is unload. This value cannot go under the operating threshold to run operating system.
  • Maximum RAM: quantity of memory to allocate when the virtual machine requires the maximum performance.
  • Memory Buffer: this value occurs more quickly in response to a virtual machines increased demand. The percentage can be set from 5 to 200% (20% is the default value). This value must be managed very carefully to avoid over memory allocation.
  • Memory Weight: is the priority of the virtual machine compared to other.

Memory Buffer

How I can calculate the buffer? Easy: memory demanded from VM + memory buffer value (es. 4GB (memory demand) + 800MB (memory buffer at 20%) = 4.8GB). In this example the memory allocation into the host will be nearly 5GB.

The figure 2 show a Task Manager of virtual machine, where we can see the memory usage and the cache area.

Figure 2 – Task Manager

To check the information, it’s possible open the Hyper-V console and view the details of virtual machine, as showed in figure 3.

Figure 3 – VM Parameters

If the memory demand is 3.3GB, the buffer will be 700MB. The reason why you could see a different value is because Hyper-V correct this to prevent problem and for internal process.

Now, what we have seen should open eyes and give us more knowledge about buffer configuration to prevent wrong configuration. In case we have virtual machines with high memory usage could be better set the Memory Buffer to 10%, to prevent the pre-allocation of entire host memory. For all those VM with a classic memory usage, the default percentage could be a good idea but it’s possible change the value in some scenarios (like web server with limited high memory request).

Maximum Memory

It’s very important define this value and not leave the default quantity because is 1TB! Set the right value allows the virtual machine to works better, reduce the unused memory and gives more breath to Hyper-V.

Add Hot Memory

Can I add memory to my VM on the fly? Yes and no. No for Startup Memory and Minimum Memory, yes for Maximum Memory but only to increase the value. Is not possible reduce the maximum memory available when the machine is running.

Workload and Scenarios

If you plan to use Dynamic Memory for all of your virtual machines could be better take a moment, because the solution is not perfect for all products or scenarios and read the vendors documentation is fundamental.

Some Microsoft products don’t support Dynamic Memory like Exchange Server and SharePoint Server, because the continuous up-down reduce the performance; by the other side, SQL Server supports DM since 2008 R2 but this not means that is the perfect idea for your environment. Again, read the documentation gives you all the information about the deployment.

PowerShell

To visualize, in one shoot, the configuration of all virtual machines with Dynamic Memory enabled, you can use this cmdlet: Get-VM | where DynamicMemoryEnabled -eq $true | ft Name, MemoryAssigned, MemoryMinimum, MemoryMaximum, MemoryDemand

Conclusion

Using Dynamic Memory correctly has a bit of an art component. You can certainly use your monitoring system to plot very scientific values, but you’re going to invest a lot of time doing so, and it is highly likely that something will change before your task is complete. You can develop shortcuts to make your life easier.