Blame SOURCES/kvm-memory-Do-not-allocate-FlatView-in-address_space_ini.patch

4a2fec
From 5bfc2be91ba382cf0c0353794ff9289cb9b064de Mon Sep 17 00:00:00 2001
4a2fec
From: David Gibson <dgibson@redhat.com>
4a2fec
Date: Thu, 16 Nov 2017 03:07:26 +0100
4a2fec
Subject: [PATCH 22/30] memory: Do not allocate FlatView in address_space_init
4a2fec
4a2fec
RH-Author: David Gibson <dgibson@redhat.com>
4a2fec
Message-id: <20171116030732.8560-17-dgibson@redhat.com>
4a2fec
Patchwork-id: 77705
4a2fec
O-Subject: [PATCH 16/22] memory: Do not allocate FlatView in address_space_init
4a2fec
Bugzilla: 1481593
4a2fec
RH-Acked-by: Thomas Huth <thuth@redhat.com>
4a2fec
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
4a2fec
RH-Acked-by: Eduardo Habkost <ehabkost@redhat.com>
4a2fec
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
4a2fec
4a2fec
From: Alexey Kardashevskiy <aik@ozlabs.ru>
4a2fec
4a2fec
This creates a new AS object without any FlatView as
4a2fec
memory_region_transaction_commit() may want to reuse the empty FV.
4a2fec
4a2fec
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
4a2fec
Message-Id: <20170921085110.25598-14-aik@ozlabs.ru>
4a2fec
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
4a2fec
(cherry picked from commit 67ace39b253ed5ae465275bc870f7e495547658b)
4a2fec
4a2fec
Signed-off-by: David Gibson <dgibson@redhat.com>
4a2fec
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
4a2fec
---
4a2fec
 memory.c | 29 +++++++++++++++++++++++------
4a2fec
 1 file changed, 23 insertions(+), 6 deletions(-)
4a2fec
4a2fec
diff --git a/memory.c b/memory.c
4a2fec
index f0c8642..6914d87 100644
4a2fec
--- a/memory.c
4a2fec
+++ b/memory.c
4a2fec
@@ -966,22 +966,37 @@ static void flatviews_reset(void)
4a2fec
 
4a2fec
 static void address_space_set_flatview(AddressSpace *as)
4a2fec
 {
4a2fec
-    FlatView *old_view = address_space_get_flatview(as);
4a2fec
+    FlatView *old_view = address_space_to_flatview(as);
4a2fec
     MemoryRegion *physmr = memory_region_get_flatview_root(as->root);
4a2fec
     FlatView *new_view = g_hash_table_lookup(flat_views, physmr);
4a2fec
 
4a2fec
     assert(new_view);
4a2fec
 
4a2fec
+    if (old_view == new_view) {
4a2fec
+        return;
4a2fec
+    }
4a2fec
+
4a2fec
+    if (old_view) {
4a2fec
+        flatview_ref(old_view);
4a2fec
+    }
4a2fec
+
4a2fec
     flatview_ref(new_view);
4a2fec
 
4a2fec
     if (!QTAILQ_EMPTY(&as->listeners)) {
4a2fec
-        address_space_update_topology_pass(as, old_view, new_view, false);
4a2fec
-        address_space_update_topology_pass(as, old_view, new_view, true);
4a2fec
+        FlatView tmpview = { .nr = 0 }, *old_view2 = old_view;
4a2fec
+
4a2fec
+        if (!old_view2) {
4a2fec
+            old_view2 = &tmpview;
4a2fec
+        }
4a2fec
+        address_space_update_topology_pass(as, old_view2, new_view, false);
4a2fec
+        address_space_update_topology_pass(as, old_view2, new_view, true);
4a2fec
     }
4a2fec
 
4a2fec
     /* Writes are protected by the BQL.  */
4a2fec
     atomic_rcu_set(&as->current_map, new_view);
4a2fec
-    flatview_unref(old_view);
4a2fec
+    if (old_view) {
4a2fec
+        flatview_unref(old_view);
4a2fec
+    }
4a2fec
 
4a2fec
     /* Note that all the old MemoryRegions are still alive up to this
4a2fec
      * point.  This relieves most MemoryListeners from the need to
4a2fec
@@ -989,7 +1004,9 @@ static void address_space_set_flatview(AddressSpace *as)
4a2fec
      * outside the iothread mutex, in which case precise reference
4a2fec
      * counting is necessary.
4a2fec
      */
4a2fec
-    flatview_unref(old_view);
4a2fec
+    if (old_view) {
4a2fec
+        flatview_unref(old_view);
4a2fec
+    }
4a2fec
 }
4a2fec
 
4a2fec
 void memory_region_transaction_begin(void)
4a2fec
@@ -2707,7 +2724,7 @@ void address_space_init(AddressSpace *as, MemoryRegion *root, const char *name)
4a2fec
     as->ref_count = 1;
4a2fec
     as->root = root;
4a2fec
     as->malloced = false;
4a2fec
-    as->current_map = flatview_new(root);
4a2fec
+    as->current_map = NULL;
4a2fec
     as->ioeventfd_nb = 0;
4a2fec
     as->ioeventfds = NULL;
4a2fec
     QTAILQ_INIT(&as->listeners);
4a2fec
-- 
4a2fec
1.8.3.1
4a2fec