io_uring: avoid whole io_wq_work copy for requests completed inline
PATCH v2 1/2 io_uring: avoid whole io_wq_work copy for requests completed inline
If requests can be submitted and completed inline, we don't need to initialize whole io_wq_work in io_init_req(), which is an expensive operation, add a new 'REQ_F_WORK_INITIALIZED' to control whether io_wq_work is initialized.
I use /dev/nullb0 to evaluate performance improvement in my physical machine:
modprobe null_blk nr_devices=1 completion_nsec=0
sudo taskset -c 60 fio -name=fiotest -filename=/dev/nullb0 -iodepth=128 -thread -rw=read -ioengine=io_uring -direct=1 -bs=4k -size=100G -numjobs=1 -time_based -runtime=120
before this patch:
Run status group 0 (all jobs):
READ: bw=724MiB/s (759MB/s), 724MiB/s-724MiB/s (759MB/s-759MB/s), io=84.8GiB (91.1GB), run=120001-120001msec
With this patch:
Run status group 0 (all jobs):
READ: bw=761MiB/s (798MB/s), 761MiB/s-761MiB/s (798MB/s-798MB/s), io=89.2GiB (95.8GB), run=120001-120001msec
About 5% improvement.
--- fs/io-wq.h | 5 ---- fs/io_uring.c | 78 ++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 62 insertions(+), 21 deletions(-)
fs/io-wq.h +0 -5
@@ -94,11 +94,6 @@ struct io_wq_work {pid_t task_pid; }; -#define INIT_IO_WORK (work, _func) \ - do { \ - *(work) = (struct io_wq_work){ .func = _func }; \ - } while (0) \ -static inline struct io_wq_work *wq_next_work (struct io_wq_work *work) {if (!work->list.next)
fs/io_uring.c +62 -16
184 lines not on this page · raw message
Signature · 1 line
2.17.2
PATCH v2 2/2 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 there is no need to always do io_wq_work copy. Here add a new flag 'REQ_F_WORK_NEED_RESTORE' to control whether to do io_wq_work copy.
--- fs/io_uring.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)
fs/io_uring.c +14 -4
@@ -536,6 +536,7 @@ enum {REQ_F_BUFFER_SELECTED_BIT ,REQ_F_NO_FILE_TABLE_BIT ,REQ_F_WORK_INITIALIZED_BIT , +REQ_F_WORK_NEED_RESTORE_BIT ,/* not a real bit, just to check we're not overflowing the space */ __REQ_F_LAST_BIT,
@@ -593,6 +594,8 @@ enum {REQ_F_NO_FILE_TABLE =BIT (REQ_F_NO_FILE_TABLE_BIT ),/* io_wq_work is initialized */ REQ_F_WORK_INITIALIZED =BIT (REQ_F_WORK_INITIALIZED_BIT ), +/* need restore io_wq_work */ + REQ_F_WORK_NEED_RESTORE = BIT(REQ_F_WORK_NEED_RESTORE_BIT), }; struct async_poll {
@@ -4411,7 +4414,8 @@ static void io_async_task_func(struct callback_head *cb)spin_unlock_irq (&ctx->completion_lock);/* restore ->work in case we need to retry again */ -memcpy (&req->work, &apoll->work,sizeof (req->work)); +if (req->flags &REQ_F_WORK_NEED_RESTORE ) +memcpy (&req->work, &apoll->work,sizeof (req->work));kfree (apoll);if (!canceled) {
@@ -4508,7 +4512,10 @@ static bool io_arm_poll_handler(struct io_kiocb *req)return false; req->flags |=REQ_F_POLLED ; -memcpy (&apoll->work, &req->work,sizeof (req->work)); +if (req->flags &REQ_F_WORK_INITIALIZED ) { + req->flags |=REQ_F_WORK_NEED_RESTORE ; +memcpy (&apoll->work, &req->work,sizeof (req->work)); + } had_io = req->io !=NULL ;get_task_struct (current);
@@ -4533,7 +4540,8 @@ static bool io_arm_poll_handler(struct io_kiocb *req)if (!had_io)io_poll_remove_double (req);spin_unlock_irq (&ctx->completion_lock); -memcpy (&req->work, &apoll->work,sizeof (req->work)); +if (req->flags &REQ_F_WORK_NEED_RESTORE ) +memcpy (&req->work, &apoll->work,sizeof (req->work));kfree (apoll);return false; }
@@ -4578,7 +4586,9 @@ static bool io_poll_remove_one(struct io_kiocb *req)* io_req_work_drop_env below when dropping the * final reference. */ -memcpy (&req->work, &apoll->work,sizeof (req->work)); +if (req->flags &REQ_F_WORK_NEED_RESTORE ) +memcpy (&req->work, &apoll->work, +sizeof (req->work));kfree (apoll); } }
Signature · 1 line
2.17.2