In a previous post I introduced Dynamic Memory, a Hyper-V memory assignment optimization feature. Today I will explain how Dynamic Memory works. Armed with this understanding, you will be able to better configure your virtual machines to make the best use of your host’s memory.
Dynamic Memory and Startup RAM
If you have configured a virtual machine with Dynamic Memory, then the virtual machine will boot up with just the configured amount of startup RAM. Initially the guest OS will not be able to see anything more than that amount of RAM.
For example, say you want a virtual machine to boot up with 768 MB RAM. That virtual machine will boot up, and if it is idle, the guest OS will think there is just 768 MB RAM. You can log into the guest OS, run Performance Monitor and open Task Manager and see just 768 MB RAM.
This is a situation where you should add a question/answer to the FAQ of any support portal of a true cloud that features self service. Any tenant who is “paying for 8 GB RAM” will be upset to see just 768 MB and is likely to open an angry helpdesk ticket (or is that one of those “helldesk” tickets?).
There is another consideration: Just about any server software you want to install will check whether you have enough RAM present before allowing the setup wizard to continue. SQL Server is a perfect example, because it is a prerequisite for so much! SQL Server will want to see at least 1024 MB to allow an installation. If it sees just 768 MB then the setup will fail without some intervention on your behalf.
Tip: I normally set my startup RAM to 1024 MB just because of this reason.
The virtual machine will be assigned the amount of RAM plus the Memory Buffer percentage. So, if a virtual machine requires 1000 MB RAM and there is a buffer of 20 percent, then 1200 MB will be assigned.
Increased Memory Pressure and Dynamic Memory Requirements
As the loads inside a virtual machine increase, Hyper-V is constantly measuring memory pressure. This is the measure of memory demand vs. memory availability. As pressure is increased, Hyper-V (through a Dynamic Memory Virtual Server Client [DMCSV] – one of the Hyper-V Integration Components) running in the guest OS of the virtual machine will assign tiny amounts of RAM to the virtual machine from the host’s free capacity. The DMVSC is virtually plugging and playing these tiny RAM additions into the running virtual machine. The guest OS sees this memory addition and the amount of installed RAM increases.
Dynamic Memory requires:
- A supported guest OS
- An up-to-date version of the Hyper-V integration components installed in the guest OS
Tip: If you want to test this out, open up MSPaint in the guest OS of the virtual machine and expand the image size to 10000 x 10000. Do this with a few copies of Paint, and you’ll see pressure increase and subside and memory is added to the virtual machine.
A virtual machine can increase its assignment of RAM until one of two things happens:
- The host has no more RAM available to assign to the virtual machine
- The virtual machine increases up to the amount of the assigned maximum RAM.
Note that the assigned buffer memory will shrink as the virtual machine reaches maximum RAM until the buffer is zero. The buffer will increase as the virtual machine’s RAM reduces.
Decreased Memory Pressure
When Hyper-V detects that pressure has subsided and there is some redundant memory in a virtual machine, the memory will be removed. This isn’t just a simple “let’s unplug some memory” task, because you cannot just remove memory from a running computer. Hyper-V does something called ballooning, which is a kind of switch con.
The DMVSC will tell the guest OS that the RAM is occupied and no longer available to other processes that are running in the guest OS. This is the balloon. Then the DMCSV will return the RAM to the host. That RAM is available for reassignment to other virtual machines.
I’m often asked what will happen when the virtual machine returns to having an increase in memory pressure. That’s simple enough: Memory is added as before. The DMVSC that is running in the guest OS “releases” memory as the balloon is gradually deflated. If enough memory is added then the balloon disappears.
Host Memory Contention
If a number of virtual machines require RAM and there is not enough left on the host to service their needs, Hyper-V will perform an unpublished algorithm using two metrics to divide up what’s left.
- Memory Pressure: How badly does each virtual machine require more memory?
- Memory Weight: How highly rated is this virtual machine in its Dynamic Memory settings?
For example, a virtual machine with high pressure and a low weight could be assigned more of the remaining host memory than a virtual machine with low pressure and a high weight value.
This setting leads to some other things that require a post all of their own. But in short, if a virtual machine becomes idle, it can balloon down to a value lower than its startup RAM value. I have seen Windows Server 2012 virtual machines shrink to around 250 MB in RAM (including the 20 percent buffer).
The benefit of this setting is that you can minimize the consumption of host resources by idle virtual machines. Maybe a host farm quietens down at night and SCVMM can use Power Optimization to temporarily power down idle hosts after draining them of quiet virtual machines using live migration. Or maybe you operate a public cloud where lots of the deployed virtual machines are idle. Margins are low, so it would be nice to legitimately continue charging for deployed machines while reclaiming unused RAM for additional revenue opportunities.
This setting was added in Windows Server 2012 Hyper-V. Windows Server 2008 R2 Service Pack 1 Hyper-V will allow virtual machines to balloon down to the startup RAM amount.