From patchwork Tue Aug 7 09:12:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 10558425 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 A56C113B4 for ; Tue, 7 Aug 2018 09:13:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8E9A326538 for ; Tue, 7 Aug 2018 09:13:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 81C1627F3E; Tue, 7 Aug 2018 09:13:05 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DB7BA26538 for ; Tue, 7 Aug 2018 09:13:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733213AbeHGL00 (ORCPT ); Tue, 7 Aug 2018 07:26:26 -0400 Received: from mail-pl0-f65.google.com ([209.85.160.65]:40541 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726879AbeHGL00 (ORCPT ); Tue, 7 Aug 2018 07:26:26 -0400 Received: by mail-pl0-f65.google.com with SMTP id s17-v6so6853746plp.7 for ; Tue, 07 Aug 2018 02:13:02 -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=76tOyzDvpxGSakJHlQHhrtxXZY1tzQpvddPPuUF4ip0=; b=L3XH1/V3Es7+EMlTxYDHiSCvgHKOWPAycSHPtnfRxQy4z0Z7hWRj1Y9pPz5Yj6L3fs V2mSeDWHP9c6kBI+2QLrSfMdPoM0pNC4bBDyY5wAlp2vmzRGB/Ur3hkg/k06p7/ahX9a Ih3xSMD7aOcl/XOgR57YF6rk3KUixGVGUI7npaGmQrEJoayIOkPUTeTNp1Ba+IqVufWt 9MT1kPsiJp+mp2fr+9tsvh+Aat28fvNeppPvyY9AquJkJiG1OVyEyPYKWeQY+gY2qiLA 2+2ui/T2ccs4nZ5iVXAqhr5LM0iSHirdQL/TVCwrdSJUO2Qsx4Vbd9DR5jZuHJftkx/y IFwg== 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=76tOyzDvpxGSakJHlQHhrtxXZY1tzQpvddPPuUF4ip0=; b=CgIH/eBC27yujbUdDhyN/4lMDs7MqvE2GEnQ/Jez/EjDqs6uI6RJyQFShTDUOO/Sgx cFWUidigFFccIArig2aTOxa6TJv57xM3DaPvJiE6b8Q3jnbLeukOdakN+U0/0xLs06Y4 13xRuVa95iS+Ciy+trLgf2gPM27fAjhKoA1oSsNA+7Q0Ki9iFBwaYmRCht6i47ZzDNv7 AaFNwCbmzMI+u3ZdY5/vAdGjsQrCo9/zpAQmMEbpYQZTycfThSvoTwgRDBYuTv23PlCh Kifjjay/Wxm/6sFc1p35IZN5c7cCG+QgdMSBt+hfKk1LuWcHvLdJH85SLxiynbNmR6Xy BnHA== X-Gm-Message-State: AOUpUlH7hEkBcHLoDFKHwFgjy5raPfsub7G2M45BD54683JYjI5mV6yw 5kRgUW2QleCIi/hBD/pNIWU= X-Google-Smtp-Source: AAOMgpd8K/2MS+uzOpqbpCHBaz/3O8ujDk75E3kgluPzez3jJr/LI1qzm9VDt/DFQyy0cb5sPJs5zw== X-Received: by 2002:a17:902:1a2:: with SMTP id b31-v6mr16760276plb.279.1533633182658; Tue, 07 Aug 2018 02:13:02 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.37]) by smtp.gmail.com with ESMTPSA id z4-v6sm2159645pfl.11.2018.08.07.02.12.58 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 07 Aug 2018 02:13:02 -0700 (PDT) From: guangrong.xiao@gmail.com X-Google-Original-From: xiaoguangrong@tencent.com To: pbonzini@redhat.com, mst@redhat.com, mtosatti@redhat.com Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, dgilbert@redhat.com, peterx@redhat.com, wei.w.wang@intel.com, jiang.biao2@zte.com.cn, eblake@redhat.com, Xiao Guangrong Subject: [PATCH v3 07/10] migration: do not flush_compressed_data at the end of each iteration Date: Tue, 7 Aug 2018 17:12:06 +0800 Message-Id: <20180807091209.13531-8-xiaoguangrong@tencent.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180807091209.13531-1-xiaoguangrong@tencent.com> References: <20180807091209.13531-1-xiaoguangrong@tencent.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Xiao Guangrong flush_compressed_data() needs to wait all compression threads to finish their work, after that all threads are free until the migration feeds new request to them, reducing its call can improve the throughput and use CPU resource more effectively We do not need to flush all threads at the end of iteration, the data can be kept locally until the memory block is changed or memory migration starts over in that case we will meet a dirtied page which may still exists in compression threads's ring Signed-off-by: Xiao Guangrong --- migration/ram.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/migration/ram.c b/migration/ram.c index 99ecf9b315..55966bc2c1 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -306,6 +306,8 @@ struct RAMState { uint64_t iterations; /* number of dirty bits in the bitmap */ uint64_t migration_dirty_pages; + /* last dirty_sync_count we have seen */ + uint64_t dirty_sync_count_prev; /* protects modification of the bitmap */ QemuMutex bitmap_mutex; /* The RAMBlock used in the last src_page_requests */ @@ -3173,6 +3175,17 @@ static int ram_save_iterate(QEMUFile *f, void *opaque) ram_control_before_iterate(f, RAM_CONTROL_ROUND); + /* + * if memory migration starts over, we will meet a dirtied page which + * may still exists in compression threads's ring, so we should flush + * the compressed data to make sure the new page is not overwritten by + * the old one in the destination. + */ + if (ram_counters.dirty_sync_count != rs->dirty_sync_count_prev) { + rs->dirty_sync_count_prev = ram_counters.dirty_sync_count; + flush_compressed_data(rs); + } + t0 = qemu_clock_get_ns(QEMU_CLOCK_REALTIME); i = 0; while ((ret = qemu_file_rate_limit(f)) == 0 || @@ -3205,7 +3218,6 @@ static int ram_save_iterate(QEMUFile *f, void *opaque) } i++; } - flush_compressed_data(rs); rcu_read_unlock(); /*