]> git.proxmox.com Git - pve-qemu.git/blob - debian/patches/pve/0044-PVE-block-pbs-fast-path-reads-without-allocation-if-.patch
a85ebc211a6df154b6a3a855b948a0219bbd7825
[pve-qemu.git] / debian / patches / pve / 0044-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 ---
15 block/pbs.c | 17 ++++++++++++++---
16 1 file changed, 14 insertions(+), 3 deletions(-)
17
18 diff --git a/block/pbs.c b/block/pbs.c
19 index 1481a2bfd1..fbf0d8d845 100644
20 --- a/block/pbs.c
21 +++ b/block/pbs.c
22 @@ -200,7 +200,16 @@ static coroutine_fn int pbs_co_preadv(BlockDriverState *bs,
23 BDRVPBSState *s = bs->opaque;
24 int ret;
25 char *pbs_error = NULL;
26 - uint8_t *buf = malloc(bytes);
27 + uint8_t *buf;
28 + bool inline_buf = true;
29 +
30 + /* for single-buffer IO vectors we can fast-path the write directly to it */
31 + if (qiov->niov == 1 && qiov->iov->iov_len >= bytes) {
32 + buf = qiov->iov->iov_base;
33 + } else {
34 + inline_buf = false;
35 + buf = g_malloc(bytes);
36 + }
37
38 ReadCallbackData rcb = {
39 .co = qemu_coroutine_self(),
40 @@ -218,8 +227,10 @@ static coroutine_fn int pbs_co_preadv(BlockDriverState *bs,
41 return -EIO;
42 }
43
44 - qemu_iovec_from_buf(qiov, 0, buf, bytes);
45 - free(buf);
46 + if (!inline_buf) {
47 + qemu_iovec_from_buf(qiov, 0, buf, bytes);
48 + g_free(buf);
49 + }
50
51 return ret;
52 }