diff mbox series

[qemu,v2,01/13] memory: Postpone flatview and dispatch tree building till all devices are added

Message ID 20170915084030.40988-2-aik@ozlabs.ru
State New
Headers show
Series memory: Reduce memory use | expand

Commit Message

Alexey Kardashevskiy Sept. 15, 2017, 8:40 a.m. UTC
Most devices use at least one address space and every time a new address
space is added, flat views and dispatch trees are rebuild for all address
spaces. This is not a problem for a relatively small amount of devices but
even 50 virtio-pci devices use more than 8GB of RAM.

What happens that on every flatview/dispatch rebuild, new arrays are
allocated and old ones release but the release is done via RCU so until
an entire machine is build, they are not released.

This wraps devices creation into memory_region_transaction_begin/commit
to massively reduce amount of flat view/dispatch tree (re)allocations.

Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
* wrapped qemu_run_machine_init_done_notifiers() as well
 vl.c | 9 +++++++++
 1 file changed, 9 insertions(+)
diff mbox series


diff --git a/vl.c b/vl.c
index fb1f05b937..ee3cc7db48 100644
--- a/vl.c
+++ b/vl.c
@@ -4661,12 +4661,16 @@  int main(int argc, char **argv, char **envp)
     /* init generic devices */
+    memory_region_transaction_begin();
     if (qemu_opts_foreach(qemu_find_opts("device"),
                           device_init_func, NULL, NULL)) {
+    memory_region_transaction_commit();
@@ -4749,8 +4753,13 @@  int main(int argc, char **argv, char **envp)
     /* TODO: once all bus devices are qdevified, this should be done
      * when bus is created by qdev.c */
     qemu_register_reset(qbus_reset_all_fn, sysbus_get_default());
+    memory_region_transaction_begin();
+    memory_region_transaction_commit();
     if (rom_check_and_register_reset() != 0) {
         error_report("rom check and register reset failed");