ram: Change offset field in PageSearchStatus to page

We are moving everything to work on pages, not addresses.

Signed-off-by: Juan Quintela <quintela@redhat.com>
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
This commit is contained in:
Juan Quintela 2017-03-21 15:36:51 +01:00
parent 269ace2951
commit a935e30fbb
1 changed files with 26 additions and 25 deletions

View File

@ -296,8 +296,8 @@ uint64_t ram_postcopy_requests(void)
struct PageSearchStatus { struct PageSearchStatus {
/* Current block being searched */ /* Current block being searched */
RAMBlock *block; RAMBlock *block;
/* Current offset to search from */ /* Current page to search from */
ram_addr_t offset; unsigned long page;
/* Set once we wrap around */ /* Set once we wrap around */
bool complete_round; bool complete_round;
}; };
@ -608,16 +608,16 @@ static int save_xbzrle_page(RAMState *rs, uint8_t **current_data,
* *
* @rs: current RAM state * @rs: current RAM state
* @rb: RAMBlock where to search for dirty pages * @rb: RAMBlock where to search for dirty pages
* @start: starting address (typically so we can continue from previous page) * @start: page where we start the search
* @page_abs: pointer into where to store the dirty page * @page_abs: pointer into where to store the dirty page
*/ */
static inline static inline
ram_addr_t migration_bitmap_find_dirty(RAMState *rs, RAMBlock *rb, unsigned long migration_bitmap_find_dirty(RAMState *rs, RAMBlock *rb,
ram_addr_t start, unsigned long start,
unsigned long *page_abs) unsigned long *page_abs)
{ {
unsigned long base = rb->offset >> TARGET_PAGE_BITS; unsigned long base = rb->offset >> TARGET_PAGE_BITS;
unsigned long nr = base + (start >> TARGET_PAGE_BITS); unsigned long nr = base + start;
uint64_t rb_size = rb->used_length; uint64_t rb_size = rb->used_length;
unsigned long size = base + (rb_size >> TARGET_PAGE_BITS); unsigned long size = base + (rb_size >> TARGET_PAGE_BITS);
unsigned long *bitmap; unsigned long *bitmap;
@ -632,7 +632,7 @@ ram_addr_t migration_bitmap_find_dirty(RAMState *rs, RAMBlock *rb,
} }
*page_abs = next; *page_abs = next;
return (next - base) << TARGET_PAGE_BITS; return next - base;
} }
static inline bool migration_bitmap_clear_dirty(RAMState *rs, static inline bool migration_bitmap_clear_dirty(RAMState *rs,
@ -810,7 +810,7 @@ static int ram_save_page(RAMState *rs, PageSearchStatus *pss, bool last_stage)
int ret; int ret;
bool send_async = true; bool send_async = true;
RAMBlock *block = pss->block; RAMBlock *block = pss->block;
ram_addr_t offset = pss->offset; ram_addr_t offset = pss->page << TARGET_PAGE_BITS;
p = block->host + offset; p = block->host + offset;
@ -842,7 +842,7 @@ static int ram_save_page(RAMState *rs, PageSearchStatus *pss, bool last_stage)
* page would be stale * page would be stale
*/ */
xbzrle_cache_zero_page(rs, current_addr); xbzrle_cache_zero_page(rs, current_addr);
ram_release_pages(block->idstr, pss->offset, pages); ram_release_pages(block->idstr, offset, pages);
} else if (!rs->ram_bulk_stage && } else if (!rs->ram_bulk_stage &&
!migration_in_postcopy() && migrate_use_xbzrle()) { !migration_in_postcopy() && migrate_use_xbzrle()) {
pages = save_xbzrle_page(rs, &p, current_addr, block, pages = save_xbzrle_page(rs, &p, current_addr, block,
@ -985,7 +985,7 @@ static int ram_save_compressed_page(RAMState *rs, PageSearchStatus *pss,
uint8_t *p; uint8_t *p;
int ret, blen; int ret, blen;
RAMBlock *block = pss->block; RAMBlock *block = pss->block;
ram_addr_t offset = pss->offset; ram_addr_t offset = pss->page << TARGET_PAGE_BITS;
p = block->host + offset; p = block->host + offset;
@ -1029,14 +1029,14 @@ static int ram_save_compressed_page(RAMState *rs, PageSearchStatus *pss,
} }
} }
if (pages > 0) { if (pages > 0) {
ram_release_pages(block->idstr, pss->offset, pages); ram_release_pages(block->idstr, offset, pages);
} }
} else { } else {
pages = save_zero_page(rs, block, offset, p); pages = save_zero_page(rs, block, offset, p);
if (pages == -1) { if (pages == -1) {
pages = compress_page_with_multi_thread(rs, block, offset); pages = compress_page_with_multi_thread(rs, block, offset);
} else { } else {
ram_release_pages(block->idstr, pss->offset, pages); ram_release_pages(block->idstr, offset, pages);
} }
} }
} }
@ -1058,10 +1058,10 @@ static int ram_save_compressed_page(RAMState *rs, PageSearchStatus *pss,
static bool find_dirty_block(RAMState *rs, PageSearchStatus *pss, static bool find_dirty_block(RAMState *rs, PageSearchStatus *pss,
bool *again, unsigned long *page_abs) bool *again, unsigned long *page_abs)
{ {
pss->offset = migration_bitmap_find_dirty(rs, pss->block, pss->offset, pss->page = migration_bitmap_find_dirty(rs, pss->block, pss->page,
page_abs); page_abs);
if (pss->complete_round && pss->block == rs->last_seen_block && if (pss->complete_round && pss->block == rs->last_seen_block &&
(pss->offset >> TARGET_PAGE_BITS) >= rs->last_page) { pss->page >= rs->last_page) {
/* /*
* We've been once around the RAM and haven't found anything. * We've been once around the RAM and haven't found anything.
* Give up. * Give up.
@ -1069,9 +1069,9 @@ static bool find_dirty_block(RAMState *rs, PageSearchStatus *pss,
*again = false; *again = false;
return false; return false;
} }
if (pss->offset >= pss->block->used_length) { if ((pss->page << TARGET_PAGE_BITS) >= pss->block->used_length) {
/* Didn't find anything in this RAM Block */ /* Didn't find anything in this RAM Block */
pss->offset = 0; pss->page = 0;
pss->block = QLIST_NEXT_RCU(pss->block, next); pss->block = QLIST_NEXT_RCU(pss->block, next);
if (!pss->block) { if (!pss->block) {
/* Hit the end of the list */ /* Hit the end of the list */
@ -1193,7 +1193,7 @@ static bool get_queued_page(RAMState *rs, PageSearchStatus *pss,
* it just requested. * it just requested.
*/ */
pss->block = block; pss->block = block;
pss->offset = offset; pss->page = offset >> TARGET_PAGE_BITS;
} }
return !!block; return !!block;
@ -1357,7 +1357,8 @@ static int ram_save_host_page(RAMState *rs, PageSearchStatus *pss,
unsigned long page_abs) unsigned long page_abs)
{ {
int tmppages, pages = 0; int tmppages, pages = 0;
size_t pagesize = qemu_ram_pagesize(pss->block); size_t pagesize_bits =
qemu_ram_pagesize(pss->block) >> TARGET_PAGE_BITS;
do { do {
tmppages = ram_save_target_page(rs, pss, last_stage, page_abs); tmppages = ram_save_target_page(rs, pss, last_stage, page_abs);
@ -1366,12 +1367,12 @@ static int ram_save_host_page(RAMState *rs, PageSearchStatus *pss,
} }
pages += tmppages; pages += tmppages;
pss->offset += TARGET_PAGE_SIZE; pss->page++;
page_abs++; page_abs++;
} while (pss->offset & (pagesize - 1)); } while (pss->page & (pagesize_bits - 1));
/* The offset we leave with is the last one we looked at */ /* The offset we leave with is the last one we looked at */
pss->offset -= TARGET_PAGE_SIZE; pss->page--;
return pages; return pages;
} }
@ -1402,7 +1403,7 @@ static int ram_find_and_save_block(RAMState *rs, bool last_stage)
} }
pss.block = rs->last_seen_block; pss.block = rs->last_seen_block;
pss.offset = rs->last_page << TARGET_PAGE_BITS; pss.page = rs->last_page;
pss.complete_round = false; pss.complete_round = false;
if (!pss.block) { if (!pss.block) {
@ -1424,7 +1425,7 @@ static int ram_find_and_save_block(RAMState *rs, bool last_stage)
} while (!pages && again); } while (!pages && again);
rs->last_seen_block = pss.block; rs->last_seen_block = pss.block;
rs->last_page = pss.offset >> TARGET_PAGE_BITS; rs->last_page = pss.page;
return pages; return pages;
} }