Book Image

Learning Hyper-V

Book Image

Learning Hyper-V

Overview of this book

Table of Contents (19 chapters)
Learning Hyper-V
Credits
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Dynamic memory


Dynamic memory is a feature that was released in Service Pack 1 for Windows Server 2008 R2 and Hyper-V Server 2008 R2. It was a long awaited feature for Hyper-V as its major competitors had other features for managing VM memory, and, until that point, Hyper-V option was the static VM memory.

This feature allows you to configure not only the amount of memory for a VM, but also define a Minimum and Maximum of vRAM. In case the VM memory is stressed, Hyper-V can provide more memory to the VM, as long as the host has physical memory. An important point for Dynamic memory is that it only uses physical memory. Other memory management techniques in the market use processors (page sharing) or disks (Second Level Paging) to address memory issues. Microsoft decided not to use these techniques as they bring overhead to the host or drag the performance of the VM, except for some VM restart operations with Smart Paging that will be explained later in this section. Instead, Dynamic memory uses another technique from the market called ballooning.

To better understand the ballooning technique, imagine the air companies' ticketing and sales process. Let's say an aircraft has 200 seats. The company will sell a given percentage above those 200 seats. In the end, only 200 passengers are allowed to check-in. With Dynamic memory, you can create any number of VMs with a maximum that exceeds the physical memory on the host, but only the available physical memory will be allocated to these VMs. If a VM requires more memory and there is no available memory on this host, the VM will have to wait for the ballooning process to work on other VMs and for the host to reclaim unused memory.

Dynamic memory configuration

The Dynamic memory configuration is made on a per-VM basis. Open the VM Settings and select Memory. Let's take a look at the Dynamic Memory configuration, as seen in the following screenshot:

The standard configuration, unless you changed it during VM creation, has the Enable Dynamic Memory checkbox cleared. With that configuration, you can specify the Startup RAM size and the VM will run with this amount of RAM all the time. This is what we call static memory.

Tip

Keep in mind that static memory is the recommended option. Dynamic memory is an alternative that can be used for consolidating VMs on environments with idle or low-load VMs. Dynamic memory is only recommended for Virtual Desktop Infrastructure (VDI) with Pooled VMs scenario. Additionally, some applications, such as SharePoint, do not support Dynamic memory.

If you enable Dynamic memory, you can also specify the Minimum RAM and Maximum RAM. This is a new configuration for Dynamic memory since Hyper-V 2012. Prior to that, you were able to set the Startup and Maximum RAM. This change enables you to set a Startup RAM that will be set to the VM at the moment of the VM startup. As the VM continues to run, and if it doesn't need that amount of RAM, Hyper-V will reclaim that memory up to the value configured on Minimum RAM. This reclaimed memory will be available for use by other VMs. This new configuration of startup and minimum memory creates a scenario issue that will be explained in detail later in this section.

The Maximum RAM will limit how much memory a VM can allocate as the application inside the VM requests more memory. When the limit is reached, Hyper-V stops giving memory to the VM.

Memory buffer

The two remaining options are as important as the other ones. Memory buffer and Memory weight are usually overlooked, but require attention as they influence the operation of the VM. The Memory buffer option is important because it is the definition of how much memory Hyper-V will try to reserve and assign for the VM on the host. When the VM requests more memory, Hyper-V will deliver the reserved memory for the VM based on the percentage and the memory requested by the application. After that, Hyper-V will reserve the percentage again. To validate the amount of memory that will be assigned to the VM, Hyper-V uses performance counters to identify the committed memory. You can check this performance counter by opening Performance Monitor and adding the Hyper-V Dynamic memory VM / Average Pressure performance counter. With that information, Hyper-V uses the following formula to determine how much memory to assign to the VM:

Amount of Memory Buffer = How much memory the virtual machine actually needs / (Memory Buffer value / 100)

For example, suppose that the memory allocation is 2000 MB and the memory buffer is 20 percent. In this case, Hyper-V will try to allocate 400 MB of RAM, with a total of 2400 MB, for the VM. But all of this will only make sense if you also configure Memory weight.

Memory weight

