From nobody Wed Nov 5 13:26:35 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 1497472423420714.3282070783036; Wed, 14 Jun 2017 13:33:43 -0700 (PDT) Received: from localhost ([::1]:50732 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dLEyy-00044z-5d for importer@patchew.org; Wed, 14 Jun 2017 16:33:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34331) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dLEvf-0000v2-MV for qemu-devel@nongnu.org; Wed, 14 Jun 2017 16:30:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dLEve-0005iQ-D4 for qemu-devel@nongnu.org; Wed, 14 Jun 2017 16:30:15 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39982) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dLEve-0005iH-6w for qemu-devel@nongnu.org; Wed, 14 Jun 2017 16:30:14 -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 3E9AB334599 for ; Wed, 14 Jun 2017 20:30:13 +0000 (UTC) Received: from localhost (ovpn-116-27.gru2.redhat.com [10.97.116.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id B6BB15C6CE; Wed, 14 Jun 2017 20:30:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3E9AB334599 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=pass smtp.mailfrom=ehabkost@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 3E9AB334599 From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Wed, 14 Jun 2017 17:29:56 -0300 Message-Id: <20170614203000.19984-2-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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 14 Jun 2017 20:30:13 +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 1/5] 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 , "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 --- 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 fdd7603c84..3f5f206921 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 ff27e0669e..dbf8878322 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 32db19e3b9..4e9a7fd05a 100644 --- a/vl.c +++ b/vl.c @@ -4762,6 +4762,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.11.0.259.g40922b1 From nobody Wed Nov 5 13:26:35 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 1497472318618318.32624460891634; Wed, 14 Jun 2017 13:31:58 -0700 (PDT) Received: from localhost ([::1]:50728 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dLExJ-0001yN-3i for importer@patchew.org; Wed, 14 Jun 2017 16:31:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34354) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dLEvh-0000wh-KE for qemu-devel@nongnu.org; Wed, 14 Jun 2017 16:30:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dLEvg-0005kh-QC for qemu-devel@nongnu.org; Wed, 14 Jun 2017 16:30:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40056) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dLEvg-0005kP-JY for qemu-devel@nongnu.org; Wed, 14 Jun 2017 16:30:16 -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 79CA437EEB for ; Wed, 14 Jun 2017 20:30:15 +0000 (UTC) Received: from localhost (ovpn-116-27.gru2.redhat.com [10.97.116.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id ED8D478437; Wed, 14 Jun 2017 20:30:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 79CA437EEB 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=pass smtp.mailfrom=ehabkost@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 79CA437EEB From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Wed, 14 Jun 2017 17:29:57 -0300 Message-Id: <20170614203000.19984-3-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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 14 Jun 2017 20:30:15 +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 2/5] memory: Allow RAM up to block->max_length to be discarded 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" Currently ram_block_discard_range() is called only by the postcopy code, using length=3Dblock->used_length. However, new code will use ram_block_discard_range() to discard the contents of the entire RAMBlock, so change the limit check to use max_length instead of used_length. Signed-off-by: Eduardo Habkost Reviewed-by: Dr. David Alan Gilbert --- exec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exec.c b/exec.c index a93e209625..585d6ed6d7 100644 --- a/exec.c +++ b/exec.c @@ -3522,7 +3522,7 @@ int ram_block_discard_range(RAMBlock *rb, uint64_t st= art, size_t length) goto err; } =20 - if ((start + length) <=3D rb->used_length) { + if ((start + length) <=3D rb->max_length) { uint8_t *host_endaddr =3D host_startaddr + length; if ((uintptr_t)host_endaddr & (rb->page_size - 1)) { error_report("ram_block_discard_range: Unaligned end address: = %p", --=20 2.11.0.259.g40922b1 From nobody Wed Nov 5 13:26:35 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 1497472334061525.3446468804352; Wed, 14 Jun 2017 13:32:14 -0700 (PDT) Received: from localhost ([::1]:50729 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dLExX-0002CQ-Jj for importer@patchew.org; Wed, 14 Jun 2017 16:32:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34393) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dLEvr-00014v-4a for qemu-devel@nongnu.org; Wed, 14 Jun 2017 16:30:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dLEvn-0005nS-Ul for qemu-devel@nongnu.org; Wed, 14 Jun 2017 16:30:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41661) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dLEvn-0005n5-PA for qemu-devel@nongnu.org; Wed, 14 Jun 2017 16:30:23 -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 BB44E3DEEB for ; Wed, 14 Jun 2017 20:30:22 +0000 (UTC) Received: from localhost (ovpn-116-27.gru2.redhat.com [10.97.116.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3DF126031C; Wed, 14 Jun 2017 20:30:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com BB44E3DEEB 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=pass smtp.mailfrom=ehabkost@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com BB44E3DEEB From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Wed, 14 Jun 2017 17:29:58 -0300 Message-Id: <20170614203000.19984-4-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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 14 Jun 2017 20:30:22 +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 3/5] memory: Add RAM_NONPERSISTENT flag 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 flag will make qemu_ram_free() discard the contents of the block. It will be used to let QEMU be configured to avoid flushing file contents to disk when exiting. As MADV_REMOVE is not always supported, the new code will try MADV_NOTNEEDED in case MADV_REMOVE fails. The new flag will also indicate that ram_block_discard_range() can use MADV_REMOVE when discarding memory pages. I have considered calling MADV_REMOVE unconditionally (as destroying the RAM contents seems to be OK every time ram_block_discard_range() is called), but for safety I decided to restrict the new code to blocks having RAM_NONPERSISTENT set. Signed-off-by: Eduardo Habkost --- exec.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/exec.c b/exec.c index 585d6ed6d7..a6e9ed4ece 100644 --- a/exec.c +++ b/exec.c @@ -102,6 +102,11 @@ static MemoryRegion io_mem_unassigned; */ #define RAM_RESIZEABLE (1 << 2) =20 +/* RAMBlock contents are not persistent, and we can discard memory contents + * when freeing the memory block. + */ +#define RAM_NONPERSISTENT (1 << 3) + #endif =20 #ifdef TARGET_PAGE_BITS_VARY @@ -2061,6 +2066,10 @@ void qemu_ram_free(RAMBlock *block) ram_block_notify_remove(block->host, block->max_length); } =20 + if (block->flags & RAM_NONPERSISTENT) { + ram_block_discard_range(block, 0, block->max_length); + } + qemu_mutex_lock_ramlist(); QLIST_REMOVE_RCU(block, next); ram_list.mru_block =3D NULL; @@ -3537,7 +3546,13 @@ int ram_block_discard_range(RAMBlock *rb, uint64_t s= tart, size_t length) /* Note: We need the madvise MADV_DONTNEED behaviour of defini= tely * freeing the page. */ - ret =3D madvise(host_startaddr, length, MADV_DONTNEED); + if (rb->flags & RAM_NONPERSISTENT) { + ret =3D madvise(host_startaddr, length, MADV_REMOVE); + } + /* Fallback to MADV_DONTNEED if MADV_REMOVE fails */ + if (ret || !(rb->flags & RAM_NONPERSISTENT)) { + ret =3D madvise(host_startaddr, length, MADV_DONTNEED); + } #endif } else { /* Huge page case - unfortunately it can't do DONTNEED, but --=20 2.11.0.259.g40922b1 From nobody Wed Nov 5 13:26:35 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 1497472345956926.7523365661082; Wed, 14 Jun 2017 13:32:25 -0700 (PDT) Received: from localhost ([::1]:50730 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dLExk-0002M2-Ho for importer@patchew.org; Wed, 14 Jun 2017 16:32:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34417) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dLEvx-00019t-E6 for qemu-devel@nongnu.org; Wed, 14 Jun 2017 16:30:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dLEvw-0005oV-EG for qemu-devel@nongnu.org; Wed, 14 Jun 2017 16:30:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51518) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dLEvw-0005oO-4r for qemu-devel@nongnu.org; Wed, 14 Jun 2017 16:30:32 -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 235BAC04B302 for ; Wed, 14 Jun 2017 20:30:31 +0000 (UTC) Received: from localhost (ovpn-116-27.gru2.redhat.com [10.97.116.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8CFFC78486; Wed, 14 Jun 2017 20:30:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 235BAC04B302 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=ehabkost@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 235BAC04B302 From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Wed, 14 Jun 2017 17:29:59 -0300 Message-Id: <20170614203000.19984-5-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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 14 Jun 2017 20:30:31 +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 4/5] memory: Add 'persistent' parameter to memory_region_init_ram_from_file() 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" Make it possible to set the RAM_NONPERSISTENT flag on the RAMBlock when mapping a file. Signed-off-by: Eduardo Habkost Reviewed-by: Dr. David Alan Gilbert --- include/exec/memory.h | 4 ++++ include/exec/ram_addr.h | 4 ++-- backends/hostmem-file.c | 2 +- exec.c | 7 +++++-- memory.c | 4 +++- numa.c | 2 +- 6 files changed, 16 insertions(+), 7 deletions(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index 80e605a96a..f47c534179 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -446,6 +446,9 @@ void memory_region_init_resizeable_ram(MemoryRegion *mr, * must be unique within any device * @size: size of the region. * @share: %true if memory must be mmaped with the MAP_SHARED flag + * @persistent: %false if RAM contents can be discarded and don't + * need to be flushed to disk when the memory region + * is freed. * @path: the path in which to allocate the RAM. * @errp: pointer to Error*, to store an error if it happens. */ @@ -454,6 +457,7 @@ void memory_region_init_ram_from_file(MemoryRegion *mr, const char *name, uint64_t size, bool share, + bool persistent, const char *path, Error **errp); #endif diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h index 140efa840c..67dc099355 100644 --- a/include/exec/ram_addr.h +++ b/include/exec/ram_addr.h @@ -63,8 +63,8 @@ static inline void *ramblock_ptr(RAMBlock *block, ram_add= r_t offset) long qemu_getrampagesize(void); unsigned long last_ram_page(void); RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr, - bool share, const char *mem_path, - Error **errp); + bool share, bool persistent, + const char *mem_path, Error **errp); RAMBlock *qemu_ram_alloc_from_ptr(ram_addr_t size, void *host, MemoryRegion *mr, Error **errp); RAMBlock *qemu_ram_alloc(ram_addr_t size, MemoryRegion *mr, Error **errp); diff --git a/backends/hostmem-file.c b/backends/hostmem-file.c index fc4ef46d11..d078775b4b 100644 --- a/backends/hostmem-file.c +++ b/backends/hostmem-file.c @@ -57,7 +57,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, + backend->size, fb->share, true, fb->mem_path, errp); g_free(path); } diff --git a/exec.c b/exec.c index a6e9ed4ece..77734198d0 100644 --- a/exec.c +++ b/exec.c @@ -1937,8 +1937,8 @@ static void ram_block_add(RAMBlock *new_block, Error = **errp) =20 #ifdef __linux__ RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr, - bool share, const char *mem_path, - Error **errp) + bool share, bool persistent, + const char *mem_path, Error **errp) { RAMBlock *new_block; Error *local_err =3D NULL; @@ -1965,6 +1965,9 @@ RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, M= emoryRegion *mr, new_block->used_length =3D size; new_block->max_length =3D size; new_block->flags =3D share ? RAM_SHARED : 0; + if (!persistent) { + new_block->flags |=3D RAM_NONPERSISTENT; + } new_block->host =3D file_ram_alloc(new_block, size, mem_path, errp); if (!new_block->host) { diff --git a/memory.c b/memory.c index 0ddc4cc28d..3c0c0ff141 100644 --- a/memory.c +++ b/memory.c @@ -1387,6 +1387,7 @@ void memory_region_init_ram_from_file(MemoryRegion *m= r, const char *name, uint64_t size, bool share, + bool persistent, const char *path, Error **errp) { @@ -1394,7 +1395,8 @@ void memory_region_init_ram_from_file(MemoryRegion *m= r, mr->ram =3D true; mr->terminates =3D true; mr->destructor =3D memory_region_destructor_ram; - mr->ram_block =3D qemu_ram_alloc_from_file(size, mr, share, path, errp= ); + mr->ram_block =3D qemu_ram_alloc_from_file(size, mr, share, persistent, + path, errp); mr->dirty_log_mask =3D tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0; } #endif diff --git a/numa.c b/numa.c index 65701cb6c8..825d5933ca 100644 --- a/numa.c +++ b/numa.c @@ -531,7 +531,7 @@ static void allocate_system_memory_nonnuma(MemoryRegion= *mr, Object *owner, if (mem_path) { #ifdef __linux__ Error *err =3D NULL; - memory_region_init_ram_from_file(mr, owner, name, ram_size, false, + memory_region_init_ram_from_file(mr, owner, name, ram_size, false,= true, mem_path, &err); if (err) { error_report_err(err); --=20 2.11.0.259.g40922b1 From nobody Wed Nov 5 13:26:35 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