From patchwork Wed Feb 28 07:25:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haozhong Zhang X-Patchwork-Id: 10246939 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 46F3B60211 for ; Wed, 28 Feb 2018 07:31:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3378928902 for ; Wed, 28 Feb 2018 07:31:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3199828CEB; Wed, 28 Feb 2018 07:31:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1D2F028D89 for ; Wed, 28 Feb 2018 07:31:15 +0000 (UTC) Received: from localhost ([::1]:42632 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eqwCp-0000Eb-74 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 28 Feb 2018 02:31:15 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55276) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eqw8K-0004lz-Ab for qemu-devel@nongnu.org; Wed, 28 Feb 2018 02:26:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eqw8J-0000Qv-CK for qemu-devel@nongnu.org; Wed, 28 Feb 2018 02:26:36 -0500 Received: from mga02.intel.com ([134.134.136.20]:30637) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eqw8J-0000CT-0R for qemu-devel@nongnu.org; Wed, 28 Feb 2018 02:26:35 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Feb 2018 23:26:34 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.47,404,1515484800"; d="scan'208";a="34718517" Received: from hz-desktop.sh.intel.com (HELO localhost) ([10.239.13.35]) by orsmga001.jf.intel.com with ESMTP; 27 Feb 2018 23:26:32 -0800 From: Haozhong Zhang To: qemu-devel@nongnu.org Date: Wed, 28 Feb 2018 15:25:57 +0800 Message-Id: <20180228072558.7434-8-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180228072558.7434-1-haozhong.zhang@intel.com> References: <20180228072558.7434-1-haozhong.zhang@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 134.134.136.20 Subject: [Qemu-devel] [PATCH v4 7/8] migration/ram: ensure write persistence on loading compressed pages to PMEM 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: Haozhong Zhang , Xiao Guangrong , mst@redhat.com, Juan Quintela , dgilbert@redhat.com, Stefan Hajnoczi , Paolo Bonzini , Igor Mammedov , Dan Williams , Eduardo Habkost Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP When loading a compressed page to persistent memory, flush CPU cache after the data is decompressed. Combined with a call to pmem_drain() at the end of memory loading, we can guarantee those compressed pages are persistently loaded to PMEM. Signed-off-by: Haozhong Zhang --- include/qemu/pmem.h | 1 + migration/ram.c | 16 +++++++++++----- stubs/pmem.c | 4 ++++ 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/include/qemu/pmem.h b/include/qemu/pmem.h index 127b87c326..120439ecb8 100644 --- a/include/qemu/pmem.h +++ b/include/qemu/pmem.h @@ -20,6 +20,7 @@ void *pmem_memcpy_nodrain(void *pmemdest, const void *src, size_t len); void *pmem_memcpy_persist(void *pmemdest, const void *src, size_t len); void *pmem_memset_nodrain(void *pmemdest, int c, size_t len); void pmem_drain(void); +void pmem_flush(const void *addr, size_t len); #endif /* CONFIG_LIBPMEM */ diff --git a/migration/ram.c b/migration/ram.c index ea2ad7dff0..37f3c39cee 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -276,6 +276,7 @@ struct DecompressParam { void *des; uint8_t *compbuf; int len; + bool is_pmem; }; typedef struct DecompressParam DecompressParam; @@ -2498,7 +2499,7 @@ static void *do_data_decompress(void *opaque) DecompressParam *param = opaque; unsigned long pagesize; uint8_t *des; - int len; + int len, rc; qemu_mutex_lock(¶m->mutex); while (!param->quit) { @@ -2514,8 +2515,11 @@ static void *do_data_decompress(void *opaque) * not a problem because the dirty page will be retransferred * and uncompress() won't break the data in other pages. */ - uncompress((Bytef *)des, &pagesize, - (const Bytef *)param->compbuf, len); + rc = uncompress((Bytef *)des, &pagesize, + (const Bytef *)param->compbuf, len); + if (rc == Z_OK && param->is_pmem) { + pmem_flush(des, len); + } qemu_mutex_lock(&decomp_done_lock); param->done = true; @@ -2601,7 +2605,8 @@ static void compress_threads_load_cleanup(void) } static void decompress_data_with_multi_threads(QEMUFile *f, - void *host, int len) + void *host, int len, + bool is_pmem) { int idx, thread_count; @@ -2615,6 +2620,7 @@ static void decompress_data_with_multi_threads(QEMUFile *f, qemu_get_buffer(f, decomp_param[idx].compbuf, len); decomp_param[idx].des = host; decomp_param[idx].len = len; + decomp_param[idx].is_pmem = is_pmem; qemu_cond_signal(&decomp_param[idx].cond); qemu_mutex_unlock(&decomp_param[idx].mutex); break; @@ -2969,7 +2975,7 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) ret = -EINVAL; break; } - decompress_data_with_multi_threads(f, host, len); + decompress_data_with_multi_threads(f, host, len, is_pmem); break; case RAM_SAVE_FLAG_XBZRLE: diff --git a/stubs/pmem.c b/stubs/pmem.c index e172f31174..cfab830131 100644 --- a/stubs/pmem.c +++ b/stubs/pmem.c @@ -31,3 +31,7 @@ void *pmem_memcpy_nodrain(void *pmemdest, const void *src, size_t len) { return memcpy(pmemdest, src, len); } + +void pmem_flush(const void *addr, size_t len) +{ +}