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

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