From patchwork Tue Jul 19 08:34:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 9236397 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id F144360574 for ; Tue, 19 Jul 2016 08:42:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E0BE52015F for ; Tue, 19 Jul 2016 08:42:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D5995205AF; Tue, 19 Jul 2016 08:42:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 72DEC2015F for ; Tue, 19 Jul 2016 08:42:33 +0000 (UTC) Received: from localhost ([::1]:53832 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPQbo-0001k4-KQ for patchwork-qemu-devel@patchwork.kernel.org; Tue, 19 Jul 2016 04:42:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43038) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPQU2-00065C-UG for qemu-devel@nongnu.org; Tue, 19 Jul 2016 04:34:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bPQU1-0003Mm-OL for qemu-devel@nongnu.org; Tue, 19 Jul 2016 04:34:30 -0400 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]:33036) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPQU1-0003Mf-Hh for qemu-devel@nongnu.org; Tue, 19 Jul 2016 04:34:29 -0400 Received: by mail-wm0-x242.google.com with SMTP id o80so2021863wme.0 for ; Tue, 19 Jul 2016 01:34:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=O/RnwEex2PSb7DaQSuhykyWWw1wCLE55vcCtdWLrq8E=; b=rECuG5tCBnIEMXMJ68Azh4n1uIjJnfuQox+CTNdeQRZXIwHbVcjvRbDIv5BuPdXltF GqdQjq3A0rN6GtEntip9StTa9cYWguJZkntNi5Kzjl8q20kWVEK8H7XjHkBpjyQ7ZeAT u+7qqMw0R9/6/xZFOwOCJ08VsG1msxNMlI9YtblfmF4NkIoMveeLmjKfzOywYvTUBhY1 RJX5Iwpqum53aJjd8Nn6InQSj4nmUk9iKAzXwEPVC57oQdR24QZzeTLkc6Rf/XbNYrD6 g23Bazf3iCWk38fOJJZicezamxxKPedpQaz6ilZhdnEL9F/WbUWJO9lBsiyl72FJUx5Y MTdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=O/RnwEex2PSb7DaQSuhykyWWw1wCLE55vcCtdWLrq8E=; b=U9noxspRBZuBjOkKdShUozOOwhXlHKtzVSOAX7ihNQXmUt0P99w3J1lFyoNz5b3k/6 8VAx2TjOpCr7RYbeijFIf47tXGT5qfOMzNUmVWYK+VeZRG7VcN95yVIJ44ITS2567NAi MZYqSgTLsWh7JzpTbgNs+xTwLtd7dHgzYTfZ/pZ9NU4PDUuyj0R1dHk2UTbuKjXRZigs IzYC/SqJgy4jzZB50XqHfekOMZzIVlNJR9ydgf4OiuyFJJSjUUfAcc8c+z27Oexuzizl 8NOWB3o10Bo2CpiUiWF+KTRUhiKEr5CeJsk7RwL7UTjWppqXE7wCEiCNtIurdQ9dAV7r Oa5A== X-Gm-Message-State: ALyK8tLn3ydZiat/70PNM7L316dWX5wpwsej/XVw7Pkg+WkFWoVrRAL79XbK0kHpOfgz2w== X-Received: by 10.28.25.71 with SMTP id 68mr2418106wmz.91.1468917268800; Tue, 19 Jul 2016 01:34:28 -0700 (PDT) Received: from donizetti.lan (94-39-158-5.adsl-ull.clienti.tiscali.it. [94.39.158.5]) by smtp.gmail.com with ESMTPSA id o142sm20886055wme.20.2016.07.19.01.34.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Jul 2016 01:34:28 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 19 Jul 2016 10:34:14 +0200 Message-Id: <1468917259-8475-8-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1468917259-8475-1-git-send-email-pbonzini@redhat.com> References: <1468917259-8475-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::242 Subject: [Qemu-devel] [PULL 07/12] exec: avoid realloc in phys_map_node_reserve 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: Peter Lieven Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Peter Lieven this is the first step in reducing the brk heap fragmentation created by the map->nodes memory allocation. Since the introduction of RCU the freeing of the PhysPageMaps is delayed so that sometimes several hundred are allocated at the same time. Even worse the memory for map->nodes is allocated and shortly afterwards reallocated. Since the number of nodes it grows to in the end is the same for all PhysPageMaps remember this value and at least avoid the reallocation. The large number of simultaneous allocations (about 450 x 70kB in my configuration) has to be addressed later. Signed-off-by: Peter Lieven Message-Id: <1468577030-21097-1-git-send-email-pl@kamp.de> Signed-off-by: Paolo Bonzini --- exec.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/exec.c b/exec.c index 011babd..60cf46a 100644 --- a/exec.c +++ b/exec.c @@ -187,10 +187,12 @@ struct CPUAddressSpace { static void phys_map_node_reserve(PhysPageMap *map, unsigned nodes) { + static unsigned alloc_hint = 16; if (map->nodes_nb + nodes > map->nodes_nb_alloc) { - map->nodes_nb_alloc = MAX(map->nodes_nb_alloc * 2, 16); + map->nodes_nb_alloc = MAX(map->nodes_nb_alloc, alloc_hint); map->nodes_nb_alloc = MAX(map->nodes_nb_alloc, map->nodes_nb + nodes); map->nodes = g_renew(Node, map->nodes, map->nodes_nb_alloc); + alloc_hint = map->nodes_nb_alloc; } }