From nobody Sat Nov 8 05:20:47 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