From: Yuan Liu <yuan1.liu@intel.com>
To: quintela@redhat.com, peterx@redhat.com, farosas@suse.de,
leobras@redhat.com
Cc: qemu-devel@nongnu.org, yuan1.liu@intel.com, nanhai.zou@intel.com
Subject: [PATCH 3/5] ram compress: Refactor ram compression functions
Date: Thu, 19 Oct 2023 06:12:22 +0800 [thread overview]
Message-ID: <20231018221224.599065-4-yuan1.liu@intel.com> (raw)
In-Reply-To: <20231018221224.599065-1-yuan1.liu@intel.com>
Refactor legacy RAM compression functions to support both IAA
compression and CPU compression.
Signed-off-by: Yuan Liu <yuan1.liu@intel.com>
Reviewed-by: Nanhai Zou <nanhai.zou@intel.com>
---
migration/migration.c | 6 +--
migration/ram-compress.c | 81 ++++++++++++++++++++++++++++++++--------
migration/ram-compress.h | 10 ++---
migration/ram.c | 18 ++++++---
4 files changed, 86 insertions(+), 29 deletions(-)
diff --git a/migration/migration.c b/migration/migration.c
index 585d3c8f55..08a9c313d0 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -237,7 +237,7 @@ void migration_incoming_state_destroy(void)
struct MigrationIncomingState *mis = migration_incoming_get_current();
multifd_load_cleanup();
- compress_threads_load_cleanup();
+ ram_compress_load_cleanup();
if (mis->to_src_file) {
/* Tell source that we are done */
@@ -524,7 +524,7 @@ process_incoming_migration_co(void *opaque)
assert(mis->from_src_file);
- if (compress_threads_load_setup(mis->from_src_file)) {
+ if (ram_compress_load_setup(mis->from_src_file)) {
error_report("Failed to setup decompress threads");
goto fail;
}
@@ -577,7 +577,7 @@ fail:
qemu_fclose(mis->from_src_file);
multifd_load_cleanup();
- compress_threads_load_cleanup();
+ ram_compress_load_cleanup();
exit(EXIT_FAILURE);
}
diff --git a/migration/ram-compress.c b/migration/ram-compress.c
index 06254d8c69..47357352f7 100644
--- a/migration/ram-compress.c
+++ b/migration/ram-compress.c
@@ -105,11 +105,11 @@ static void *do_data_compress(void *opaque)
return NULL;
}
-void compress_threads_save_cleanup(void)
+static void compress_threads_save_cleanup(void)
{
int i, thread_count;
- if (!migrate_compress() || !comp_param) {
+ if (!comp_param) {
return;
}
@@ -144,13 +144,10 @@ void compress_threads_save_cleanup(void)
comp_param = NULL;
}
-int compress_threads_save_setup(void)
+static int compress_threads_save_setup(void)
{
int i, thread_count;
- if (!migrate_compress()) {
- return 0;
- }
thread_count = migrate_compress_threads();
compress_threads = g_new0(QemuThread, thread_count);
comp_param = g_new0(CompressParam, thread_count);
@@ -370,6 +367,11 @@ int wait_for_decompress_done(void)
return 0;
}
+ if (migrate_compress_with_iaa()) {
+ /* Implement in next patch */
+ return 0;
+ }
+
thread_count = migrate_decompress_threads();
qemu_mutex_lock(&decomp_done_lock);
for (idx = 0; idx < thread_count; idx++) {
@@ -381,13 +383,10 @@ int wait_for_decompress_done(void)
return qemu_file_get_error(decomp_file);
}
-void compress_threads_load_cleanup(void)
+static void compress_threads_load_cleanup(void)
{
int i, thread_count;
- if (!migrate_compress()) {
- return;
- }
thread_count = migrate_decompress_threads();
for (i = 0; i < thread_count; i++) {
/*
@@ -422,14 +421,10 @@ void compress_threads_load_cleanup(void)
decomp_file = NULL;
}
-int compress_threads_load_setup(QEMUFile *f)
+static int compress_threads_load_setup(QEMUFile *f)
{
int i, thread_count;
- if (!migrate_compress()) {
- return 0;
- }
-
thread_count = migrate_decompress_threads();
decompress_threads = g_new0(QemuThread, thread_count);
decomp_param = g_new0(DecompressParam, thread_count);
@@ -457,7 +452,7 @@ exit:
return -1;
}
-void decompress_data_with_multi_threads(QEMUFile *f, void *host, int len)
+static void decompress_data_with_multi_threads(QEMUFile *f, void *host, int len)
{
int idx, thread_count;
@@ -483,3 +478,57 @@ void decompress_data_with_multi_threads(QEMUFile *f, void *host, int len)
}
}
}
+
+int ram_compress_save_setup(void)
+{
+ if (!migrate_compress()) {
+ return 0;
+ }
+ if (migrate_compress_with_iaa()) {
+ /* Implement in next patch */
+ return 0;
+ }
+ return compress_threads_save_setup();
+}
+
+void ram_compress_save_cleanup(void)
+{
+ if (!migrate_compress()) {
+ return;
+ }
+ if (migrate_compress_with_iaa()) {
+ /* Implement in next patch */
+ return;
+ }
+ compress_threads_save_cleanup();
+}
+
+void ram_decompress_data(QEMUFile *f, void *host, int len)
+{
+ if (migrate_compress_with_iaa()) {
+ /* Implement in next patch */
+ }
+ decompress_data_with_multi_threads(f, host, len);
+}
+
+int ram_compress_load_setup(QEMUFile *f)
+{
+ if (!migrate_compress()) {
+ return 0;
+ }
+ if (migrate_compress_with_iaa()) {
+ /* Implement in next patch */
+ }
+ return compress_threads_load_setup(f);
+}
+
+void ram_compress_load_cleanup(void)
+{
+ if (!migrate_compress()) {
+ return;
+ }
+ if (migrate_compress_with_iaa()) {
+ /* Implement in next patch */
+ }
+ compress_threads_load_cleanup();
+}
diff --git a/migration/ram-compress.h b/migration/ram-compress.h
index 6f7fe2f472..382083acf6 100644
--- a/migration/ram-compress.h
+++ b/migration/ram-compress.h
@@ -55,16 +55,16 @@ struct CompressParam {
};
typedef struct CompressParam CompressParam;
-void compress_threads_save_cleanup(void);
-int compress_threads_save_setup(void);
+void ram_compress_save_cleanup(void);
+int ram_compress_save_setup(void);
void flush_compressed_data(int (send_queued_data(CompressParam *)));
int compress_page_with_multi_thread(RAMBlock *block, ram_addr_t offset,
int (send_queued_data(CompressParam *)));
int wait_for_decompress_done(void);
-void compress_threads_load_cleanup(void);
-int compress_threads_load_setup(QEMUFile *f);
-void decompress_data_with_multi_threads(QEMUFile *f, void *host, int len);
+void ram_compress_load_cleanup(void);
+int ram_compress_load_setup(QEMUFile *f);
+void ram_decompress_data(QEMUFile *f, void *host, int len);
#endif
diff --git a/migration/ram.c b/migration/ram.c
index e4bfd39f08..34ee1de332 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -1347,6 +1347,10 @@ static void ram_flush_compressed_data(RAMState *rs)
if (!save_page_use_compression(rs)) {
return;
}
+ if (migrate_compress_with_iaa()) {
+ /* Implement in next patch */
+ return;
+ }
flush_compressed_data(send_queued_data);
}
@@ -2099,6 +2103,10 @@ static bool save_compress_page(RAMState *rs, PageSearchStatus *pss,
return false;
}
+ if (migrate_compress_with_iaa()) {
+ /* Implement in next patch */
+ return true;
+ }
if (compress_page_with_multi_thread(block, offset, send_queued_data) > 0) {
return true;
}
@@ -2498,7 +2506,7 @@ static void ram_save_cleanup(void *opaque)
}
xbzrle_cleanup();
- compress_threads_save_cleanup();
+ ram_compress_save_cleanup();
ram_state_cleanup(rsp);
g_free(migration_ops);
migration_ops = NULL;
@@ -3023,14 +3031,14 @@ static int ram_save_setup(QEMUFile *f, void *opaque)
RAMBlock *block;
int ret;
- if (compress_threads_save_setup()) {
+ if (ram_compress_save_setup()) {
return -1;
}
/* migration has already setup the bitmap, reuse it. */
if (!migration_in_colo_state()) {
if (ram_init_all(rsp) != 0) {
- compress_threads_save_cleanup();
+ ram_compress_save_cleanup();
return -1;
}
}
@@ -3753,7 +3761,7 @@ int ram_load_postcopy(QEMUFile *f, int channel)
ret = -EINVAL;
break;
}
- decompress_data_with_multi_threads(f, page_buffer, len);
+ ram_decompress_data(f, page_buffer, len);
break;
case RAM_SAVE_FLAG_MULTIFD_FLUSH:
multifd_recv_sync_main();
@@ -4022,7 +4030,7 @@ static int ram_load_precopy(QEMUFile *f)
ret = -EINVAL;
break;
}
- decompress_data_with_multi_threads(f, host, len);
+ ram_decompress_data(f, host, len);
break;
case RAM_SAVE_FLAG_XBZRLE:
--
2.39.3
next prev parent reply other threads:[~2023-10-19 13:40 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-18 22:12 [PATCH 0/5] Live Migration Acceleration with IAA Compression Yuan Liu
2023-10-18 22:12 ` [PATCH 1/5] configure: add qpl meson option Yuan Liu
2023-10-19 11:12 ` Juan Quintela
2023-10-18 22:12 ` [PATCH 2/5] qapi/migration: Introduce compress-with-iaa migration parameter Yuan Liu
2023-10-19 11:15 ` Juan Quintela
2023-10-19 14:02 ` Peter Xu
2023-10-18 22:12 ` Yuan Liu [this message]
2023-10-19 11:19 ` [PATCH 3/5] ram compress: Refactor ram compression functions Juan Quintela
2023-10-18 22:12 ` [PATCH 4/5] migration iaa-compress: Add IAA initialization and deinitialization Yuan Liu
2023-10-19 11:27 ` Juan Quintela
2023-10-18 22:12 ` [PATCH 5/5] migration iaa-compress: Implement IAA compression Yuan Liu
2023-10-19 11:36 ` Juan Quintela
2023-10-19 11:13 ` [PATCH 0/5] Live Migration Acceleration with IAA Compression Juan Quintela
2023-10-19 11:40 ` Juan Quintela
2023-10-19 14:52 ` Daniel P. Berrangé
2023-10-19 15:23 ` Peter Xu
2023-10-19 15:31 ` Juan Quintela
2023-10-19 15:32 ` Daniel P. Berrangé
2023-10-23 8:33 ` Liu, Yuan1
2023-10-23 10:29 ` Daniel P. Berrangé
2023-10-23 10:47 ` Juan Quintela
2023-10-23 14:54 ` Liu, Yuan1
2023-10-23 14:36 ` Liu, Yuan1
2023-10-23 10:38 ` Juan Quintela
2023-10-23 16:32 ` Liu, Yuan1
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=20231018221224.599065-4-yuan1.liu@intel.com \
--to=yuan1.liu@intel.com \
--cc=farosas@suse.de \
--cc=leobras@redhat.com \
--cc=nanhai.zou@intel.com \
--cc=peterx@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
/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;
as well as URLs for NNTP newsgroup(s).