From nobody Wed Nov 5 15:20:29 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.zoho.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 1497472517292441.4422870231232; Wed, 14 Jun 2017 13:35:17 -0700 (PDT) Received: from localhost ([::1]:50736 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dLF0W-0004xo-23 for importer@patchew.org; Wed, 14 Jun 2017 16:35:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34477) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dLEw4-0001Hk-VI for qemu-devel@nongnu.org; Wed, 14 Jun 2017 16:30:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dLEw3-0005r8-Mk for qemu-devel@nongnu.org; Wed, 14 Jun 2017 16:30:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39200) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dLEw3-0005qZ-DU for qemu-devel@nongnu.org; Wed, 14 Jun 2017 16:30:39 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6D08580C08 for ; Wed, 14 Jun 2017 20:30:38 +0000 (UTC) Received: from localhost (ovpn-116-27.gru2.redhat.com [10.97.116.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id DB1E460F85; Wed, 14 Jun 2017 20:30:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6D08580C08 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=ehabkost@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 6D08580C08 From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Wed, 14 Jun 2017 17:30:00 -0300 Message-Id: <20170614203000.19984-6-ehabkost@redhat.com> In-Reply-To: <20170614203000.19984-1-ehabkost@redhat.com> References: <20170614203000.19984-1-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 14 Jun 2017 20:30:38 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 5/5] hostmem-file: Add "persistent" 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: Paolo Bonzini , "Dr. David Alan Gilbert" , Igor Mammedov 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" The new option can be used to indicate that the memory block contents can be safely discarded and don't need to be flushed to the filesystem when the memory backend is destroyed (including when QEMU exits). Internally, it will trigger a madvise(MADV_REMOVE) or fallocate(FALLOC_FL_PUNCH_HOLE) call when the memory backend is destroyed. Signed-off-by: Eduardo Habkost --- backends/hostmem-file.c | 35 ++++++++++++++++++++++++++++++++++- qemu-options.hx | 9 ++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/backends/hostmem-file.c b/backends/hostmem-file.c index d078775b4b..e6cb232349 100644 --- a/backends/hostmem-file.c +++ b/backends/hostmem-file.c @@ -32,6 +32,7 @@ struct HostMemoryBackendFile { HostMemoryBackend parent_obj; =20 bool share; + bool persistent; char *mem_path; }; =20 @@ -57,7 +58,7 @@ file_backend_memory_alloc(HostMemoryBackend *backend, Err= or **errp) path =3D object_get_canonical_path(OBJECT(backend)); memory_region_init_ram_from_file(&backend->mr, OBJECT(backend), path, - backend->size, fb->share, true, + backend->size, fb->share, fb->persistent, fb->mem_path, errp); g_free(path); } @@ -103,6 +104,26 @@ static void file_memory_backend_set_share(Object *o, b= ool value, Error **errp) fb->share =3D value; } =20 +static bool file_memory_backend_get_persistent(Object *o, Error **errp) +{ + HostMemoryBackendFile *fb =3D MEMORY_BACKEND_FILE(o); + + return fb->persistent; +} + +static void file_memory_backend_set_persistent(Object *o, bool value, + Error **errp) +{ + HostMemoryBackend *backend =3D MEMORY_BACKEND(o); + HostMemoryBackendFile *fb =3D MEMORY_BACKEND_FILE(o); + + if (host_memory_backend_mr_inited(backend)) { + error_setg(errp, "cannot change property value"); + return; + } + fb->persistent =3D value; +} + static void file_backend_class_init(ObjectClass *oc, void *data) { @@ -110,14 +131,25 @@ file_backend_class_init(ObjectClass *oc, void *data) =20 bc->alloc =3D file_backend_memory_alloc; =20 + object_class_property_add_bool(oc, "share", file_memory_backend_get_share, file_memory_backend_set_share, &error_abort); + object_class_property_add_bool(oc, "persistent", + file_memory_backend_get_persistent, file_memory_backend_set_persis= tent, + &error_abort); object_class_property_add_str(oc, "mem-path", get_mem_path, set_mem_path, &error_abort); } =20 +static void file_backend_instance_init(Object *o) +{ + HostMemoryBackendFile *fb =3D MEMORY_BACKEND_FILE(o); + + fb->persistent =3D true; +} + static void file_backend_instance_finalize(Object *o) { HostMemoryBackendFile *fb =3D MEMORY_BACKEND_FILE(o); @@ -129,6 +161,7 @@ static const TypeInfo file_backend_info =3D { .name =3D TYPE_MEMORY_BACKEND_FILE, .parent =3D TYPE_MEMORY_BACKEND, .class_init =3D file_backend_class_init, + .instance_init =3D file_backend_instance_init, .instance_finalize =3D file_backend_instance_finalize, .instance_size =3D sizeof(HostMemoryBackendFile), }; diff --git a/qemu-options.hx b/qemu-options.hx index 30c4f9850f..7fb4feec9b 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -3961,7 +3961,7 @@ property must be set. These objects are placed in the =20 @table @option =20 -@item -object memory-backend-file,id=3D@var{id},size=3D@var{size},mem-path= =3D@var{dir},share=3D@var{on|off} +@item -object memory-backend-file,id=3D@var{id},size=3D@var{size},mem-path= =3D@var{dir},share=3D@var{on|off},persistent=3D@var{on|off} =20 Creates a memory file backend object, which can be used to back the guest RAM with huge pages. The @option{id} parameter is a @@ -3973,6 +3973,13 @@ the path to either a shared memory or huge page file= system mount. The @option{share} boolean option determines whether the memory region is marked as private to QEMU, or shared. The latter allows a co-operating external process to access the QEMU memory region. +Setting the @option{persistent} boolean option to @var{off} +indicates that memory contents can be safely discarded and not +flushed to disk when the backend object is destroyed or QEMU +exits. @option{persistent} is @var{on} by default. It is valid +to set @option{persistent} to @var{off} if @option{share} is +@var{on}. It is redundant to set @option{persistent} to @var{off} +if @option{share} is @var{off}. =20 @item -object rng-random,id=3D@var{id},filename=3D@var{/dev/random} =20 --=20 2.11.0.259.g40922b1