]>
Commit | Line | Data |
---|---|---|
677d0d16 SR |
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> | |
ddbf7a87 | 14 | Signed-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 | ||
19 | diff --git a/block/pbs.c b/block/pbs.c | |
4567474e | 20 | index 0b05ea9080..c5eb4d5bad 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 | ||
52 | return ret; | |
53 | } |