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 --- 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; -- 2.43.0