From nobody Sun Apr 6 22:06:31 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1736896128; cv=none; d=zohomail.com; s=zohoarc; b=nnL/R76fyYsXCC2f/SKNNbkwepcs9cqSp/tlzoG1zynGC3LKvoSyoHF1EUbNMHmjhUfmJyiPcA2Ijo9cQy+mHZL97t79gTTP9krZhkafEpJJ87f9tD+jDqRVTj0G7hlh5GipuZglBEIPYLjyb2fQR+e1NaYYphT5ukTpW2oFDPE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1736896128; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=enSH5rlxcTb/KVObjDkc8rdqQsMxW2lwvt88NiL40BA=; b=FMIk42ZdQcBJimUySNb9digFipqi3oXEmvCc/YJ558CO8SeNzWzzIw0dd1Qw6yAy0TWgjS1gAeJXFj3657JQw17XYaYvCQli4UHuVtij/B0eeTEBJ7deRVmFeyVIY/eKckB7sB+XwZk0Vb8CqGAd1xLYM91HSVXz0efngIIze0c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1736896128534180.35710623703596; Tue, 14 Jan 2025 15:08:48 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tXq0x-0001rI-Ks; Tue, 14 Jan 2025 18:08:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tXq0w-0001qo-2K for qemu-devel@nongnu.org; Tue, 14 Jan 2025 18:08:02 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tXq0u-00043U-J0 for qemu-devel@nongnu.org; Tue, 14 Jan 2025 18:08:01 -0500 Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-207-mSHRlySrNpWY4uCGChMGjQ-1; Tue, 14 Jan 2025 18:07:56 -0500 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-46c83bc370bso5734481cf.0 for ; Tue, 14 Jan 2025 15:07:56 -0800 (PST) Received: from x1n.redhat.com (pool-99-254-114-190.cpe.net.cable.rogers.com. [99.254.114.190]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-46c873cd1b0sm59268971cf.49.2025.01.14.15.07.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2025 15:07:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736896079; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=enSH5rlxcTb/KVObjDkc8rdqQsMxW2lwvt88NiL40BA=; b=GAcoavBNhXWu+QhAEk3OA8U+KU0Oil0CyIkPDkmXnM2jfneo3n51NKsUc0RAGXNly17ZBb lH3JjyBSrC2WK+RfzcBXGiukww90hyl5j2Sb0M9xF3tH6I00xIvBVcy+NdqAAh2gX3/QFw wUPiB+nw40h4S6nfRCCizAEfeTQgsHs= X-MC-Unique: mSHRlySrNpWY4uCGChMGjQ-1 X-Mimecast-MFC-AGG-ID: mSHRlySrNpWY4uCGChMGjQ X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736896075; x=1737500875; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=enSH5rlxcTb/KVObjDkc8rdqQsMxW2lwvt88NiL40BA=; b=eJ4hrB0mkkSvDiNr9PeOTxN/sgDZ5UZLFH0bGZV5c3uBDvg4NY0zrgnnD0RYAlPvxB S6wFILW9ICaraf0AOByTVZxP2VdzLjnWKmt6N8NxyP9Zt6G+pPuyQwENorqQLxy8JArb 9dbyrNpGU8iiJafISRNw4GcPvWHk8/UBnTvHeu2d3aKrblzkFQ1n/27qqtZ9P7IsdTMi 2TZuJTW7X3y2+3K0PcAFh1G19fdqI6/wp53xqMMhRLu0JToM1yXl5Z44rnFuJsB+0nGh VrFh86+PWc8BTreeVZgIKLZAQBwmrMAI+JCpPWC0GDaNTVEU6YccwKLOEOFPnGp5FPWM Inxg== X-Gm-Message-State: AOJu0YwW04rEHCpyz1Q3zTq3bDGC0RP9ITI5T963OG+vN27kAiYI1GXb JHHj99Nc5NLfJ8bTa5JatCb4JLrPzT8HI1iYSBjzEPYO3VReHklP6DT2WdzSygri55JpGMaEUyz 9RGf82Tpn+gmKgB1L2bduxq5cmtUXGkldjt5Ve6lFICY0bC6ckJRkkwD8LbRMe26x0lNaEC7V84 3ATE9Af2QXQs2zcO0AmIc2+TnRF+bhNqkFcg== X-Gm-Gg: ASbGncuk/2NyA6xZ7V9jc8d7XgO/rypddPq1mu/d3KjeRqo2G+mCpsiaf3gqsJP00x0 BR8YLv8FklZCg7GSIQxRkPT23PvGFy4Xw9jrrFtzYjXdsu6OWb15zcMJBdOWDkVQwzEMdKCdlKz Gp3+IysS+/FsZrnm/eA3bTh8q5lM5ILgbErsCvdAOrbnWlwHF0HOAHx/a/kifKRc/X/rFJfbeh1 5boaMODwHt8z3MvUjdsmlMH91sR6Oz1vjxyhIoTBVHXo/C+2FfyvUqXZJeR2uH6Chkpy0zPf8tn TuUv+YAdYsuX6tsHdiw4221/3UQMBPl9 X-Received: by 2002:a05:622a:5a07:b0:467:85f9:2a6c with SMTP id d75a77b69052e-46df569e6f0mr14053131cf.10.1736896074904; Tue, 14 Jan 2025 15:07:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IH6CnqlXk+V6YEg6yK9um5/g0qtpiIkDWbqOmkTL2DWXP+7th4OYi4UEewIWCI4VCGYIcO3MQ== X-Received: by 2002:a05:622a:5a07:b0:467:85f9:2a6c with SMTP id d75a77b69052e-46df569e6f0mr14052811cf.10.1736896074572; Tue, 14 Jan 2025 15:07:54 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Cc: peterx@redhat.com, Juraj Marcin , Julia Suvorova , Prasad Pandit , Fabiano Rosas Subject: [PATCH 03/16] migration: Optimize postcopy on downtime by avoiding JSON writer Date: Tue, 14 Jan 2025 18:07:33 -0500 Message-ID: <20250114230746.3268797-4-peterx@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250114230746.3268797-1-peterx@redhat.com> References: <20250114230746.3268797-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.063, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1736896130922019000 Content-Type: text/plain; charset="utf-8" postcopy_start() is the entry function that postcopy is destined to start. It also means QEMU source will not dump VM description, aka, the JSON writer is garbage now. We can leave that to be cleaned up when migration completes, however when with the JSON writer object being present, vmstate_save() will still try to construct the JSON objects for the VM descriptions, even though it'll never be used later if it's postcopy. To save those cycles, release the JSON writer earlier for postcopy. Then vmstate_save() later will be smart enough to skip the JSON object constructions completely. It can logically reduce downtime because all such JSON constructions happen during postcopy blackout. Signed-off-by: Peter Xu --- migration/migration.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index bad7b39293..0eb28e850d 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1397,6 +1397,11 @@ void migrate_set_state(MigrationStatus *state, Migra= tionStatus old_state, } } =20 +static void migration_cleanup_json_writer(MigrationState *s) +{ + g_clear_pointer(&s->vmdesc, json_writer_free); +} + static void migrate_fd_cleanup(MigrationState *s) { MigrationEventType type; @@ -1404,11 +1409,11 @@ static void migrate_fd_cleanup(MigrationState *s) =20 trace_migrate_fd_cleanup(); =20 + migration_cleanup_json_writer(s); + g_free(s->hostname); s->hostname =3D NULL; =20 - g_clear_pointer(&s->vmdesc, json_writer_free); - qemu_savevm_state_cleanup(); =20 close_return_path_on_source(s); @@ -2501,6 +2506,14 @@ static int postcopy_start(MigrationState *ms, Error = **errp) uint64_t bandwidth =3D migrate_max_postcopy_bandwidth(); int cur_state =3D MIGRATION_STATUS_ACTIVE; =20 + /* + * Now we're 100% sure to switch to postcopy, so JSON writer won't be + * useful anymore. Free the resources early if it is there. Clearing + * the vmdesc also means any follow up vmstate_save()s will start to + * skip all JSON operations, which can shrink postcopy downtime. + */ + migration_cleanup_json_writer(ms); + if (migrate_postcopy_preempt()) { migration_wait_main_channel(ms); if (postcopy_preempt_establish_channel(ms)) { --=20 2.47.0