From cd401c5c1b5dcba739d69875795828e1be1d726b Mon Sep 17 00:00:00 2001 From: Sean Mooney Date: Wed, 11 Jun 2025 01:41:08 +0100 Subject: [PATCH] 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 --- nova/tests/fixtures/libvirt_data.py | 2 +- nova/tests/unit/virt/libvirt/test_config.py | 7 ++++--- nova/virt/libvirt/config.py | 2 ++ ...todeflate-freepage-reporting-13c25d410cca9d23.yaml | 11 +++++++++++ 4 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 releasenotes/notes/libvirt-memballoon-autodeflate-freepage-reporting-13c25d410cca9d23.yaml diff --git a/nova/tests/fixtures/libvirt_data.py b/nova/tests/fixtures/libvirt_data.py index cfc9a1412c69..99d361367396 100644 --- a/nova/tests/fixtures/libvirt_data.py +++ b/nova/tests/fixtures/libvirt_data.py @@ -229,7 +229,7 @@ FAKE_KVM_GUEST = """ - + diff --git a/nova/tests/unit/virt/libvirt/test_config.py b/nova/tests/unit/virt/libvirt/test_config.py index 199d5807c76c..1d772f543294 100644 --- a/nova/tests/unit/virt/libvirt/test_config.py +++ b/nova/tests/unit/virt/libvirt/test_config.py @@ -4247,7 +4247,7 @@ class LibvirtConfigMemoryBalloonTest(LibvirtConfigBaseTest): xml = balloon.to_xml() expected_xml = """ - + """ @@ -4259,7 +4259,8 @@ class LibvirtConfigMemoryBalloonTest(LibvirtConfigBaseTest): xml = balloon.to_xml() expected_xml = """ - """ + """ self.assertXmlEqual(expected_xml, xml) @@ -4272,7 +4273,7 @@ class LibvirtConfigMemoryBalloonTest(LibvirtConfigBaseTest): xml = balloon.to_xml() expected_xml = """ - + """ diff --git a/nova/virt/libvirt/config.py b/nova/virt/libvirt/config.py index 2c6e859f9990..f3253c734f3c 100644 --- a/nova/virt/libvirt/config.py +++ b/nova/virt/libvirt/config.py @@ -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: diff --git a/releasenotes/notes/libvirt-memballoon-autodeflate-freepage-reporting-13c25d410cca9d23.yaml b/releasenotes/notes/libvirt-memballoon-autodeflate-freepage-reporting-13c25d410cca9d23.yaml new file mode 100644 index 000000000000..6988ac2c5abb --- /dev/null +++ b/releasenotes/notes/libvirt-memballoon-autodeflate-freepage-reporting-13c25d410cca9d23.yaml @@ -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.