Since Windows Server 2008 R2, the Dynamic Memory feature of Hyper-V was introduced. We can configure the minimum and maximum RAM value of a Virtual Machine with this feature. It also enable
us to change the Hyper-V host memory resource priority related settings.
Windows Guest VM
With Windows Server 2012 or later, a running Dynamic Memory supported Windows guest virtual machines can Hot-Add memory. You can use the following steps to hot-add memory to a running guest VM.
1. Open Hyper-V Manager -> right click the virtual machine -> settings.
2. Click Memory-> Input the new maximum memory value -> Apply -> OK. (Figure 1)
Figure 1 Adjust the maximum RAM value.
After we modify the Maximum RAM value, the guest VM can use the added memory immediately.
Linux Guest VM
With CentOS, Red Hat Enterprise Linux and Oracle Linux guest VM, you will notice that they cannot use the Hot-Added memory immediately. It is due to that there are some limitations.
1. This feature only available on 64-bit virtual machines and the specific Linux distributions.
a) CentOS 6.5 and 7.0 can use the Hot-Add memory feature when the Hyper-V host is Server 2008 R2 or later.
b) Oracle Linux 6.5 can use the Hot-Add memory feature, the Hyper-V host can be Server 2012 or later Hyper-V.
c) SUSE Linux 11 SP3 can use the Hot-Add Memory feature, the Hyper-V host can be Server 2012 or later Hyper-V.
2. By default, Hot-Add must be enabled manually on CentOS and Oracle Linux.
For Linux VMs, we can use same steps as Windows guest VMs to enable the Hot-Add memory feature in Hyper-V manager. Then, we need to configure the following in guest VMs.
a) Create a file “/etc/udev/rules.d/100-balloon.rules”. (You may use any other desired name for the file)
b) Add the following content to the file: SUBSYSTEM=="memory", ACTION=="add", ATTR{state}="online" (Figure 2)
c) Reboot the system to enable the Hot-Add support.
Figure 2 Add the Hot-Add configure file.
Now, when we find that our Linux server at a high memory utilization, we can assign more memory resource to it in real time. (Figure 3 & 4)
Figure 3 Use the stress tool give system a memory stress test.
Figure 4 System use the added memory immediately.
Note: Please don't use the stress test tool on your product environment computer, it may crash your VM or get high workload.
However, the operation may fail if the guest operating system is running with low memory. Here are some best practices:
1. Startup memory and minimal memory should be equal to or greater than the amount of memory that the distribution vendor recommends.
2. Applications that tend to consume the entire available memory on a system should be limited to consuming up to 80 percent of available RAM.
3. If you are using Dynamic Memory on a Windows Server 2012 operating system, specifyStartup memory, Minimum memory, and Maximum memory parameters in multiples of 128 megabytes (MB).
If you need further assistance, welcome to post your questions in the Hyper-V forum.
Please click to vote if the post helps you. This can be beneficial to other community members reading the thread.