CLOUDSTACK-4498 we should not reserve memory and cpu for vmware VMs if the

vmware.reserve.cpu and vmware.reserve.mem are set to false while not overcommiting

Signed-off-by: Jayapal <jayapal@apache.org>
This commit is contained in:
Bharat Kumar 2013-12-09 12:34:04 +05:30 committed by Jayapal
parent d715058fa1
commit 36cbc2dfbf
3 changed files with 60 additions and 16 deletions

View File

@ -27,8 +27,12 @@ import java.util.UUID;
import javax.ejb.Local;
import javax.inject.Inject;
import com.cloud.dc.dao.ClusterDao;
import com.cloud.vm.dao.VMInstanceDao;
import org.apache.log4j.Logger;
import org.apache.cloudstack.framework.config.ConfigKey;
import org.apache.cloudstack.framework.config.Configurable;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.cloudstack.storage.command.CopyCommand;
import org.apache.cloudstack.storage.to.VolumeObjectTO;
@ -92,8 +96,8 @@ import com.cloud.vm.VirtualMachineProfile;
import com.cloud.vm.VmDetailConstants;
import com.cloud.vm.dao.NicDao;
@Local(value = HypervisorGuru.class)
public class VMwareGuru extends HypervisorGuruBase implements HypervisorGuru {
@Local(value=HypervisorGuru.class)
public class VMwareGuru extends HypervisorGuruBase implements HypervisorGuru, Configurable {
private static final Logger s_logger = Logger.getLogger(VMwareGuru.class);
@Inject
@ -121,12 +125,21 @@ public class VMwareGuru extends HypervisorGuruBase implements HypervisorGuru {
@Inject
PhysicalNetworkTrafficTypeDao _physicalNetworkTrafficTypeDao;
@Inject
ClusterManager _clusterMgr;
VMInstanceDao _vmDao;
@Inject
ClusterDao _clusterDao;
@Inject ClusterManager _clusterMgr;
protected VMwareGuru() {
super();
}
static final ConfigKey<Boolean> VmwareReserveCpu = new ConfigKey<Boolean>(Boolean.class, "vmware.reserve.cpu", "Advanced", "false",
"Specify whether or not to reserve CPU when not overprovisioning, In case of cpu overprovisioning we will always reserve cpu.", true, ConfigKey.Scope.Cluster, null);
static final ConfigKey<Boolean> VmwareReserveMemory = new ConfigKey<Boolean>(Boolean.class, "vmware.reserve.cpu", "Advanced", "false",
"Specify whether or not to reserve memory when not overprovisioning, In case of memory overprovisioning we will always reserve memory.", true, ConfigKey.Scope.Cluster, null);
@Override
public HypervisorType getHypervisorType() {
return HypervisorType.VMware;
@ -187,7 +200,9 @@ public class VMwareGuru extends HypervisorGuruBase implements HypervisorGuru {
break;
}
}
long clusterId = _hostDao.findById( _vmDao.findById(vm.getId()).getHostId()).getClusterId();
details.put(Config.VmwareReserveCpu.key(), VmwareReserveCpu.valueIn(clusterId).toString());
details.put(Config.VmwareReserveMem.key(), VmwareReserveMemory.valueIn(clusterId).toString());
to.setDetails(details);
if (vm.getVirtualMachine() instanceof DomainRouterVO) {
@ -436,4 +451,14 @@ public class VMwareGuru extends HypervisorGuruBase implements HypervisorGuru {
}
return commands;
}
@Override
public String getConfigComponentName() {
return VMwareGuru.class.getSimpleName();
}
@Override
public ConfigKey<?>[] getConfigKeys() {
return new ConfigKey<?>[] {VmwareReserveCpu, VmwareReserveMemory};
}
}

View File

@ -548,8 +548,6 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw
params.put("vm.instancename.flag", _instanceNameFlag);
params.put("service.console.name", _serviceConsoleName);
params.put("management.portgroup.name", _managemetPortGroupName);
params.put("vmware.reserve.cpu", _reserveCpu);
params.put("vmware.reserve.mem", _reserveMem);
params.put("vmware.root.disk.controller", _rootDiskController);
params.put("vmware.recycle.hung.wokervm", _recycleHungWorker);
params.put("ports.per.dvportgroup", _portsPerDvPortGroup);

View File

@ -45,6 +45,9 @@ import java.util.concurrent.TimeUnit;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
import com.cloud.configuration.Config;
import com.cloud.agent.api.routing.*;
import org.apache.log4j.Logger;
import org.apache.log4j.NDC;
@ -362,10 +365,9 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
protected int _portsPerDvPortGroup;
protected boolean _fullCloneFlag = false;
protected boolean _instanceNameFlag = false;
protected boolean _reserveCpu;
protected boolean _reserveMem;
protected boolean _reserveCpu = false;
protected boolean _reserveMem = false;
protected boolean _recycleHungWorker = false;
protected DiskControllerType _rootDiskController = DiskControllerType.ide;
@ -2700,7 +2702,6 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
vmMo.tearDownDevices(new Class<?>[] {VirtualEthernetCard.class});
vmMo.ensureScsiDeviceController();
} else {
int ramMb = (int)(vmSpec.getMinRam() / (1024 * 1024));
Pair<ManagedObjectReference, DatastoreMO> rootDiskDataStoreDetails = null;
for (DiskTO vol : disks) {
if (vol.getType() == Volume.Type.ROOT) {
@ -2717,9 +2718,9 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
dcMo.getMor(), false);
}
if (!hyperHost.createBlankVm(vmNameOnVcenter, vmInternalCSName, vmSpec.getCpus(), vmSpec.getMaxSpeed().intValue(), vmSpec.getMinSpeed(),
vmSpec.getLimitCpuUse(), (int)(vmSpec.getMaxRam() / (1024 * 1024)), ramMb, translateGuestOsIdentifier(vmSpec.getArch(), vmSpec.getOs()).value(),
rootDiskDataStoreDetails.first(), false)) {
if (!hyperHost.createBlankVm(vmNameOnVcenter, vmInternalCSName, vmSpec.getCpus(), vmSpec.getMaxSpeed().intValue(),
getReservedCpuMHZ(vmSpec), vmSpec.getLimitCpuUse(),(int)(vmSpec.getMaxRam()/(1024*1024)), getReservedMemoryMb(vmSpec),
translateGuestOsIdentifier(vmSpec.getArch(), vmSpec.getOs()).value(), rootDiskDataStoreDetails.first(), false)) {
throw new Exception("Failed to create VM. vmName: " + vmInternalCSName);
}
}
@ -2743,11 +2744,11 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
}
VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
int ramMb = (int)(vmSpec.getMinRam() / (1024 * 1024));
String guestOsId = translateGuestOsIdentifier(vmSpec.getArch(), vmSpec.getOs()).value();
VmwareHelper.setBasicVmConfig(vmConfigSpec, vmSpec.getCpus(), vmSpec.getMaxSpeed(), vmSpec.getMinSpeed(), (int)(vmSpec.getMaxRam() / (1024 * 1024)), ramMb,
guestOsId, vmSpec.getLimitCpuUse());
VmwareHelper.setBasicVmConfig(vmConfigSpec, vmSpec.getCpus(), vmSpec.getMaxSpeed(),
getReservedCpuMHZ(vmSpec),(int) (vmSpec.getMaxRam()/(1024*1024)), getReservedMemoryMb(vmSpec),
guestOsId, vmSpec.getLimitCpuUse());
// Check for hotadd settings
vmConfigSpec.setMemoryHotAddEnabled(vmMo.isMemoryHotAddSupported(guestOsId));
@ -3003,6 +3004,26 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
}
}
int getReservedMemoryMb(VirtualMachineTO vmSpec) {
if (vmSpec.getDetails().get(Config.VmwareReserveMem.key()).equalsIgnoreCase("true")) {
return (int) (vmSpec.getMinRam() / (1024 * 1024));
} else if (vmSpec.getMinRam() != vmSpec.getMaxRam()) {
s_logger.warn("memory overprovisioning factor is set to "+ (vmSpec.getMaxRam()/vmSpec.getMinRam())+" ignoring the flag vmware.reserve.mem");
return (int) (vmSpec.getMinRam() / (1024 * 1024));
}
return 0;
}
int getReservedCpuMHZ(VirtualMachineTO vmSpec) {
if (vmSpec.getDetails().get(Config.VmwareReserveCpu.key()).equalsIgnoreCase("true")) {
return vmSpec.getMinSpeed();
}else if (vmSpec.getMinSpeed().intValue() != vmSpec.getMaxSpeed().intValue()) {
s_logger.warn("cpu overprovisioning factor is set to "+ (vmSpec.getMaxSpeed().intValue()/vmSpec.getMinSpeed().intValue())+" ignoring the flag vmware.reserve.cpu");
return vmSpec.getMinSpeed();
}
return 0;
}
// return the finalized disk chain for startup, from top to bottom
private String[] syncDiskChain(DatacenterMO dcMo, VirtualMachineMO vmMo, VirtualMachineTO vmSpec, DiskTO vol, VirtualMachineDiskInfo diskInfo,
HashMap<String, Pair<ManagedObjectReference, DatastoreMO>> dataStoresDetails) throws Exception {