[PATCH RFC v2 10/11] vmstate: Stop checking size for nullptr compression

Peter Xu posted 11 patches 6 days, 21 hours ago
[PATCH RFC v2 10/11] vmstate: Stop checking size for nullptr compression
Posted by Peter Xu 6 days, 21 hours ago
From: Fabiano Rosas <farosas@suse.de>

The NULL pointer marker code applies only to VMS_ARRAY_OF_POINTER,
where the size is never NULL. Move the setting of is_null under
VMS_ARRAY_OF_POINTER, so we can stop checking the size.

Signed-off-by: Fabiano Rosas <farosas@suse.de>
Signed-off-by: Peter Xu <peterx@redhat.com>
---
 migration/vmstate.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/migration/vmstate.c b/migration/vmstate.c
index 9cd0a88ce9..1923602f3b 100644
--- a/migration/vmstate.c
+++ b/migration/vmstate.c
@@ -673,14 +673,14 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VMStateDescription *vmsd,
                 const VMStateField *inner_field;
                 /* maximum number of elements to compress in the JSON blob */
                 int max_elems = vmsd_can_compress(field) ? (n_elems - i) : 1;
-                bool use_marker_field, is_null;
+                bool use_marker_field, is_null = false;
 
                 if (field->flags & VMS_ARRAY_OF_POINTER) {
                     assert(curr_elem);
                     curr_elem = *(void **)curr_elem;
+                    is_null = !curr_elem;
                 }
 
-                is_null = !curr_elem && size;
                 use_marker_field = use_dynamic_array || is_null;
 
                 if (use_marker_field) {
@@ -708,7 +708,7 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VMStateDescription *vmsd,
 
                     for (int j = i + 1; j < n_elems; j++) {
                         void *elem = *(void **)(first_elem + size * j);
-                        bool elem_is_null = !elem && size;
+                        bool elem_is_null = !elem;
 
                         if (is_null != elem_is_null) {
                             max_elems = j - i;
-- 
2.50.1
Re: [PATCH RFC v2 10/11] vmstate: Stop checking size for nullptr compression
Posted by Alexander Mikhalitsyn 1 day, 5 hours ago
Am Do., 26. März 2026 um 22:05 Uhr schrieb Peter Xu <peterx@redhat.com>:
>
> From: Fabiano Rosas <farosas@suse.de>
>
> The NULL pointer marker code applies only to VMS_ARRAY_OF_POINTER,
> where the size is never NULL. Move the setting of is_null under
> VMS_ARRAY_OF_POINTER, so we can stop checking the size.
>
> Signed-off-by: Fabiano Rosas <farosas@suse.de>
> Signed-off-by: Peter Xu <peterx@redhat.com>

Reviewed-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@futurfusion.io>

> ---
>  migration/vmstate.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/migration/vmstate.c b/migration/vmstate.c
> index 9cd0a88ce9..1923602f3b 100644
> --- a/migration/vmstate.c
> +++ b/migration/vmstate.c
> @@ -673,14 +673,14 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VMStateDescription *vmsd,
>                  const VMStateField *inner_field;
>                  /* maximum number of elements to compress in the JSON blob */
>                  int max_elems = vmsd_can_compress(field) ? (n_elems - i) : 1;
> -                bool use_marker_field, is_null;
> +                bool use_marker_field, is_null = false;
>
>                  if (field->flags & VMS_ARRAY_OF_POINTER) {
>                      assert(curr_elem);
>                      curr_elem = *(void **)curr_elem;
> +                    is_null = !curr_elem;
>                  }
>
> -                is_null = !curr_elem && size;
>                  use_marker_field = use_dynamic_array || is_null;
>
>                  if (use_marker_field) {
> @@ -708,7 +708,7 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VMStateDescription *vmsd,
>
>                      for (int j = i + 1; j < n_elems; j++) {
>                          void *elem = *(void **)(first_elem + size * j);
> -                        bool elem_is_null = !elem && size;
> +                        bool elem_is_null = !elem;
>
>                          if (is_null != elem_is_null) {
>                              max_elems = j - i;
> --
> 2.50.1
>