David Hildenbrand
2022-Aug-01 20:12 UTC
[PATCH v6 1/2] Create debugfs file with virtio balloon usage information
>>> + >>> + if (!virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_DEFLATE_ON_OOM)) >>> + num_pages = -num_pages; >> With VIRTIO_BALLOON_F_DEFLATE_ON_OOM this will now always report "0". >> >> which would be the same as "num_pages = 0;" and would deserve a comment >> explaining why we don't indicate that as "inflated: ". >> >> Thanks. > > Except if "now" refers to some commit that i am missing it does not report 0./me facepalm I read "-= num_pages"> > > with qemu-system-x86_64 -enable-kvm -device virtio-balloon,id=balloon0,deflate-on-oom=on,notify_on_empty=on,page-per-vq=on -m 3G .... > > / # cat /sys/kernel/debug/virtio-balloon > inflated: 0 kB > / # QEMU 4.2.1 monitor - type 'help' for more information > (qemu) balloon 1024 > (qemu) > > / # cat /sys/kernel/debug/virtio-balloon > inflated: 2097152 kB > / # > > with qemu-system-x86_64? -enable-kvm -device > virtio-balloon,id=balloon0,deflate-on-oom=off,notify_on_empty=on,page-per-vq=on > -m 3G ... > > / # cat /sys/kernel/debug/virtio-balloon > inflated: 0 kB > / # QEMU 4.2.1 monitor - type 'help' for more information > (qemu) balloon 1024 > (qemu) > / # cat /sys/kernel/debug/virtio-balloon > inflated: -2097152 kBWhat's the rationale of making it negative?> > To join the threads: > >>> Always account inflated memory as used for both cases - with and >>> without deflate on oom. Do not change total ram which can confuse >>> userspace and users. > >> Sorry, but NAK. > > Ok. > >> This would affect existing users / user space / balloon stats. For example >> HV just recently switch to properly using adjust_managed_page_count() > > > I am wondering what's the rationale behind this i have never seen such users > that expect it to work like this. Do you have any pointers to such users, so > i can understood why they do so ?We adjust total pages and managed pages to simulate what memory is actually available to the system (just like during memory hot(un)plug). Even though the pages are "allocated" by the driver, they are actually unusable for the system, just as if they would have been offlined. Strictly speaking, the guest OS can kill as many processes as it wants, it cannot reclaim that memory, as it's logically no longer available. There is nothing (valid, well, except driver unloading) the guest can do to reuse these pages. The hypervisor has to get involved first to grant access to some of these pages again (deflate the balloon). It's different with deflate-on-oom: the guest will *itself* decide to reuse inflated pages to deflate them. So the allocated pages can become back usable easily. There was a recent discussion for virtio-balloon to change that behavior when it's known that the hypervisor essentially implements "deflate-on-oom" by looking at guest memory stats and adjusting the balloon size accordingly; however, as long as we don't know what the hypervisor does or doesn't do, we have to keep the existing behavior. Note that most balloon drivers under Linux share that behavior. In case of Hyper-V I remember a customer BUG report that requested that exact behavior, however, I'm not able to locate the BZ quickly. [1] https://lists.linuxfoundation.org/pipermail/virtualization/2021-November/057767.html (note that I can't easily find the original mail in the archives) Note: I suggested under [1] to expose inflated pages via /proc/meminfo directly. We could do that consistently over all balloon drivers ... doesn't sound too crazy. -- Thanks, David / dhildenb