Thursday, April 07 2011 08:32 Written by VMGuru
Earlier I posted an article that talked about what happens on an ESX Server when a virtual machine has a memory limit set lower than the amount of memory assigned to that virtual machine. Sound confusing? If so, head over and read the original blog post.
The short version is that the situation is simply not good, and has major performance implications across the ESX Host, and potentially across the whole infrastructure. Today, I want to show how you can simply identify and resolve this significant VMware Infrastructure issue using some simple PowerShell commands.
In order to use PowerShell scripting to resolve this issue you will need two components at a minimum:
- Windows PowerShell - Command line shell and scripting language that helps IT professionals achieve greater control and productivity
- VMware PowerCLI - Powerful yet simple command line interface for task based management of the VMware Infrastructure Platform
- Quest PowerGUI - Desktop application for novice and expert IT administrators leveraging Windows PowerShell scripts across their multi-platform virtual environments
Once you have the two required components installed on a Windows system you are well on your way to a whole new world of managing your VMware environment, but today we just want to focus on a small portion: Resolving memory limit configuration issues.
Start by opening the VMware PowerCLI console (Or the PowerGUI Script Editor if you installed PowerGUI). For the purpose of this post, I'm going to assume that everyone knows how to work with a console and hope that most people have some PowerShell experience. This post is not a "How to use PowerShell" tutorial.
Once you are in the VI Toolkit console, you must first connect to your ESX Host or VirtualCenter server using the following command: Replace the ServeName, myUsername, and myPassword with your own configuration.
Once you have a connection established you can query a list of Virtual Machine resource configuration settings with the following command:
This will provide a list of all virtual machines and their resource configuration settings. We can drill this down to identify only virtual machines whose memory limit is NOT set to unlimited with the following command:
If this command does not return any data, congratulations, you do not have any virtual machines that have a hard memory limit configured. If you do have objects that are returned, it means there are potential configuration errors for your virtual machines. What you optimally want is for all of your virtual machines to have their memory limit set to "unlimited". Again, using the capabilities of PowerShell, we can extend onto our command again to resolve any potential configuration issues.
It is important to note that the above script does not give you the option to ignore a particular VM. While I cannot personally think of any reason to modify this default behavior for Memory Limits, it doesn't mean a valid reason doesn't exist somewhere.
I know the changes can be made on the fly and on Live vms, but will the limit be removed with out a reboot? I have one machine that I "tested" with and removed it's limit, and it's still ballooning and swaping... thoughts?
I plan on running the script during an outage this weekend, and would just like to know if I have to bounce the vms too.
Cheers and thanks for the awesome 411.
Will do. So far the test machine hasn't dropped any ballooning size. back story is I recently started here and inherited this environment, the vm in question is hardest hit, looking at it I see a memory grant of 2GB but a limit set at 256MB (what were they thinking??) so the vm has 1.3GB ballooned and 201MB swapped. will monitor it throughout the day (removed limit 2Hrs ago) and will update later.