Skip to contentSkip to conversation

Block patches

GIT PULL Stefan Hajnoczi 3 participants 9 messages Jul 15, 2016 – Jul 19, 2016 Block layer

lore
Share & tools
lore
#0 lore raw

The following changes since commit 14c7d99333e4a474c65bdae6f99aa8837e8078e6:

Merge remote-tracking branch 'remotes/pmaydell/tags/pull-target-arm-20160714' into staging (2016-07-14 17:32:53 +0100)

are available in the git repository at:

git://github.com/stefanha/qemu.git tags/block-pull-request

for you to fetch changes up to 325e00006139a30a4c747cf35489ea5bee8da272:

linux-aio: prevent submitting more than MAX_EVENTS (2016-07-15 12:45:47 +0100)

----------------------------------------------------------------

----------------------------------------------------------------

Cao jin (1):
aio_ctx_check: follow CODING_STYLE

Paolo Bonzini (1):
linux-aio: share one LinuxAioState within an AioContext

Roman Pen (1):
linux-aio: prevent submitting more than MAX_EVENTS

Vladimir Sementsov-Ogievskiy (1):
spec/parallels: fix a mistake

 async.c                  |  25 +++++++++-
 block/linux-aio.c        |  36 ++++++++------
 block/raw-aio.h          |  68 ---------------------------
 block/raw-posix.c        | 119 ++++++-----------------------------------------
 block/raw-win32.c        |   2 +-
 docs/specs/parallels.txt |   2 +-
 include/block/aio.h      |  13 ++++++
 include/block/raw-aio.h  |  68 +++++++++++++++++++++++++++
 8 files changed, 143 insertions(+), 190 deletions(-)
 delete mode 100644 block/raw-aio.h
 create mode 100644 include/block/raw-aio.h
Signature · 1 line
2.7.4
#1 lore raw

[Qemu-devel] [PULL 1/4] spec/parallels: fix a mistake

From: Vladimir Sementsov-Ogievskiy <[email protected]>

We have only one flag for now - Empty Image flag. The patch fixes unused bits specification and marks bit 1 as usused.

---
 docs/specs/parallels.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
docs/specs/parallels.txt +1 -1
index b4fe229..e9271eb 100644
@@ -94,7 +94,7 @@ Bytes:
               Bit 0: Empty Image bit. If set, the image should be
                      considered clear.
 
-              Bits 2-31: Unused.
+              Bits 1-31: Unused.
 
   56 - 63:    ext_off
               Format Extension offset, an offset, in sectors, from the start of
Signature · 1 line
2.7.4
#2 lore raw

[Qemu-devel] [PULL 3/4] aio_ctx_check: follow CODING_STYLE

In reply to Stefan Hajnoczi

From: Cao jin <[email protected]>

replace tab with spaces

Message-id: [email protected]

---
 async.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
async.c +1 -1
index 6caa98c..0e0efc3 100644
@@ -218,7 +218,7 @@ aio_ctx_check(GSource *source)
     for (bh = ctx->first_bh; bh; bh = bh->next) {
         if (!bh->deleted && bh->scheduled) {
             return true;
-	}
+        }
     }
     return aio_pending(ctx) || (timerlistgroup_deadline_ns(&ctx->tlg) == 0);
 }
Signature · 1 line
2.7.4
#3 lore raw

[Qemu-devel] [PULL 2/4] linux-aio: share one LinuxAioState within an AioContext

In reply to Stefan Hajnoczi

From: Paolo Bonzini <[email protected]>

This has better performance because it executes fewer system calls and does not use a bottom half per disk.

Originally proposed by Ming Lei.

Message-id: [email protected]

---
 async.c                 |  23 ++++++++++
 block/linux-aio.c       |  10 ++--
 block/raw-aio.h         |  68 ---------------------------
 block/raw-posix.c       | 119 ++++++------------------------------------------
 block/raw-win32.c       |   2 +-
 include/block/aio.h     |  13 ++++++
 include/block/raw-aio.h |  68 +++++++++++++++++++++++++++
 7 files changed, 125 insertions(+), 178 deletions(-)
 delete mode 100644 block/raw-aio.h
 create mode 100644 include/block/raw-aio.h
