aboutsummaryrefslogtreecommitdiff
path: root/migration
diff options
context:
space:
mode:
authorLukas Straub <lukasstraub2@web.de>2023-04-20 11:48:06 +0200
committerJuan Quintela <quintela@redhat.com>2023-05-08 15:25:26 +0200
commit3e81763e4c2e9f1b4bc331605a6450b6845d8970 (patch)
tree7f8ec37e1f711068364f3bddf43ce33bae6bdd77 /migration
parentb5cf1cd3e81eebb6343404fe8029d61dfb817d5a (diff)
downloadqemu-3e81763e4c2e9f1b4bc331605a6450b6845d8970.zip
qemu-3e81763e4c2e9f1b4bc331605a6450b6845d8970.tar.gz
qemu-3e81763e4c2e9f1b4bc331605a6450b6845d8970.tar.bz2
ram.c: Do not call save_page_header() from compress threads
save_page_header() accesses several global variables, so calling it from multiple threads is pretty ugly. Instead, call save_page_header() before writing out the compressed data from the compress buffer to the migration stream. This also makes the core compress code more independend from ram.c. Signed-off-by: Lukas Straub <lukasstraub2@web.de> Reviewed-by: Juan Quintela <quintela@redhat.com> Signed-off-by: Juan Quintela <quintela@redhat.com>
Diffstat (limited to 'migration')
-rw-r--r--migration/ram.c44
1 files changed, 35 insertions, 9 deletions
diff --git a/migration/ram.c b/migration/ram.c
index 4e14e3b..c52602b 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -1465,17 +1465,13 @@ static CompressResult do_compress_ram_page(QEMUFile *f, z_stream *stream,
RAMBlock *block, ram_addr_t offset,
uint8_t *source_buf)
{
- RAMState *rs = ram_state;
- PageSearchStatus *pss = &rs->pss[RAM_CHANNEL_PRECOPY];
uint8_t *p = block->host + offset;
int ret;
- if (save_zero_page_to_file(pss, f, block, offset)) {
+ if (buffer_is_zero(p, TARGET_PAGE_SIZE)) {
return RES_ZEROPAGE;
}
- save_page_header(pss, f, block, offset | RAM_SAVE_FLAG_COMPRESS_PAGE);
-
/*
* copy it to a internal buffer to avoid it being modified by VM
* so that we can catch up the error during compression and
@@ -1515,9 +1511,40 @@ static inline void compress_reset_result(CompressParam *param)
param->offset = 0;
}
-static void flush_compressed_data(RAMState *rs)
+static int send_queued_data(CompressParam *param)
{
+ PageSearchStatus *pss = &ram_state->pss[RAM_CHANNEL_PRECOPY];
MigrationState *ms = migrate_get_current();
+ QEMUFile *file = ms->to_dst_file;
+ int len = 0;
+
+ RAMBlock *block = param->block;
+ ram_addr_t offset = param->offset;
+
+ if (param->result == RES_NONE) {
+ return 0;
+ }
+
+ assert(block == pss->last_sent_block);
+
+ if (param->result == RES_ZEROPAGE) {
+ len += save_page_header(pss, file, block, offset | RAM_SAVE_FLAG_ZERO);
+ qemu_put_byte(file, 0);
+ len += 1;
+ ram_release_page(block->idstr, offset);
+ } else if (param->result == RES_COMPRESS) {
+ len += save_page_header(pss, file, block,
+ offset | RAM_SAVE_FLAG_COMPRESS_PAGE);
+ len += qemu_put_qemu_file(file, param->file);
+ } else {
+ abort();
+ }
+
+ return len;
+}
+
+static void flush_compressed_data(RAMState *rs)
+{
int idx, len, thread_count;
if (!save_page_use_compression(rs)) {
@@ -1537,7 +1564,7 @@ static void flush_compressed_data(RAMState *rs)
qemu_mutex_lock(&comp_param[idx].mutex);
if (!comp_param[idx].quit) {
CompressParam *param = &comp_param[idx];
- len = qemu_put_qemu_file(ms->to_dst_file, param->file);
+ len = send_queued_data(param);
compress_reset_result(param);
/*
@@ -1563,7 +1590,6 @@ static int compress_page_with_multi_thread(RAMBlock *block, ram_addr_t offset)
{
int idx, thread_count, bytes_xmit = -1, pages = -1;
bool wait = migrate_compress_wait_thread();
- MigrationState *ms = migrate_get_current();
thread_count = migrate_compress_threads();
qemu_mutex_lock(&comp_done_lock);
@@ -1573,7 +1599,7 @@ retry:
CompressParam *param = &comp_param[idx];
qemu_mutex_lock(&param->mutex);
param->done = false;
- bytes_xmit = qemu_put_qemu_file(ms->to_dst_file, param->file);
+ bytes_xmit = send_queued_data(param);
compress_reset_result(param);
set_compress_params(param, block, offset);