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
7 ...and switch over to g_malloc/g_free while at it to align with other
10 Tracing shows the fast-path is taken almost all the time, though not
11 100% so the slow one is still necessary.
13 Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
14 Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
16 block/pbs.c | 17 ++++++++++++++---
17 1 file changed, 14 insertions(+), 3 deletions(-)
19 diff --git a/block/pbs.c b/block/pbs.c
20 index 9d1f1f39d4..ce9a870885 100644
23 @@ -200,7 +200,16 @@ static coroutine_fn int pbs_co_preadv(BlockDriverState *bs,
24 BDRVPBSState *s = bs->opaque;
26 char *pbs_error = NULL;
27 - uint8_t *buf = malloc(bytes);
29 + bool inline_buf = true;
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;
36 + buf = g_malloc(bytes);
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,
45 - qemu_iovec_from_buf(qiov, 0, buf, bytes);
48 + qemu_iovec_from_buf(qiov, 0, buf, bytes);