From patchwork Mon Sep 3 09:26:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 10585637 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 7E16D5A4 for ; Mon, 3 Sep 2018 09:28:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 795EF29121 for ; Mon, 3 Sep 2018 09:28:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6C35529135; Mon, 3 Sep 2018 09:28:07 +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=unavailable 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 242EC29121 for ; Mon, 3 Sep 2018 09:28:07 +0000 (UTC) Received: from localhost ([::1]:44252 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fwl9S-0001P5-Cw for patchwork-qemu-devel@patchwork.kernel.org; Mon, 03 Sep 2018 05:28:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39676) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fwl8M-00075U-Ji for qemu-devel@nongnu.org; Mon, 03 Sep 2018 05:26:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fwl8L-00042A-HS for qemu-devel@nongnu.org; Mon, 03 Sep 2018 05:26:58 -0400 Received: from mail-pl1-x641.google.com ([2607:f8b0:4864:20::641]:33930) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fwl8L-00041v-As for qemu-devel@nongnu.org; Mon, 03 Sep 2018 05:26:57 -0400 Received: by mail-pl1-x641.google.com with SMTP id f6-v6so8400555plo.1 for ; Mon, 03 Sep 2018 02:26:57 -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=i7/Q4JsMLeh0YBIjVpnpDZhWPuGe41yrvKr/wJ5inLI=; b=ZHAWZMkmQ+X1gSpJHiJJdNHcNmSjwuhCe4kYLn2jYqPZvGQoYeNTr6Wga9bF96nf3i JbxKOaxtOsefmml6c23/bamlOWt0d6ecSxaa5ZhGIuf3gPYxqNn5GGZsRVbyt3Vn3+AM +irwxvZpqM8MlxQt3DS3FMkcPaDa/noMisySLE5zE6qym/0GzbsvZpk1AgwqCinTP4Jr efjtM53C3vNsxrhVakbUdXhv0fL7WVT5tbWIKWt0dG0O5/YMRKo/k11ATeU6p9rhqg5S yulM22Qb8kZgwt0wY/hmoI9ePVY021Wp1ekE23BP9Fua44eHE6SLEPnF3+7HGYQCpxR2 RCvg== 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=i7/Q4JsMLeh0YBIjVpnpDZhWPuGe41yrvKr/wJ5inLI=; b=UKM9VkP+RHiXPa8WHHQVgiSOjF9XG8qq/6d7AVs+Q4MG9IQyeDGZ4PVAH64H/GOHag NgsHZp5kbA/mF9OJTWWf/vd64r9drWKEoftBM23X/2XC9s4JlyLAUth9JsMMVLkP1nS8 SYIuNH5fnJJ+hM6ecrIltC5aGvNhQMsN2MYiTjO/zJbFmHgIBmdaxWdqwVitqeG72cM4 vAfJBeO8GXTty7fba1QAiKsKytA3R7CaMf45PrlwNPP3fvco7OKAVRTzgbzq+0boiLut l04v/EFaCwn2gAd2KcwXCdy2c81aae6uMk5VM6JtashZEmw52BcUCSm3PFabR0Ym584x o9NA== X-Gm-Message-State: APzg51AbOy1q893z4NcmzVy3Pu1MxCgaXzqCjeuShPtgW1TCRelaBeNu +7dGA9iZRBJ+LQVK0E9MwIg= X-Google-Smtp-Source: ANB0VdYACEq+NN/sX1vsrzYjv1ITfYyVQCK2T23L/l+ol3pcWi2cF7JgGYywoUzu+Lhfuj0rko7lUg== X-Received: by 2002:a17:902:820a:: with SMTP id x10-v6mr27467039pln.261.1535966816510; Mon, 03 Sep 2018 02:26:56 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.40]) by smtp.gmail.com with ESMTPSA id 3-v6sm33543102pfq.10.2018.09.03.02.26.52 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 03 Sep 2018 02:26:56 -0700 (PDT) From: guangrong.xiao@gmail.com X-Google-Original-From: xiaoguangrong@tencent.com To: pbonzini@redhat.com, mst@redhat.com, mtosatti@redhat.com Date: Mon, 3 Sep 2018 17:26:41 +0800 Message-Id: <20180903092644.25812-2-xiaoguangrong@tencent.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180903092644.25812-1-xiaoguangrong@tencent.com> References: <20180903092644.25812-1-xiaoguangrong@tencent.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::641 Subject: [Qemu-devel] [PATCH v5 1/4] migration: do not flush_compressed_data at the end of each iteration 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: kvm@vger.kernel.org, quintela@redhat.com, Xiao Guangrong , qemu-devel@nongnu.org, peterx@redhat.com, dgilbert@redhat.com, wei.w.wang@intel.com, jiang.biao2@zte.com.cn Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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 79c89425a3..2ad07b5e15 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -307,6 +307,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; /* protects modification of the bitmap */ QemuMutex bitmap_mutex; /* The RAMBlock used in the last src_page_requests */ @@ -3180,6 +3182,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) { + rs->dirty_sync_count = 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 || @@ -3212,7 +3225,6 @@ static int ram_save_iterate(QEMUFile *f, void *opaque) } i++; } - flush_compressed_data(rs); rcu_read_unlock(); /*