1. Optimizing workload consolidation
One of the key benefits of server virtualization is that it
allows businesses to better utilize their hardware resources. For
example, in a traditional (nonvirtualized) environment, you might have
a dozen servers at your head office location with each server
performing some specialized role, such as file server, print server,
database server, DHCP server, and so on. Many of these server roles
can incur low average processing overhead, and this means that much of
the system hardware in your server room might be significantly
underutilized. For example, a dedicated DHCP server might have an
average CPU usage of less than 10 percent.
By virtualizing your server workloads, however, you might be
able to consolidate most—or even all—of your existing physical servers
as virtual machines running on a single two-mode failover cluster of
Hyper-V hosts. This reduces the number of physical servers in your
environment from a dozen to only two, which not only simplifies your
physical infrastructure but might also lead to significant cost
savings because of the reduced power requirements. By using P2V
conversion using the tools available in System Center Virtual Machine
Manager or a third-party product, you now have a dozen virtualized
server workloads to manage instead of a dozen physical systems. And by
carefully analyzing the processor and memory requirements of your
original servers, you can choose appropriate system hardware for your
two Hyper-V hosts to ensure that they have enough processing and
memory resources to run all these virtual machines with optimal
performance.
By adjusting the memory allocated to each virtual machine on a host so
that the virtual machine has just enough memory to perform optimally,
you might be able to significantly increase the number of virtual
machines that can simultaneously run on the host. Achieving higher
virtual machine consolidation ratios through this approach can result
in cost savings by eliminating the need for costly memory upgrades or
even more costly purchases of additional host systems.
This capability is what Dynamic Memory is all about. Dynamic
Memory was first introduced for Hyper-V in Windows Server 2008 R2 as a
way of enabling Hyper-V hosts to make more effective use of physical
memory allocated to virtual machines running on the host. Dynamic
Memory works by adjusting the amount of memory available to a virtual
machine in real time. These adjustments in memory allocation are based
on how much memory the virtual machine needs and on how Dynamic Memory
settings have been configured for the virtual machine.
Although it can provide some benefit when virtualizing server
workloads, Dynamic Memory is especially valuable for virtual desktop
infrastructure (VDI) scenarios, where it can provide scalability and
performance benefits that can result in significant cost savings. This
is because at any given time in a VDI environment, some of the virtual
machines running on the host tend either to be idle or to have a
relatively low load. By using Dynamic Memory, however, you can
consolidate greater numbers of virtual machines on your Hyper-V hosts.
This means that you’ll need fewer hosts for provisioning virtual
desktops to your user population, which means you won’t need to
procure as much high-end server hardware and can therefore save
money.
Configuring Dynamic Memory
As shown in Figure 1, you can use
the Memory page of the virtual machine settings dialog box in
Hyper-V Manager to enable and configure Dynamic Memory for a virtual
machine. Dynamic Memory can be enabled and configured only on a
per-virtual machine basis. Once it is enabled for a virtual machine,
the settings you can configure for Dynamic Memory include the
following:
-
Minimum RAM This setting
specifies the minimum amount of memory that the virtual machine
can use while it is running.
-
Maximum RAM This setting
specifies the maximum amount of memory that the virtual machine
can use.
-
Memory buffer This setting
specifies the amount of memory (as a percentage of the amount
that the virtual machine actually needs to perform its workload)
that can be allocated to the virtual machine when there is
sufficient memory available on the host.
-
Memory weight This setting
is a parameter that determines how available memory on the host
is allocated among the different virtual machines running on the
host.
Note
Understanding the
memory buffer
The Memory Buffer setting for Dynamic Memory can be thought
of as a memory reserve for the virtual machine. For example, if
you configure the buffer to have a value of 50 percent, an
additional amount of memory of up to 50 percent of the committed
memory can be allocated to the virtual machine when needed.
One common scenario where this can provide benefits is when
the virtual machine is running a workload that makes heavy use of
the disk cache. In this case, increasing the buffer setting will
result in additional memory being allocated to the virtual memory
from the pool of idle memory on the host. For such scenarios,
begin by raising the buffer setting from its default value of 20
percent to something like 30 or 40 percent and observe the change
in the performance of the workload. Then if additional tuning is
required, try raising the buffer setting a little further. Just
don’t suddenly bump it up to 300 percent because you might end up
starving the other workloads on the host!
The Minimum RAM setting is new in Windows Server 2012 Hyper-V,
and it was introduced because Windows generally needs more memory
when starting than it does when idle and running. As a result of
this change, you now can specify sufficient Startup RAM to enable
the virtual machine to start quickly and then a lesser amount of
memory (the minimum RAM) for when the virtual machine is running.
That way, a virtual machine can get some extra memory so that it can
start properly, and then once it’s started, Windows reclaims the
unneeded memory so that other virtual machines on the host can use
the reclaimed memory if needed.
Another change in the way that Dynamic Memory can be
configured in Windows Server 2012 is that now you can modify the
Maximum RAM and Minimum RAM settings while the virtual machine is
running. In Windows Server 2008 R2, the Maximum RAM setting could be
modified only when the virtual machine was in a stopped state. This
change gives you a new way of quickly provisioning more memory to a
critical virtual machine when needed.
You can also use the Set-VM cmdlet to enable and configure
Dynamic Memory for a virtual machine using Windows PowerShell. For
example, let’s say you wanted to enable Dynamic Memory for a virtual
machine named SRV-B that is running on HOST4 and configure the
maximum RAM as 4 GBs. To do this, you first have to stop the virtual
machine because you cannot enable or disable Dynamic Memory while
the virtual machine is running. You can use the Stop-VM cmdlet to do
this as follows:
PS C:\> Stop-VM -Name SRV-B -ComputerName HOST4
Next you can use the Set-VM cmdlet to enable Dynamic Memory
for the virtual machine and set the maximum RAM to 4 GBs as
follows:
PS C:\> Set-VM -Name SRV-B -ComputerName HOST4 -DynamicMemory -MemoryMaximumBytes 4GB
Now you can use Start-VM to restart the stopped virtual
machine:
PS C:\> Start-VM -Name SRV-B -ComputerName HOST4
Finally, you can use Get-VM to verify the result:
PS C:\> Get-VM -Name SRV-B -ComputerName HOST4 | `
Format-List DynamicMemoryEnabled,MemoryMaximum
DynamicMemoryEnabled : True
MemoryMaximum : 4294967296
Let’s now say that you decide later that 3 GBs would be a
better value for maximum RAM than 4 GBs. By using the
–Passthru parameter, which specifies that an
object is to be passed through to the pipeline, you can make the
change and verify the result using a single Windows PowerShell
command as follows:
PS C:\> Stop-VM -Name SRV-B -ComputerName HOST4 -Passthru | Set-VM -DynamicMemory `
-MemoryMaximumBytes 3GB -Passthru | Start-VM -Passthru | Get-VM | `
Format-List DynamicMemoryEnabled,MemoryMaximum
DynamicMemoryEnabled : True
MemoryMaximum : 3221225472
Configuring host reserved memory
Although Dynamic Memory can help you consolidate more
virtualized workloads on a host, it’s important that the host itself
have enough memory. If the host has insufficient memory, the
management operating system might hang or crash, resulting in all
virtual machines being stopped unexpectedly, with a possible loss of
data occurring.
To prevent this from happening, Hyper-V automatically reserves
some of the host’s physical memory for the management operating
system. With Hyper-V in Windows Server 2008 R2 SP1, you could also
manually specify how much memory should be reserved for the host by
using Registry Editor to create a REG_DWORD registry value named
MemoryReserve in the following location:
HKLM\Software\Microsoft\Windows
NT\CurrentVersion\Virtualization
MemoryReserve could then be used to specify the amount of
physical memory in MBs that should be reserved for the parent
partition, with 2 GBs (2048 MBs) being the recommended value. The
host then had to be rebooted for the change to take effect.
With Hyper-V in Windows Server 2012, however, the management
operating system on the host now reserves more memory than in
previous versions of Hyper-V to ensure greater reliability and
responsiveness. In addition, manually configuring the MemoryReserve
registry value as I just described can have undesirable results in
some circumstances. For example, it might happen that a combination
of management activity, background processes, scheduled tasks, and
other activity on the host cause memory usage by the management
operating system to temporarily rise above the value you manually
configured using the MemoryReserve registry value. Should this
occur, the management operating system might hang or crash,
resulting in service interruption and possible data loss. As a
result, Microsoft no longer recommends manually configuring the
MemoryReserve registry value. Instead, you should allow Hyper-V
itself to ensure enough memory is always reserved for the
host.