Dynamic Memory in the upcoming Hyper-V R2 Service Pack 1 removes the guesswork from memory allocation. While VMware's memory overcommit feature assigns virtual memory automatically, Hyper-V Dynamic Memory lets you adjust virtual memory settings. This flexibility provides important constraints for the host and enables you to allocate memory with greater precision and ease.
With Hyper-V Dynamic Memory, the host automatically rebalances memory among virtual machines (VMs) on a moment-by-moment basis. Memory is pooled on one physical host, then it is dynamically distributed to VMs as necessary. But there's a problem with this memory allocation: Hyper-V assigns the memory in one-second intervals.
In computer time, one second is a remarkably long period. In a second or two, a VM's memory requirements can change drastically. During this interim, a host can remove memory from a VM that suddenly requires more. For this reason, Hyper-V Dynamic Memory includes virtual memory settings -- known as Memory Buffer and Memory Priority -- to control a host's behavior and improve virtual memory management.
The Memory Buffer setting provides a VM with greater memory capacity than it needs. The Memory Priority setting allows you to indicate which VMs should receive memory first if a shortage occurs. You can find both controls in the virtual memory settings of any VM in the box marked Memory Management.
The Memory Buffer setting
The Memory Buffer is essential to Hyper-V's virtual memory settings. It reserves additional space on each VM. The machine uses this space if RAM requirements change between one-second intervals. Without a buffer, an increase in memory requirements during this mere second automatically forces a VM into an out-of-memory condition and memory pages are swapped to disk. But you don't want swapping to disk to happen -- ever. It drastically drains performance as the computer converts high-speed memory data into comparatively low-speed disk data.
The Memory Buffer setting is configured on a per-VM basis. Memory Management features a slider for increasing and decreasing the percentage of memory that's reserved as a buffer. This additional memory scales with whatever amount a Hyper-V host has assigned to that VM at that second.
So, for example, let's say you configured a VM to reserve 10% of memory as a buffer. Let's also say that at a particular moment this VM reports that it needs 1,000 MB of memory. In this case, the Hyper-V host actually assigns 1,100 MB to the VM. A few seconds later, a VM might report that it now needs 1,500 MB of memory. Then, the Hyper-V host will assign it 1,650 MB. Remember, a host reserves memory according to whatever percentage you assign in virtual memory settings.
Obviously, adding more reserved memory decreases the chance that a VM needs to swap to disk should a change in memory requirements occur. At the same time, a larger buffer results in wasted memory. The reserved memory is always available, so it sits unused unless a VM needs it. The setting lets you reserve anywhere from 5% to 95%, giving you a wide range of options. A good rule of thumb for this virtual memory setting is to start small. You can always inch the slider upwards if you observe your VM regularly swapping to disk.
The Memory Priority setting
Another important tool for virtual memory management is the Memory Priority configuration. Hyper-V Dynamic Memory constantly rebalances the memory, but sometimes there's not enough memory to meet every VM's needs. Perhaps you powered on one too many machines. Or a VM might suddenly need a huge amount of memory to process a certain thread.
When such memory contention occurs, the Memory Priority setting allows you to prioritize VMs. You essentially give Hyper-V an ordered list of VMs from which it should pull memory first. Lower-priority VMs lose memory before higher-priority VMs during memory allocation.
If the host consults this virtual memory setting, that means you're in a low-memory situation. The host consults Memory Priority only when the total memory available for distribution has run out. So the vast majority of the time, Hyper-V won't consult it. But if it does, any VM that has its memory reduced will be forced to page to disk, which significantly reduces performance. You should organize this list to protect your highest-priority VMs, but also configure your Hyper-V hosts so that they don't need to use Memory Priority much, if at all.
These virtual memory settings can ease virtual memory management and help troubleshoot memory contention problems. You can play with the Hyper-V Dynamic Memory settings to determine which configurations best fit your memory allocation needs.
Greg Shields is an independent author, instructor, Microsoft MVP and IT consultant based in Denver. He is a co-founder of Concentrated Technology LLC and has nearly 15 years of experience in IT architecture and enterprise administration. Shields specializes in Microsoft administration, systems management and monitoring, and virtualization. He is the author of several books, including Windows Server 2008: What's New/What's Changed, available from Sapien Press.