Nodes are no longer added to poll_aio_handlers when adaptive polling is disabled, preventing unnecessary try_poll_mode() calls. Additionally, aio_poll() skips try_poll_mode() when timeout is 0.
This avoids iterating over all nodes to compute max_ns unnecessarily when polling is disabled or timeout is 0. Signed-off-by: Jaehoon Kim <[email protected]> --- util/aio-posix.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/util/aio-posix.c b/util/aio-posix.c index e24b955fd9..7ddf92a25f 100644 --- a/util/aio-posix.c +++ b/util/aio-posix.c @@ -306,9 +306,8 @@ static bool aio_dispatch_handler(AioContext *ctx, AioHandler *node) * fdmon_supports_polling(), but only until the fd fires for the first * time. */ - if (!QLIST_IS_INSERTED(node, node_deleted) && - !QLIST_IS_INSERTED(node, node_poll) && - node->io_poll) { + if (ctx->poll_max_ns && !QLIST_IS_INSERTED(node, node_deleted) && + !QLIST_IS_INSERTED(node, node_poll) && node->io_poll) { trace_poll_add(ctx, node, node->pfd.fd, revents); if (ctx->poll_started && node->io_poll_begin) { node->io_poll_begin(node->opaque); @@ -630,7 +629,7 @@ static void adjust_polling_time(AioContext *ctx, AioPolledEvent *poll, bool aio_poll(AioContext *ctx, bool blocking) { AioHandlerList ready_list = QLIST_HEAD_INITIALIZER(ready_list); - bool progress; + bool progress = false; bool use_notify_me; int64_t timeout; int64_t start = 0; @@ -655,7 +654,9 @@ bool aio_poll(AioContext *ctx, bool blocking) } timeout = blocking ? aio_compute_timeout(ctx) : 0; - progress = try_poll_mode(ctx, &ready_list, &timeout); + if ((ctx->poll_max_ns != 0) && (timeout != 0)) { + progress = try_poll_mode(ctx, &ready_list, &timeout); + } assert(!(timeout && progress)); /* -- 2.50.1
