From: Peter Xu <peterx@redhat.com>
To: qemu-devel@nongnu.org
Cc: Alexander Mikhalitsyn <alexander@mihalicyn.com>,
Juraj Marcin <jmarcin@redhat.com>,
Fabiano Rosas <farosas@suse.de>
Subject: Re: [PATCH RFC 04/10] vmstate: Limit the vmdesc_loop dedup trick to compressable field
Date: Thu, 26 Mar 2026 15:27:59 -0400 [thread overview]
Message-ID: <acWIv8ZtxETTlXR_@x1.local> (raw)
In-Reply-To: <20260317232332.15209-5-peterx@redhat.com>
On Tue, Mar 17, 2026 at 07:23:26PM -0400, Peter Xu wrote:
> We have a trick in vmstate_save_vmsd_v() where we will try to compress
> multiple JSON vmstate field dumps into one line with a count to avoid
> duplicated entries.
>
> That only applies to the cases where vmsd_can_compress() should return
> true. For example, vmsd_desc_field_start() later (who will take the
> updated max_elems as the last parameter) will ignore the value passed in
> when vmsd_can_compress() returns false.
>
> Add that check to the trick too, it will be used later to bypass this logic
> to some special new VMSD fields.
>
> No functional change intended in this patch alone.
>
> Signed-off-by: Peter Xu <peterx@redhat.com>
> ---
> migration/vmstate.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/migration/vmstate.c b/migration/vmstate.c
> index e29a8c3f49..caa7b50bce 100644
> --- a/migration/vmstate.c
> +++ b/migration/vmstate.c
> @@ -578,7 +578,8 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VMStateDescription *vmsd,
> }
>
> /*
> - * This logic only matters when dumping VM Desc.
> + * This logic only matters when dumping VM Desc, and only
> + * when the VMSD field can be compressed.
> *
> * Due to the fake nullptr handling above, if there's mixed
> * null/non-null data, it doesn't make sense to emit a
> @@ -587,7 +588,8 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VMStateDescription *vmsd,
> * vs. nullptr). Search ahead for the next null/non-null element
> * and start a new compressed array if found.
> */
> - if (vmdesc && (field->flags & VMS_ARRAY_OF_POINTER) &&
> + if (vmdesc && vmsd_can_compress(field) &&
> + (field->flags & VMS_ARRAY_OF_POINTER) &&
> is_null != is_prev_null) {
>
> is_prev_null = is_null;
> --
> 2.50.1
>
This patch unfortunately stops working when I start to test
analyze-migration.py. I plan to use another similar patch below to replace
this one:
From e72df6470e64715caaf3857a899fe63086bf4628 Mon Sep 17 00:00:00 2001
From: Peter Xu <peterx@redhat.com>
Date: Tue, 17 Mar 2026 19:23:26 -0400
Subject: [PATCH] vmstate: Update max_elems early and check field compressable
once
QEMU has a trick in vmstate_save_vmsd_v(), where it will try to compress
multiple JSON entries into one with a count to avoid duplicated entries.
That only applies to the cases where vmsd_can_compress() should return
true. For example, vmsd_desc_field_start() later (who will take the
updated max_elems as the last parameter) will ignore the value passed in
when vmsd_can_compress() returns false.
Do that check once at the start of loop, and use it to update max_elems, so
that max_elems keeps 1 for uncompressable VMSD fields, which is more
straightforward.
This also paves way to make this counter work for ptr marker VMSD fields
too.
No functional change intended in this patch alone.
Signed-off-by: Peter Xu <peterx@redhat.com>
---
migration/vmstate.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/migration/vmstate.c b/migration/vmstate.c
index e29a8c3f49..05badef42f 100644
--- a/migration/vmstate.c
+++ b/migration/vmstate.c
@@ -556,7 +556,8 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VMStateDescription *vmsd,
void *curr_elem = first_elem + size * i;
const VMStateField *inner_field;
bool is_null;
- int max_elems = n_elems - i;
+ /* maximum number of elements to compress in the JSON blob */
+ int max_elems = vmsd_can_compress(field) ? (n_elems - i) : 1;
old_offset = qemu_file_transferred(f);
if (field->flags & VMS_ARRAY_OF_POINTER) {
@@ -587,7 +588,8 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VMStateDescription *vmsd,
* vs. nullptr). Search ahead for the next null/non-null element
* and start a new compressed array if found.
*/
- if (vmdesc && (field->flags & VMS_ARRAY_OF_POINTER) &&
+ if (vmdesc && max_elems > 1 &&
+ (field->flags & VMS_ARRAY_OF_POINTER) &&
is_null != is_prev_null) {
is_prev_null = is_null;
@@ -626,7 +628,7 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VMStateDescription *vmsd,
}
/* Compressed arrays only care about the first element */
- if (vmdesc_loop && vmsd_can_compress(field)) {
+ if (vmdesc_loop && max_elems > 1) {
vmdesc_loop = NULL;
}
}
--
2.50.1
--
Peter Xu
next prev parent reply other threads:[~2026-03-26 19:28 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-17 23:23 [PATCH RFC 00/10] vmstate: Implement VMS_ARRAY_OF_POINTER_AUTO_ALLOC Peter Xu
2026-03-17 23:23 ` [PATCH RFC 01/10] vmstate: Pass in struct itself for VMSTATE_ARRAY_OF_POINTER Peter Xu
2026-03-18 9:36 ` Alexander Mikhalitsyn
2026-03-17 23:23 ` [PATCH RFC 02/10] vmstate: Pass in struct itself for VMSTATE_VARRAY_OF_POINTER_UINT32 Peter Xu
2026-03-18 9:37 ` Alexander Mikhalitsyn
2026-03-17 23:23 ` [PATCH RFC 03/10] vmstate: Do not set size for VMS_ARRAY_OF_POINTER Peter Xu
2026-03-18 9:37 ` Alexander Mikhalitsyn
2026-03-17 23:23 ` [PATCH RFC 04/10] vmstate: Limit the vmdesc_loop dedup trick to compressable field Peter Xu
2026-03-18 9:43 ` Alexander Mikhalitsyn
2026-03-26 19:27 ` Peter Xu [this message]
2026-03-17 23:23 ` [PATCH RFC 05/10] vmstate: Rename VMS_NULLPTR_MARKER to VMS_MARKER_PTR_NULL Peter Xu
2026-03-18 9:38 ` Alexander Mikhalitsyn
2026-03-17 23:23 ` [PATCH RFC 06/10] vmstate: Introduce vmstate_save_field_with_vmdesc() Peter Xu
2026-03-18 9:39 ` Alexander Mikhalitsyn
2026-03-19 20:36 ` Fabiano Rosas
2026-03-17 23:23 ` [PATCH RFC 07/10] vmstate: Allow vmstate_info_nullptr to emit non-NULL markers Peter Xu
2026-03-18 9:40 ` Alexander Mikhalitsyn
2026-03-19 20:46 ` Fabiano Rosas
2026-03-26 19:25 ` Peter Xu
2026-03-26 21:19 ` Fabiano Rosas
2026-03-17 23:23 ` [PATCH RFC 08/10] vmstate: Implement load of ptr marker in vmstate core Peter Xu
2026-03-18 9:48 ` Alexander Mikhalitsyn
2026-03-19 20:56 ` Fabiano Rosas
2026-03-19 21:57 ` Peter Xu
2026-03-19 22:07 ` Alexander Graf
2026-03-20 13:03 ` Fabiano Rosas
2026-03-20 14:51 ` Peter Xu
2026-03-17 23:23 ` [PATCH RFC 09/10] vmstate: Implement VMS_ARRAY_OF_POINTER_AUTO_ALLOC Peter Xu
2026-03-18 10:00 ` Alexander Mikhalitsyn
2026-03-19 14:10 ` Peter Xu
2026-03-19 22:06 ` Fabiano Rosas
2026-03-20 14:42 ` Fabiano Rosas
2026-03-20 15:37 ` Peter Xu
2026-03-17 23:23 ` [PATCH RFC 10/10] tests/unit/test-vmstate: add tests for VMS_ARRAY_OF_POINTER_ALLOW_NULL Peter Xu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=acWIv8ZtxETTlXR_@x1.local \
--to=peterx@redhat.com \
--cc=alexander@mihalicyn.com \
--cc=farosas@suse.de \
--cc=jmarcin@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox