Skip to content

Commit 405a5d2

Browse files
Xiaoguang Wangaxboe
authored andcommitted
io_uring: avoid unnecessary io_wq_work copy for fast poll feature
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 <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 7cdaf58 commit 405a5d2

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
@@ -4262,7 +4262,8 @@ static void io_async_task_func(struct callback_head *cb)
42624262
spin_unlock_irq(&ctx->completion_lock);
42634263

42644264
/* restore ->work in case we need to retry again */
4265-
memcpy(&req->work, &apoll->work, sizeof(req->work));
4265+
if (req->flags & REQ_F_WORK_INITIALIZED)
4266+
memcpy(&req->work, &apoll->work, sizeof(req->work));
42664267
kfree(apoll);
42674268

42684269
if (!canceled) {
@@ -4359,7 +4360,8 @@ static bool io_arm_poll_handler(struct io_kiocb *req)
43594360
return false;
43604361

43614362
req->flags |= REQ_F_POLLED;
4362-
memcpy(&apoll->work, &req->work, sizeof(req->work));
4363+
if (req->flags & REQ_F_WORK_INITIALIZED)
4364+
memcpy(&apoll->work, &req->work, sizeof(req->work));
43634365
had_io = req->io != NULL;
43644366

43654367
get_task_struct(current);
@@ -4384,7 +4386,8 @@ static bool io_arm_poll_handler(struct io_kiocb *req)
43844386
if (!had_io)
43854387
io_poll_remove_double(req);
43864388
spin_unlock_irq(&ctx->completion_lock);
4387-
memcpy(&req->work, &apoll->work, sizeof(req->work));
4389+
if (req->flags & REQ_F_WORK_INITIALIZED)
4390+
memcpy(&req->work, &apoll->work, sizeof(req->work));
43884391
kfree(apoll);
43894392
return false;
43904393
}
@@ -4429,7 +4432,9 @@ static bool io_poll_remove_one(struct io_kiocb *req)
44294432
* io_req_work_drop_env below when dropping the
44304433
* final reference.
44314434
*/
4432-
memcpy(&req->work, &apoll->work, sizeof(req->work));
4435+
if (req->flags & REQ_F_WORK_INITIALIZED)
4436+
memcpy(&req->work, &apoll->work,
4437+
sizeof(req->work));
44334438
kfree(apoll);
44344439
}
44354440
}

0 commit comments

Comments
 (0)