Skip to content

Commit

Permalink
io_uring: add helper for task work execution code
Browse files Browse the repository at this point in the history
Add a helper for task work execution code. We will use it later.

Reviewed-by: Pavel Begunkov <asml.silence@gmail.com>
Signed-off-by: Hao Xu <haoxu@linux.alibaba.com>
Link: https://lore.kernel.org/r/20211207093951.247840-4-haoxu@linux.alibaba.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
Hao Xu authored and Jens Axboe committed Dec 7, 2021
1 parent 4813c37 commit 9f8d032
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions fs/io_uring.c
Original file line number Diff line number Diff line change
Expand Up @@ -2217,6 +2217,25 @@ static void ctx_flush_and_put(struct io_ring_ctx *ctx, bool *locked)
percpu_ref_put(&ctx->refs);
}

static void handle_tw_list(struct io_wq_work_node *node, struct io_ring_ctx **ctx, bool *locked)
{
do {
struct io_wq_work_node *next = node->next;
struct io_kiocb *req = container_of(node, struct io_kiocb,
io_task_work.node);

if (req->ctx != *ctx) {
ctx_flush_and_put(*ctx, locked);
*ctx = req->ctx;
/* if not contended, grab and improve batching */
*locked = mutex_trylock(&(*ctx)->uring_lock);
percpu_ref_get(&(*ctx)->refs);
}
req->io_task_work.func(req, locked);
node = next;
} while (node);
}

static void tctx_task_work(struct callback_head *cb)
{
bool locked = false;
Expand All @@ -2239,22 +2258,7 @@ static void tctx_task_work(struct callback_head *cb)
if (!node)
break;

do {
struct io_wq_work_node *next = node->next;
struct io_kiocb *req = container_of(node, struct io_kiocb,
io_task_work.node);

if (req->ctx != ctx) {
ctx_flush_and_put(ctx, &locked);
ctx = req->ctx;
/* if not contended, grab and improve batching */
locked = mutex_trylock(&ctx->uring_lock);
percpu_ref_get(&ctx->refs);
}
req->io_task_work.func(req, &locked);
node = next;
} while (node);

handle_tw_list(node, &ctx, &locked);
cond_resched();
}

Expand Down

0 comments on commit 9f8d032

Please sign in to comment.