Using Dynamic Memory in Hyper-V R2 SP1

by [Published on 22 Sept. 2010 / Last Updated on 22 Sept. 2010]

Taking a look at the Hyper-V R2 SP1 dynamic memory architecture, how to configure the new virtual machine memory settings and how to interpret the new memory status columns in the Hyper-V manager console.

Introduction

With Windows Server 2008 R2 SP1, Microsoft delivers a dynamic memory feature for Hyper-V that enables higher virtual machine density on any single Hyper-V host, and dynamically manages virtual machine memory requirements. In this article, you will learn about the Hyper-V R2 SP1 dynamic memory architecture, how to configure the new virtual machine memory settings, and how to interpret the new memory status columns in the Hyper-V Manager console that allow you to track virtual machine dynamic memory balancing.

Memory Allocation in Hyper-V and Hyper-V R2

In the Hyper-V and Hyper-V R2 releases, a virtual machine is configured with a static amount of memory. Therefore, when creating a virtual machine, you usually set the memory configuration to represent the maximum amount of memory that you expect the virtual machine to use, although the virtual machine may consume much less memory during most of its execution time. If Hyper-V or Hyper-V R2 cannot allocate all of the requested memory to a virtual machine at startup, then the virtual machine startup fails, even if it requires only a fraction of the assigned memory at startup. This static memory allocation model has a direct negative impact on the virtual machine density that can be achieved with Hyper-V and Hyper-V R2.

Dynamic Memory Allocation in Hyper-V R2 SP1

In Hyper-V R2 SP1, Microsoft retains the static memory allocation option, while introducing a new virtual machine dynamic memory allocation feature. Dynamic memory balancing supports increasing virtual machine density, as well as adjusting virtual machine memory on-the-fly based on actual workload requirements. Dynamic memory is supported in both Windows Server 2008 Hyper-V R2 SP1 and Microsoft Hyper-V Server 2008 R2 SP1. As the dynamic memory feature is implemented using the Virtualization Service Provider (VSP) and Virtualization Service Client (VSC) model, it is only available for Windows operating systems that support Integration Components. The list of supported guest operating systems includes:

  • Windows Server 2003 Enterprise and Datacenter with SP2 (32 and 64-bit versions)
  • Windows Server 2003 R2 Enterprise and Datacenter with SP2 (32 and 64-bit versions)
  • Windows Server 2008 Enterprise and Datacenter (32 and 64-bit versions)
  • Windows Server 2008 R2 Enterprise and Datacenter (32 and 64-bit versions)
  • Windows Vista Ultimate and Enterprise with SP1 (32 and 64-bit versions)
  • Windows 7 Ultimate and Enterprise  (32 and 64-bit versions)

Dynamic Memory Architecture

As shown in Figure 1, dynamic memory is implemented in the parent partition with a user mode VSP interface that communicates through the VMBus with a kernel mode VSC (synthetic driver) in a child partition. When you install Windows Server 2008 R2 SP1, Hyper-V files containing the new components shown in the figure are updated. In order to update a supported guest operating system, you must install the new integration components that are provided with Windows Server 2008 R2 SP1.


Figure 1:
Dynamic Memory Architecture in Hyper-V R2 SP1

One of the primary responsibilities of the dynamic memory VSC is to report the memory requirements from the guest operating system back to the parent partition. In the parent partition, the Memory Balancer component assesses memory allocation requirements across the entire set of running virtual machines, and then decides the memory allocation and de-allocation scheme to satisfy virtual machine needs.

The dynamic memory VSC also communicates with the guest operating system Windows kernel to add and remove memory. Essentially, the guest operating system Windows kernel is informed through the VSC that additional memory is available for use. Removing memory from a virtual machine is accomplished through a “ballooning” mechanism. Using “ballooning”, the VSC reclaims memory from the guest operating system by working with native memory management algorithms to return free memory to the VSC, or if free memory is not available, by paging to virtual disk to provide the VSC with the requested memory pages. The sanitized memory pages allocated to the VSC are used by the parent partition to increase the memory allocation of other virtual machines. When the memory pages are no longer needed by other virtual machines, the VSC can release the memory to the guest operating system by deflating the memory balloon.

Dynamic Memory Configuration

Even after Windows Server 2008 R2 SP1 installation, if you use the Hyper-V Manager to create a new virtual machine, the default specifies a static memory allocation. However, as shown in Figure 2, if you open the virtual machine settings in the Hyper-V Manager, you are provided with several new virtual machine memory configuration parameters.


Figure 2: Virtual Machine Memory Settings in Hyper-V Manager

In fact, the first selection to make is whether or not to switch from a static to a dynamic memory. If you select the static memory option, then you specify a set amount of memory for use by the virtual machine. If you select the dynamic memory option, then you must configure the Startup RAM, Maximum RAM, and Memory Buffer options.

The Startup RAM option defines the minimum amount of memory that is allocated to the virtual machine and reported to the guest operating system BIOS. In order to most effectively leverage dynamic memory, the Startup RAM should be configured to represent the amount of memory required by the virtual machine to startup and boot. If you configure dynamic memory for a guest operating system that does not support it, then the Startup RAM is the memory allocation that is assigned to the virtual machine, and there will be no attempt to dynamically manage the virtual machine memory. The Startup RAM option default is 512 MB.

The Maximum RAM option defines the peak amount of memory that can be allocated to the virtual machine. Even if the virtual machine reports that it requires more memory than the amount specified in the Maximum RAM setting, it will not be allocated more. The Maximum RAM option default is 64 GB.

The Memory Buffer option provides the ability to specify a percentage of additional memory to allocate to the virtual machine above what is required to run the workload. This additional memory can be used for file caching or used as needed when the virtual machine requires it. The actual memory buffer for a virtual machine may be lower than this setting depending on the amount of available memory in the system. The Memory Buffer option default is 20 percent, and should be adjusted based on the particular requirements of virtual machine workloads.

In addition, you can also specify a Memory Priority configuration for a virtual machine. This option allows you to prioritize the distribution of memory for a virtual machine with respect to other virtual machines on a host, if there is not enough available memory to satisfy all virtual machine requirements. The Memory Priority option ranges from Low to High and the default is a mid-range setting.

As shown in Figure 2, the Memory Buffer and Memory Priority options are the only memory parameters that can be modified while a virtual machine is running. Changing between static and dynamic memory management options and configuration of Startup RAM and Maximum RAM settings can only be performed when a virtual machine is powered off.

Monitoring Dynamic Memory in Hyper-V Manager

Figure 3 shows the Hyper-V Manager console after applying Windows Server 2008 R2 SP1 to a server running Hyper-V. There are two new columns in the Virtual Machines pane of Hyper-V Manager: Current Memory and Memory Available. These two columns allow you to view current memory information and monitor how memory availability changes as Hyper-V dynamically balances memory among virtual machines.


Figure 3: Virtual Machines Memory Monitoring in Hyper-V Manager

More specifically, the Current Memory column displays memory that is allocated to the virtual machine at any particular point in time. The Memory Available column displays the amount of memory allocated to the memory buffer as a percentage of the committed memory in the virtual machine. The Memory Available column may display a negative value when there is not enough available memory to allocate to a virtual machine based on its current requirements. A virtual machine guest operating system can use its native memory management to cope with this situation just as it would on a physical server (e.g., page out to the swap file).

Monitoring Dynamic Memory using Performance Counters

Windows Server 2008 R2 SP1 also includes new performance counters that allow you to monitor dynamic memory allocation, and these are contained in new performance counter groups: Hyper-V Dynamic Memory Balancer and Hyper-V Dynamic Memory VM. You can create Data Collector sets to gather performance counter data, and use Performance Monitor to see the data in real time.

Conclusion

With Windows Server 2008 R2 SP1, the new Dynamic Memory feature provides a means to increase the virtual machine density on your Hyper-V host, and use system memory more effectively by dynamically adding and removing memory from virtual machines as required by workloads. In order to start testing Hyper-V Dynamic Memory, download the Windows Server 2008 R2 SP1 beta version available from here.

Featured Links