From patchwork Sat Aug 11 20:59:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Chen X-Patchwork-Id: 10563551 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7868913B4 for ; Sat, 11 Aug 2018 21:05:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 697A229239 for ; Sat, 11 Aug 2018 21:05:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5A81629758; Sat, 11 Aug 2018 21:05:16 +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=-7.8 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 EB37729239 for ; Sat, 11 Aug 2018 21:05:15 +0000 (UTC) Received: from localhost ([::1]:33198 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fob4V-0000tx-7b for patchwork-qemu-devel@patchwork.kernel.org; Sat, 11 Aug 2018 17:05:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48172) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1foazr-000533-Vf for qemu-devel@nongnu.org; Sat, 11 Aug 2018 17:00:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1foazq-0001NH-Tk for qemu-devel@nongnu.org; Sat, 11 Aug 2018 17:00:27 -0400 Received: from mail-pl0-x236.google.com ([2607:f8b0:400e:c01::236]:45121) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1foazq-0001MV-GZ for qemu-devel@nongnu.org; Sat, 11 Aug 2018 17:00:26 -0400 Received: by mail-pl0-x236.google.com with SMTP id j8-v6so5375679pll.12 for ; Sat, 11 Aug 2018 14:00:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=hl4GecGoDAwGK9lm9frRd4U00FYZiPtvthNssXbfQco=; b=Dul44DDBRnDFrf8kPM2Od8PDVChLotH4obsw4tpcTrjTjxljOzcDps11sff+bv8Dte af5FP1fZk84tlmStlrsg3knsmE6qULsi6UfE5JBC1JX4hAtTMafWU5c6jVZnZ5SxOlxq xX34vt36mZuxMW/pncrwWaYyGMddM6CFXBXkX8l/kFqi5jdDG3yCUIvyWvG8WiKHq3hp Qo7666Hqt4mRw7HbHcNo4E9BmcwLx8bLFdtb188FfKNWMYCTmYjqe2aoUi99s5gYEwYc BrFKOfdep4wzbnMBmJHE9CDD9BxQpa+HDElnLUIh7wjQuW973epECiysMSESys9X2nX4 FiDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=hl4GecGoDAwGK9lm9frRd4U00FYZiPtvthNssXbfQco=; b=Zou+UGrmZQ17VucSDgWyzI7BBzWfkN3aDysoRPvWZ2gblfNifQFn7l7xtekBPB4qXr jYZPwMdw9h61wAbIp9qP0DDQbtBuPLANqFflcqfWMoR5K2nio/StMu8jpH6qLuL4ANFd RImqa0SBZOnwR27x3139SmoQguyk8DxMeteK7WQRsae+AsDczs72c9krhEjjO+y7RMaC 2pwAf3d45o9dzowGoJmTqLQovx1MqjpBKmPo4hehz4GOII/8iJLNBz+ExUb9InFhCQfG QHDsQrXEPhhWzy5VD6TZbTNECyGttRgCnKOgf3ukGnR+GYucsJc8n6RceSiCkZHU3TEt qX6A== X-Gm-Message-State: AOUpUlFUVClr/WXEq+NzvNleMv9Rrs6OtLABTP0+4l16MhF8gzdkvZ7g iV78pR9c9rVDDyYFmZxOuHHgBSk7 X-Google-Smtp-Source: AA+uWPyISmh4AoYFhX33KZzrdtQ03XyRshGsvqvYax0drWfC2DIMELCKSupe87FbA1pV5kVcHrLQiw== X-Received: by 2002:a17:902:8d8c:: with SMTP id v12-v6mr10915205plo.94.1534021225198; Sat, 11 Aug 2018 14:00:25 -0700 (PDT) Received: from localhost.localdomain (155.150.229.35.bc.googleusercontent.com. [35.229.150.155]) by smtp.gmail.com with ESMTPSA id h24-v6sm23502641pfk.113.2018.08.11.14.00.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 11 Aug 2018 14:00:24 -0700 (PDT) From: Zhang Chen To: qemu-devel@nongnu.org, Paolo Bonzini , Juan Quintela , "Dr . David Alan Gilbert" , Jason Wang , Eric Blake , Markus Armbruster Date: Sun, 12 Aug 2018 04:59:13 +0800 Message-Id: <20180811205924.4113-10-zhangckid@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180811205924.4113-1-zhangckid@gmail.com> References: <20180811205924.4113-1-zhangckid@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c01::236 Subject: [Qemu-devel] [PATCH V11 09/20] COLO: Flush memory data from ram cache 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: zhanghailiang , Li Zhijian , Zhang Chen Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP During the time of VM's running, PVM may dirty some pages, we will transfer PVM's dirty pages to SVM and store them into SVM's RAM cache at next checkpoint time. So, the content of SVM's RAM cache will always be same with PVM's memory after checkpoint. Instead of flushing all content of PVM's RAM cache into SVM's MEMORY, we do this in a more efficient way: Only flush any page that dirtied by PVM since last checkpoint. In this way, we can ensure SVM's memory same with PVM's. Besides, we must ensure flush RAM cache before load device state. Signed-off-by: zhanghailiang Signed-off-by: Li Zhijian Reviewed-by: Dr. David Alan Gilbert --- migration/ram.c | 37 +++++++++++++++++++++++++++++++++++++ migration/trace-events | 2 ++ 2 files changed, 39 insertions(+) diff --git a/migration/ram.c b/migration/ram.c index 3dc403adb5..b4cbcf783f 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -3841,6 +3841,39 @@ static bool postcopy_is_running(void) return ps >= POSTCOPY_INCOMING_LISTENING && ps < POSTCOPY_INCOMING_END; } +/* + * Flush content of RAM cache into SVM's memory. + * Only flush the pages that be dirtied by PVM or SVM or both. + */ +static void colo_flush_ram_cache(void) +{ + RAMBlock *block = NULL; + void *dst_host; + void *src_host; + unsigned long offset = 0; + + trace_colo_flush_ram_cache_begin(ram_state->migration_dirty_pages); + rcu_read_lock(); + block = QLIST_FIRST_RCU(&ram_list.blocks); + + while (block) { + offset = migration_bitmap_find_dirty(ram_state, block, offset); + + if (offset << TARGET_PAGE_BITS >= block->used_length) { + offset = 0; + block = QLIST_NEXT_RCU(block, next); + } else { + migration_bitmap_clear_dirty(ram_state, block, offset); + dst_host = block->host + (offset << TARGET_PAGE_BITS); + src_host = block->colo_cache + (offset << TARGET_PAGE_BITS); + memcpy(dst_host, src_host, TARGET_PAGE_SIZE); + } + } + + rcu_read_unlock(); + trace_colo_flush_ram_cache_end(); +} + static int ram_load(QEMUFile *f, void *opaque, int version_id) { int flags = 0, ret = 0, invalid_flags = 0; @@ -4017,6 +4050,10 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) ret |= wait_for_decompress_done(); rcu_read_unlock(); trace_ram_load_complete(ret, seq_iter); + + if (!ret && migration_incoming_in_colo_state()) { + colo_flush_ram_cache(); + } return ret; } diff --git a/migration/trace-events b/migration/trace-events index fa0ff3f3bf..bd2d0cd25a 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -102,6 +102,8 @@ ram_dirty_bitmap_sync_start(void) "" ram_dirty_bitmap_sync_wait(void) "" ram_dirty_bitmap_sync_complete(void) "" ram_state_resume_prepare(uint64_t v) "%" PRId64 +colo_flush_ram_cache_begin(uint64_t dirty_pages) "dirty_pages %" PRIu64 +colo_flush_ram_cache_end(void) "" # migration/migration.c await_return_path_close_on_source_close(void) ""