From nobody Wed Nov 5 10:28:09 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.zohomail.com; dkim=fail; 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; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1534021554429314.9183854765017; Sat, 11 Aug 2018 14:05:54 -0700 (PDT) Received: from localhost ([::1]:33198 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fob57-0000tx-8t for importer@patchew.org; Sat, 11 Aug 2018 17:05:53 -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) 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) 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) 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 checkp= oint time. So, the content of SVM's RAM cache will always be same with PVM's mem= ory 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 >=3D POSTCOPY_INCOMING_LISTENING && ps < POSTCOPY_INCOMING_E= ND; } =20 +/* + * 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 =3D NULL; + void *dst_host; + void *src_host; + unsigned long offset =3D 0; + + trace_colo_flush_ram_cache_begin(ram_state->migration_dirty_pages); + rcu_read_lock(); + block =3D QLIST_FIRST_RCU(&ram_list.blocks); + + while (block) { + offset =3D migration_bitmap_find_dirty(ram_state, block, offset); + + if (offset << TARGET_PAGE_BITS >=3D block->used_length) { + offset =3D 0; + block =3D QLIST_NEXT_RCU(block, next); + } else { + migration_bitmap_clear_dirty(ram_state, block, offset); + dst_host =3D block->host + (offset << TARGET_PAGE_BITS); + src_host =3D 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 =3D 0, ret =3D 0, invalid_flags =3D 0; @@ -4017,6 +4050,10 @@ static int ram_load(QEMUFile *f, void *opaque, int v= ersion_id) ret |=3D 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; } =20 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) "" =20 # migration/migration.c await_return_path_close_on_source_close(void) "" --=20 2.17.GIT