[PATCH 4/5] migration/ram: Return early from save_zero_page

Fabiano Rosas posted 5 patches 2 years, 5 months ago
Maintainers: Juan Quintela <quintela@redhat.com>, Peter Xu <peterx@redhat.com>, Leonardo Bras <leobras@redhat.com>
There is a newer version of this series
[PATCH 4/5] migration/ram: Return early from save_zero_page
Posted by Fabiano Rosas 2 years, 5 months ago
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>
---
 migration/ram.c | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)

diff --git a/migration/ram.c b/migration/ram.c
index a10410a1a5..8ec38f69e8 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -1169,23 +1169,24 @@ static int save_zero_page(RAMState *rs, PageSearchStatus *pss, RAMBlock *block,
 {
     int len = save_zero_page_to_file(pss, block, offset);
 
-    if (len) {
-        stat64_add(&mig_stats.zero_pages, 1);
-        ram_transferred_add(len);
+    if (!len) {
+        return -1;
+    }
 
-        /*
-         * 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();
-        }
+    stat64_add(&mig_stats.zero_pages, 1);
+    ram_transferred_add(len);
 
-        return 1;
+    /*
+     * 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;
 }
 
 /*
-- 
2.35.3
Re: [PATCH 4/5] migration/ram: Return early from save_zero_page
Posted by Peter Xu 2 years, 5 months ago
On Tue, Aug 15, 2023 at 11:38:27AM -0300, Fabiano Rosas wrote:
> 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>
> ---
>  migration/ram.c | 29 +++++++++++++++--------------
>  1 file changed, 15 insertions(+), 14 deletions(-)
> 
> diff --git a/migration/ram.c b/migration/ram.c
> index a10410a1a5..8ec38f69e8 100644
> --- a/migration/ram.c
> +++ b/migration/ram.c
> @@ -1169,23 +1169,24 @@ static int save_zero_page(RAMState *rs, PageSearchStatus *pss, RAMBlock *block,
>  {
>      int len = save_zero_page_to_file(pss, block, offset);
>  
> -    if (len) {
> -        stat64_add(&mig_stats.zero_pages, 1);
> -        ram_transferred_add(len);
> +    if (!len) {
> +        return -1;
> +    }
>  
> -        /*
> -         * 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();
> -        }
> +    stat64_add(&mig_stats.zero_pages, 1);
> +    ram_transferred_add(len);
>  
> -        return 1;
> +    /*
> +     * 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;
>  }

Can we squash this into previous patch?

-- 
Peter Xu