Blame SOURCES/kvm-aio-posix-completely-stop-polling-when-disabled.patch

8fced6
From 4b4fb1cccb8e0307658cee3bc90c77e5f1dde60a Mon Sep 17 00:00:00 2001
8fced6
From: Thomas Huth <thuth@redhat.com>
8fced6
Date: Fri, 9 Oct 2020 10:08:49 -0400
8fced6
Subject: [PATCH 13/14] aio-posix: completely stop polling when disabled
8fced6
8fced6
RH-Author: Thomas Huth <thuth@redhat.com>
8fced6
Message-id: <20201009100849.264994-10-thuth@redhat.com>
8fced6
Patchwork-id: 98603
8fced6
O-Subject: [RHEL-8.4.0 qemu-kvm PATCH 9/9] aio-posix: completely stop polling when disabled
8fced6
Bugzilla: 1846975
8fced6
RH-Acked-by: Jens Freimann <jfreimann@redhat.com>
8fced6
RH-Acked-by: David Hildenbrand <david@redhat.com>
8fced6
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
8fced6
8fced6
From: Stefan Hajnoczi <stefanha@redhat.com>
8fced6
8fced6
One iteration of polling is always performed even when polling is
8fced6
disabled.  This is done because:
8fced6
1. Userspace polling is cheaper than making a syscall.  We might get
8fced6
   lucky.
8fced6
2. We must poll once more after polling has stopped in case an event
8fced6
   occurred while stopping polling.
8fced6
8fced6
However, there are downsides:
8fced6
1. Polling becomes a bottleneck when the number of event sources is very
8fced6
   high.  It's more efficient to monitor fds in that case.
8fced6
2. A high-frequency polling event source can starve non-polling event
8fced6
   sources because ppoll(2)/epoll(7) is never invoked.
8fced6
8fced6
This patch removes the forced polling iteration so that poll_ns=0 really
8fced6
means no polling.
8fced6
8fced6
IOPS increases from 10k to 60k when the guest has 100
8fced6
virtio-blk-pci,num-queues=32 devices and 1 virtio-blk-pci,num-queues=1
8fced6
device because the large number of event sources being polled slows down
8fced6
the event loop.
8fced6
8fced6
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
8fced6
Link: https://lore.kernel.org/r/20200305170806.1313245-2-stefanha@redhat.com
8fced6
Message-Id: <20200305170806.1313245-2-stefanha@redhat.com>
8fced6
(cherry picked from commit e4346192f1c2e1683a807b46efac47ef0cf9b545)
8fced6
Signed-off-by: Thomas Huth <thuth@redhat.com>
8fced6
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
8fced6
---
8fced6
 util/aio-posix.c | 22 +++++++++++++++-------
8fced6
 1 file changed, 15 insertions(+), 7 deletions(-)
8fced6
8fced6
diff --git a/util/aio-posix.c b/util/aio-posix.c
8fced6
index a4977f538e..abc396d030 100644
8fced6
--- a/util/aio-posix.c
8fced6
+++ b/util/aio-posix.c
8fced6
@@ -340,12 +340,13 @@ void aio_set_event_notifier_poll(AioContext *ctx,
8fced6
                     (IOHandler *)io_poll_end);
8fced6
 }
8fced6
 
8fced6
-static void poll_set_started(AioContext *ctx, bool started)
8fced6
+static bool poll_set_started(AioContext *ctx, bool started)
8fced6
 {
8fced6
     AioHandler *node;
8fced6
+    bool progress = false;
8fced6
 
8fced6
     if (started == ctx->poll_started) {
8fced6
-        return;
8fced6
+        return false;
8fced6
     }
8fced6
 
8fced6
     ctx->poll_started = started;
8fced6
@@ -367,8 +368,15 @@ static void poll_set_started(AioContext *ctx, bool started)
8fced6
         if (fn) {
8fced6
             fn(node->opaque);
8fced6
         }
8fced6
+
8fced6
+        /* Poll one last time in case ->io_poll_end() raced with the event */
8fced6
+        if (!started) {
8fced6
+            progress = node->io_poll(node->opaque) || progress;
8fced6
+        }
8fced6
     }
8fced6
     qemu_lockcnt_dec(&ctx->list_lock);
8fced6
+
8fced6
+    return progress;
8fced6
 }
8fced6
 
8fced6
 
8fced6
@@ -599,12 +607,12 @@ static bool try_poll_mode(AioContext *ctx, int64_t *timeout)
8fced6
         }
8fced6
     }
8fced6
 
8fced6
-    poll_set_started(ctx, false);
8fced6
+    if (poll_set_started(ctx, false)) {
8fced6
+        *timeout = 0;
8fced6
+        return true;
8fced6
+    }
8fced6
 
8fced6
-    /* Even if we don't run busy polling, try polling once in case it can make
8fced6
-     * progress and the caller will be able to avoid ppoll(2)/epoll_wait(2).
8fced6
-     */
8fced6
-    return run_poll_handlers_once(ctx, timeout);
8fced6
+    return false;
8fced6
 }
8fced6
 
8fced6
 bool aio_poll(AioContext *ctx, bool blocking)
8fced6
-- 
8fced6
2.27.0
8fced6