From nobody Mon Sep 21 18:57:16 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=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1784038683; cv=none; d=zohomail.com; s=zohoarc; b=DxgLTRVOFfNa17EmEb6NUlpFW3inEoX8HcWvsegkY09Kdfc7UCCpHd4Jribl86FslE0OqwqsW2LAytgvXxwuB4QTHg8gdXy1/5EVbuE+FCVDBbm5RD4mojE/odWcMDKqTqwXcAxUSDEA/8jh7S7V6DGWU6bheMGO/NG4PctmXsY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784038683; 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=3rc6X3QUuPZRks4ZEy0gC68K6c+Nml37luhf4A5r5bs=; b=T83T2HAvpCIkVLrxYnkscpjdEwZ1HPcGe/kysO2y5wTUI1oEsNI7ndAJ+pemL6e3W7NWRDLAl/VVSKebUrP2hj1vEb0KdSyb/fdY6bDWXNxr/31EfmsBON+o81OkfPPEgeXH92KZaxymlBhiUGSmB7ADXHpNxTLWKpPYf+/RB08= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1784038683460991.264756699905; Tue, 14 Jul 2026 07:18:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wjdwi-0006Gp-Qt; Tue, 14 Jul 2026 10:17:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wjdwb-0006Bb-BV for qemu-devel@nongnu.org; Tue, 14 Jul 2026 10:17:10 -0400 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wjdwZ-0002cW-L6 for qemu-devel@nongnu.org; Tue, 14 Jul 2026 10:17:09 -0400 Received: by mail-pj1-x1035.google.com with SMTP id 98e67ed59e1d1-3856d6fbcb3so985837a91.2 for ; Tue, 14 Jul 2026 07:17:07 -0700 (PDT) Received: from setun ([2405:201:502b:3014:cc0c:536:1b1e:6def]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3118ee6091dsm97329733eec.14.2026.07.14.07.17.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jul 2026 07:17:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784038626; x=1784643426; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=3rc6X3QUuPZRks4ZEy0gC68K6c+Nml37luhf4A5r5bs=; b=MHpKRJ21Dfpiw7qe/U34qwVzakTPp9V995O/Klw9SG0rDQ1w8Z0P8VVw7OMXp/fIVI rbTGlSsxpd0mGQbaTgrkfsdNqEOBp3SVou/ToXY2sS5FwF+SsEORnJKCIW7CDCcBQrdy Osaals9o/AsbewJnY6rT9lsC9sKsUuSO8IkOtyhH/jFZ26rV3ELWB6CPauvLwfWrqP2+ Pi3Pb03cns14vECN/xk6/6l9u39iY+X/OBLWXnBGdzaHXcIsNZhLXziev9pRHprZz05s vEyvEiiVnHS/Q40jZUXOZpVBhwWxkoxHf5+wY3iznyvQyugEsH5lXv6Rq41+nviFYF5y I9Fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784038626; x=1784643426; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=3rc6X3QUuPZRks4ZEy0gC68K6c+Nml37luhf4A5r5bs=; b=VGsROgvSZViQeV076IYhRS3d5e2C9eWcQfK1hqaTn4N9SQtL1TqFLBToy2saJ+/2sQ 47YI/MKkGGZ+yRm402ywQ7Tr79DrqX6F+/zz7h1wbj/JAdYssSSHR8X3illstjZaUecA 7VxVkrSV638DDFCak48AjJOMNCqkEZjXLGTk2p3hsUw7DJ39TuxbTgKR1zv4Fbc60Nji wEmCS3B9jLlAEb/Nxd99fXfSvEad4F2CKTLxytLsArgTIWDcvvv9oQmV8M8QEMhO6wrB fe3DYMeNCpvUqlEibLcsVFJ+Lc9KEBZoZfvPwCZFMOJCPG8wEmwiEkwOUQ6GBtsWc4C/ 1h/A== X-Gm-Message-State: AOJu0YwLELFbA5jSaiaMRPEzkIDzMuI64IftuRZg6vSiuziS/bxduuo2 Aih7tGOhETeFZAieQz9e3VhNgQVDh1Dm4U/0QNg/dhO6qKo18GxUCdBiYDSqU4U5 X-Gm-Gg: AfdE7cmQ9ezTfEg0Cf0dP4rNFIqM5X6hFMLvDKU/UzJ+1tQamdpGmyfEYE6xf1MskVY TjGQhJfy5tlpzzuNqF5YlWuJJ84UyW9vFkDQ1gFgdO8/T89RR+fkq/w+zri1B34CeqQatqSfL27 Kzn8SOidntpRObIYZZ7nRrdu7Tmv/VwQJiR1mqIZ+W8xYVs9+AOZ6c4FYCC7NukGYeUrybYbVKn xgbTmukjZSN4TQbFlmaYzi8F+1j2r9hmIw0eLbyXrtM9Krk3ZCp/+o+xQidOfJsbtkQp4AMDTxf rW6ANK9XMq8kgiSYQ2iK/hfiZ1R2ka/f4bbXzd7QJpY0rJgRfGu37bgJanHLNvzSnVXQDXYGnhO kslcKevXU2u/RkfrCsEya/Hg7CSSUocr33VMx001f80As5AOseMEb7ak5VWBGg9RBGRsPviAFsM AvwLzF4AtAZDZ2eDLtU7HfbvRRL6690+k8apNsX47WNg== X-Received: by 2002:a17:90b:3d4b:b0:381:1f51:1ff0 with SMTP id 98e67ed59e1d1-38dc782ab85mr12118993a91.2.1784038625965; Tue, 14 Jul 2026 07:17:05 -0700 (PDT) From: Aadeshveer Singh To: qemu-devel@nongnu.org Cc: peterx@redhat.com, farosas@suse.de, pbonzini@redhat.com, philmd@mailo.com, lvivier@redhat.com, ayoub@saferwall.com, pierrick.bouvier@oss.qualcomm.com, Aadeshveer Singh Subject: [PATCH v3 06/11] migration: add RAMBlock field and helper for fast snapshot load Date: Tue, 14 Jul 2026 19:45:42 +0530 Message-ID: <20260714141547.1268000-7-aadeshveer07@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260714141547.1268000-1-aadeshveer07@gmail.com> References: <20260714141547.1268000-1-aadeshveer07@gmail.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=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1035; envelope-from=aadeshveer07@gmail.com; helo=mail-pj1-x1035.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 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, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, 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: qemu development 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 @gmail.com) X-ZM-MESSAGEID: 1784038685305158500 Content-Type: text/plain; charset="utf-8" Add pending_bmap field per RAMBlock which is a Bitmap to store internal state of which pages have been read by some thread to ensure coordination between fault thread and eager load thread. Modify parse_ramblock_mapped_ram(), to not load the actual RAMBlocks data in postcopy case as that will be loaded by fault thread and eager thread after the VM starts running. Change ram_load() to use new function ram_should_load_postcopy_pages() to decide how to load/read RAM. Signed-off-by: Aadeshveer Singh Reviewed-by: Peter Xu --- include/system/ramblock.h | 6 ++++ migration/ram.c | 59 +++++++++++++++++++++++++++++++++++---- 2 files changed, 59 insertions(+), 6 deletions(-) diff --git a/include/system/ramblock.h b/include/system/ramblock.h index 4435f8d55f..83187bf44c 100644 --- a/include/system/ramblock.h +++ b/include/system/ramblock.h @@ -60,6 +60,12 @@ struct RAMBlock { =20 /* Bitmap of already received pages. Only used on destination side. */ unsigned long *receivedmap; + /* + * Bitmap for pages that are yet to be read from disk. It is required = for + * fault thread and eager thread to keep note of which pages are curre= ntly + * being read. Used by fast snapshot load. + */ + unsigned long *pending_bmap; =20 /* * bitmap to track already cleared dirty bitmap. When the bit is diff --git a/migration/ram.c b/migration/ram.c index 967db7c0db..330fceaa43 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -263,6 +263,18 @@ static void ramblock_file_bmap_init(void) } } =20 +static void ramblock_pending_bmap_init(void) +{ + RAMBlock *rb; + + RAMBLOCK_FOREACH_NOT_IGNORED(rb) { + assert(!rb->pending_bmap); + size_t size =3D rb->max_length >> qemu_target_page_bits(); + rb->pending_bmap =3D bitmap_new(size); + bitmap_set(rb->pending_bmap, 0, size); + } +} + static void ramblock_recv_map_init(void) { RAMBlock *rb; @@ -3762,6 +3774,10 @@ static int ram_load_setup(QEMUFile *f, void *opaque,= Error **errp) ramblock_recv_map_init(); if (migrate_mapped_ram()) { ramblock_file_bmap_init(); + if (migrate_postcopy_ram()) { + /* fast snapshot load */ + ramblock_pending_bmap_init(); + } } =20 return 0; @@ -3782,6 +3798,7 @@ static int ram_load_cleanup(void *opaque) RAMBLOCK_FOREACH_NOT_IGNORED(rb) { g_clear_pointer(&rb->receivedmap, g_free); g_clear_pointer(&rb->file_bmap, g_free); + g_clear_pointer(&rb->pending_bmap, g_free); } =20 return 0; @@ -4201,9 +4218,12 @@ static void parse_ramblock_mapped_ram(QEMUFile *f, R= AMBlock *block, return; } =20 - if (!read_ramblock_mapped_ram(f, block, num_pages, block->file_bmap, - errp)) { - return; + if (!migrate_postcopy_ram()) { + /* Do not load RAM during setup for fast snapshot load */ + if (!read_ramblock_mapped_ram(f, block, num_pages, block->file_bma= p, + errp)) { + return; + } } =20 /* Skip pages array */ @@ -4475,15 +4495,42 @@ static int ram_load_precopy(QEMUFile *f) return ret; } =20 +static bool ram_should_load_postcopy_pages(void) +{ + /* This is pure precopy, we don't need to load pages in postcopy way */ + if (!postcopy_is_running()) { + return false; + } + + /* + * This is postcopy, but when with mapped-ram, pages are not loaded in= the + * migration stream here, but done separately in a thread eagerly read= ing + * pages from the snapshot. Here, we only need to read the ram header= s, + * reusing the precopy code. + * TODO: when we have separate function to parse RAM headers we should + * switch to that. + */ + if (migrate_mapped_ram()) { + return false; + } + + /* + * Genuine network postcopy, we will load pages in this current stream= and + * they need to be done in postcopy way. + */ + return true; +} + static int ram_load(QEMUFile *f, void *opaque, int version_id) { int ret =3D 0; static uint64_t seq_iter; /* * If system is running in postcopy mode, page inserts to host memory = must - * be atomic + * be atomic. However, fast snapshot load uses the mapped ram precopy = like + * path to read block headers and populating bitmaps. */ - bool postcopy_running =3D postcopy_is_running(); + bool load_postcopy_pages =3D ram_should_load_postcopy_pages(); =20 seq_iter++; =20 @@ -4499,7 +4546,7 @@ static int ram_load(QEMUFile *f, void *opaque, int ve= rsion_id) */ trace_ram_load_start(); WITH_RCU_READ_LOCK_GUARD() { - if (postcopy_running) { + if (load_postcopy_pages) { /* * Note! Here RAM_CHANNEL_PRECOPY is the precopy channel of * postcopy migration, we have another RAM_CHANNEL_POSTCOPY to --=20 2.55.0