[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 14/21] ram.c: Do not call save_page_header() from compress threads
From: |
Juan Quintela |
Subject: |
[PULL 14/21] ram.c: Do not call save_page_header() from compress threads |
Date: |
Fri, 28 Apr 2023 21:11:56 +0200 |
From: Lukas Straub <lukasstraub2@web.de>
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>
---
migration/ram.c | 44 +++++++++++++++++++++++++++++++++++---------
1 file changed, 35 insertions(+), 9 deletions(-)
diff --git a/migration/ram.c b/migration/ram.c
index b0b11f37fb..53aba37be9 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 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)
{
- MigrationState *ms = migrate_get_current();
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(¶m->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);
--
2.40.0
- [PULL 01/21] multifd: We already account for this packet on the multifd thread, (continued)
- [PULL 01/21] multifd: We already account for this packet on the multifd thread, Juan Quintela, 2023/04/28
- [PULL 03/21] migration: Rename ram_counters to mig_stats, Juan Quintela, 2023/04/28
- [PULL 04/21] migration: Rename RAMStats to MigrationAtomicStats, Juan Quintela, 2023/04/28
- [PULL 07/21] migration: Drop unused parameter for migration_tls_get_creds(), Juan Quintela, 2023/04/28
- [PULL 05/21] migration/rdma: Split the zero page case from acct_update_position, Juan Quintela, 2023/04/28
- [PULL 06/21] migration/rdma: Unfold last user of acct_update_position(), Juan Quintela, 2023/04/28
- [PULL 08/21] migration: Drop unused parameter for migration_tls_client_create(), Juan Quintela, 2023/04/28
- [PULL 10/21] qtest/migration-test.c: Add postcopy tests with compress enabled, Juan Quintela, 2023/04/28
- [PULL 09/21] qtest/migration-test.c: Add tests with compress enabled, Juan Quintela, 2023/04/28
- [PULL 11/21] ram.c: Let the compress threads return a CompressResult enum, Juan Quintela, 2023/04/28
- [PULL 14/21] ram.c: Do not call save_page_header() from compress threads,
Juan Quintela <=
- [PULL 12/21] ram.c: Dont change param->block in the compress thread, Juan Quintela, 2023/04/28
- [PULL 13/21] ram.c: Reset result after sending queued data, Juan Quintela, 2023/04/28
- [PULL 16/21] ram.c: Remove last ram.c dependency from the core compress code, Juan Quintela, 2023/04/28
- [PULL 15/21] ram.c: Call update_compress_thread_counts from compress_send_queued_data, Juan Quintela, 2023/04/28
- [PULL 18/21] ram.c: Move core decompression code into its own file, Juan Quintela, 2023/04/28
- [PULL 19/21] ram compress: Assert that the file buffer matches the result, Juan Quintela, 2023/04/28
- [PULL 17/21] ram.c: Move core compression code into its own file, Juan Quintela, 2023/04/28
- [PULL 21/21] migration: Initialize and cleanup decompression in migration.c, Juan Quintela, 2023/04/28
- [PULL 20/21] ram-compress.c: Make target independent, Juan Quintela, 2023/04/28
- Re: [PULL 00/21] Migration 20230428 patches, Richard Henderson, 2023/04/29