async.c +23 -0
index b4bf205..6caa98c 100644
@@ -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
index 5c104bd..1d702a5 100644
@@ -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-aio.h deleted +0 -68

68 lines not on this page · raw message

block/raw-posix.c +14 -105

222 lines not on this page · raw message

block/raw-win32.c +1 -1
index 62edb1a..9b813d9 100644
@@ -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
index 88a64ee..afd72a7 100644
@@ -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 new file +68 -0

68 lines not on this page · raw message

Signature · 1 line
2.7.4
#4 lore raw

[Qemu-devel] [PULL 4/4] linux-aio: prevent submitting more than MAX_EVENTS

In reply to Stefan Hajnoczi

From: Roman Pen <[email protected]>

Invoking io_setup(MAX_EVENTS) we ask kernel to create ring buffer for us with specified number of events. But kernel ring buffer allocation logic is a bit tricky (ring buffer is page size aligned + some percpu allocation are required) so eventually more than requested events number is allocated.

Quoted 1 line

From a userspace side we have to follow the convention and should not try

to io_submit() more or logic, which consumes completed events, should be changed accordingly. The pitfall is in the following sequence:

    MAX_EVENTS = 128
    io_setup(MAX_EVENTS)

    io_submit(MAX_EVENTS)
    io_submit(MAX_EVENTS)

    /* now 256 events are in-flight */

    io_getevents(MAX_EVENTS) = 128

    /* we can handle only 128 events at once, to be sure
     * that nothing is pended the io_getevents(MAX_EVENTS)
     * call must be invoked once more or hang will happen. */

To prevent the hang or reiteration of io_getevents() call this patch restricts the number of in-flights, which is now limited to MAX_EVENTS.

Message-id: [email protected]

---
 block/linux-aio.c | 26 ++++++++++++++++----------
 1 file changed, 16 insertions(+), 10 deletions(-)
block/linux-aio.c +16 -10
index 1d702a5..de3548f 100644
@@ -28,8 +28,6 @@
  */
 #define MAX_EVENTS 128
 
-#define MAX_QUEUED_IO  128
-
 struct qemu_laiocb {
     BlockAIOCB common;
     Coroutine *co;
@@ -44,7 +42,8 @@ struct qemu_laiocb {
 
 typedef struct {
     int plugged;
-    unsigned int n;
+    unsigned int in_queue;
+    unsigned int in_flight;
     bool blocked;
     QSIMPLEQ_HEAD(, qemu_laiocb) pending;
 } LaioQueue;
@@ -131,6 +130,7 @@ static void qemu_laio_completion_bh(void *opaque)
             s->event_max = 0;
             return; /* no more events */
         }
+        s->io_q.in_flight -= s->event_max;
     }
 
     /* Reschedule so nested event loops see currently pending completions */
@@ -192,7 +192,8 @@ static void ioq_init(LaioQueue *io_q)
 {
     QSIMPLEQ_INIT(&io_q->pending);
     io_q->plugged = 0;
-    io_q->n = 0;
+    io_q->in_queue = 0;
+    io_q->in_flight = 0;
     io_q->blocked = false;
 }
 
@@ -200,14 +201,17 @@ static void ioq_submit(LinuxAioState *s)
 {
     int ret, len;
     struct qemu_laiocb *aiocb;
-    struct iocb *iocbs[MAX_QUEUED_IO];
+    struct iocb *iocbs[MAX_EVENTS];
     QSIMPLEQ_HEAD(, qemu_laiocb) completed;
 
     do {
+        if (s->io_q.in_flight >= MAX_EVENTS) {
+            break;
+        }
         len = 0;
         QSIMPLEQ_FOREACH(aiocb, &s->io_q.pending, next) {
             iocbs[len++] = &aiocb->iocb;
-            if (len == MAX_QUEUED_IO) {
+            if (s->io_q.in_flight + len >= MAX_EVENTS) {
                 break;
             }
         }
@@ -220,11 +224,12 @@ static void ioq_submit(LinuxAioState *s)
             abort();
         }
 
-        s->io_q.n -= ret;
+        s->io_q.in_flight += ret;
+        s->io_q.in_queue  -= ret;
         aiocb = container_of(iocbs[ret - 1], struct qemu_laiocb, iocb);
         QSIMPLEQ_SPLIT_AFTER(&s->io_q.pending, aiocb, next, &completed);
     } while (ret == len && !QSIMPLEQ_EMPTY(&s->io_q.pending));
-    s->io_q.blocked = (s->io_q.n > 0);
+    s->io_q.blocked = (s->io_q.in_queue > 0);
 }
 
 void laio_io_plug(BlockDriverState *bs, LinuxAioState *s)
