From patchwork Sun Jul 22 19:33:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Chen X-Patchwork-Id: 10539379 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 0841B174A for ; Sun, 22 Jul 2018 19:39:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EE0662842E for ; Sun, 22 Jul 2018 19:39:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E229028434; Sun, 22 Jul 2018 19:39:15 +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 703E92842E for ; Sun, 22 Jul 2018 19:39:15 +0000 (UTC) Received: from localhost ([::1]:57228 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fhKCI-00064w-IU for patchwork-qemu-devel@patchwork.kernel.org; Sun, 22 Jul 2018 15:39:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37754) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fhK8E-0002kp-K2 for qemu-devel@nongnu.org; Sun, 22 Jul 2018 15:35:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fhK8D-0000h0-Ck for qemu-devel@nongnu.org; Sun, 22 Jul 2018 15:35:02 -0400 Received: from mail-pg1-x52d.google.com ([2607:f8b0:4864:20::52d]:41393) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fhK8D-0000gl-6n for qemu-devel@nongnu.org; Sun, 22 Jul 2018 15:35:01 -0400 Received: by mail-pg1-x52d.google.com with SMTP id z8-v6so10655531pgu.8 for ; Sun, 22 Jul 2018 12:35:01 -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=BEIbFZWpl6d3aI3vjmk78DkeNB/5U4L8tjZqNXpkXj8=; b=O5jKYkmqEsAhprJ3gHL/8DRxd/zY32HDzTfRb5PKkfJjOduro5j7e9GH3DZ8uuesJL BGutIWNccDZpsL8fUEpocDlOoOgk0IewhkeN8tXVZNT3CT80sLabqtUaxBygchwApDcc axGkUwBXl0Kcb4c1nFtJ73AjO+SzH3Z1uZLqN5jW7H79aOry2jUXM/ooSBJACL8Old/p 7n8Htg+rVpawaV2ZKjV28gBJe6MPFgTx5JqOhJEW/VlGegVJaMDtAkr6RG4D8NqNCtDu SIlMkvCFdQmXYSMrxnBpk21EVfCv4dcE5fNnNbK2XzdHjOgjR8WQfuUhOZQwe9IwHeba VrTQ== 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=BEIbFZWpl6d3aI3vjmk78DkeNB/5U4L8tjZqNXpkXj8=; b=fRh9HseGo366XYrUxOxgeM410NOc+KxCMshQRPURp3ZBxTn+1HtXbniBBO3hdg9q3S yiHWncuHb1fjQVSArc8PIm5gRvT4YNdez1PedHoOZV8fTFMjXO+svROdUHsdrIkuZNYu 5jCqHLOXJBkL42qdgOyAwfMLrUhJ53rgN+n+LlQpGmZSqs+neRiNPm7FuvNYpiNyvJHm ZPCfcyA4UgXJE/PL6n5aTog/c77juYUOZrYQXJ9+0XwXW/wtZwHzPJgZG1Vqh0+2LOgb o404EtJbFI49d0GCFgjE/7D7c6f63b1aG23FdruepDxvkFX2a5t43aD2ybLq1bOI+LLg RXdA== X-Gm-Message-State: AOUpUlEMoGwF9hvpiLUe2v/i2pazQSgZY9urpnMr1XmIFTiDCfeXG8jG YZcEo6a88/Bd0FhdIyaIE3viIXn2 X-Google-Smtp-Source: AAOMgpdLde/bNsZZIY454p1KBOpCRsb3dPmT41/Nxh5HgKr1rrSGyLl+hrixR5VRc8H0o3vBQhRaFg== X-Received: by 2002:a65:6411:: with SMTP id a17-v6mr9374539pgv.287.1532288100000; Sun, 22 Jul 2018 12:35:00 -0700 (PDT) Received: from localhost.localdomain (155.150.229.35.bc.googleusercontent.com. [35.229.150.155]) by smtp.gmail.com with ESMTPSA id 87-v6sm14215353pfn.103.2018.07.22.12.34.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 22 Jul 2018 12:34:59 -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: Mon, 23 Jul 2018 03:33:39 +0800 Message-Id: <20180722193350.6028-10-zhangckid@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180722193350.6028-1-zhangckid@gmail.com> References: <20180722193350.6028-1-zhangckid@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::52d Subject: [Qemu-devel] [PATCH V10 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 d1060f1337..4df85d69c1 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -3830,6 +3830,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; @@ -4006,6 +4039,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) ""