qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] permit dynamic adjust compress level when migration running
@ 2018-12-04 13:49 Ivan Ren
  0 siblings, 0 replies; only message in thread
From: Ivan Ren @ 2018-12-04 13:49 UTC (permalink / raw)
  To: quintela, dgilbert; +Cc: qemu-devel

After commit dcaf446ebda5d87e05eb41cdbafb7ae4a7cc4a62, we can't
dynamic adjust the compress level when migration running.
For some scenes, dynamic adjust the compress level to change the
compress behavior without restart a new migration is useful.

Signed-off-by: Ivan Ren <ivanren@tencent.com>
---
 migration/ram.c | 32 ++++++++++++++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)

diff --git a/migration/ram.c b/migration/ram.c
index 7e7deec..653a484 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -361,6 +361,7 @@ struct CompressParam {
 
     /* internally used fields */
     z_stream stream;
+    int current_compress_level;
     uint8_t *originbuf;
 };
 typedef struct CompressParam CompressParam;
@@ -394,6 +395,27 @@ static QemuThread *decompress_threads;
 static QemuMutex decomp_done_lock;
 static QemuCond decomp_done_cond;
 
+static int initial_compress_stream(CompressParam *param)
+{
+    int ret = -1;
+    int current_compress_level = 0;
+
+    if (param == NULL) {
+        goto exit;
+    }
+
+    current_compress_level = migrate_compress_level();
+    if (deflateInit(&(param->stream), current_compress_level) != Z_OK) {
+        goto exit;
+    }
+
+    param->current_compress_level = current_compress_level;
+    return 0;
+
+exit:
+    return ret;
+}
+
 static bool do_compress_ram_page(QEMUFile *f, z_stream *stream, RAMBlock *block,
                                  ram_addr_t offset, uint8_t *source_buf);
 
@@ -410,6 +432,12 @@ static void *do_data_compress(void *opaque)
             block = param->block;
             offset = param->offset;
             param->block = NULL;
+            if (param->current_compress_level != migrate_compress_level()) {
+                if (initial_compress_stream(param) != 0) {
+                    qemu_file_set_error(migrate_get_current()->to_dst_file, -1);
+                    error_report("fail to update compress stream!");
+                }
+            }
             qemu_mutex_unlock(&param->mutex);
 
             zero_page = do_compress_ram_page(param->file, &param->stream,
@@ -488,8 +516,8 @@ static int compress_threads_save_setup(void)
             goto exit;
         }
 
-        if (deflateInit(&comp_param[i].stream,
-                        migrate_compress_level()) != Z_OK) {
+        if (initial_compress_stream(&comp_param[i]) != 0) {
+            error_report("fail to initial compress stream!");
             g_free(comp_param[i].originbuf);
             goto exit;
         }
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2018-12-04 13:49 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-12-04 13:49 [Qemu-devel] [PATCH] permit dynamic adjust compress level when migration running Ivan Ren

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).