I have recently been having a large number of calls from clients regarding slow responding VM's. Upon investigating the VMs I have often found that they are ballooning and the MEMCTL driver is showing as active in ESXTOP.
After looking over the ESX/ESXI server there appears to be plenty of free memory, VMware tools is up to date and Virtual hardware is level 7.
I then looked at the VMs settings from the "Edit settings" of the VM in vCenter. I Then went to the resources tab and could see there were a problem.....
For some reason there were limits on the memory for less than the memory granted at the configuration of the VM. I asked why these were set and the customers all say they have not set these settings. Once the limits are moved the VM ballooning stops and the machines start to respond ok.
It was then clear that the majority of all VMs had these limits on them, some causing problems and some just set to the memory of the VM. On a vCenter with 500+ VMs it is very time consuming to remove all of these. I had a quick Google to see if there was a Powershell script to do it, why make one if someone else has already, found a very helpful script that someone had already created. I checked the script over and then ran it in the vSPhere Power CLI
"
Connect-VIServer
$ResourceAllocationInfo = New-Object VMware.Vim.ResourceAllocationInfo
$ResourceAllocationInfo.Limit = -1
# Get the Managed object for each VM
Foreach ($VM in get-vm | get-view) {
# Create a fresh VirtualMachineConfigSpec
$VirtualMachineConfigSpec = New-object VMware.Vim.VirtualMachineConfigSpec
$i = 0
# If the CPU Allocation is not unlimited add CPU to our spec.
IF ($VM.ResourceConfig.CpuAllocation.Limit -ne -1) {
$VirtualMachineConfigSpec.cpuAllocation = $ResourceAllocationIn
$i++
}
# If the Memory Allocation is not unlimited add Memory to our spec.
IF ($VM.ResourceConfig.MemoryAllocation.Limit -ne -1) {
$VirtualMachineConfigSpec.memoryAllocation = $ResourceAllocationInfo
$i++
}
# If $I is gt 0 then we have a VM to fix... Trigger the reconfig task.
IF ($I -gt 0) {
write-verbose "Removing limits on $($VM.Name)"
[void]$VM.ReconfigVM_Task($VirtualMachineConfigSpec)
}
}
"$ResourceAllocationInfo = New-Object VMware.Vim.ResourceAllocationInfo
$ResourceAllocationInfo.Limit = -1
# Get the Managed object for each VM
Foreach ($VM in get-vm | get-view) {
# Create a fresh VirtualMachineConfigSpec
$VirtualMachineConfigSpec = New-object VMware.Vim.VirtualMachineConfigSpec
$i = 0
# If the CPU Allocation is not unlimited add CPU to our spec.
IF ($VM.ResourceConfig.CpuAllocation.Limit -ne -1) {
$VirtualMachineConfigSpec.cpuAllocation = $ResourceAllocationIn
$i++
}
# If the Memory Allocation is not unlimited add Memory to our spec.
IF ($VM.ResourceConfig.MemoryAllocation.Limit -ne -1) {
$VirtualMachineConfigSpec.memoryAllocation = $ResourceAllocationInfo
$i++
}
# If $I is gt 0 then we have a VM to fix... Trigger the reconfig task.
IF ($I -gt 0) {
write-verbose "Removing limits on $($VM.Name)"
[void]$VM.ReconfigVM_Task($VirtualMachineConfigSpec)
}
}
I take no responsibility for this script so please be careful. You will see all the tasks in vCenter for when the settings are being set to unlimited.
Thanks
No comments:
Post a Comment