qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH] permit dynamic adjust compress level when migration


From: Ivan Ren
Subject: [Qemu-devel] [PATCH] permit dynamic adjust compress level when migration running
Date: Tue, 4 Dec 2018 21:49:40 +0800

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 <address@hidden>
---
 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]