Are your VMs swapping ?: A fast check.

Recently I faced the horror of dealing with a very high overcommitted cluster and needed to assess the amount of memory usage quickly. Get-View PowerCli cmdlet stores the deepest secret of any virtual machine. This time I’m searching for those virtual machines that are swapping. Well it turns out the answer is called SwappedMemory and it goes – in a non-elegant but quick mode – like that:

$Result = Get-cluster <ClusterName> | Get-Vm | % { $D= $_ | Get-View | Select Summary; $VmName=$_.Name;$D.Summary.QuickStats | Select @{n="VM";e={$VmName}},SwappedMemory};$result | % {$X+= $_.SwappedMemory}; $X

If you get something greater than 1 then “Winter is coming…” for you 🙂 . The greater the number is, the coldest winter you’ll have. Run the following command so you can identify which VMs are affected by Swapping / Ballooned:

Get-Cluster <ClusterName> | Get-Vm | % { $D= $_ | Get-View | Select Summary; $VmName=$_.Name;$D.Summary.QuickStats | Select @{n="VM";e={$VmName}},BalloonedMemory, swappedmemory}

One possible cause of memory ballooning or swapping could be due to some memory limits. Check it on your VM settings or you can disable Memory Limits on several VMs using the following command:

Get-Cluster <ClusterName> | Get-Vm | Get-VMResourceConfiguration | ? {$_.;MemLimitMB -gt 0} | % { get-vm $_.vm | Get-VMResourceConfiguration | Set-VMResourceConfiguration -MemLimitMB $null}

Check VMware tools on the VMs and keep them updated so memctl is working as it should.

Sometimes you might find that VMs are still swapping but the Host is in a High State and memory is not overcommited, check what Duncan says about it, I think some old ESXi versions are not able to reset the swapping ram after a real lack of memory specially if ballooning / swapped amount of MB is equal to the current Host free memory.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s