Skip to content

Commit 8ac5d85

Browse files
committed
io_uring: add local task_work run helper that is entered locked
We have a few spots that drop the mutex just to run local task_work, which immediately tries to grab it again. Add a helper that just passes in whether we're locked already. Signed-off-by: Jens Axboe <[email protected]>
1 parent a1119fb commit 8ac5d85

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

io_uring/io_uring.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,9 +1161,8 @@ static void __cold io_move_task_work_from_local(struct io_ring_ctx *ctx)
11611161
}
11621162
}
11631163

1164-
int io_run_local_work(struct io_ring_ctx *ctx)
1164+
int __io_run_local_work(struct io_ring_ctx *ctx, bool locked)
11651165
{
1166-
bool locked;
11671166
struct llist_node *node;
11681167
struct llist_node fake;
11691168
struct llist_node *current_final = NULL;
@@ -1178,8 +1177,6 @@ int io_run_local_work(struct io_ring_ctx *ctx)
11781177
return -EEXIST;
11791178
}
11801179

1181-
locked = mutex_trylock(&ctx->uring_lock);
1182-
11831180
node = io_llist_xchg(&ctx->work_llist, &fake);
11841181
ret = 0;
11851182
again:
@@ -1204,12 +1201,24 @@ int io_run_local_work(struct io_ring_ctx *ctx)
12041201
goto again;
12051202
}
12061203

1207-
if (locked) {
1204+
if (locked)
12081205
io_submit_flush_completions(ctx);
1209-
mutex_unlock(&ctx->uring_lock);
1210-
}
12111206
trace_io_uring_local_work_run(ctx, ret, loops);
12121207
return ret;
1208+
1209+
}
1210+
1211+
int io_run_local_work(struct io_ring_ctx *ctx)
1212+
{
1213+
bool locked;
1214+
int ret;
1215+
1216+
locked = mutex_trylock(&ctx->uring_lock);
1217+
ret = __io_run_local_work(ctx, locked);
1218+
if (locked)
1219+
mutex_unlock(&ctx->uring_lock);
1220+
1221+
return ret;
12131222
}
12141223

12151224
static void io_req_tw_post(struct io_kiocb *req, bool *locked)

io_uring/io_uring.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ enum {
2727
struct io_uring_cqe *__io_get_cqe(struct io_ring_ctx *ctx);
2828
bool io_req_cqe_overflow(struct io_kiocb *req);
2929
int io_run_task_work_sig(struct io_ring_ctx *ctx);
30+
int __io_run_local_work(struct io_ring_ctx *ctx, bool locked);
3031
int io_run_local_work(struct io_ring_ctx *ctx);
3132
void io_req_complete_failed(struct io_kiocb *req, s32 res);
3233
void __io_req_complete(struct io_kiocb *req, unsigned issue_flags);

0 commit comments

Comments
 (0)