* [Qemu-devel] [PATCH 0/3] block: three optimizations
@ 2014-12-17 15:09 Paolo Bonzini
2014-12-17 15:09 ` [Qemu-devel] [PATCH 1/3] block: mark AioContext as recursive Paolo Bonzini
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Paolo Bonzini @ 2014-12-17 15:09 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf
These are three unrelated micro-optimizations of the block layer.
The first is only visible on non-dataplane operation, the others
are generic.
Paolo Bonzini (3):
block: mark AioContext as recursive
block: do not allocate an iovec per read of a growable/zero_after_eof BDS
block: replace g_new0 with g_new for bottom half allocation.
async.c | 11 +++++++----
block.c | 12 +++++-------
2 files changed, 12 insertions(+), 11 deletions(-)
--
2.1.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH 1/3] block: mark AioContext as recursive
2014-12-17 15:09 [Qemu-devel] [PATCH 0/3] block: three optimizations Paolo Bonzini
@ 2014-12-17 15:09 ` Paolo Bonzini
2014-12-17 15:09 ` [Qemu-devel] [PATCH 2/3] block: do not allocate an iovec per read of a growable/zero_after_eof BDS Paolo Bonzini
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Paolo Bonzini @ 2014-12-17 15:09 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf
AioContext can be accessed recursively, in fact that's what we do with
aio_poll. Marking the GSource as recursive avoids that GLib blocks it
and unblocks it around every call to aio_dispatch, which is a pretty
expensive operation.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
async.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/async.c b/async.c
index 3939b79..572f239 100644
--- a/async.c
+++ b/async.c
@@ -300,6 +300,7 @@ AioContext *aio_context_new(Error **errp)
error_setg_errno(errp, -ret, "Failed to initialize event notifier");
return NULL;
}
+ g_source_set_can_recurse(&ctx->source, true);
aio_set_event_notifier(ctx, &ctx->notifier,
(EventNotifierHandler *)
event_notifier_test_and_clear);
--
2.1.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH 2/3] block: do not allocate an iovec per read of a growable/zero_after_eof BDS
2014-12-17 15:09 [Qemu-devel] [PATCH 0/3] block: three optimizations Paolo Bonzini
2014-12-17 15:09 ` [Qemu-devel] [PATCH 1/3] block: mark AioContext as recursive Paolo Bonzini
@ 2014-12-17 15:09 ` Paolo Bonzini
2014-12-17 15:10 ` [Qemu-devel] [PATCH 3/3] block: replace g_new0 with g_new for bottom half allocation Paolo Bonzini
2014-12-18 12:35 ` [Qemu-devel] [PATCH 0/3] block: three optimizations Kevin Wolf
3 siblings, 0 replies; 5+ messages in thread
From: Paolo Bonzini @ 2014-12-17 15:09 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf
Most reads do not go past the end of the file, and they can use the
input QEMUIOVector instead of creating one. This removes the
qemu_iovec_* functions from the profile.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
block.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/block.c b/block.c
index 4165d42..58f8042 100644
--- a/block.c
+++ b/block.c
@@ -3034,18 +3034,16 @@ static int coroutine_fn bdrv_aligned_preadv(BlockDriverState *bs,
max_nb_sectors = ROUND_UP(MAX(0, total_sectors - sector_num),
align >> BDRV_SECTOR_BITS);
- if (max_nb_sectors > 0) {
+ if (nb_sectors < max_nb_sectors) {
+ ret = drv->bdrv_co_readv(bs, sector_num, nb_sectors, qiov);
+ } else if (max_nb_sectors > 0) {
QEMUIOVector local_qiov;
- size_t local_sectors;
-
- max_nb_sectors = MIN(max_nb_sectors, SIZE_MAX / BDRV_SECTOR_BITS);
- local_sectors = MIN(max_nb_sectors, nb_sectors);
qemu_iovec_init(&local_qiov, qiov->niov);
qemu_iovec_concat(&local_qiov, qiov, 0,
- local_sectors * BDRV_SECTOR_SIZE);
+ max_nb_sectors * BDRV_SECTOR_SIZE);
- ret = drv->bdrv_co_readv(bs, sector_num, local_sectors,
+ ret = drv->bdrv_co_readv(bs, sector_num, max_nb_sectors,
&local_qiov);
qemu_iovec_destroy(&local_qiov);
--
2.1.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH 3/3] block: replace g_new0 with g_new for bottom half allocation.
2014-12-17 15:09 [Qemu-devel] [PATCH 0/3] block: three optimizations Paolo Bonzini
2014-12-17 15:09 ` [Qemu-devel] [PATCH 1/3] block: mark AioContext as recursive Paolo Bonzini
2014-12-17 15:09 ` [Qemu-devel] [PATCH 2/3] block: do not allocate an iovec per read of a growable/zero_after_eof BDS Paolo Bonzini
@ 2014-12-17 15:10 ` Paolo Bonzini
2014-12-18 12:35 ` [Qemu-devel] [PATCH 0/3] block: three optimizations Kevin Wolf
3 siblings, 0 replies; 5+ messages in thread
From: Paolo Bonzini @ 2014-12-17 15:10 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf
This saves about 15% of the clock cycles spent on allocation. Using the
slice allocator does not add a visible improvement; allocation is faster
than malloc, while freeing seems to be slower.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
async.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/async.c b/async.c
index 572f239..2be88cc 100644
--- a/async.c
+++ b/async.c
@@ -44,10 +44,12 @@ struct QEMUBH {
QEMUBH *aio_bh_new(AioContext *ctx, QEMUBHFunc *cb, void *opaque)
{
QEMUBH *bh;
- bh = g_new0(QEMUBH, 1);
- bh->ctx = ctx;
- bh->cb = cb;
- bh->opaque = opaque;
+ bh = g_new(QEMUBH, 1);
+ *bh = (QEMUBH){
+ .ctx = ctx,
+ .cb = cb,
+ .opaque = opaque,
+ };
qemu_mutex_lock(&ctx->bh_lock);
bh->next = ctx->first_bh;
/* Make sure that the members are ready before putting bh into list */
--
2.1.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH 0/3] block: three optimizations
2014-12-17 15:09 [Qemu-devel] [PATCH 0/3] block: three optimizations Paolo Bonzini
` (2 preceding siblings ...)
2014-12-17 15:10 ` [Qemu-devel] [PATCH 3/3] block: replace g_new0 with g_new for bottom half allocation Paolo Bonzini
@ 2014-12-18 12:35 ` Kevin Wolf
3 siblings, 0 replies; 5+ messages in thread
From: Kevin Wolf @ 2014-12-18 12:35 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: qemu-devel
Am 17.12.2014 um 16:09 hat Paolo Bonzini geschrieben:
> These are three unrelated micro-optimizations of the block layer.
> The first is only visible on non-dataplane operation, the others
> are generic.
Thanks, applied all to the block branch.
Kevin
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-12-18 12:35 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-17 15:09 [Qemu-devel] [PATCH 0/3] block: three optimizations Paolo Bonzini
2014-12-17 15:09 ` [Qemu-devel] [PATCH 1/3] block: mark AioContext as recursive Paolo Bonzini
2014-12-17 15:09 ` [Qemu-devel] [PATCH 2/3] block: do not allocate an iovec per read of a growable/zero_after_eof BDS Paolo Bonzini
2014-12-17 15:10 ` [Qemu-devel] [PATCH 3/3] block: replace g_new0 with g_new for bottom half allocation Paolo Bonzini
2014-12-18 12:35 ` [Qemu-devel] [PATCH 0/3] block: three optimizations Kevin Wolf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).