[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 2/3] multifd: compression support variables
From: |
Juan Quintela |
Subject: |
[Qemu-devel] [PATCH 2/3] multifd: compression support variables |
Date: |
Wed, 20 Feb 2019 13:57:54 +0100 |
Signed-off-by: Juan Quintela <address@hidden>
---
migration/ram.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 46 insertions(+)
diff --git a/migration/ram.c b/migration/ram.c
index d57db00ce4..7de27e1a35 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -597,6 +597,12 @@ typedef struct {
uint64_t num_pages;
/* syncs main thread and channels */
QemuSemaphore sem_sync;
+ /* stream for compression */
+ z_stream zs;
+ /* compressed buffer */
+ uint8_t *zbuff;
+ /* size of compressed buffer */
+ uint32_t zbuff_len;
} MultiFDSendParams;
typedef struct {
@@ -632,6 +638,12 @@ typedef struct {
uint64_t num_pages;
/* syncs main thread and channels */
QemuSemaphore sem_sync;
+ /* stream for compression */
+ z_stream zs;
+ /* compressed buffer */
+ uint8_t *zbuff;
+ /* size of compressed buffer */
+ uint32_t zbuff_len;
} MultiFDRecvParams;
static int multifd_send_initial_packet(MultiFDSendParams *p, Error **errp)
@@ -969,6 +981,9 @@ void multifd_save_cleanup(void)
p->packet_len = 0;
g_free(p->packet);
p->packet = NULL;
+ deflateEnd(&p->zs);
+ g_free(p->zbuff);
+ p->zbuff = NULL;
}
qemu_sem_destroy(&multifd_send_state->channels_ready);
qemu_sem_destroy(&multifd_send_state->sem_sync);
@@ -1132,6 +1147,7 @@ int multifd_save_setup(void)
for (i = 0; i < thread_count; i++) {
MultiFDSendParams *p = &multifd_send_state->params[i];
+ z_stream *zs = &p->zs;
qemu_mutex_init(&p->mutex);
qemu_sem_init(&p->sem, 0);
@@ -1145,6 +1161,17 @@ int multifd_save_setup(void)
p->packet = g_malloc0(p->packet_len);
p->name = g_strdup_printf("multifdsend_%d", i);
socket_send_channel_create(multifd_new_send_channel_async, p);
+ zs->zalloc = Z_NULL;
+ zs->zfree = Z_NULL;
+ zs->opaque = Z_NULL;
+ if (deflateInit(zs, migrate_compress_level()) != Z_OK) {
+ printf("deflate init failed\n");
+ return -1;
+ }
+ /* We will never have more than page_count pages */
+ p->zbuff_len = page_count * qemu_target_page_size();
+ p->zbuff_len *= 2;
+ p->zbuff = g_malloc0(p->zbuff_len);
}
return 0;
}
@@ -1212,6 +1239,9 @@ int multifd_load_cleanup(Error **errp)
p->packet_len = 0;
g_free(p->packet);
p->packet = NULL;
+ inflateEnd(&p->zs);
+ g_free(p->zbuff);
+ p->zbuff = NULL;
}
qemu_sem_destroy(&multifd_recv_state->sem_sync);
g_free(multifd_recv_state->params);
@@ -1330,6 +1360,7 @@ int multifd_load_setup(void)
for (i = 0; i < thread_count; i++) {
MultiFDRecvParams *p = &multifd_recv_state->params[i];
+ z_stream *zs = &p->zs;
qemu_mutex_init(&p->mutex);
qemu_sem_init(&p->sem_sync, 0);
@@ -1339,6 +1370,21 @@ int multifd_load_setup(void)
+ sizeof(ram_addr_t) * page_count;
p->packet = g_malloc0(p->packet_len);
p->name = g_strdup_printf("multifdrecv_%d", i);
+
+ zs->zalloc = Z_NULL;
+ zs->zfree = Z_NULL;
+ zs->opaque = Z_NULL;
+ zs->avail_in = 0;
+ zs->next_in = Z_NULL;
+ if (inflateInit(zs) != Z_OK) {
+ printf("inflate init failed\n");
+ return -1;
+ }
+ /* We will never have more than page_count pages */
+ p->zbuff_len = page_count * qemu_target_page_size();
+ /* We know compression "could" use more space */
+ p->zbuff_len *= 2;
+ p->zbuff = g_malloc0(p->zbuff_len);
}
return 0;
}
--
2.20.1