Skip to content

Commit b260773

Browse files
author
Xiaoguang Wang
committed
io_uring: avoid unnecessary io_wq_work copy for fast poll feature
to #28736503 commit 405a5d2 upstream Basically IORING_OP_POLL_ADD command and async armed poll handlers for regular commands don't touch io_wq_work, so only REQ_F_WORK_INITIALIZED is set, can we do io_wq_work copy and restore. Signed-off-by: Xiaoguang Wang <xiaoguang.wang@linux.alibaba.com> Acked-by: Joseph Qi <joseph.qi@linux.alibaba.com> Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Xiaoguang Wang <xiaoguang.wang@linux.alibaba.com> Acked-by: Joseph Qi <joseph.qi@linux.alibaba.com>
1 parent cfbe7e8 commit b260773

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

fs/io_uring.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4254,7 +4254,8 @@ static void io_async_task_func(struct callback_head *cb)
42544254
spin_unlock_irq(&ctx->completion_lock);
42554255

42564256
/* restore ->work in case we need to retry again */
4257-
memcpy(&req->work, &apoll->work, sizeof(req->work));
4257+
if (req->flags & REQ_F_WORK_INITIALIZED)
4258+
memcpy(&req->work, &apoll->work, sizeof(req->work));
42584259
kfree(apoll);
42594260

42604261
if (!canceled) {
@@ -4351,7 +4352,8 @@ static bool io_arm_poll_handler(struct io_kiocb *req)
43514352
return false;
43524353

43534354
req->flags |= REQ_F_POLLED;
4354-
memcpy(&apoll->work, &req->work, sizeof(req->work));
4355+
if (req->flags & REQ_F_WORK_INITIALIZED)
4356+
memcpy(&apoll->work, &req->work, sizeof(req->work));
43554357
had_io = req->io != NULL;
43564358

43574359
get_task_struct(current);
@@ -4376,7 +4378,8 @@ static bool io_arm_poll_handler(struct io_kiocb *req)
43764378
if (!had_io)
43774379
io_poll_remove_double(req);
43784380
spin_unlock_irq(&ctx->completion_lock);
4379-
memcpy(&req->work, &apoll->work, sizeof(req->work));
4381+
if (req->flags & REQ_F_WORK_INITIALIZED)
4382+
memcpy(&req->work, &apoll->work, sizeof(req->work));
43804383
kfree(apoll);
43814384
return false;
43824385
}
@@ -4421,7 +4424,9 @@ static bool io_poll_remove_one(struct io_kiocb *req)
44214424
* io_req_work_drop_env below when dropping the
44224425
* final reference.
44234426
*/
4424-
memcpy(&req->work, &apoll->work, sizeof(req->work));
4427+
if (req->flags & REQ_F_WORK_INITIALIZED)
4428+
memcpy(&req->work, &apoll->work,
4429+
sizeof(req->work));
44254430
kfree(apoll);
44264431
}
44274432
}

0 commit comments

Comments
 (0)