Blame 0002-aio-posix-disable-fdmon-io_uring-when-GSource-is-use.patch

3da886
From: Stefan Hajnoczi <stefanha@redhat.com>
3da886
Date: Mon, 11 May 2020 19:36:30 +0100
3da886
Subject: [PATCH] aio-posix: disable fdmon-io_uring when GSource is used
3da886
3da886
The glib event loop does not call fdmon_io_uring_wait() so fd handlers
3da886
waiting to be submitted build up in the list. There is no benefit is
3da886
using io_uring when the glib GSource is being used, so disable it
3da886
instead of implementing a more complex fix.
3da886
3da886
This fixes a memory leak where AioHandlers would build up and increasing
3da886
amounts of CPU time were spent iterating them in aio_pending(). The
3da886
symptom is that guests become slow when QEMU is built with io_uring
3da886
support.
3da886
3da886
Buglink: https://bugs.launchpad.net/qemu/+bug/1877716
3da886
Fixes: 73fd282e7b6dd4e4ea1c3bbb3d302c8db51e4ccf ("aio-posix: add io_uring fd monitoring implementation")
3da886
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
3da886
---
3da886
 include/block/aio.h |  3 +++
3da886
 util/aio-posix.c    | 12 ++++++++++++
3da886
 util/aio-win32.c    |  4 ++++
3da886
 util/async.c        |  1 +
3da886
 4 files changed, 20 insertions(+)
3da886
3da886
diff --git a/include/block/aio.h b/include/block/aio.h
3da886
index 62ed954344..b2f703fa3f 100644
3da886
--- a/include/block/aio.h
3da886
+++ b/include/block/aio.h
3da886
@@ -701,6 +701,9 @@ void aio_context_setup(AioContext *ctx);
3da886
  */
3da886
 void aio_context_destroy(AioContext *ctx);
3da886
 
3da886
+/* Used internally, do not call outside AioContext code */
3da886
+void aio_context_use_g_source(AioContext *ctx);
3da886
+
3da886
 /**
3da886
  * aio_context_set_poll_params:
3da886
  * @ctx: the aio context
3da886
diff --git a/util/aio-posix.c b/util/aio-posix.c
3da886
index 8af334ab19..1b2a3af65b 100644
3da886
--- a/util/aio-posix.c
3da886
+++ b/util/aio-posix.c
3da886
@@ -682,6 +682,18 @@ void aio_context_destroy(AioContext *ctx)
3da886
     aio_free_deleted_handlers(ctx);
3da886
 }
3da886
 
3da886
+void aio_context_use_g_source(AioContext *ctx)
3da886
+{
3da886
+    /*
3da886
+     * Disable io_uring when the glib main loop is used because it doesn't
3da886
+     * support mixed glib/aio_poll() usage. It relies on aio_poll() being
3da886
+     * called regularly so that changes to the monitored file descriptors are
3da886
+     * submitted, otherwise a list of pending fd handlers builds up.
3da886
+     */
3da886
+    fdmon_io_uring_destroy(ctx);
3da886
+    aio_free_deleted_handlers(ctx);
3da886
+}
3da886
+
3da886
 void aio_context_set_poll_params(AioContext *ctx, int64_t max_ns,
3da886
                                  int64_t grow, int64_t shrink, Error **errp)
3da886
 {
3da886
diff --git a/util/aio-win32.c b/util/aio-win32.c
3da886
index 729d533faf..953c56ab48 100644
3da886
--- a/util/aio-win32.c
3da886
+++ b/util/aio-win32.c
3da886
@@ -414,6 +414,10 @@ void aio_context_destroy(AioContext *ctx)
3da886
 {
3da886
 }
3da886
 
3da886
+void aio_context_use_g_source(AioContext *ctx)
3da886
+{
3da886
+}
3da886
+
3da886
 void aio_context_set_poll_params(AioContext *ctx, int64_t max_ns,
3da886
                                  int64_t grow, int64_t shrink, Error **errp)
3da886
 {
3da886
diff --git a/util/async.c b/util/async.c
3da886
index 3165a28f2f..1319eee3bc 100644
3da886
--- a/util/async.c
3da886
+++ b/util/async.c
3da886
@@ -362,6 +362,7 @@ static GSourceFuncs aio_source_funcs = {
3da886
 
3da886
 GSource *aio_get_g_source(AioContext *ctx)
3da886
 {
3da886
+    aio_context_use_g_source(ctx);
3da886
     g_source_ref(&ctx->source);
3da886
     return &ctx->source;
3da886
 }