KVM memballooning requires free page reporting and autodeflate (#11932)

This commit is contained in:
Brad House 2025-12-16 10:58:32 -05:00 committed by GitHub
parent 7aba434dc4
commit d5165183ea
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 25 additions and 4 deletions

View File

@ -1340,7 +1340,13 @@ public class LibvirtVMDef {
@Override
public String toString() {
StringBuilder memBalloonBuilder = new StringBuilder();
memBalloonBuilder.append("<memballoon model='" + memBalloonModel + "'>\n");
memBalloonBuilder.append("<memballoon model='" + memBalloonModel + "'");
/* Version integer format: major * 1,000,000 + minor * 1,000 + release.
* Require: libvirt 6.9.0, qemu 5.1.0 */
if (memBalloonModel != MemBalloonModel.NONE && s_qemuVersion >= 5001000 && s_libvirtVersion >= 6009000) {
memBalloonBuilder.append(" autodeflate='on' freePageReporting='on'");
}
memBalloonBuilder.append(">\n");
if (StringUtils.isNotBlank(memBalloonStatsPeriod)) {
memBalloonBuilder.append("<stats period='" + memBalloonStatsPeriod +"'/>\n");
}

View File

@ -196,7 +196,7 @@ public class LibvirtDomainXMLParserTest extends TestCase {
"<alias name='video0'/>" +
"<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>" +
"</video>" +
"<memballoon model='virtio'>" +
"<memballoon model='virtio' autodeflate='on' freePageReporting='on'>" +
"<stats period='60'/>" +
"<alias name='balloon0'/>" +
"<address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>" +
@ -379,7 +379,7 @@ public class LibvirtDomainXMLParserTest extends TestCase {
" <redirdev bus='usb' type='spicevmc'>\n" +
" <address type='usb' bus='0' port='3'/>\n" +
" </redirdev>\n" +
" <memballoon model='virtio'>\n" +
" <memballoon model='virtio' autodeflate='on' freePageReporting='on'>\n" +
" <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>\n" +
" </memballoon>\n" +
" </devices>\n" +

View File

@ -465,6 +465,21 @@ public class LibvirtVMDefTest extends TestCase {
@Test
public void memBalloonDefTestVirtio() {
LibvirtVMDef.setGlobalQemuVersion(5001000L);
LibvirtVMDef.setGlobalLibvirtVersion(6009000L);
String expectedXml = "<memballoon model='virtio' autodeflate='on' freePageReporting='on'>\n<stats period='60'/>\n</memballoon>";
MemBalloonDef memBalloonDef = new MemBalloonDef();
memBalloonDef.defVirtioMemBalloon("60");
String xmlDef = memBalloonDef.toString();
assertEquals(expectedXml, xmlDef);
}
@Test
public void memBalloonDefTestVirtioOld() {
LibvirtVMDef.setGlobalQemuVersion(2006000L);
LibvirtVMDef.setGlobalLibvirtVersion(9008L);
String expectedXml = "<memballoon model='virtio'>\n<stats period='60'/>\n</memballoon>";
MemBalloonDef memBalloonDef = new MemBalloonDef();
memBalloonDef.defVirtioMemBalloon("60");

View File

@ -208,7 +208,7 @@ public class LibvirtMigrateVolumeCommandWrapperTest {
" <alias name='watchdog0'/>\n" +
" <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>\n" +
" </watchdog>\n" +
" <memballoon model='virtio'>\n" +
" <memballoon model='virtio' autodeflate='on' freePageReporting='on'>\n" +
" <alias name='balloon0'/>\n" +
" <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>\n" +
" </memballoon>\n" +