linux-aio: share one LinuxAioState within an AioContext
PATCH RESEND 1/1 linux-aio: share one LinuxAioState within an AioContext
This has better performance because it executes fewer system calls and does not use a bottom half per disk.
Originally proposed by Ming Lei.
Acked-by Stefan Hajnoczi <[email protected]>
Signed-off-by Paolo Bonzini <[email protected]>
---
async.c | 23 +++++++
block/linux-aio.c | 10 ++--
block/raw-posix.c | 119 +++++--------------------------------
block/raw-win32.c | 2 +-
include/block/aio.h | 13 ++++
{block => include/block}/raw-aio.h | 0
6 files changed, 57 insertions(+), 110 deletions(-)
rename {block => include/block}/raw-aio.h (100%)async.c +23 -0
@@ -29,6 +29,7 @@#include "block/thread-pool.h" #include "qemu/main-loop.h" #include "qemu/atomic.h" +#include "block/raw-aio.h" /***********************************************************/ /* bottom halves (can be seen as timers which expire ASAP) */
@@ -242,6 +243,14 @@ aio_ctx_finalize(GSource *source)qemu_bh_delete (ctx->notify_dummy_bh);thread_pool_free (ctx->thread_pool); +#ifdef CONFIG_LINUX_AIO +if (ctx->linux_aio) { +laio_detach_aio_context (ctx->linux_aio, ctx); +laio_cleanup (ctx->linux_aio); + ctx->linux_aio =NULL ; + } +#endif +qemu_mutex_lock (&ctx->bh_lock);while (ctx->first_bh) {QEMUBH *next = ctx->first_bh->next;
@@ -282,6 +291,17 @@ ThreadPool *aio_get_thread_pool(AioContext *ctx)return ctx->thread_pool; } +#ifdef CONFIG_LINUX_AIO +LinuxAioState *aio_get_linux_aio (AioContext *ctx) +{ +if (!ctx->linux_aio) { + ctx->linux_aio =laio_init (); +laio_attach_aio_context (ctx->linux_aio, ctx); + } +return ctx->linux_aio; +} +#endif +void aio_notify (AioContext *ctx) {/* Write e.g. bh->scheduled before reading ctx->notify_me. Pairs
@@ -345,6 +365,9 @@ AioContext *aio_context_new(Error **errp) false, (EventNotifierHandler *) event_notifier_dummy_cb); +#ifdef CONFIG_LINUX_AIO + ctx->linux_aio =NULL ; +#endif ctx->thread_pool =NULL ;qemu_mutex_init (&ctx->bh_lock);rfifolock_init (&ctx->lock, aio_rfifolock_cb, ctx);
block/linux-aio.c +6 -4
@@ -50,6 +50,8 @@ typedef struct { } LaioQueue;struct LinuxAioState { +AioContext *aio_context; +io_context_t ctx;EventNotifier e;
@@ -227,15 +229,14 @@ static void ioq_submit(LinuxAioState *s)void laio_io_plug (BlockDriverState *bs,LinuxAioState *s) { -assert (!s->io_q.plugged); - s->io_q.plugged =1 ; + s->io_q.plugged++; }void laio_io_unplug (BlockDriverState *bs,LinuxAioState *s) {assert (s->io_q.plugged); - s->io_q.plugged =0 ; -if (!s->io_q.blocked && !QSIMPLEQ_EMPTY (&s->io_q.pending)) { +if (--s->io_q.plugged ==0 && + !s->io_q.blocked && !QSIMPLEQ_EMPTY (&s->io_q.pending)) {ioq_submit (s); } }
@@ -325,6 +326,7 @@ void laio_detach_aio_context(LinuxAioState *s, AioContext *old_context)void laio_attach_aio_context (LinuxAioState *s,AioContext *new_context) { + s->aio_context = new_context; s->completion_bh =aio_bh_new (new_context, qemu_laio_completion_bh, s);aio_set_event_notifier (new_context, &s->e, false, qemu_laio_completion_cb);
block/raw-posix.c +14 -105
222 lines not on this page · raw message
block/raw-win32.c +1 -1
@@ -27,7 +27,7 @@#include "qemu/timer.h" #include "block/block_int.h" #include "qemu/module.h" -#include "raw-aio.h" +#include "block/raw-aio.h" #include "trace.h" #include "block/thread-pool.h" #include "qemu/iov.h"
include/block/aio.h +13 -0
@@ -47,6 +47,9 @@ typedef struct AioHandler AioHandler;typedef void QEMUBHFunc (void *opaque);typedef void IOHandler (void *opaque); +struct ThreadPool ; +struct LinuxAioState ; +struct AioContext {GSource source;
@@ -119,6 +122,13 @@ struct AioContext {/* Thread pool for performing work and receiving completion callbacks */ struct ThreadPool *thread_pool; +#ifdef CONFIG_LINUX_AIO +/* State for native Linux AIO. Uses aio_context_acquire/release for +* locking. +*/ +struct LinuxAioState *linux_aio; +#endif +/* TimerLists for calling timers - one per clock type */ QEMUTimerListGroup tlg;
@@ -335,6 +345,9 @@ GSource *aio_get_g_source(AioContext *ctx);/* Return the ThreadPool bound to this AioContext */ struct ThreadPool *aio_get_thread_pool (AioContext *ctx); +/* Return the LinuxAioState bound to this AioContext */ +struct LinuxAioState *aio_get_linux_aio (AioContext *ctx); +/** * aio_timer_new: * @ctx: the aio context
include/block/raw-aio.h renamed from block/raw-aio.h +0 -0
Signature · 1 line
1.8.3.1