From patchwork Mon Nov 25 12:05:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Kotov X-Patchwork-Id: 1200365 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; 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=yandex-team.ru Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=yandex-team.ru header.i=@yandex-team.ru header.b="IxEaEfA3"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47M5mg1Sytz9s7T for ; Mon, 25 Nov 2019 23:23:47 +1100 (AEDT) Received: from localhost ([::1]:42850 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iZDP6-00022O-SA for incoming@patchwork.ozlabs.org; Mon, 25 Nov 2019 07:23:44 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:59020) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iZDMF-0007OF-AB for qemu-devel@nongnu.org; Mon, 25 Nov 2019 07:20:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iZD7z-0001C9-2X for qemu-devel@nongnu.org; Mon, 25 Nov 2019 07:06:04 -0500 Received: from forwardcorp1j.mail.yandex.net ([5.45.199.163]:50542) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iZD7y-00018q-IQ for qemu-devel@nongnu.org; Mon, 25 Nov 2019 07:06:03 -0500 Received: from mxbackcorp1o.mail.yandex.net (mxbackcorp1o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::301]) by forwardcorp1j.mail.yandex.net (Yandex) with ESMTP id 7450F2E1474; Mon, 25 Nov 2019 15:05:57 +0300 (MSK) Received: from myt4-4db2488e778a.qloud-c.yandex.net (myt4-4db2488e778a.qloud-c.yandex.net [2a02:6b8:c00:884:0:640:4db2:488e]) by mxbackcorp1o.mail.yandex.net (mxbackcorp/Yandex) with ESMTP id Z1P9ohGCVf-5vR4wKeF; Mon, 25 Nov 2019 15:05:57 +0300 Precedence: bulk DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1574683557; bh=optWGQGzt93VczwH4jmudhaXP7tOdb+hmGNEbeSDRG0=; h=Message-Id:Date:Subject:To:From:Cc; b=IxEaEfA3MtIKOcRA1PHx/bO4Tok4kcH/MQIEFjVdCN+DJRjmNAyraC3oN9Zw6CYgL uFz/J28TzCXUY5+XeSF16jgZ6CaIecfV8BJ9fjw1HP4Bewg357OlEZbuO9VV7UOGX4 jvsExCkBA18arRHXC/RQ9u6U400VgbN0f/DVl8iw= Authentication-Results: mxbackcorp1o.mail.yandex.net; dkim=pass header.i=@yandex-team.ru Received: from dynamic-red.dhcp.yndx.net (dynamic-red.dhcp.yndx.net [2a02:6b8:0:408:bc57:f91d:ee50:9634]) by myt4-4db2488e778a.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id za0yjLhNnN-5vWa3H5x; Mon, 25 Nov 2019 15:05:57 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) From: Yury Kotov To: qemu-devel@nongnu.org (open list:All patches CC here) Subject: [PATCH] migration/ram: Yield periodically to the main loop Date: Mon, 25 Nov 2019 15:05:48 +0300 Message-Id: <20191125120548.13589-1-yury-kotov@yandex-team.ru> X-Mailer: git-send-email 2.24.0 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 5.45.199.163 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Dr. David Alan Gilbert" , yc-core@yandex-team.ru, Juan Quintela Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Usually, incoming migration coroutine yields to the main loop when it's IO-channel waits for data to receive. But there is a case when RAM migration and data receive have the same speed: VM with huge zeroed RAM. In this case, IO-channel won't read and thus the main loop is stuck and for example, it doesn't respond to QMP commands. For this case, yield periodically, but not too often, so as not to affect the speed of migration. Signed-off-by: Yury Kotov --- migration/ram.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/migration/ram.c b/migration/ram.c index 5078f94490..fed6ef4b22 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -4227,7 +4227,7 @@ static void colo_flush_ram_cache(void) */ static int ram_load_precopy(QEMUFile *f) { - int flags = 0, ret = 0, invalid_flags = 0, len = 0; + int flags = 0, ret = 0, invalid_flags = 0, len = 0, i = 0; /* ADVISE is earlier, it shows the source has the postcopy capability on */ bool postcopy_advised = postcopy_is_advised(); if (!migrate_use_compression()) { @@ -4239,6 +4239,17 @@ static int ram_load_precopy(QEMUFile *f) void *host = NULL; uint8_t ch; + /* + * Yield periodically to let main loop run, but an iteration of + * the main loop is expensive, so do it each some iterations + */ + if ((i & 32767) == 0) { + aio_co_schedule(qemu_get_current_aio_context(), + qemu_coroutine_self()); + qemu_coroutine_yield(); + } + i++; + addr = qemu_get_be64(f); flags = addr & ~TARGET_PAGE_MASK; addr &= TARGET_PAGE_MASK;