yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-linux-aio-limit-the-batch-size-using-aio-max-batch-p.patch

a83cc2
From 6f4cb3e1e5d718356f16645e806d47cb2159ae98 Mon Sep 17 00:00:00 2001
a83cc2
From: Stefano Garzarella <sgarzare@redhat.com>
a83cc2
Date: Thu, 29 Jul 2021 07:42:33 -0400
a83cc2
Subject: [PATCH 19/39] linux-aio: limit the batch size using `aio-max-batch`
a83cc2
 parameter
a83cc2
a83cc2
RH-Author: Miroslav Rezanina <mrezanin@redhat.com>
a83cc2
RH-MergeRequest: 32: Synchronize with RHEL-AV 8.5 release 27 to RHEL 9
a83cc2
RH-Commit: [11/15] 44e2f2d294d8ed1d13fb29c5c1599543b86c67e5 (mrezanin/centos-src-qemu-kvm)
a83cc2
RH-Bugzilla: 1957194
a83cc2
RH-Acked-by: Stefano Garzarella <sgarzare@redhat.com>
a83cc2
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
a83cc2
RH-Acked-by: Igor Mammedov <imammedo@redhat.com>
a83cc2
RH-Acked-by: Andrew Jones <drjones@redhat.com>
a83cc2
a83cc2
When there are multiple queues attached to the same AIO context,
a83cc2
some requests may experience high latency, since in the worst case
a83cc2
the AIO engine queue is only flushed when it is full (MAX_EVENTS) or
a83cc2
there are no more queues plugged.
a83cc2
a83cc2
Commit 2558cb8dd4 ("linux-aio: increasing MAX_EVENTS to a larger
a83cc2
hardcoded value") changed MAX_EVENTS from 128 to 1024, to increase
a83cc2
the number of in-flight requests. But this change also increased
a83cc2
the potential maximum batch to 1024 elements.
a83cc2
a83cc2
When there is a single queue attached to the AIO context, the issue
a83cc2
is mitigated from laio_io_unplug() that will flush the queue every
a83cc2
time is invoked since there can't be others queue plugged.
a83cc2
a83cc2
Let's use the new `aio-max-batch` IOThread parameter to mitigate
a83cc2
this issue, limiting the number of requests in a batch.
a83cc2
a83cc2
We also define a default value (32): this value is obtained running
a83cc2
some benchmarks and it represents a good tradeoff between the latency
a83cc2
increase while a request is queued and the cost of the io_submit(2)
a83cc2
system call.
a83cc2
a83cc2
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
a83cc2
Message-id: 20210721094211.69853-4-sgarzare@redhat.com
a83cc2
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
a83cc2
(cherry picked from commit d7ddd0a1618a75b31dc308bb37365ce1da972154)
a83cc2
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
a83cc2
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
a83cc2
---
a83cc2
 block/linux-aio.c | 9 ++++++++-
a83cc2
 1 file changed, 8 insertions(+), 1 deletion(-)
a83cc2
a83cc2
diff --git a/block/linux-aio.c b/block/linux-aio.c
a83cc2
index 3c0527c2bf..0dab507b71 100644
a83cc2
--- a/block/linux-aio.c
a83cc2
+++ b/block/linux-aio.c
a83cc2
@@ -28,6 +28,9 @@
a83cc2
  */
a83cc2
 #define MAX_EVENTS 1024
a83cc2
 
a83cc2
+/* Maximum number of requests in a batch. (default value) */
a83cc2
+#define DEFAULT_MAX_BATCH 32
a83cc2
+
a83cc2
 struct qemu_laiocb {
a83cc2
     Coroutine *co;
a83cc2
     LinuxAioState *ctx;
a83cc2
@@ -351,6 +354,10 @@ static int laio_do_submit(int fd, struct qemu_laiocb *laiocb, off_t offset,
a83cc2
     LinuxAioState *s = laiocb->ctx;
a83cc2
     struct iocb *iocbs = &laiocb->iocb;
a83cc2
     QEMUIOVector *qiov = laiocb->qiov;
a83cc2
+    int64_t max_batch = s->aio_context->aio_max_batch ?: DEFAULT_MAX_BATCH;
a83cc2
+
a83cc2
+    /* limit the batch with the number of available events */
a83cc2
+    max_batch = MIN_NON_ZERO(MAX_EVENTS - s->io_q.in_flight, max_batch);
a83cc2
 
a83cc2
     switch (type) {
a83cc2
     case QEMU_AIO_WRITE:
a83cc2
@@ -371,7 +378,7 @@ static int laio_do_submit(int fd, struct qemu_laiocb *laiocb, off_t offset,
a83cc2
     s->io_q.in_queue++;
a83cc2
     if (!s->io_q.blocked &&
a83cc2
         (!s->io_q.plugged ||
a83cc2
-         s->io_q.in_flight + s->io_q.in_queue >= MAX_EVENTS)) {
a83cc2
+         s->io_q.in_queue >= max_batch)) {
a83cc2
         ioq_submit(s);
a83cc2
     }
a83cc2
 
a83cc2
-- 
a83cc2
2.27.0
a83cc2