From patchwork Thu Sep 21 23:16:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 817247 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="MUeauWds"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xytL40vwXz9tYH for ; Fri, 22 Sep 2017 09:36:36 +1000 (AEST) Received: from localhost ([::1]:55946 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dvB1G-0004RE-45 for incoming@patchwork.ozlabs.org; Thu, 21 Sep 2017 19:36:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37465) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dvAiX-0004uP-2J for qemu-devel@nongnu.org; Thu, 21 Sep 2017 19:17:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dvAiW-0004TZ-3K for qemu-devel@nongnu.org; Thu, 21 Sep 2017 19:17:13 -0400 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]:35743) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dvAiV-0004SU-Sb for qemu-devel@nongnu.org; Thu, 21 Sep 2017 19:17:12 -0400 Received: by mail-wm0-x244.google.com with SMTP id e64so6456852wmi.2 for ; Thu, 21 Sep 2017 16:17:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=NOnw5MaoK+euvPHQsq6zeKgOCjDOGpSGqZnRUahr4Ls=; b=MUeauWds5csG9qP7286haW0ABqelsaeso2ZftfrV+xl3PO0xxi+jJzl6wiOrJed937 Al2oWZQuUzYem8Hd8OxXNj/bYDYEm/ilmmfuUFe8z5gScbn57qBXab41X920jTiKTti0 bPuXnsif7Uje0cx6B6cSfAKRoau5vjSwWUgw2VDuaRyw00C6Fz0byXohezHW8iSmruvA LpoSU0BPX8FKUkWNLQIbzUJwlV1DncQQHOsxneuvXkJGTr/6taA054GVCJB/bW7XGVQF yM0/BKNpratOgumELy/Jr5xvG2udpAHF3gUYCHDAq6UzV/7uE6Ch2jvcm8sqZ3soQabO w1/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=NOnw5MaoK+euvPHQsq6zeKgOCjDOGpSGqZnRUahr4Ls=; b=od3/u3dKx+HuT9/afv5FQS1nCAHAWTurpYMxUk4IAM3vdREIixAAenqN2lhc++8MdX P7WytLP2yQgLy6mQfeQJkbiZYAQih4STlPmVl3qV+En6NMSRTF5XTeDiqt5/MRc9Hw4B fTypjXU0PCu0eBPQRfgPNNCohtbnG6fnhXJMIujq6TIraOpj8zTg156byTykwZ0MOn6w 7NfmejowOvsIqpi8sYo50NUV5GTbDGyJvlIeETjiZdXpKGKKFytgn3SRbWmfBjZ/9gko KUl8VRMPLQr+6aYiL8pwUPDtPhlGeECkNJ6lSNjticJoW6CIATpm5LfoVWlExE+0aZQn UKJA== X-Gm-Message-State: AHPjjUikkFsnQvZsLgl+bpOX4rrNCvaQsvji9GsFY+NPcB9xoIp6TSjg Dfywc+hdhUrLcDDOJVIQYzRomXMl X-Google-Smtp-Source: AOwi7QAl+6NiIRKWBbZxEto9mLAexaEy+JY1lFChpNQ8897hsOdAEgo50UsgrkpWlUKxFwDJpQgKBw== X-Received: by 10.28.220.85 with SMTP id t82mr2265619wmg.95.1506035830609; Thu, 21 Sep 2017 16:17:10 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-246-117.clienti.tiscali.it. [78.12.246.117]) by smtp.gmail.com with ESMTPSA id u186sm2596278wmd.19.2017.09.21.16.17.09 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Sep 2017 16:17:09 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 22 Sep 2017 01:16:31 +0200 Message-Id: <1506035800-30509-24-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1506035800-30509-1-git-send-email-pbonzini@redhat.com> References: <1506035800-30509-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::244 Subject: [Qemu-devel] [PULL 23/32] memory: seek FlatView sharing candidates among children subregions 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: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" A container can be used instead of an alias to allow switching between multiple subregions. In this case we cannot directly share the subregions (since they only belong to a single parent), but if the subregions are aliases we can in turn walk those. This is not enough to remove all source of quadratic FlatView creation, but it enables sharing of the PCI bus master FlatViews (and their AddressSpaceDispatch structures) across all PCI devices. For 112 virtio-net-pci devices, boot time is reduced from 25 to 10 seconds and memory consumption from 1.4 to 1 G. Signed-off-by: Paolo Bonzini --- memory.c | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/memory.c b/memory.c index 68cdf8b..15b1bd7 100644 --- a/memory.c +++ b/memory.c @@ -734,12 +734,40 @@ static void render_memory_region(FlatView *view, static MemoryRegion *memory_region_get_flatview_root(MemoryRegion *mr) { - while (mr->alias && !mr->alias_offset && - int128_ge(mr->size, mr->alias->size)) { - /* The alias is included in its entirety. Use it as - * the "real" root, so that we can share more FlatViews. - */ - mr = mr->alias; + while (mr->enabled) { + if (mr->alias) { + if (!mr->alias_offset && int128_ge(mr->size, mr->alias->size)) { + /* The alias is included in its entirety. Use it as + * the "real" root, so that we can share more FlatViews. + */ + mr = mr->alias; + continue; + } + } else if (!mr->terminates) { + unsigned int found = 0; + MemoryRegion *child, *next = NULL; + QTAILQ_FOREACH(child, &mr->subregions, subregions_link) { + if (child->enabled) { + if (++found > 1) { + next = NULL; + break; + } + if (!child->addr && int128_ge(mr->size, child->size)) { + /* A child is included in its entirety. If it's the only + * enabled one, use it in the hope of finding an alias down the + * way. This will also let us share FlatViews. + */ + next = child; + } + } + } + if (next) { + mr = next; + continue; + } + } + + break; } return mr;