Files

218 lines
7.6 KiB
Diff
Raw Permalink Normal View History

2020-05-04 14:35:01 +02:00
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
2021-02-11 17:11:11 +01:00
Subject: [PATCH] PVE: add optional buffer size to QEMUFile
2020-05-04 14:35:01 +02:00
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>
2021-02-11 17:11:11 +01:00
[increase max IOV count in QEMUFile to actually write more data]
Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
2022-01-13 10:34:33 +01:00
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2022-10-14 14:07:13 +02:00
[FE: adapt to removal of QEMUFileOps]
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
2020-05-04 14:35:01 +02:00
---
2024-04-25 17:21:28 +02:00
migration/qemu-file.c | 50 +++++++++++++++++++++++++++-------------
2022-10-14 14:07:13 +02:00
migration/qemu-file.h | 2 ++
migration/savevm-async.c | 5 ++--
2024-04-25 17:21:28 +02:00
3 files changed, 39 insertions(+), 18 deletions(-)
2020-05-04 14:35:01 +02:00
diff --git a/migration/qemu-file.c b/migration/qemu-file.c
2024-04-25 17:21:29 +02:00
index a10882d47f..19c1de0472 100644
2020-05-04 14:35:01 +02:00
--- a/migration/qemu-file.c
+++ b/migration/qemu-file.c
2024-04-25 17:21:29 +02:00
@@ -35,8 +35,8 @@
2024-04-25 17:21:28 +02:00
#include "rdma.h"
2024-04-25 17:21:29 +02:00
#include "io/channel-file.h"
2020-05-04 14:35:01 +02:00
-#define IO_BUF_SIZE 32768
2021-02-11 17:11:11 +01:00
-#define MAX_IOV_SIZE MIN_CONST(IOV_MAX, 64)
2020-05-04 14:35:01 +02:00
+#define DEFAULT_IO_BUF_SIZE 32768
2021-02-11 17:11:11 +01:00
+#define MAX_IOV_SIZE MIN_CONST(IOV_MAX, 256)
2020-05-04 14:35:01 +02:00
struct QEMUFile {
2024-04-25 17:21:28 +02:00
QIOChannel *ioc;
2024-04-25 17:21:29 +02:00
@@ -44,7 +44,8 @@ struct QEMUFile {
2022-10-14 14:07:13 +02:00
2020-05-04 14:35:01 +02:00
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];
2024-04-25 17:21:29 +02:00
@@ -101,7 +102,9 @@ int qemu_file_shutdown(QEMUFile *f)
2023-10-17 14:10:09 +02:00
return 0;
2020-05-04 14:35:01 +02:00
}
2022-10-14 14:07:13 +02:00
-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)
2020-05-04 14:35:01 +02:00
{
QEMUFile *f;
2024-04-25 17:21:29 +02:00
@@ -110,6 +113,8 @@ static QEMUFile *qemu_file_new_impl(QIOChannel *ioc, bool is_writable)
2022-10-14 14:07:13 +02:00
object_ref(ioc);
f->ioc = ioc;
f->is_writable = is_writable;
2020-05-04 14:35:01 +02:00
+ f->buf_allocated_size = buffer_size;
+ f->buf = malloc(buffer_size);
2022-10-14 14:07:13 +02:00
2020-05-04 14:35:01 +02:00
return f;
}
2024-04-25 17:21:29 +02:00
@@ -120,17 +125,27 @@ static QEMUFile *qemu_file_new_impl(QIOChannel *ioc, bool is_writable)
2022-10-14 14:07:13 +02:00
*/
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);
}
2020-05-04 14:35:01 +02:00
2022-10-14 14:07:13 +02:00
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)
2020-05-04 14:35:01 +02:00
+{
2022-10-14 14:07:13 +02:00
+ 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);
2020-05-04 14:35:01 +02:00
+}
+
2022-10-14 14:07:13 +02:00
+QEMUFile *qemu_file_new_input_sized(QIOChannel *ioc, size_t buffer_size)
+{
+ return qemu_file_new_impl(ioc, false, buffer_size);
}
2020-05-04 14:35:01 +02:00
2024-04-25 17:21:28 +02:00
/*
2024-04-25 17:21:29 +02:00
@@ -328,7 +343,7 @@ static ssize_t coroutine_mixed_fn qemu_fill_buffer(QEMUFile *f)
2022-10-14 14:07:13 +02:00
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()) {
2024-04-25 17:21:29 +02:00
@@ -368,6 +383,9 @@ int qemu_fclose(QEMUFile *f)
2024-04-25 17:21:28 +02:00
ret = ret2;
2020-05-04 14:35:01 +02:00
}
2022-10-14 14:07:13 +02:00
g_clear_pointer(&f->ioc, object_unref);
2024-04-25 17:21:28 +02:00
+
2020-05-04 14:35:01 +02:00
+ free(f->buf);
+
2024-04-25 17:21:28 +02:00
error_free(f->last_error_obj);
g_free(f);
trace_qemu_file_fclose();
2024-04-25 17:21:29 +02:00
@@ -416,7 +434,7 @@ static void add_buf_to_iovec(QEMUFile *f, size_t len)
2020-05-04 14:35:01 +02:00
{
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);
}
}
2024-04-25 17:21:29 +02:00
@@ -441,7 +459,7 @@ void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, size_t size)
2020-05-04 14:35:01 +02:00
}
while (size > 0) {
- l = IO_BUF_SIZE - f->buf_index;
+ l = f->buf_allocated_size - f->buf_index;
if (l > size) {
l = size;
}
2024-04-25 17:21:29 +02:00
@@ -587,8 +605,8 @@ size_t coroutine_mixed_fn qemu_peek_buffer(QEMUFile *f, uint8_t **buf, size_t si
2020-05-04 14:35:01 +02:00
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;
2024-04-25 17:21:29 +02:00
@@ -638,7 +656,7 @@ size_t coroutine_mixed_fn qemu_get_buffer(QEMUFile *f, uint8_t *buf, size_t size
2020-05-04 14:35:01 +02:00
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;
}
2024-04-25 17:21:29 +02:00
@@ -672,7 +690,7 @@ size_t coroutine_mixed_fn qemu_get_buffer(QEMUFile *f, uint8_t *buf, size_t size
2020-05-04 14:35:01 +02:00
*/
2023-10-17 14:10:09 +02:00
size_t coroutine_mixed_fn qemu_get_buffer_in_place(QEMUFile *f, uint8_t **buf, size_t size)
2020-05-04 14:35:01 +02:00
{
- if (size < IO_BUF_SIZE) {
+ if (size < f->buf_allocated_size) {
size_t res;
2021-05-27 12:43:32 +02:00
uint8_t *src = NULL;
2020-05-04 14:35:01 +02:00
2024-04-25 17:21:29 +02:00
@@ -697,7 +715,7 @@ int coroutine_mixed_fn qemu_peek_byte(QEMUFile *f, int offset)
2020-05-04 14:35:01 +02:00
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);
2024-04-25 17:21:29 +02:00
@@ -811,7 +829,7 @@ static int qemu_compress_data(z_stream *stream, uint8_t *dest, size_t dest_len,
2020-05-04 14:35:01 +02:00
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
2024-04-25 17:21:29 +02:00
index 32fd4a34fd..36a0cd8cc8 100644
2020-05-04 14:35:01 +02:00
--- a/migration/qemu-file.h
+++ b/migration/qemu-file.h
2024-04-25 17:21:28 +02:00
@@ -30,7 +30,9 @@
#include "io/channel.h"
2020-05-04 14:35:01 +02:00
2022-10-14 14:07:13 +02:00
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);
2020-05-04 14:35:01 +02:00
int qemu_fclose(QEMUFile *f);
2022-10-14 14:07:13 +02:00
2024-04-25 17:21:28 +02:00
/*
2021-02-11 17:11:11 +01:00
diff --git a/migration/savevm-async.c b/migration/savevm-async.c
index 72cf6588c2..fb4e8ea689 100644
2021-02-11 17:11:11 +01:00
--- a/migration/savevm-async.c
+++ b/migration/savevm-async.c
2024-04-25 17:21:29 +02:00
@@ -379,7 +379,7 @@ void qmp_savevm_start(const char *statefile, Error **errp)
2020-05-04 14:35:01 +02:00
2022-10-14 14:07:13 +02:00
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);
2020-05-04 14:35:01 +02:00
if (!snap_state.file) {
error_set(errp, ERROR_CLASS_GENERIC_ERROR, "failed to open '%s'", statefile);
@@ -503,7 +503,8 @@ int load_snapshot_from_blockdev(const char *filename, Error **errp)
2020-05-04 14:35:01 +02:00
blk_op_block_all(be, blocker);
/* restore the VM state */
2022-10-14 14:07:13 +02:00
- 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);
2020-05-04 14:35:01 +02:00
if (!f) {
error_setg(errp, "Could not open VM state file");
goto the_end;