From nobody Mon Nov 3 20:17:57 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1505984681665316.6606744741566; Thu, 21 Sep 2017 02:04:41 -0700 (PDT) Received: from localhost ([::1]:52478 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1duxPV-0007QQ-0O for importer@patchew.org; Thu, 21 Sep 2017 05:04:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48549) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1duxCt-00057y-B6 for qemu-devel@nongnu.org; Thu, 21 Sep 2017 04:51:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1duxCs-0001MO-Ai for qemu-devel@nongnu.org; Thu, 21 Sep 2017 04:51:39 -0400 Received: from ozlabs.ru ([107.173.13.209]:54112) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1duxCs-0001CA-4C for qemu-devel@nongnu.org; Thu, 21 Sep 2017 04:51:38 -0400 Received: from vpl1.ozlabs.ibm.com (localhost [IPv6:::1]) by ozlabs.ru (Postfix) with ESMTP id F13153A60051; Thu, 21 Sep 2017 04:52:53 -0400 (EDT) From: Alexey Kardashevskiy To: qemu-devel@nongnu.org Date: Thu, 21 Sep 2017 18:51:07 +1000 Message-Id: <20170921085110.25598-16-aik@ozlabs.ru> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170921085110.25598-1-aik@ozlabs.ru> References: <20170921085110.25598-1-aik@ozlabs.ru> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 107.173.13.209 Subject: [Qemu-devel] [PATCH qemu v5 15/18] memory: Share special empty FlatView X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexey Kardashevskiy , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This shares an cached empty FlatView among address spaces. The empty FV is used every time when a root MR renders into a FV without memory sections which happens when MR or its children are not enabled or zero-sized. The empty_view is not NULL to keep the rest of memory API intact; it also has a dispatch tree for the same reason. On POWER8 with 255 CPUs, 255 virtio-net, 40 PCI bridges guest this halves the amount of FlatView's in use (557 -> 260) and dispatch tables (~800000 -> ~370000), however the total memory footprint is pretty much the same as RCU is holding all these temporary FVs which are created (and then released) to make sure that they are empty and can be replaced with @empty_view. Signed-off-by: Alexey Kardashevskiy --- Changes: v5: * generate_memory_topology() now destroys temporary FV directly as it is not in use anyway * check for mr->enabled and avoid even temporaty FV allocation --- memory.c | 44 +++++++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/memory.c b/memory.c index 8ab953ba24..4c28b91890 100644 --- a/memory.c +++ b/memory.c @@ -48,6 +48,7 @@ static QTAILQ_HEAD(, AddressSpace) address_spaces =3D QTAILQ_HEAD_INITIALIZER(address_spaces); =20 static GHashTable *flat_views; +static FlatView *empty_view; =20 typedef struct AddrRange AddrRange; =20 @@ -746,22 +747,43 @@ static FlatView *generate_memory_topology(MemoryRegio= n *mr) { int i; FlatView *view; + bool use_empty =3D false; =20 - view =3D flatview_new(mr); + if (!mr->enabled) { + use_empty =3D true; + } else { + view =3D flatview_new(mr); + if (mr) { + render_memory_region(view, mr, int128_zero(), + addrrange_make(int128_zero(), int128_2_64= ()), + false); + } + flatview_simplify(view); =20 - if (mr) { - render_memory_region(view, mr, int128_zero(), - addrrange_make(int128_zero(), int128_2_64()),= false); + if (!view->nr) { + flatview_destroy(view); + use_empty =3D true; + } } - flatview_simplify(view); =20 - view->dispatch =3D address_space_dispatch_new(view); - for (i =3D 0; i < view->nr; i++) { - MemoryRegionSection mrs =3D - section_from_flat_range(&view->ranges[i], view); - flatview_add_to_dispatch(view, &mrs); + if (use_empty) { + if (!empty_view) { + empty_view =3D flatview_new(NULL); + } + view =3D empty_view; + flatview_ref(view); } - address_space_dispatch_compact(view->dispatch); + + if (!view->dispatch) { + view->dispatch =3D address_space_dispatch_new(view); + for (i =3D 0; i < view->nr; i++) { + MemoryRegionSection mrs =3D + section_from_flat_range(&view->ranges[i], view); + flatview_add_to_dispatch(view, &mrs); + } + address_space_dispatch_compact(view->dispatch); + } + g_hash_table_replace(flat_views, mr, view); =20 return view; --=20 2.11.0