linux-aio: allow block devices to limit aio-max-batch
cover linux-aio: allow block devices to limit aio-max-batch
Commit d7ddd0a161 ("linux-aio: limit the batch size using aio-max-batch parameter") added a way to limit the batch size of Linux AIO backend for the entire AIO context.
The same AIO context can be shared by multiple devices, so latency-sensitive devices may want to limit the batch size even more to avoid increasing latency.
This series add the aio-max-batch option to the file backend, and use it in laio_co_submit() and laio_io_unplug() to limit the Linux AIO batch size more than the limit set by the AIO context.
Stefano Garzarella (3):
file-posix: add aio-max-batch option
linux-aio: add dev_max_batch parameter to laio_co_submit()
linux-aio: add dev_max_batch parameter to laio_io_unplug()
qapi/block-core.json | 5 +++++ include/block/raw-aio.h | 6 ++++-- block/file-posix.c | 14 ++++++++++++-- block/linux-aio.c | 38 +++++++++++++++++++++++++++----------- 4 files changed, 48 insertions(+), 15 deletions(-)
Signature · 1 line
2.31.1
PATCH 1/3 file-posix: add `aio-max-batch` option
Commit d7ddd0a161 ("linux-aio: limit the batch size using aio-max-batch parameter") added a way to limit the batch size of Linux AIO backend for the entire AIO context.
The same AIO context can be shared by multiple devices, so latency-sensitive devices may want to limit the batch size even more to avoid increasing latency.
For this reason we add the aio-max-batch option to the file backend, which will be used by the next commits to limit the size of batches including requests generated by this device.
--- qapi/block-core.json | 5 +++++ block/file-posix.c | 9 +++++++++ 2 files changed, 14 insertions(+)
qapi/block-core.json +5 -0
@@ -2851,6 +2851,10 @@ # for this device (default: none, forward the commands via SG_IO; # since 2.11) # @aio: AIO backend (default: threads) (since: 2.8) +# @aio-max-batch: maximum number of requests in an AIO backend batch that +# contains request from this block device. 0 means that the +# AIO backend will handle it automatically. +# (default:0, since 6.2) # @locking: whether to enable file locking. If set to 'auto', only enable # when Open File Descriptor (OFD) locking API is available # (default: auto, since 2.10)
@@ -2879,6 +2883,7 @@ '*pr-manager': 'str', '*locking': 'OnOffAuto', '*aio': 'BlockdevAioOptions', + '*aio-max-batch': 'int', '*drop-cache': {'type': 'bool', 'if': 'CONFIG_LINUX'}, '*x-check-cache-dropped': 'bool' },
block/file-posix.c +9 -0
@@ -150,6 +150,8 @@ typedef struct BDRVRawState {uint64_t locked_perm;uint64_t locked_shared_perm; +uint64_t aio_max_batch; +int perm_change_fd;int perm_change_flags;BDRVReopenState *reopen_state;
@@ -530,6 +532,11 @@ static QemuOptsList raw_runtime_opts = { .type = QEMU_OPT_STRING, .help = "host AIO implementation (threads, native, io_uring)", }, + { + .name = "aio-max-batch", + .type = QEMU_OPT_NUMBER, + .help = "AIO max batch size (0 = auto handled by AIO backend, default: 0)", + }, { .name = "locking", .type = QEMU_OPT_STRING,
@@ -609,6 +616,8 @@ static int raw_open_common(BlockDriverState *bs, QDict *options, s->use_linux_io_uring = (aio ==BLOCKDEV_AIO_OPTIONS_IO_URING );#endif + s->aio_max_batch =qemu_opt_get_number (opts,"aio-max-batch" ,0 ); + locking =qapi_enum_parse (&OnOffAuto_lookup,qemu_opt_get (opts,"locking" ),ON_OFF_AUTO_AUTO , &local_err);
Signature · 1 line
2.31.1
Re: [PATCH 1/3] file-posix: add `aio-max-batch` option
Quoted 24 lines · Stefano Garzarella
Commit
d7ddd0a161("linux-aio: limit the batch size usingaio-max-batchparameter") added a way to limit the batch size of Linux AIO backend for the entire AIO context.The same AIO context can be shared by multiple devices, so latency-sensitive devices may want to limit the batch size even more to avoid increasing latency.
For this reason we add the
aio-max-batchoption to the file backend, which will be used by the next commits to limit the size of batches including requests generated by this device.Suggested-by Kevin Wolf <[email protected]>Signed-off-by Stefano Garzarella <[email protected]>--- qapi/block-core.json | 5 +++++ block/file-posix.c | 9 +++++++++ 2 files changed, 14 insertions(+)qapi/block-core.json +0
-0
qapi/block-core.json line 2855
Quoted 5 lines
qapi/block-core.json +2
-0@@ -2851,6 +2851,10 @@ # for this device (default: none, forward the commands via SG_IO; # since 2.11) # @aio: AIO backend (default: threads) (since: 2.8) +# @aio-max-batch: maximum number of requests in an AIO backend batch that +# contains request from this block device. 0 means that the
The first sentence is a little unclear. I guess s/request/requests/ but that still doesn't doesn't fully explain how this works.
Does the AIO backend use the minimum aio-max-batch value of all its blockdevs?
Maybe:
maximum number of requests to batch together into a single submission in the AIO backend. If multiple BlockdevOptionsFile sharing an AIO backend have different values the smallest value is chosen. ...
Re: [PATCH 1/3] file-posix: add `aio-max-batch` option
Quoted 34 lines · Stefan Hajnoczi
Quoted 24 lines · Stefano Garzarella
Commit
d7ddd0a161("linux-aio: limit the batch size usingaio-max-batchparameter") added a way to limit the batch size of Linux AIO backend for the entire AIO context.The same AIO context can be shared by multiple devices, so latency-sensitive devices may want to limit the batch size even more to avoid increasing latency.
For this reason we add the
aio-max-batchoption to the file backend, which will be used by the next commits to limit the size of batches including requests generated by this device.Suggested-by Kevin Wolf <[email protected]>Signed-off-by Stefano Garzarella <[email protected]>--- qapi/block-core.json | 5 +++++ block/file-posix.c | 9 +++++++++ 2 files changed, 14 insertions(+)qapi/block-core.json +0
-0qapi/block-core.json line 2855
Quoted 5 lines
qapi/block-core.json +2
-0@@ -2851,6 +2851,10 @@ # for this device (default: none, forward the commands via SG_IO; # since 2.11) # @aio: AIO backend (default: threads) (since: 2.8) +# @aio-max-batch: maximum number of requests in an AIO backend batch that +# contains request from this block device. 0 means that theThe first sentence is a little unclear. I guess s/request/requests/ but that still doesn't doesn't fully explain how this works.
Quoted 2 lines
Does the AIO backend use the minimum aio-max-batch value of all its blockdevs?
It's a little simpler to avoid having to recalculate the minimum for each attach/release of blockdevs.
When the blockdev does submit or unplug, the queue is flushed if the number of requests in the batch is greater or equal then the smallest aio-max-batch value of the blockdev and the AIO context.
Quoted 6 lines
Maybe:
maximum number of requests to batch together into a single submission in the AIO backend. If multiple BlockdevOptionsFile sharing an AIO backend have different values the smallest value is chosen. ...
Whath about this:
maximum number of requests to batch together into a single submission in the AIO backend. The smallest value between this and AIO context's aio-max-batch value is chosen. ...
Thanks,
Stefano
Re: [PATCH 1/3] file-posix: add `aio-max-batch` option
Am 25.10.2021 um 12:20 hat Stefano Garzarella geschrieben:
Quoted 52 lines · Stefan Hajnoczi
Quoted 34 lines · Stefano Garzarella
Quoted 24 lines
Commit
d7ddd0a161("linux-aio: limit the batch size usingaio-max-batchparameter") added a way to limit the batch size of Linux AIO backend for the entire AIO context.The same AIO context can be shared by multiple devices, so latency-sensitive devices may want to limit the batch size even more to avoid increasing latency.
For this reason we add the
aio-max-batchoption to the file backend, which will be used by the next commits to limit the size of batches including requests generated by this device.Suggested-by Kevin Wolf <[email protected]>Signed-off-by Stefano Garzarella <[email protected]>--- qapi/block-core.json | 5 +++++ block/file-posix.c | 9 +++++++++ 2 files changed, 14 insertions(+)qapi/block-core.json +0
-0qapi/block-core.json line 2855
Quoted 5 lines
qapi/block-core.json +2
-0@@ -2851,6 +2851,10 @@ # for this device (default: none, forward the commands via SG_IO; # since 2.11) # @aio: AIO backend (default: threads) (since: 2.8) +# @aio-max-batch: maximum number of requests in an AIO backend batch that +# contains request from this block device. 0 means that theThe first sentence is a little unclear. I guess s/request/requests/ but that still doesn't doesn't fully explain how this works.
Quoted 2 lines
Does the AIO backend use the minimum aio-max-batch value of all its blockdevs?
It's a little simpler to avoid having to recalculate the minimum for each attach/release of blockdevs.
When the blockdev does submit or unplug, the queue is flushed if the number of requests in the batch is greater or equal then the smallest aio-max-batch value of the blockdev and the AIO context.
Quoted 6 lines
Maybe:
maximum number of requests to batch together into a single submission in the AIO backend. If multiple BlockdevOptionsFile sharing an AIO backend have different values the smallest value is chosen. ...
Quoted 5 lines
Whath about this:
maximum number of requests to batch together into a single submission in the AIO backend. The smallest value between this and AIO context's
aio-max-batch value is chosen. ...
I like this, except that AioContexts are an implementation detail. I think we should refer to the iothread object instead, which is the user visible interface to AioContexts.
Kevin
Re: [PATCH 1/3] file-posix: add `aio-max-batch` option
Quoted 55 lines · Kevin Wolf
Am 25.10.2021 um 12:20 hat Stefano Garzarella geschrieben:
Quoted 54 lines · Stefan Hajnoczi
Quoted 34 lines · Stefano Garzarella
Quoted 24 lines
Commit
d7ddd0a161("linux-aio: limit the batch size usingaio-max-batchparameter") added a way to limit the batch size of Linux AIO backend for the entire AIO context.The same AIO context can be shared by multiple devices, so latency-sensitive devices may want to limit the batch size even more to avoid increasing latency.
For this reason we add the
aio-max-batchoption to the file backend, which will be used by the next commits to limit the size of batches including requests generated by this device.Suggested-by Kevin Wolf <[email protected]>Signed-off-by Stefano Garzarella <[email protected]>--- qapi/block-core.json | 5 +++++ block/file-posix.c | 9 +++++++++ 2 files changed, 14 insertions(+)qapi/block-core.json +0
-0qapi/block-core.json line 2855
Quoted 5 lines
qapi/block-core.json +2
-0@@ -2851,6 +2851,10 @@ # for this device (default: none, forward the commands via SG_IO; # since 2.11) # @aio: AIO backend (default: threads) (since: 2.8) +# @aio-max-batch: maximum number of requests in an AIO backend batch that +# contains request from this block device. 0 means that theThe first sentence is a little unclear. I guess s/request/requests/ but that still doesn't doesn't fully explain how this works.
Quoted 2 lines
Does the AIO backend use the minimum aio-max-batch value of all its blockdevs?
It's a little simpler to avoid having to recalculate the minimum for each attach/release of blockdevs.
When the blockdev does submit or unplug, the queue is flushed if the number of requests in the batch is greater or equal then the smallest aio-max-batch value of the blockdev and the AIO context.
Quoted 6 lines
Maybe:
maximum number of requests to batch together into a single submission in the AIO backend. If multiple BlockdevOptionsFile sharing an AIO backend have different values the smallest value is chosen. ...
Whath about this:
Quoted 7 lines
Quoted 3 lines
maximum number of requests to batch together into a single submission in the AIO backend. The smallest value between this and AIO context's
aio-max-batch value is chosen. ...I like this, except that AioContexts are an implementation detail. I think we should refer to the iothread object instead, which is the user visible interface to AioContexts.
Yep, definitely better:
maximum number of requests to batch together into a single submission in the AIO backend. The smallest value between this and the aio-max-batch value of the IOThread object is chosen. ...
Thanks,
Stefano
PATCH 2/3 linux-aio: add `dev_max_batch` parameter to laio_co_submit()
In reply to Stefano GarzarellaThis new parameter can be used by block devices to limit the Linux AIO batch size more than the limit set by the AIO context.
file-posix backend supports this, passing its aio-max-batch option previously added.
Add an helper function to calculate the maximum batch size.
--- include/block/raw-aio.h | 3 ++- block/file-posix.c | 3 ++- block/linux-aio.c | 30 ++++++++++++++++++++++-------- 3 files changed, 26 insertions(+), 10 deletions(-)
include/block/raw-aio.h +2 -1
@@ -51,7 +51,8 @@ typedef struct LinuxAioState LinuxAioState;LinuxAioState *laio_init (Error **errp);void laio_cleanup (LinuxAioState *s); int coroutine_fn laio_co_submit(BlockDriverState *bs, LinuxAioState *s, int fd, -uint64_t offset,QEMUIOVector *qiov,int type); +uint64_t offset,QEMUIOVector *qiov,int type, +uint64_t dev_max_batch);void laio_detach_aio_context (LinuxAioState *s,AioContext *old_context);void laio_attach_aio_context (LinuxAioState *s,AioContext *new_context);void laio_io_plug (BlockDriverState *bs,LinuxAioState *s);
block/file-posix.c +2 -1
@@ -2066,7 +2066,8 @@ static int coroutine_fn raw_co_prw(BlockDriverState *bs, uint64_t offset, } else if (s->use_linux_aio) {LinuxAioState *aio =aio_get_linux_aio (bdrv_get_aio_context (bs));assert (qiov->size == bytes); -return laio_co_submit (bs, aio, s->fd, offset, qiov, type); +return laio_co_submit (bs, aio, s->fd, offset, qiov, type, + s->aio_max_batch);#endif }
block/linux-aio.c +22 -8
@@ -334,6 +334,23 @@ static void ioq_submit(LinuxAioState *s) } } +static uint64_t laio_max_batch (LinuxAioState *s,uint64_t dev_max_batch) +{ +uint64_t max_batch = s->aio_context->aio_max_batch ?:DEFAULT_MAX_BATCH ; + +/* +* AIO context can be shared between multiple block devices, so +* `dev_max_batch` allows reducing the batch size for latency-sensitive +* devices. +*/ + max_batch =MIN_NON_ZERO (dev_max_batch, max_batch); + +/* limit the batch with the number of available events */ + max_batch =MIN_NON_ZERO (MAX_EVENTS - s->io_q.in_flight, max_batch); + +return max_batch; +} +void laio_io_plug (BlockDriverState *bs,LinuxAioState *s) { s->io_q.plugged++;
@@ -349,15 +366,11 @@ void laio_io_unplug(BlockDriverState *bs, LinuxAioState *s) }static int laio_do_submit (int fd,struct qemu_laiocb *laiocb,off_t offset, -int type) +int type,uint64_t dev_max_batch) {LinuxAioState *s = laiocb->ctx;struct iocb *iocbs = &laiocb->iocb;QEMUIOVector *qiov = laiocb->qiov; -int64_t max_batch = s->aio_context->aio_max_batch ?:DEFAULT_MAX_BATCH ; - -/* limit the batch with the number of available events */ - max_batch =MIN_NON_ZERO (MAX_EVENTS - s->io_q.in_flight, max_batch);switch (type) {case QEMU_AIO_WRITE :
@@ -378,7 +391,7 @@ static int laio_do_submit(int fd, struct qemu_laiocb *laiocb, off_t offset, s->io_q.in_queue++;if (!s->io_q.blocked && (!s->io_q.plugged || - s->io_q.in_queue >= max_batch)) { + s->io_q.in_queue >=laio_max_batch (s, dev_max_batch))) {ioq_submit (s); }
@@ -386,7 +399,8 @@ static int laio_do_submit(int fd, struct qemu_laiocb *laiocb, off_t offset, } int coroutine_fn laio_co_submit(BlockDriverState *bs, LinuxAioState *s, int fd, -uint64_t offset,QEMUIOVector *qiov,int type) +uint64_t offset,QEMUIOVector *qiov,int type, +uint64_t dev_max_batch) {int ret;struct qemu_laiocb laiocb = {
@@ -398,7 +412,7 @@ int coroutine_fn laio_co_submit(BlockDriverState *bs, LinuxAioState *s, int fd, .qiov = qiov, }; - ret =laio_do_submit (fd, &laiocb, offset, type); + ret =laio_do_submit (fd, &laiocb, offset, type, dev_max_batch);if (ret <0 ) {return ret; }
Signature · 1 line
2.31.1
Re: [PATCH 2/3] linux-aio: add `dev_max_batch` parameter to laio_co_submit()
Quoted 6 lines · Stefano Garzarella
This new parameter can be used by block devices to limit the Linux AIO batch size more than the limit set by the AIO context.
file-posix backend supports this, passing its
aio-max-batchoption previously added.
Quoted 8 lines
Add an helper function to calculate the maximum batch size.
Signed-off-by Stefano Garzarella <[email protected]>--- include/block/raw-aio.h | 3 ++- block/file-posix.c | 3 ++- block/linux-aio.c | 30 ++++++++++++++++++++++-------- 3 files changed, 26 insertions(+), 10 deletions(-)
PATCH 3/3 linux-aio: add `dev_max_batch` parameter to laio_io_unplug()
In reply to Stefano GarzarellaBetween the submission of a request and the unplug, other devices with larger limits may have been queued new requests without flushing the batch.
Using the new dev_max_batch parameter, laio_io_unplug() can check if the batch exceeds the device limit to flush the current batch.
--- include/block/raw-aio.h | 3 ++- block/file-posix.c | 2 +- block/linux-aio.c | 8 +++++--- 3 files changed, 8 insertions(+), 5 deletions(-)
include/block/raw-aio.h +2 -1
@@ -56,7 +56,8 @@ int coroutine_fn laio_co_submit(BlockDriverState *bs, LinuxAioState *s, int fd,void laio_detach_aio_context (LinuxAioState *s,AioContext *old_context);void laio_attach_aio_context (LinuxAioState *s,AioContext *new_context);void laio_io_plug (BlockDriverState *bs,LinuxAioState *s); -void laio_io_unplug (BlockDriverState *bs,LinuxAioState *s); +void laio_io_unplug (BlockDriverState *bs,LinuxAioState *s, +uint64_t dev_max_batch);#endif /* io_uring.c - Linux io_uring implementation */ #ifdef CONFIG_LINUX_IO_URING
block/file-posix.c +1 -1
@@ -2125,7 +2125,7 @@ static void raw_aio_unplug(BlockDriverState *bs)#ifdef CONFIG_LINUX_AIO if (s->use_linux_aio) {LinuxAioState *aio =aio_get_linux_aio (bdrv_get_aio_context (bs)); -laio_io_unplug (bs, aio); +laio_io_unplug (bs, aio, s->aio_max_batch); }#endif #ifdef CONFIG_LINUX_IO_URING
block/linux-aio.c +5 -3
@@ -356,11 +356,13 @@ void laio_io_plug(BlockDriverState *bs, LinuxAioState *s) s->io_q.plugged++; } -void laio_io_unplug (BlockDriverState *bs,LinuxAioState *s) +void laio_io_unplug (BlockDriverState *bs,LinuxAioState *s, +uint64_t dev_max_batch) {assert (s->io_q.plugged); -if (--s->io_q.plugged ==0 && - !s->io_q.blocked && !QSIMPLEQ_EMPTY (&s->io_q.pending)) { +if (s->io_q.in_queue >=laio_max_batch (s, dev_max_batch) || + (--s->io_q.plugged ==0 && + !s->io_q.blocked && !QSIMPLEQ_EMPTY (&s->io_q.pending))) {ioq_submit (s); } }
Signature · 1 line
2.31.1
Re: [PATCH 3/3] linux-aio: add `dev_max_batch` parameter to laio_io_unplug()
Quoted 7 lines · Stefano Garzarella
Between the submission of a request and the unplug, other devices with larger limits may have been queued new requests without flushing the batch.
Using the new
dev_max_batchparameter,laio_io_unplug()can check if the batch exceeds the device limit to flush the current batch.
Quoted 6 lines
Signed-off-by Stefano Garzarella <[email protected]>--- include/block/raw-aio.h | 3 ++- block/file-posix.c | 2 +- block/linux-aio.c | 8 +++++--- 3 files changed, 8 insertions(+), 5 deletions(-)
Kind ping :-)
Thanks,
Stefano
Quoted 28 lines · Stefano Garzarella
Commit
d7ddd0a161("linux-aio: limit the batch size usingaio-max-batchparameter") added a way to limit the batch size of Linux AIO backend for the entire AIO context.The same AIO context can be shared by multiple devices, so latency-sensitive devices may want to limit the batch size even more to avoid increasing latency.
This series add the
aio-max-batchoption to the file backend, and use it inlaio_co_submit()andlaio_io_unplug()to limit the Linux AIO batch size more than the limit set by the AIO context.Stefano Garzarella (3):
file-posix: addaio-max-batchoption
linux-aio: adddev_max_batchparameter tolaio_co_submit()
linux-aio: adddev_max_batchparameter tolaio_io_unplug()qapi/block-core.json | 5 +++++ include/block/raw-aio.h | 6 ++++-- block/file-posix.c | 14 ++++++++++++-- block/linux-aio.c | 38 +++++++++++++++++++++++++++----------- 4 files changed, 48 insertions(+), 15 deletions(-)--
2.31.1
Quoted 17 lines · Stefano Garzarella
Commit
d7ddd0a161("linux-aio: limit the batch size usingaio-max-batchparameter") added a way to limit the batch size of Linux AIO backend for the entire AIO context.The same AIO context can be shared by multiple devices, so latency-sensitive devices may want to limit the batch size even more to avoid increasing latency.
This series add the
aio-max-batchoption to the file backend, and use it inlaio_co_submit()andlaio_io_unplug()to limit the Linux AIO batch size more than the limit set by the AIO context.Stefano Garzarella (3):
file-posix: addaio-max-batchoption
linux-aio: adddev_max_batchparameter tolaio_co_submit()
linux-aio: adddev_max_batchparameter tolaio_io_unplug()
Quoted 5 lines
qapi/block-core.json | 5 +++++ include/block/raw-aio.h | 6 ++++-- block/file-posix.c | 14 ++++++++++++-- block/linux-aio.c | 38 +++++++++++++++++++++++++++----------- 4 files changed, 48 insertions(+), 15 deletions(-)
Sorry for the slow review. Comments posted!
Stefan
Am 23.09.2021 um 16:30 hat Stefano Garzarella geschrieben:
Quoted 11 lines
Commit
d7ddd0a161("linux-aio: limit the batch size usingaio-max-batchparameter") added a way to limit the batch size of Linux AIO backend for the entire AIO context.The same AIO context can be shared by multiple devices, so latency-sensitive devices may want to limit the batch size even more to avoid increasing latency.
This series add the
aio-max-batchoption to the file backend, and use it inlaio_co_submit()andlaio_io_unplug()to limit the Linux AIO batch size more than the limit set by the AIO context.
Looks like you're only going to improve the wording for the QAPI documentation for v2, so feel free to add:
Quoted 9 lines · Kevin Wolf
Am 23.09.2021 um 16:30 hat Stefano Garzarella geschrieben:
Quoted 8 lines
Commit
d7ddd0a161("linux-aio: limit the batch size usingaio-max-batchparameter") added a way to limit the batch size of Linux AIO backend for the entire AIO context.The same AIO context can be shared by multiple devices, so latency-sensitive devices may want to limit the batch size even more to avoid increasing latency.
Quoted 9 lines
Quoted 3 lines
This series add the
aio-max-batchoption to the file backend, and use it inlaio_co_submit()andlaio_io_unplug()to limit the Linux AIO batch size more than the limit set by the AIO context.Looks like you're only going to improve the wording for the QAPI documentation for v2, so feel free to add:
Reviewed-by Kevin Wolf <[email protected]>
Yep, I'll add your R-b in the v2 :-)
Thanks,
Stefano