Over the course of a day, the amount of memory that my desktop uses for applications at any given moment varies greatly. When I’m browsing the web reading the news, it’s very low. But when I open a large document at the same time as I’m running several other applications, the amount of memory used shoots up. Servers typically have the same changes in resource utilization over a given period, with peaks and troughs.
For a physical server, the highest possible memory utilization must become the amount of memory installed into the server. The result is large amounts of memory wasted during non-peak times. Virtual environments are different, particularly when cohosted workloads have peaks at different times than other workloads.
Windows Server 2008 R2 Service Pack 1 (SP1) introduced a major new capability to Hyper-V: Dynamic Memory, which was enhanced in. Prior to Dynamic Memory, the amount of memory that was specified for a virtual machine (VM) was all allocated to the VM on startup. As for a physical server, this amount needed to be based on peak memory requirements, which often meant a large amount of wasted memory. But Dynamic Memory enables you to specify a startup amount of memory, a minimum amount of memory, a maximum amount of memory, and a buffer percentage for a VM, as the following figure shows.
When the VM first starts, it is allocated the Startup RAM. Hyper-V then monitors the working set of the guest OS that is running inside the VM. Essentially, this is the amount of memory that processes are actually using. If Hyper-V sees that the amount of memory that processes are using increases and is consuming memory from the memory buffer allocated to the VM, and if sufficient memory is available in the Hyper-V host, then additional memory is added to the VM. If the amount of memory that processes are using drops, then memory can be reclaimed from the VM by using something called a balloon driver. A balloon driver allows the guest OS to decide what memory it no longer needs. The reclaimed memory can be made available for allocation to other VMs.
Memory can be reclaimed down to the minimum value that is defined for the VM. Many people ask me the purpose of the Startup RAM and Minimum RAM values. It’s fairly common for some OSs to require a certain amount of memory to start up. But most don’t need all that memory after initializing. By having a Minimum memory value that is smaller than the Startup value, a VM can have an amount of allocated memory when it starts and that memory can be reclaimed when it is no longer needed. The memory buffer is used because allocating memory after the guest OS is already out of memory is too late. By specifying an available buffer amount the VM has an amount of additional memory available beyond what processes currently require. Hyper-V can add memory to a VM before the currently allocated memory is completely exhausted.
Dynamic Memory works with Windows and many Linux distributions. The legacy approach to memory optimization for virtual environments was to allocate large amounts of memory and hope that the VM did not use it all. However, modern Windows and Linux OSs typically use all available memory, if only for caching purposes. That’s why Dynamic Memory focuses on the memory that is used by actual processes: to make optimal use of it.
Dynamic Memory works with nearly all application workloads. Certain workloads that have their own memory-optimization mechanisms, such as SQL Server and Java, have Dynamic Memory configuration recommendations. Make sure to check the Dynamic Memory guidelines for application-specific information before you implement the feature.
By using Dynamic Memory, you can enable a higher density of server workloads, without compromising performance. In addition, you can use System Center Virtual Machine Manager (VMM) to enhance functionality. Use Dynamic Optimization to automatically move VMs between hosts in a cluster if resource utilization is uneven and specific hosts are becoming resource constrained.
If Hyper-V Dynamic Memory sounds as good to you as it does to me, you can learn more at the Microsoft Windows Server 2012 R2 Virtualization page at http://www.microsoft.com/en-us/server-cloud/solutions/virtualization.aspx.