Next round of migration atomic counters
cover Next round of migration atomic counters
Hi
On this series:
- Make sure that qemu_file_transferred() make sense and its used coherently
- Use stat64 for qemu_file_transferred(), so we can call the function from any thread.
- Don't account for the same transfer twice (i.e. it is multifd_bytes, rdma_bytes or qemu_file_bytes) qemu_file_transferred() just sums all of them.
- Use this new counter for rate_limit()
- Remove old trasferred stat64 (now we use the real thing)
- Simplify qemu_file_get_error(): see where next cleanups are coming
- As an example, qemu_fflush() now return errors.
Please review.
Later, Juan.
Based-on: Message-Id: <[email protected]>
Subject: [PULL 00/21] Migration 20230530 patches
Juan Quintela (16):
qemu-file: Rename qemu_file_transferred_ fast -> noflush
migration: Change qemu_file_transferred to noflush
migration: Use qemu_file_transferred_noflush() for block migration.
qemu-file: Don't call qemu_fflush() for read only files
qemu-file: We only call qemu_file_transferred_* on the sending side
qemu_file: Use a stat64 for qemu_file_transferred
qemu_file: total_transferred is not used anymore
migration: Use the number of transferred bytes directly
qemu_file: Remove unused qemu_file_transferred()
qemu-file: Remove _noflush from qemu_file_transferred_noflush()
migration: migration_transferred_bytes() don't need the QEMUFile
migration: migration_rate_limit_reset() don't need the QEMUFile
qemu-file: Simplify qemu_file_get_error()
migration: Use migration_transferred_bytes()
migration: Remove transferred atomic counter
qemu-file: Make qemu_fflush() return errors
migration/migration-stats.h | 16 ++++++---------- migration/qemu-file.h | 29 +++++------------------------ migration/colo.c | 11 +++-------- migration/migration-stats.c | 10 +++++----- migration/migration.c | 17 ++++++----------- migration/multifd.c | 3 --- migration/qemu-file.c | 35 ++++++++++++++--------------------- migration/ram.c | 29 ++++++++++------------------- migration/rdma.c | 4 +--- migration/savevm.c | 7 +++---- migration/vmstate.c | 4 ++-- 11 files changed, 55 insertions(+), 110 deletions(-)
Signature · 1 line
2.40.1
PATCH 1/16 qemu-file: Rename qemu_file_transferred_ fast -> noflush
Fast don't say much. Noflush indicates more clearly that it is like qemu_file_transferred but without the flush.
--- migration/qemu-file.h | 11 +++++------ migration/qemu-file.c | 2 +- migration/savevm.c | 4 ++-- migration/vmstate.c | 4 ++-- 4 files changed, 10 insertions(+), 11 deletions(-)
migration/qemu-file.h +5 -6
@@ -52,16 +52,15 @@ int qemu_fclose(QEMUFile *f);uint64_t qemu_file_transferred (QEMUFile *f);/* -* qemu_file_transferred_fast: +* qemu_file_transferred_noflush: * -* As qemu_file_transferred except for writable -* files, where no flush is performed and the reported -* amount will include the size of any queued buffers, -* on top of the amount actually transferred. +* As qemu_file_transferred except for writable files, where no flush +* is performed and the reported amount will include the size of any +* queued buffers, on top of the amount actually transferred. * * Returns: the total bytes transferred and queued */ -uint64_t qemu_file_transferred_fast (QEMUFile *f); +uint64_t qemu_file_transferred_noflush (QEMUFile *f);/* * put_buffer without copying the buffer.
migration/qemu-file.c +1 -1
@@ -627,7 +627,7 @@ int coroutine_mixed_fn qemu_get_byte(QEMUFile *f)return result; } -uint64_t qemu_file_transferred_fast (QEMUFile *f) +uint64_t qemu_file_transferred_noflush (QEMUFile *f) {uint64_t ret = f->total_transferred;int i;
migration/savevm.c +2 -2
@@ -927,9 +927,9 @@ static int vmstate_load(QEMUFile *f, SaveStateEntry *se)static void vmstate_save_old_style (QEMUFile *f,SaveStateEntry *se,JSONWriter *vmdesc) { -uint64_t old_offset =qemu_file_transferred_fast (f); +uint64_t old_offset =qemu_file_transferred_noflush (f); se->ops->save_state (f, se->opaque); -uint64_t size =qemu_file_transferred_fast (f) - old_offset; +uint64_t size =qemu_file_transferred_noflush (f) - old_offset;if (vmdesc) {json_writer_int64 (vmdesc,"size" , size);
migration/vmstate.c +2 -2
@@ -361,7 +361,7 @@ int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd,void *curr_elem = first_elem + size * i;vmsd_desc_field_start (vmsd, vmdesc_loop, field, i, n_elems); - old_offset =qemu_file_transferred_fast (f); + old_offset =qemu_file_transferred_noflush (f);if (field->flags &VMS_ARRAY_OF_POINTER ) {assert (curr_elem); curr_elem = *(void **)curr_elem;
@@ -391,7 +391,7 @@ int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd,return ret; } - written_bytes =qemu_file_transferred_fast (f) - old_offset; + written_bytes =qemu_file_transferred_noflush (f) - old_offset;vmsd_desc_field_end (vmsd, vmdesc_loop, field, written_bytes, i);/* Compressed arrays only care about the first element */
Signature · 1 line
2.40.1
Re: [PATCH 01/16] qemu-file: Rename qemu_file_transferred_ fast -> noflush
Quoted 10 lines · Juan Quintela
Fast don't say much. Noflush indicates more clearly that it is like
qemu_file_transferredbut without the flush.Signed-off-by Juan Quintela <[email protected]>--- migration/qemu-file.h | 11 +++++------ migration/qemu-file.c | 2 +- migration/savevm.c | 4 ++-- migration/vmstate.c | 4 ++-- 4 files changed, 10 insertions(+), 11 deletions(-)
To clarify further, qemu_file_transferred() could be renamed as qemu_file_transferred_flush[ed]().
Re: [PATCH 01/16] qemu-file: Rename qemu_file_transferred_ fast -> noflush
Quoted 12 lines · Philippe Mathieu-Daudé
Quoted 10 lines · Juan Quintela
Fast don't say much. Noflush indicates more clearly that it is like
qemu_file_transferredbut without the flush.Signed-off-by Juan Quintela <[email protected]>---
migration/qemu-file.h| 11 +++++------
migration/qemu-file.c| 2 +-
migration/savevm.c | 4 ++--
migration/vmstate.c | 4 ++--4 files changed, 10 insertions(+), 11 deletions(-)
Quoted 2 lines
To clarify further,
qemu_file_transferred()could be renamed as qemu_file_transferred_flush[ed]().
Never mind, it gets removed later in this series.
PATCH 2/16 migration: Change qemu_file_transferred to noflush
In reply to Juan QuintelaWe do a qemu_fclose() just after that, that also does a qemu_fflush(), so remove one qemu_fflush().
--- migration/savevm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
migration/savevm.c +1 -1
@@ -2952,7 +2952,7 @@ bool save_snapshot(const char *name, bool overwrite, const char *vmstate, goto the_end; } ret =qemu_savevm_state (f, errp); - vm_state_size =qemu_file_transferred (f); + vm_state_size =qemu_file_transferred_noflush (f); ret2 =qemu_fclose (f);if (ret <0 ) { goto the_end;
Signature · 1 line
2.40.1
Re: [PATCH 02/16] migration: Change qemu_file_transferred to noflush
Quoted 7 lines · Juan Quintela
We do a
qemu_fclose()just after that, that also does aqemu_fflush(), so remove oneqemu_fflush().Signed-off-by Juan Quintela <[email protected]>--- migration/savevm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
PATCH 3/16 migration: Use qemu_file_transferred_noflush() for block migration.
In reply to Juan QuintelaWe only care about the amount of bytes transferred. Flushing is done by the system somewhere else.
--- migration/block.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
migration/block.c +2 -2
@@ -748,7 +748,7 @@ static int block_save_setup(QEMUFile *f, void *opaque)static int block_save_iterate (QEMUFile *f,void *opaque) {int ret; -uint64_t last_bytes =qemu_file_transferred (f); +uint64_t last_bytes =qemu_file_transferred_noflush (f);trace_migration_block_save ("iterate" , block_mig_state.submitted, block_mig_state.transferred);
@@ -800,7 +800,7 @@ static int block_save_iterate(QEMUFile *f, void *opaque) }qemu_put_be64 (f,BLK_MIG_FLAG_EOS ); -uint64_t delta_bytes =qemu_file_transferred (f) - last_bytes; +uint64_t delta_bytes =qemu_file_transferred_noflush (f) - last_bytes;return (delta_bytes >0 ); }
Signature · 1 line
2.40.1
Re: [PATCH 03/16] migration: Use qemu_file_transferred_noflush() for block migration.
Quoted 4 lines · Juan Quintela
We only care about the amount of bytes transferred. Flushing is done by the system somewhere else.
Signed-off-by Juan Quintela <[email protected]>
PATCH 4/16 qemu-file: Don't call qemu_fflush() for read only files
In reply to Juan QuintelaThis was the only caller for read only files. So change the test for an assert in qemu_fflush().
--- migration/qemu-file.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
migration/qemu-file.c +4 -4
@@ -272,9 +272,7 @@ static void qemu_iovec_release_ram(QEMUFile *f)*/ void qemu_fflush (QEMUFile *f) { -if (!qemu_file_is_writable (f)) { -return ; - } +g_assert (qemu_file_is_writable (f));if (qemu_file_get_error (f)) {return ;
@@ -363,7 +361,9 @@ static ssize_t coroutine_mixed_fn qemu_fill_buffer(QEMUFile *f)int qemu_fclose (QEMUFile *f) {int ret, ret2; -qemu_fflush (f); +if (qemu_file_is_writable (f)) { +qemu_fflush (f); + } ret =qemu_file_get_error (f); ret2 =qio_channel_close (f->ioc,NULL );
Signature · 1 line
2.40.1
Re: [PATCH 04/16] qemu-file: Don't call qemu_fflush() for read only files
Quoted 4 lines · Juan Quintela
This was the only caller for read only files. So change the test for an assert in
qemu_fflush().Signed-off-by Juan Quintela <[email protected]>
Re: [PATCH 04/16] qemu-file: Don't call qemu_fflush() for read only files
In reply to Juan QuintelaQuoted 2 lines · Juan Quintela
This was the only caller for read only files. So change the test for an assert in
qemu_fflush().
Not a fan, as fflush(stdin) is well-defined.
r~
Re: [PATCH 04/16] qemu-file: Don't call qemu_fflush() for read only files
Quoted 6 lines · Richard Henderson
Quoted 2 lines · Juan Quintela
This was the only caller for read only files. So change the test for an assert in
qemu_fflush().Not a fan, as fflush(stdin) is well-defined.
I guess you mean this:
For input streams associated with seekable files (e.g., disk files, but not pipes or terminals), fflush() discards any buffered data that has been fetched from the underlying file, but has not been consumed by the application.
Two things:
- Current code just do nothing for imput streams
- We only call it from qemu_fclose()
- If we drop anything from the input stream, migration get broken.
If it makes you feel better, I can rename the function to qemu_file_write_buffer() or whatever name your preffer.
Later, Juan.
Re: [PATCH 04/16] qemu-file: Don't call qemu_fflush() for read only files
Quoted 6 lines · Juan Quintela
Quoted 5 lines · Richard Henderson
Quoted 2 lines · Juan Quintela
This was the only caller for read only files. So change the test for an assert in
qemu_fflush().
Quoted 8 lines
Quoted 1 line
Not a fan, as fflush(stdin) is well-defined.
I guess you mean this:
For input streams associated with seekable files (e.g., disk files, but not pipes or terminals),
fflush()discards any buffered data that has been fetched from the underlying file, but has not been consumed by the application.
Yes, in that, importantly, it does not assert.
Quoted 4 lines
Two things:
- Current code just do nothing for imput streams
- We only call it fromqemu_fclose()
Pardon? There are nearly 30 calls to qemu_fflush.
Quoted 1 line
- If we drop anything from the input stream, migration get broken.
I'm not talking about dropping anything. Obviously QEMUFile works different from stdio, and therefore resetting the file state to that of the unbuffered data is not relevant.
r~
Re: [PATCH 04/16] qemu-file: Don't call qemu_fflush() for read only files
Quoted 8 lines · Richard Henderson
Quoted 7 lines · Juan Quintela
Quoted 6 lines · Richard Henderson
Quoted 2 lines · Juan Quintela
This was the only caller for read only files. So change the test for an assert in
qemu_fflush().Not a fan, as fflush(stdin) is well-defined.
Quoted 8 lines
Quoted 6 lines
I guess you mean this:
For input streams associated with seekable files (e.g., disk
files, but
not pipes or terminals),fflush()discards any buffered data that has been fetched from the underlying file, but has not been consumed by the application.Yes, in that, importantly, it does not assert.
I can let it do nothing if it makes you feel better.
Quoted 5 lines
Quoted 3 lines
Two things:
- Current code just do nothing for imput streams
- We only call it fromqemu_fclose()Pardon? There are nearly 30 calls to
qemu_fflush.
None of them in a file that is not open for writting.
Quoted 5 lines
Quoted 1 line
- If we drop anything from the input stream, migration get broken.
I'm not talking about dropping anything. Obviously QEMUFile works different from stdio, and therefore resetting the file state to that of the unbuffered data is not relevant.
Ok, if you feel so strong, I will change the assert() to a check that does nothing.
Later, Juan.
Re: [PATCH 04/16] qemu-file: Don't call qemu_fflush() for read only files
In reply to Juan QuintelaQuoted 4 lines · Juan Quintela
This was the only caller for read only files. So change the test for an assert in
qemu_fflush().Signed-off-by Juan Quintela <[email protected]>
Drop this patch.
As Richard has strong opinions about calling fflush() on input streams. I still think that it makes zero sense to call it on a migration input stream.
But I don't care enough to fight this battle O:-)
Later, Juan.
PATCH 5/16 qemu-file: We only call qemu_file_transferred_* on the sending side
In reply to Juan QuintelaRemove the increase in qemu_file_fill_buffer() and add asserts to qemu_file_transferred* functions.
--- migration/qemu-file.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
migration/qemu-file.c +3 -1
@@ -340,7 +340,6 @@ static ssize_t coroutine_mixed_fn qemu_fill_buffer(QEMUFile *f)if (len >0 ) { f->buf_size += len; - f->total_transferred += len; }else if (len ==0 ) {qemu_file_set_error_obj (f, -EIO , local_error); }else {
@@ -632,6 +631,8 @@ uint64_t qemu_file_transferred_noflush(QEMUFile *f)uint64_t ret = f->total_transferred;int i; +g_assert (qemu_file_is_writable (f)); +for (i =0 ; i < f->iovcnt; i++) { ret += f->iov[i].iov_len; }
@@ -641,6 +642,7 @@ uint64_t qemu_file_transferred_noflush(QEMUFile *f)uint64_t qemu_file_transferred (QEMUFile *f) { +g_assert (qemu_file_is_writable (f));qemu_fflush (f);return f->total_transferred; }
Signature · 1 line
2.40.1
PATCH 6/16 qemu_file: Use a stat64 for qemu_file_transferred
In reply to Juan QuintelaThis way we can read it from any thread.
I checked that it gives the same value than the current one. We never use to qemu_files at the same time.
--- migration/migration-stats.h | 4 ++++ migration/qemu-file.c | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-)
migration/migration-stats.h +4 -0
@@ -81,6 +81,10 @@ typedef struct {* Number of bytes sent during precopy stage. */ Stat64 precopy_bytes; +/* +* Number of bytes transferred with QEMUFile. +*/ +Stat64 qemu_file_transferred;/* * Amount of transferred data at the start of current cycle. */
migration/qemu-file.c +3 -2
@@ -286,6 +286,7 @@ void qemu_fflush(QEMUFile *f) }else {uint64_t size =iov_size (f->iov, f->iovcnt); f->total_transferred += size; +stat64_add (&mig_stats.qemu_file_transferred, size); }qemu_iovec_release_ram (f);
@@ -628,7 +629,7 @@ int coroutine_mixed_fn qemu_get_byte(QEMUFile *f)uint64_t qemu_file_transferred_noflush (QEMUFile *f) { -uint64_t ret = f->total_transferred; +uint64_t ret =stat64_get (&mig_stats.qemu_file_transferred);int i;g_assert (qemu_file_is_writable (f));
@@ -644,7 +645,7 @@ uint64_t qemu_file_transferred(QEMUFile *f) {g_assert (qemu_file_is_writable (f));qemu_fflush (f); -return f->total_transferred; +return stat64_get (&mig_stats.qemu_file_transferred); }void qemu_put_be16 (QEMUFile *f,unsigned int v)
Signature · 1 line
2.40.1
PATCH 7/16 qemu_file: total_transferred is not used anymore
In reply to Juan Quintela--- migration/qemu-file.c | 4 ---- 1 file changed, 4 deletions(-)
migration/qemu-file.c +0 -4
@@ -41,9 +41,6 @@ struct QEMUFile {QIOChannel *ioc;bool is_writable; -/* The sum of bytes transferred on the wire */ -uint64_t total_transferred; -int buf_index;int buf_size;/* 0 when writing */ uint8_t buf[IO_BUF_SIZE ];
@@ -285,7 +282,6 @@ void qemu_fflush(QEMUFile *f)qemu_file_set_error_obj (f, -EIO , local_error); }else {uint64_t size =iov_size (f->iov, f->iovcnt); - f->total_transferred += size;stat64_add (&mig_stats.qemu_file_transferred, size); }
Signature · 1 line
2.40.1
PATCH 8/16 migration: Use the number of transferred bytes directly
In reply to Juan QuintelaWe only use migration_transferred_bytes() to calculate the rate_limit, for that we don't need to flush whatever is on the qemu_file buffer. Remember that the buffer is really small (normal case is 32K if we use iov's can be 64 * TARGET_PAGE_SIZE), so this is not relevant to calculations.
--- migration/migration-stats.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
migration/migration-stats.c +1 -1
@@ -62,7 +62,7 @@ uint64_t migration_transferred_bytes(QEMUFile *f) {uint64_t multifd =stat64_get (&mig_stats.multifd_bytes);uint64_t rdma =stat64_get (&mig_stats.rdma_bytes); -uint64_t qemu_file =qemu_file_transferred (f); +uint64_t qemu_file =stat64_get (&mig_stats.qemu_file_transferred);trace_migration_transferred_bytes (qemu_file, multifd, rdma);return qemu_file + multifd + rdma;
Signature · 1 line
2.40.1
PATCH 9/16 qemu_file: Remove unused qemu_file_transferred()
In reply to Juan Quintela--- migration/qemu-file.h | 18 ------------------ migration/qemu-file.c | 7 ------- 2 files changed, 25 deletions(-)
migration/qemu-file.h +0 -18
@@ -33,24 +33,6 @@ QEMUFile *qemu_file_new_input(QIOChannel *ioc);QEMUFile *qemu_file_new_output (QIOChannel *ioc);int qemu_fclose (QEMUFile *f); -/* -* qemu_file_transferred: -* -* Report the total number of bytes transferred with -* this file. -* -* For writable files, any pending buffers will be -* flushed, so the reported value will be equal to -* the number of bytes transferred on the wire. -* -* For readable files, the reported value will be -* equal to the number of bytes transferred on the -* wire. -* -* Returns: the total bytes transferred -*/ -uint64_t qemu_file_transferred (QEMUFile *f); -/* * qemu_file_transferred_noflush: *
migration/qemu-file.c +0 -7
@@ -637,13 +637,6 @@ uint64_t qemu_file_transferred_noflush(QEMUFile *f)return ret; } -uint64_t qemu_file_transferred (QEMUFile *f) -{ -g_assert (qemu_file_is_writable (f)); -qemu_fflush (f); -return stat64_get (&mig_stats.qemu_file_transferred); -} -void qemu_put_be16 (QEMUFile *f,unsigned int v) {qemu_put_byte (f, v >>8 );
Signature · 1 line
2.40.1
PATCH 10/16 qemu-file: Remove _noflush from qemu_file_transferred_noflush()
In reply to Juan Quintelaqemu_file_transferred() don't exist anymore, so we can reuse the name.
--- migration/qemu-file.h | 4 ++-- migration/block.c | 4 ++-- migration/qemu-file.c | 2 +- migration/savevm.c | 6 +++--- migration/vmstate.c | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-)
migration/qemu-file.h +2 -2
@@ -34,7 +34,7 @@ QEMUFile *qemu_file_new_output(QIOChannel *ioc);int qemu_fclose (QEMUFile *f);/* -* qemu_file_transferred_noflush: +* qemu_file_transferred: * * As qemu_file_transferred except for writable files, where no flush * is performed and the reported amount will include the size of any
@@ -42,7 +42,7 @@ int qemu_fclose(QEMUFile *f);* * Returns: the total bytes transferred and queued */ -uint64_t qemu_file_transferred_noflush (QEMUFile *f); +uint64_t qemu_file_transferred (QEMUFile *f);/* * put_buffer without copying the buffer.
migration/block.c +2 -2
@@ -748,7 +748,7 @@ static int block_save_setup(QEMUFile *f, void *opaque)static int block_save_iterate (QEMUFile *f,void *opaque) {int ret; -uint64_t last_bytes =qemu_file_transferred_noflush (f); +uint64_t last_bytes =qemu_file_transferred (f);trace_migration_block_save ("iterate" , block_mig_state.submitted, block_mig_state.transferred);
@@ -800,7 +800,7 @@ static int block_save_iterate(QEMUFile *f, void *opaque) }qemu_put_be64 (f,BLK_MIG_FLAG_EOS ); -uint64_t delta_bytes =qemu_file_transferred_noflush (f) - last_bytes; +uint64_t delta_bytes =qemu_file_transferred (f) - last_bytes;return (delta_bytes >0 ); }
migration/qemu-file.c +1 -1
@@ -623,7 +623,7 @@ int coroutine_mixed_fn qemu_get_byte(QEMUFile *f)return result; } -uint64_t qemu_file_transferred_noflush (QEMUFile *f) +uint64_t qemu_file_transferred (QEMUFile *f) {uint64_t ret =stat64_get (&mig_stats.qemu_file_transferred);int i;
migration/savevm.c +3 -3
@@ -927,9 +927,9 @@ static int vmstate_load(QEMUFile *f, SaveStateEntry *se)static void vmstate_save_old_style (QEMUFile *f,SaveStateEntry *se,JSONWriter *vmdesc) { -uint64_t old_offset =qemu_file_transferred_noflush (f); +uint64_t old_offset =qemu_file_transferred (f); se->ops->save_state (f, se->opaque); -uint64_t size =qemu_file_transferred_noflush (f) - old_offset; +uint64_t size =qemu_file_transferred (f) - old_offset;if (vmdesc) {json_writer_int64 (vmdesc,"size" , size);
@@ -2952,7 +2952,7 @@ bool save_snapshot(const char *name, bool overwrite, const char *vmstate, goto the_end; } ret =qemu_savevm_state (f, errp); - vm_state_size =qemu_file_transferred_noflush (f); + vm_state_size =qemu_file_transferred (f); ret2 =qemu_fclose (f);if (ret <0 ) { goto the_end;
migration/vmstate.c +2 -2
@@ -361,7 +361,7 @@ int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd,void *curr_elem = first_elem + size * i;vmsd_desc_field_start (vmsd, vmdesc_loop, field, i, n_elems); - old_offset =qemu_file_transferred_noflush (f); + old_offset =qemu_file_transferred (f);if (field->flags &VMS_ARRAY_OF_POINTER ) {assert (curr_elem); curr_elem = *(void **)curr_elem;
@@ -391,7 +391,7 @@ int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd,return ret; } - written_bytes =qemu_file_transferred_noflush (f) - old_offset; + written_bytes =qemu_file_transferred (f) - old_offset;vmsd_desc_field_end (vmsd, vmdesc_loop, field, written_bytes, i);/* Compressed arrays only care about the first element */
Signature · 1 line
2.40.1
Re: [PATCH 10/16] qemu-file: Remove _noflush from qemu_file_transferred_noflush()
Quoted 16 lines · Juan Quintela
qemu_file_transferred()don't exist anymore, so we can reuse the name.Signed-off-by Juan Quintela <[email protected]>--- migration/qemu-file.h | 4 ++-- migration/block.c | 4 ++-- migration/qemu-file.c | 2 +- migration/savevm.c | 6 +++--- migration/vmstate.c | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-)migration/qemu-file.h +0
-0
migration/qemu-file.h QEMUFile *qemu_file_new_output(QIOChannel *ioc); · line 39
Quoted 7 lines
migration/qemu-file.h +1
-1@@ -34,7 +34,7 @@ QEMUFile *qemu_file_new_output(QIOChannel *ioc);int qemu_fclose (QEMUFile *f);/* -* qemu_file_transferred_noflush: +* qemu_file_transferred: * * As qemu_file_transferred except for writable files, where no flush
Docs need updating^
Quoted 7 lines
migration/qemu-file.h +1
-1* is performed and the reported amount will include the size of any @@ -42,7 +42,7 @@ int qemu_fclose(QEMUFile *f);* * Returns: the total bytes transferred and queued */ -uint64_t qemu_file_transferred_noflush (QEMUFile *f); +uint64_t qemu_file_transferred (QEMUFile *f);
Re: [PATCH 10/16] qemu-file: Remove _noflush from qemu_file_transferred_noflush()
Quoted 20 lines · Fabiano Rosas
Quoted 18 lines · Juan Quintela
qemu_file_transferred()don't exist anymore, so we can reuse the name.Signed-off-by Juan Quintela <[email protected]>--- migration/qemu-file.h | 4 ++-- migration/block.c | 4 ++-- migration/qemu-file.c | 2 +- migration/savevm.c | 6 +++--- migration/vmstate.c | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-)migration/qemu-file.h +0
-0@@ -34,7 +34,7 @@ QEMUFile *qemu_file_new_output(QIOChannel *ioc);int qemu_fclose (QEMUFile *f);
Quoted 7 lines
migration/qemu-file.h QEMUFile *qemu_file_new_output(QIOChannel *ioc); · line 39
Quoted 5 lines
migration/qemu-file.h +1
-1/* -* qemu_file_transferred_noflush: +* qemu_file_transferred: * * As qemu_file_transferred except for writable files, where no flush Docs need updating^
Fixed, thanks.
Quoted 7 lines
Quoted 7 lines
migration/qemu-file.h +1
-1* is performed and the reported amount will include the size of any @@ -42,7 +42,7 @@ int qemu_fclose(QEMUFile *f);* * Returns: the total bytes transferred and queued */ -uint64_t qemu_file_transferred_noflush (QEMUFile *f); +uint64_t qemu_file_transferred (QEMUFile *f);
PATCH 11/16 migration: migration_transferred_bytes() don't need the QEMUFile
In reply to Juan Quintela--- migration/migration-stats.h | 4 +--- migration/migration-stats.c | 6 +++--- migration/migration.c | 6 +++--- 3 files changed, 7 insertions(+), 9 deletions(-)
migration/migration-stats.h +1 -3
@@ -137,11 +137,9 @@ void migration_rate_set(uint64_t new_rate);/** * migration_transferred_bytes: Return number of bytes transferred * -* @f: QEMUFile used for main migration channel -* * Returns how many bytes have we transferred since the beginning of * the migration. It accounts for bytes sent through any migration * channel, multifd, qemu_file, rdma, .... */ -uint64_t migration_transferred_bytes (QEMUFile *f); +uint64_t migration_transferred_bytes (void );#endif
migration/migration-stats.c +3 -3
@@ -25,7 +25,7 @@ bool migration_rate_exceeded(QEMUFile *f) }uint64_t rate_limit_start =stat64_get (&mig_stats.rate_limit_start); -uint64_t rate_limit_current =migration_transferred_bytes (f); +uint64_t rate_limit_current =migration_transferred_bytes ();uint64_t rate_limit_used = rate_limit_current - rate_limit_start;uint64_t rate_limit_max =stat64_get (&mig_stats.rate_limit_max);
@@ -55,10 +55,10 @@ void migration_rate_set(uint64_t limit)void migration_rate_reset (QEMUFile *f) { -stat64_set (&mig_stats.rate_limit_start,migration_transferred_bytes (f)); +stat64_set (&mig_stats.rate_limit_start,migration_transferred_bytes ()); } -uint64_t migration_transferred_bytes (QEMUFile *f) +uint64_t migration_transferred_bytes (void ) {uint64_t multifd =stat64_get (&mig_stats.multifd_bytes);uint64_t rdma =stat64_get (&mig_stats.rdma_bytes);
migration/migration.c +3 -3
@@ -2628,7 +2628,7 @@ static MigThrError migration_detect_error(MigrationState *s)static void migration_calculate_complete (MigrationState *s) { -uint64_t bytes =migration_transferred_bytes (s->to_dst_file); +uint64_t bytes =migration_transferred_bytes ();int64_t end_time =qemu_clock_get_ms (QEMU_CLOCK_REALTIME );int64_t transfer_time;
@@ -2654,7 +2654,7 @@ static void update_iteration_initial_status(MigrationState *s)* wrong speed calculation. */ s->iteration_start_time =qemu_clock_get_ms (QEMU_CLOCK_REALTIME ); - s->iteration_initial_bytes =migration_transferred_bytes (s->to_dst_file); + s->iteration_initial_bytes =migration_transferred_bytes (); s->iteration_initial_pages =ram_get_total_transferred_pages (); }
@@ -2669,7 +2669,7 @@ static void migration_update_counters(MigrationState *s,return ; } - current_bytes =migration_transferred_bytes (s->to_dst_file); + current_bytes =migration_transferred_bytes (); transferred = current_bytes - s->iteration_initial_bytes; time_spent = current_time - s->iteration_start_time; bandwidth = (double )transferred / time_spent;
Signature · 1 line
2.40.1
Re: [PATCH 11/16] migration: migration_transferred_bytes() don't need the QEMUFile
Quoted 6 lines · Juan Quintela
Signed-off-by Juan Quintela <[email protected]>--- migration/migration-stats.h | 4 +--- migration/migration-stats.c | 6 +++--- migration/migration.c | 6 +++--- 3 files changed, 7 insertions(+), 9 deletions(-)
PATCH 12/16 migration: migration_rate_limit_reset() don't need the QEMUFile
In reply to Juan Quintela--- migration/migration-stats.h | 4 +--- migration/migration-stats.c | 2 +- migration/migration.c | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-)
migration/migration-stats.h +1 -3
@@ -120,10 +120,8 @@ uint64_t migration_rate_get(void);* migration_rate_reset: Reset the rate limit counter. * * This is called when we know we start a new transfer cycle. -* -* @f: QEMUFile used for main migration channel */ -void migration_rate_reset (QEMUFile *f); +void migration_rate_reset (void );/** * migration_rate_set: Set the maximum amount that can be transferred.
migration/migration-stats.c +1 -1
@@ -53,7 +53,7 @@ void migration_rate_set(uint64_t limit)stat64_set (&mig_stats.rate_limit_max, limit /XFER_LIMIT_RATIO ); } -void migration_rate_reset (QEMUFile *f) +void migration_rate_reset (void ) {stat64_set (&mig_stats.rate_limit_start,migration_transferred_bytes ()); }
migration/migration.c +1 -1
@@ -2693,7 +2693,7 @@ static void migration_update_counters(MigrationState *s,stat64_get (&mig_stats.dirty_bytes_last_sync) / bandwidth; } -migration_rate_reset (s->to_dst_file); +migration_rate_reset ();update_iteration_initial_status (s);
Signature · 1 line
2.40.1
Re: [PATCH 12/16] migration: migration_rate_limit_reset() don't need the QEMUFile
Quoted 6 lines · Juan Quintela
Signed-off-by Juan Quintela <[email protected]>--- migration/migration-stats.h | 4 +--- migration/migration-stats.c | 2 +- migration/migration.c | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-)
PATCH 13/16 qemu-file: Simplify qemu_file_get_error()
In reply to Juan QuintelaIf we pass a NULL error is the same that returning dirrectly the value.
--- migration/qemu-file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
migration/qemu-file.c +1 -1
@@ -209,7 +209,7 @@ void qemu_file_set_error_obj(QEMUFile *f, int ret, Error *err)*/ int qemu_file_get_error (QEMUFile *f) { -return qemu_file_get_error_obj (f,NULL ); +return f->last_error; }/*
Signature · 1 line
2.40.1
Re: [PATCH 13/16] qemu-file: Simplify qemu_file_get_error()
Quoted 3 lines · Juan Quintela
If we pass a NULL error is the same that returning dirrectly the value.
Signed-off-by Juan Quintela <[email protected]>
PATCH 14/16 migration: Use migration_transferred_bytes()
In reply to Juan QuintelaThere are only two differnces with the old value:
- the amount of QEMUFile that hasn't yet been flushed. It can be discussed what is more exact, the new or the old one.
- the amount of transferred bytes that we forgot to account for (the newer is better, i.e. exact).
Notice that this two values are used to:
a - present to the user
b - calculate the rate_limit
So a few KB here and there is not going to make a difference.
--- migration/migration.c | 2 +- migration/ram.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-)
migration/migration.c +1 -1
@@ -912,7 +912,7 @@ static void populate_ram_info(MigrationInfo *info, MigrationState *s)size_t page_size =qemu_target_page_size (); info->ram =g_malloc0 (sizeof (*info->ram)); - info->ram->transferred =stat64_get (&mig_stats.transferred); + info->ram->transferred =migration_transferred_bytes (); info->ram->total =ram_bytes_total (); info->ram->duplicate =stat64_get (&mig_stats.zero_pages);/* legacy value. It is not used anymore */
migration/ram.c +3 -3
@@ -552,7 +552,7 @@ void mig_throttle_counter_reset(void) rs->time_last_bitmap_sync =qemu_clock_get_ms (QEMU_CLOCK_REALTIME ); rs->num_dirty_pages_period =0 ; - rs->bytes_xfer_prev =stat64_get (&mig_stats.transferred); + rs->bytes_xfer_prev =migration_transferred_bytes (); }/**
@@ -988,7 +988,7 @@ static void migration_trigger_throttle(RAMState *rs) {uint64_t threshold =migrate_throttle_trigger_threshold ();uint64_t bytes_xfer_period = -stat64_get (&mig_stats.transferred) - rs->bytes_xfer_prev; +migration_transferred_bytes () - rs->bytes_xfer_prev;uint64_t bytes_dirty_period = rs->num_dirty_pages_period *TARGET_PAGE_SIZE ;uint64_t bytes_dirty_threshold = bytes_xfer_period * threshold /100 ;
@@ -1051,7 +1051,7 @@ static void migration_bitmap_sync(RAMState *rs, bool last_stage)/* reset period counters */ rs->time_last_bitmap_sync = end_time; rs->num_dirty_pages_period =0 ; - rs->bytes_xfer_prev =stat64_get (&mig_stats.transferred); + rs->bytes_xfer_prev =migration_transferred_bytes (); }if (migrate_events ()) {uint64_t generation =stat64_get (&mig_stats.dirty_sync_count);
Signature · 1 line
2.40.1
PATCH 15/16 migration: Remove transferred atomic counter
In reply to Juan QuintelaAfter last commit, it is a write only variable.
--- migration/migration-stats.h | 4 ---- migration/multifd.c | 3 --- migration/ram.c | 1 - 3 files changed, 8 deletions(-)
migration/migration-stats.h +0 -4
@@ -97,10 +97,6 @@ typedef struct {* Number of bytes sent through RDMA. */ Stat64 rdma_bytes; -/* -* Total number of bytes transferred. -*/ -Stat64 transferred;/* * Number of pages transferred that were full of zeros. */
migration/multifd.c +0 -3
@@ -188,7 +188,6 @@ static int multifd_send_initial_packet(MultiFDSendParams *p, Error **errp)return -1 ; }stat64_add (&mig_stats.multifd_bytes, size); -stat64_add (&mig_stats.transferred, size);return 0 ; }
@@ -715,7 +714,6 @@ static void *multifd_send_thread(void *opaque)break ; }stat64_add (&mig_stats.multifd_bytes, p->packet_len); -stat64_add (&mig_stats.transferred, p->packet_len); }else {/* Send header using the same writev call */ p->iov[0 ].iov_len = p->packet_len;
@@ -729,7 +727,6 @@ static void *multifd_send_thread(void *opaque) }stat64_add (&mig_stats.multifd_bytes, p->next_packet_size); -stat64_add (&mig_stats.transferred, p->next_packet_size);qemu_mutex_lock (&p->mutex); p->pending_job--;qemu_mutex_unlock (&p->mutex);
migration/ram.c +0 -1
@@ -443,7 +443,6 @@ void ram_transferred_add(uint64_t bytes) }else {stat64_add (&mig_stats.downtime_bytes, bytes); } -stat64_add (&mig_stats.transferred, bytes); } struct MigrationOps {
Signature · 1 line
2.40.1
PATCH 16/16 qemu-file: Make qemu_fflush() return errors
In reply to Juan QuintelaThis let us simplify code of this shape.
qemu_fflush(f);
int ret = qemu_file_get_error(f);
if (ret) {
return ret;
}into:
int ret = qemu_fflush(f);
if (ret) {
return ret;
}I updated all callers where there is any error check.
--- migration/qemu-file.h | 2 +- migration/colo.c | 11 +++-------- migration/migration.c | 7 +------ migration/qemu-file.c | 7 ++++--- migration/ram.c | 22 +++++++--------------- migration/rdma.c | 4 +--- migration/savevm.c | 3 +-- 7 files changed, 18 insertions(+), 38 deletions(-)
migration/qemu-file.h +1 -1
@@ -75,7 +75,7 @@ void qemu_file_set_error_obj(QEMUFile *f, int ret, Error *err);void qemu_file_set_error (QEMUFile *f,int ret);int qemu_file_shutdown (QEMUFile *f);QEMUFile *qemu_file_get_return_path (QEMUFile *f); -void qemu_fflush (QEMUFile *f); +int qemu_fflush (QEMUFile *f);void qemu_file_set_blocking (QEMUFile *f,bool block);int qemu_file_get_to_fd (QEMUFile *f,int fd,size_t size);
migration/colo.c +3 -8
@@ -314,9 +314,7 @@ static void colo_send_message(QEMUFile *f, COLOMessage msg,return ; }qemu_put_be32 (f, msg); -qemu_fflush (f); - - ret =qemu_file_get_error (f); + ret =qemu_fflush (f);if (ret <0 ) {error_setg_errno (errp, -ret,"Can't send COLO message" ); }
@@ -335,9 +333,7 @@ static void colo_send_message_value(QEMUFile *f, COLOMessage msg,return ; }qemu_put_be64 (f, value); -qemu_fflush (f); - - ret =qemu_file_get_error (f); + ret =qemu_fflush (f);if (ret <0 ) {error_setg_errno (errp, -ret,"Failed to send value for message:%s" ,COLOMessage_str (msg));
@@ -483,8 +479,7 @@ static int colo_do_checkpoint_transaction(MigrationState *s, }qemu_put_buffer (s->to_dst_file, bioc->data, bioc->usage); -qemu_fflush (s->to_dst_file); - ret =qemu_file_get_error (s->to_dst_file); + ret =qemu_fflush (s->to_dst_file);if (ret <0 ) { goto out; }
migration/migration.c +1 -6
@@ -297,12 +297,7 @@ static int migrate_send_rp_message(MigrationIncomingState *mis,qemu_put_be16 (mis->to_src_file, (unsigned int )message_type);qemu_put_be16 (mis->to_src_file, len);qemu_put_buffer (mis->to_src_file, data, len); -qemu_fflush (mis->to_src_file); - -/* It's possible that qemu file got error during sending */ - ret =qemu_file_get_error (mis->to_src_file); - -return ret; +return qemu_fflush (mis->to_src_file); }/* Request one page from the source VM at the given start address.
migration/qemu-file.c +4 -3
@@ -267,12 +267,12 @@ static void qemu_iovec_release_ram(QEMUFile *f)* This will flush all pending data. If data was only partially flushed, it * will set an error state. */ -void qemu_fflush (QEMUFile *f) +int qemu_fflush (QEMUFile *f) {g_assert (qemu_file_is_writable (f)); -if (qemu_file_get_error (f)) { -return ; +if (f->last_error) { +return f->last_error; }if (f->iovcnt >0 ) {Error *local_error =NULL ;
@@ -290,6 +290,7 @@ void qemu_fflush(QEMUFile *f) f->buf_index =0 ; f->iovcnt =0 ; +return f->last_error; }/*
migration/ram.c +7 -15
@@ -301,17 +301,15 @@ int64_t ramblock_recv_bitmap_send(QEMUFile *file,qemu_put_be64 (file, size);qemu_put_buffer (file, (const uint8_t *)le_bitmap, size); +g_free (le_bitmap);/* * Mark as an end, in case the middle part is screwed up due to * some "mysterious" reason. */ qemu_put_be64 (file,RAMBLOCK_RECV_BITMAP_ENDING ); -qemu_fflush (file); - -g_free (le_bitmap); - -if (qemu_file_get_error (file)) { -return qemu_file_get_error (file); +int ret =qemu_fflush (file); +if (ret) { +return ret; }return size +sizeof (size);
@@ -3034,9 +3032,7 @@ static int ram_save_setup(QEMUFile *f, void *opaque) }qemu_put_be64 (f,RAM_SAVE_FLAG_EOS ); -qemu_fflush (f); - -return 0 ; +return qemu_fflush (f); }/**
@@ -3155,10 +3151,8 @@ out: }qemu_put_be64 (f,RAM_SAVE_FLAG_EOS ); -qemu_fflush (f);ram_transferred_add (8 ); - - ret =qemu_file_get_error (f); + ret =qemu_fflush (f); }if (ret <0 ) {return ret;
@@ -3235,9 +3229,7 @@ static int ram_save_complete(QEMUFile *f, void *opaque)qemu_put_be64 (f,RAM_SAVE_FLAG_MULTIFD_FLUSH ); }qemu_put_be64 (f,RAM_SAVE_FLAG_EOS ); -qemu_fflush (f); - -return 0 ; +return qemu_fflush (f); } static void ram_state_pending_estimate(void *opaque, uint64_t *must_precopy,
migration/rdma.c +1 -3
@@ -3886,9 +3886,7 @@ int rdma_registration_start(QEMUFile *f, uint64_t flags)trace_rdma_registration_start (flags);qemu_put_be64 (f,RAM_SAVE_FLAG_HOOK ); -qemu_fflush (f); - -return 0 ; +return qemu_fflush (f); }/*
migration/savevm.c +1 -2
@@ -1536,8 +1536,7 @@ int qemu_savevm_state_complete_precopy(QEMUFile *f, bool iterable_only, } flush: -qemu_fflush (f); -return 0 ; +return qemu_fflush (f); }/* Give an estimate of the amount left to be transferred,
Signature · 1 line
2.40.1
Re: [PATCH 16/16] qemu-file: Make qemu_fflush() return errors
Quoted 18 lines · Juan Quintela
This let us simplify code of this shape.
qemu_fflush(f); int ret = qemu_file_get_error(f); if (ret) { return ret; }into:
int ret = qemu_fflush(f); if (ret) { return ret; }I updated all callers where there is any error check.
Signed-off-by Juan Quintela <[email protected]>
Quoted 9 lines
--- migration/qemu-file.h | 2 +- migration/colo.c | 11 +++-------- migration/migration.c | 7 +------ migration/qemu-file.c | 7 ++++--- migration/ram.c | 22 +++++++--------------- migration/rdma.c | 4 +--- migration/savevm.c | 3 +-- 7 files changed, 18 insertions(+), 38 deletions(-)
Quoted 1 line · Juan Quintela
Hi
Hi
Fiona, I forgot to put your on the CC'd list. This series should reget the speed problem that you find.
Later, Juan.
Quoted 57 lines
On this series:
- Make sure that
qemu_file_transferred()make sense and its used coherently- Use stat64 for
qemu_file_transferred(), so we can call the function from any thread.- Don't account for the same transfer twice (i.e. it is
multifd_bytes,rdma_bytesorqemu_file_bytes)qemu_file_transferred()just sums all of them.- Use this new counter for
rate_limit()- Remove old trasferred stat64 (now we use the real thing)
- Simplify
qemu_file_get_error(): see where next cleanups are coming- As an example,
qemu_fflush()now return errors.Please review.
Later, Juan.
Based-on: Message-Id: <[email protected]>
Subject: [PULL 00/21] Migration 20230530 patchesJuan Quintela (16):
qemu-file: Renameqemu_file_transferred_fast -> noflush
migration: Changeqemu_file_transferredto noflush
migration: Useqemu_file_transferred_noflush()for block migration.
qemu-file: Don't callqemu_fflush()for read only files
qemu-file: We only call qemu_file_transferred_* on the sending side
qemu_file: Use a stat64 forqemu_file_transferred
qemu_file:total_transferredis not used anymore
migration: Use the number of transferred bytes directly
qemu_file: Remove unusedqemu_file_transferred()
qemu-file: Remove_noflushfromqemu_file_transferred_noflush()
migration:migration_transferred_bytes()don't need the QEMUFile
migration:migration_rate_limit_reset()don't need the QEMUFile
qemu-file: Simplifyqemu_file_get_error()
migration: Usemigration_transferred_bytes()
migration: Remove transferred atomic counter
qemu-file: Makeqemu_fflush()return errorsmigration/migration-stats.h | 16 ++++++---------- migration/qemu-file.h | 29 +++++------------------------ migration/colo.c | 11 +++-------- migration/migration-stats.c | 10 +++++----- migration/migration.c | 17 ++++++----------- migration/multifd.c | 3 --- migration/qemu-file.c | 35 ++++++++++++++--------------------- migration/ram.c | 29 ++++++++++------------------- migration/rdma.c | 4 +--- migration/savevm.c | 7 +++---- migration/vmstate.c | 4 ++-- 11 files changed, 55 insertions(+), 110 deletions(-)