On Tue, Sep 08, 2026 at 03:48:38PM -0500, Michael Roth wrote: > When using in-place conversion, there is no need to discard memory after > conversion because the same memory will continue to be used after the > conversion to back the same GPA. Discarding it would only cause > unnecessary reallocation of memory after each conversion. Instead, only > enable it for non-in-place conversions. > > Signed-off-by: Michael Roth <[email protected]> > --- > accel/kvm/kvm-all.c | 22 ++++++++++++---------- > 1 file changed, 12 insertions(+), 10 deletions(-) > > diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c > index ff07050935..b28c9fbd33 100644 > --- a/accel/kvm/kvm-all.c > +++ b/accel/kvm/kvm-all.c > @@ -3611,17 +3611,19 @@ static int > kvm_post_convert_section(MemoryRegionSection *section, bool to_privat > } > } > > - if (to_private) { > - if (rb->page_size != qemu_real_host_page_size()) { > - /* > - * shared memory is backed by hugetlb, which is supposed to be > - * pre-allocated and doesn't need to be discarded > - */ > - return 0; > + if (!machine_require_guest_memfd_convert_in_place(current_machine)) { > + if (to_private) { > + if (rb->page_size != qemu_real_host_page_size()) { > + /* > + * shared memory is backed by hugetlb, which is supposed to > be > + * pre-allocated and doesn't need to be discarded > + */ > + return 0; > + } > + ret = ram_block_discard_shared_range(rb, offset, size); > + } else { > + ret = ram_block_discard_guest_memfd_range(rb, offset, size); > } > - ret = ram_block_discard_shared_range(rb, offset, size); > - } else { > - ret = ram_block_discard_guest_memfd_range(rb, offset, size); > } > > return ret;
Sorry, with this patch it's now possible to return ret when it is still uninitialized, so a "int ret = 0;" is needed above. I had the change made locally but apparently didn't amend the commit before sending :( I've gone ahead and pushed the fixed patch to the snp-inplace-v2 branch. -Mike > -- > 2.43.0 >
