yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

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

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