@@ -264,9 +269,10 @@ static int laio_do_submit(int fd, struct qemu_laiocb *laiocb, off_t offset,
     io_set_eventfd(&laiocb->iocb, event_notifier_get_fd(&s->e));
 
     QSIMPLEQ_INSERT_TAIL(&s->io_q.pending, laiocb, next);
-    s->io_q.n++;
+    s->io_q.in_queue++;
     if (!s->io_q.blocked &&
-        (!s->io_q.plugged || s->io_q.n >= MAX_QUEUED_IO)) {
+        (!s->io_q.plugged ||
+         s->io_q.in_flight + s->io_q.in_queue >= MAX_EVENTS)) {
         ioq_submit(s);
     }
 
Signature · 1 line
2.7.4
#5 lore raw
In reply to Stefan Hajnoczi
Quoted 8 lines · Stefan Hajnoczi

The following changes since commit 14c7d99333e4a474c65bdae6f99aa8837e8078e6:

Merge remote-tracking branch 'remotes/pmaydell/tags/pull-target-arm-20160714' into staging (2016-07-14 17:32:53 +0100)

are available in the git repository at:

git://github.com/stefanha/qemu.git tags/block-pull-request

Quoted 7 lines

for you to fetch changes up to 325e00006139a30a4c747cf35489ea5bee8da272:

linux-aio: prevent submitting more than MAX_EVENTS (2016-07-15 12:45:47 +0100)

----------------------------------------------------------------

----------------------------------------------------------------

I'm afraid this fails to build for w32:

/home/petmay01/linaro/qemu-for-merges/block/win32-aio.c:30:21: fatal
error: raw-aio.h: No such file or directory

 #include "raw-aio.h"
                     ^

compilation terminated.

Looks like that should be "block/raw-aio.h".

thanks
-- PMM

#6 lore raw
Quoted 9 lines · Peter Maydell

I'm afraid this fails to build for w32:

/home/petmay01/linaro/qemu-for-merges/block/win32-aio.c:30:21: fatal
error: raw-aio.h: No such file or directory

 #include "raw-aio.h"
                     ^

compilation terminated.

Looks like that should be "block/raw-aio.h".

But that's in the patch:

block/raw-win32.c +1 -1
index 62edb1a..9b813d9 100644
@@ -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"

Did you get a conflict, or did git screw up some resolution?

Paolo

#7 lore raw

block/raw-win32.c

Quoted 16 lines · Paolo Bonzini
Quoted 9 lines · Peter Maydell

I'm afraid this fails to build for w32:

/home/petmay01/linaro/qemu-for-merges/block/win32-aio.c:30:21: fatal
error: raw-aio.h: No such file or directory

 #include "raw-aio.h"
                     ^

compilation terminated.

Looks like that should be "block/raw-aio.h".

But that's in the patch:

block/raw-win32.c +0 -0

This is not the .c file which is mentioned in the above compiler error message :-)

thanks
-- PMM

#8 lore raw
Quoted 12 lines · Peter Maydell
Quoted 11 lines · Paolo Bonzini
Quoted 8 lines · Peter Maydell

I'm afraid this fails to build for w32:

/home/petmay01/linaro/qemu-for-merges/block/win32-aio.c:30:21: fatal
error: raw-aio.h: No such file or directory

 #include "raw-aio.h"
                     ^

compilation terminated.

Quoted 8 lines

block/raw-win32.c

Quoted 5 lines
Quoted 1 line

Looks like that should be "block/raw-aio.h".

But that's in the patch:

block/raw-win32.c +0 -0

This is not the .c file which is mentioned in the above compiler error message :-)

I resolved the issue yesterday and sent a new block pull request.

Stefan