In the early days of Windows, the paging file was primarily used to compensate for insufficient RAM. Back in the day, RAM was very expensive, and swapping pages of memory between the paging file and RAM kept costs down. Since that time, of course, memory has become much more affordable. This raises the question of whether the paging file is still needed, especially in the case of Hyper-V virtual machines.
There are compelling arguments for and against using a swap file, and I’m not sure there is a universally acceptable answer. Still, I wanted to give you a few things to consider when deciding whether or not to use a paging file with Hyper-V virtual machines.
The role of the page file has changed
One of the main arguments against using the paging file is that you don’t need it as long as Windows has enough memory. However, it should be noted that the role of the paging file has changed a bit over the years. While a swap file can still be used to compensate for physical memory shortages, that is no longer its primary purpose. Instead, a paging file is used to support system crash dumps.
It should also be noted that some Windows Server roles actually require a paging file to function properly. These include Windows Server domain controllers, Distributed File System Replication servers, Windows servers that act as a certification authority, and ADAM / LDS servers.
The reason these servers need to access the paging file is because of the way they use the expandable storage engine. This database engine, also used in Microsoft Exchange Server, must free memory if this memory is requested by other processes running on the server. When this happens, the page file is used to store a copy of the data residing in these pages of memory before it is published.
So do you need to use a paging file in a Hyper-V environment? According to Microsoft, Hyper-V must have the parent operating system paging file set to System Managed. When it comes to Hyper-V virtual machines, however, things aren’t that simple.
Suppose for a moment that you have a virtual machine that is not running any of the services mentioned above. Just to keep things interesting, let’s forget about the crash dumps for now and just focus on memory. Assuming the virtual machine has received a lot of RAM, you should theoretically be able to bypass the need to have a paging file. However, as a general rule, it is a good idea to leave the paging file enabled (and set to System Managed) if the virtual machine uses dynamic memory.
This is because dynamic memory is designed to allocate memory to virtual machines based on memory pressure. In other words, a virtual machine under a heavy workload and requiring additional memory can take that memory from another virtual machine that is inactive and not using all the memory that has been allocated to it. While this looks good in theory, it’s unlikely that a virtual machine will sit idle and could easily give up some of its memory in the real world. While Hyper-V generally does a good job of juggling available memory among VMs that use it dynamically, the process of moving RAM from one VM to another isn’t always instantaneous. In these types of situations, Windows may temporarily use the paging file until it obtains the RAM it needs.
Allocating memory to virtual machines: a balancing act
Of course, allocating memory to Hyper-V virtual machines is a bit of a balancing act. Suppose you allocate too much memory to your Hyper-V virtual machines. In this case, some of this memory will likely be unused and you may reduce the total number of virtual machines that your Hyper-V host can accommodate. On the other hand, allocating too little memory to a Hyper-V virtual machine results in performance issues and increased CPU and storage usage.
So how do you know if you’ve allocated the right amount of memory to a Hyper-V VM? There are three performance monitor counters that you can use to see if a virtual machine is under memory pressure and needs more memory allocated.
The first of these counters is Memory – Standby Cache Reserve Bytes. The value of this counter will vary depending on the amount of memory allocated to the virtual machine. If a Windows virtual machine received only 1 GB of RAM, this counter should reflect a value of 200 GB or more. If the virtual machine has at least 2 GB of RAM, the value should be at least 300 GB. A lower value indicates that the virtual machine is under memory pressure and could benefit from additional RAM.
The second Performance Monitor counter that you should monitor is memory – Free Page List Bytes and Zero. As was the case with Memory – Hot spare cache reserve bytes, systems with 1 GB of RAM should show a value of at least 200 MB, and systems with 2 GB or more of RAM should show a value of at least 300 MB.
The third Performance Monitor counter worth watching is the Memory – Input Pages / Sec counter. Unfortunately, the value of this counter fluctuates a lot, so you can’t just take a look at the current value of the counter. Instead, Microsoft recommends taking the average value over at least one hour. The average value must be less than 10.
So, is the paging file enabled or disabled? It depends
As a general rule of thumb, it’s usually best to leave the paging file enabled for your Hyper-V virtual machines. Even so, there are situations in which disabling the paging file may be justified.
Featured Image: Shutterstock