[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 131/136] memory: batch allocate ioeventfds[] in address_space_upda
From: |
Paolo Bonzini |
Subject: |
[PULL 131/136] memory: batch allocate ioeventfds[] in address_space_update_ioeventfds() |
Date: |
Tue, 25 Feb 2020 13:07:29 +0100 |
From: Stefan Hajnoczi <address@hidden>
Reallocing the ioeventfds[] array each time an element is added is very
expensive as the number of ioeventfds increases. Batch allocate instead
to amortize the cost of realloc.
This patch reduces Linux guest boot times from 362s to 140s when there
are 2 virtio-blk devices with 1 virtqueue and 99 virtio-blk devices with
32 virtqueues.
Signed-off-by: Stefan Hajnoczi <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
memory.c | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/memory.c b/memory.c
index aeaa8dc..09be40e 100644
--- a/memory.c
+++ b/memory.c
@@ -794,10 +794,19 @@ static void address_space_update_ioeventfds(AddressSpace
*as)
FlatView *view;
FlatRange *fr;
unsigned ioeventfd_nb = 0;
- MemoryRegionIoeventfd *ioeventfds = NULL;
+ unsigned ioeventfd_max;
+ MemoryRegionIoeventfd *ioeventfds;
AddrRange tmp;
unsigned i;
+ /*
+ * It is likely that the number of ioeventfds hasn't changed much, so use
+ * the previous size as the starting value, with some headroom to avoid
+ * gratuitous reallocations.
+ */
+ ioeventfd_max = QEMU_ALIGN_UP(as->ioeventfd_nb, 4);
+ ioeventfds = g_new(MemoryRegionIoeventfd, ioeventfd_max);
+
view = address_space_get_flatview(as);
FOR_EACH_FLAT_RANGE(fr, view) {
for (i = 0; i < fr->mr->ioeventfd_nb; ++i) {
@@ -806,8 +815,11 @@ static void address_space_update_ioeventfds(AddressSpace
*as)
int128_make64(fr->offset_in_region)));
if (addrrange_intersects(fr->addr, tmp)) {
++ioeventfd_nb;
- ioeventfds = g_realloc(ioeventfds,
- ioeventfd_nb * sizeof(*ioeventfds));
+ if (ioeventfd_nb > ioeventfd_max) {
+ ioeventfd_max = MAX(ioeventfd_max * 2, 4);
+ ioeventfds = g_realloc(ioeventfds,
+ ioeventfd_max * sizeof(*ioeventfds));
+ }
ioeventfds[ioeventfd_nb-1] = fr->mr->ioeventfds[i];
ioeventfds[ioeventfd_nb-1].addr = tmp;
}
--
1.8.3.1
- [PULL 119/136] hw/arm: Remove unnecessary memory_region_set_readonly() on ROM alias, (continued)
- [PULL 119/136] hw/arm: Remove unnecessary memory_region_set_readonly() on ROM alias, Paolo Bonzini, 2020/02/25
- [PULL 122/136] hw/char: Let devices own the MemoryRegion they create, Paolo Bonzini, 2020/02/25
- [PULL 123/136] hw/core: Let devices own the MemoryRegion they create, Paolo Bonzini, 2020/02/25
- [PULL 124/136] hw/display: Let devices own the MemoryRegion they create, Paolo Bonzini, 2020/02/25
- [PULL 115/136] hw/ppc/ppc405: Use memory_region_init_rom() with read-only regions, Paolo Bonzini, 2020/02/25
- [PULL 121/136] hw/arm: Let devices own the MemoryRegion they create, Paolo Bonzini, 2020/02/25
- [PULL 127/136] hw/input/milkymist-softusb: Remove unused 'pmem_ptr' field, Paolo Bonzini, 2020/02/25
- [PULL 126/136] hw/riscv: Let devices own the MemoryRegion they create, Paolo Bonzini, 2020/02/25
- [PULL 128/136] hw/input/milkymist-softusb: Let devices own the MemoryRegion they create, Paolo Bonzini, 2020/02/25
- [PULL 130/136] hw/block/onenand: Let devices own the MemoryRegion they create, Paolo Bonzini, 2020/02/25
- [PULL 131/136] memory: batch allocate ioeventfds[] in address_space_update_ioeventfds(),
Paolo Bonzini <=
- [PULL 135/136] accel/kvm: Check ioctl(KVM_SET_USER_MEMORY_REGION) return value, Paolo Bonzini, 2020/02/25
- [PULL 136/136] WHPX: Assigning maintainer for Windows Hypervisor Platform, Paolo Bonzini, 2020/02/25
- [PULL 120/136] scripts/cocci: Patch to let devices own their MemoryRegions, Paolo Bonzini, 2020/02/25
- [PULL 125/136] hw/dma: Let devices own the MemoryRegion they create, Paolo Bonzini, 2020/02/25
- [PULL 133/136] qdev-monitor: Forbid repeated device_del, Paolo Bonzini, 2020/02/25
- [PULL 129/136] hw/net/milkymist-minimac2: Let devices own the MemoryRegion they create, Paolo Bonzini, 2020/02/25
- [PULL 134/136] target/i386: check for empty register in FXAM, Paolo Bonzini, 2020/02/25
- [PULL 132/136] mem-prealloc: optimize large guest startup, Paolo Bonzini, 2020/02/25
- Re: [PULL 000/136] Misc patches for 2020-02-25 (refactoring and Coccinelle edition), Aleksandar Markovic, 2020/02/26