From patchwork Thu Jul 19 12:15:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 946241 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="CavB5tmO"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41WY745njTz9s0n for ; Thu, 19 Jul 2018 22:22:24 +1000 (AEST) Received: from localhost ([::1]:42096 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fg7ws-0006c5-Fc for incoming@patchwork.ozlabs.org; Thu, 19 Jul 2018 08:22:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35106) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fg7qs-0002Gi-Nm for qemu-devel@nongnu.org; Thu, 19 Jul 2018 08:16:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fg7qr-0005bm-Nn for qemu-devel@nongnu.org; Thu, 19 Jul 2018 08:16:10 -0400 Received: from mail-pl0-x243.google.com ([2607:f8b0:400e:c01::243]:33306) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fg7qr-0005bB-HP for qemu-devel@nongnu.org; Thu, 19 Jul 2018 08:16:09 -0400 Received: by mail-pl0-x243.google.com with SMTP id 6-v6so3585895plb.0 for ; Thu, 19 Jul 2018 05:16:09 -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=jL/6YSOrNyL/s7T74f7jW6HHfWELAyr7TPcJtMb86yk=; b=CavB5tmOx/YDEIys4RvgT2p6mAK95q4AZjp4IThQhZsu5rt5LwoRSxU2PV1fH6LojU SSS8BEL3ZmVIMn9aJKTwTxRlZlXsysFI8ELcegq2E/AZt91XQvWaBenLU2nJd/gqwlHB Spt+m2fIGmFl7P+wM4fPVvudtZFvql+W+PUw6POxciuVaEbze73vvHoL1YDwKtVQ8FNz Vn3iF6kvsuNCYtC/072s6VCfRz2Bh9ornjgiBwpblKVVHC/bj9C5WSUjllf8uZt7XOgH sV3kbIydNLrpPw8zRj2ptoWaAY/wq9k1BRLuWHTH4O39oYMbhXRb5F1qmQhDCOP5cobq GonA== 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=jL/6YSOrNyL/s7T74f7jW6HHfWELAyr7TPcJtMb86yk=; b=I2CCiT9zHEC+BQ/+plGD+UgcgkrJZn88qpbLpTfd2Tw65C1fPkJUVxIozjhibhIOJO IHOBoBqynFoMb9pNoktMTNPw92ktMTGyQJWfuGVV8IDvNlCuoN4rQoQTWkZ4NQBYJ05Q 0Cp+MHntT3Fanb8zr7nsuy3A1gpQyauk33ugfGvD3SobHxKzyUzkFbFfRd5v/QJGeVkr ek1R5PEGsWe7AdsUhdjaKEx1qtxhK72a8udZ0p5FG6XeCH0aKv8Yg6OwOQXTJ4L2b/Rs 1+5G4exDt+ky1i8ki2kPu0FzWDCa3sDdtP5Gh1ZEdnL3eqiQO4NiOYzU97jPscHhj0E+ vJPA== X-Gm-Message-State: AOUpUlHxVQHolpI3aXmPdjEnODgW3384RqSghhQyUqybvFglANQACOa/ 6gNI1VB1RqIg8p/rR/GsGkM= X-Google-Smtp-Source: AAOMgpdRFhLQGFOuDoLK8+53PHsuaQb2i3Fi4BFpHQW5AiSPV6kt5CLvtO8kvxDG1v1wa3iWFOdIEg== X-Received: by 2002:a17:902:8207:: with SMTP id x7-v6mr9787553pln.57.1532002568733; Thu, 19 Jul 2018 05:16:08 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.37]) by smtp.gmail.com with ESMTPSA id h190-v6sm21270456pge.85.2018.07.19.05.16.05 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 19 Jul 2018 05:16:08 -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: Thu, 19 Jul 2018 20:15:20 +0800 Message-Id: <20180719121520.30026-9-xiaoguangrong@tencent.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180719121520.30026-1-xiaoguangrong@tencent.com> References: <20180719121520.30026-1-xiaoguangrong@tencent.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c01::243 Subject: [Qemu-devel] [PATCH v2 8/8] 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, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/migration/ram.c b/migration/ram.c index 89305c7af5..fdab13821d 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -315,6 +315,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 */ @@ -2532,6 +2534,7 @@ static void ram_save_cleanup(void *opaque) } xbzrle_cleanup(); + flush_compressed_data(*rsp); compress_threads_save_cleanup(); ram_state_cleanup(rsp); } @@ -3203,6 +3206,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 || @@ -3235,7 +3249,6 @@ static int ram_save_iterate(QEMUFile *f, void *opaque) } i++; } - flush_compressed_data(rs); rcu_read_unlock(); /*