Smart Paging in Hyper-V Dynamic Memory
A new feature was added to Hyper-V’s Dynamic Memory in Windows Server 2012 (WS2012) called Smart Paging. This new feature is something that you should very rarely see in the real world but is one that you should know about and understand. In this post I will explain what Smart Paging is and how it operates in Hyper-V Dynamic Memory.
What Is Smart Paging?
The Smart Paging feature of Hyper-V is used in a very rare scenario when you need to restart one or more virtual machines on a memory starved host. The need for Smart Paging was introduced in WS2012 when the Minimum RAM setting was added. With Minimum RAM enabled, a virtual machine will boot up to its startup RAM (enough to boot the OS and get services running) and, if idle, it can balloon down to a lower amount of RAM as specified by Minimum RAM.
Let’s make this real with an example. Imagine a hosting customer in a cloud deploys a small specification virtual machine. This machine has the following settings:
- Startup RAM = 512 MB
- Maximum RAM = 2048 MB
- Minimum RAM = 32 MB
- Buffer = 20 percent
The virtual machine starts up and immediately consumes 512 MB plus an additional 20 percent of memory. Approximately 615 MB is consumed by the virtual machine from the host. No additional software is running, and like many hosting customers, the machine is left idle. Dynamic Memory will seek to optimize the memory allocation. Windows requires 512 MB to boot, but it can run on less! This virtual machine might balloon down to 300 MB RAM, less than the amount required to boot.
Read the Best Personal and Business Tech without Ads
Staying updated on what is happening in the technology sector is important to your career and your personal life but ads can make reading news, distracting. With Thurrott Premium, you can enjoy the best coverage in tech without the annoying ads.
If any of the following happens then the virtual machine will need enough RAM to start the OS:
- A host reboot
- A VM reboot
- A VM reset
Now, 300 MB will not be enough to boot up the guest OS of the virtual machine. Normally, sufficient RAM will be assigned to the virtual machine. But what happens if the host’s administrators have been careless and deployed too many machines onto this Hyper-V host?
In the below example there are four such virtual machines, each requiring 512 MB to boot up and each able to balloon down to 300 MB. Each virtual machine is idle and has ballooned down, therefore consuming a total of just 1200 MB from the host. That’s fine, because the host had 1400 MB to run those four virtual machines.
The four virtual machines are patched and rebooted automatically. Now each virtual machine needs the memory defined in Startup RAM to get the guest OS started. There’s the problem: The host has just 1400 MB of RAM, which was fine for the virtual machines when they were idle, but now the virtual machines require a total of 2048 MB (and that’s without considering the buffer percentage).
Dynamic Memory will use the virtual machines’ priority setting and the guest OS pressure for more RAM to divide up the remaining 1400 MB between the virtual machines. But that still won’t be enough. This is where Smart Paging kicks in.
In this rare scenario, Hyper-V will provide a per-virtual machine paging file to simulate additional RAM for each virtual machine that is short of the required Startup RAM requirement. Please bear in mind that this is not dumb second-level paging that is done by some hypervisors on a near permanent basis. Smart Paging is done temporarily and only for required virtual machines. When the virtual machine has booted up, it will return to its previous idle state and balloon back down towards the Minimum RAM amount. Eventually pressure for memory from the host will subside and the need for the Smart Paging file will disappear. The per-virtual machine design also means that you have granular control over the location of the Smart Paging file. By default (and this almost never changed because Smart Paging is very rare) the Smart Paging file is stored with the virtual machine’s files.
How to Avoid Smart Paging
Smart Paging will reduce the performance of virtual machines temporarily before the idle back down to their previous state. You could argue that this doesn’t matter much because the virtual machines were idle anyway. But what if the host rebooted and every virtual machine had to start up again? You would have no control over which virtual machine would use Smart Paging in that scenario.
There are ways to avoid smart paging:
- Don’t oversubscribe host RAM: This is obvious advice. Be careful about deploying too many virtual machines onto a host. Note that Intelligent Placement in System Center Virtual Machine Manager (SCVMM) will prevent you from harming yourself in this regard.
- Avoid Minimum RAM: Configure the Minimum RAM setting to be the same as Startup RAM. This would give you the same effect as Windows Server 2008 R2 virtual machines. I don’t like this one – Minimum RAM allows you to reclaim wasted memory from idle virtual machines (which do exist thanks to “VM sprawl”).
- Manual intervention: If you are manually rebooting a lot of virtual machines or a host where there is physical memory starvation, then you could use live migration to move virtual machines to hosts with less pressure.
- System Center: System Center Operations Manager (SCOM) can detect sudden spikes in memory demand and use Performance and Resource Optimization (PRO) management packs to instruct SCVMM to live migrate virtual machines to more suitable hosts. SCVMM can also be configured to implement Dynamic Optimization (like vSphere DRS) to intelligently load balance virtual machines across your Hyper-V hosts. The System Center options are best because they offer an automatic and intelligent option based on performance metrics.