[openstack][nova]qemu system wont release memory
Hello. I have an OpenStack instance that was using 14GB out of 16GB of memory. Later, when it was using only 4GB, I checked the QEMU process on the compute node, and it was still consuming 14GB, this means memory isn't released when usage decreases. Do we have solutions for this? I use Ubuntu 24.04 instances. Nguyen Huu Khoi
On 21/05/2025 05:22, Nguyễn Hữu Khôi wrote:
Hello.
I have an OpenStack instance that was using 14GB out of 16GB of memory. Later, when it was using only 4GB, I checked the QEMU process on the compute node, and it was still consuming 14GB, this means memory isn't released when usage decreases.
correct this is the current designed behavior. while the mem balloon is enable there has never been support for using that to free unallcoated memory when teh guest frees pages the men-ballon was originally added in nova purely to allow gathering guest memory statistics. if your over allocating memory in nova your required to have sufficient swap space so that the kernel can page out the inactive memory.
Do we have solutions for this? I use Ubuntu 24.04 instances.
It would be a new RFE its not one that we have not consiered before but its just never been a priority since this is not how we expect to over subsribe. we over subscribe via swap space. runing nova without swap leads to the python interpreture usign more memory then required otherwise, that partly why we do not recommend running without swap even if guest memory oversubscribe is not planned. since swap shoudl alwasy be present on compute nodes it the natural extension prefer it for oversubscribtion and let the kernel manage paging then maintaining another agent or requireing you to use an external one. libvirt has gained some funtionality in thsi space that i have consiered writign a patch to enable https://libvirt.org/formatdomain.html#memory-balloon-device specificly ``` autodeflate The optional autodeflate attribute allows to enable/disable (values "on"/"off", respectively) the ability of the QEMU virtio memory balloon to release some memory at the last moment before a guest's process get killed by Out of Memory killer. Since 1.3.1, QEMU and KVM only freePageReporting The optional freePageReporting attribute allows to enable/disable ("on"/"off", respectively) the ability of the QEMU virtio memory balloon to return unused pages back to the hypervisor to be used by other guests or processes. Please note that despite its name it has no effect on free memory as reported by virDomainMemoryStats() and/or virsh dommemstat. Since 6.9.0, QEMU and KVM only ``` auto deflate would make sent to enable unconditionally in an opnestack env for deomains not using file or hugepage backed memory. freePageReporting is the value that peaked my interest on this topic most recently. in caracal we finally got our min libvirt version high enough to be able to use it un contiontally as well. thats the feature you want and its not hard to add i just have not had time to work on this lately. if you want to submit a patch to work on those i think this could be covered as a small specless blueprint. prior to caracal this would have been much more painfail to enabel as nova woudl have needed to implement an agent to do the memroy freeign. that is what proxymox and ovirt have done in the past to get the same effect. now that libvirt has native support we can just turn it on and let it do it on our behalf.
Nguyen Huu Khoi
Hello. Thank you for your very detailed explanation. and I hope that will come with Openstack in the near future so with it we can rebalance instances more efficiently. Nguyen Huu Khoi On Wed, May 21, 2025 at 3:13 PM Sean Mooney <smooney@redhat.com> wrote:
On 21/05/2025 05:22, Nguyễn Hữu Khôi wrote:
Hello.
I have an OpenStack instance that was using 14GB out of 16GB of memory. Later, when it was using only 4GB, I checked the QEMU process on the compute node, and it was still consuming 14GB, this means memory isn't released when usage decreases.
correct this is the current designed behavior.
while the mem balloon is enable there has never been support for using that to free unallcoated memory when teh guest frees pages
the men-ballon was originally added in nova purely to allow gathering guest memory statistics.
if your over allocating memory in nova your required to have sufficient swap space so that the kernel can page out the inactive memory.
Do we have solutions for this? I use Ubuntu 24.04 instances.
It would be a new RFE
its not one that we have not consiered before but its just never been a priority since this is not how we expect to over subsribe.
we over subscribe via swap space. runing nova without swap leads to the python interpreture usign more memory then required otherwise, that partly why we do not recommend running without swap even if guest memory oversubscribe is not planned.
since swap shoudl alwasy be present on compute nodes it the natural extension prefer it for oversubscribtion and let the kernel
manage paging then maintaining another agent or requireing you to use an external one.
libvirt has gained some funtionality in thsi space that i have consiered writign a patch to enable
https://libvirt.org/formatdomain.html#memory-balloon-device
specificly
```
autodeflate
The optional autodeflate attribute allows to enable/disable (values "on"/"off", respectively) the ability of the QEMU virtio memory balloon to release some memory at the last moment before a guest's process get killed by Out of Memory killer. Since 1.3.1, QEMU and KVM only
freePageReporting
The optional freePageReporting attribute allows to enable/disable ("on"/"off", respectively) the ability of the QEMU virtio memory balloon to return unused pages back to the hypervisor to be used by other guests or processes. Please note that despite its name it has no effect on free memory as reported by virDomainMemoryStats() and/or virsh dommemstat. Since 6.9.0, QEMU and KVM only
```
auto deflate would make sent to enable unconditionally in an opnestack env for deomains not using file or hugepage backed memory.
freePageReporting is the value that peaked my interest on this topic most recently. in caracal we finally got our min libvirt version high enough
to be able to use it un contiontally as well.
thats the feature you want and its not hard to add i just have not had time to work on this lately.
if you want to submit a patch to work on those i think this could be covered as a small specless blueprint.
prior to caracal this would have been much more painfail to enabel as nova woudl have needed to implement an agent to do the memroy freeign.
that is what proxymox and ovirt have done in the past to get the same effect.
now that libvirt has native support we can just turn it on and let it do it on our behalf.
Nguyen Huu Khoi
Hi Sean. Thank you for the patch, I tested it and it works as I expect. Nguyen Huu Khoi On Wed, May 21, 2025 at 8:10 PM Nguyễn Hữu Khôi <nguyenhuukhoinw@gmail.com> wrote:
Hello. Thank you for your very detailed explanation. and I hope that will come with Openstack in the near future so with it we can rebalance instances more efficiently. Nguyen Huu Khoi
On Wed, May 21, 2025 at 3:13 PM Sean Mooney <smooney@redhat.com> wrote:
On 21/05/2025 05:22, Nguyễn Hữu Khôi wrote:
Hello.
I have an OpenStack instance that was using 14GB out of 16GB of memory. Later, when it was using only 4GB, I checked the QEMU process on the compute node, and it was still consuming 14GB, this means memory isn't released when usage decreases.
correct this is the current designed behavior.
while the mem balloon is enable there has never been support for using that to free unallcoated memory when teh guest frees pages
the men-ballon was originally added in nova purely to allow gathering guest memory statistics.
if your over allocating memory in nova your required to have sufficient swap space so that the kernel can page out the inactive memory.
Do we have solutions for this? I use Ubuntu 24.04 instances.
It would be a new RFE
its not one that we have not consiered before but its just never been a priority since this is not how we expect to over subsribe.
we over subscribe via swap space. runing nova without swap leads to the python interpreture usign more memory then required otherwise, that partly why we do not recommend running without swap even if guest memory oversubscribe is not planned.
since swap shoudl alwasy be present on compute nodes it the natural extension prefer it for oversubscribtion and let the kernel
manage paging then maintaining another agent or requireing you to use an external one.
libvirt has gained some funtionality in thsi space that i have consiered writign a patch to enable
https://libvirt.org/formatdomain.html#memory-balloon-device
specificly
```
autodeflate
The optional autodeflate attribute allows to enable/disable (values "on"/"off", respectively) the ability of the QEMU virtio memory balloon to release some memory at the last moment before a guest's process get killed by Out of Memory killer. Since 1.3.1, QEMU and KVM only
freePageReporting
The optional freePageReporting attribute allows to enable/disable ("on"/"off", respectively) the ability of the QEMU virtio memory balloon to return unused pages back to the hypervisor to be used by other guests or processes. Please note that despite its name it has no effect on free memory as reported by virDomainMemoryStats() and/or virsh dommemstat. Since 6.9.0, QEMU and KVM only
```
auto deflate would make sent to enable unconditionally in an opnestack env for deomains not using file or hugepage backed memory.
freePageReporting is the value that peaked my interest on this topic most recently. in caracal we finally got our min libvirt version high enough
to be able to use it un contiontally as well.
thats the feature you want and its not hard to add i just have not had time to work on this lately.
if you want to submit a patch to work on those i think this could be covered as a small specless blueprint.
prior to caracal this would have been much more painfail to enabel as nova woudl have needed to implement an agent to do the memroy freeign.
that is what proxymox and ovirt have done in the past to get the same effect.
now that libvirt has native support we can just turn it on and let it do it on our behalf.
Nguyen Huu Khoi
im glad to hear that. for those wondering which patch https://review.opendev.org/c/openstack/nova/+/952306 will be part of 2025.2 which should be released in 2 days. we also fixed and backporte the ablity to disable the memballon device entirly https://review.opendev.org/c/openstack/nova/+/952961 so if you do not want qemu to automatically report that the memory can be freeded when the guest frees memory you can set mem_stats_period_seconds=0 which is the recommendation for realtime hosts. On 25/09/2025 05:03, Nguyễn Hữu Khôi wrote:
Hi Sean.
Thank you for the patch, I tested it and it works as I expect.
Nguyen Huu Khoi
On Wed, May 21, 2025 at 8:10 PM Nguyễn Hữu Khôi <nguyenhuukhoinw@gmail.com> wrote:
Hello. Thank you for your very detailed explanation. and I hope that will come with Openstack in the near future so with it we can rebalance instances more efficiently. Nguyen Huu Khoi
On Wed, May 21, 2025 at 3:13 PM Sean Mooney <smooney@redhat.com> wrote:
On 21/05/2025 05:22, Nguyễn Hữu Khôi wrote: > Hello. > > I have an OpenStack instance that was using 14GB out of 16GB of > memory. Later, when it was using only 4GB, I checked the QEMU process > on the compute node, and it was still consuming 14GB, this means > memory isn't released when usage decreases.
correct this is the current designed behavior.
while the mem balloon is enable there has never been support for using that to free unallcoated memory when teh guest frees pages
the men-ballon was originally added in nova purely to allow gathering guest memory statistics.
if your over allocating memory in nova your required to have sufficient swap space so that the kernel can page out the inactive memory.
> > Do we have solutions for this? I use Ubuntu 24.04 instances.
It would be a new RFE
its not one that we have not consiered before but its just never been a priority since this is not how we expect to over subsribe.
we over subscribe via swap space. runing nova without swap leads to the python interpreture usign more memory then required otherwise, that partly why we do not recommend running without swap even if guest memory oversubscribe is not planned.
since swap shoudl alwasy be present on compute nodes it the natural extension prefer it for oversubscribtion and let the kernel
manage paging then maintaining another agent or requireing you to use an external one.
libvirt has gained some funtionality in thsi space that i have consiered writign a patch to enable
https://libvirt.org/formatdomain.html#memory-balloon-device
specificly
```
autodeflate
The optional autodeflate attribute allows to enable/disable (values "on"/"off", respectively) the ability of the QEMU virtio memory balloon to release some memory at the last moment before a guest's process get killed by Out of Memory killer. Since 1.3.1, QEMU and KVM only
freePageReporting
The optional freePageReporting attribute allows to enable/disable ("on"/"off", respectively) the ability of the QEMU virtio memory balloon to return unused pages back to the hypervisor to be used by other guests or processes. Please note that despite its name it has no effect on free memory as reported by virDomainMemoryStats() and/or virsh dommemstat. Since 6.9.0, QEMU and KVM only
```
auto deflate would make sent to enable unconditionally in an opnestack env for deomains not using file or hugepage backed memory.
freePageReporting is the value that peaked my interest on this topic most recently. in caracal we finally got our min libvirt version high enough
to be able to use it un contiontally as well.
thats the feature you want and its not hard to add i just have not had time to work on this lately.
if you want to submit a patch to work on those i think this could be covered as a small specless blueprint.
prior to caracal this would have been much more painfail to enabel as nova woudl have needed to implement an agent to do the memroy freeign.
that is what proxymox and ovirt have done in the past to get the same effect.
now that libvirt has native support we can just turn it on and let it do it on our behalf.
> > Nguyen Huu Khoi
Hi Sean, This patch is working fine but I see that the other problem is instances using memory for cache so It is hard to reclaim memory in this case? Would you tell me some ideas to work with this case? Nguyen Huu Khoi On Mon, Sep 29, 2025 at 6:52 PM Sean Mooney <smooney@redhat.com> wrote:
im glad to hear that.
for those wondering which patch https://review.opendev.org/c/openstack/nova/+/952306
will be part of 2025.2 which should be released in 2 days.
we also fixed and backporte the ablity to disable the memballon device entirly
https://review.opendev.org/c/openstack/nova/+/952961
so if you do not want qemu to automatically report that the memory can be freeded when the guest frees memory you can set mem_stats_period_seconds=0 which is the recommendation for realtime hosts.
On 25/09/2025 05:03, Nguyễn Hữu Khôi wrote:
Hi Sean.
Thank you for the patch, I tested it and it works as I expect.
Nguyen Huu Khoi
On Wed, May 21, 2025 at 8:10 PM Nguyễn Hữu Khôi <nguyenhuukhoinw@gmail.com> wrote:
Hello. Thank you for your very detailed explanation. and I hope that will come with Openstack in the near future so with it we can rebalance instances more efficiently. Nguyen Huu Khoi
On Wed, May 21, 2025 at 3:13 PM Sean Mooney <smooney@redhat.com> wrote:
On 21/05/2025 05:22, Nguyễn Hữu Khôi wrote: > Hello. > > I have an OpenStack instance that was using 14GB out of 16GB of > memory. Later, when it was using only 4GB, I checked the QEMU process > on the compute node, and it was still consuming 14GB, this means > memory isn't released when usage decreases.
correct this is the current designed behavior.
while the mem balloon is enable there has never been support for using that to free unallcoated memory when teh guest frees pages
the men-ballon was originally added in nova purely to allow gathering guest memory statistics.
if your over allocating memory in nova your required to have sufficient swap space so that the kernel can page out the inactive memory.
> > Do we have solutions for this? I use Ubuntu 24.04 instances.
It would be a new RFE
its not one that we have not consiered before but its just never been a priority since this is not how we expect to over subsribe.
we over subscribe via swap space. runing nova without swap leads to the python interpreture usign more memory then required otherwise, that partly why we do not recommend running without swap even if guest memory oversubscribe is not planned.
since swap shoudl alwasy be present on compute nodes it the natural extension prefer it for oversubscribtion and let the kernel
manage paging then maintaining another agent or requireing you to use an external one.
libvirt has gained some funtionality in thsi space that i have consiered writign a patch to enable
https://libvirt.org/formatdomain.html#memory-balloon-device
specificly
```
autodeflate
The optional autodeflate attribute allows to enable/disable (values "on"/"off", respectively) the ability of the QEMU virtio memory balloon to release some memory at the last moment before a guest's process get killed by Out of Memory killer. Since 1.3.1, QEMU and KVM only
freePageReporting
The optional freePageReporting attribute allows to enable/disable ("on"/"off", respectively) the ability of the QEMU virtio memory balloon to return unused pages back to the hypervisor to be used by other guests or processes. Please note that despite its name it has no effect on free memory as reported by virDomainMemoryStats() and/or virsh dommemstat. Since 6.9.0, QEMU and KVM only
```
auto deflate would make sent to enable unconditionally in an opnestack env for deomains not using file or hugepage backed memory.
freePageReporting is the value that peaked my interest on this topic most recently. in caracal we finally got our min libvirt version high enough
to be able to use it un contiontally as well.
thats the feature you want and its not hard to add i just have not had time to work on this lately.
if you want to submit a patch to work on those i think this could be covered as a small specless blueprint.
prior to caracal this would have been much more painfail to enabel as nova woudl have needed to implement an agent to do the memroy freeign.
that is what proxymox and ovirt have done in the past to get the same effect.
now that libvirt has native support we can just turn it on and let it do it on our behalf.
> > Nguyen Huu Khoi
i assume when you say for cache you mean the kernel page cache ectra the only tuneable that nova has related to caching is https://docs.openstack.org/nova/latest/configuration/config.html#libvirt.dis... which will allow you to contole qemus block device caching behvior [libvirt] disk_cachemodes=file=none,block=none,network=none if you want to trune the kernel to mor agressivly relaime the file system cache you can teake the following values ``` # Prefer reclaiming filesystem cache over swapping VM/process anonymous memory vm.swappiness = 10 # Reclaim inode/dentry caches somewhat more aggressively vm.vfs_cache_pressure = 200 # Keep the amount of dirty page cache bounded vm.dirty_background_ratio = 2 vm.dirty_ratio = 5 # or via fixed value rather then percents 512M and 2G respctivly # on large systems using the byte valeus is a little more predicable #vm.dirty_background_bytes = 536870912 #vm.dirty_bytes = 2147483648 ``` vm.watermark_scale_factor i apprenly also relevent to memroy reclaim but its not a value i have personally used in the past basically https://wiki.archlinux.org/title/Sysctl#Virtual_memory you might also be interested in https://wiki.archlinux.org/title/Zswap if your realy tring to pack as much vms on a host as possible in ci we are optimisting for a diffent usecase but you can see thw values we are settin https://github.com/openstack/devstack/blob/master/lib/host#L68-L118 we defer writes when there is free memroy and tell the kerenl ot consider swapping to be the same cost as page caching since swap is actully accclerated via the zswap compressoin ratio. on linux cache usage is not gerenally cosndier a bad thing it just he kernel being efficet about avdiedin disk reads/writes those caches will alwsy be purged when memory is needed for other usecases. in general we do not recommend hvelly over commiting in memory and alwasy recomemnd havign enough swap for thte total memy time sthe over commit ration if that ratio exceeds 1.0 that is so that the kernel never has to choose between OOM killing your guest or paging its memory but beyound that i dont realy have any ohter advice on this topic. i generally woudl not try to force cache memory reclaim with somethign like `echo3> /proc/sys/vm/drop_caches` i personally do not like any of tuned's in tree profiles but that may also hlep you find intersint tunabels to consider https://github.com/redhat-performance/tuned/tree/master/profiles On 25/08/2026 08:35, Nguyễn Hữu Khôi wrote:
Hi Sean, This patch is working fine but I see that the other problem is instances using memory for cache so It is hard to reclaim memory in this case? Would you tell me some ideas to work with this case? Nguyen Huu Khoi
On Mon, Sep 29, 2025 at 6:52 PM Sean Mooney <smooney@redhat.com> wrote:
im glad to hear that.
for those wondering which patch https://review.opendev.org/c/openstack/nova/+/952306
will be part of 2025.2 which should be released in 2 days.
we also fixed and backporte the ablity to disable the memballon device entirly
https://review.opendev.org/c/openstack/nova/+/952961
so if you do not want qemu to automatically report that the memory can be freeded when the guest frees memory you can set mem_stats_period_seconds=0 which is the recommendation for realtime hosts.
On 25/09/2025 05:03, Nguyễn Hữu Khôi wrote: > Hi Sean. > > Thank you for the patch, I tested it and it works as I expect. > > Nguyen Huu Khoi > > > On Wed, May 21, 2025 at 8:10 PM Nguyễn Hữu Khôi > <nguyenhuukhoinw@gmail.com> wrote: > > Hello. > Thank you for your very detailed explanation. and I hope that will > come with Openstack in the near future so with it we can rebalance > instances more efficiently. > Nguyen Huu Khoi > > > On Wed, May 21, 2025 at 3:13 PM Sean Mooney <smooney@redhat.com> > wrote: > > > On 21/05/2025 05:22, Nguyễn Hữu Khôi wrote: > > Hello. > > > > I have an OpenStack instance that was using 14GB out of > 16GB of > > memory. Later, when it was using only 4GB, I checked the > QEMU process > > on the compute node, and it was still consuming 14GB, this > means > > memory isn't released when usage decreases. > > correct this is the current designed behavior. > > while the mem balloon is enable there has never been support > for using > that to free unallcoated memory when teh guest frees pages > > the men-ballon was originally added in nova purely to allow > gathering > guest memory statistics. > > if your over allocating memory in nova your required to have > sufficient > swap space so that the kernel can page out the inactive memory. > > > > > Do we have solutions for this? I use Ubuntu 24.04 instances. > > It would be a new RFE > > its not one that we have not consiered before but its just > never been a > priority since this is not how we expect to over subsribe. > > we over subscribe via swap space. runing nova without swap > leads to the > python interpreture usign more memory then required > otherwise, that partly why we do not recommend running without > swap even > if guest memory oversubscribe is not planned. > > since swap shoudl alwasy be present on compute nodes it the > natural > extension prefer it for oversubscribtion and let the kernel > > manage paging then maintaining another agent or requireing you > to use an > external one. > > > libvirt has gained some funtionality in thsi space that i have > consiered > writign a patch to enable > > https://libvirt.org/formatdomain.html#memory-balloon-device > > specificly > > > ``` > > autodeflate > > The optional autodeflate attribute allows to > enable/disable (values > "on"/"off", respectively) the ability of the QEMU virtio > memory > balloon to release some memory at the last moment before a > guest's > process get killed by Out of Memory killer. Since 1.3.1, > QEMU and > KVM only > > freePageReporting > > The optional freePageReporting attribute allows to > enable/disable > ("on"/"off", respectively) the ability of the QEMU virtio > memory > balloon to return unused pages back to the hypervisor to > be used by > other guests or processes. Please note that despite its > name it has > no effect on free memory as reported by virDomainMemoryStats() > and/or virsh dommemstat. Since 6.9.0, QEMU and KVM only > > ``` > > auto deflate would make sent to enable unconditionally in an > opnestack > env for deomains not using file or hugepage backed memory. > > freePageReporting is the value that peaked my interest on this > topic > most recently. in caracal we finally got our min libvirt > version high enough > > to be able to use it un contiontally as well. > > > thats the feature you want and its not hard to add i just have > not had > time to work on this lately. > > > if you want to submit a patch to work on those i think this > could be > covered as a small specless blueprint. > > prior to caracal this would have been much more painfail to > enabel as > nova woudl have needed to implement an agent to do the memroy > freeign. > > that is what proxymox and ovirt have done in the past to get > the same > effect. > > now that libvirt has native support we can just turn it on and > let it do > it on our behalf. > > > > > Nguyen Huu Khoi >
Thanks for the breakdown — I'm seeing an example of this. `virsh dommemstat` on one instance: ``` actual 249561088 unused 35707248 disk_caches 71486684 rss 216835168 ``` Guest itself reports ~68GB as reclaimable disk cache (via balloon), but host-side RSS for QEMU is ~207GB — almost the full allocation. Seems like once guest pages are touched they're backed 1:1 by host RAM, so the host can't tell cache pages apart from "real" usage — it just sees high RSS. So `cache=none` doesn't apply here (that's host-side caching of the disk image, different thing), and the sysctl tuning is also host-side only. Is ballooning/free-page-reporting really the only way to reclaim this from the host, or is there another lever I'm missing? Nguyen Huu Khoi On Tue, Aug 25, 2026, 6:53 PM Sean Mooney <smooney@redhat.com> wrote:
i assume when you say for cache you mean the kernel page cache ectra
the only tuneable that nova has related to caching is
https://docs.openstack.org/nova/latest/configuration/config.html#libvirt.dis... which will allow you to contole qemus block device caching behvior [libvirt]
disk_cachemodes=file=none,block=none,network=none
if you want to trune the kernel to mor agressivly relaime the file system cache you can teake the following values
``` # Prefer reclaiming filesystem cache over swapping VM/process anonymous memory vm.swappiness = 10
# Reclaim inode/dentry caches somewhat more aggressively vm.vfs_cache_pressure = 200
# Keep the amount of dirty page cache bounded vm.dirty_background_ratio = 2 vm.dirty_ratio = 5 # or via fixed value rather then percents 512M and 2G respctivly # on large systems using the byte valeus is a little more predicable #vm.dirty_background_bytes = 536870912 #vm.dirty_bytes = 2147483648 ```
vm.watermark_scale_factor i apprenly also relevent to memroy reclaim but its not a value i have personally used in the past
basically https://wiki.archlinux.org/title/Sysctl#Virtual_memory you might also be interested in https://wiki.archlinux.org/title/Zswap if your realy tring to pack as much vms on a host as possible
in ci we are optimisting for a diffent usecase but you can see thw values we are settin https://github.com/openstack/devstack/blob/master/lib/host#L68-L118
we defer writes when there is free memroy and tell the kerenl ot consider swapping to be the same cost as page caching since swap is actully accclerated via the zswap compressoin ratio.
on linux cache usage is not gerenally cosndier a bad thing it just he kernel being efficet about avdiedin disk reads/writes those caches will alwsy be purged when memory is needed for other usecases.
in general we do not recommend hvelly over commiting in memory and alwasy recomemnd havign enough swap for thte total memy time sthe over commit ration if that ratio exceeds 1.0 that is so that the kernel never has to choose between OOM killing your guest or paging its memory but beyound that i dont realy have any ohter advice on this topic. i generally woudl not try to force cache memory reclaim with somethign like
`echo3> /proc/sys/vm/drop_caches`
i personally do not like any of tuned's in tree profiles but that may also hlep you find intersint tunabels to consider https://github.com/redhat-performance/tuned/tree/master/profiles
On 25/08/2026 08:35, Nguyễn Hữu Khôi wrote:
Hi Sean, This patch is working fine but I see that the other problem is instances using memory for cache so It is hard to reclaim memory in this case? Would you tell me some ideas to work with this case? Nguyen Huu Khoi
On Mon, Sep 29, 2025 at 6:52 PM Sean Mooney <smooney@redhat.com> wrote:
im glad to hear that.
for those wondering which patch https://review.opendev.org/c/openstack/nova/+/952306
will be part of 2025.2 which should be released in 2 days.
we also fixed and backporte the ablity to disable the memballon device entirly
https://review.opendev.org/c/openstack/nova/+/952961
so if you do not want qemu to automatically report that the memory can be freeded when the guest frees memory you can set mem_stats_period_seconds=0 which is the recommendation for realtime hosts.
On 25/09/2025 05:03, Nguyễn Hữu Khôi wrote: > Hi Sean. > > Thank you for the patch, I tested it and it works as I expect. > > Nguyen Huu Khoi > > > On Wed, May 21, 2025 at 8:10 PM Nguyễn Hữu Khôi > <nguyenhuukhoinw@gmail.com> wrote: > > Hello. > Thank you for your very detailed explanation. and I hope that will > come with Openstack in the near future so with it we can rebalance > instances more efficiently. > Nguyen Huu Khoi > > > On Wed, May 21, 2025 at 3:13 PM Sean Mooney < smooney@redhat.com> > wrote: > > > On 21/05/2025 05:22, Nguyễn Hữu Khôi wrote: > > Hello. > > > > I have an OpenStack instance that was using 14GB out of > 16GB of > > memory. Later, when it was using only 4GB, I checked the > QEMU process > > on the compute node, and it was still consuming 14GB, this > means > > memory isn't released when usage decreases. > > correct this is the current designed behavior. > > while the mem balloon is enable there has never been support > for using > that to free unallcoated memory when teh guest frees pages > > the men-ballon was originally added in nova purely to allow > gathering > guest memory statistics. > > if your over allocating memory in nova your required to have > sufficient > swap space so that the kernel can page out the inactive memory. > > > > > Do we have solutions for this? I use Ubuntu 24.04 instances. > > It would be a new RFE > > its not one that we have not consiered before but its just > never been a > priority since this is not how we expect to over subsribe. > > we over subscribe via swap space. runing nova without swap > leads to the > python interpreture usign more memory then required > otherwise, that partly why we do not recommend running without > swap even > if guest memory oversubscribe is not planned. > > since swap shoudl alwasy be present on compute nodes it the > natural > extension prefer it for oversubscribtion and let the kernel > > manage paging then maintaining another agent or requireing you > to use an > external one. > > > libvirt has gained some funtionality in thsi space that i have > consiered > writign a patch to enable > > https://libvirt.org/formatdomain.html#memory-balloon-device > > specificly > > > ``` > > autodeflate > > The optional autodeflate attribute allows to > enable/disable (values > "on"/"off", respectively) the ability of the QEMU virtio > memory > balloon to release some memory at the last moment before a > guest's > process get killed by Out of Memory killer. Since 1.3.1, > QEMU and > KVM only > > freePageReporting > > The optional freePageReporting attribute allows to > enable/disable > ("on"/"off", respectively) the ability of the QEMU virtio > memory > balloon to return unused pages back to the hypervisor to > be used by > other guests or processes. Please note that despite its > name it has > no effect on free memory as reported by virDomainMemoryStats() > and/or virsh dommemstat. Since 6.9.0, QEMU and KVM only > > ``` > > auto deflate would make sent to enable unconditionally in an > opnestack > env for deomains not using file or hugepage backed memory. > > freePageReporting is the value that peaked my interest on this > topic > most recently. in caracal we finally got our min libvirt > version high enough > > to be able to use it un contiontally as well. > > > thats the feature you want and its not hard to add i just have > not had > time to work on this lately. > > > if you want to submit a patch to work on those i think this > could be > covered as a small specless blueprint. > > prior to caracal this would have been much more painfail to > enabel as > nova woudl have needed to implement an agent to do the memroy > freeign. > > that is what proxymox and ovirt have done in the past to get > the same > effect. > > now that libvirt has native support we can just turn it on and > let it do > it on our behalf. > > > > > Nguyen Huu Khoi >
On 25/08/2026 14:09, Nguyễn Hữu Khôi wrote:
Thanks for the breakdown — I'm seeing an example of this. `virsh dommemstat` on one instance:
``` actual 249561088 unused 35707248 disk_caches 71486684 rss 216835168 ```
Guest itself reports ~68GB as reclaimable disk cache (via balloon), but host-side RSS for QEMU is ~207GB — almost the full allocation. Seems like once guest pages are touched they're backed 1:1 by host RAM, so the host can't tell cache pages apart from "real" usage — it just sees high RSS.
So `cache=none` doesn't apply here (that's host-side caching of the disk image, different thing),
that is not waht that is that is host side cachign fo reads/write to the disk image not cachign of the disk image iself.
and the sysctl tuning is also host-side only. Is ballooning/free-page-reporting really the only way to reclaim this from the host, or is there another lever I'm missing? i think there may be a disconenct betwen expectaions form an openstack perspective if a guest touches a page adn qemu allcoate it openstack and hte host kernel in genreeal should not know whtehr the guest is activlly usign that page or the guest kernel is suign it for tis own cache. those are the same form teh host perspective by design and we do nto attapemt to optimise the guest cache usage
that crossing a trust bondary that as a cloud operator you generally shoudl not cross unless this is a proviage cloud where you are contolign the workload. ballooning/free-page-reporting is the only way to reclaim from the host side the breakdwon of the memory usage in the guest is entirely ther own private business and not somethign we should be tryign to mange form the host.
Nguyen Huu Khoi
On Tue, Aug 25, 2026, 6:53 PM Sean Mooney <smooney@redhat.com> wrote:
i assume when you say for cache you mean the kernel page cache ectra
the only tuneable that nova has related to caching is https://docs.openstack.org/nova/latest/configuration/config.html#libvirt.dis... which will allow you to contole qemus block device caching behvior [libvirt]
disk_cachemodes=file=none,block=none,network=none
if you want to trune the kernel to mor agressivly relaime the file system cache you can teake the following values
``` # Prefer reclaiming filesystem cache over swapping VM/process anonymous memory vm.swappiness = 10
# Reclaim inode/dentry caches somewhat more aggressively vm.vfs_cache_pressure = 200
# Keep the amount of dirty page cache bounded vm.dirty_background_ratio = 2 vm.dirty_ratio = 5 # or via fixed value rather then percents 512M and 2G respctivly # on large systems using the byte valeus is a little more predicable #vm.dirty_background_bytes = 536870912 #vm.dirty_bytes = 2147483648 ```
vm.watermark_scale_factor i apprenly also relevent to memroy reclaim but its not a value i have personally used in the past
basically https://wiki.archlinux.org/title/Sysctl#Virtual_memory you might also be interested in https://wiki.archlinux.org/title/Zswap if your realy tring to pack as much vms on a host as possible
in ci we are optimisting for a diffent usecase but you can see thw values we are settin https://github.com/openstack/devstack/blob/master/lib/host#L68-L118
we defer writes when there is free memroy and tell the kerenl ot consider swapping to be the same cost as page caching since swap is actully accclerated via the zswap compressoin ratio.
on linux cache usage is not gerenally cosndier a bad thing it just he kernel being efficet about avdiedin disk reads/writes those caches will alwsy be purged when memory is needed for other usecases.
in general we do not recommend hvelly over commiting in memory and alwasy recomemnd havign enough swap for thte total memy time sthe over commit ration if that ratio exceeds 1.0 that is so that the kernel never has to choose between OOM killing your guest or paging its memory but beyound that i dont realy have any ohter advice on this topic. i generally woudl not try to force cache memory reclaim with somethign like
`echo3> /proc/sys/vm/drop_caches`
i personally do not like any of tuned's in tree profiles but that may also hlep you find intersint tunabels to consider https://github.com/redhat-performance/tuned/tree/master/profiles
On 25/08/2026 08:35, Nguyễn Hữu Khôi wrote: > Hi Sean, > This patch is working fine but I see that the other problem is > instances using memory for cache so It is hard to reclaim memory in > this case? Would you tell me some ideas to work with this case? > Nguyen Huu Khoi > > > On Mon, Sep 29, 2025 at 6:52 PM Sean Mooney <smooney@redhat.com> wrote: > > im glad to hear that. > > for those wondering which patch > https://review.opendev.org/c/openstack/nova/+/952306 > > will be part of 2025.2 which should be released in 2 days. > > we also fixed and backporte the ablity to disable the memballon > device > entirly > > https://review.opendev.org/c/openstack/nova/+/952961 > > so if you do not want qemu to automatically report that the memory > can > be freeded > when the guest frees memory you can set mem_stats_period_seconds=0 > which is > the recommendation for realtime hosts. > > On 25/09/2025 05:03, Nguyễn Hữu Khôi wrote: > > Hi Sean. > > > > Thank you for the patch, I tested it and it works as I expect. > > > > Nguyen Huu Khoi > > > > > > On Wed, May 21, 2025 at 8:10 PM Nguyễn Hữu Khôi > > <nguyenhuukhoinw@gmail.com> wrote: > > > > Hello. > > Thank you for your very detailed explanation. and I hope > that will > > come with Openstack in the near future so with it we can > rebalance > > instances more efficiently. > > Nguyen Huu Khoi > > > > > > On Wed, May 21, 2025 at 3:13 PM Sean Mooney <smooney@redhat.com> > > wrote: > > > > > > On 21/05/2025 05:22, Nguyễn Hữu Khôi wrote: > > > Hello. > > > > > > I have an OpenStack instance that was using 14GB out of > > 16GB of > > > memory. Later, when it was using only 4GB, I checked the > > QEMU process > > > on the compute node, and it was still consuming 14GB, this > > means > > > memory isn't released when usage decreases. > > > > correct this is the current designed behavior. > > > > while the mem balloon is enable there has never been support > > for using > > that to free unallcoated memory when teh guest frees pages > > > > the men-ballon was originally added in nova purely to allow > > gathering > > guest memory statistics. > > > > if your over allocating memory in nova your required to have > > sufficient > > swap space so that the kernel can page out the inactive > memory. > > > > > > > > Do we have solutions for this? I use Ubuntu 24.04 > instances. > > > > It would be a new RFE > > > > its not one that we have not consiered before but its just > > never been a > > priority since this is not how we expect to over subsribe. > > > > we over subscribe via swap space. runing nova without swap > > leads to the > > python interpreture usign more memory then required > > otherwise, that partly why we do not recommend running > without > > swap even > > if guest memory oversubscribe is not planned. > > > > since swap shoudl alwasy be present on compute nodes it the > > natural > > extension prefer it for oversubscribtion and let the kernel > > > > manage paging then maintaining another agent or > requireing you > > to use an > > external one. > > > > > > libvirt has gained some funtionality in thsi space that > i have > > consiered > > writign a patch to enable > > > > https://libvirt.org/formatdomain.html#memory-balloon-device > > > > specificly > > > > > > ``` > > > > autodeflate > > > > The optional autodeflate attribute allows to > > enable/disable (values > > "on"/"off", respectively) the ability of the QEMU virtio > > memory > > balloon to release some memory at the last moment > before a > > guest's > > process get killed by Out of Memory killer. Since 1.3.1, > > QEMU and > > KVM only > > > > freePageReporting > > > > The optional freePageReporting attribute allows to > > enable/disable > > ("on"/"off", respectively) the ability of the QEMU > virtio > > memory > > balloon to return unused pages back to the hypervisor to > > be used by > > other guests or processes. Please note that despite its > > name it has > > no effect on free memory as reported by > virDomainMemoryStats() > > and/or virsh dommemstat. Since 6.9.0, QEMU and KVM only > > > > ``` > > > > auto deflate would make sent to enable unconditionally in an > > opnestack > > env for deomains not using file or hugepage backed memory. > > > > freePageReporting is the value that peaked my interest > on this > > topic > > most recently. in caracal we finally got our min libvirt > > version high enough > > > > to be able to use it un contiontally as well. > > > > > > thats the feature you want and its not hard to add i > just have > > not had > > time to work on this lately. > > > > > > if you want to submit a patch to work on those i think this > > could be > > covered as a small specless blueprint. > > > > prior to caracal this would have been much more painfail to > > enabel as > > nova woudl have needed to implement an agent to do the > memroy > > freeign. > > > > that is what proxymox and ovirt have done in the past to get > > the same > > effect. > > > > now that libvirt has native support we can just turn it > on and > > let it do > > it on our behalf. > > > > > > > > Nguyen Huu Khoi > > >
Thanks, that confirms it. So virsh setmem is the manual lever for this then — lowering actual below current usage triggers the balloon driver in the guest to reclaim (cache first) and hand pages back, which should bring host-side RSS down over time? Do u think it will resolve our problem? Nguyen Huu Khoi On Tue, Aug 25, 2026, 8:18 PM Sean Mooney <smooney@redhat.com> wrote:
On 25/08/2026 14:09, Nguyễn Hữu Khôi wrote:
Thanks for the breakdown — I'm seeing an example of this. `virsh dommemstat` on one instance:
``` actual 249561088 unused 35707248 disk_caches 71486684 rss 216835168 ```
Guest itself reports ~68GB as reclaimable disk cache (via balloon), but host-side RSS for QEMU is ~207GB — almost the full allocation. Seems like once guest pages are touched they're backed 1:1 by host RAM, so the host can't tell cache pages apart from "real" usage — it just sees high RSS.
So `cache=none` doesn't apply here (that's host-side caching of the disk image, different thing),
that is not waht that is
that is host side cachign fo reads/write to the disk image not cachign of the disk image iself.
and the sysctl tuning is also host-side only. Is ballooning/free-page-reporting really the only way to reclaim this from the host, or is there another lever I'm missing? i think there may be a disconenct betwen expectaions form an openstack perspective if a guest touches a page adn qemu allcoate it openstack and hte host kernel in genreeal should not know whtehr the guest is activlly usign that page or the guest kernel is suign it for tis own cache. those are the same form teh host perspective by design and we do nto attapemt to optimise the guest cache usage
that crossing a trust bondary that as a cloud operator you generally shoudl not cross unless this is a proviage cloud where you are contolign the workload.
ballooning/free-page-reporting is the only way to reclaim from the host side the breakdwon of the memory usage in the guest is entirely ther own private business and not somethign we should be tryign to mange form the host.
Nguyen Huu Khoi
On Tue, Aug 25, 2026, 6:53 PM Sean Mooney <smooney@redhat.com> wrote:
i assume when you say for cache you mean the kernel page cache ectra
the only tuneable that nova has related to caching is
https://docs.openstack.org/nova/latest/configuration/config.html#libvirt.dis...
which will allow you to contole qemus block device caching behvior [libvirt]
disk_cachemodes=file=none,block=none,network=none
if you want to trune the kernel to mor agressivly relaime the file system cache you can teake the following values
``` # Prefer reclaiming filesystem cache over swapping VM/process anonymous memory vm.swappiness = 10
# Reclaim inode/dentry caches somewhat more aggressively vm.vfs_cache_pressure = 200
# Keep the amount of dirty page cache bounded vm.dirty_background_ratio = 2 vm.dirty_ratio = 5 # or via fixed value rather then percents 512M and 2G respctivly # on large systems using the byte valeus is a little more predicable #vm.dirty_background_bytes = 536870912 #vm.dirty_bytes = 2147483648 ```
vm.watermark_scale_factor i apprenly also relevent to memroy reclaim but its not a value i have personally used in the past
basically https://wiki.archlinux.org/title/Sysctl#Virtual_memory you might also be interested in https://wiki.archlinux.org/title/Zswap if your realy tring to pack as much vms on a host as possible
in ci we are optimisting for a diffent usecase but you can see thw values we are settin https://github.com/openstack/devstack/blob/master/lib/host#L68-L118
we defer writes when there is free memroy and tell the kerenl ot consider swapping to be the same cost as page caching since swap is actully accclerated via the zswap compressoin ratio.
on linux cache usage is not gerenally cosndier a bad thing it just he kernel being efficet about avdiedin disk reads/writes those caches will alwsy be purged when memory is needed for other usecases.
in general we do not recommend hvelly over commiting in memory and alwasy recomemnd havign enough swap for thte total memy time sthe over commit ration if that ratio exceeds 1.0 that is so that the kernel never has to choose between OOM killing your guest or paging its memory but beyound that i dont realy have any ohter advice on this topic. i generally woudl not try to force cache memory reclaim with somethign like
`echo3> /proc/sys/vm/drop_caches`
i personally do not like any of tuned's in tree profiles but that may also hlep you find intersint tunabels to consider https://github.com/redhat-performance/tuned/tree/master/profiles
On 25/08/2026 08:35, Nguyễn Hữu Khôi wrote: > Hi Sean, > This patch is working fine but I see that the other problem is > instances using memory for cache so It is hard to reclaim memory in > this case? Would you tell me some ideas to work with this case? > Nguyen Huu Khoi > > > On Mon, Sep 29, 2025 at 6:52 PM Sean Mooney <smooney@redhat.com> wrote: > > im glad to hear that. > > for those wondering which patch > https://review.opendev.org/c/openstack/nova/+/952306 > > will be part of 2025.2 which should be released in 2 days. > > we also fixed and backporte the ablity to disable the memballon > device > entirly > > https://review.opendev.org/c/openstack/nova/+/952961 > > so if you do not want qemu to automatically report that the memory > can > be freeded > when the guest frees memory you can set mem_stats_period_seconds=0 > which is > the recommendation for realtime hosts. > > On 25/09/2025 05:03, Nguyễn Hữu Khôi wrote: > > Hi Sean. > > > > Thank you for the patch, I tested it and it works as I
expect.
> > > > Nguyen Huu Khoi > > > > > > On Wed, May 21, 2025 at 8:10 PM Nguyễn Hữu Khôi > > <nguyenhuukhoinw@gmail.com> wrote: > > > > Hello. > > Thank you for your very detailed explanation. and I hope > that will > > come with Openstack in the near future so with it we can > rebalance > > instances more efficiently. > > Nguyen Huu Khoi > > > > > > On Wed, May 21, 2025 at 3:13 PM Sean Mooney <smooney@redhat.com> > > wrote: > > > > > > On 21/05/2025 05:22, Nguyễn Hữu Khôi wrote: > > > Hello. > > > > > > I have an OpenStack instance that was using 14GB out of > > 16GB of > > > memory. Later, when it was using only 4GB, I checked the > > QEMU process > > > on the compute node, and it was still consuming 14GB, this > > means > > > memory isn't released when usage decreases. > > > > correct this is the current designed behavior. > > > > while the mem balloon is enable there has never been support > > for using > > that to free unallcoated memory when teh guest frees pages > > > > the men-ballon was originally added in nova purely to allow > > gathering > > guest memory statistics. > > > > if your over allocating memory in nova your required to have > > sufficient > > swap space so that the kernel can page out the inactive > memory. > > > > > > > > Do we have solutions for this? I use Ubuntu 24.04 > instances. > > > > It would be a new RFE > > > > its not one that we have not consiered before but its just > > never been a > > priority since this is not how we expect to over subsribe. > > > > we over subscribe via swap space. runing nova without swap > > leads to the > > python interpreture usign more memory then required > > otherwise, that partly why we do not recommend
running
> without > > swap even > > if guest memory oversubscribe is not planned. > > > > since swap shoudl alwasy be present on compute nodes it the > > natural > > extension prefer it for oversubscribtion and let the kernel > > > > manage paging then maintaining another agent or > requireing you > > to use an > > external one. > > > > > > libvirt has gained some funtionality in thsi space that > i have > > consiered > > writign a patch to enable > > > > https://libvirt.org/formatdomain.html#memory-balloon-device > > > > specificly > > > > > > ``` > > > > autodeflate > > > > The optional autodeflate attribute allows to > > enable/disable (values > > "on"/"off", respectively) the ability of the QEMU virtio > > memory > > balloon to release some memory at the last moment > before a > > guest's > > process get killed by Out of Memory killer. Since 1.3.1, > > QEMU and > > KVM only > > > > freePageReporting > > > > The optional freePageReporting attribute allows
to
> > enable/disable > > ("on"/"off", respectively) the ability of the
QEMU
> virtio > > memory > > balloon to return unused pages back to the hypervisor to > > be used by > > other guests or processes. Please note that despite its > > name it has > > no effect on free memory as reported by > virDomainMemoryStats() > > and/or virsh dommemstat. Since 6.9.0, QEMU and KVM only > > > > ``` > > > > auto deflate would make sent to enable unconditionally in an > > opnestack > > env for deomains not using file or hugepage backed memory. > > > > freePageReporting is the value that peaked my
interest
> on this > > topic > > most recently. in caracal we finally got our min libvirt > > version high enough > > > > to be able to use it un contiontally as well. > > > > > > thats the feature you want and its not hard to add i > just have > > not had > > time to work on this lately. > > > > > > if you want to submit a patch to work on those i think this > > could be > > covered as a small specless blueprint. > > > > prior to caracal this would have been much more painfail to > > enabel as > > nova woudl have needed to implement an agent to do
the
> memroy > > freeign. > > > > that is what proxymox and ovirt have done in the past to get > > the same > > effect. > > > > now that libvirt has native support we can just turn it > on and > > let it do > > it on our behalf. > > > > > > > > Nguyen Huu Khoi > > >
On 25/08/2026 14:35, Nguyễn Hữu Khôi wrote:
Thanks, that confirms it. So virsh setmem is the manual lever for this then — lowering actual below current usage triggers the balloon driver in the guest to reclaim (cache first) and hand pages back, which should bring host-side RSS down over time? yes but we dont supprot doing that in nova if you want to use that api direcly you can make that choce for your cloud but the vm wil nolonger be supprot and any memory related bug are not nova bugs.
Do u think it will resolve our problem? perhaps but nova is working as intended as is qemu form what i can tell
Nguyen Huu Khoi
On Tue, Aug 25, 2026, 8:18 PM Sean Mooney <smooney@redhat.com> wrote:
On 25/08/2026 14:09, Nguyễn Hữu Khôi wrote: > > Thanks for the breakdown — I'm seeing an example of this. `virsh > dommemstat` on one instance: > > ``` > actual 249561088 > unused 35707248 > disk_caches 71486684 > rss 216835168 > ``` > > Guest itself reports ~68GB as reclaimable disk cache (via balloon), > but host-side RSS for QEMU is ~207GB — almost the full allocation. > Seems like once guest pages are touched they're backed 1:1 by host > RAM, so the host can't tell cache pages apart from "real" usage — it > just sees high RSS. > > So `cache=none` doesn't apply here (that's host-side caching of the > disk image, different thing), that is not waht that is
that is host side cachign fo reads/write to the disk image not cachign of the disk image iself.
> and the sysctl tuning is also host-side only. Is > ballooning/free-page-reporting really the only way to reclaim this > from the host, or is there another lever I'm missing? i think there may be a disconenct betwen expectaions form an openstack perspective if a guest touches a page adn qemu allcoate it openstack and hte host kernel in genreeal should not know whtehr the guest is activlly usign that page or the guest kernel is suign it for tis own cache. those are the same form teh host perspective by design and we do nto attapemt to optimise the guest cache usage
that crossing a trust bondary that as a cloud operator you generally shoudl not cross unless this is a proviage cloud where you are contolign the workload.
ballooning/free-page-reporting is the only way to reclaim from the host side the breakdwon of the memory usage in the guest is entirely ther own private business and not somethign we should be tryign to mange form the host.
> Nguyen Huu Khoi > > On Tue, Aug 25, 2026, 6:53 PM Sean Mooney <smooney@redhat.com> wrote: > > i assume when you say for cache you mean the kernel page cache ectra > > the only tuneable that nova has related to caching is > https://docs.openstack.org/nova/latest/configuration/config.html#libvirt.dis... > which will allow you to contole qemus block device caching behvior > [libvirt] > > disk_cachemodes=file=none,block=none,network=none > > if you want to trune the kernel to mor agressivly relaime the file > system cache you can teake the following values > > ``` > # Prefer reclaiming filesystem cache over swapping VM/process > anonymous > memory > vm.swappiness = 10 > > # Reclaim inode/dentry caches somewhat more aggressively > vm.vfs_cache_pressure = 200 > > # Keep the amount of dirty page cache bounded > vm.dirty_background_ratio = 2 > vm.dirty_ratio = 5 > # or via fixed value rather then percents 512M and 2G respctivly > # on large systems using the byte valeus is a little more predicable > #vm.dirty_background_bytes = 536870912 > #vm.dirty_bytes = 2147483648 > ``` > > vm.watermark_scale_factor i apprenly also relevent to memroy > reclaim but > its not a value i have personally used in the past > > basically https://wiki.archlinux.org/title/Sysctl#Virtual_memory > you might also be interested in > https://wiki.archlinux.org/title/Zswap > if your realy tring to pack as much vms on a host as possible > > in ci we are optimisting for a diffent usecase but you can see thw > values we are settin > https://github.com/openstack/devstack/blob/master/lib/host#L68-L118 > > we defer writes when there is free memroy and tell the kerenl ot > consider swapping to be the same > cost as page caching since swap is actully accclerated via the zswap > compressoin ratio. > > on linux cache usage is not gerenally cosndier a bad thing it just he > kernel being efficet about > avdiedin disk reads/writes > those caches will alwsy be purged when memory is needed for other > usecases. > > in general we do not recommend hvelly over commiting in memory and > alwasy recomemnd havign enough swap for thte total memy time sthe > over > commit ration if that ratio exceeds 1.0 > that is so that the kernel never has to choose between OOM killing > your > guest or paging its memory but > beyound that i dont realy have any ohter advice on this topic. i > generally woudl not try > to force cache memory reclaim with somethign like > > `echo3> /proc/sys/vm/drop_caches` > > i personally do not like any of tuned's in tree profiles but that may > also hlep you find > intersint tunabels to consider > https://github.com/redhat-performance/tuned/tree/master/profiles > > > > On 25/08/2026 08:35, Nguyễn Hữu Khôi wrote: > > Hi Sean, > > This patch is working fine but I see that the other problem is > > instances using memory for cache so It is hard to reclaim memory in > > this case? Would you tell me some ideas to work with this case? > > Nguyen Huu Khoi > > > > > > On Mon, Sep 29, 2025 at 6:52 PM Sean Mooney <smooney@redhat.com> > wrote: > > > > im glad to hear that. > > > > for those wondering which patch > > https://review.opendev.org/c/openstack/nova/+/952306 > > > > will be part of 2025.2 which should be released in 2 days. > > > > we also fixed and backporte the ablity to disable the memballon > > device > > entirly > > > > https://review.opendev.org/c/openstack/nova/+/952961 > > > > so if you do not want qemu to automatically report that the > memory > > can > > be freeded > > when the guest frees memory you can set > mem_stats_period_seconds=0 > > which is > > the recommendation for realtime hosts. > > > > On 25/09/2025 05:03, Nguyễn Hữu Khôi wrote: > > > Hi Sean. > > > > > > Thank you for the patch, I tested it and it works as I expect. > > > > > > Nguyen Huu Khoi > > > > > > > > > On Wed, May 21, 2025 at 8:10 PM Nguyễn Hữu Khôi > > > <nguyenhuukhoinw@gmail.com> wrote: > > > > > > Hello. > > > Thank you for your very detailed explanation. and I hope > > that will > > > come with Openstack in the near future so with it we can > > rebalance > > > instances more efficiently. > > > Nguyen Huu Khoi > > > > > > > > > On Wed, May 21, 2025 at 3:13 PM Sean Mooney > <smooney@redhat.com> > > > wrote: > > > > > > > > > On 21/05/2025 05:22, Nguyễn Hữu Khôi wrote: > > > > Hello. > > > > > > > > I have an OpenStack instance that was using > 14GB out of > > > 16GB of > > > > memory. Later, when it was using only 4GB, I > checked the > > > QEMU process > > > > on the compute node, and it was still consuming > 14GB, this > > > means > > > > memory isn't released when usage decreases. > > > > > > correct this is the current designed behavior. > > > > > > while the mem balloon is enable there has never > been support > > > for using > > > that to free unallcoated memory when teh guest > frees pages > > > > > > the men-ballon was originally added in nova purely > to allow > > > gathering > > > guest memory statistics. > > > > > > if your over allocating memory in nova your > required to have > > > sufficient > > > swap space so that the kernel can page out the > inactive > > memory. > > > > > > > > > > > Do we have solutions for this? I use Ubuntu 24.04 > > instances. > > > > > > It would be a new RFE > > > > > > its not one that we have not consiered before but > its just > > > never been a > > > priority since this is not how we expect to over > subsribe. > > > > > > we over subscribe via swap space. runing nova > without swap > > > leads to the > > > python interpreture usign more memory then required > > > otherwise, that partly why we do not recommend running > > without > > > swap even > > > if guest memory oversubscribe is not planned. > > > > > > since swap shoudl alwasy be present on compute > nodes it the > > > natural > > > extension prefer it for oversubscribtion and let > the kernel > > > > > > manage paging then maintaining another agent or > > requireing you > > > to use an > > > external one. > > > > > > > > > libvirt has gained some funtionality in thsi space > that > > i have > > > consiered > > > writign a patch to enable > > > > > > https://libvirt.org/formatdomain.html#memory-balloon-device > > > > > > specificly > > > > > > > > > ``` > > > > > > autodeflate > > > > > > The optional autodeflate attribute allows to > > > enable/disable (values > > > "on"/"off", respectively) the ability of the > QEMU virtio > > > memory > > > balloon to release some memory at the last moment > > before a > > > guest's > > > process get killed by Out of Memory killer. > Since 1.3.1, > > > QEMU and > > > KVM only > > > > > > freePageReporting > > > > > > The optional freePageReporting attribute allows to > > > enable/disable > > > ("on"/"off", respectively) the ability of the QEMU > > virtio > > > memory > > > balloon to return unused pages back to the > hypervisor to > > > be used by > > > other guests or processes. Please note that > despite its > > > name it has > > > no effect on free memory as reported by > > virDomainMemoryStats() > > > and/or virsh dommemstat. Since 6.9.0, QEMU and > KVM only > > > > > > ``` > > > > > > auto deflate would make sent to enable > unconditionally in an > > > opnestack > > > env for deomains not using file or hugepage backed > memory. > > > > > > freePageReporting is the value that peaked my interest > > on this > > > topic > > > most recently. in caracal we finally got our min > libvirt > > > version high enough > > > > > > to be able to use it un contiontally as well. > > > > > > > > > thats the feature you want and its not hard to add i > > just have > > > not had > > > time to work on this lately. > > > > > > > > > if you want to submit a patch to work on those i > think this > > > could be > > > covered as a small specless blueprint. > > > > > > prior to caracal this would have been much more > painfail to > > > enabel as > > > nova woudl have needed to implement an agent to do the > > memroy > > > freeign. > > > > > > that is what proxymox and ovirt have done in the > past to get > > > the same > > > effect. > > > > > > now that libvirt has native support we can just > turn it > > on and > > > let it do > > > it on our behalf. > > > > > > > > > > > Nguyen Huu Khoi > > > > > >
Hi. Thank for your reply. I would like to ask if someone submit this feature and is there any chance to become an official support? Nguyen Huu Khoi On Tue, Aug 25, 2026, 8:50 PM Sean Mooney <smooney@redhat.com> wrote:
On 25/08/2026 14:35, Nguyễn Hữu Khôi wrote:
Thanks, that confirms it. So virsh setmem is the manual lever for this then — lowering actual below current usage triggers the balloon driver in the guest to reclaim (cache first) and hand pages back, which should bring host-side RSS down over time? yes but we dont supprot doing that in nova if you want to use that api direcly you can make that choce for your cloud but the vm wil nolonger be supprot and any memory related bug are not nova bugs.
Do u think it will resolve our problem? perhaps but nova is working as intended as is qemu form what i can tell
Nguyen Huu Khoi
On Tue, Aug 25, 2026, 8:18 PM Sean Mooney <smooney@redhat.com> wrote:
On 25/08/2026 14:09, Nguyễn Hữu Khôi wrote: > > Thanks for the breakdown — I'm seeing an example of this. `virsh > dommemstat` on one instance: > > ``` > actual 249561088 > unused 35707248 > disk_caches 71486684 > rss 216835168 > ``` > > Guest itself reports ~68GB as reclaimable disk cache (via balloon), > but host-side RSS for QEMU is ~207GB — almost the full allocation. > Seems like once guest pages are touched they're backed 1:1 by host > RAM, so the host can't tell cache pages apart from "real" usage — it > just sees high RSS. > > So `cache=none` doesn't apply here (that's host-side caching of the > disk image, different thing), that is not waht that is
that is host side cachign fo reads/write to the disk image not cachign of the disk image iself.
> and the sysctl tuning is also host-side only. Is > ballooning/free-page-reporting really the only way to reclaim this > from the host, or is there another lever I'm missing? i think there may be a disconenct betwen expectaions form an openstack perspective if a guest touches a page adn qemu allcoate it openstack and hte host kernel in genreeal should not know whtehr the guest is activlly usign that page or the guest kernel is suign it for tis own cache. those are the same form teh host perspective by design and we do nto attapemt to optimise the guest cache usage
that crossing a trust bondary that as a cloud operator you generally shoudl not cross unless this is a proviage cloud where you are contolign the workload.
ballooning/free-page-reporting is the only way to reclaim from the host side the breakdwon of the memory usage in the guest is entirely ther own private business and not somethign we should be tryign to mange form the host.
> Nguyen Huu Khoi > > On Tue, Aug 25, 2026, 6:53 PM Sean Mooney <smooney@redhat.com> wrote: > > i assume when you say for cache you mean the kernel page cache ectra > > the only tuneable that nova has related to caching is >
https://docs.openstack.org/nova/latest/configuration/config.html#libvirt.dis...
> which will allow you to contole qemus block device caching behvior > [libvirt] > > disk_cachemodes=file=none,block=none,network=none > > if you want to trune the kernel to mor agressivly relaime the file > system cache you can teake the following values > > ``` > # Prefer reclaiming filesystem cache over swapping VM/process > anonymous > memory > vm.swappiness = 10 > > # Reclaim inode/dentry caches somewhat more aggressively > vm.vfs_cache_pressure = 200 > > # Keep the amount of dirty page cache bounded > vm.dirty_background_ratio = 2 > vm.dirty_ratio = 5 > # or via fixed value rather then percents 512M and 2G
respctivly
> # on large systems using the byte valeus is a little more predicable > #vm.dirty_background_bytes = 536870912 > #vm.dirty_bytes = 2147483648 > ``` > > vm.watermark_scale_factor i apprenly also relevent to memroy > reclaim but > its not a value i have personally used in the past > > basically
https://wiki.archlinux.org/title/Sysctl#Virtual_memory
> you might also be interested in > https://wiki.archlinux.org/title/Zswap > if your realy tring to pack as much vms on a host as possible > > in ci we are optimisting for a diffent usecase but you can see thw > values we are settin >
https://github.com/openstack/devstack/blob/master/lib/host#L68-L118
> > we defer writes when there is free memroy and tell the kerenl
ot
> consider swapping to be the same > cost as page caching since swap is actully accclerated via the zswap > compressoin ratio. > > on linux cache usage is not gerenally cosndier a bad thing it just he > kernel being efficet about > avdiedin disk reads/writes > those caches will alwsy be purged when memory is needed for other > usecases. > > in general we do not recommend hvelly over commiting in memory and > alwasy recomemnd havign enough swap for thte total memy time sthe > over > commit ration if that ratio exceeds 1.0 > that is so that the kernel never has to choose between OOM killing > your > guest or paging its memory but > beyound that i dont realy have any ohter advice on this topic.
i
> generally woudl not try > to force cache memory reclaim with somethign like > > `echo3> /proc/sys/vm/drop_caches` > > i personally do not like any of tuned's in tree profiles but that may > also hlep you find > intersint tunabels to consider > https://github.com/redhat-performance/tuned/tree/master/profiles > > > > On 25/08/2026 08:35, Nguyễn Hữu Khôi wrote: > > Hi Sean, > > This patch is working fine but I see that the other problem
is
> > instances using memory for cache so It is hard to reclaim memory in > > this case? Would you tell me some ideas to work with this case? > > Nguyen Huu Khoi > > > > > > On Mon, Sep 29, 2025 at 6:52 PM Sean Mooney <smooney@redhat.com> > wrote: > > > > im glad to hear that. > > > > for those wondering which patch > > https://review.opendev.org/c/openstack/nova/+/952306 > > > > will be part of 2025.2 which should be released in 2
days.
> > > > we also fixed and backporte the ablity to disable the memballon > > device > > entirly > > > > https://review.opendev.org/c/openstack/nova/+/952961 > > > > so if you do not want qemu to automatically report that the > memory > > can > > be freeded > > when the guest frees memory you can set > mem_stats_period_seconds=0 > > which is > > the recommendation for realtime hosts. > > > > On 25/09/2025 05:03, Nguyễn Hữu Khôi wrote: > > > Hi Sean. > > > > > > Thank you for the patch, I tested it and it works as I expect. > > > > > > Nguyen Huu Khoi > > > > > > > > > On Wed, May 21, 2025 at 8:10 PM Nguyễn Hữu Khôi > > > <nguyenhuukhoinw@gmail.com> wrote: > > > > > > Hello. > > > Thank you for your very detailed explanation. and I hope > > that will > > > come with Openstack in the near future so with it we can > > rebalance > > > instances more efficiently. > > > Nguyen Huu Khoi > > > > > > > > > On Wed, May 21, 2025 at 3:13 PM Sean Mooney > <smooney@redhat.com> > > > wrote: > > > > > > > > > On 21/05/2025 05:22, Nguyễn Hữu Khôi wrote: > > > > Hello. > > > > > > > > I have an OpenStack instance that was using > 14GB out of > > > 16GB of > > > > memory. Later, when it was using only 4GB, I > checked the > > > QEMU process > > > > on the compute node, and it was still consuming > 14GB, this > > > means > > > > memory isn't released when usage decreases. > > > > > > correct this is the current designed behavior. > > > > > > while the mem balloon is enable there has never > been support > > > for using > > > that to free unallcoated memory when teh guest > frees pages > > > > > > the men-ballon was originally added in nova purely > to allow > > > gathering > > > guest memory statistics. > > > > > > if your over allocating memory in nova your > required to have > > > sufficient > > > swap space so that the kernel can page out the > inactive > > memory. > > > > > > > > > > > Do we have solutions for this? I use Ubuntu 24.04 > > instances. > > > > > > It would be a new RFE > > > > > > its not one that we have not consiered before but > its just > > > never been a > > > priority since this is not how we expect to
over
> subsribe. > > > > > > we over subscribe via swap space. runing nova > without swap > > > leads to the > > > python interpreture usign more memory then required > > > otherwise, that partly why we do not recommend running > > without > > > swap even > > > if guest memory oversubscribe is not planned. > > > > > > since swap shoudl alwasy be present on compute > nodes it the > > > natural > > > extension prefer it for oversubscribtion and
let
> the kernel > > > > > > manage paging then maintaining another agent or > > requireing you > > > to use an > > > external one. > > > > > > > > > libvirt has gained some funtionality in thsi space > that > > i have > > > consiered > > > writign a patch to enable > > > > > > https://libvirt.org/formatdomain.html#memory-balloon-device > > > > > > specificly > > > > > > > > > ``` > > > > > > autodeflate > > > > > > The optional autodeflate attribute allows
to
> > > enable/disable (values > > > "on"/"off", respectively) the ability of
the
> QEMU virtio > > > memory > > > balloon to release some memory at the last moment > > before a > > > guest's > > > process get killed by Out of Memory killer. > Since 1.3.1, > > > QEMU and > > > KVM only > > > > > > freePageReporting > > > > > > The optional freePageReporting attribute allows to > > > enable/disable > > > ("on"/"off", respectively) the ability of the QEMU > > virtio > > > memory > > > balloon to return unused pages back to the > hypervisor to > > > be used by > > > other guests or processes. Please note that > despite its > > > name it has > > > no effect on free memory as reported by > > virDomainMemoryStats() > > > and/or virsh dommemstat. Since 6.9.0, QEMU and > KVM only > > > > > > ``` > > > > > > auto deflate would make sent to enable > unconditionally in an > > > opnestack > > > env for deomains not using file or hugepage backed > memory. > > > > > > freePageReporting is the value that peaked my interest > > on this > > > topic > > > most recently. in caracal we finally got our
min
> libvirt > > > version high enough > > > > > > to be able to use it un contiontally as well. > > > > > > > > > thats the feature you want and its not hard to add i > > just have > > > not had > > > time to work on this lately. > > > > > > > > > if you want to submit a patch to work on those
i
> think this > > > could be > > > covered as a small specless blueprint. > > > > > > prior to caracal this would have been much more > painfail to > > > enabel as > > > nova woudl have needed to implement an agent to do the > > memroy > > > freeign. > > > > > > that is what proxymox and ovirt have done in
the
> past to get > > > the same > > > effect. > > > > > > now that libvirt has native support we can just > turn it > > on and > > > let it do > > > it on our behalf. > > > > > > > > > > > Nguyen Huu Khoi > > > > > >
On 25/08/2026 15:05, Nguyễn Hữu Khôi wrote:
Hi. Thank for your reply. I would like to ask if someone submit this feature and is there any chance to become an official support? its unlikely there were propsoal sot do auto balloning in the past but it can cause guest application to crash ovirt had a script/agent for it but i think this is not a feature that fits in nova.
Nguyen Huu Khoi
On Tue, Aug 25, 2026, 8:50 PM Sean Mooney <smooney@redhat.com> wrote:
On 25/08/2026 14:35, Nguyễn Hữu Khôi wrote: > Thanks, that confirms it. So virsh setmem is the manual lever for this > then — lowering actual below current usage triggers the balloon driver > in the guest to reclaim (cache first) and hand pages back, which > should bring host-side RSS down over time? yes but we dont supprot doing that in nova if you want to use that api direcly you can make that choce for your cloud but the vm wil nolonger be supprot and any memory related bug are not nova bugs. > > Do u think it will resolve our problem? perhaps but nova is working as intended as is qemu form what i can tell > > Nguyen Huu Khoi > > > > On Tue, Aug 25, 2026, 8:18 PM Sean Mooney <smooney@redhat.com> wrote: > > On 25/08/2026 14:09, Nguyễn Hữu Khôi wrote: > > > > Thanks for the breakdown — I'm seeing an example of this. `virsh > > dommemstat` on one instance: > > > > ``` > > actual 249561088 > > unused 35707248 > > disk_caches 71486684 > > rss 216835168 > > ``` > > > > Guest itself reports ~68GB as reclaimable disk cache (via balloon), > > but host-side RSS for QEMU is ~207GB — almost the full allocation. > > Seems like once guest pages are touched they're backed 1:1 by host > > RAM, so the host can't tell cache pages apart from "real" usage > — it > > just sees high RSS. > > > > So `cache=none` doesn't apply here (that's host-side caching of the > > disk image, different thing), > that is not waht that is > > that is host side cachign fo reads/write to the disk image not > cachign > of the disk image iself. > > > and the sysctl tuning is also host-side only. Is > > ballooning/free-page-reporting really the only way to reclaim this > > from the host, or is there another lever I'm missing? > i think there may be a disconenct betwen expectaions > form an openstack perspective if a guest touches a page adn qemu > allcoate it openstack and hte host kernel in genreeal should not know > whtehr the guest is activlly usign that page or the guest kernel is > suign it for tis own cache. > those are the same form teh host perspective by design and we do nto > attapemt to optimise the guest cache usage > > that crossing a trust bondary that as a cloud operator you generally > shoudl not cross unless this is a proviage cloud where you are > contolign > the workload. > > > ballooning/free-page-reporting is the only way to reclaim from > the host > side > the breakdwon of the memory usage in the guest is entirely ther own > private business and > not somethign we should be tryign to mange form the host. > > > Nguyen Huu Khoi > > > > On Tue, Aug 25, 2026, 6:53 PM Sean Mooney <smooney@redhat.com> > wrote: > > > > i assume when you say for cache you mean the kernel page > cache ectra > > > > the only tuneable that nova has related to caching is > > > https://docs.openstack.org/nova/latest/configuration/config.html#libvirt.dis... > > which will allow you to contole qemus block device caching > behvior > > [libvirt] > > > > disk_cachemodes=file=none,block=none,network=none > > > > if you want to trune the kernel to mor agressivly relaime > the file > > system cache you can teake the following values > > > > ``` > > # Prefer reclaiming filesystem cache over swapping VM/process > > anonymous > > memory > > vm.swappiness = 10 > > > > # Reclaim inode/dentry caches somewhat more aggressively > > vm.vfs_cache_pressure = 200 > > > > # Keep the amount of dirty page cache bounded > > vm.dirty_background_ratio = 2 > > vm.dirty_ratio = 5 > > # or via fixed value rather then percents 512M and 2G respctivly > > # on large systems using the byte valeus is a little more > predicable > > #vm.dirty_background_bytes = 536870912 > > #vm.dirty_bytes = 2147483648 > > ``` > > > > vm.watermark_scale_factor i apprenly also relevent to memroy > > reclaim but > > its not a value i have personally used in the past > > > > basically https://wiki.archlinux.org/title/Sysctl#Virtual_memory > > you might also be interested in > > https://wiki.archlinux.org/title/Zswap > > if your realy tring to pack as much vms on a host as possible > > > > in ci we are optimisting for a diffent usecase but you can > see thw > > values we are settin > > https://github.com/openstack/devstack/blob/master/lib/host#L68-L118 > > > > we defer writes when there is free memroy and tell the kerenl ot > > consider swapping to be the same > > cost as page caching since swap is actully accclerated via > the zswap > > compressoin ratio. > > > > on linux cache usage is not gerenally cosndier a bad thing > it just he > > kernel being efficet about > > avdiedin disk reads/writes > > those caches will alwsy be purged when memory is needed for > other > > usecases. > > > > in general we do not recommend hvelly over commiting in > memory and > > alwasy recomemnd havign enough swap for thte total memy time > sthe > > over > > commit ration if that ratio exceeds 1.0 > > that is so that the kernel never has to choose between OOM > killing > > your > > guest or paging its memory but > > beyound that i dont realy have any ohter advice on this topic. i > > generally woudl not try > > to force cache memory reclaim with somethign like > > > > `echo3> /proc/sys/vm/drop_caches` > > > > i personally do not like any of tuned's in tree profiles but > that may > > also hlep you find > > intersint tunabels to consider > > https://github.com/redhat-performance/tuned/tree/master/profiles > > > > > > > > On 25/08/2026 08:35, Nguyễn Hữu Khôi wrote: > > > Hi Sean, > > > This patch is working fine but I see that the other problem is > > > instances using memory for cache so It is hard to reclaim > memory in > > > this case? Would you tell me some ideas to work with this > case? > > > Nguyen Huu Khoi > > > > > > > > > On Mon, Sep 29, 2025 at 6:52 PM Sean Mooney > <smooney@redhat.com> > > wrote: > > > > > > im glad to hear that. > > > > > > for those wondering which patch > > > https://review.opendev.org/c/openstack/nova/+/952306 > > > > > > will be part of 2025.2 which should be released in 2 days. > > > > > > we also fixed and backporte the ablity to disable the > memballon > > > device > > > entirly > > > > > > https://review.opendev.org/c/openstack/nova/+/952961 > > > > > > so if you do not want qemu to automatically report > that the > > memory > > > can > > > be freeded > > > when the guest frees memory you can set > > mem_stats_period_seconds=0 > > > which is > > > the recommendation for realtime hosts. > > > > > > On 25/09/2025 05:03, Nguyễn Hữu Khôi wrote: > > > > Hi Sean. > > > > > > > > Thank you for the patch, I tested it and it works as > I expect. > > > > > > > > Nguyen Huu Khoi > > > > > > > > > > > > On Wed, May 21, 2025 at 8:10 PM Nguyễn Hữu Khôi > > > > <nguyenhuukhoinw@gmail.com> wrote: > > > > > > > > Hello. > > > > Thank you for your very detailed explanation. > and I hope > > > that will > > > > come with Openstack in the near future so with > it we can > > > rebalance > > > > instances more efficiently. > > > > Nguyen Huu Khoi > > > > > > > > > > > > On Wed, May 21, 2025 at 3:13 PM Sean Mooney > > <smooney@redhat.com> > > > > wrote: > > > > > > > > > > > > On 21/05/2025 05:22, Nguyễn Hữu Khôi wrote: > > > > > Hello. > > > > > > > > > > I have an OpenStack instance that was using > > 14GB out of > > > > 16GB of > > > > > memory. Later, when it was using only 4GB, I > > checked the > > > > QEMU process > > > > > on the compute node, and it was still > consuming > > 14GB, this > > > > means > > > > > memory isn't released when usage decreases. > > > > > > > > correct this is the current designed behavior. > > > > > > > > while the mem balloon is enable there has never > > been support > > > > for using > > > > that to free unallcoated memory when teh guest > > frees pages > > > > > > > > the men-ballon was originally added in nova > purely > > to allow > > > > gathering > > > > guest memory statistics. > > > > > > > > if your over allocating memory in nova your > > required to have > > > > sufficient > > > > swap space so that the kernel can page out the > > inactive > > > memory. > > > > > > > > > > > > > > Do we have solutions for this? I use > Ubuntu 24.04 > > > instances. > > > > > > > > It would be a new RFE > > > > > > > > its not one that we have not consiered > before but > > its just > > > > never been a > > > > priority since this is not how we expect to over > > subsribe. > > > > > > > > we over subscribe via swap space. runing nova > > without swap > > > > leads to the > > > > python interpreture usign more memory then > required > > > > otherwise, that partly why we do not > recommend running > > > without > > > > swap even > > > > if guest memory oversubscribe is not planned. > > > > > > > > since swap shoudl alwasy be present on compute > > nodes it the > > > > natural > > > > extension prefer it for oversubscribtion and let > > the kernel > > > > > > > > manage paging then maintaining another agent or > > > requireing you > > > > to use an > > > > external one. > > > > > > > > > > > > libvirt has gained some funtionality in thsi > space > > that > > > i have > > > > consiered > > > > writign a patch to enable > > > > > > > > > https://libvirt.org/formatdomain.html#memory-balloon-device > > > > > > > > specificly > > > > > > > > > > > > ``` > > > > > > > > autodeflate > > > > > > > > The optional autodeflate attribute allows to > > > > enable/disable (values > > > > "on"/"off", respectively) the ability of the > > QEMU virtio > > > > memory > > > > balloon to release some memory at the > last moment > > > before a > > > > guest's > > > > process get killed by Out of Memory killer. > > Since 1.3.1, > > > > QEMU and > > > > KVM only > > > > > > > > freePageReporting > > > > > > > > The optional freePageReporting attribute > allows to > > > > enable/disable > > > > ("on"/"off", respectively) the ability > of the QEMU > > > virtio > > > > memory > > > > balloon to return unused pages back to the > > hypervisor to > > > > be used by > > > > other guests or processes. Please note that > > despite its > > > > name it has > > > > no effect on free memory as reported by > > > virDomainMemoryStats() > > > > and/or virsh dommemstat. Since 6.9.0, > QEMU and > > KVM only > > > > > > > > ``` > > > > > > > > auto deflate would make sent to enable > > unconditionally in an > > > > opnestack > > > > env for deomains not using file or hugepage > backed > > memory. > > > > > > > > freePageReporting is the value that peaked > my interest > > > on this > > > > topic > > > > most recently. in caracal we finally got our min > > libvirt > > > > version high enough > > > > > > > > to be able to use it un contiontally as well. > > > > > > > > > > > > thats the feature you want and its not hard > to add i > > > just have > > > > not had > > > > time to work on this lately. > > > > > > > > > > > > if you want to submit a patch to work on those i > > think this > > > > could be > > > > covered as a small specless blueprint. > > > > > > > > prior to caracal this would have been much more > > painfail to > > > > enabel as > > > > nova woudl have needed to implement an agent > to do the > > > memroy > > > > freeign. > > > > > > > > that is what proxymox and ovirt have done in the > > past to get > > > > the same > > > > effect. > > > > > > > > now that libvirt has native support we can just > > turn it > > > on and > > > > let it do > > > > it on our behalf. > > > > > > > > > > > > > > Nguyen Huu Khoi > > > > > > > > > >
Ok. I get it now. Thank you very much. Nguyen Huu Khoi On Tue, Aug 25, 2026, 9:10 PM Sean Mooney <smooney@redhat.com> wrote:
On 25/08/2026 15:05, Nguyễn Hữu Khôi wrote:
Hi. Thank for your reply. I would like to ask if someone submit this feature and is there any chance to become an official support? its unlikely there were propsoal sot do auto balloning in the past but it can cause guest application to crash ovirt had a script/agent for it but i think this is not a feature that fits in nova.
Nguyen Huu Khoi
On Tue, Aug 25, 2026, 8:50 PM Sean Mooney <smooney@redhat.com> wrote:
On 25/08/2026 14:35, Nguyễn Hữu Khôi wrote: > Thanks, that confirms it. So virsh setmem is the manual lever for this > then — lowering actual below current usage triggers the balloon driver > in the guest to reclaim (cache first) and hand pages back, which > should bring host-side RSS down over time? yes but we dont supprot doing that in nova if you want to use that api direcly you can make that choce for your cloud but the vm wil nolonger be supprot and any memory related bug are not nova bugs. > > Do u think it will resolve our problem? perhaps but nova is working as intended as is qemu form what i can tell > > Nguyen Huu Khoi > > > > On Tue, Aug 25, 2026, 8:18 PM Sean Mooney <smooney@redhat.com> wrote: > > On 25/08/2026 14:09, Nguyễn Hữu Khôi wrote: > > > > Thanks for the breakdown — I'm seeing an example of this. `virsh > > dommemstat` on one instance: > > > > ``` > > actual 249561088 > > unused 35707248 > > disk_caches 71486684 > > rss 216835168 > > ``` > > > > Guest itself reports ~68GB as reclaimable disk cache (via balloon), > > but host-side RSS for QEMU is ~207GB — almost the full allocation. > > Seems like once guest pages are touched they're backed 1:1 by host > > RAM, so the host can't tell cache pages apart from "real" usage > — it > > just sees high RSS. > > > > So `cache=none` doesn't apply here (that's host-side caching of the > > disk image, different thing), > that is not waht that is > > that is host side cachign fo reads/write to the disk image not > cachign > of the disk image iself. > > > and the sysctl tuning is also host-side only. Is > > ballooning/free-page-reporting really the only way to reclaim this > > from the host, or is there another lever I'm missing? > i think there may be a disconenct betwen expectaions > form an openstack perspective if a guest touches a page adn qemu > allcoate it openstack and hte host kernel in genreeal should not know > whtehr the guest is activlly usign that page or the guest kernel is > suign it for tis own cache. > those are the same form teh host perspective by design and we do nto > attapemt to optimise the guest cache usage > > that crossing a trust bondary that as a cloud operator you generally > shoudl not cross unless this is a proviage cloud where you are > contolign > the workload. > > > ballooning/free-page-reporting is the only way to reclaim from > the host > side > the breakdwon of the memory usage in the guest is entirely ther own > private business and > not somethign we should be tryign to mange form the host. > > > Nguyen Huu Khoi > > > > On Tue, Aug 25, 2026, 6:53 PM Sean Mooney < smooney@redhat.com> > wrote: > > > > i assume when you say for cache you mean the kernel page > cache ectra > > > > the only tuneable that nova has related to caching is > > >
https://docs.openstack.org/nova/latest/configuration/config.html#libvirt.dis...
> > which will allow you to contole qemus block device
caching
> behvior > > [libvirt] > > > > disk_cachemodes=file=none,block=none,network=none > > > > if you want to trune the kernel to mor agressivly relaime > the file > > system cache you can teake the following values > > > > ``` > > # Prefer reclaiming filesystem cache over swapping VM/process > > anonymous > > memory > > vm.swappiness = 10 > > > > # Reclaim inode/dentry caches somewhat more aggressively > > vm.vfs_cache_pressure = 200 > > > > # Keep the amount of dirty page cache bounded > > vm.dirty_background_ratio = 2 > > vm.dirty_ratio = 5 > > # or via fixed value rather then percents 512M and 2G respctivly > > # on large systems using the byte valeus is a little more > predicable > > #vm.dirty_background_bytes = 536870912 > > #vm.dirty_bytes = 2147483648 > > ``` > > > > vm.watermark_scale_factor i apprenly also relevent to memroy > > reclaim but > > its not a value i have personally used in the past > > > > basically https://wiki.archlinux.org/title/Sysctl#Virtual_memory > > you might also be interested in > > https://wiki.archlinux.org/title/Zswap > > if your realy tring to pack as much vms on a host as possible > > > > in ci we are optimisting for a diffent usecase but you
can
> see thw > > values we are settin > > https://github.com/openstack/devstack/blob/master/lib/host#L68-L118 > > > > we defer writes when there is free memroy and tell the kerenl ot > > consider swapping to be the same > > cost as page caching since swap is actully accclerated
via
> the zswap > > compressoin ratio. > > > > on linux cache usage is not gerenally cosndier a bad
thing
> it just he > > kernel being efficet about > > avdiedin disk reads/writes > > those caches will alwsy be purged when memory is needed for > other > > usecases. > > > > in general we do not recommend hvelly over commiting in > memory and > > alwasy recomemnd havign enough swap for thte total memy time > sthe > > over > > commit ration if that ratio exceeds 1.0 > > that is so that the kernel never has to choose between
OOM
> killing > > your > > guest or paging its memory but > > beyound that i dont realy have any ohter advice on this topic. i > > generally woudl not try > > to force cache memory reclaim with somethign like > > > > `echo3> /proc/sys/vm/drop_caches` > > > > i personally do not like any of tuned's in tree profiles but > that may > > also hlep you find > > intersint tunabels to consider > > https://github.com/redhat-performance/tuned/tree/master/profiles > > > > > > > > On 25/08/2026 08:35, Nguyễn Hữu Khôi wrote: > > > Hi Sean, > > > This patch is working fine but I see that the other problem is > > > instances using memory for cache so It is hard to reclaim > memory in > > > this case? Would you tell me some ideas to work with this > case? > > > Nguyen Huu Khoi > > > > > > > > > On Mon, Sep 29, 2025 at 6:52 PM Sean Mooney > <smooney@redhat.com> > > wrote: > > > > > > im glad to hear that. > > > > > > for those wondering which patch > > > https://review.opendev.org/c/openstack/nova/+/952306 > > > > > > will be part of 2025.2 which should be released in 2 days. > > > > > > we also fixed and backporte the ablity to disable the > memballon > > > device > > > entirly > > > > > > https://review.opendev.org/c/openstack/nova/+/952961 > > > > > > so if you do not want qemu to automatically report > that the > > memory > > > can > > > be freeded > > > when the guest frees memory you can set > > mem_stats_period_seconds=0 > > > which is > > > the recommendation for realtime hosts. > > > > > > On 25/09/2025 05:03, Nguyễn Hữu Khôi wrote: > > > > Hi Sean. > > > > > > > > Thank you for the patch, I tested it and it works as > I expect. > > > > > > > > Nguyen Huu Khoi > > > > > > > > > > > > On Wed, May 21, 2025 at 8:10 PM Nguyễn Hữu Khôi > > > > <nguyenhuukhoinw@gmail.com> wrote: > > > > > > > > Hello. > > > > Thank you for your very detailed explanation. > and I hope > > > that will > > > > come with Openstack in the near future so
with
> it we can > > > rebalance > > > > instances more efficiently. > > > > Nguyen Huu Khoi > > > > > > > > > > > > On Wed, May 21, 2025 at 3:13 PM Sean Mooney > > <smooney@redhat.com> > > > > wrote: > > > > > > > > > > > > On 21/05/2025 05:22, Nguyễn Hữu Khôi wrote: > > > > > Hello. > > > > > > > > > > I have an OpenStack instance that was using > > 14GB out of > > > > 16GB of > > > > > memory. Later, when it was using only 4GB, I > > checked the > > > > QEMU process > > > > > on the compute node, and it was still > consuming > > 14GB, this > > > > means > > > > > memory isn't released when usage decreases. > > > > > > > > correct this is the current designed behavior. > > > > > > > > while the mem balloon is enable there has never > > been support > > > > for using > > > > that to free unallcoated memory when teh guest > > frees pages > > > > > > > > the men-ballon was originally added in nova > purely > > to allow > > > > gathering > > > > guest memory statistics. > > > > > > > > if your over allocating memory in nova your > > required to have > > > > sufficient > > > > swap space so that the kernel can page out the > > inactive > > > memory. > > > > > > > > > > > > > > Do we have solutions for this? I use > Ubuntu 24.04 > > > instances. > > > > > > > > It would be a new RFE > > > > > > > > its not one that we have not consiered > before but > > its just > > > > never been a > > > > priority since this is not how we expect to over > > subsribe. > > > > > > > > we over subscribe via swap space. runing nova > > without swap > > > > leads to the > > > > python interpreture usign more memory
then
> required > > > > otherwise, that partly why we do not > recommend running > > > without > > > > swap even > > > > if guest memory oversubscribe is not planned. > > > > > > > > since swap shoudl alwasy be present on compute > > nodes it the > > > > natural > > > > extension prefer it for oversubscribtion and let > > the kernel > > > > > > > > manage paging then maintaining another agent or > > > requireing you > > > > to use an > > > > external one. > > > > > > > > > > > > libvirt has gained some funtionality in thsi > space > > that > > > i have > > > > consiered > > > > writign a patch to enable > > > > > > > > > https://libvirt.org/formatdomain.html#memory-balloon-device > > > > > > > > specificly > > > > > > > > > > > > ``` > > > > > > > > autodeflate > > > > > > > > The optional autodeflate attribute allows to > > > > enable/disable (values > > > > "on"/"off", respectively) the ability of the > > QEMU virtio > > > > memory > > > > balloon to release some memory at the > last moment > > > before a > > > > guest's > > > > process get killed by Out of Memory killer. > > Since 1.3.1, > > > > QEMU and > > > > KVM only > > > > > > > > freePageReporting > > > > > > > > The optional freePageReporting attribute > allows to > > > > enable/disable > > > > ("on"/"off", respectively) the
ability
> of the QEMU > > > virtio > > > > memory > > > > balloon to return unused pages back to the > > hypervisor to > > > > be used by > > > > other guests or processes. Please note that > > despite its > > > > name it has > > > > no effect on free memory as reported by > > > virDomainMemoryStats() > > > > and/or virsh dommemstat. Since 6.9.0, > QEMU and > > KVM only > > > > > > > > ``` > > > > > > > > auto deflate would make sent to enable > > unconditionally in an > > > > opnestack > > > > env for deomains not using file or hugepage > backed > > memory. > > > > > > > > freePageReporting is the value that
peaked
> my interest > > > on this > > > > topic > > > > most recently. in caracal we finally got our min > > libvirt > > > > version high enough > > > > > > > > to be able to use it un contiontally as well. > > > > > > > > > > > > thats the feature you want and its not hard > to add i > > > just have > > > > not had > > > > time to work on this lately. > > > > > > > > > > > > if you want to submit a patch to work on those i > > think this > > > > could be > > > > covered as a small specless blueprint. > > > > > > > > prior to caracal this would have been much more > > painfail to > > > > enabel as > > > > nova woudl have needed to implement an agent > to do the > > > memroy > > > > freeign. > > > > > > > > that is what proxymox and ovirt have done in the > > past to get > > > > the same > > > > effect. > > > > > > > > now that libvirt has native support we can just > > turn it > > > on and > > > > let it do > > > > it on our behalf. > > > > > > > > > > > > > > Nguyen Huu Khoi > > > > > > > > > >
participants (2)
-
Nguyễn Hữu Khôi
-
Sean Mooney