From nobody Mon Dec 15 22:58:28 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=quarantine dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1765195887; cv=none; d=zohomail.com; s=zohoarc; b=ep1fmfEypuD0flx5Rjq7MHpKG8FEhwg9Mj6O09GtK1TmifAT2E6bZ7tod6xqt9GTN3Ckd4e8cuResq6OrggngIO8V2Tc32tZl2nAy7HCuSEgP4pLQ4ZmrZm5ye7Vc+xT/Y3v0gSyJ4ekr3+vYd8yGlur+MmzzkwFl4bJABvOn3s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765195887; h=Content-Type: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=9fivGahwD7eJxbsYIpWsK5p26Hc0D9+NFC1zD62ElmQ=; b=mJuavF5unlyzIk8QdyjPfO1PNPANDJ01Ib3KU5d5V6YKOVgz/zMxsCS3/9SG7gLhqQ4F6VjRhBjhbBZj/wFAREBDRnqSsWnmqHVQe8eNfquwBNjqboi/DeO9b5RtQ9BKyZ4lysf9pJBwSCFIlyQIv+d/JL7H1zHwAmbs7yDd3k8= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1765195887366746.1816178871329; Mon, 8 Dec 2025 04:11:27 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vSa4y-0007Bf-5q; Mon, 08 Dec 2025 07:11:00 -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 1vSa4l-000720-3I for qemu-devel@nongnu.org; Mon, 08 Dec 2025 07:10:49 -0500 Received: from sg-1-101.ptr.blmpb.com ([118.26.132.101]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vSa4i-0003Ro-OG for qemu-devel@nongnu.org; Mon, 08 Dec 2025 07:10:46 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=2212171451; d=bytedance.com; t=1765195828; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=9fivGahwD7eJxbsYIpWsK5p26Hc0D9+NFC1zD62ElmQ=; b=CTregnjBbwjlmEvmTq4Ce10OHaHdkqN69DaHkoramvpKD1jicjkaqqDeMz20XxpVaP9s31 iWxN1HmJg8xhuexP+5LxG9H3pNtJMsrge+ZxLBlzcLMeOp/ngIzGKXLFavlpNPqBxwu3Z5 wMdnVKYPx4YckQKMcrkwWYrVu6qJ664eQ7T4hfUjpWOzZbuimotizW2ynDVn1G2VzvXwk5 H8/D7JbP0lv7tmF/NFV9p1C2+v7Hw1KresIu/rFF3XvVrggJXLSPctMeEPiIb2/4VjPbgO v/tNLdh0OdBf9w5aWdTIHmLGtziVfALvZzU4zXUNcnNcrrIWY2GmIdWCWtoP4Q== From: "Chuang Xu" Subject: [RFC v1 1/2] vhost: eliminate duplicate dirty_bitmap sync when log shared by multiple devices Content-Transfer-Encoding: quoted-printable X-Original-From: Chuang Xu X-Lms-Return-Path: Cc: , , , , , , , , "xuchuangxclwt" References: <20251208120952.37563-1-xuchuangxclwt@bytedance.com> Date: Mon, 8 Dec 2025 20:09:51 +0800 Mime-Version: 1.0 X-Mailer: git-send-email 2.39.3 (Apple Git-146) To: Message-Id: <20251208120952.37563-2-xuchuangxclwt@bytedance.com> In-Reply-To: <20251208120952.37563-1-xuchuangxclwt@bytedance.com> 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=118.26.132.101; envelope-from=xuchuangxclwt@bytedance.com; helo=sg-1-101.ptr.blmpb.com X-Spam_score_int: -15 X-Spam_score: -1.6 X-Spam_bar: - X-Spam_report: (-1.6 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FROM_LOCAL_NOVOWEL=0.5, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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 @bytedance.com) X-ZM-MESSAGEID: 1765195890344158500 Content-Type: text/plain; charset="utf-8" From: xuchuangxclwt Although logs can now be shared among multiple vhost devices, live migration still performs repeated vhost_log_sync for each vhost device during bitmap_sync, which increases the time required for bitmap_sync and makes it more difficult for dirty pages to converge. Attempt to eliminate these duplicate sync. Signed-off-by: Chuang Xu --- hw/virtio/vhost.c | 30 ++++++++++++++++++++++-------- include/hw/virtio/vhost.h | 1 + 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 266a11514a..d397ca327f 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -268,14 +268,6 @@ static int vhost_sync_dirty_bitmap(struct vhost_dev *d= ev, return 0; } =20 -static void vhost_log_sync(MemoryListener *listener, - MemoryRegionSection *section) -{ - struct vhost_dev *dev =3D container_of(listener, struct vhost_dev, - memory_listener); - vhost_sync_dirty_bitmap(dev, section, 0x0, ~0x0ULL); -} - static void vhost_log_sync_range(struct vhost_dev *dev, hwaddr first, hwaddr last) { @@ -287,6 +279,27 @@ static void vhost_log_sync_range(struct vhost_dev *dev, } } =20 +static void vhost_log_sync(MemoryListener *listener, + MemoryRegionSection *section) +{ + struct vhost_dev *dev =3D container_of(listener, struct vhost_dev, + memory_listener); + struct vhost_log *log =3D dev->log; + + if (log && log->refcnt > 1) { + /* + * When multiple devices use same log, we implement the logic of + * vhost_log_sync just like what we do in vhost_log_put. + */ + log->sync_cnt =3D (log->sync_cnt + 1) % log->refcnt; + if (!log->sync_cnt) { + vhost_log_sync_range(dev, 0, dev->log_size * VHOST_LOG_CHUNK -= 1); + } + } else { + vhost_sync_dirty_bitmap(dev, section, 0x0, ~0x0ULL); + } +} + static uint64_t vhost_get_log_size(struct vhost_dev *dev) { uint64_t log_size =3D 0; @@ -383,6 +396,7 @@ static struct vhost_log *vhost_log_get(VhostBackendType= backend_type, ++log->refcnt; } =20 + log->sync_cnt =3D 0; return log; } =20 diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index 08bbb4dfe9..43bf1c2150 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -50,6 +50,7 @@ typedef unsigned long vhost_log_chunk_t; struct vhost_log { unsigned long long size; int refcnt; + int sync_cnt; int fd; vhost_log_chunk_t *log; }; --=20 2.20.1