Skip to content

Commit dc5e4f3

Browse files
yadvrDaanHoogland
andauthored
Allow KVM overcommit to work without reducing minimum VM memory when vm ballooning is disabled (#7810)
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com> Co-authored-by: dahn <daan.hoogland@gmail.com> Co-authored-by: Daan Hoogland <daan@onecht.net>
1 parent 6b21825 commit dc5e4f3

File tree

4 files changed

+24
-22
lines changed

4 files changed

+24
-22
lines changed

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2780,15 +2780,10 @@ protected GuestResourceDef createGuestResourceDef(VirtualMachineTO vmTO){
27802780

27812781
grd.setMemBalloning(!_noMemBalloon);
27822782

2783-
long maxRam = ByteScaleUtils.bytesToKibibytes(vmTO.getMaxRam());
2784-
long currRam = vmTO.getType() == VirtualMachine.Type.User ? getCurrentMemAccordingToMemBallooning(vmTO, maxRam) : maxRam;
2785-
2786-
if (s_logger.isTraceEnabled()) {
2787-
s_logger.trace(String.format("memory values for VM %s are %d/%d",vmTO.getName(),maxRam, currRam));
2788-
}
2783+
Long maxRam = ByteScaleUtils.bytesToKibibytes(vmTO.getMaxRam());
27892784

27902785
grd.setMemorySize(maxRam);
2791-
grd.setCurrentMem(currRam);
2786+
grd.setCurrentMem(getCurrentMemAccordingToMemBallooning(vmTO, maxRam));
27922787

27932788
int vcpus = vmTO.getCpus();
27942789
Integer maxVcpus = vmTO.getVcpuMaxLimit();
@@ -2800,12 +2795,17 @@ protected GuestResourceDef createGuestResourceDef(VirtualMachineTO vmTO){
28002795
}
28012796

28022797
protected long getCurrentMemAccordingToMemBallooning(VirtualMachineTO vmTO, long maxRam) {
2798+
long retVal = maxRam;
28032799
if (_noMemBalloon) {
28042800
s_logger.warn(String.format("Setting VM's [%s] current memory as max memory [%s] due to memory ballooning is disabled. If you are using a custom service offering, verify if memory ballooning really should be disabled.", vmTO.toString(), maxRam));
2805-
return maxRam;
2801+
} else if (vmTO != null && vmTO.getType() != VirtualMachine.Type.User) {
2802+
s_logger.warn(String.format("Setting System VM's [%s] current memory as max memory [%s].", vmTO.toString(), maxRam));
28062803
} else {
2807-
return ByteScaleUtils.bytesToKibibytes(vmTO.getMinRam());
2804+
long minRam = ByteScaleUtils.bytesToKibibytes(vmTO.getMinRam());
2805+
s_logger.debug(String.format("Setting VM's [%s] current memory as min memory [%s] due to memory ballooning is enabled.", vmTO.toString(), minRam));
2806+
retVal = minRam;
28082807
}
2808+
return retVal;
28092809
}
28102810

28112811
/**

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ public void setMemBalloning(boolean memoryBalloning) {
282282
@Override
283283
public String toString() {
284284
StringBuilder response = new StringBuilder();
285-
response.append(String.format("<memory>%s</memory>\n", this.memory));
285+
response.append(String.format("<memory>%s</memory>\n", this.currentMemory));
286286
response.append(String.format("<currentMemory>%s</currentMemory>\n", this.currentMemory));
287287

288288
if (this.memory > this.currentMemory) {
@@ -1238,7 +1238,7 @@ public String getMemBalloonStatsPeriod() {
12381238
@Override
12391239
public String toString() {
12401240
StringBuilder memBalloonBuilder = new StringBuilder();
1241-
memBalloonBuilder.append("<memballoon model='" + memBalloonModel + "' autodeflate='on'>\n");
1241+
memBalloonBuilder.append("<memballoon model='" + memBalloonModel + "'>\n");
12421242
if (StringUtils.isNotBlank(memBalloonStatsPeriod)) {
12431243
memBalloonBuilder.append("<stats period='" + memBalloonStatsPeriod +"'/>\n");
12441244
}

plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ private void verifyVcpu(VirtualMachineTO to, Document domainDoc) {
760760

761761
private void verifyMemory(VirtualMachineTO to, Document domainDoc, String minRam) {
762762
assertXpath(domainDoc, "/domain/maxMemory/text()", String.valueOf( to.getMaxRam() / 1024 ));
763-
assertXpath(domainDoc, "/domain/currentMemory/text()",minRam);
763+
assertXpath(domainDoc, "/domain/memory/text()",minRam);
764764
assertXpath(domainDoc, "/domain/cpu/numa/cell/@memory", minRam);
765765
assertXpath(domainDoc, "/domain/currentMemory/text()", minRam);
766766
}
@@ -5762,6 +5762,7 @@ public void testAddExtraConfigComponentNotEmptyExtraConfig() {
57625762

57635763
public void validateGetCurrentMemAccordingToMemBallooningWithoutMemBalooning(){
57645764
VirtualMachineTO vmTo = Mockito.mock(VirtualMachineTO.class);
5765+
Mockito.when(vmTo.getType()).thenReturn(Type.User);
57655766
LibvirtComputingResource libvirtComputingResource = new LibvirtComputingResource();
57665767
libvirtComputingResource._noMemBalloon = true;
57675768
long maxMemory = 2048;
@@ -5780,6 +5781,7 @@ public void validateGetCurrentMemAccordingToMemBallooningWithtMemBalooning(){
57805781
long minMemory = ByteScaleUtils.mebibytesToBytes(64);
57815782

57825783
VirtualMachineTO vmTo = Mockito.mock(VirtualMachineTO.class);
5784+
Mockito.when(vmTo.getType()).thenReturn(Type.User);
57835785
Mockito.when(vmTo.getMinRam()).thenReturn(minMemory);
57845786

57855787
long currentMemory = libvirtComputingResource.getCurrentMemAccordingToMemBallooning(vmTo, maxMemory);

plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtVMDefTest.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,11 @@ public void testDiskDef() {
214214
assertEquals(bus, disk.getBusType());
215215
assertEquals(DiskDef.DeviceType.DISK, disk.getDeviceType());
216216

217-
String resultingXml = disk.toString();
217+
String xmlDef = disk.toString();
218218
String expectedXml = "<disk device='disk' type='file'>\n<driver name='qemu' type='" + type.toString() + "' cache='" + cacheMode.toString() + "' />\n" +
219219
"<source file='" + filePath + "'/>\n<target dev='" + diskLabel + "' bus='" + bus.toString() + "'/>\n</disk>\n";
220220

221-
assertEquals(expectedXml, resultingXml);
221+
assertEquals(expectedXml, xmlDef);
222222
}
223223

224224
@Test
@@ -346,7 +346,7 @@ public void testDiskDefWithBurst() {
346346
LibvirtVMDef.setGlobalQemuVersion(2006000L);
347347
LibvirtVMDef.setGlobalLibvirtVersion(9008L);
348348

349-
String resultingXml = disk.toString();
349+
String xmlDef = disk.toString();
350350
String expectedXml = "<disk device='disk' type='file'>\n<driver name='qemu' type='" + type.toString() + "' cache='none' />\n" +
351351
"<source file='" + filePath + "'/>\n<target dev='" + diskLabel + "' bus='" + bus.toString() + "'/>\n" +
352352
"<iotune>\n<read_bytes_sec>"+bytesReadRate+"</read_bytes_sec>\n<write_bytes_sec>"+bytesWriteRate+"</write_bytes_sec>\n" +
@@ -356,29 +356,29 @@ public void testDiskDefWithBurst() {
356356
"<read_bytes_sec_max_length>"+bytesReadRateMaxLength+"</read_bytes_sec_max_length>\n<write_bytes_sec_max_length>"+bytesWriteRateMaxLength+"</write_bytes_sec_max_length>\n" +
357357
"<read_iops_sec_max_length>"+iopsReadRateMaxLength+"</read_iops_sec_max_length>\n<write_iops_sec_max_length>"+iopsWriteRateMaxLength+"</write_iops_sec_max_length>\n</iotune>\n</disk>\n";
358358

359-
assertEquals(expectedXml, resultingXml);
359+
assertEquals(expectedXml, xmlDef);
360360
}
361361

362362
@Test
363363
public void memBalloonDefTestNone() {
364-
String expectedXml = "<memballoon model='none' autodeflate='on'>\n</memballoon>";
364+
String expectedXml = "<memballoon model='none'>\n</memballoon>";
365365
MemBalloonDef memBalloonDef = new MemBalloonDef();
366366
memBalloonDef.defNoneMemBalloon();
367367

368-
String resultingXml = memBalloonDef.toString();
368+
String xmlDef = memBalloonDef.toString();
369369

370-
assertEquals(expectedXml, resultingXml);
370+
assertEquals(expectedXml, xmlDef);
371371
}
372372

373373
@Test
374374
public void memBalloonDefTestVirtio() {
375-
String expectedXml = "<memballoon model='virtio' autodeflate='on'>\n<stats period='60'/>\n</memballoon>";
375+
String expectedXml = "<memballoon model='virtio'>\n<stats period='60'/>\n</memballoon>";
376376
MemBalloonDef memBalloonDef = new MemBalloonDef();
377377
memBalloonDef.defVirtioMemBalloon("60");
378378

379-
String resultingXml = memBalloonDef.toString();
379+
String xmlDef = memBalloonDef.toString();
380380

381-
assertEquals(expectedXml, resultingXml);
381+
assertEquals(expectedXml, xmlDef);
382382
}
383383

384384
@Test

0 commit comments

Comments
 (0)