]> git.proxmox.com Git - pve-qemu.git/blob - debian/patches/pve/0045-PVE-block-pbs-fast-path-reads-without-allocation-if-.patch
update submodule and patches to 7.2.0
[pve-qemu.git] / debian / patches / pve / 0045-PVE-block-pbs-fast-path-reads-without-allocation-if-.patch
1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: Stefan Reiter <s.reiter@proxmox.com>
3 Date: Wed, 9 Dec 2020 11:46:57 +0100
4 Subject: [PATCH] PVE: block/pbs: fast-path reads without allocation if
5 possible
6
7 ...and switch over to g_malloc/g_free while at it to align with other
8 QEMU code.
9
10 Tracing shows the fast-path is taken almost all the time, though not
11 100% so the slow one is still necessary.
12
13 Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
14 Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
15 ---
16 block/pbs.c | 17 ++++++++++++++---
17 1 file changed, 14 insertions(+), 3 deletions(-)
18
19 diff --git a/block/pbs.c b/block/pbs.c
20 index 9d1f1f39d4..ce9a870885 100644
21 --- a/block/pbs.c
22 +++ b/block/pbs.c
23 @@ -200,7 +200,16 @@ static coroutine_fn int pbs_co_preadv(BlockDriverState *bs,
24 BDRVPBSState *s = bs->opaque;
25 int ret;
26 char *pbs_error = NULL;
27 - uint8_t *buf = malloc(bytes);
28 + uint8_t *buf;
29 + bool inline_buf = true;
30 +
31 + /* for single-buffer IO vectors we can fast-path the write directly to it */
32 + if (qiov->niov == 1 && qiov->iov->iov_len >= bytes) {
33 + buf = qiov->iov->iov_base;
34 + } else {
35 + inline_buf = false;
36 + buf = g_malloc(bytes);
37 + }
38
39 if (offset < 0 || bytes < 0) {
40 fprintf(stderr, "unexpected negative 'offset' or 'bytes' value!\n");
41 @@ -223,8 +232,10 @@ static coroutine_fn int pbs_co_preadv(BlockDriverState *bs,
42 return -EIO;
43 }
44
45 - qemu_iovec_from_buf(qiov, 0, buf, bytes);
46 - free(buf);
47 + if (!inline_buf) {
48 + qemu_iovec_from_buf(qiov, 0, buf, bytes);
49 + g_free(buf);
50 + }
51
52 return 0;
53 }