From nobody Fri Apr 11 18:21:09 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1552475395008155.27549973446446; Wed, 13 Mar 2019 04:09:55 -0700 (PDT) Received: from localhost ([127.0.0.1]:42360 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h41lf-0000Jv-SR for importer@patchew.org; Wed, 13 Mar 2019 07:09:51 -0400 Received: from eggs.gnu.org ([209.51.188.92]:43817) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h41kG-0007qg-4W for qemu-devel@nongnu.org; Wed, 13 Mar 2019 07:08:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h41kF-000107-4J for qemu-devel@nongnu.org; Wed, 13 Mar 2019 07:08:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44476) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h41k5-0000yo-Nj; Wed, 13 Mar 2019 07:08:13 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 827FD88ABB; Wed, 13 Mar 2019 11:08:11 +0000 (UTC) Received: from localhost (ovpn-117-163.ams2.redhat.com [10.36.117.163]) by smtp.corp.redhat.com (Postfix) with ESMTP id D54B2601AE; Wed, 13 Mar 2019 11:08:10 +0000 (UTC) From: Stefan Hajnoczi To: qemu-devel@nongnu.org Date: Wed, 13 Mar 2019 11:08:02 +0000 Message-Id: <20190313110802.29186-2-stefanha@redhat.com> In-Reply-To: <20190313110802.29186-1-stefanha@redhat.com> References: <20190313110802.29186-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 13 Mar 2019 11:08:11 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL for-4.0 1/1] file-posix: add drop-cache=on|off option 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: Kevin Wolf , Peter Maydell , qemu-block@nongnu.org, "Michael S. Tsirkin" , Markus Armbruster , Max Reitz , Stefan Hajnoczi , Neil Skrypuch , Stefano Garzarella Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Commit dd577a26ff03b6829721b1ffbbf9e7c411b72378 ("block/file-posix: implement bdrv_co_invalidate_cache() on Linux") introduced page cache invalidation so that cache.direct=3Doff live migration is safe on Linux. The invalidation takes a significant amount of time when the file is large and present in the page cache. Normally this is not the case for cross-host live migration but it can happen when migrating between QEMU processes on the same host. On same-host migration we don't need to invalidate pages for correctness anyway, so an option to skip page cache invalidation is useful. I investigated optimizing invalidation and detecting same-host migration, but both are hard to achieve so a user-visible option will suffice. As a bonus this option means that the cache invalidation feature will now be detectable by libvirt via QMP schema introspection. Suggested-by: Neil Skrypuch Tested-by: Neil Skrypuch Reviewed-by: Stefano Garzarella Reviewed-by: Eric Blake Signed-off-by: Stefan Hajnoczi Message-id: 20190307164941.3322-1-stefanha@redhat.com Message-Id: <20190307164941.3322-1-stefanha@redhat.com> Signed-off-by: Stefan Hajnoczi --- qapi/block-core.json | 6 ++++++ block/file-posix.c | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/qapi/block-core.json b/qapi/block-core.json index 919d0530b2..ce91177bbc 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -2816,6 +2816,10 @@ # @locking: whether to enable file locking. If set to 'auto', only ena= ble # when Open File Descriptor (OFD) locking API is available # (default: auto, since 2.10) +# @drop-cache: invalidate page cache during live migration. This prevents +# stale data on the migration destination with cache.direct= =3Doff. +# Currently only supported on Linux hosts. +# (default: on, since: 4.0) # @x-check-cache-dropped: whether to check that page cache was dropped on = live # migration. May cause noticeable delays if the i= mage # file is large, do not use in production. @@ -2828,6 +2832,8 @@ '*pr-manager': 'str', '*locking': 'OnOffAuto', '*aio': 'BlockdevAioOptions', + '*drop-cache': {'type': 'bool', + 'if': 'defined(CONFIG_LINUX)'}, '*x-check-cache-dropped': 'bool' } } =20 ## diff --git a/block/file-posix.c b/block/file-posix.c index ba6ab62a38..936dea8096 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -154,6 +154,7 @@ typedef struct BDRVRawState { bool page_cache_inconsistent:1; bool has_fallocate; bool needs_alignment; + bool drop_cache; bool check_cache_dropped; =20 PRManager *pr_mgr; @@ -162,6 +163,7 @@ typedef struct BDRVRawState { typedef struct BDRVRawReopenState { int fd; int open_flags; + bool drop_cache; bool check_cache_dropped; } BDRVRawReopenState; =20 @@ -422,6 +424,13 @@ static QemuOptsList raw_runtime_opts =3D { .type =3D QEMU_OPT_STRING, .help =3D "id of persistent reservation manager object (defaul= t: none)", }, +#if defined(__linux__) + { + .name =3D "drop-cache", + .type =3D QEMU_OPT_BOOL, + .help =3D "invalidate page cache during live migration (defaul= t: on)", + }, +#endif { .name =3D "x-check-cache-dropped", .type =3D QEMU_OPT_BOOL, @@ -511,6 +520,7 @@ static int raw_open_common(BlockDriverState *bs, QDict = *options, } } =20 + s->drop_cache =3D qemu_opt_get_bool(opts, "drop-cache", true); s->check_cache_dropped =3D qemu_opt_get_bool(opts, "x-check-cache-drop= ped", false); =20 @@ -869,6 +879,7 @@ static int raw_reopen_prepare(BDRVReopenState *state, goto out; } =20 + rs->drop_cache =3D qemu_opt_get_bool_del(opts, "drop-cache", true); rs->check_cache_dropped =3D qemu_opt_get_bool_del(opts, "x-check-cache-dropped", false); =20 @@ -946,6 +957,7 @@ static void raw_reopen_commit(BDRVReopenState *state) BDRVRawState *s =3D state->bs->opaque; Error *local_err =3D NULL; =20 + s->drop_cache =3D rs->drop_cache; s->check_cache_dropped =3D rs->check_cache_dropped; s->open_flags =3D rs->open_flags; =20 @@ -2531,6 +2543,10 @@ static void coroutine_fn raw_co_invalidate_cache(Blo= ckDriverState *bs, return; } =20 + if (!s->drop_cache) { + return; + } + if (s->open_flags & O_DIRECT) { return; /* No host kernel page cache */ } --=20 2.20.1