From nobody Sat Nov 23 20:30:34 2024 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=fail(p=none dis=none) header.from=smartx.com ARC-Seal: i=1; a=rsa-sha256; t=1730973443; cv=none; d=zohomail.com; s=zohoarc; b=LJnRtI4RuKAk2Sbap+STc5svM7mo53ysPZhrsO0UGPqkE/kJesaD1inpOVFzKll7tGXEuNJ2rSO1PVEEOGOIFlarBAWnVPzJMCcaSrYmNhzxZ+gJ+86nQ+KQgaF7GUgwLhO3XoBjHQ01FF1gA2+RWXHQl+9/XI/f5VniR1Og93g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730973443; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=EoaV+03QvTu6WP8sJ+9r3MumZMCi97oZx93fGFaJShw=; b=YGXlXsLMslqjTl2yt2kxzzQeqkO5uoBoiAHNk+2nu1HsoP/TeL8CYt3BqeGM7Jjxq6HJEKeF+bLSiVviGgaOOaHgspl+bJ7ZlXSW3FhDyk/DiHM/NHUnWcbrf2f4kKf/CWSO+2fYrrWxG9UkCXROAmX7IJQ4BI4yRpSsv89c9Es= 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=fail 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 1730973443297220.23887203736854; Thu, 7 Nov 2024 01:57:23 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8zGJ-00080H-3u; Thu, 07 Nov 2024 04:57:11 -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 1t8zGG-0007zm-8R for qemu-devel@nongnu.org; Thu, 07 Nov 2024 04:57:08 -0500 Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t8zGD-0005EH-Sl for qemu-devel@nongnu.org; Thu, 07 Nov 2024 04:57:08 -0500 Received: by mail-pj1-x1036.google.com with SMTP id 98e67ed59e1d1-2e2a999b287so626752a91.0 for ; Thu, 07 Nov 2024 01:57:04 -0800 (PST) Received: from Hyman-Dev-Euler.zelin.local ([103.172.41.205]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e9a5f90ce5sm1149970a91.31.2024.11.07.01.57.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2024 01:57:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20230601.gappssmtp.com; s=20230601; t=1730973423; x=1731578223; darn=nongnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=EoaV+03QvTu6WP8sJ+9r3MumZMCi97oZx93fGFaJShw=; b=1AUiaDs/tQAJ8Son0JkL9DYhfWhUKNtDN5OrGlVheSfP4+GbxdqDQDHjI1b2xarQ57 25Fb8Q4pn3cpTv9ND+yZ+V3E0anz8YXHGF7L4oApY9H7wFRmM8zTYdpnYGgnX0JAJOle eN0K+XXNg6I4j96ssVfJY8m7MayJLinEVetGGc6d67eh94AEGxVkh55qlb1mzIprzMXt G/VrNWYO+QTwCxw4SqSbJC4NSP1l6pLwv+jwgJHM/PVslwZBWK6wdeMhY31U6FyaDwAM 0IT6huvFAlTkkIgH3lg8Cd1SoEVDrPRCO+aWC3a/cohSaqwPtZRLeUp6y7+HCnWizYHU 3DTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730973423; x=1731578223; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=EoaV+03QvTu6WP8sJ+9r3MumZMCi97oZx93fGFaJShw=; b=n3bkgV84Rth/714hLR1RIIc26BOt+338RJxjkcJM7RPpJLJnPcl5Dvmb6W9lCzBuHf 6shd0f+XC4Po8Wabwjl4mmrerq5prxH9bqy0slH25Xn5Gl5Ymxij+rH807uBbNRtRJKL C3nqV97k4iQRvpz3VypmeKqviYYJr2rwpyN3DH8UvY76rTF+TQSF1kRlRYsjbvYVQBSV OGgl+KlrLM1iiCVw6LRvI9bIUSlpRZz1D/4jsde3io7a1DnR0phLvcEA/wFbvAK+XqGc M9F7feR8vBLIajsPgl5a4aZ0IMkDfpw4rIRYYt8+jjeo3xmLN0nWY00S3WyXfzrUrC1m iUDA== X-Gm-Message-State: AOJu0YxNaNR9jc8e5X/RCZkhmfmvbqbieYpDy9JGLPjsuphN/eNFDprt r25ZOe/faH3V3ocF1AKGqkcaIsROGnoSaN4ZBKFN/NdNvoRwAIf4HMb+fll6FXhCw+kpy5f1Myo 4BrA4lw== X-Google-Smtp-Source: AGHT+IFnPCZO6vrC51dB1DA6HPA/QkpcwZ6sjGT93+j3ZIva4m6euqSQqdZhMyVBO58iCFp1m4Y7+Q== X-Received: by 2002:a17:90b:5444:b0:2e2:8995:dd1b with SMTP id 98e67ed59e1d1-2e9aaff9a68mr529532a91.3.1730973422311; Thu, 07 Nov 2024 01:57:02 -0800 (PST) From: yong.huang@smartx.com To: qemu-devel@nongnu.org Cc: Peter Xu , Fabiano Rosas , yong.huang@smartx.com Subject: [PATCH] migration: Do not perform RAMBlock dirty sync during the first iteration Date: Thu, 7 Nov 2024 17:56:50 +0800 Message-Id: X-Mailer: git-send-email 2.27.0 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=2607:f8b0:4864:20::1036; envelope-from=yong.huang@smartx.com; helo=mail-pj1-x1036.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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 @smartx-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1730973445711116600 Content-Type: text/plain; charset="utf-8" From: Hyman Huang The first iteration's RAMBlock dirty sync can be omitted because QEMU always initializes the RAMBlock's bmap to all 1s by default. Signed-off-by: Hyman Huang --- migration/cpu-throttle.c | 2 +- migration/ram.c | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/migration/cpu-throttle.c b/migration/cpu-throttle.c index 5179019e33..674dc2004e 100644 --- a/migration/cpu-throttle.c +++ b/migration/cpu-throttle.c @@ -141,7 +141,7 @@ void cpu_throttle_dirty_sync_timer_tick(void *opaque) * effect on guest performance, therefore omit it to avoid * paying extra for the sync penalty. */ - if (sync_cnt <=3D 1) { + if (!sync_cnt) { goto end; } =20 diff --git a/migration/ram.c b/migration/ram.c index 05ff9eb328..a0123eb93e 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -2718,7 +2718,7 @@ static void ram_list_init_bitmaps(void) { MigrationState *ms =3D migrate_get_current(); RAMBlock *block; - unsigned long pages; + unsigned long pages, clear_bmap_pages; uint8_t shift; =20 /* Skip setting bitmap if there is no RAM */ @@ -2736,6 +2736,7 @@ static void ram_list_init_bitmaps(void) =20 RAMBLOCK_FOREACH_NOT_IGNORED(block) { pages =3D block->max_length >> TARGET_PAGE_BITS; + clear_bmap_pages =3D clear_bmap_size(pages, shift); /* * The initial dirty bitmap for migration must be set with all * ones to make sure we'll migrate every guest RAM page to @@ -2751,7 +2752,12 @@ static void ram_list_init_bitmaps(void) block->file_bmap =3D bitmap_new(pages); } block->clear_bmap_shift =3D shift; - block->clear_bmap =3D bitmap_new(clear_bmap_size(pages, shift)= ); + block->clear_bmap =3D bitmap_new(clear_bmap_pages); + /* + * Set clear_bmap to 1 unconditionally, as we always set bmap + * to all 1s by default. + */ + bitmap_set(block->clear_bmap, 0, clear_bmap_pages); } } } @@ -2771,6 +2777,7 @@ static void migration_bitmap_clear_discarded_pages(RA= MState *rs) =20 static bool ram_init_bitmaps(RAMState *rs, Error **errp) { + Error *local_err =3D NULL; bool ret =3D true; =20 qemu_mutex_lock_ramlist(); @@ -2783,7 +2790,13 @@ static bool ram_init_bitmaps(RAMState *rs, Error **e= rrp) if (!ret) { goto out_unlock; } - migration_bitmap_sync_precopy(false); + /* + * Bypass the RAMBlock dirty sync and still publish the + * notification. + */ + if (precopy_notify(PRECOPY_NOTIFY_AFTER_BITMAP_SYNC, &local_er= r)) { + error_report_err(local_err); + } } } out_unlock: --=20 2.27.0