How to Configure Hyper-V Dynamic Memory on Windows Server 2012 R2
Hyper-V Dynamic Memory is a feature that allows the hypervisor to dynamically adjust the amount of physical RAM allocated to each virtual machine based on actual workload demand. Instead of statically reserving a fixed amount of memory for each VM — even when that VM is idle — Dynamic Memory reclaims unused memory from idle VMs and redistributes it to VMs that need more. This results in higher VM density per physical host and better utilisation of expensive RAM resources.
How Dynamic Memory Works
Dynamic Memory uses two mechanisms to manage VM memory:
- Memory Ballooning: The Dynamic Memory balloon driver (part of Integration Services) inside the guest OS can inflate or deflate to reduce or increase the amount of memory available to the guest OS. When the host needs to reclaim memory, it asks the balloon driver to inflate, which causes the guest OS to treat that memory as consumed (it effectively disappears from the guest’s available pool). The hypervisor then takes that memory back for other VMs
- Page Remapping: The hypervisor can also use second-level address translation (SLAT) to remap pages that have not been recently accessed
Key Dynamic Memory settings per VM:
- Startup Memory: The amount of RAM assigned when the VM starts
- Minimum Memory: The lowest amount of RAM the hypervisor can reduce the VM to
- Maximum Memory: The upper limit of RAM that can be assigned to the VM
- Memory Buffer: A percentage of additional memory the host attempts to keep available above what the guest is currently using
- Memory Weight: Relative priority for memory allocation when the host is under memory pressure (1-10000, default 5000)
Prerequisites
- Windows Server 2012 R2 Hyper-V host
- Guest OS must support Dynamic Memory (Windows Server 2008 SP1+, Windows 7 SP1+, or a Linux OS with LIS including Dynamic Memory support)
- Integration Services installed and running in the guest
Step 1 — Enable Dynamic Memory on a VM
The VM must be powered off to enable Dynamic Memory (if it is currently using static memory):
Set-VMMemory -VMName "AppServer01" -DynamicMemoryEnabled $true -StartupBytes 2GB -MinimumBytes 512MB -MaximumBytes 8GB -Buffer 20
Verify the configuration:
Get-VMMemory -VMName "AppServer01"
Step 2 — Configure Memory Buffer
The memory buffer (default 20%) is the additional percentage of memory the host tries to maintain above the current working set demand of the guest. A higher buffer reduces balloon driver activity but reduces host-level memory efficiency:
# For a latency-sensitive application like a database, use a higher buffer:
Set-VMMemory -VMName "SQLServer01" -DynamicMemoryEnabled $true -StartupBytes 8GB -MinimumBytes 4GB -MaximumBytes 32GB -Buffer 30
# For a general-purpose VM with tolerant workload, use a standard buffer:
Set-VMMemory -VMName "WebServer01" -DynamicMemoryEnabled $true -StartupBytes 2GB -MinimumBytes 512MB -MaximumBytes 4GB -Buffer 20
Step 3 — Configure Memory Weight
When the host is under memory pressure and cannot satisfy all VMs’ memory demands, memory is allocated proportionally based on weight:
# High-priority production VM (higher weight = more memory when resources are scarce):
Set-VMMemory -VMName "ProductionSQL" -Priority 9000
# Lower-priority VM:
Set-VMMemory -VMName "TestServer01" -Priority 2000
Step 4 — Enable Dynamic Memory on Multiple VMs
$VMConfigs = @(
@{Name="WebServer01"; Min="512MB"; Start="2GB"; Max="4GB"; Buffer=20},
@{Name="AppServer01"; Min="1GB"; Start="4GB"; Max="8GB"; Buffer=25},
@{Name="FileServer01"; Min="1GB"; Start="2GB"; Max="6GB"; Buffer=20}
)
foreach ($Config in $VMConfigs) {
Set-VMMemory -VMName $Config.Name `
-DynamicMemoryEnabled $true `
-MinimumBytes ([int64]([string]$Config.Min | ConvertFrom-StringData | Out-Null; Invoke-Expression "[int64]$($Config.Min.Replace('MB','') * 1MB)")) `
-StartupBytes (Invoke-Expression "[int64]$($Config.Start)") `
-MaximumBytes (Invoke-Expression "[int64]$($Config.Max)") `
-Buffer $Config.Buffer
Write-Host "Dynamic Memory configured for $($Config.Name)"
}
A simpler loop approach:
$DevVMs = Get-VM | Where-Object { $_.Name -like "Dev-*" }
foreach ($VM in $DevVMs) {
Set-VMMemory -VMName $VM.Name -DynamicMemoryEnabled $true -StartupBytes 2GB -MinimumBytes 512MB -MaximumBytes 4GB -Buffer 20
}
Step 5 — Monitor Dynamic Memory in Real Time
View current memory allocation across all VMs:
Get-VM | Select-Object Name, MemoryAssigned, MemoryDemand, MemoryStatus, DynamicMemoryEnabled | Format-Table -AutoSize
Key columns:
- MemoryAssigned: Current amount of RAM allocated to the VM by the hypervisor
- MemoryDemand: Amount of RAM the guest OS is currently using (reported by the balloon driver)
- MemoryStatus: OK = demand is being met; Warning = host is under pressure; Low = VM is memory-constrained
Step 6 — View Memory Pressure on the Host
# View host memory counters via Performance Monitor:
Get-Counter -Counter "Hyper-V Dynamic Memory BalancerAverage Pressure" -SampleInterval 5 -MaxSamples 3
# Check total memory assigned vs total host memory:
$TotalAssigned = (Get-VM | Where-Object {$_.State -eq "Running"} | Measure-Object -Property MemoryAssigned -Sum).Sum / 1GB
$TotalHostRAM = (Get-WmiObject -Class Win32_ComputerSystem).TotalPhysicalMemory / 1GB
Write-Host "Total Assigned: $([math]::Round($TotalAssigned, 1)) GB / Total Host RAM: $([math]::Round($TotalHostRAM, 1)) GB"
Step 7 — Disable Dynamic Memory (Return to Static)
To disable Dynamic Memory and return to a static allocation (VM must be off):
Set-VMMemory -VMName "AppServer01" -DynamicMemoryEnabled $false -StartupBytes 4GB
Dynamic Memory Considerations
Dynamic Memory is not suitable for all workloads:
- Avoid for memory-locking applications: SQL Server, Oracle Database, and some Java applications pre-allocate and lock their memory pool. Balloon driver activity in these VMs can cause them to page excessively or behave unpredictably. For SQL Server, either disable Dynamic Memory or set the minimum equal to the maximum
- Domain Controllers: Domain controllers can tolerate Dynamic Memory, but set the minimum to at least 512MB to ensure the AD database stays in memory
- Guest OS support: Only Windows Server 2008 SP1+ and Windows 7 SP1+ guests include the Dynamic Memory balloon driver. Linux requires LIS with Dynamic Memory support
Summary
Hyper-V Dynamic Memory on Windows Server 2012 R2 is a powerful feature for increasing VM density on Hyper-V hosts by reclaiming and redistributing unused memory from idle VMs to those under load. Proper configuration of startup, minimum, and maximum memory values, combined with appropriate memory buffer percentages, allows the hypervisor to keep memory-intensive VMs well-supplied during peak loads while efficiently recovering unused memory from lighter workloads. Use memory weight to prioritise critical production VMs when the host is under memory pressure, and monitor MemoryStatus to ensure no VMs are operating in a memory-starved condition.