]> git.proxmox.com Git - pve-qemu.git/blame - 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
CommitLineData
677d0d16
SR
1From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2From: Stefan Reiter <s.reiter@proxmox.com>
3Date: Wed, 9 Dec 2020 11:46:57 +0100
4Subject: [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
8QEMU code.
9
10Tracing shows the fast-path is taken almost all the time, though not
11100% so the slow one is still necessary.
12
13Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
ddbf7a87 14Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
677d0d16
SR
15---
16 block/pbs.c | 17 ++++++++++++++---
17 1 file changed, 14 insertions(+), 3 deletions(-)
18
19diff --git a/block/pbs.c b/block/pbs.c
d03e1b3c 20index 9d1f1f39d4..ce9a870885 100644
677d0d16
SR
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
4567474e
FE
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,
677d0d16
SR
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
4e1935c2 52 return 0;
677d0d16 53 }