f1eed34ac7
This version includes both the AioContext lock and the block graph lock, so there might be some deadlocks lurking. It's not possible to disable the block graph lock like was done in QEMU 8.1, because there are no changes like the function bdrv_schedule_unref() that require it. QEMU 9.0 will finally get rid of the AioContext locking. During live-restore with a VirtIO SCSI drive with iothread there is a known racy deadlock related to the AioContext lock. Not new [1], but not sure if more likely now. Should be fixed in QEMU 9.0. The block graph lock comes with annotations that can be checked by clang's TSA. This required changes to the block drivers, i.e. alloc-track, pbs, zeroinit as well as taking the appropriate locks in pve-backup, savevm-async, vma-reader. Local variable shadowing is prohibited via a compiler flag now, required slight adaptation in vma.c. Major changes only affect alloc-track: * It is not possible to call a generated co-wrapper like bdrv_get_info() while holding the block graph lock exclusively [0], which does happen during initialization of alloc-track when the backing hd is set and the refresh_limits driver callback is invoked. The bdrv_get_info() call to get the cluster size is moved to directly after opening the file child in track_open(). The important thing is that at least the request alignment for the write target is used, because then the RMW cycle in bdrv_pwritev will gather enough data from the backing file. Partial cluster allocations in the target are not a fundamental issue, because the driver returns its allocation status based on the bitmap, so any other data that maps to the same cluster will still be copied later by a stream job (or during writes to that cluster). * Replacing the node cannot be done in the track_co_change_backing_file() callback, because it is a coroutine and cannot hold the block graph lock exclusively. So it is moved to the stream job itself with the auto-remove option not having an effect anymore (qemu-server would always set it anyways). In the future, there could either be a special option for the stream job, or maybe the upcoming blockdev-replace QMP command can be used. Replacing the backing child is actually already done in the stream job, so no need to do it in the track_co_change_backing_file() callback. It also cannot be called from a coroutine. Looking at the implementation in the qcow2 driver, it doesn't seem to be intended to change the backing child itself, just update driver-internal state. Other changes: * alloc-track: Error out early when used without auto-remove. Since replacing the node now happens in the stream job, where the option cannot be read from (it's internal to the driver), it will always be treated as 'on'. Makes sure to have users beside qemu-server notice the change (should they even exist). The option can be fully dropped in the future while adding a version guard in qemu-server. * alloc-track: Avoid seemingly superfluous child permission update. Doesn't seem necessary nowadays (maybe after commit "alloc-track: fix deadlock during drop" where the dropping is not rescheduled and delayed anymore or some upstream change). Replacing the block node will already update the permissions of the new node (which was the file child before). Should there really be some issue, instead of having a drop state, this could also be just based off the fact whether there is still a backing child. Dumping the cumulative (shared) permissions for the BDS with a debug print yields the same values after this patch and with QEMU 8.1, namely 3 and 5. * PBS block driver: compile unconditionally. Proxmox VE always needs it and something in the build process changed to make it not enabled by default. Probably would need to move the build option to meson otherwise. * backup: job unreferencing during cleanup needs to happen outside of coroutine, so it was moved to before invoking the clean * mirror: Cherry-pick stable fix to avoid potential deadlock. * savevm-async: migrate_init now can fail, so propagate potential error. * savevm-async: compression counters are not accessible outside migration/ram-compress now, so drop code that prophylactically set it to zero. [0]: https://lore.kernel.org/qemu-devel/220be383-3b0d-4938-b584-69ad214e5d5d@proxmox.com/ [1]: https://lore.kernel.org/qemu-devel/e13b488e-bf13-44f2-acca-e724d14f43fd@proxmox.com/ Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
218 lines
7.6 KiB
Diff
218 lines
7.6 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Wolfgang Bumiller <w.bumiller@proxmox.com>
|
|
Date: Mon, 4 May 2020 11:05:08 +0200
|
|
Subject: [PATCH] PVE: add optional buffer size to QEMUFile
|
|
|
|
So we can use a 4M buffer for savevm-async which should
|
|
increase performance storing the state onto ceph.
|
|
|
|
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
|
|
[increase max IOV count in QEMUFile to actually write more data]
|
|
Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
|
|
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
|
|
[FE: adapt to removal of QEMUFileOps]
|
|
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
|
|
---
|
|
migration/qemu-file.c | 50 +++++++++++++++++++++++++++-------------
|
|
migration/qemu-file.h | 2 ++
|
|
migration/savevm-async.c | 5 ++--
|
|
3 files changed, 39 insertions(+), 18 deletions(-)
|
|
|
|
diff --git a/migration/qemu-file.c b/migration/qemu-file.c
|
|
index 94231ff295..afda98292f 100644
|
|
--- a/migration/qemu-file.c
|
|
+++ b/migration/qemu-file.c
|
|
@@ -34,8 +34,8 @@
|
|
#include "qapi/error.h"
|
|
#include "rdma.h"
|
|
|
|
-#define IO_BUF_SIZE 32768
|
|
-#define MAX_IOV_SIZE MIN_CONST(IOV_MAX, 64)
|
|
+#define DEFAULT_IO_BUF_SIZE 32768
|
|
+#define MAX_IOV_SIZE MIN_CONST(IOV_MAX, 256)
|
|
|
|
struct QEMUFile {
|
|
QIOChannel *ioc;
|
|
@@ -43,7 +43,8 @@ struct QEMUFile {
|
|
|
|
int buf_index;
|
|
int buf_size; /* 0 when writing */
|
|
- uint8_t buf[IO_BUF_SIZE];
|
|
+ size_t buf_allocated_size;
|
|
+ uint8_t *buf;
|
|
|
|
DECLARE_BITMAP(may_free, MAX_IOV_SIZE);
|
|
struct iovec iov[MAX_IOV_SIZE];
|
|
@@ -97,7 +98,9 @@ int qemu_file_shutdown(QEMUFile *f)
|
|
return 0;
|
|
}
|
|
|
|
-static QEMUFile *qemu_file_new_impl(QIOChannel *ioc, bool is_writable)
|
|
+static QEMUFile *qemu_file_new_impl(QIOChannel *ioc,
|
|
+ bool is_writable,
|
|
+ size_t buffer_size)
|
|
{
|
|
QEMUFile *f;
|
|
|
|
@@ -106,6 +109,8 @@ static QEMUFile *qemu_file_new_impl(QIOChannel *ioc, bool is_writable)
|
|
object_ref(ioc);
|
|
f->ioc = ioc;
|
|
f->is_writable = is_writable;
|
|
+ f->buf_allocated_size = buffer_size;
|
|
+ f->buf = malloc(buffer_size);
|
|
|
|
return f;
|
|
}
|
|
@@ -116,17 +121,27 @@ static QEMUFile *qemu_file_new_impl(QIOChannel *ioc, bool is_writable)
|
|
*/
|
|
QEMUFile *qemu_file_get_return_path(QEMUFile *f)
|
|
{
|
|
- return qemu_file_new_impl(f->ioc, !f->is_writable);
|
|
+ return qemu_file_new_impl(f->ioc, !f->is_writable, DEFAULT_IO_BUF_SIZE);
|
|
}
|
|
|
|
QEMUFile *qemu_file_new_output(QIOChannel *ioc)
|
|
{
|
|
- return qemu_file_new_impl(ioc, true);
|
|
+ return qemu_file_new_impl(ioc, true, DEFAULT_IO_BUF_SIZE);
|
|
+}
|
|
+
|
|
+QEMUFile *qemu_file_new_output_sized(QIOChannel *ioc, size_t buffer_size)
|
|
+{
|
|
+ return qemu_file_new_impl(ioc, true, buffer_size);
|
|
}
|
|
|
|
QEMUFile *qemu_file_new_input(QIOChannel *ioc)
|
|
{
|
|
- return qemu_file_new_impl(ioc, false);
|
|
+ return qemu_file_new_impl(ioc, false, DEFAULT_IO_BUF_SIZE);
|
|
+}
|
|
+
|
|
+QEMUFile *qemu_file_new_input_sized(QIOChannel *ioc, size_t buffer_size)
|
|
+{
|
|
+ return qemu_file_new_impl(ioc, false, buffer_size);
|
|
}
|
|
|
|
/*
|
|
@@ -320,7 +335,7 @@ static ssize_t coroutine_mixed_fn qemu_fill_buffer(QEMUFile *f)
|
|
do {
|
|
len = qio_channel_read(f->ioc,
|
|
(char *)f->buf + pending,
|
|
- IO_BUF_SIZE - pending,
|
|
+ f->buf_allocated_size - pending,
|
|
&local_error);
|
|
if (len == QIO_CHANNEL_ERR_BLOCK) {
|
|
if (qemu_in_coroutine()) {
|
|
@@ -360,6 +375,9 @@ int qemu_fclose(QEMUFile *f)
|
|
ret = ret2;
|
|
}
|
|
g_clear_pointer(&f->ioc, object_unref);
|
|
+
|
|
+ free(f->buf);
|
|
+
|
|
error_free(f->last_error_obj);
|
|
g_free(f);
|
|
trace_qemu_file_fclose();
|
|
@@ -408,7 +426,7 @@ static void add_buf_to_iovec(QEMUFile *f, size_t len)
|
|
{
|
|
if (!add_to_iovec(f, f->buf + f->buf_index, len, false)) {
|
|
f->buf_index += len;
|
|
- if (f->buf_index == IO_BUF_SIZE) {
|
|
+ if (f->buf_index == f->buf_allocated_size) {
|
|
qemu_fflush(f);
|
|
}
|
|
}
|
|
@@ -433,7 +451,7 @@ void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, size_t size)
|
|
}
|
|
|
|
while (size > 0) {
|
|
- l = IO_BUF_SIZE - f->buf_index;
|
|
+ l = f->buf_allocated_size - f->buf_index;
|
|
if (l > size) {
|
|
l = size;
|
|
}
|
|
@@ -478,8 +496,8 @@ size_t coroutine_mixed_fn qemu_peek_buffer(QEMUFile *f, uint8_t **buf, size_t si
|
|
size_t index;
|
|
|
|
assert(!qemu_file_is_writable(f));
|
|
- assert(offset < IO_BUF_SIZE);
|
|
- assert(size <= IO_BUF_SIZE - offset);
|
|
+ assert(offset < f->buf_allocated_size);
|
|
+ assert(size <= f->buf_allocated_size - offset);
|
|
|
|
/* The 1st byte to read from */
|
|
index = f->buf_index + offset;
|
|
@@ -529,7 +547,7 @@ size_t coroutine_mixed_fn qemu_get_buffer(QEMUFile *f, uint8_t *buf, size_t size
|
|
size_t res;
|
|
uint8_t *src;
|
|
|
|
- res = qemu_peek_buffer(f, &src, MIN(pending, IO_BUF_SIZE), 0);
|
|
+ res = qemu_peek_buffer(f, &src, MIN(pending, f->buf_allocated_size), 0);
|
|
if (res == 0) {
|
|
return done;
|
|
}
|
|
@@ -563,7 +581,7 @@ size_t coroutine_mixed_fn qemu_get_buffer(QEMUFile *f, uint8_t *buf, size_t size
|
|
*/
|
|
size_t coroutine_mixed_fn qemu_get_buffer_in_place(QEMUFile *f, uint8_t **buf, size_t size)
|
|
{
|
|
- if (size < IO_BUF_SIZE) {
|
|
+ if (size < f->buf_allocated_size) {
|
|
size_t res;
|
|
uint8_t *src = NULL;
|
|
|
|
@@ -588,7 +606,7 @@ int coroutine_mixed_fn qemu_peek_byte(QEMUFile *f, int offset)
|
|
int index = f->buf_index + offset;
|
|
|
|
assert(!qemu_file_is_writable(f));
|
|
- assert(offset < IO_BUF_SIZE);
|
|
+ assert(offset < f->buf_allocated_size);
|
|
|
|
if (index >= f->buf_size) {
|
|
qemu_fill_buffer(f);
|
|
@@ -702,7 +720,7 @@ static int qemu_compress_data(z_stream *stream, uint8_t *dest, size_t dest_len,
|
|
ssize_t qemu_put_compression_data(QEMUFile *f, z_stream *stream,
|
|
const uint8_t *p, size_t size)
|
|
{
|
|
- ssize_t blen = IO_BUF_SIZE - f->buf_index - sizeof(int32_t);
|
|
+ ssize_t blen = f->buf_allocated_size - f->buf_index - sizeof(int32_t);
|
|
|
|
if (blen < compressBound(size)) {
|
|
return -1;
|
|
diff --git a/migration/qemu-file.h b/migration/qemu-file.h
|
|
index 8aec9fabf7..5d0b18c51c 100644
|
|
--- a/migration/qemu-file.h
|
|
+++ b/migration/qemu-file.h
|
|
@@ -30,7 +30,9 @@
|
|
#include "io/channel.h"
|
|
|
|
QEMUFile *qemu_file_new_input(QIOChannel *ioc);
|
|
+QEMUFile *qemu_file_new_input_sized(QIOChannel *ioc, size_t buffer_size);
|
|
QEMUFile *qemu_file_new_output(QIOChannel *ioc);
|
|
+QEMUFile *qemu_file_new_output_sized(QIOChannel *ioc, size_t buffer_size);
|
|
int qemu_fclose(QEMUFile *f);
|
|
|
|
/*
|
|
diff --git a/migration/savevm-async.c b/migration/savevm-async.c
|
|
index 8f63c4c637..f8d1c2f2b1 100644
|
|
--- a/migration/savevm-async.c
|
|
+++ b/migration/savevm-async.c
|
|
@@ -382,7 +382,7 @@ void qmp_savevm_start(const char *statefile, Error **errp)
|
|
|
|
QIOChannel *ioc = QIO_CHANNEL(qio_channel_savevm_async_new(snap_state.target,
|
|
&snap_state.bs_pos));
|
|
- snap_state.file = qemu_file_new_output(ioc);
|
|
+ snap_state.file = qemu_file_new_output_sized(ioc, 4 * 1024 * 1024);
|
|
|
|
if (!snap_state.file) {
|
|
error_set(errp, ERROR_CLASS_GENERIC_ERROR, "failed to open '%s'", statefile);
|
|
@@ -499,7 +499,8 @@ int load_snapshot_from_blockdev(const char *filename, Error **errp)
|
|
blk_op_block_all(be, blocker);
|
|
|
|
/* restore the VM state */
|
|
- f = qemu_file_new_input(QIO_CHANNEL(qio_channel_savevm_async_new(be, &bs_pos)));
|
|
+ f = qemu_file_new_input_sized(QIO_CHANNEL(qio_channel_savevm_async_new(be, &bs_pos)),
|
|
+ 4 * 1024 * 1024);
|
|
if (!f) {
|
|
error_setg(errp, "Could not open VM state file");
|
|
goto the_end;
|