From patchwork Sun Jul 22 19:33:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Chen X-Patchwork-Id: 10539397 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 E54C6112B for ; Sun, 22 Jul 2018 19:47:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C973B27F92 for ; Sun, 22 Jul 2018 19:47:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BA7E227FA1; Sun, 22 Jul 2018 19:47:35 +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 173D92842E for ; Sun, 22 Jul 2018 19:47:34 +0000 (UTC) Received: from localhost ([::1]:57277 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fhKKL-0004qa-K3 for patchwork-qemu-devel@patchwork.kernel.org; Sun, 22 Jul 2018 15:47:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37740) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fhK8B-0002iW-11 for qemu-devel@nongnu.org; Sun, 22 Jul 2018 15:35:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fhK87-0000fP-TO for qemu-devel@nongnu.org; Sun, 22 Jul 2018 15:34:59 -0400 Received: from mail-pl0-x244.google.com ([2607:f8b0:400e:c01::244]:36471) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fhK87-0000f6-N1 for qemu-devel@nongnu.org; Sun, 22 Jul 2018 15:34:55 -0400 Received: by mail-pl0-x244.google.com with SMTP id e11-v6so7297669plb.3 for ; Sun, 22 Jul 2018 12:34:55 -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=8tCTr8WWMvBgNBqYh56Canq/y8D1wo9Vrf1vFwhwvxM=; b=BYjbt/D31AfRjt0ypbw56SQCThTq3xJZEuzrufBarRp5l+bcnmrxGoOMks6W13Em7P As8Pf3E3TR4vBL/DQXbciKmQY+re6J2xOMdoJ+zU4xkTcay/XFSYbkdWeyCNQ1Zay8Hi S4AEbhwwhzcZ5+npDPxNQV1Su98skkP1oBz38bLyl5q4KrViuImxZhRv6uxntS5Int6v h/mMbOdEdnPF2v7rglGj2dXfEEgcIUFlIQKdSfqrlIAWI9cG/WFAQgfeswPX7choKLbx WyfCqwMyaq+EuKkgiDg1iv2KNoQM5KH/Ch9PSL5MnPSetsE1n3UB4VW7Po4OT2hlxsEB EWaA== 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=8tCTr8WWMvBgNBqYh56Canq/y8D1wo9Vrf1vFwhwvxM=; b=byQLB5KO6nJO9DT1Gw4Wcq8DWgFHXMcZKWXrJd6gSQzfG7hTD+9mh3HZlct0EtRet/ eDL9jUN4dxkv0KQmwn4hYAgWO1m0egNZU8IRlxFjKM68SK+V52wLxu25TA+ESLNXu1KV Lqg+BxKlm+Af4jD5zresJp9TvF6NNuiy2td66vWK1ksrORwh14epLa4qEUUNw3rdGLls Lo2LM+dnk+uZJJunkjqLh9MxKDKv05HOeXC6LPdX/sPuSZ6Fp4LxpkfqR/Hv8qepOz/K nRfNiCbDs69M/FRetM49FePX2pmVRCe3XfcoTY7Wf7NWD9IsqbWhSmHioszm/WGxxip5 LBvg== X-Gm-Message-State: AOUpUlFEQ9UM9JHQCCwhh5XP1iGw2fVraP5M/kEOCMgdTlOIGo1dOoCK HHy9opOEwey4mPy/QHNCMLv0LqPh X-Google-Smtp-Source: AAOMgpeDZGwwLv4qsxVQD8VVQU3TVK5td2Ixud/cw8bbR/Tp5R3j9HvrRfhUrP/qUNdvrEiyH2vPxA== X-Received: by 2002:a17:902:6ac3:: with SMTP id i3-v6mr10164882plt.252.1532288094508; Sun, 22 Jul 2018 12:34:54 -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.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 22 Jul 2018 12:34:53 -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:38 +0800 Message-Id: <20180722193350.6028-9-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:400e:c01::244 Subject: [Qemu-devel] [PATCH V10 08/20] ram/COLO: Record the dirty pages that SVM received 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 We record the address of the dirty pages that received, it will help flushing pages that cached into SVM. Here, it is a trick, we record dirty pages by re-using migration dirty bitmap. In the later patch, we will start the dirty log for SVM, just like migration, in this way, we can record both the dirty pages caused by PVM and SVM, we only flush those dirty pages from RAM cache while do checkpoint. Signed-off-by: zhanghailiang Reviewed-by: Dr. David Alan Gilbert --- migration/ram.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/migration/ram.c b/migration/ram.c index 33ebd09d70..d1060f1337 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -3325,6 +3325,15 @@ static inline void *colo_cache_from_block_offset(RAMBlock *block, __func__, block->idstr); return NULL; } + + /* + * During colo checkpoint, we need bitmap of these migrated pages. + * It help us to decide which pages in ram cache should be flushed + * into VM's RAM later. + */ + if (!test_and_set_bit(offset >> TARGET_PAGE_BITS, block->bmap)) { + ram_state->migration_dirty_pages++; + } return block->colo_cache + offset; } @@ -3555,6 +3564,24 @@ int colo_init_ram_cache(void) memcpy(block->colo_cache, block->host, block->used_length); } rcu_read_unlock(); + /* + * Record the dirty pages that sent by PVM, we use this dirty bitmap together + * with to decide which page in cache should be flushed into SVM's RAM. Here + * we use the same name 'ram_bitmap' as for migration. + */ + if (ram_bytes_total()) { + RAMBlock *block; + + QLIST_FOREACH_RCU(block, &ram_list.blocks, next) { + unsigned long pages = block->max_length >> TARGET_PAGE_BITS; + + block->bmap = bitmap_new(pages); + bitmap_set(block->bmap, 0, pages); + } + } + ram_state = g_new0(RAMState, 1); + ram_state->migration_dirty_pages = 0; + return 0; out_locked: @@ -3574,6 +3601,10 @@ void colo_release_ram_cache(void) { RAMBlock *block; + QLIST_FOREACH_RCU(block, &ram_list.blocks, next) { + g_free(block->bmap); + block->bmap = NULL; + } rcu_read_lock(); QLIST_FOREACH_RCU(block, &ram_list.blocks, next) { if (block->colo_cache) { @@ -3582,6 +3613,8 @@ void colo_release_ram_cache(void) } } rcu_read_unlock(); + g_free(ram_state); + ram_state = NULL; } /**