libvirt: Enable autodeflate and freePageReporting for memballoon

The libvirt driver now automatically enables autodeflate and
freePageReporting attributes for virtio memory balloon devices.
The autodeflate feature allows the QEMU virtio memory balloon
to release memory before the Out of Memory killer activates.
The freePageReporting feature enables returning unused pages
back to the hypervisor for use by other guests or processes,
improving overall memory efficiency on compute hosts.

These features are always enabled when a memballoon device is
configured, requiring no additional configuration from operators.

implements: blueprint automatic-memballoon-freeing
Generated-By: claude-code
Change-Id: If47a6d38cd311b08b78acffb307a99a7a2a080a1
Signed-off-by: Sean Mooney <work@seanmooney.info>
This commit is contained in:
Sean Mooney
2025-06-11 01:41:08 +01:00
committed by sean mooney
parent 38d06f41a9
commit cd401c5c1b
4 changed files with 18 additions and 4 deletions
+1 -1
View File
@@ -229,7 +229,7 @@ FAKE_KVM_GUEST = """
<model type='virtio'/>
<source bridge='virbr0'/>
</interface>
<memballoon model='virtio'>
<memballoon model='virtio' autodeflate='on' freePageReporting='on'>
<stats period='11'/>
</memballoon>
<input type="mouse" bus="virtio"/>
+4 -3
View File
@@ -4247,7 +4247,7 @@ class LibvirtConfigMemoryBalloonTest(LibvirtConfigBaseTest):
xml = balloon.to_xml()
expected_xml = """
<memballoon model='virtio'>
<memballoon model='virtio' autodeflate='on' freePageReporting='on'>
<stats period='11'/>
</memballoon>"""
@@ -4259,7 +4259,8 @@ class LibvirtConfigMemoryBalloonTest(LibvirtConfigBaseTest):
xml = balloon.to_xml()
expected_xml = """
<memballoon model='virtio' />"""
<memballoon model='virtio' autodeflate='on'
freePageReporting='on' />"""
self.assertXmlEqual(expected_xml, xml)
@@ -4272,7 +4273,7 @@ class LibvirtConfigMemoryBalloonTest(LibvirtConfigBaseTest):
xml = balloon.to_xml()
expected_xml = """
<memballoon model='virtio'>
<memballoon model='virtio' autodeflate='on' freePageReporting='on'>
<driver iommu="on" />
</memballoon>"""
+2
View File
@@ -2302,6 +2302,8 @@ class LibvirtConfigMemoryBalloon(LibvirtConfigGuestDevice):
def format_dom(self):
dev = super(LibvirtConfigMemoryBalloon, self).format_dom()
dev.set('model', str(self.model))
dev.set('autodeflate', 'on')
dev.set('freePageReporting', 'on')
if self.period is not None:
dev.append(etree.Element('stats', period=str(self.period)))
if self.driver_iommu:
@@ -0,0 +1,11 @@
---
features:
- |
The libvirt driver now automatically enables ``autodeflate`` and
``freePageReporting`` features for virtio memory balloon devices.
The ``autodeflate`` feature allows the QEMU virtio memory balloon
to release memory at the last moment before a guest process is
killed by the Out of Memory killer. The ``freePageReporting``
feature enables the memory balloon to return unused pages back
to the hypervisor for use by other guests or processes, improving
overall memory efficiency on the compute host.