From: Amit Shah <amit.shah@redhat.com>
To: Juan Quintela <quintela@redhat.com>
Cc: Amit Shah <amit.shah@redhat.com>,
qemu list <qemu-devel@nongnu.org>,
"Dr. David Alan Gilbert" <dgilbert@redhat.com>
Subject: [Qemu-devel] [migration PULL 9/9] ram_find_and_save_block: Split out the finding
Date: Tue, 29 Sep 2015 12:02:24 +0530 [thread overview]
Message-ID: <b9e6092814735853cc1149e2e68245b09f621306.1443508205.git.amit.shah@redhat.com> (raw)
In-Reply-To: <cover.1443508205.git.amit.shah@redhat.com>
In-Reply-To: <cover.1443508205.git.amit.shah@redhat.com>
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
Split out the finding of the dirty page and all the wrap detection
into a separate function since it was getting a bit hairy.
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Message-Id: <1443018431-11170-3-git-send-email-dgilbert@redhat.com>
Reviewed-by: Amit Shah <amit.shah@redhat.com>
[Fix comment -- Amit]
Signed-off-by: Amit Shah <amit.shah@redhat.com>
---
migration/ram.c | 84 ++++++++++++++++++++++++++++++++++++++++-----------------
1 file changed, 59 insertions(+), 25 deletions(-)
diff --git a/migration/ram.c b/migration/ram.c
index d79d79d..5187637 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -917,6 +917,59 @@ static int ram_save_compressed_page(QEMUFile *f, RAMBlock *block,
return pages;
}
+/*
+ * Find the next dirty page and update any state associated with
+ * the search process.
+ *
+ * Returns: True if a page is found
+ *
+ * @f: Current migration stream.
+ * @pss: Data about the state of the current dirty page scan.
+ * @*again: Set to false if the search has scanned the whole of RAM
+ */
+static bool find_dirty_block(QEMUFile *f, PageSearchStatus *pss,
+ bool *again)
+{
+ pss->offset = migration_bitmap_find_and_reset_dirty(pss->block,
+ pss->offset);
+ if (pss->complete_round && pss->block == last_seen_block &&
+ pss->offset >= last_offset) {
+ /*
+ * We've been once around the RAM and haven't found anything.
+ * Give up.
+ */
+ *again = false;
+ return false;
+ }
+ if (pss->offset >= pss->block->used_length) {
+ /* Didn't find anything in this RAM Block */
+ pss->offset = 0;
+ pss->block = QLIST_NEXT_RCU(pss->block, next);
+ if (!pss->block) {
+ /* Hit the end of the list */
+ pss->block = QLIST_FIRST_RCU(&ram_list.blocks);
+ /* Flag that we've looped */
+ pss->complete_round = true;
+ ram_bulk_stage = false;
+ if (migrate_use_xbzrle()) {
+ /* If xbzrle is on, stop using the data compression at this
+ * point. In theory, xbzrle can do better than compression.
+ */
+ flush_compressed_data(f);
+ compression_switch = false;
+ }
+ }
+ /* Didn't find anything this time, but try again on the new block */
+ *again = true;
+ return false;
+ } else {
+ /* Can go around again, but... */
+ *again = true;
+ /* We've found something so probably don't need to */
+ return true;
+ }
+}
+
/**
* ram_find_and_save_block: Finds a dirty page and sends it to f
*
@@ -935,6 +988,7 @@ static int ram_find_and_save_block(QEMUFile *f, bool last_stage,
{
PageSearchStatus pss;
int pages = 0;
+ bool again, found;
pss.block = last_seen_block;
pss.offset = last_offset;
@@ -944,29 +998,10 @@ static int ram_find_and_save_block(QEMUFile *f, bool last_stage,
pss.block = QLIST_FIRST_RCU(&ram_list.blocks);
}
- while (true) {
- pss.offset = migration_bitmap_find_and_reset_dirty(pss.block,
- pss.offset);
- if (pss.complete_round && pss.block == last_seen_block &&
- pss.offset >= last_offset) {
- break;
- }
- if (pss.offset >= pss.block->used_length) {
- pss.offset = 0;
- pss.block = QLIST_NEXT_RCU(pss.block, next);
- if (!pss.block) {
- pss.block = QLIST_FIRST_RCU(&ram_list.blocks);
- pss.complete_round = true;
- ram_bulk_stage = false;
- if (migrate_use_xbzrle()) {
- /* If xbzrle is on, stop using the data compression at this
- * point. In theory, xbzrle can do better than compression.
- */
- flush_compressed_data(f);
- compression_switch = false;
- }
- }
- } else {
+ do {
+ found = find_dirty_block(f, &pss, &again);
+
+ if (found) {
if (compression_switch && migrate_use_compression()) {
pages = ram_save_compressed_page(f, pss.block, pss.offset,
last_stage,
@@ -979,10 +1014,9 @@ static int ram_find_and_save_block(QEMUFile *f, bool last_stage,
/* if page is unmodified, continue to the next */
if (pages > 0) {
last_sent_block = pss.block;
- break;
}
}
- }
+ } while (!pages && again);
last_seen_block = pss.block;
last_offset = pss.offset;
--
2.4.3
next prev parent reply other threads:[~2015-09-29 6:33 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-29 6:32 [Qemu-devel] [migration PULL 0/9] Migration queue - for Juan Amit Shah
2015-09-29 6:32 ` [Qemu-devel] [migration PULL 1/9] vmstate: Remove redefinition of VMSTATE_UINT32_ARRAY Amit Shah
2015-09-29 6:32 ` [Qemu-devel] [migration PULL 2/9] migration/ram.c: Use RAMBlock rather than MemoryRegion Amit Shah
2015-09-29 6:32 ` [Qemu-devel] [migration PULL 3/9] Split out end of migration code from migration_thread Amit Shah
2015-09-29 6:32 ` [Qemu-devel] [migration PULL 4/9] Init page sizes in qtest Amit Shah
2015-09-29 6:32 ` [Qemu-devel] [migration PULL 5/9] migration: size_t'ify some of qemu-file Amit Shah
2015-09-29 6:32 ` [Qemu-devel] [migration PULL 6/9] migration: qemu-file more size_t'ifying Amit Shah
2015-09-29 6:32 ` [Qemu-devel] [migration PULL 7/9] migration: Use g_new() & friends where that makes obvious sense Amit Shah
2015-09-29 6:32 ` [Qemu-devel] [migration PULL 8/9] Move dirty page search state into separate structure Amit Shah
2015-09-29 6:32 ` Amit Shah [this message]
2015-09-29 12:50 ` [Qemu-devel] [migration PULL 0/9] Migration queue - for Juan Peter Maydell
2015-09-29 13:05 ` Amit Shah
2015-09-29 13:23 ` Peter Maydell
2015-09-30 16:23 ` Juan Quintela
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=b9e6092814735853cc1149e2e68245b09f621306.1443508205.git.amit.shah@redhat.com \
--to=amit.shah@redhat.com \
--cc=dgilbert@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
/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).