From: Aadeshveer Singh <aadeshveer07@gmail.com>
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 <aadeshveer07@gmail.com>
Subject: [PATCH v4 02/11] migration: Extract blocktime marking helper
Date: Sat, 1 Aug 2026 08:06:19 +0530 [thread overview]
Message-ID: <20260801023628.22665-3-aadeshveer07@gmail.com> (raw)
In-Reply-To: <20260801023628.22665-1-aadeshveer07@gmail.com>
Use new function try_mark_postcopy_blocktim_begin() to call
mark_postcopy_blocktime_begin if page was not received and return if it
actually marked it.
This will help in having a cleaner API to call
mark_postcopy_blocktime_begin as it requires the page to not be received
by asserting on it's existance in RAMBlock->receivedmap.
Signed-off-by: Aadeshveer Singh <aadeshveer07@gmail.com>
Reviewed-by: Peter Xu <peterx@redhat.com>
---
migration/migration.c | 24 ++----------------------
migration/postcopy-ram.c | 31 +++++++++++++++++++++++++++++++
migration/postcopy-ram.h | 3 +++
3 files changed, 36 insertions(+), 22 deletions(-)
diff --git a/migration/migration.c b/migration/migration.c
index 074d3f2c69..07394d8eea 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -577,32 +577,12 @@ int migrate_send_rp_req_pages(MigrationIncomingState *mis,
RAMBlock *rb, ram_addr_t start, uint64_t haddr,
uint32_t tid)
{
- void *aligned = (void *)(uintptr_t)ROUND_DOWN(haddr, qemu_ram_pagesize(rb));
- bool received = false;
-
- WITH_QEMU_LOCK_GUARD(&mis->page_request_mutex) {
- received = ramblock_recv_bitmap_test_byte_offset(rb, start);
- if (!received) {
- if (!g_tree_lookup(mis->page_requested, aligned)) {
- /*
- * The page has not been received, and it's not yet in the
- * page request list. Queue it. Set the value of element
- * to 1, so that things like g_tree_lookup() will return
- * TRUE (1) when found.
- */
- g_tree_insert(mis->page_requested, aligned, (gpointer)1);
- qatomic_inc(&mis->page_requested_count);
- trace_postcopy_page_req_add(aligned, mis->page_requested_count);
- }
- mark_postcopy_blocktime_begin(haddr, tid, rb);
- }
- }
-
/*
+ * If not able to mark page for blocktime it must already be present.
* If the page is there, skip sending the message. We don't even need the
* lock because as long as the page arrived, it'll be there forever.
*/
- if (received) {
+ if (!try_mark_postcopy_blocktime_begin(mis, rb, start, haddr, tid)) {
return 0;
}
diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c
index 96a65aa976..4b8f882e1e 100644
--- a/migration/postcopy-ram.c
+++ b/migration/postcopy-ram.c
@@ -1057,6 +1057,37 @@ static void blocktime_fault_inject(PostcopyBlocktimeContext *ctx,
trace_postcopy_blocktime_begin(addr, time, cpu, !!head);
}
+/*
+ * Take @page_request_mutex and try marking postcopy blocktime begin.
+ * Return true if marking is successful and false if page alredy exists.
+ */
+bool try_mark_postcopy_blocktime_begin(MigrationIncomingState *mis,
+ RAMBlock *rb, ram_addr_t start,
+ uint64_t haddr, uint32_t tid)
+{
+ bool received = false;
+ void *aligned = (void *)(uintptr_t)ROUND_DOWN(haddr, qemu_ram_pagesize(rb));
+
+ WITH_QEMU_LOCK_GUARD(&mis->page_request_mutex) {
+ received = ramblock_recv_bitmap_test_byte_offset(rb, start);
+ if (!received) {
+ if (!g_tree_lookup(mis->page_requested, aligned)) {
+ /*
+ * The page has not been received, and it's not yet in the
+ * page request list. Queue it. Set the value of element
+ * to 1, so that things like g_tree_lookup() will return
+ * TRUE (1) when found.
+ */
+ g_tree_insert(mis->page_requested, aligned, (gpointer)1);
+ qatomic_inc(&mis->page_requested_count);
+ trace_postcopy_page_req_add(aligned, mis->page_requested_count);
+ }
+ mark_postcopy_blocktime_begin((uint64_t)aligned, tid, rb);
+ }
+ }
+ return !received;
+}
+
/*
* This function is being called when pagefault occurs. It tracks down vCPU
* blocking time. It's protected by @page_request_mutex.
diff --git a/migration/postcopy-ram.h b/migration/postcopy-ram.h
index 98d918713f..ea879f0bc6 100644
--- a/migration/postcopy-ram.h
+++ b/migration/postcopy-ram.h
@@ -196,6 +196,9 @@ void postcopy_preempt_new_channel(MigrationIncomingState *mis, QEMUFile *file);
void postcopy_preempt_setup(MigrationState *s);
int postcopy_preempt_establish_channel(MigrationState *s);
bool postcopy_is_paused(MigrationStatus status);
+bool try_mark_postcopy_blocktime_begin(MigrationIncomingState *mis,
+ RAMBlock *rb, ram_addr_t start,
+ uint64_t haddr, uint32_t tid);
void mark_postcopy_blocktime_begin(uintptr_t addr, uint32_t ptid,
RAMBlock *rb);
--
2.55.0
next prev parent reply other threads:[~2026-08-01 2:37 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-01 2:36 [PATCH v4 00/11] migration: fast snapshot load Aadeshveer Singh
2026-08-01 2:36 ` [PATCH v4 01/11] migration: Propagate error in postcopy setup functions Aadeshveer Singh
2026-08-10 15:08 ` Juraj Marcin
2026-08-01 2:36 ` Aadeshveer Singh [this message]
2026-08-10 15:08 ` [PATCH v4 02/11] migration: Extract blocktime marking helper Juraj Marcin
2026-08-01 2:36 ` [PATCH v4 03/11] migration: Rename postcopy_listen_thread_bh Aadeshveer Singh
2026-08-10 15:09 ` Juraj Marcin
2026-08-01 2:36 ` [PATCH v4 04/11] migration: Use file_bmap for RAMBlock during incoming file load Aadeshveer Singh
2026-08-10 15:09 ` Juraj Marcin
2026-08-01 2:36 ` [PATCH v4 05/11] migration: Make qemu_get_buffer_at() thread-safe Aadeshveer Singh
2026-08-10 14:14 ` Peter Xu
2026-08-10 15:10 ` Juraj Marcin
2026-08-01 2:36 ` [PATCH v4 06/11] migration: add RAMBlock field and helper for fast snapshot load Aadeshveer Singh
2026-08-10 15:12 ` Juraj Marcin
2026-08-01 2:36 ` [PATCH v4 07/11] migration: add support for fault thread to load pages from disk Aadeshveer Singh
2026-08-08 4:34 ` Aadeshveer Singh
2026-08-10 15:40 ` Peter Xu
2026-08-01 2:36 ` [PATCH v4 08/11] migration: add eager load thread and setup for fast snapshot load Aadeshveer Singh
2026-08-10 15:48 ` Juraj Marcin
2026-08-01 2:36 ` [PATCH v4 09/11] migration: update capability conflict test for postcopy-ram+mapped-ram Aadeshveer Singh
2026-08-10 15:49 ` Juraj Marcin
2026-08-10 18:23 ` Peter Xu
2026-08-01 2:36 ` [PATCH v4 10/11] migration/tests: Add test for fast snapshot load Aadeshveer Singh
2026-08-10 15:50 ` Juraj Marcin
2026-08-01 2:36 ` [PATCH v4 11/11] docs/migration: Add documentation for fast snapshot load feature Aadeshveer Singh
2026-08-10 18:24 ` Peter Xu
2026-08-10 19:02 ` [PATCH v4 00/11] migration: fast snapshot load Peter Xu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260801023628.22665-3-aadeshveer07@gmail.com \
--to=aadeshveer07@gmail.com \
--cc=ayoub@saferwall.com \
--cc=farosas@suse.de \
--cc=lvivier@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peterx@redhat.com \
--cc=philmd@mailo.com \
--cc=pierrick.bouvier@oss.qualcomm.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.