]>
Commit | Line | Data |
---|---|---|
abc9e57f WB |
1 | From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
2 | From: Wolfgang Bumiller <w.bumiller@proxmox.com> | |
3 | Date: Mon, 4 May 2020 11:05:08 +0200 | |
817b7667 | 4 | Subject: [PATCH] PVE: add optional buffer size to QEMUFile |
abc9e57f WB |
5 | |
6 | So we can use a 4M buffer for savevm-async which should | |
7 | increase performance storing the state onto ceph. | |
8 | ||
9 | Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com> | |
817b7667 SR |
10 | [increase max IOV count in QEMUFile to actually write more data] |
11 | Signed-off-by: Stefan Reiter <s.reiter@proxmox.com> | |
ddbf7a87 | 12 | Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com> |
abc9e57f | 13 | --- |
817b7667 SR |
14 | migration/qemu-file.c | 38 +++++++++++++++++++++++++------------- |
15 | migration/qemu-file.h | 1 + | |
16 | migration/savevm-async.c | 4 ++-- | |
17 | 3 files changed, 28 insertions(+), 15 deletions(-) | |
abc9e57f WB |
18 | |
19 | diff --git a/migration/qemu-file.c b/migration/qemu-file.c | |
f376b2b9 | 20 | index 6338d8e2ff..6697a93a7e 100644 |
abc9e57f WB |
21 | --- a/migration/qemu-file.c |
22 | +++ b/migration/qemu-file.c | |
817b7667 | 23 | @@ -30,8 +30,8 @@ |
abc9e57f WB |
24 | #include "trace.h" |
25 | #include "qapi/error.h" | |
26 | ||
27 | -#define IO_BUF_SIZE 32768 | |
817b7667 | 28 | -#define MAX_IOV_SIZE MIN_CONST(IOV_MAX, 64) |
abc9e57f | 29 | +#define DEFAULT_IO_BUF_SIZE 32768 |
817b7667 | 30 | +#define MAX_IOV_SIZE MIN_CONST(IOV_MAX, 256) |
abc9e57f WB |
31 | |
32 | struct QEMUFile { | |
817b7667 | 33 | const QEMUFileOps *ops; |
abc9e57f WB |
34 | @@ -45,7 +45,8 @@ struct QEMUFile { |
35 | when reading */ | |
36 | int buf_index; | |
37 | int buf_size; /* 0 when writing */ | |
38 | - uint8_t buf[IO_BUF_SIZE]; | |
39 | + size_t buf_allocated_size; | |
40 | + uint8_t *buf; | |
41 | ||
42 | DECLARE_BITMAP(may_free, MAX_IOV_SIZE); | |
43 | struct iovec iov[MAX_IOV_SIZE]; | |
f376b2b9 | 44 | @@ -103,7 +104,7 @@ bool qemu_file_mode_is_not_valid(const char *mode) |
abc9e57f WB |
45 | return false; |
46 | } | |
47 | ||
f376b2b9 SR |
48 | -QEMUFile *qemu_fopen_ops(void *opaque, const QEMUFileOps *ops, bool has_ioc) |
49 | +QEMUFile *qemu_fopen_ops_sized(void *opaque, const QEMUFileOps *ops, bool has_ioc, size_t buffer_size) | |
abc9e57f WB |
50 | { |
51 | QEMUFile *f; | |
52 | ||
f376b2b9 | 53 | @@ -112,9 +113,17 @@ QEMUFile *qemu_fopen_ops(void *opaque, const QEMUFileOps *ops, bool has_ioc) |
abc9e57f WB |
54 | f->opaque = opaque; |
55 | f->ops = ops; | |
f376b2b9 | 56 | f->has_ioc = has_ioc; |
abc9e57f WB |
57 | + f->buf_allocated_size = buffer_size; |
58 | + f->buf = malloc(buffer_size); | |
59 | + | |
60 | return f; | |
61 | } | |
62 | ||
f376b2b9 | 63 | +QEMUFile *qemu_fopen_ops(void *opaque, const QEMUFileOps *ops, bool has_ioc) |
abc9e57f | 64 | +{ |
f376b2b9 | 65 | + return qemu_fopen_ops_sized(opaque, ops, has_ioc, DEFAULT_IO_BUF_SIZE); |
abc9e57f WB |
66 | +} |
67 | + | |
68 | ||
69 | void qemu_file_set_hooks(QEMUFile *f, const QEMUFileHooks *hooks) | |
70 | { | |
f376b2b9 | 71 | @@ -349,7 +358,7 @@ static ssize_t qemu_fill_buffer(QEMUFile *f) |
abc9e57f WB |
72 | } |
73 | ||
74 | len = f->ops->get_buffer(f->opaque, f->buf + pending, f->pos, | |
75 | - IO_BUF_SIZE - pending, &local_error); | |
76 | + f->buf_allocated_size - pending, &local_error); | |
77 | if (len > 0) { | |
78 | f->buf_size += len; | |
79 | f->pos += len; | |
f376b2b9 | 80 | @@ -389,6 +398,9 @@ int qemu_fclose(QEMUFile *f) |
abc9e57f WB |
81 | ret = ret2; |
82 | } | |
83 | } | |
84 | + | |
85 | + free(f->buf); | |
86 | + | |
87 | /* If any error was spotted before closing, we should report it | |
88 | * instead of the close() return value. | |
89 | */ | |
f376b2b9 | 90 | @@ -443,7 +455,7 @@ static void add_buf_to_iovec(QEMUFile *f, size_t len) |
abc9e57f WB |
91 | { |
92 | if (!add_to_iovec(f, f->buf + f->buf_index, len, false)) { | |
93 | f->buf_index += len; | |
94 | - if (f->buf_index == IO_BUF_SIZE) { | |
95 | + if (f->buf_index == f->buf_allocated_size) { | |
96 | qemu_fflush(f); | |
97 | } | |
98 | } | |
f376b2b9 | 99 | @@ -469,7 +481,7 @@ void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, size_t size) |
abc9e57f WB |
100 | } |
101 | ||
102 | while (size > 0) { | |
103 | - l = IO_BUF_SIZE - f->buf_index; | |
104 | + l = f->buf_allocated_size - f->buf_index; | |
105 | if (l > size) { | |
106 | l = size; | |
107 | } | |
f376b2b9 | 108 | @@ -516,8 +528,8 @@ size_t qemu_peek_buffer(QEMUFile *f, uint8_t **buf, size_t size, size_t offset) |
abc9e57f WB |
109 | size_t index; |
110 | ||
111 | assert(!qemu_file_is_writable(f)); | |
112 | - assert(offset < IO_BUF_SIZE); | |
113 | - assert(size <= IO_BUF_SIZE - offset); | |
114 | + assert(offset < f->buf_allocated_size); | |
115 | + assert(size <= f->buf_allocated_size - offset); | |
116 | ||
117 | /* The 1st byte to read from */ | |
118 | index = f->buf_index + offset; | |
f376b2b9 | 119 | @@ -567,7 +579,7 @@ size_t qemu_get_buffer(QEMUFile *f, uint8_t *buf, size_t size) |
abc9e57f WB |
120 | size_t res; |
121 | uint8_t *src; | |
122 | ||
123 | - res = qemu_peek_buffer(f, &src, MIN(pending, IO_BUF_SIZE), 0); | |
124 | + res = qemu_peek_buffer(f, &src, MIN(pending, f->buf_allocated_size), 0); | |
125 | if (res == 0) { | |
126 | return done; | |
127 | } | |
f376b2b9 | 128 | @@ -601,7 +613,7 @@ size_t qemu_get_buffer(QEMUFile *f, uint8_t *buf, size_t size) |
abc9e57f WB |
129 | */ |
130 | size_t qemu_get_buffer_in_place(QEMUFile *f, uint8_t **buf, size_t size) | |
131 | { | |
132 | - if (size < IO_BUF_SIZE) { | |
133 | + if (size < f->buf_allocated_size) { | |
134 | size_t res; | |
8dca018b | 135 | uint8_t *src = NULL; |
abc9e57f | 136 | |
f376b2b9 | 137 | @@ -626,7 +638,7 @@ int qemu_peek_byte(QEMUFile *f, int offset) |
abc9e57f WB |
138 | int index = f->buf_index + offset; |
139 | ||
140 | assert(!qemu_file_is_writable(f)); | |
141 | - assert(offset < IO_BUF_SIZE); | |
142 | + assert(offset < f->buf_allocated_size); | |
143 | ||
144 | if (index >= f->buf_size) { | |
145 | qemu_fill_buffer(f); | |
f376b2b9 | 146 | @@ -778,7 +790,7 @@ static int qemu_compress_data(z_stream *stream, uint8_t *dest, size_t dest_len, |
abc9e57f WB |
147 | ssize_t qemu_put_compression_data(QEMUFile *f, z_stream *stream, |
148 | const uint8_t *p, size_t size) | |
149 | { | |
150 | - ssize_t blen = IO_BUF_SIZE - f->buf_index - sizeof(int32_t); | |
151 | + ssize_t blen = f->buf_allocated_size - f->buf_index - sizeof(int32_t); | |
152 | ||
153 | if (blen < compressBound(size)) { | |
154 | return -1; | |
155 | diff --git a/migration/qemu-file.h b/migration/qemu-file.h | |
f376b2b9 | 156 | index 3f36d4dc8c..67501fd9cf 100644 |
abc9e57f WB |
157 | --- a/migration/qemu-file.h |
158 | +++ b/migration/qemu-file.h | |
f376b2b9 | 159 | @@ -121,6 +121,7 @@ typedef struct QEMUFileHooks { |
abc9e57f WB |
160 | } QEMUFileHooks; |
161 | ||
f376b2b9 SR |
162 | QEMUFile *qemu_fopen_ops(void *opaque, const QEMUFileOps *ops, bool has_ioc); |
163 | +QEMUFile *qemu_fopen_ops_sized(void *opaque, const QEMUFileOps *ops, bool has_ioc, size_t buffer_size); | |
abc9e57f WB |
164 | void qemu_file_set_hooks(QEMUFile *f, const QEMUFileHooks *hooks); |
165 | int qemu_get_fd(QEMUFile *f); | |
166 | int qemu_fclose(QEMUFile *f); | |
817b7667 | 167 | diff --git a/migration/savevm-async.c b/migration/savevm-async.c |
f376b2b9 | 168 | index 79a0cda906..970ee3b3fc 100644 |
817b7667 SR |
169 | --- a/migration/savevm-async.c |
170 | +++ b/migration/savevm-async.c | |
e9b36665 | 171 | @@ -418,7 +418,7 @@ void qmp_savevm_start(bool has_statefile, const char *statefile, Error **errp) |
abc9e57f WB |
172 | goto restart; |
173 | } | |
174 | ||
175 | - snap_state.file = qemu_fopen_ops(&snap_state, &block_file_ops); | |
f376b2b9 | 176 | + snap_state.file = qemu_fopen_ops_sized(&snap_state, &block_file_ops, false, 4 * 1024 * 1024); |
abc9e57f WB |
177 | |
178 | if (!snap_state.file) { | |
179 | error_set(errp, ERROR_CLASS_GENERIC_ERROR, "failed to open '%s'", statefile); | |
e9b36665 | 180 | @@ -567,7 +567,7 @@ int load_snapshot_from_blockdev(const char *filename, Error **errp) |
abc9e57f WB |
181 | blk_op_block_all(be, blocker); |
182 | ||
183 | /* restore the VM state */ | |
184 | - f = qemu_fopen_ops(be, &loadstate_file_ops); | |
f376b2b9 | 185 | + f = qemu_fopen_ops_sized(be, &loadstate_file_ops, false, 4 * 1024 * 1024); |
abc9e57f WB |
186 | if (!f) { |
187 | error_setg(errp, "Could not open VM state file"); | |
188 | goto the_end; |