{"id":816829,"url":"http://patchwork.ozlabs.org/api/patches/816829/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20170921120751.3027-4-pbonzini@redhat.com/","project":{"id":14,"url":"http://patchwork.ozlabs.org/api/projects/14/?format=json","name":"QEMU Development","link_name":"qemu-devel","list_id":"qemu-devel.nongnu.org","list_email":"qemu-devel@nongnu.org","web_url":"","scm_url":"","webscm_url":"","list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20170921120751.3027-4-pbonzini@redhat.com>","list_archive_url":null,"date":"2017-09-21T12:07:51","name":"[3/3] memory: Share special empty FlatView","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"331aaacb0b88d313c356d02a3f955a5e6cbc6dbd","submitter":{"id":2701,"url":"http://patchwork.ozlabs.org/api/people/2701/?format=json","name":"Paolo Bonzini","email":"pbonzini@redhat.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20170921120751.3027-4-pbonzini@redhat.com/mbox/","series":[{"id":4365,"url":"http://patchwork.ozlabs.org/api/series/4365/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/list/?series=4365","date":"2017-09-21T12:07:49","name":"FlatView memory savings","version":1,"mbox":"http://patchwork.ozlabs.org/series/4365/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/816829/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/816829/checks/","tags":{},"related":[],"headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","ext-mx02.extmail.prod.ext.phx2.redhat.com;\n\tdmarc=none (p=none dis=none) header.from=redhat.com","ext-mx02.extmail.prod.ext.phx2.redhat.com;\n\tspf=fail smtp.mailfrom=pbonzini@redhat.com"],"Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xyb4K1x3dz9s7h\n\tfor <incoming@patchwork.ozlabs.org>;\n\tThu, 21 Sep 2017 22:08:49 +1000 (AEST)","from localhost ([::1]:53379 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1dv0Hf-0002KN-8X\n\tfor incoming@patchwork.ozlabs.org; Thu, 21 Sep 2017 08:08:47 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:39304)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <pbonzini@redhat.com>) id 1dv0Gv-0002IU-J7\n\tfor qemu-devel@nongnu.org; Thu, 21 Sep 2017 08:08:02 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <pbonzini@redhat.com>) id 1dv0Gr-00029E-Ue\n\tfor qemu-devel@nongnu.org; Thu, 21 Sep 2017 08:08:01 -0400","from mx1.redhat.com ([209.132.183.28]:55632)\n\tby eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)\n\t(Exim 4.71) (envelope-from <pbonzini@redhat.com>) id 1dv0Gr-00026w-NW\n\tfor qemu-devel@nongnu.org; Thu, 21 Sep 2017 08:07:57 -0400","from smtp.corp.redhat.com\n\t(int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15])\n\t(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby mx1.redhat.com (Postfix) with ESMTPS id CD97B883C3;\n\tThu, 21 Sep 2017 12:07:56 +0000 (UTC)","from donizetti.redhat.com (ovpn-117-52.ams2.redhat.com\n\t[10.36.117.52])\n\tby smtp.corp.redhat.com (Postfix) with ESMTP id 0E1875EDF9;\n\tThu, 21 Sep 2017 12:07:55 +0000 (UTC)"],"DMARC-Filter":"OpenDMARC Filter v1.3.2 mx1.redhat.com CD97B883C3","From":"Paolo Bonzini <pbonzini@redhat.com>","To":"qemu-devel@nongnu.org","Date":"Thu, 21 Sep 2017 14:07:51 +0200","Message-Id":"<20170921120751.3027-4-pbonzini@redhat.com>","In-Reply-To":"<20170921120751.3027-1-pbonzini@redhat.com>","References":"<20170921120751.3027-1-pbonzini@redhat.com>","X-Scanned-By":"MIMEDefang 2.79 on 10.5.11.15","X-Greylist":"Sender IP whitelisted, not delayed by milter-greylist-4.5.16\n\t(mx1.redhat.com [10.5.110.26]);\n\tThu, 21 Sep 2017 12:07:56 +0000 (UTC)","X-detected-operating-system":"by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]\n\t[fuzzy]","X-Received-From":"209.132.183.28","Subject":"[Qemu-devel] [PATCH 3/3] memory: Share special empty FlatView","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"aik@ozlabs.ru","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"},"content":"From: Alexey Kardashevskiy <aik@ozlabs.ru>\n\nThis shares an cached empty FlatView among address spaces. The empty\nFV is used every time when a root MR would render into a FV without\nmemory sections, which happens when MR or its children are not enabled\n(or zero-sized, which isn't caught yet). The empty_view is not NULL to\nkeep the rest of memory API intact; it also has a dispatch tree for the\nsame reason.\n\nOn POWER8 with 255 CPUs, 255 virtio-net, 40 PCI bridges guest this halves\nthe amount of FlatView's in use (557 -> 260) and dispatch tables\n(~800000 -> ~370000).  In an unrelated experiment with 112 non-virtio\ndevices on x86 (\"-M pc\"), only 4 FlatViews are alive while the guest runs.\n\nSigned-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>\nMessage-Id: <20170921085110.25598-16-aik@ozlabs.ru>\nSigned-off-by: Paolo Bonzini <pbonzini@redhat.com>\n---\n memory.c | 18 ++++++++++++++++--\n 1 file changed, 16 insertions(+), 2 deletions(-)","diff":"diff --git a/memory.c b/memory.c\nindex 3207ae55e2..cb369223b1 100644\n--- a/memory.c\n+++ b/memory.c\n@@ -316,6 +316,7 @@ static void flatview_ref(FlatView *view)\n static void flatview_unref(FlatView *view)\n {\n     if (atomic_fetch_dec(&view->ref) == 1) {\n+        assert(view->root);\n         call_rcu(view, flatview_destroy, rcu);\n     }\n }\n@@ -761,16 +762,19 @@ static MemoryRegion *memory_region_get_flatview_root(MemoryRegion *mr)\n                     }\n                 }\n             }\n+            if (found == 0) {\n+                return NULL;\n+            }\n             if (next) {\n                 mr = next;\n                 continue;\n             }\n         }\n \n-        break;\n+        return mr;\n     }\n \n-    return mr;\n+    return NULL;\n }\n \n /* Render a memory topology into a list of disjoint absolute ranges. */\n@@ -962,12 +966,22 @@ static void address_space_update_topology_pass(AddressSpace *as,\n \n static void flatviews_init(void)\n {\n+    static FlatView *empty_view;\n+\n     if (flat_views) {\n         return;\n     }\n \n     flat_views = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL,\n                                        (GDestroyNotify) flatview_unref);\n+    if (!empty_view) {\n+        empty_view = generate_memory_topology(NULL);\n+        /* We keep it alive forever in the global variable.  */\n+        flatview_ref(empty_view);\n+    } else {\n+        g_hash_table_replace(flat_views, NULL, empty_view);\n+        flatview_ref(empty_view);\n+    }\n }\n \n static void flatviews_reset(void)\n","prefixes":["3/3"]}