Open adamierymenko opened 1 year ago
That's a great idea to implement free page reporting, and that's part of recent versions of Virtio and VMWare balloon devices. I'll look into that (At last a good virtio device with no direct HW replacements, lol). There are also other good memory saving techniques in RVVM: KSM (Page merging, could also reclaim free pages in some cases) and transparent caches (Guest caches may be reclaimed by host).
Be aware however that explicit ballooning on host demand (Initial usecase of Virtio Balloon device) isn't that great of a concept: You force the guest to use less memory, and it most likely will start swapping / will OOM. It is much better to have large amount of virtual memory (zram/swap) on the host - from efficiency standpoint. Otherwise you'll just make pressure on the guest and make it suffer.
https://github.com/LekKit/RVVM/issues/147#issuecomment-2384627249
virtio-balloon is a guest device, and has two separate modes of operation:
* Actual "ballooning" (as implied by the original devie name), where host forces the guest to "reserve" it's physical pages and then reclaims those pages on the host. It's a weird, old mode which is unlikely to ever be implemented in RVVM because it's just badly designed * Free page reporting: A newer mode, where guests gets to report pages which are **actually** unused, then the VM can zero them without any harm for the guest.
The needed host-specific functionality is already implemented in
src/vma_ops.c
, specificallyvma_clean()
function. It works on any OS including Windows. It is also already used to release unused JIT heap space. So it's a matter of writing a virtio-balloon device emulation driver.It is mostly redundant feature if we consider KSM, but it surely will help non-Linux hosts.
which is what makes it capable of returning unused paged back to the os
eg, its current memory usage without baloon would be its peak
usage for the lifetime of the processes due to the vm being unable to tell which parts of any memory it has been requested have been unused (eg freed)
eg free(malloc(10000))
malloc
gets done the vm knows only that it has to commit however much more memory to satisfy the kernel request of more memory should it have no memory available to reusefree
gets done the vm does not know if this freed memory will be reused or not so it just keeps it around and and kernel will reuse it as reusable memory instead of requesting more memoryballoon free
gets done the vm is notified that this memory will no longer be reused and thus can return it back to the host, which itself may reuse it for further allocations as per free
this may be useful https://youtu.be/Fq47WCCm-HM
a detailed overview of traditional mem balloon and virtio mem balloon / virtio-pmem / virtio-mem ect (what it is, what it does, how they work, ect)
also details free page hinting and many other features related to guest<->host memory management
some parts can be very detailed and others can lack detail for simplification
virtio related #149
might also be related to #147
Another obvious idea: implement support for minimum and maximum memory and dynamic allocation / ballooning.