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.
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:
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.
If any of the following happens then the virtual machine will need enough RAM to start the OS:
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.
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: