Virtualization is one of the most tested subjects on the exams required for the Microsoft Certified Solutions Expert (MCSE) certification. The last two articles of this series; reviewed Windows Server 2012 Hyper-V technical requirements, different installation options, initial virtual network configuration and advanced network configuration options
The number and performance of virtual machines running on a Hyper-V host depends on the physical resources available on that host. RAM, processor, storage and networking are crucial components for the proper operation of Hyper-V servers. These resources are the virtual machines’ lifeblood. This article reviews the memory features of Windows Server 2012 R2 Hyper-V with special attention to Dynamic Memory allocation and its benefits.
Virtualization technologies are critical in many data centers as businesses continue to embrace private and public clouds to manage their services and infrastructures. Windows Server 2012 R2 Hyper-V aims at those data centers; a Hyper-V server host supports a maximum of 320 logical processors and up to 4 TB of RAM. Up to 1TB RAM and a maximum of 64 virtual CPUs are supported per virtual machine. The amount of physical RAM is especially important, usually bottleneck issues are more related to RAM than to any other resource. That is why dynamic memory plays a very important role on the performance of Hyper-V servers.
MCSE Training – Resources (Intense)
Before Dynamic memory was introduced on Windows Server 2008 Service Pack 1, the amount of memory assigned to a virtual machine would be consumed by the VM regardless of whether the guest operating system required that much RAM or not. On Windows Server 2012 R2 Hyper-Vdynamic memory has been enhanced with configuration options designed to optimize how the host memory is allocated to virtual machines by the Management OS. Implementing dynamic memory improves the Hyper-V host flexibility to optimize the allocation of RAM to virtual machines.
A running virtual machine can expand its memory usage up to the Maximum RAM value assigned to the VM. However, the Hyper-V host retrieves the memory back from the virtual machine when it is no longer needed or required. Because Dynamic Memory allocates only what the virtual machine demands within the configured parameters, memory bottlenecks are minimized. You can enable or disable dynamic memory on a per-VM basis.
This feature works as long as the Hyper-V integration services are installed on the VMs. Dynamic Memory is now supported for Linux virtual machines. On Windows Server 2012 R2 Hyper-V, you can use Linux Integration Services to take advantage of dynamic memory on VMs running Red Hat Enterprise Linux, SUSE Linux Enterprise Server, CentOS, Ubuntu Server, or Debian.
To configure virtual machine memory, open the Hyper-V Manager console, right-click on a VM and choose the Settings command from the shortcut menu. When the Settings for the VM box appears, click on Memory.There you can allocate Startup RAM and configure the Dynamic memory options (see Figure 1).
TheDynamic Memory configuration includes settings to adjust Minimum RAM, Maximum RAM, Memory buffer and Memory weight. The virtual machine must be turned off to enable Dynamic Memory. Once Dynamic Memory has been enabled, the Minimum RAM, Maximum RAM, Memory buffer and Memory weight values can be modified while the VM is running. However, you must shutdown the VM to increase the Minimum RAM or to decrease the Maximum RAM.
Let’s take a closer look at these parameters:
Startup RAM: Indicates the amount of RAM required starting the virtual machine, regardless of whether or not you configure dynamic memory. You must assign enough memory to allow the guest operating system to start; the virtual machine will fail to boot if this memory cannot be fully assigned during the startup process. However, you do not want to assign this value too high either because that may hinder optimal memory utilization and possible higher consolidation ratios.
Minimum RAM: Refers to the amount of memory that should be allocated to the virtual machine after the virtual machine has started. This new and interesting setting allows you to take advantage of the fact that VMs can guzzle far less memory when they are running but idle than when they are starting up. In those cases, the unused memory is returned to the host and can then be automatically reassigned to other virtual machines. The Minimum RAM can be way lower but never higher than the Startup RAM value.
- Maximum RAM: Designates the highest amount of memory that the VM is allowed to use. This number cannot be lower than the Startup RAM. By default, Hyper-V assigns a value of 1,048,576 MB which is the equivalent of 1TB. That is the maximum amount of RAM that can be allocated to a virtual machine. Nevertheless, keep in mind that it is impossible for a virtual machine to have more RAM than what is available on the host. Also, the guest operating system running within the VM may have limitations below the value that you configure as Maximum RAM. For example, if you specify 8 GB for a virtual machine running a 32-bit guest operating system that supports a maximum of 4 GB, the virtual machine cannot use more than 4 GB.
Memory buffer: Represents a spare amount of memory allocated to the virtual machine above what the VM currently requires to run its services and applications. The default value is 20%. By tracking the performance counters in the virtual machine, Hyper-V learns the total committed memory and estimates the current memory requirements of the VM. This information allows Hyper-V to calculate the amount of memory buffer based on the following formula:
Amount of memory buffer = (nRAMxmBuffer) /100
- nRAM = How much memory the virtual machine actually needs
- mBuffer = Configured memory buffer value
While the memory buffer is configured as a percentage value, the amount of memory buffer is an absolute quantity that indicates additional RAM that Dynamic Memory allocates to the VM to prevent latency in cases when the guest operating system suddenly starts craving for more memory. For example, let’s say that you keep the default memory buffer value of 20% and a virtual machine requires 2,000 MB of RAM.
Applying the formula:
Amount of memory buffer = (2,000 x 20) / 100 = 400.
Based on these results Dynamic Memory will allocate 2,400 MB of RAM to the virtual machine.
- Memory weight: This setting is used by Hyper-V to prioritize RAM distribution when multiple virtual machines start competing for memory allocation. It is a sliding value from lower to higher priority. A virtual machine with a higher Memory weight will have a higher priority for a share of the remaining contended memory on a host than a virtual machine with a lower Memory weight.
You can configure all these settings using Windows PowerShell.
- Set-VM -Name Svr* -DynamicMemory -MemoryMinimumBytes2GB -MemoryMaximumBytes 16GB -MemoryStartupBytes 8GB
In the example above, the Set-VM cmdlet is used to configure dynamic memory with the minimum, maximum and startup values to all servers with names that start with Svr.
Here is another example:
- Set-VMMemory DC1 -DynamicMemoryEnabled $true -MinimumBytes 1024MB -StartupBytes 2048MB -MaximumBytes 5GB -Priority 75 -Buffer 30
In this case, the Set-VMMemorycmdlet enables dynamic memory on a virtual machine named DC1, sets its minimum (1,024MB), startup (2,048MB), and maximum memory (5GB), its memory priority (75), and its buffer (30%).
There are two other important memory settings that will be reviewed next: NUMA Spanning and the Smart Paging File.
Non-Uniform Memory Access (NUMA) is a hardware architecture designed to overcome the limitations of classic symmetric multiprocessing (SMP) implementations which limit all memory access to the same shared memory bus.
NUMA topology provides separate memory for each processor avoiding the potential bottleneck that occurs when several processors attempt to address the same memory. On computers with multiple processors, each processor controls and directly connects to specific blocks of memory via a local memory bus. Multi-processor systems without NUMA severely hinder performance as only one processor can access the computer memory at a time.
Enabling NUMA Spanning on Hyper-V has some pros and cons. A high-end processor with many cores may divide itself to enable parallel direct connections to different banks of memory. Multiple cores can be grouped into two or more NUMA nodes. In this case, the cores group into each NUMA node and will have access to a different set of memory by default.
When NUMA Spanning is enabled, if a process running on cores in a NUMA node requires more memory than the amount available for that node, then the operating system or hypervisor will assign the additional RAM from another NUMA node. The NUMA spanning activity introduces some latency because the core processors now need to reach out a little farther to access the memory they need to run their memory starving processes.
NUMA spanning is enabled by default on Windows Server 2012; this may allow you to run more virtual machines simultaneously, but it could hamper performance as this configuration does not force the virtual machines to use memory on the same NUMA node as the processor cores.
To change the NUMA Spanning settings, open the Hyper-V Manager console, right-click on the Hyper-V server host name and choose the Hyper-V Settings command from the shortcut menu. On the Hyper-V Settings box, select on NUMA Spanning. See Figure 2 below. You must restart the Virtual Machine Management Service after changing the NUMA Spanning configuration. Before you restart this service, all virtual machines running on that Hyper-V server must be stopped or migrated to another host.
You can also use Windows PowerShell to disable NUMA spanning and restart the Hyper-V Virtual Machine Management service on the Hyper-V host:
- Set-VMHost -NumaSpanningEnabled $false
- Restart-Service “Hyper-V Virtual Machine Management”
Either one of the following two Windows PowerShell commands allow you to verify the NUMA spanning settings:
- Get-VMhost | Format-List ComputerName,NumaSpanningEnabled
Smart Paging File
This special type of virtual memory file is created only when needed by a virtual machine to restart after the following conditions apply all together:
- The configured VM Minimum Memory is lower than the Startup memory.
- No more physical memory is available.
- The Hyper-V host cannot retrieve spare memory from other running VMs.
The Smart Paging File is a last resource that uses hard drive storage to provide temporary memory when more RAM is required to restart a virtual machine. Once a virtual machine restarts and settles down to the Minimum Memory usage, the Smart paging file is automatically deleted by the Hyper-V host. The short life span of this file prevents the VM from degrading its performance after the restart process completes.
It is important to note that the Smart Paging File is not used when the hyper-V host memory is oversubscribed. In those cases the guest operating system uses its own Windows memory management to execute paging operations. This makes sense because Windows Memory Manager within the virtual machine has better intelligence about its own memory usage than the Hyper-V host does.
To change the Smart Paging File Location, open the Hyper-V Manager console, right-click on a VM and choose the Settings command from the shortcut menu. When the Settings for the VM box appears, select Smart Paging File Location and click on Browse (See Figure 3). The virtual machine must be turned off to be able to change this setting.
It is possible to change the Smart Paging File path using Windows PowerShell. For example, the following command will change the path of the Smart Paging File on a virtual machine named DC1 to a new location on the X drive.
Set-VM DC1 -SmartPagingFilePath “X:\Smart Paging Files\DC1”
You can verify the new path by using either one of these PowerShell commands:
- Get-VM DC1 | Format-List SmartpagingFilePath
This article focused on Hyper-V memory functionality including Startup RAM,dynamic memory, NUMA Spanning, and the Smart Paging File. We demonstrated how to change memory configuration settings on Hyper-V hosts and virtual machines using the Hyper-V Management console and Windows PowerShell. RAM availability is the most common cause of bottleneck issues on server virtualization; it is possible to greatly improve performance and minimize bottlenecks by properly configuring and allocating memory resources on your Hyper-V hosts.