Block patches
The following changes since commit 801f3db7564dcce8a37a70833c0abe40ec19f8ce:
Merge remote-tracking branch 'remotes/philmd/tags/kconfig-20210720' into staging (2021-07-20 19:30:28 +0100)
are available in the Git repository at:
https://gitlab.com/stefanha/qemu.git tags/block-pull-request
for you to fetch changes up to d7ddd0a1618a75b31dc308bb37365ce1da972154:
linux-aio: limit the batch size using aio-max-batch parameter (2021-07-21 13:47:50 +0100)
----------------------------------------------------------------
Pull request
Stefano's performance regression fix for commit 2558cb8dd4 ("linux-aio:
increasing MAX_EVENTS to a larger hardcoded value").
----------------------------------------------------------------
Stefano Garzarella (3):
iothread: generalize iothread_set_param/iothread_get_param
iothread: add aio-max-batch parameter
linux-aio: limit the batch size using aio-max-batch parameter
qapi/misc.json | 6 ++- qapi/qom.json | 7 +++- include/block/aio.h | 12 ++++++ include/sysemu/iothread.h | 3 ++ block/linux-aio.c | 9 ++++- iothread.c | 82 ++++++++++++++++++++++++++++++++++----- monitor/hmp-cmds.c | 2 + util/aio-posix.c | 12 ++++++ util/aio-win32.c | 5 +++ util/async.c | 2 + qemu-options.hx | 8 +++- 11 files changed, 134 insertions(+), 14 deletions(-)
Signature · 1 line
2.31.1
[PULL for-6.1 1/3] iothread: generalize iothread_set_param/iothread_get_param
From: Stefano Garzarella <[email protected]>
Changes in preparation for next patches where we add a new parameter not related to the poll mechanism.
Let's add two new generic functions (iothread_set_param and iothread_get_param) that we use to set and get IOThread parameters.
Message-id: [email protected]
--- iothread.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-)
iothread.c +23 -4
@@ -213,7 +213,7 @@ static PollParamInfo poll_shrink_info = { "poll-shrink", offsetof(IOThread, poll_shrink), }; -static void iothread_get_poll_param (Object *obj,Visitor *v, +static void iothread_get_param (Object *obj,Visitor *v,const char *name,void *opaque,Error **errp) {IOThread *iothread =IOTHREAD (obj);
@@ -223,7 +223,7 @@ static void iothread_get_poll_param(Object *obj, Visitor *v,visit_type_int64 (v, name, field, errp); } -static void iothread_set_poll_param (Object *obj,Visitor *v, +static bool iothread_set_param (Object *obj,Visitor *v,const char *name,void *opaque,Error **errp) {IOThread *iothread =IOTHREAD (obj);
@@ -232,17 +232,36 @@ static void iothread_set_poll_param(Object *obj, Visitor *v,int64_t value;if (!visit_type_int64 (v, name, &value, errp)) { -return ; +return false; }if (value <0 ) {error_setg (errp,"%s value must be in range [0, %" PRId64"]" , info->name,INT64_MAX ); -return ; +return false; } *field = value; +return true; +} + +static void iothread_get_poll_param (Object *obj,Visitor *v, +const char *name,void *opaque,Error **errp) +{ + +iothread_get_param (obj, v, name, opaque, errp); +} + +static void iothread_set_poll_param (Object *obj,Visitor *v, +const char *name,void *opaque,Error **errp) +{ +IOThread *iothread =IOTHREAD (obj); + +if (!iothread_set_param (obj, v, name, opaque, errp)) { +return ; + } +if (iothread->ctx) { aio_context_set_poll_params(iothread->ctx, iothread->poll_max_ns,
Signature · 1 line
2.31.1
[PULL for-6.1 3/3] linux-aio: limit the batch size using `aio-max-batch` parameter
In reply to Stefan HajnocziFrom: Stefano Garzarella <[email protected]>
When there are multiple queues attached to the same AIO context, some requests may experience high latency, since in the worst case the AIO engine queue is only flushed when it is full (MAX_EVENTS) or there are no more queues plugged.
Commit 2558cb8dd4 ("linux-aio: increasing MAX_EVENTS to a larger hardcoded value") changed MAX_EVENTS from 128 to 1024, to increase the number of in-flight requests. But this change also increased the potential maximum batch to 1024 elements.
When there is a single queue attached to the AIO context, the issue is mitigated from laio_io_unplug() that will flush the queue every time is invoked since there can't be others queue plugged.
Let's use the new aio-max-batch IOThread parameter to mitigate this issue, limiting the number of requests in a batch.
We also define a default value (32): this value is obtained running some benchmarks and it represents a good tradeoff between the latency increase while a request is queued and the cost of the io_submit(2) system call.
Message-id: [email protected]
--- block/linux-aio.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
block/linux-aio.c +8 -1
@@ -28,6 +28,9 @@*/ #define MAX_EVENTS 1024 +/* Maximum number of requests in a batch. (default value) */ +#define DEFAULT_MAX_BATCH 32 +struct qemu_laiocb {Coroutine *co;LinuxAioState *ctx;
@@ -351,6 +354,10 @@ static int laio_do_submit(int fd, struct qemu_laiocb *laiocb, off_t offset,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 :
@@ -371,7 +378,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_flight + s->io_q.in_queue >=MAX_EVENTS )) { + s->io_q.in_queue >= max_batch)) {ioq_submit (s); }
Signature · 1 line
2.31.1
[PULL for-6.1 2/3] iothread: add aio-max-batch parameter
In reply to Stefan HajnocziFrom: Stefano Garzarella <[email protected]>
The aio-max-batch parameter will be propagated to AIO engines and it will be used to control the maximum number of queued requests.
When there are in queue a number of requests equal to aio-max-batch, the engine invokes the system call to forward the requests to the kernel.
This parameter allows us to control the maximum batch size to reduce the latency that requests might accumulate while queued in the AIO engine queue.
If aio-max-batch is equal to 0 (default value), the AIO engine will use its default maximum batch size value.
Message-id: [email protected]
--- qapi/misc.json | 6 ++++- qapi/qom.json | 7 ++++- include/block/aio.h | 12 +++++++++ include/sysemu/iothread.h | 3 +++ iothread.c | 55 +++++++++++++++++++++++++++++++++++---- monitor/hmp-cmds.c | 2 ++ util/aio-posix.c | 12 +++++++++ util/aio-win32.c | 5 ++++ util/async.c | 2 ++ qemu-options.hx | 8 ++++-- 10 files changed, 103 insertions(+), 9 deletions(-)
qapi/misc.json +5 -1
@@ -86,6 +86,9 @@ # @poll-shrink: how many ns will be removed from polling time, 0 means that # it's not configured (since 2.9) # +# @aio-max-batch: maximum number of requests in a batch for the AIO engine, +# 0 means that the engine will use its default (since 6.1) +# # Since: 2.0 ## { 'struct': 'IOThreadInfo',
@@ -93,7 +96,8 @@ 'thread-id': 'int', 'poll-max-ns': 'int', 'poll-grow': 'int', - 'poll-shrink': 'int' } } + 'poll-shrink': 'int', + 'aio-max-batch': 'int' } } ## # @query-iothreads:
qapi/qom.json +6 -1
@@ -516,12 +516,17 @@ # algorithm detects it is spending too long polling without # encountering events. 0 selects a default behaviour (default: 0) # +# @aio-max-batch: maximum number of requests in a batch for the AIO engine, +# 0 means that the engine will use its default +# (default:0, since 6.1) +# # Since: 2.0 ## { 'struct': 'IothreadProperties', 'data': { '*poll-max-ns': 'int', '*poll-grow': 'int', - '*poll-shrink': 'int' } } + '*poll-shrink': 'int', + '*aio-max-batch': 'int' } } ## # @MemoryBackendProperties:
include/block/aio.h +12 -0
@@ -232,6 +232,9 @@ struct AioContext {int64_t poll_grow;/* polling time growth factor */ int64_t poll_shrink;/* polling time shrink factor */ +/* AIO engine parameters */ +int64_t aio_max_batch;/* maximum number of requests in a batch */ +/* * List of handlers participating in userspace polling. Protected by * ctx->list_lock. Iterated and modified mostly by the event loop thread
@@ -755,4 +758,13 @@ void aio_context_set_poll_params(AioContext *ctx, int64_t max_ns, int64_t grow, int64_t shrink, Error **errp); +/** +* aio_context_set_aio_params: +* @ctx: the aio context +* @max_batch: maximum number of requests in a batch, 0 means that the +* engine will use its default +*/ +void aio_context_set_aio_params (AioContext *ctx,int64_t max_batch, +Error **errp); +#endif
include/sysemu/iothread.h +3 -0
@@ -37,6 +37,9 @@ struct IOThread {int64_t poll_max_ns;int64_t poll_grow;int64_t poll_shrink; + +/* AioContext AIO engine parameters */ +int64_t aio_max_batch; };typedef struct IOThread IOThread ;
iothread.c +50 -5
91 lines not on this page · raw message
monitor/hmp-cmds.c +2 -0
@@ -1893,6 +1893,8 @@ void hmp_info_iothreads(Monitor *mon, const QDict *qdict)monitor_printf (mon," poll-max-ns=%" PRId64"\n" , value->poll_max_ns);monitor_printf (mon," poll-grow=%" PRId64"\n" , value->poll_grow);monitor_printf (mon," poll-shrink=%" PRId64"\n" , value->poll_shrink); +monitor_printf (mon," aio-max-batch=%" PRId64"\n" , + value->aio_max_batch); }qapi_free_IOThreadInfoList (info_list);
util/aio-posix.c +12 -0
@@ -716,3 +716,15 @@ void aio_context_set_poll_params(AioContext *ctx, int64_t max_ns,aio_notify (ctx); } + +void aio_context_set_aio_params (AioContext *ctx,int64_t max_batch, +Error **errp) +{ +/* +* No thread synchronization here, it doesn't matter if an incorrect value +* is used once. +*/ + ctx->aio_max_batch = max_batch; + +aio_notify (ctx); +}
util/aio-win32.c +5 -0
@@ -440,3 +440,8 @@ void aio_context_set_poll_params(AioContext *ctx, int64_t max_ns,error_setg (errp,"AioContext polling is not implemented on Windows" ); } } + +void aio_context_set_aio_params (AioContext *ctx,int64_t max_batch, +Error **errp) +{ +}
util/async.c +2 -0
@@ -554,6 +554,8 @@ AioContext *aio_context_new(Error **errp) ctx->poll_grow =0 ; ctx->poll_shrink =0 ; + ctx->aio_max_batch =0 ; +return ctx; fail:g_source_destroy (&ctx->source);
qemu-options.hx +6 -2
@@ -5301,7 +5301,7 @@ SRST CN=laptop.example.com,O=Example Home,L=London,ST=London,C=GB - ``-object iothread,id=id,poll-max-ns=poll-max-ns,poll-grow=poll-grow,poll-shrink=poll-shrink`` + ``-object iothread,id=id,poll-max-ns=poll-max-ns,poll-grow=poll-grow,poll-shrink=poll-shrink,aio-max-batch=aio-max-batch`` Creates a dedicated event loop thread that devices can be assigned to. This is known as an IOThread. By default device emulation happens in vCPU threads or the main event loop thread.
@@ -5337,7 +5337,11 @@ SRST the polling time when the algorithm detects it is spending too long polling without encountering events. - The polling parameters can be modified at run-time using the + The ``aio-max-batch`` parameter is the maximum number of requests + in a batch for the AIO engine, 0 means that the engine will use + its default. + + The IOThread parameters can be modified at run-time using the ``qom-set`` command (where ``iothread1`` is the IOThread's ``id``):
Signature · 1 line
2.31.1
Peter Maydell
AppliedQuoted 13 lines · Stefan Hajnoczi
The following changes since commit
801f3db7564dcce8a37a70833c0abe40ec19f8ce:Merge remote-tracking branch 'remotes/philmd/tags/kconfig-20210720' into staging (2021-07-20 19:30:28 +0100)
are available in the Git repository at:
https://gitlab.com/stefanha/qemu.git tags/block-pull-request
for you to fetch changes up to
d7ddd0a1618a75b31dc308bb37365ce1da972154:linux-aio: limit the batch size using
aio-max-batchparameter (2021-07-21 13:47:50 +0100)
Quoted 7 lines
----------------------------------------------------------------
Pull requestStefano's performance regression fix for commit
2558cb8dd4("linux-aio:
increasingMAX_EVENTSto a larger hardcoded value").----------------------------------------------------------------
Applied, thanks.
Please update the changelog at https://wiki.qemu.org/ChangeLog/6.1
for any user-visible changes.
-- PMM