]>
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> | |
abc9e57f | 12 | --- |
817b7667 SR |
13 | migration/qemu-file.c | 38 +++++++++++++++++++++++++------------- |
14 | migration/qemu-file.h | 1 + | |
15 | migration/savevm-async.c | 4 ++-- | |
16 | 3 files changed, 28 insertions(+), 15 deletions(-) | |
abc9e57f WB |
17 | |
18 | diff --git a/migration/qemu-file.c b/migration/qemu-file.c | |
817b7667 | 19 | index be21518c57..1926b5202c 100644 |
abc9e57f WB |
20 | --- a/migration/qemu-file.c |
21 | +++ b/migration/qemu-file.c | |
817b7667 | 22 | @@ -30,8 +30,8 @@ |
abc9e57f WB |
23 | #include "trace.h" |
24 | #include "qapi/error.h" | |
25 | ||
26 | -#define IO_BUF_SIZE 32768 | |
817b7667 | 27 | -#define MAX_IOV_SIZE MIN_CONST(IOV_MAX, 64) |
abc9e57f | 28 | +#define DEFAULT_IO_BUF_SIZE 32768 |
817b7667 | 29 | +#define MAX_IOV_SIZE MIN_CONST(IOV_MAX, 256) |
abc9e57f WB |
30 | |
31 | struct QEMUFile { | |
817b7667 | 32 | const QEMUFileOps *ops; |
abc9e57f WB |
33 | @@ -45,7 +45,8 @@ struct QEMUFile { |
34 | when reading */ | |
35 | int buf_index; | |
36 | int buf_size; /* 0 when writing */ | |
37 | - uint8_t buf[IO_BUF_SIZE]; | |
38 | + size_t buf_allocated_size; | |
39 | + uint8_t *buf; | |
40 | ||
41 | DECLARE_BITMAP(may_free, MAX_IOV_SIZE); | |
42 | struct iovec iov[MAX_IOV_SIZE]; | |
43 | @@ -101,7 +102,7 @@ bool qemu_file_mode_is_not_valid(const char *mode) | |
44 | return false; | |
45 | } | |
46 | ||
47 | -QEMUFile *qemu_fopen_ops(void *opaque, const QEMUFileOps *ops) | |
48 | +QEMUFile *qemu_fopen_ops_sized(void *opaque, const QEMUFileOps *ops, size_t buffer_size) | |
49 | { | |
50 | QEMUFile *f; | |
51 | ||
52 | @@ -109,9 +110,17 @@ QEMUFile *qemu_fopen_ops(void *opaque, const QEMUFileOps *ops) | |
53 | ||
54 | f->opaque = opaque; | |
55 | f->ops = ops; | |
56 | + f->buf_allocated_size = buffer_size; | |
57 | + f->buf = malloc(buffer_size); | |
58 | + | |
59 | return f; | |
60 | } | |
61 | ||
62 | +QEMUFile *qemu_fopen_ops(void *opaque, const QEMUFileOps *ops) | |
63 | +{ | |
64 | + return qemu_fopen_ops_sized(opaque, ops, DEFAULT_IO_BUF_SIZE); | |
65 | +} | |
66 | + | |
67 | ||
68 | void qemu_file_set_hooks(QEMUFile *f, const QEMUFileHooks *hooks) | |
69 | { | |
70 | @@ -346,7 +355,7 @@ static ssize_t qemu_fill_buffer(QEMUFile *f) | |
71 | } | |
72 | ||
73 | len = f->ops->get_buffer(f->opaque, f->buf + pending, f->pos, | |
74 | - IO_BUF_SIZE - pending, &local_error); | |
75 | + f->buf_allocated_size - pending, &local_error); | |
76 | if (len > 0) { | |
77 | f->buf_size += len; | |
78 | f->pos += len; | |
79 | @@ -386,6 +395,9 @@ int qemu_fclose(QEMUFile *f) | |
80 | ret = ret2; | |
81 | } | |
82 | } | |
83 | + | |
84 | + free(f->buf); | |
85 | + | |
86 | /* If any error was spotted before closing, we should report it | |
87 | * instead of the close() return value. | |
88 | */ | |
89 | @@ -435,7 +447,7 @@ static void add_buf_to_iovec(QEMUFile *f, size_t len) | |
90 | { | |
91 | if (!add_to_iovec(f, f->buf + f->buf_index, len, false)) { | |
92 | f->buf_index += len; | |
93 | - if (f->buf_index == IO_BUF_SIZE) { | |
94 | + if (f->buf_index == f->buf_allocated_size) { | |
95 | qemu_fflush(f); | |
96 | } | |
97 | } | |
98 | @@ -461,7 +473,7 @@ void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, size_t size) | |
99 | } | |
100 | ||
101 | while (size > 0) { | |
102 | - l = IO_BUF_SIZE - f->buf_index; | |
103 | + l = f->buf_allocated_size - f->buf_index; | |
104 | if (l > size) { | |
105 | l = size; | |
106 | } | |
107 | @@ -508,8 +520,8 @@ size_t qemu_peek_buffer(QEMUFile *f, uint8_t **buf, size_t size, size_t offset) | |
108 | size_t index; | |
109 | ||
110 | assert(!qemu_file_is_writable(f)); | |
111 | - assert(offset < IO_BUF_SIZE); | |
112 | - assert(size <= IO_BUF_SIZE - offset); | |
113 | + assert(offset < f->buf_allocated_size); | |
114 | + assert(size <= f->buf_allocated_size - offset); | |
115 | ||
116 | /* The 1st byte to read from */ | |
117 | index = f->buf_index + offset; | |
118 | @@ -559,7 +571,7 @@ size_t qemu_get_buffer(QEMUFile *f, uint8_t *buf, size_t size) | |
119 | size_t res; | |
120 | uint8_t *src; | |
121 | ||
122 | - res = qemu_peek_buffer(f, &src, MIN(pending, IO_BUF_SIZE), 0); | |
123 | + res = qemu_peek_buffer(f, &src, MIN(pending, f->buf_allocated_size), 0); | |
124 | if (res == 0) { | |
125 | return done; | |
126 | } | |
127 | @@ -593,7 +605,7 @@ size_t qemu_get_buffer(QEMUFile *f, uint8_t *buf, size_t size) | |
128 | */ | |
129 | size_t qemu_get_buffer_in_place(QEMUFile *f, uint8_t **buf, size_t size) | |
130 | { | |
131 | - if (size < IO_BUF_SIZE) { | |
132 | + if (size < f->buf_allocated_size) { | |
133 | size_t res; | |
134 | uint8_t *src; | |
135 | ||
136 | @@ -618,7 +630,7 @@ int qemu_peek_byte(QEMUFile *f, int offset) | |
137 | int index = f->buf_index + offset; | |
138 | ||
139 | assert(!qemu_file_is_writable(f)); | |
140 | - assert(offset < IO_BUF_SIZE); | |
141 | + assert(offset < f->buf_allocated_size); | |
142 | ||
143 | if (index >= f->buf_size) { | |
144 | qemu_fill_buffer(f); | |
145 | @@ -770,7 +782,7 @@ static int qemu_compress_data(z_stream *stream, uint8_t *dest, size_t dest_len, | |
146 | ssize_t qemu_put_compression_data(QEMUFile *f, z_stream *stream, | |
147 | const uint8_t *p, size_t size) | |
148 | { | |
149 | - ssize_t blen = IO_BUF_SIZE - f->buf_index - sizeof(int32_t); | |
150 | + ssize_t blen = f->buf_allocated_size - f->buf_index - sizeof(int32_t); | |
151 | ||
152 | if (blen < compressBound(size)) { | |
153 | return -1; | |
154 | diff --git a/migration/qemu-file.h b/migration/qemu-file.h | |
155 | index a9b6d6ccb7..8752d27c74 100644 | |
156 | --- a/migration/qemu-file.h | |
157 | +++ b/migration/qemu-file.h | |
158 | @@ -120,6 +120,7 @@ typedef struct QEMUFileHooks { | |
159 | } QEMUFileHooks; | |
160 | ||
161 | QEMUFile *qemu_fopen_ops(void *opaque, const QEMUFileOps *ops); | |
162 | +QEMUFile *qemu_fopen_ops_sized(void *opaque, const QEMUFileOps *ops, size_t buffer_size); | |
163 | void qemu_file_set_hooks(QEMUFile *f, const QEMUFileHooks *hooks); | |
164 | int qemu_get_fd(QEMUFile *f); | |
165 | int qemu_fclose(QEMUFile *f); | |
817b7667 | 166 | diff --git a/migration/savevm-async.c b/migration/savevm-async.c |
e9b36665 | 167 | index 593a619088..cc2552d977 100644 |
817b7667 SR |
168 | --- a/migration/savevm-async.c |
169 | +++ b/migration/savevm-async.c | |
e9b36665 | 170 | @@ -418,7 +418,7 @@ void qmp_savevm_start(bool has_statefile, const char *statefile, Error **errp) |
abc9e57f WB |
171 | goto restart; |
172 | } | |
173 | ||
174 | - snap_state.file = qemu_fopen_ops(&snap_state, &block_file_ops); | |
175 | + snap_state.file = qemu_fopen_ops_sized(&snap_state, &block_file_ops, 4 * 1024 * 1024); | |
176 | ||
177 | if (!snap_state.file) { | |
178 | error_set(errp, ERROR_CLASS_GENERIC_ERROR, "failed to open '%s'", statefile); | |
e9b36665 | 179 | @@ -567,7 +567,7 @@ int load_snapshot_from_blockdev(const char *filename, Error **errp) |
abc9e57f WB |
180 | blk_op_block_all(be, blocker); |
181 | ||
182 | /* restore the VM state */ | |
183 | - f = qemu_fopen_ops(be, &loadstate_file_ops); | |
184 | + f = qemu_fopen_ops_sized(be, &loadstate_file_ops, 4 * 1024 * 1024); | |
185 | if (!f) { | |
186 | error_setg(errp, "Could not open VM state file"); | |
187 | goto the_end; |