VMGuru.com - Home of the Virtualization Gurus

Our Books REALLY are Available Now!

Don’t become overwhelmed by your VMware Infrastructure project. Use the books that tens of thousands of others have used to design, plan, and implement their virtual infrastructures.Download Now!

Resolving Improper Memory Limits on your Virtual Machines PDF Print
Written by Scott Herold   
Monday, 11 May 2009 12:14

Last week 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:

1.       Microsoft Windows PowerShell – Command line shell and scripting language that helps IT professionals achieve greater control and productivity (I ripped this off from Microsoft’s website)

2.       VMware Infrastructure Toolkit – Powerful yet simple command line interface for task based management of the VMware Infrastructure Platform (again, stolen)

3.       {OPTIONAL] Virtualizaiton EcoShell  – 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 VI Toolkit” console (Or the VESI Script Editor if you installed Virtualization EcoShell).  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, username, and password with your own configuration.

Connect-VIServer ServerName –User username –Password password


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

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:

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.  Note the backtick at the end of the first line.  This indicates the command should continue as if it were on a single line, but I ran out of space.

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.  Because of this, I have created a fully interactive script that allows someone to Query all VM Configurations, Identify potential configuration errors, and Resolve select virtual machines.  The QueryMem.ps1 file, which is attached at the bottom of this blog post, can be used in one of three modes:

Query Resource Allocations:

     QueryMem.ps1 -VMHost server1.domain.com -User administrator -Password passw0rd -Action query

Idenfity Potential Misconfigurations:

     QueryMem.ps1 -VMHost server1.domain.com -User administrator -Password passw0rd -Action id

Modify Misconfigured VMs:

     QueryMem.ps1 -VMHost server1.domain.com -User administrator -Password passw0rd -Action resolve `
          -vm vm1, vm2, vm3

Attachments:
FileDescriptionFile sizeDownloads
Download this file (QueryMem.ps1)QueryMem.ps1PowerShell sacript to identify and resolve Memory Limit configuration issues2 Kb531
Trackback(0)
Comments (3)Add Comment
Erik
Erik
June 03, 2009
Votes: +0
How did the limits get there?

Based on the articles, I checked my memory limits with the powershell script. Sure enough, memory limits existed. I was a bit stumped because I haven't explicitly set any limits. Checked my resource pools, and they indeed were unlimited. Decided to check the individual VMs, and there they were set.

Do the individual VMs get this because they are built from a template?

At any rate, thanks for the scripts to detect and fix the issue.

Rasmus Jensen
Rasmus Jensen
June 10, 2009
Votes: +0
...

From my experience the limit comes from either settings in the template, from where the VM orignates, or some kind of bug (as Scott mentions in his first post).
I have seen templates configured with 256MB ram (Not as a limit, but as a memory configuration) which turns out to be set as a limit, once deployed to a VM.

jason robinson
jason robinson
August 03, 2009
Votes: +0
...

I am not sure if this is a bug or feature of DRS but I have also noticed that when you remove a host from a DRS enabled cluster and add the host back to the cluster all of the vm's on that host now have memory limits set. We ran into this with several of our vms.

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

busy
 

Buy on Amazon