Skip to content

Commit 3ef18c7

Browse files
vishesh92dhslove
authored andcommitted
engine/orchestration: Update overcommit ratio during live VM migration (apache#9178)
During live migration of a VM from between hosts having different cgroup versions (cgroupv2 & cgroup), overcommit ratio is ignored. This PR fixes the above issue.
1 parent e0669f8 commit 3ef18c7

File tree

3 files changed

+31
-15
lines changed

3 files changed

+31
-15
lines changed

api/src/main/java/com/cloud/vm/VirtualMachineProfile.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@ public boolean equals(Object obj) {
193193

194194
Map<Param, Object> getParameters();
195195

196+
void setCpuOvercommitRatio(Float cpuOvercommitRatio);
197+
198+
void setMemoryOvercommitRatio(Float memoryOvercommitRatio);
199+
196200
Float getCpuOvercommitRatio();
197201

198202
Float getMemoryOvercommitRatio();

engine/components-api/src/main/java/com/cloud/vm/VirtualMachineProfileImpl.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,11 +264,13 @@ public void setServiceOffering(ServiceOffering offering) {
264264
_offering = offering;
265265
}
266266

267+
@Override
267268
public void setCpuOvercommitRatio(Float cpuOvercommitRatio) {
268269
this.cpuOvercommitRatio = cpuOvercommitRatio;
269270

270271
}
271272

273+
@Override
272274
public void setMemoryOvercommitRatio(Float memoryOvercommitRatio) {
273275
this.memoryOvercommitRatio = memoryOvercommitRatio;
274276

engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,21 +1235,9 @@ public void orchestrateStart(final String vmUuid, final Map<VirtualMachineProfil
12351235

12361236
long destHostId = dest.getHost().getId();
12371237
vm.setPodIdToDeployIn(dest.getPod().getId());
1238-
final Long cluster_id = dest.getCluster().getId();
1239-
final ClusterDetailsVO cluster_detail_cpu = _clusterDetailsDao.findDetail(cluster_id, VmDetailConstants.CPU_OVER_COMMIT_RATIO);
1240-
final ClusterDetailsVO cluster_detail_ram = _clusterDetailsDao.findDetail(cluster_id, VmDetailConstants.MEMORY_OVER_COMMIT_RATIO);
1241-
1242-
if (userVmDetailsDao.findDetail(vm.getId(), VmDetailConstants.CPU_OVER_COMMIT_RATIO) == null &&
1243-
(Float.parseFloat(cluster_detail_cpu.getValue()) > 1f || Float.parseFloat(cluster_detail_ram.getValue()) > 1f)) {
1244-
userVmDetailsDao.addDetail(vm.getId(), VmDetailConstants.CPU_OVER_COMMIT_RATIO, cluster_detail_cpu.getValue(), true);
1245-
userVmDetailsDao.addDetail(vm.getId(), VmDetailConstants.MEMORY_OVER_COMMIT_RATIO, cluster_detail_ram.getValue(), true);
1246-
} else if (userVmDetailsDao.findDetail(vm.getId(), VmDetailConstants.CPU_OVER_COMMIT_RATIO) != null) {
1247-
userVmDetailsDao.addDetail(vm.getId(), VmDetailConstants.CPU_OVER_COMMIT_RATIO, cluster_detail_cpu.getValue(), true);
1248-
userVmDetailsDao.addDetail(vm.getId(), VmDetailConstants.MEMORY_OVER_COMMIT_RATIO, cluster_detail_ram.getValue(), true);
1249-
}
1238+
final Long clusterId = dest.getCluster().getId();
1239+
updateOverCommitRatioForVmProfile(vmProfile, clusterId);
12501240

1251-
vmProfile.setCpuOvercommitRatio(Float.parseFloat(cluster_detail_cpu.getValue()));
1252-
vmProfile.setMemoryOvercommitRatio(Float.parseFloat(cluster_detail_ram.getValue()));
12531241
StartAnswer startAnswer = null;
12541242

12551243
try {
@@ -1264,7 +1252,7 @@ public void orchestrateStart(final String vmUuid, final Map<VirtualMachineProfil
12641252
resetVmNicsDeviceId(vm.getId());
12651253
_networkMgr.prepare(vmProfile, dest, ctx);
12661254
if (vm.getHypervisorType() != HypervisorType.BareMetal) {
1267-
checkAndAttemptMigrateVmAcrossCluster(vm, cluster_id, dest.getStorageForDisks());
1255+
checkAndAttemptMigrateVmAcrossCluster(vm, clusterId, dest.getStorageForDisks());
12681256
volumeMgr.prepare(vmProfile, dest);
12691257
}
12701258

@@ -1510,6 +1498,27 @@ private void addToNetworkNameMap(long networkId, long dataCenterId, Map<Long, St
15101498
}
15111499
networkToNetworkNameMap.put(networkVO.getId(), networkName);
15121500
}
1501+
1502+
private void updateOverCommitRatioForVmProfile(VirtualMachineProfile vmProfile, long clusterId) {
1503+
final ClusterDetailsVO clusterDetailCpu = _clusterDetailsDao.findDetail(clusterId, VmDetailConstants.CPU_OVER_COMMIT_RATIO);
1504+
final ClusterDetailsVO clusterDetailRam = _clusterDetailsDao.findDetail(clusterId, VmDetailConstants.MEMORY_OVER_COMMIT_RATIO);
1505+
final float parsedClusterCpuDetailCpu = Float.parseFloat(clusterDetailCpu.getValue());
1506+
final float parsedClusterDetailRam = Float.parseFloat(clusterDetailRam.getValue());
1507+
UserVmDetailVO vmDetailCpu = userVmDetailsDao.findDetail(vmProfile.getId(), VmDetailConstants.CPU_OVER_COMMIT_RATIO);
1508+
UserVmDetailVO vmDetailRam = userVmDetailsDao.findDetail(vmProfile.getId(), VmDetailConstants.MEMORY_OVER_COMMIT_RATIO);
1509+
1510+
if ((vmDetailCpu == null && parsedClusterCpuDetailCpu > 1f) ||
1511+
(vmDetailCpu != null && Float.parseFloat(vmDetailCpu.getValue()) != parsedClusterCpuDetailCpu)) {
1512+
userVmDetailsDao.addDetail(vmProfile.getId(), VmDetailConstants.CPU_OVER_COMMIT_RATIO, clusterDetailCpu.getValue(), true);
1513+
}
1514+
if ((vmDetailRam == null && parsedClusterDetailRam > 1f) ||
1515+
(vmDetailRam != null && Float.parseFloat(vmDetailRam.getValue()) != parsedClusterDetailRam)) {
1516+
userVmDetailsDao.addDetail(vmProfile.getId(), VmDetailConstants.MEMORY_OVER_COMMIT_RATIO, clusterDetailRam.getValue(), true);
1517+
}
1518+
1519+
vmProfile.setCpuOvercommitRatio(Float.parseFloat(clusterDetailCpu.getValue()));
1520+
vmProfile.setMemoryOvercommitRatio(Float.parseFloat(clusterDetailRam.getValue()));
1521+
}
15131522

15141523
/**
15151524
* Setting pod id to null can result in migration of Volumes across pods. This is not desirable for VMs which
@@ -2740,6 +2749,7 @@ protected void migrate(final VMInstanceVO vm, final long srcHostId, final Deploy
27402749
_networkMgr.prepareNicForMigration(profile, dest);
27412750
volumeMgr.prepareForMigration(profile, dest);
27422751
profile.setConfigDriveLabel(VmConfigDriveLabel.value());
2752+
updateOverCommitRatioForVmProfile(profile, dest.getHost().getClusterId());
27432753

27442754
final VirtualMachineTO to = toVmTO(profile);
27452755
final PrepareForMigrationCommand pfmc = new PrepareForMigrationCommand(to);

0 commit comments

Comments
 (0)