Resolving Rogue Memory Limits on your Virtual Machines

PDFPrintE-mail

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.

1
Connect-VIServer ServerName -User myUsername -Password myPassword

Once you have a connection established you can query a list of Virtual Machine resource configuration settings with the following command:

1
Get-VM | Get-VMResourceConfiguration

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:

1
Get-VM | Get-VMResourceConfiguration | where {$_.MemLimitMB -ne '-1'}

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.

1
Get-VM | Get-VMResourceConfiguration | where {$_.MemLimitMB -ne '-1'} | Set-VMResourceConfiguration -MemLimitMB $null

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.

Trackback(0)
Comments (4)Add Comment
Wade
April 11, 2011
199.246.153.2
Votes: +0
...

Hi Scott,
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.

Wade

VMGuru
April 11, 2011
98.228.170.78
Votes: +0
...

If I recall, what is written to swap will stay in swap until a hard reboot of the VM is performed (Power Off/Power On). The ballooning should not continue once the limit is removed unless the host itself is under memory contention. Once the limit is removed, the ballon should deflate and you should see the amount of memory consumed increase for that VM. I COULD be wrong though. I'd be interested in an update based on your testing!

Wade
April 11, 2011
199.246.153.2
Votes: +0
...

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.

Thanks again

Wade
April 13, 2011
199.246.153.2
Votes: +0
...

*UPDATE* Since original posting 2 days ago, the test vm has reduce swap to 104MB and balloon has stayed the same. Appears to be a very slow process...

Write comment
You must be logged in to post a comment. Please register if you do not have an account yet.

busy