This is an automated email from the ASF dual-hosted git repository. rohit pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/cloudstack.git
The following commit(s) were added to refs/heads/master by this push: new 65f31f1 kvm: Agent should not check if remaining memory on host is sufficient (#2766) 65f31f1 is described below commit 65f31f1a9fbc1c20cd752d80a7e1117efc0248a5 Author: Wido den Hollander <w...@widodh.nl> AuthorDate: Wed Aug 8 08:44:26 2018 +0200 kvm: Agent should not check if remaining memory on host is sufficient (#2766) When a Instance is (attempted to be) started in KVM Host the Agent should not worry about the allocated memory on this host. To make a proper judgement we need to take more into account: - Memory Overcommit ratio - Host reserved memory - Host overcommit memory The Management Server has all the information and the DeploymentPlanner has to make the decision if a Instance should and can be started on a Host, not the host itself. Signed-off-by: Wido den Hollander <w...@widodh.nl> --- .../kvm/resource/LibvirtComputingResource.java | 6 ----- .../wrapper/LibvirtStartCommandWrapper.java | 26 ---------------------- .../kvm/resource/LibvirtComputingResourceTest.java | 1 - 3 files changed, 33 deletions(-) diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java index 3983b18..ed87974 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java @@ -277,7 +277,6 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv protected int _rngRateBytes = 2048; private File _qemuSocketsPath; private final String _qemuGuestAgentSocketName = "org.qemu.guest_agent.0"; - private long _totalMemory; protected WatchDogAction _watchDogAction = WatchDogAction.NONE; protected WatchDogModel _watchDogModel = WatchDogModel.I6300ESB; @@ -2603,7 +2602,6 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv public StartupCommand[] initialize() { final List<Object> info = getHostInfo(); - _totalMemory = (Long)info.get(2); final StartupRoutingCommand cmd = new StartupRoutingCommand((Integer)info.get(0), (Long)info.get(1), (Long)info.get(2), (Long)info.get(4), (String)info.get(3), _hypervisorType, @@ -3792,10 +3790,6 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv } } - public long getTotalMemory() { - return _totalMemory; - } - public String getHostDistro() { return _hostDistro; } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtStartCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtStartCommandWrapper.java index 5a75f07..fd5f2fa 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtStartCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtStartCommandWrapper.java @@ -24,7 +24,6 @@ import java.util.List; import org.apache.log4j.Logger; import org.libvirt.Connect; -import org.libvirt.Domain; import org.libvirt.DomainInfo.DomainState; import org.libvirt.LibvirtException; @@ -65,13 +64,6 @@ public final class LibvirtStartCommandWrapper extends CommandWrapper<StartComman vm = libvirtComputingResource.createVMFromSpec(vmSpec); conn = libvirtUtilitiesHelper.getConnectionByType(vm.getHvsType()); - Long remainingMem = getFreeMemory(conn, libvirtComputingResource); - if (remainingMem == null){ - return new StartAnswer(command, "failed to get free memory"); - } else if (remainingMem < vmSpec.getMinRam()) { - return new StartAnswer(command, "Not enough memory on the host, remaining: " + remainingMem + ", asking: " + vmSpec.getMinRam()); - } - final NicTO[] nics = vmSpec.getNics(); for (final NicTO nic : nics) { @@ -160,22 +152,4 @@ public final class LibvirtStartCommandWrapper extends CommandWrapper<StartComman } } } - - private Long getFreeMemory(final Connect conn, final LibvirtComputingResource libvirtComputingResource){ - try { - long allocatedMem = 0; - int[] ids = conn.listDomains(); - for(int id :ids) { - Domain dm = conn.domainLookupByID(id); - allocatedMem += dm.getMaxMemory() * 1024L; - s_logger.debug("vm: " + dm.getName() + " mem: " + dm.getMaxMemory() * 1024L); - } - Long remainingMem = libvirtComputingResource.getTotalMemory() - allocatedMem; - s_logger.debug("remaining mem" + remainingMem); - return remainingMem; - } catch (Exception e) { - s_logger.debug("failed to get free memory", e); - return null; - } - } } diff --git a/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java b/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java index be191f5..adadc1f 100644 --- a/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java +++ b/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java @@ -5038,7 +5038,6 @@ public class LibvirtComputingResourceTest { when(conn.domainLookupByID(vmId)).thenReturn(dm); when(dm.getMaxMemory()).thenReturn(1024L); when(dm.getName()).thenReturn(vmName); - when(libvirtComputingResource.getTotalMemory()).thenReturn(2048*1024L); doNothing().when(libvirtComputingResource).createVbd(conn, vmSpec, vmName, vmDef); } catch (final LibvirtException e) { fail(e.getMessage());