From patchwork Thu Jan 4 06:01:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Chen X-Patchwork-Id: 10143901 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 726CF6034B for ; Thu, 4 Jan 2018 06:10:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5C57A201CB for ; Thu, 4 Jan 2018 06:10:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4FE4420572; Thu, 4 Jan 2018 06:10: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=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, 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 E9BBE201CB for ; Thu, 4 Jan 2018 06:10:33 +0000 (UTC) Received: from localhost ([::1]:47501 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eWyjZ-0003Eb-60 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 04 Jan 2018 01:10:33 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36920) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eWybS-0003ji-OG for qemu-devel@nongnu.org; Thu, 04 Jan 2018 01:02:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eWybR-0004EI-Uf for qemu-devel@nongnu.org; Thu, 04 Jan 2018 01:02:10 -0500 Received: from mail-pg0-x242.google.com ([2607:f8b0:400e:c05::242]:41971) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eWybR-0004Da-PP for qemu-devel@nongnu.org; Thu, 04 Jan 2018 01:02:09 -0500 Received: by mail-pg0-x242.google.com with SMTP id 77so337610pgd.8 for ; Wed, 03 Jan 2018 22:02:09 -0800 (PST) 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=1O7DhA3M1mLMMkTBL0M4sTQjX2JumqYNE/EWLuud8p8=; b=VIKTnYpMdXbPvF5kmt4Eop+gQTDWrAssXEFI0cUYuLu84P1G/sgZSZtYYGYMzXYBA4 SbYsfNIWE/HdPby6uV/5eBHhsRuUGWEHdCDBdjkq1U2Y4ZIzbVD1/Gu7E9epNyPxbGTX DFeTXPcoxdg0zTXTLbaAqc5IxuS+EWNLMQwsTVBko3gu4c1C47xi1OKJ8LqbMB5NpL1P snOXC6qb7ao9kLZEX6KhKLqmZaPACt1bKRhZEtvXiLMsG+XgVyOiT9El/k8C7dL8IV6i OsP8rX+VE/MjnvrUY2/7eigDhe9sUOMMQ8CWmn7htyCI6JtWYHk3jfcvRlftjKJ4BwpG LjCQ== 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=1O7DhA3M1mLMMkTBL0M4sTQjX2JumqYNE/EWLuud8p8=; b=RKbUrUE5A0bPh0HKhZQKssuAjkQMX2Ikwbx/zyZbGLF/DQgnQrqnyOQDzWdufjRqK6 s+f3t5LyuhlnCyIXs7XkVakjNaC5XO5wBdsHH4YH/YH8NWfwcfeOn5wb2pTLRWGeHkBR WTkm+TLl9Cedvvz0aO3WmKUP+O6xhNlnGspI4+jWZhkbFQUd2VZpj14LfpR+WdautwY7 7xcjyg+5mdVXZyu4bjCFoqtavyWuiyZZ0wIc+qt16WRBVNp3BgH8Ao2OG3oy/wfOa1DB RMiUBBNJEWhKIAyHtVua6Z1dkoQ6kAPjxnQPH0Fdazn2ePcWQtrsJRbcQCHOiZ8d1UPS zMIg== X-Gm-Message-State: AKGB3mJ60gup9hYpEbZvHSeQu+krStKWNR8w1PoPFd4LTJcCOIYHjch9 6lVaSX83oxd/9sge93NdIRb2pyUu X-Google-Smtp-Source: ACJfBovehN5VRDnkJUgNMEr86awtLEpQxRO77xfurCibx19JgdupVo9cjiF0IR1zjHZT0qsjgd3mLQ== X-Received: by 10.98.224.200 with SMTP id d69mr3770578pfm.100.1515045728417; Wed, 03 Jan 2018 22:02:08 -0800 (PST) Received: from localhost.localdomain (120.236.201.35.bc.googleusercontent.com. [35.201.236.120]) by smtp.gmail.com with ESMTPSA id w5sm6214775pfi.74.2018.01.03.22.02.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 03 Jan 2018 22:02:07 -0800 (PST) From: Zhang Chen To: qemu devel Date: Thu, 4 Jan 2018 14:01:07 +0800 Message-Id: <1515045675-6993-9-git-send-email-zhangckid@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1515045675-6993-1-git-send-email-zhangckid@gmail.com> References: <1515045675-6993-1-git-send-email-zhangckid@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::242 Subject: [Qemu-devel] [PATCH RESEND V3 08/16] 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: Juan Quintela , zhanghailiang , 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. Cc: Juan Quintela 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 0fc0aee..388333d 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -2477,6 +2477,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; } @@ -2653,6 +2662,24 @@ int colo_init_ram_cache(void) } } 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: @@ -2672,6 +2699,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) { @@ -2680,6 +2711,8 @@ void colo_release_ram_cache(void) } } rcu_read_unlock(); + g_free(ram_state); + ram_state = NULL; } /**