From patchwork Wed Mar 6 03:06:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gibson X-Patchwork-Id: 10840331 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4F31B17E0 for ; Wed, 6 Mar 2019 03:07:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 39F4427BA5 for ; Wed, 6 Mar 2019 03:07:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2DC7A2BF4F; Wed, 6 Mar 2019 03:07:35 +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=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C9C6D27BA5 for ; Wed, 6 Mar 2019 03:07:34 +0000 (UTC) Received: from localhost ([127.0.0.1]:53337 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1Mu5-0006JW-3n for patchwork-qemu-devel@patchwork.kernel.org; Tue, 05 Mar 2019 22:07:33 -0500 Received: from eggs.gnu.org ([209.51.188.92]:51073) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1Msn-0005L0-EL for qemu-devel@nongnu.org; Tue, 05 Mar 2019 22:06:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1Msm-0003t1-I1 for qemu-devel@nongnu.org; Tue, 05 Mar 2019 22:06:13 -0500 Received: from ozlabs.org ([203.11.71.1]:41033) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h1Msm-0003rZ-6A; Tue, 05 Mar 2019 22:06:12 -0500 Received: by ozlabs.org (Postfix, from userid 1007) id 44Ddv15cpcz9sMx; Wed, 6 Mar 2019 14:06:05 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1551841565; bh=yusD85qIYVgH/pKubWtX6vS2lRoxDJ4ZczKDtB6/rcw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Qiltl24zgL4B1/14evluqeyaICoya0mP2yANn6lzx62tIudxYm4y9+6Q7AWIsubOQ uTes0nfYVoVdFXgA3N31GYf/Pf9kZaVY/iTZHsqmn9V6DRjbTzAACnwolA9OstFyzo txjINGkaqVzly+h+HWf5t9liS+iF7SC/UnQVLVNk= From: David Gibson To: Michael Tsirkin , David Hildenbrand , Peter Maydell Date: Wed, 6 Mar 2019 14:06:01 +1100 Message-Id: <20190306030601.21986-4-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190306030601.21986-1-david@gibson.dropbear.id.au> References: <20190306030601.21986-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 203.11.71.1 Subject: [Qemu-devel] [PATCH 3/3] virtio-balloon: Restore MADV_WILLNEED hint on balloon deflate 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: qemu-ppc@nongnu.org, qemu-devel@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Prior to f6deb6d9 "virtio-balloon: Remove unnecessary MADV_WILLNEED on deflate", the balloon device issued an madvise() MADV_WILLNEED on pages removed from the balloon. That would hint to the host kernel that the pages were likely to be needed by the guest in the near future. It's unclear if this is actually valuable or not, and so f6deb6d9 removed this, essentially ignoring balloon deflate requests. However, concerns have been raised that this might cause a performance regression by causing extra latency for the guest in certain configurations. So, until we can get actual benchmark data to see if that's the case, this restores the old behaviour, issuing a MADV_WILLNEED when a page is removed from the balloon. Signed-off-by: David Gibson --- hw/virtio/virtio-balloon.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c index 7412bf8c85..ac36988605 100644 --- a/hw/virtio/virtio-balloon.c +++ b/hw/virtio/virtio-balloon.c @@ -118,6 +118,8 @@ static void balloon_deflate_page(VirtIOBalloon *balloon, RAMBlock *rb; size_t rb_page_size; ram_addr_t ram_offset, host_page_base; + void *host_addr; + int ret; /* XXX is there a better way to get to the RAMBlock than via a * host address? */ @@ -146,6 +148,17 @@ static void balloon_deflate_page(VirtIOBalloon *balloon, balloon->pbp = NULL; } } + + host_addr = (void *)((uintptr_t)addr & ~(rb_page_size - 1)); + + /* When a page is deflated, we hint the whole host page it lives + * on, since we can't do anything smaller */ + ret = qemu_madvise(host_addr, rb_page_size, QEMU_MADV_WILLNEED); + if (ret != 0) { + warn_report("Couldn't MADV_WILLNEED on balloon deflate: %s", + strerror(errno)); + /* Otherwise ignore, failing to page hint shouldn't be fatal */ + } } static const char *balloon_stat_names[] = {