Compare commits

...

5 Commits

Author SHA1 Message Date
Fabiano Rosas
a7e7f47f14 migration/ram: Merge save_zero_page functions
We don't need to do this in two pieces. One single function makes it
easier to grasp, specially since it removes the indirection on the
return value handling.

Signed-off-by: Fabiano Rosas <farosas@suse.de>
2023-08-15 10:31:44 -03:00
Fabiano Rosas
fe9a3b860a migration/ram: Return early from save_zero_page
Invert the first conditional so we return early when len == 0. This is
merely to make the next patch easier to read.

Signed-off-by: Fabiano Rosas <farosas@suse.de>
2023-08-15 10:31:42 -03:00
Fabiano Rosas
ea9609508e migration/ram: Move xbzrle zero page handling into save_zero_page
It makes a bit more sense to have the zero page handling of xbzrle
right where we save the zero page.

This also makes save_zero_page() follow the same format as
save_compress_page() at the top level of
ram_save_target_page_legacy().

Signed-off-by: Fabiano Rosas <farosas@suse.de>
2023-08-15 10:31:05 -03:00
Fabiano Rosas
9137628939 migration/ram: Stop passing QEMUFile around in save_zero_page
We don't need the QEMUFile when we're already passing the
PageSearchStatus.

Signed-off-by: Fabiano Rosas <farosas@suse.de>
2023-08-14 16:33:31 -03:00
Fabiano Rosas
91d8ade20c migration/ram: Remove RAMState from xbzrle_cache_zero_page
'rs' is not used in that function. It's a leftover from commit
9360447d34 ("ram: Use MigrationStats for statistics").

Signed-off-by: Fabiano Rosas <farosas@suse.de>
2023-08-14 16:21:10 -03:00

View File

@@ -561,7 +561,6 @@ void mig_throttle_counter_reset(void)
/**
* xbzrle_cache_zero_page: insert a zero page in the XBZRLE cache
*
* @rs: current RAM state
* @current_addr: address for the zero page
*
* Update the xbzrle cache to reflect a page that's been sent as all 0.
@@ -570,7 +569,7 @@ void mig_throttle_counter_reset(void)
* As a bonus, if the page wasn't in the cache it gets added so that
* when a small write is made into the 0'd page it gets XBZRLE sent.
*/
static void xbzrle_cache_zero_page(RAMState *rs, ram_addr_t current_addr)
static void xbzrle_cache_zero_page(ram_addr_t current_addr)
{
/* We don't care if this fails to allocate a new cache page
* as long as it updated an old one */
@@ -1129,51 +1128,46 @@ void ram_release_page(const char *rbname, uint64_t offset)
ram_discard_range(rbname, offset, TARGET_PAGE_SIZE);
}
/**
* save_zero_page_to_file: send the zero page to the file
*
* Returns the size of data written to the file, 0 means the page is not
* a zero page
*
* @pss: current PSS channel
* @block: block that contains the page we want to send
* @offset: offset inside the block for the page
*/
static int save_zero_page_to_file(PageSearchStatus *pss, QEMUFile *file,
RAMBlock *block, ram_addr_t offset)
{
uint8_t *p = block->host + offset;
int len = 0;
if (buffer_is_zero(p, TARGET_PAGE_SIZE)) {
len += save_page_header(pss, file, block, offset | RAM_SAVE_FLAG_ZERO);
qemu_put_byte(file, 0);
len += 1;
ram_release_page(block->idstr, offset);
}
return len;
}
/**
* save_zero_page: send the zero page to the stream
*
* Returns the number of pages written.
*
* @rs: current RAM state
* @pss: current PSS channel
* @block: block that contains the page we want to send
* @offset: offset inside the block for the page
*/
static int save_zero_page(PageSearchStatus *pss, QEMUFile *f, RAMBlock *block,
static int save_zero_page(RAMState *rs, PageSearchStatus *pss, RAMBlock *block,
ram_addr_t offset)
{
int len = save_zero_page_to_file(pss, f, block, offset);
uint8_t *p = block->host + offset;
QEMUFile *file = pss->pss_channel;
int len = 0;
if (len) {
stat64_add(&mig_stats.zero_pages, 1);
ram_transferred_add(len);
return 1;
if (!buffer_is_zero(p, TARGET_PAGE_SIZE)) {
return 0;
}
return -1;
len += save_page_header(pss, file, block, offset | RAM_SAVE_FLAG_ZERO);
qemu_put_byte(file, 0);
len += 1;
ram_release_page(block->idstr, offset);
stat64_add(&mig_stats.zero_pages, 1);
ram_transferred_add(len);
/*
* Must let xbzrle know, otherwise a previous (now 0'd) cached
* page would be stale.
*/
if (rs->xbzrle_started) {
XBZRLE_cache_lock();
xbzrle_cache_zero_page(block->offset + offset);
XBZRLE_cache_unlock();
}
return len;
}
/*
@@ -2141,17 +2135,8 @@ static int ram_save_target_page_legacy(RAMState *rs, PageSearchStatus *pss)
return 1;
}
res = save_zero_page(pss, pss->pss_channel, block, offset);
if (res > 0) {
/* Must let xbzrle know, otherwise a previous (now 0'd) cached
* page would be stale
*/
if (rs->xbzrle_started) {
XBZRLE_cache_lock();
xbzrle_cache_zero_page(rs, block->offset + offset);
XBZRLE_cache_unlock();
}
return res;
if (save_zero_page(rs, pss, block, offset)) {
return 1;
}
/*