From nobody Sun Apr 28 22:50:12 2024 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.zohomail.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 1503603191183136.20867943035591; Thu, 24 Aug 2017 12:33:11 -0700 (PDT) Received: from localhost ([::1]:50128 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dkxsL-0006Kt-UN for importer@patchew.org; Thu, 24 Aug 2017 15:33:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50988) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dkxis-0006Re-5j for qemu-devel@nongnu.org; Thu, 24 Aug 2017 15:23:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dkxiq-0001YK-S0 for qemu-devel@nongnu.org; Thu, 24 Aug 2017 15:23:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48088) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dkxiq-0001Xg-Lp for qemu-devel@nongnu.org; Thu, 24 Aug 2017 15:23:20 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B1D67267FB; Thu, 24 Aug 2017 19:23:19 +0000 (UTC) Received: from localhost (ovpn-116-4.gru2.redhat.com [10.97.116.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2793017CC4; Thu, 24 Aug 2017 19:23:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B1D67267FB Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=ehabkost@redhat.com From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Thu, 24 Aug 2017 16:23:13 -0300 Message-Id: <20170824192315.5897-2-ehabkost@redhat.com> In-Reply-To: <20170824192315.5897-1-ehabkost@redhat.com> References: <20170824192315.5897-1-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 24 Aug 2017 19:23:19 +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 v2 1/3] vl: Clean up user-creatable objects when exiting 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 , Zack Cornelius , "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" Delete all user-creatable objects in /objects when exiting QEMU, so they can perform cleanup actions. Signed-off-by: Eduardo Habkost Acked-by: Philippe Mathieu-Daud=C3=A9 --- Changes v1 -> v2: * (none) --- include/qom/object_interfaces.h | 8 ++++++++ qom/object_interfaces.c | 5 +++++ vl.c | 1 + 3 files changed, 14 insertions(+) diff --git a/include/qom/object_interfaces.h b/include/qom/object_interface= s.h index fdd7603..3f5f206 100644 --- a/include/qom/object_interfaces.h +++ b/include/qom/object_interfaces.h @@ -148,4 +148,12 @@ int user_creatable_add_opts_foreach(void *opaque, */ void user_creatable_del(const char *id, Error **errp); =20 +/** + * user_creatable_cleanup: + * + * Delete all user-creatable objects and the user-creatable + * objects container. + */ +void user_creatable_cleanup(void); + #endif diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c index ff27e06..dbf8878 100644 --- a/qom/object_interfaces.c +++ b/qom/object_interfaces.c @@ -193,6 +193,11 @@ void user_creatable_del(const char *id, Error **errp) object_unparent(obj); } =20 +void user_creatable_cleanup(void) +{ + object_unparent(object_get_objects_root()); +} + static void register_types(void) { static const TypeInfo uc_interface_info =3D { diff --git a/vl.c b/vl.c index 8e247cc..91d0ef0 100644 --- a/vl.c +++ b/vl.c @@ -4801,6 +4801,7 @@ int main(int argc, char **argv, char **envp) audio_cleanup(); monitor_cleanup(); qemu_chr_cleanup(); + user_creatable_cleanup(); /* TODO: unref root container, check all devices are ok */ =20 return 0; --=20 2.9.4 From nobody Sun Apr 28 22:50:12 2024 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.zohomail.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 150360312183987.88862357940991; Thu, 24 Aug 2017 12:32:01 -0700 (PDT) Received: from localhost ([::1]:50125 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dkxrE-0005Ei-Ag for importer@patchew.org; Thu, 24 Aug 2017 15:32:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51030) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dkxiw-0006V8-Aw for qemu-devel@nongnu.org; Thu, 24 Aug 2017 15:23:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dkxiu-0001c9-Mn for qemu-devel@nongnu.org; Thu, 24 Aug 2017 15:23:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49824) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dkxiu-0001bc-HC for qemu-devel@nongnu.org; Thu, 24 Aug 2017 15:23:24 -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 8264E81DF8; Thu, 24 Aug 2017 19:23:23 +0000 (UTC) Received: from localhost (ovpn-116-4.gru2.redhat.com [10.97.116.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1097A61348; Thu, 24 Aug 2017 19:23:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8264E81DF8 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=ehabkost@redhat.com From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Thu, 24 Aug 2017 16:23:14 -0300 Message-Id: <20170824192315.5897-3-ehabkost@redhat.com> In-Reply-To: <20170824192315.5897-1-ehabkost@redhat.com> References: <20170824192315.5897-1-ehabkost@redhat.com> 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.25]); Thu, 24 Aug 2017 19:23:23 +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 v2 2/3] osdep: Define QEMU_MADV_REMOVE 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 , Zack Cornelius , "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" Define QEMU_MADV_REMOVE, so we can use it with qemu_madvise(). Signed-off-by: Eduardo Habkost Reviewed-by: Dr. David Alan Gilbert --- Changes v1 -> v2: * New patch added to series --- include/qemu/osdep.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index 6855b94..e9fa217 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -257,6 +257,11 @@ void qemu_anon_ram_free(void *ptr, size_t size); #else #define QEMU_MADV_NOHUGEPAGE QEMU_MADV_INVALID #endif +#ifdef MADV_REMOVE +#define QEMU_MADV_REMOVE MADV_REMOVE +#else +#define QEMU_MADV_REMOVE QEMU_MADV_INVALID +#endif =20 #elif defined(CONFIG_POSIX_MADVISE) =20 @@ -269,6 +274,7 @@ void qemu_anon_ram_free(void *ptr, size_t size); #define QEMU_MADV_DONTDUMP QEMU_MADV_INVALID #define QEMU_MADV_HUGEPAGE QEMU_MADV_INVALID #define QEMU_MADV_NOHUGEPAGE QEMU_MADV_INVALID +#define QEMU_MADV_REMOVE QEMU_MADV_INVALID =20 #else /* no-op */ =20 @@ -281,6 +287,7 @@ void qemu_anon_ram_free(void *ptr, size_t size); #define QEMU_MADV_DONTDUMP QEMU_MADV_INVALID #define QEMU_MADV_HUGEPAGE QEMU_MADV_INVALID #define QEMU_MADV_NOHUGEPAGE QEMU_MADV_INVALID +#define QEMU_MADV_REMOVE QEMU_MADV_INVALID =20 #endif =20 --=20 2.9.4 From nobody Sun Apr 28 22:50:12 2024 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.zohomail.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 1503603295980530.4520429117033; Thu, 24 Aug 2017 12:34:55 -0700 (PDT) Received: from localhost ([::1]:50138 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dkxu2-0007uG-JT for importer@patchew.org; Thu, 24 Aug 2017 15:34:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51057) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dkxix-0006WL-Ux for qemu-devel@nongnu.org; Thu, 24 Aug 2017 15:23:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dkxiw-0001dk-VU for qemu-devel@nongnu.org; Thu, 24 Aug 2017 15:23:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60314) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dkxiw-0001d8-NM for qemu-devel@nongnu.org; Thu, 24 Aug 2017 15:23:26 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C208113A82; Thu, 24 Aug 2017 19:23:25 +0000 (UTC) Received: from localhost (ovpn-116-4.gru2.redhat.com [10.97.116.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id EF0481712D; Thu, 24 Aug 2017 19:23:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C208113A82 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=ehabkost@redhat.com From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Thu, 24 Aug 2017 16:23:15 -0300 Message-Id: <20170824192315.5897-4-ehabkost@redhat.com> In-Reply-To: <20170824192315.5897-1-ehabkost@redhat.com> References: <20170824192315.5897-1-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 24 Aug 2017 19:23:25 +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 v2 3/3] hostmem-file: Add "discard-data" 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 , Zack Cornelius , "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 file contents can be destroyed and don't need to be flushed to disk when QEMU exits or when the memory backend object is removed. Internally, it will trigger a madvise(MADV_REMOVE) call when the memory backend is removed. Signed-off-by: Eduardo Habkost --- Changes v1 -> v2: * Replaced 'persistent=3Dno' with 'discard-data=3Dyes', to make it clear that the flag will destroy data on the backing file. * Call madvise() directly from unparent() method instead of relying on low-level memory backend code to call it. v1 relied on getting the memory region reference count back to 0, which doesn't happen when QEMU is exiting because there's no machine cleanup code to ensure that. --- backends/hostmem-file.c | 29 +++++++++++++++++++++++++++++ qemu-options.hx | 5 ++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/backends/hostmem-file.c b/backends/hostmem-file.c index fc4ef46..e44c319 100644 --- a/backends/hostmem-file.c +++ b/backends/hostmem-file.c @@ -32,6 +32,7 @@ struct HostMemoryBackendFile { HostMemoryBackend parent_obj; =20 bool share; + bool discard_data; char *mem_path; }; =20 @@ -103,16 +104,44 @@ static void file_memory_backend_set_share(Object *o, = bool value, Error **errp) fb->share =3D value; } =20 +static bool file_memory_backend_get_discard_data(Object *o, Error **errp) +{ + return MEMORY_BACKEND_FILE(o)->discard_data; +} + +static void file_memory_backend_set_discard_data(Object *o, bool value, + Error **errp) +{ + MEMORY_BACKEND_FILE(o)->discard_data =3D value; +} + +static void file_backend_unparent(Object *obj) +{ + HostMemoryBackend *backend =3D MEMORY_BACKEND(obj); + HostMemoryBackendFile *fb =3D MEMORY_BACKEND_FILE(obj); + + if (host_memory_backend_mr_inited(backend) && fb->discard_data) { + void *ptr =3D memory_region_get_ram_ptr(&backend->mr); + uint64_t sz =3D memory_region_size(&backend->mr); + + qemu_madvise(ptr, sz, QEMU_MADV_REMOVE); + } +} + static void file_backend_class_init(ObjectClass *oc, void *data) { HostMemoryBackendClass *bc =3D MEMORY_BACKEND_CLASS(oc); =20 bc->alloc =3D file_backend_memory_alloc; + oc->unparent =3D file_backend_unparent; =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, "discard-data", + file_memory_backend_get_discard_data, file_memory_backend_set_disc= ard_data, + &error_abort); object_class_property_add_str(oc, "mem-path", get_mem_path, set_mem_path, &error_abort); diff --git a/qemu-options.hx b/qemu-options.hx index 9f6e2ad..ad985e4 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -4160,7 +4160,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},discard-data=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 @@ -4172,6 +4172,9 @@ the path to either a shared memory or huge page files= ystem 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{discard-data} boolean option to @var{on} +indicates that file contents can be destroyed when QEMU exits, +to avoid unnecessarily flushing data to the backing file. =20 @item -object rng-random,id=3D@var{id},filename=3D@var{/dev/random} =20 --=20 2.9.4