Message ID | 20230815143828.15436-4-farosas@suse.de |
---|---|
State | New |
Headers | show |
Series | migration/ram: Merge zero page handling | expand |
On Tue, Aug 15, 2023 at 11:38:26AM -0300, Fabiano Rosas wrote: > 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> Reviewed-by: Peter Xu <peterx@redhat.com>
Fabiano Rosas <farosas@suse.de> writes: > 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> > --- > migration/ram.c | 27 +++++++++++++++------------ > 1 file changed, 15 insertions(+), 12 deletions(-) > > diff --git a/migration/ram.c b/migration/ram.c > index 761f43dc34..a10410a1a5 100644 > --- a/migration/ram.c > +++ b/migration/ram.c > @@ -1159,11 +1159,12 @@ static int save_zero_page_to_file(PageSearchStatus *pss, RAMBlock *block, > * > * 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, 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, block, offset); > @@ -1171,6 +1172,17 @@ static int save_zero_page(PageSearchStatus *pss, RAMBlock *block, > if (len) { > 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 1; > } > return -1; > @@ -2141,17 +2153,8 @@ static int ram_save_target_page_legacy(RAMState *rs, PageSearchStatus *pss) > return 1; > } > > - res = save_zero_page(pss, block, offset); > - if (res > 0) { These two subtractions should be in patch 5. > - /* 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 res; > + if (save_zero_page(rs, pss, block, offset)) { > + return 1; These two additions should be in patch 5. > } > > /*
diff --git a/migration/ram.c b/migration/ram.c index 761f43dc34..a10410a1a5 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1159,11 +1159,12 @@ static int save_zero_page_to_file(PageSearchStatus *pss, RAMBlock *block, * * 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, 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, block, offset); @@ -1171,6 +1172,17 @@ static int save_zero_page(PageSearchStatus *pss, RAMBlock *block, if (len) { 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 1; } return -1; @@ -2141,17 +2153,8 @@ static int ram_save_target_page_legacy(RAMState *rs, PageSearchStatus *pss) return 1; } - res = save_zero_page(pss, 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(block->offset + offset); - XBZRLE_cache_unlock(); - } - return res; + if (save_zero_page(rs, pss, block, offset)) { + return 1; } /*
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> --- migration/ram.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-)