Split up ram_find_and_save_block
v2 cover Split up ram_find_and_save_block
From: "Dr. David Alan Gilbert" <[email protected]>
Chop up ram_find_and_save_block so it's smaller again. (from comments on my postcopy patch that adds more to it).
This pair is based on top of my previous 5 patch cleanup series posted in August, but rebased on current qemu master.
Dave
Dr. David Alan Gilbert (2):
Move dirty page search state into separate structure
ram_find_and_save_block: Split out the finding
migration/ram.c | 119 +++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 84 insertions(+), 35 deletions(-)
v2
Typo fixes from Amit's review
Signature · 1 line
2.5.0
PATCH v2 1/2 Move dirty page search state into separate structure
From: "Dr. David Alan Gilbert" <[email protected]>
Pull the search state for one iteration of the dirty page search into a structure.
--- migration/ram.c | 55 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 20 deletions(-)
migration/ram.c +35 -20
@@ -227,6 +227,17 @@ static uint64_t migration_dirty_pages;static uint32_t last_version;static bool ram_bulk_stage; +/* used by the search for pages to send */ +struct PageSearchStatus { +/* Current block being searched */ +RAMBlock *block; +/* Current offset to search from */ +ram_addr_t offset; +/* Set once we wrap around */ +bool complete_round; +}; +typedef struct PageSearchStatus PageSearchStatus ; +struct CompressParam {bool start;bool done;
@@ -531,7 +542,6 @@ static void migration_bitmap_sync_range(ram_addr_t start, ram_addr_t length)cpu_physical_memory_sync_dirty_bitmap (bitmap, start, length); } -/* Fix me: there are too many global variables used in migration process. */ static int64_t start_time;static int64_t bytes_xfer_prev;
@@ -923,26 +933,30 @@ static int ram_save_compressed_page(QEMUFile *f, RAMBlock *block,static int ram_find_and_save_block (QEMUFile *f,bool last_stage,uint64_t *bytes_transferred) { -RAMBlock *block = last_seen_block; -ram_addr_t offset = last_offset; -bool complete_round = false; +PageSearchStatus pss;int pages =0 ; -if (!block) - block =QLIST_FIRST_RCU (&ram_list.blocks); + pss.block = last_seen_block; + pss.offset = last_offset; + pss.complete_round = false; + +if (!pss.block) { + pss.block =QLIST_FIRST_RCU (&ram_list.blocks); + }while (true) { - offset =migration_bitmap_find_and_reset_dirty (block, offset); -if (complete_round && block == last_seen_block && - offset >= last_offset) { + 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 (offset >= block->used_length) { - offset =0 ; - block =QLIST_NEXT_RCU (block, next); -if (!block) { - block =QLIST_FIRST_RCU (&ram_list.blocks); - complete_round = true; +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
@@ -954,23 +968,24 @@ static int ram_find_and_save_block(QEMUFile *f, bool last_stage, } }else {if (compression_switch &&migrate_use_compression ()) { - pages =ram_save_compressed_page (f, block, offset, last_stage, + pages =ram_save_compressed_page (f, pss.block, pss.offset, + last_stage, bytes_transferred); }else { - pages =ram_save_page (f, block, offset, last_stage, + pages =ram_save_page (f, pss.block, pss.offset, last_stage, bytes_transferred); }/* if page is unmodified, continue to the next */ if (pages >0 ) { - last_sent_block = block; + last_sent_block = pss.block;break ; } } } - last_seen_block = block; - last_offset = offset; + last_seen_block = pss.block; + last_offset = pss.offset;return pages; }
Signature · 1 line
2.5.0
PATCH v2 2/2 ram_find_and_save_block: Split out the finding
In reply to Dr. David Alan Gilbert (git)From: "Dr. David Alan Gilbert" <[email protected]>
Split out the finding of the dirty page and all the wrap detection into a separate function since it was getting a bit hairy.
--- migration/ram.c | 84 ++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 59 insertions(+), 25 deletions(-)
migration/ram.c +59 -25
@@ -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;
Signature · 1 line
2.5.0
Re: [Qemu-devel] [PATCH v2 2/2] ram_find_and_save_block: Split out the finding
migration/ram.c static int ram_save_compressed_page(QEMUFile *f, RAMBlock *block, · line 939
Quoted 12 lines · Dr. David Alan Gilbert (git)
From: "Dr. David Alan Gilbert" <[email protected]>
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 <[email protected]>migration/ram.c +5
-0+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.
I didn't notice this first time around - but I can fix this up while merging. Give up should be another sentence, right?
Amit
Quoted 7 lines · Dr. David Alan Gilbert (git)
From: "Dr. David Alan Gilbert" <[email protected]>
Chop up
ram_find_and_save_blockso it's smaller again. (from comments on my postcopy patch that adds more to it).This pair is based on top of my previous 5 patch cleanup series posted in August, but rebased on current qemu master.
Amit