What Is Hyper-V Dynamic Memory?
Windows Server 2008 R2 (W2008 R2) SP1 introduced a feature to Hyper-V called Dynamic Memory. With this feature enabled a virtual machine optimize how is consumes memory from a host. With Dynamic Memory enabled you can increase the virtual machine to host ratio and reduce your overall cost of host acquisition and ownership.
Hyper-V Without Dynamic Memory
If you deploy Hyper-V virtual machines without Dynamic Memory enabled, each virtual machine will attempt to boot up and consume 100 percent of its configured RAM from the host. So, a virtual machine configured with 16 GB of RAM will consume all of that 16 GB, even it will average at 4 GB and only reach 16 GB at peak periods. Ninety percent of the time, 12 GB RAM will be wasted and unavailable to other virtual machines.
That was the way Hyper-V was before SP1 was released for W2008 R2 and Dynamic Memory was added to Hyper-V. After that we could configure a number of settings on a per virtual machine basis, assuming that both the guest OS and the services running in that virtual machine would support it. Before Windows Server 2012 R2 (WS2012 R2) Linux did not have support for Dynamic Memory (check this post on “Linux Virtual Machines on Hyper-V” for distribution, edition, and architecture specifics). The mailbox role of Microsoft Exchange does not support Dynamic Memory, and pre-2012 versions of SQL Server below the Enterprise edition cannot make use of it either.
Dynamic Memory Overview
With Dynamic Memory enabled, a virtual machine will boot up with a small amount of RAM, and will consume RAM as required from the host. In WS2012 and WS2012 R2 there are a number of settings that are configured on a per-virtual machine basis:
- Startup RAM: This is the amount of memory that a virtual machine is configured to start with. If a virtual machine has 1024 MB startup RAM then it will consume 1 GB RAM from the host upon startup. Note that when you log into the guest OS and run any performance tools, you will only see 1024 MB RAM until more RAM is assigned. For Windows, this should be at least 512 MB, but that should be enough to get your guest OS and essential services operational.
- Minimum RAM: This is the amount of memory that a virtual machine can shrink down to. Note that Windows 8 and Windows Server 2012 (WS2012) need 512 MB to boot, but they can run on less than 300 MB when idle!
- Maximum RAM: This defines how much RAM a virtual machine can expand to. This is 1 TB by default, but is normally set to a more realistic amount to avoid waste. Using the previous example of a virtual machine requiring 16 GB for peak usage, you would set it to 16384 MB if enabling Dynamic Memory.
- Memory Buffer: This is a percentage of spare RAM that is assigned to the virtual machine. It is used to service instant demands for more RAM. A Windows guest OS will also use it for caching when memory is not under pressure.
- Memory Weight: A slider defines the importance of this virtual machine. Virtual machines will a higher priority have a better chance of getting more RAM than virtual machines with a lower priority when there are limited resources available on the host.
Strictly speaking, there are no-one-size-fits-all strategy for Dynamic Memory. For example, there is specialist guidance for SQL Server. A virtual machine that is running the Exchange mailbox role shouldn’t use Dynamic Memory. If you are deploying virtual machines by hand then you should tweak the setup. If you are using System Center Virtual Machine Manager (SCVMM or VMM), then you should have different hardware profiles and virtual machine templates to suit your needs.
In my environments I typically set the startup RAM to 1024 MB. That’s enough to install SQL Server; remember that a guest OS only sees what it starts up with unless more memory has been assigned. I’ll set minimum RAM for something small like 128 MB. Maximum RAM is set to whatever the peak demand is for the service or application that will run in the guest OS. And I normally leave memory buffer at 20 percent. However, I will change that to 5 percent for SQL Server VMs.
Be sure to check back here on Petri IT Knowledgebase, as I’ll write some more posts on Dynamic Memory over the coming weeks to explain in more depth how this Hyper-V feature works.