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 <wido@widodh.nl>
This commit is contained in:
Wido den Hollander 2018-08-08 08:44:26 +02:00 committed by Rohit Yadav
parent 75030e5522
commit 65f31f1a9f
3 changed files with 0 additions and 33 deletions

View File

@ -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;
}

View File

@ -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;
}
}
}

View File

@ -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());