Hot-remove memory in a Linux virtual machine

Linux supports hot-adding memory when running as a VM guest, in VMware for example. (Sometimes you need to manually inform the guest OS.)

Is there a safe way to do the inverse operation — reducing the amount of memory allocated to a virtual machine, and if so, do you need to manually inform the Linux guest before such an operation? (If so, is the procedure specific to VMware tools, or is it generic for any kind of virtualization mechanism?)


Solution 1:

ESXi doesn't support hot-removing memory or CPUs from a VM. Someone I met in the pub a couple of months ago told me that the sister of a friend of his cousin *cough* got the answer that virtually no customer demands this feature. In other words: It doesn't pay to bother implementing hot-remove.

If you want ESXi to support this, go to VMware and tell them. The more people do, the higher the chances they'll implement it.

Solution 2:

I can not say for sure in vmware, but when using kvm decreasing memory of a running virtual machine works fine. Of course up to a limit, but the software will tell you. When you decrease it the memory in the virtual machine will gradually be lowered, until it can't be lowered any further. If you set the memory to be lower than where it stopped you will need to reboot the virtual machine to have it lowered completely.

I recently did that on a system running kvm with about 20 virtual machines, where someone thought it wise to over commit memory, causing some virtual machines to run in swap (doh!). To fix it I lowered the memory by about 20-40% of 2/3 of the virtual machines and most were able to lower it completely while running. A few needed a reboot to have the new memory setting take effect completely.

Going from that I would assume a vmware virtual machine could allow this behaviour as well. However a quick test in vmware player tells me that it will need a reboot to take effect (fancier vmware software may behave nicer). Otherwise it is safe to do so on a running system. Of course whether the amount of memory it is left with is enough to run it correctly is another matter.