Memory weight is the configuration that confirms the reserved memory. Once the VM requests memory and Hyper-V delivers it, Hyper-V is unable to remove the memory from the VM as this can crash the VM operation. If the Memory weight is the same for all VMs, then all VMs can actually request all available memory on the host, as long as the maximum memory allows it, even if this memory is reserved to another VM. If a VM is more important in your environment, and you want to ensure that the reserved memory is not consumed by other VMs, you can increase the Memory weight. This configuration will ensure that VMs with a lower configuration of Memory weight do not use the reserved memory from VMs with higher Memory weight configuration.

After configuring Dynamic memory, you can verify the VM memory on Hyper-V Memory, as seen in the following screenshot:

As you can see from the image above, there is some important information on Hyper-V Manager for you to take note of, and to verify that your VM is correctly configured. If you need more details on Dynamic memory, there are other performance counters under Hyper-V Dynamic Memory VM in Performance Monitor.

As mentioned earlier, this Dynamic memory configuration can cause another problem in a specific scenario. Check the following Hyper-V and VMs configuration:

VMs

Startup RAM

Minimum RAM

Maximum RAM

Host

4 GB

N/A

N/A

VM01

1 GB

512 MB

4 GB

VM02

1 GB

512 MB

4 GB

VM03

1 GB

512 MB

4 GB

VM04

1 GB

512 MB

4 GB

With the configuration above, if all VMs are turned on at the same time, Hyper-V will be able to allocate the correct amount of memory for each VM.

Note

The preceding configuration is an example. In fact, due to memory management overhead, you need more memory on the host to be able to turn on the VMs with the VM configuration illustrated in this table. A minimum of 512 MB is recommended to be reserved on the host.

In case you turn off VM04 and VM01 requests more memory, VM01 will be able to use 2 GB of RAM. In this case, if you try to turn on VM04 again, you won't be able to power on as there are not enough resources. The following error will be presented:

But there is another case where a situation like this can happen even without turning any VM off. With the same configuration from the previous table, imagine that after a while, Hyper-V tries to reclaim memory from the VMs, and VM01 is with low utilization. As VM01 is configured to use 512 MB of Minimum RAM, Hyper-V will reclaim another 512 MB of RAM. At this moment, VM04 is stressed and requests more memory. Hyper-V will then allocate the available 512 MB of RAM to VM04.

Everything is okay until VM01 begins to restart. As VM01 is configured to use 1 GB of startup RAM, the VM won't be able to initialize. To avoid this scenario, Microsoft introduced Smart Paging.

Smart Paging

Smart Paging is a feature released in Hyper-V 2012. It creates a Smart Paging file on the host disk for allocating memory to the VM so that the VM can use the correct Startup memory configuration. This feature can be used only under certain conditions (all must be true), which are as follows:

  • The virtual machine is being restarted

  • There is no available physical memory

  • No memory can be reclaimed from other virtual machines running on the host

If all of the above are true, Smart Paging will work to allow the VM to restart. You can configure the Smart Paging location by navigating to Hyper-V Manager | VM Settings... | Smart Paging File Location. It is recommended to use a Solid-State Disk (SSD), or disks which are not over-utilized, for better performance.

With all the Dynamic memory configuration in place, it is important to understand its behavior from the architectural perspective and guest OS limitations. As you were probably able to figure out, for Hyper-V to be able to reclaim unused memory, the guest OS will be prompted to return this memory. This can only be achieved by using IC or LIS, so it is extremely important to have IC/LIS updated on the guest OS.

The IC will create the balloon driver and this driver will be utilized by the VSC on the guest OS. This driver will inflate when an application requests memory and Hyper-V delivers it. For this driver to work, there are some requirements for the guest OS. When using a Windows Server 2012 or 2012 R2, both Standard and Datacenter versions will support it. But some versions of previous releases of Windows Server, the Standard and Datacenter versions did not support it. For Windows Server 2008 and 2008 R2, the Standard version did not support Dynamic memory. For Windows 8 and 8.1, only Professional and Enterprise support it. For a complete list of guest OS, that support Dynamic memory, check the official article at http://technet.microsoft.com/en-us/library/hh831766.aspx.