[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 07/23] accel: kvm: Fix memory waste under mismatch page size
From: |
Paolo Bonzini |
Subject: |
[PULL 07/23] accel: kvm: Fix memory waste under mismatch page size |
Date: |
Sat, 6 Mar 2021 11:54:03 +0100 |
From: Keqian Zhu <zhukeqian1@huawei.com>
When handle dirty log, we face qemu_real_host_page_size and
TARGET_PAGE_SIZE. The first one is the granule of KVM dirty
bitmap, and the second one is the granule of QEMU dirty bitmap.
As qemu_real_host_page_size >= TARGET_PAGE_SIZE (kvm_init()
enforced it), misuse TARGET_PAGE_SIZE to init kvmslot dirty_bmap
may waste memory. For example, when qemu_real_host_page_size is
64K and TARGET_PAGE_SIZE is 4K, it wastes 93.75% (15/16) memory.
Signed-off-by: Keqian Zhu <zhukeqian1@huawei.com>
Reviewed-by: Andrew Jones <drjones@redhat.com>
Reviewed-by: Peter Xu <peterx@redhat.com>
Message-Id: <20201217014941.22872-2-zhukeqian1@huawei.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
accel/kvm/kvm-all.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index 84c943fcdb..ffce83f1a7 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -598,8 +598,12 @@ static void kvm_memslot_init_dirty_bitmap(KVMSlot *mem)
* too, in most cases).
* So for now, let's align to 64 instead of HOST_LONG_BITS here, in
* a hope that sizeof(long) won't become >8 any time soon.
+ *
+ * Note: the granule of kvm dirty log is qemu_real_host_page_size.
+ * And mem->memory_size is aligned to it (otherwise this mem can't
+ * be registered to KVM).
*/
- hwaddr bitmap_size = ALIGN(((mem->memory_size) >> TARGET_PAGE_BITS),
+ hwaddr bitmap_size = ALIGN(mem->memory_size / qemu_real_host_page_size,
/*HOST_LONG_BITS*/ 64) / 8;
mem->dirty_bmap = g_malloc0(bitmap_size);
}
--
2.29.2
- [PULL 00/23] Misc patches for 2021-03-06, Paolo Bonzini, 2021/03/06
- [PULL 01/23] KVM: x86: do not fail if software breakpoint has already been removed, Paolo Bonzini, 2021/03/06
- [PULL 02/23] KVM: x86: deprecate -M kernel-irqchip=off except for -M isapc, Paolo Bonzini, 2021/03/06
- [PULL 03/23] qga-vss: Use dynamic linking for GLib, Paolo Bonzini, 2021/03/06
- [PULL 04/23] chardev: add nodelay option, Paolo Bonzini, 2021/03/06
- [PULL 05/23] qom: Check for wellformed id in user_creatable_add_type(), Paolo Bonzini, 2021/03/06
- [PULL 06/23] vl.c: do not execute trace_init_backends() before daemonizing, Paolo Bonzini, 2021/03/06
- [PULL 07/23] accel: kvm: Fix memory waste under mismatch page size,
Paolo Bonzini <=
- [PULL 10/23] elf_ops: correct loading of 32 bit PVH kernel, Paolo Bonzini, 2021/03/06
- [PULL 11/23] x86/pvh: extract only 4 bytes of start address for 32 bit kernels, Paolo Bonzini, 2021/03/06
- [PULL 13/23] scsi: Rename linux-specific SG_ERR codes to generic SCSI_HOST error codes, Paolo Bonzini, 2021/03/06
- [PULL 12/23] qemu-config: add error propagation to qemu_config_parse, Paolo Bonzini, 2021/03/06
- [PULL 15/23] scsi-generic: do not snoop the output of failed commands, Paolo Bonzini, 2021/03/06
- [PULL 16/23] scsi: inline sg_io_sense_from_errno() into the callers., Paolo Bonzini, 2021/03/06
- [PULL 20/23] meson: adjust timeouts for some slower tests, Paolo Bonzini, 2021/03/06
- [PULL 21/23] trace: fix "-trace file=...", Paolo Bonzini, 2021/03/06
- [PULL 22/23] trace: skip qemu_set_log_filename if no "-D" option was passed, Paolo Bonzini, 2021/03/06
- [PULL 08/23] accel: kvm: Add aligment assert for kvm_log_clear_one_slot, Paolo Bonzini, 2021/03/06