Blame SOURCES/kvm-memory-seek-FlatView-sharing-candidates-among-childr.patch

4a2fec
From 34644299c4e930a16b7e0a7725f69b7b83ca600e Mon Sep 17 00:00:00 2001
4a2fec
From: David Gibson <dgibson@redhat.com>
4a2fec
Date: Thu, 16 Nov 2017 03:07:31 +0100
4a2fec
Subject: [PATCH 27/30] memory: seek FlatView sharing candidates among children
4a2fec
 subregions
4a2fec
4a2fec
RH-Author: David Gibson <dgibson@redhat.com>
4a2fec
Message-id: <20171116030732.8560-22-dgibson@redhat.com>
4a2fec
Patchwork-id: 77708
4a2fec
O-Subject: [PATCH 21/22] memory: seek FlatView sharing candidates among children subregions
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: Paolo Bonzini <pbonzini@redhat.com>
4a2fec
4a2fec
A container can be used instead of an alias to allow switching between
4a2fec
multiple subregions.  In this case we cannot directly share the
4a2fec
subregions (since they only belong to a single parent), but if the
4a2fec
subregions are aliases we can in turn walk those.
4a2fec
4a2fec
This is not enough to remove all source of quadratic FlatView creation,
4a2fec
but it enables sharing of the PCI bus master FlatViews (and their
4a2fec
AddressSpaceDispatch structures) across all PCI devices.  For 112
4a2fec
virtio-net-pci devices, boot time is reduced from 25 to 10 seconds and
4a2fec
memory consumption from 1.4 to 1 G.
4a2fec
4a2fec
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
4a2fec
(cherry picked from commit e673ba9af9bf8fd8e0f44025ac738b8285b3ed27)
4a2fec
4a2fec
Signed-off-by: David Gibson <dgibson@redhat.com>
4a2fec
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
4a2fec
---
4a2fec
 memory.c | 40 ++++++++++++++++++++++++++++++++++------
4a2fec
 1 file changed, 34 insertions(+), 6 deletions(-)
4a2fec
4a2fec
diff --git a/memory.c b/memory.c
4a2fec
index 8733efc..38eabe7 100644
4a2fec
--- a/memory.c
4a2fec
+++ b/memory.c
4a2fec
@@ -733,12 +733,40 @@ static void render_memory_region(FlatView *view,
4a2fec
 
4a2fec
 static MemoryRegion *memory_region_get_flatview_root(MemoryRegion *mr)
4a2fec
 {
4a2fec
-    while (mr->alias && !mr->alias_offset &&
4a2fec
-           int128_ge(mr->size, mr->alias->size)) {
4a2fec
-        /* The alias is included in its entirety.  Use it as
4a2fec
-         * the "real" root, so that we can share more FlatViews.
4a2fec
-         */
4a2fec
-        mr = mr->alias;
4a2fec
+    while (mr->enabled) {
4a2fec
+        if (mr->alias) {
4a2fec
+            if (!mr->alias_offset && int128_ge(mr->size, mr->alias->size)) {
4a2fec
+                /* The alias is included in its entirety.  Use it as
4a2fec
+                 * the "real" root, so that we can share more FlatViews.
4a2fec
+                 */
4a2fec
+                mr = mr->alias;
4a2fec
+                continue;
4a2fec
+            }
4a2fec
+        } else if (!mr->terminates) {
4a2fec
+            unsigned int found = 0;
4a2fec
+            MemoryRegion *child, *next = NULL;
4a2fec
+            QTAILQ_FOREACH(child, &mr->subregions, subregions_link) {
4a2fec
+                if (child->enabled) {
4a2fec
+                    if (++found > 1) {
4a2fec
+                        next = NULL;
4a2fec
+                        break;
4a2fec
+                    }
4a2fec
+                    if (!child->addr && int128_ge(mr->size, child->size)) {
4a2fec
+                        /* A child is included in its entirety.  If it's the only
4a2fec
+                         * enabled one, use it in the hope of finding an alias down the
4a2fec
+                         * way. This will also let us share FlatViews.
4a2fec
+                         */
4a2fec
+                        next = child;
4a2fec
+                    }
4a2fec
+                }
4a2fec
+            }
4a2fec
+            if (next) {
4a2fec
+                mr = next;
4a2fec
+                continue;
4a2fec
+            }
4a2fec
+        }
4a2fec
+
4a2fec
+        break;
4a2fec
     }
4a2fec
 
4a2fec
     return mr;
4a2fec
-- 
4a2fec
1.8.3.1
4a2fec