|
|
9bac43 |
From f47eec19ea8dd0f693755cf42e4962e3ec43b06b Mon Sep 17 00:00:00 2001
|
|
|
9bac43 |
From: David Gibson <dgibson@redhat.com>
|
|
|
9bac43 |
Date: Thu, 16 Nov 2017 03:07:25 +0100
|
|
|
9bac43 |
Subject: [PATCH 21/30] memory: Share FlatView's and dispatch trees between
|
|
|
9bac43 |
address spaces
|
|
|
9bac43 |
|
|
|
9bac43 |
RH-Author: David Gibson <dgibson@redhat.com>
|
|
|
9bac43 |
Message-id: <20171116030732.8560-16-dgibson@redhat.com>
|
|
|
9bac43 |
Patchwork-id: 77707
|
|
|
9bac43 |
O-Subject: [PATCH 15/22] memory: Share FlatView's and dispatch trees between address spaces
|
|
|
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 allows sharing flat views between address spaces (AS) when
|
|
|
9bac43 |
the same root memory region is used when creating a new address space.
|
|
|
9bac43 |
This is done by walking through all ASes and caching one FlatView per
|
|
|
9bac43 |
a physical root MR (i.e. not aliased).
|
|
|
9bac43 |
|
|
|
9bac43 |
This removes search for duplicates from address_space_init_shareable() as
|
|
|
9bac43 |
FlatViews are shared elsewhere and keeping as::ref_count correct seems
|
|
|
9bac43 |
an unnecessary and useless complication.
|
|
|
9bac43 |
|
|
|
9bac43 |
This should cause no change and memory use or boot time yet.
|
|
|
9bac43 |
|
|
|
9bac43 |
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
|
|
|
9bac43 |
Message-Id: <20170921085110.25598-13-aik@ozlabs.ru>
|
|
|
9bac43 |
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
9bac43 |
(cherry picked from commit 967dc9b1194a9281124b2e1ce67b6c3359a2138f)
|
|
|
9bac43 |
|
|
|
9bac43 |
Signed-off-by: David Gibson <dgibson@redhat.com>
|
|
|
9bac43 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
9bac43 |
---
|
|
|
9bac43 |
memory.c | 56 +++++++++++++++++++++++++++++++++++++++++++++-----------
|
|
|
9bac43 |
1 file changed, 45 insertions(+), 11 deletions(-)
|
|
|
9bac43 |
|
|
|
9bac43 |
diff --git a/memory.c b/memory.c
|
|
|
9bac43 |
index 1f58d29..f0c8642 100644
|
|
|
9bac43 |
--- a/memory.c
|
|
|
9bac43 |
+++ b/memory.c
|
|
|
9bac43 |
@@ -47,6 +47,8 @@ static QTAILQ_HEAD(memory_listeners, MemoryListener) memory_listeners
|
|
|
9bac43 |
static QTAILQ_HEAD(, AddressSpace) address_spaces
|
|
|
9bac43 |
= QTAILQ_HEAD_INITIALIZER(address_spaces);
|
|
|
9bac43 |
|
|
|
9bac43 |
+static GHashTable *flat_views;
|
|
|
9bac43 |
+
|
|
|
9bac43 |
typedef struct AddrRange AddrRange;
|
|
|
9bac43 |
|
|
|
9bac43 |
/*
|
|
|
9bac43 |
@@ -760,6 +762,7 @@ static FlatView *generate_memory_topology(MemoryRegion *mr)
|
|
|
9bac43 |
flatview_add_to_dispatch(view, &mrs);
|
|
|
9bac43 |
}
|
|
|
9bac43 |
address_space_dispatch_compact(view->dispatch);
|
|
|
9bac43 |
+ g_hash_table_replace(flat_views, mr, view);
|
|
|
9bac43 |
|
|
|
9bac43 |
return view;
|
|
|
9bac43 |
}
|
|
|
9bac43 |
@@ -929,11 +932,47 @@ static void address_space_update_topology_pass(AddressSpace *as,
|
|
|
9bac43 |
}
|
|
|
9bac43 |
}
|
|
|
9bac43 |
|
|
|
9bac43 |
-static void address_space_update_topology(AddressSpace *as)
|
|
|
9bac43 |
+static void flatviews_init(void)
|
|
|
9bac43 |
+{
|
|
|
9bac43 |
+ if (flat_views) {
|
|
|
9bac43 |
+ return;
|
|
|
9bac43 |
+ }
|
|
|
9bac43 |
+
|
|
|
9bac43 |
+ flat_views = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL,
|
|
|
9bac43 |
+ (GDestroyNotify) flatview_unref);
|
|
|
9bac43 |
+}
|
|
|
9bac43 |
+
|
|
|
9bac43 |
+static void flatviews_reset(void)
|
|
|
9bac43 |
+{
|
|
|
9bac43 |
+ AddressSpace *as;
|
|
|
9bac43 |
+
|
|
|
9bac43 |
+ if (flat_views) {
|
|
|
9bac43 |
+ g_hash_table_unref(flat_views);
|
|
|
9bac43 |
+ flat_views = NULL;
|
|
|
9bac43 |
+ }
|
|
|
9bac43 |
+ flatviews_init();
|
|
|
9bac43 |
+
|
|
|
9bac43 |
+ /* Render unique FVs */
|
|
|
9bac43 |
+ QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) {
|
|
|
9bac43 |
+ MemoryRegion *physmr = memory_region_get_flatview_root(as->root);
|
|
|
9bac43 |
+
|
|
|
9bac43 |
+ if (g_hash_table_lookup(flat_views, physmr)) {
|
|
|
9bac43 |
+ continue;
|
|
|
9bac43 |
+ }
|
|
|
9bac43 |
+
|
|
|
9bac43 |
+ generate_memory_topology(physmr);
|
|
|
9bac43 |
+ }
|
|
|
9bac43 |
+}
|
|
|
9bac43 |
+
|
|
|
9bac43 |
+static void address_space_set_flatview(AddressSpace *as)
|
|
|
9bac43 |
{
|
|
|
9bac43 |
FlatView *old_view = address_space_get_flatview(as);
|
|
|
9bac43 |
- MemoryRegion *physmr = memory_region_get_flatview_root(old_view->root);
|
|
|
9bac43 |
- FlatView *new_view = generate_memory_topology(physmr);
|
|
|
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 |
+ flatview_ref(new_view);
|
|
|
9bac43 |
|
|
|
9bac43 |
if (!QTAILQ_EMPTY(&as->listeners)) {
|
|
|
9bac43 |
address_space_update_topology_pass(as, old_view, new_view, false);
|
|
|
9bac43 |
@@ -969,10 +1008,12 @@ void memory_region_transaction_commit(void)
|
|
|
9bac43 |
--memory_region_transaction_depth;
|
|
|
9bac43 |
if (!memory_region_transaction_depth) {
|
|
|
9bac43 |
if (memory_region_update_pending) {
|
|
|
9bac43 |
+ flatviews_reset();
|
|
|
9bac43 |
+
|
|
|
9bac43 |
MEMORY_LISTENER_CALL_GLOBAL(begin, Forward);
|
|
|
9bac43 |
|
|
|
9bac43 |
QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) {
|
|
|
9bac43 |
- address_space_update_topology(as);
|
|
|
9bac43 |
+ address_space_set_flatview(as);
|
|
|
9bac43 |
address_space_update_ioeventfds(as);
|
|
|
9bac43 |
}
|
|
|
9bac43 |
memory_region_update_pending = false;
|
|
|
9bac43 |
@@ -2695,13 +2736,6 @@ AddressSpace *address_space_init_shareable(MemoryRegion *root, const char *name)
|
|
|
9bac43 |
{
|
|
|
9bac43 |
AddressSpace *as;
|
|
|
9bac43 |
|
|
|
9bac43 |
- QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) {
|
|
|
9bac43 |
- if (root == as->root && as->malloced) {
|
|
|
9bac43 |
- as->ref_count++;
|
|
|
9bac43 |
- return as;
|
|
|
9bac43 |
- }
|
|
|
9bac43 |
- }
|
|
|
9bac43 |
-
|
|
|
9bac43 |
as = g_malloc0(sizeof *as);
|
|
|
9bac43 |
address_space_init(as, root, name);
|
|
|
9bac43 |
as->malloced = true;
|
|
|
9bac43 |
--
|
|
|
9bac43 |
1.8.3.1
|
|
|
9bac43 |
|