From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 84C8D66EB8; Mon, 11 Jan 2021 12:15:10 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 7D21B190FA; Mon, 11 Jan 2021 12:14:40 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 08D18190EA; Mon, 11 Jan 2021 12:14:40 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id C88FC45F58; Mon, 11 Jan 2021 12:14:39 +0100 (CET) From: Stefan Reiter To: pve-devel@lists.proxmox.com, pbs-devel@lists.proxmox.com Date: Mon, 11 Jan 2021 12:14:00 +0100 Message-Id: <20210111111409.32385-3-s.reiter@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210111111409.32385-1-s.reiter@proxmox.com> References: <20210111111409.32385-1-s.reiter@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.041 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH qemu 02/11] PVE: block/pbs: fast-path reads without allocation if possible X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Jan 2021 11:15:10 -0000 ...and switch over to g_malloc/g_free while at it to align with other QEMU code. Tracing shows the fast-path is taken almost all the time, though not 100% so the slow one is still necessary. Signed-off-by: Stefan Reiter --- For that slight unnoticable performance boost :) block/pbs.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/block/pbs.c b/block/pbs.c index 1481a2bfd1..fbf0d8d845 100644 --- a/block/pbs.c +++ b/block/pbs.c @@ -200,7 +200,16 @@ static coroutine_fn int pbs_co_preadv(BlockDriverState *bs, BDRVPBSState *s = bs->opaque; int ret; char *pbs_error = NULL; - uint8_t *buf = malloc(bytes); + uint8_t *buf; + bool inline_buf = true; + + /* for single-buffer IO vectors we can fast-path the write directly to it */ + if (qiov->niov == 1 && qiov->iov->iov_len >= bytes) { + buf = qiov->iov->iov_base; + } else { + inline_buf = false; + buf = g_malloc(bytes); + } ReadCallbackData rcb = { .co = qemu_coroutine_self(), @@ -218,8 +227,10 @@ static coroutine_fn int pbs_co_preadv(BlockDriverState *bs, return -EIO; } - qemu_iovec_from_buf(qiov, 0, buf, bytes); - free(buf); + if (!inline_buf) { + qemu_iovec_from_buf(qiov, 0, buf, bytes); + g_free(buf); + } return ret; } -- 2.20.1