From nobody Tue Feb 10 05:44:34 2026 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=1683742270; cv=none; d=zohomail.com; s=zohoarc; b=XTP5t1+1KnKdRLr6Uowu8gVqHVGeL++7CrXBs8YeTQedrP9lGLwAq9MxqFGGUzzQtfaCUnm/btZEdGk/Pba2Mwm3AbUTmE5PIDlTVwEsTjP1rxje7GV3do9CFnfLvmqqjxXDZiUv9+x76+SjJYkFsCxSP2G16ETeZpVVc6Unxeg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683742270; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=HNSclBZXhxDxDy/DGSigditt2TN1w7TvNTjMre5f+dY=; b=f1RzybHwDtnjju0TQ0v0GcMSvRjIXVx66WIUidlGbWTNV1VPDVI9Do4/HbvkSg5S9COY4G15CxUS/6wikUK6g7TmArjk9XLjRaNBAm+0lG/C0nTvYYLM5ffCyFH7o6VMz/1IswZW1nWFNBAEIaHK1yuiacBWjdy0vUWCIHfG5PY= 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 1683742270004833.290849191154; Wed, 10 May 2023 11:11:10 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pwoG8-0002Oz-0I; Wed, 10 May 2023 14:09:52 -0400 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 1pwoG6-0002LB-E3 for qemu-devel@nongnu.org; Wed, 10 May 2023 14:09:50 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pwoG4-0000hf-LJ for qemu-devel@nongnu.org; Wed, 10 May 2023 14:09:50 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-438-kv1zpGSQMXuDDrb1d5rmGA-1; Wed, 10 May 2023 14:09:46 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EC58C84AF33; Wed, 10 May 2023 18:09:45 +0000 (UTC) Received: from secure.mitica (unknown [10.39.192.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6CF1C14171BC; Wed, 10 May 2023 18:09:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683742187; 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=HNSclBZXhxDxDy/DGSigditt2TN1w7TvNTjMre5f+dY=; b=RCrZiufjdabTpNVFsdNzP7CM/5LVWtKCsGRCWtSV/6UdllJadgZVg+NZEpePanT0OP1GkS 0d4DQ3IGGgil6C91K6b2cKQ4lRaed9yhD5QdTRr1Z8PoKEEXtT9sH4z3HhSgkrSETcBT1+ X9dopkfrMbJLtyjOhrniWtye945/tKw= X-MC-Unique: kv1zpGSQMXuDDrb1d5rmGA-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Kevin Wolf , Peter Xu , Eric Blake , Hanna Reitz , "Dr. David Alan Gilbert" , Markus Armbruster , Leonardo Bras , qemu-block@nongnu.org, Hailiang Zhang , Paolo Bonzini , Juan Quintela , Lukas Straub Subject: [PULL 01/10] ram: Add public helper to set colo bitmap Date: Wed, 10 May 2023 20:09:29 +0200 Message-Id: <20230510180938.6338-2-quintela@redhat.com> In-Reply-To: <20230510180938.6338-1-quintela@redhat.com> References: <20230510180938.6338-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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.133.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: 1683742270322100001 Content-Type: text/plain; charset="utf-8" From: Lukas Straub The overhead of the mutex in non-multifd mode is negligible, because in that case its just the single thread taking the mutex. This will be used in the next commits to add colo support to multifd. Signed-off-by: Lukas Straub Reviewed-by: Juan Quintela Message-Id: <22d83cb428f37929563155531bfb69fd8953cc61.1683572883.git.lukass= traub2@web.de> Signed-off-by: Juan Quintela --- migration/ram.h | 1 + migration/ram.c | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/migration/ram.h b/migration/ram.h index 6fffbeb5f1..ea1f3c25b5 100644 --- a/migration/ram.h +++ b/migration/ram.h @@ -82,6 +82,7 @@ int colo_init_ram_cache(void); void colo_flush_ram_cache(void); void colo_release_ram_cache(void); void colo_incoming_start_dirty_log(void); +void colo_record_bitmap(RAMBlock *block, ram_addr_t *normal, uint32_t page= s); =20 /* Background snapshot */ bool ram_write_tracking_available(void); diff --git a/migration/ram.c b/migration/ram.c index f78e9912cd..b5d03f85ab 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -3408,6 +3408,18 @@ static ram_addr_t host_page_offset_from_ram_block_of= fset(RAMBlock *block, return ((uintptr_t)block->host + offset) & (block->page_size - 1); } =20 +void colo_record_bitmap(RAMBlock *block, ram_addr_t *normal, uint32_t page= s) +{ + qemu_mutex_lock(&ram_state->bitmap_mutex); + for (int i =3D 0; i < pages; i++) { + ram_addr_t offset =3D normal[i]; + ram_state->migration_dirty_pages +=3D !test_and_set_bit( + offset >> TARGET_PAGE_BITS, + block->bmap); + } + qemu_mutex_unlock(&ram_state->bitmap_mutex); +} + static inline void *colo_cache_from_block_offset(RAMBlock *block, ram_addr_t offset, bool record_bitmap) { @@ -3425,9 +3437,8 @@ static inline void *colo_cache_from_block_offset(RAMB= lock *block, * It help us to decide which pages in ram cache should be flushed * into VM's RAM later. */ - if (record_bitmap && - !test_and_set_bit(offset >> TARGET_PAGE_BITS, block->bmap)) { - ram_state->migration_dirty_pages++; + if (record_bitmap) { + colo_record_bitmap(block, &offset, 1); } return block->colo_cache + offset; } --=20 2.40.1