From: Prasad Pandit <ppandit@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Xu <peterx@redhat.com>, Fabiano Rosas <farosas@suse.de>,
Prasad Pandit <pjp@fedoraproject.org>
Subject: [PATCH 4/5] migration: refactor ram_save_target_page functions
Date: Tue, 29 Oct 2024 20:39:07 +0530 [thread overview]
Message-ID: <20241029150908.1136894-5-ppandit@redhat.com> (raw)
In-Reply-To: <20241029150908.1136894-1-ppandit@redhat.com>
From: Prasad Pandit <pjp@fedoraproject.org>
Refactor ram_save_target_page legacy and multifd
functions into one. Other than simplifying it,
it avoids reinitialization of the 'migration_ops'
object, when migration moves from multifd to postcopy
phase.
Signed-off-by: Prasad Pandit <pjp@fedoraproject.org>
---
migration/ram.c | 54 ++++++++++++++++++++-----------------------------
1 file changed, 22 insertions(+), 32 deletions(-)
diff --git a/migration/ram.c b/migration/ram.c
index 326ce7eb79..f9a6395d00 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -1985,18 +1985,36 @@ int ram_save_queue_pages(const char *rbname, ram_addr_t start, ram_addr_t len,
}
/**
- * ram_save_target_page_legacy: save one target page
+ * ram_save_target_page_common:
+ * send one target page to multifd workers OR save one target page.
*
- * Returns the number of pages written
+ * Multifd mode: returns 1 if the page was queued, -1 otherwise.
+ *
+ * Non-multifd mode: returns the number of pages written
*
* @rs: current RAM state
* @pss: data about the page we want to send
*/
-static int ram_save_target_page_legacy(RAMState *rs, PageSearchStatus *pss)
+static int ram_save_target_page_common(RAMState *rs, PageSearchStatus *pss)
{
ram_addr_t offset = ((ram_addr_t)pss->page) << TARGET_PAGE_BITS;
int res;
+ if (migrate_multifd()) {
+ RAMBlock *block = pss->block;
+ /*
+ * While using multifd live migration, we still need to handle zero
+ * page checking on the migration main thread.
+ */
+ if (migrate_zero_page_detection() == ZERO_PAGE_DETECTION_LEGACY) {
+ if (save_zero_page(rs, pss, offset)) {
+ return 1;
+ }
+ }
+
+ return ram_save_multifd_page(block, offset);
+ }
+
if (control_save_page(pss, offset, &res)) {
return res;
}
@@ -2008,32 +2026,6 @@ static int ram_save_target_page_legacy(RAMState *rs, PageSearchStatus *pss)
return ram_save_page(rs, pss);
}
-/**
- * ram_save_target_page_multifd: send one target page to multifd workers
- *
- * Returns 1 if the page was queued, -1 otherwise.
- *
- * @rs: current RAM state
- * @pss: data about the page we want to send
- */
-static int ram_save_target_page_multifd(RAMState *rs, PageSearchStatus *pss)
-{
- RAMBlock *block = pss->block;
- ram_addr_t offset = ((ram_addr_t)pss->page) << TARGET_PAGE_BITS;
-
- /*
- * While using multifd live migration, we still need to handle zero
- * page checking on the migration main thread.
- */
- if (migrate_zero_page_detection() == ZERO_PAGE_DETECTION_LEGACY) {
- if (save_zero_page(rs, pss, offset)) {
- return 1;
- }
- }
-
- return ram_save_multifd_page(block, offset);
-}
-
/* Should be called before sending a host page */
static void pss_host_page_prepare(PageSearchStatus *pss)
{
@@ -3055,12 +3047,10 @@ static int ram_save_setup(QEMUFile *f, void *opaque, Error **errp)
}
migration_ops = g_malloc0(sizeof(MigrationOps));
+ migration_ops->ram_save_target_page = ram_save_target_page_common;
if (migrate_multifd()) {
multifd_ram_save_setup();
- migration_ops->ram_save_target_page = ram_save_target_page_multifd;
- } else {
- migration_ops->ram_save_target_page = ram_save_target_page_legacy;
}
bql_unlock();
--
2.47.0
next prev parent reply other threads:[~2024-10-29 15:10 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-29 15:09 [PATCH 0/5] Allow to enable multifd and postcopy migration together Prasad Pandit
2024-10-29 15:09 ` [PATCH 1/5] migration/multifd: move macros to multifd header Prasad Pandit
2024-10-29 15:09 ` [PATCH 2/5] migration/postcopy: magic value for postcopy channel Prasad Pandit
[not found] ` <ZyTnBwpOwXcHGGPJ@x1n>
2024-11-04 12:32 ` Prasad Pandit
2024-11-04 17:18 ` Peter Xu
2024-11-05 11:19 ` Prasad Pandit
2024-11-05 13:00 ` Peter Xu
2024-11-06 12:19 ` Prasad Pandit
2024-11-06 13:11 ` Fabiano Rosas
2024-11-07 12:05 ` Prasad Pandit
2024-11-07 12:11 ` Fabiano Rosas
2024-11-07 12:33 ` Daniel P. Berrangé
2024-11-07 16:17 ` Peter Xu
2024-11-07 16:57 ` Daniel P. Berrangé
2024-11-07 17:45 ` Peter Xu
2024-11-08 12:37 ` Prasad Pandit
2024-11-08 13:25 ` Fabiano Rosas
2024-11-06 16:00 ` Peter Xu
2024-11-07 11:52 ` Prasad Pandit
2024-11-07 15:56 ` Peter Xu
2024-10-29 15:09 ` [PATCH 3/5] migration: remove multifd check with postcopy Prasad Pandit
[not found] ` <ZyTnWYyHlrJUYQRB@x1n>
2024-11-04 12:23 ` Prasad Pandit
2024-11-04 16:52 ` Peter Xu
2024-11-05 9:50 ` Prasad Pandit
2024-10-29 15:09 ` Prasad Pandit [this message]
[not found] ` <ZyToBbvfWkIZ_40W@x1n>
2024-11-04 11:56 ` [PATCH 4/5] migration: refactor ram_save_target_page functions Prasad Pandit
2024-11-04 17:00 ` Peter Xu
2024-11-05 10:01 ` Prasad Pandit
2024-11-05 13:01 ` Peter Xu
2024-10-29 15:09 ` [PATCH 5/5] migration: enable multifd and postcopy together Prasad Pandit
2024-11-04 17:48 ` Peter Xu
2024-11-05 11:54 ` Prasad Pandit
2024-11-05 16:55 ` 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=20241029150908.1136894-5-ppandit@redhat.com \
--to=ppandit@redhat.com \
--cc=farosas@suse.de \
--cc=peterx@redhat.com \
--cc=pjp@fedoraproject.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).