Should I Allocate More Memory?

So let’s attempt to answer this question: “Should I add more memory to a Virtual Machine?”  To which my answer is “It Depends….”

The simple answer is this “High guest OS memory usage with no ballooning or virtual machine sway indicates the need to add more memory to the virtual” –Scott Lowe, Mastering VMware vSphere 4. It should be noted though that Scott’s statement implies that everything is working correctly in the guest OS. If you have a buggy program, script etc.,  it may hog all the memory you give it regardless.

Of course now I should talk about the balloon and swapping that Scott’s mentions.

This picture shows a VM which does not need memory added to it. The guest is using about a quarter of its memory. If this was taken over a period of a week or a month, I might even go so far as to say you could lower the allocated memory to this VM.

Looking at the picture we also see that the guest is not swapping or ballooning either.

Ballooning:


Ballooning occurs when the host on which the virtual machine is running becomes constrained on memory. VMware says that the ballooning causes the guest to become aware of the host’s low memory; however that is not the way I generally look at it. To me it seems as though the guest is just interacting with a process and is still unaware of the host…but then again, I am not VMware :).

Let’s explain this with an example. A host is constrained on memory and needs to get some of that memory back. The host has no idea what memory pages the guest/VM is actively using and which memory pages are free, so it also has no idea which memory pages can be reclaimed from the guest. VMware Tools has a balloon driver, and this driver/process is started on the guest. This driver starts requesting memory pages from the guest in order to “inflate” the balloon with memory pages it doesn’t need. Once the guest allocates the memory to the balloon driver, the driver notifies the hypervisor in order for the hypervisor to reclaim the host physical pages that are backing the balloon driver. Page 9 Understanding Memory Resource Management in VMware

Once those pages have been reclaimed, the host can allocates those pages somewhere else.

Swapping:


This one is fortunately much easier to explain. From the vSphere Resource Management Guide:

“ESX/ESXi hosts use swapping to forcibly reclaim memory from a virtual machine when the VMmemctl(balloon) driver is not available or is not responsive.”

Swapping is, to put it simply, using a swap file  to act as memory/RAM for the machine. Using a swap file as memory for a VM is Much slower than using the physical RAM so it is usually something you don’t want to happen. The guest memory is “swapped” to the swap file instead of physical memory

From the quote, the host will force the VM to swap when the balloon driver is not able to reclaim the memory. Swapping will also occur if you set a Limit on you memory resource in a VM that is less than the configured memory for the VM. If you use Edit Settings-Resource tab on a VM, you can set the memory limit, which tells the VM how much host physical memory it may use. If you set that to be less than the configured memory allocation, the VM will make up the rest of the memory in swap. So If memory limit< configured memory allocation, then  memory limit(physical) +swap = configured memory allocation.

If you do have a VM with high memory usage in the guest OS with no balloon or swapping, there is a good chance that it needs more memory. However if there is swapping or ballooning, the host is under memory contention and you should maybe migrate some VMs around or investigate further.

Hope this helps. Please drop me a line in the comments.

Leave a Reply