From patchwork Wed Jun 27 20:41:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Chen X-Patchwork-Id: 10492623 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 A38F4601A0 for ; Wed, 27 Jun 2018 20:47:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A8F5829FDD for ; Wed, 27 Jun 2018 20:47:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9C87929FE4; Wed, 27 Jun 2018 20:47:04 +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 1E13C29FDD for ; Wed, 27 Jun 2018 20:47:04 +0000 (UTC) Received: from localhost ([::1]:33122 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYHLD-0007Qd-A1 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 27 Jun 2018 16:47:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49514) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYHGp-0003vc-IE for qemu-devel@nongnu.org; Wed, 27 Jun 2018 16:42:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYHGo-0006Az-IO for qemu-devel@nongnu.org; Wed, 27 Jun 2018 16:42:31 -0400 Received: from mail-pl0-x244.google.com ([2607:f8b0:400e:c01::244]:41162) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fYHGo-0006A2-Bb for qemu-devel@nongnu.org; Wed, 27 Jun 2018 16:42:30 -0400 Received: by mail-pl0-x244.google.com with SMTP id w8-v6so1594783ply.8 for ; Wed, 27 Jun 2018 13:42:30 -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=BlmXYOMD7aS9b5gmx01wGSp+AEPIzdhdvfz8COXFZ6I=; b=HMDFTf1+hoU/JboktfQ+Ub5PDmGu+X1C2ifTCmjCErvWIC4E+0OpW8xaY8H0CRSPM2 ze9t3lh48u1z8KZasfuW6LUCRwapHEv4rM3FyPuEpKYirkMZj87/EN4Z4SNNoTsIsDA7 pMOy9Pq4ZyrxQ0fvhA2PThAFLcxN3+LCdzFD7oe78+FQ0ufBnFo8ucoayyRM0RIORhL7 Su43qDDTOpk+lM1r5qDt7MprVh0CtEmFK3nZBizT20FhIcjBqIoKPt/wsaSAxzJxHJZA u70en4sUw2e5ntNCXfVoiWW7KYjBlyfszJqyZTZjbbrztSVerQmnioCvw1QnXEMGYKVT OKmQ== 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=BlmXYOMD7aS9b5gmx01wGSp+AEPIzdhdvfz8COXFZ6I=; b=PeijHQVzmrVjF/aJHsVk28UnCJF4v5cHFS4dBtfJw+mQXta6yEydzgTa3iEhCgtqQS oQqKDzHkUjMXTsG069lVBp/EvybgsHgK2VcZWOdMtUxIhh4sQ3sB7QFSFolbOl2DCIhl ssiwi9qaNjhWXW/3J8SQje2yTi7fxkLu8WI9KmfFGjUKga4RxRn5phoUdwH/3cqa62sc A6b74CVbRWM032/2P7EQ6WChwrl1SlJ1k8Bz9LznaNCarZzN/gVVkCQHWlKSynzidGVU vMc9C0olozlxGqPlgeXEgsMxRDwgTc11ZB64PXPVRYzNNrUoXF2KNtMRrdeAjxOzDSsi 2RTA== X-Gm-Message-State: APt69E2FzH3gOwIcMBGneShDAtlVmPLE5bsbG0iJbENq6B6nyfZMfNEV 3qb1jjSK9cMEP9X498ukhgiU6A== X-Google-Smtp-Source: ADUXVKJJCsMfl6mlout0KSUc/L8nqpH6kUAjD6h5OmK4F7+VWVHFPThNkhqD3GrY7LN3EaABZ6k+gg== X-Received: by 2002:a17:902:8f94:: with SMTP id z20-v6mr7527052plo.337.1530132149095; Wed, 27 Jun 2018 13:42:29 -0700 (PDT) Received: from localhost.localdomain (155.150.229.35.bc.googleusercontent.com. [35.229.150.155]) by smtp.gmail.com with ESMTPSA id c67-v6sm9690428pfj.173.2018.06.27.13.42.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Jun 2018 13:42:28 -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: Thu, 28 Jun 2018 04:41:24 +0800 Message-Id: <20180627204136.4177-9-zhangckid@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180627204136.4177-1-zhangckid@gmail.com> References: <20180627204136.4177-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 V9 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 30cc83996f..ecc5f46068 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -2869,6 +2869,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; } @@ -3099,6 +3108,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: @@ -3118,6 +3145,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) { @@ -3126,6 +3157,8 @@ void colo_release_ram_cache(void) } } rcu_read_unlock(); + g_free(ram_state); + ram_state = NULL; } /**