public inbox for [email protected]
 help / color / mirror / Atom feed
From: Pavel Begunkov <[email protected]>
To: Jens Axboe <[email protected]>, [email protected]
Subject: [PATCH 3/3] io_uring: tweak io_req_task_work_add
Date: Wed, 30 Jun 2021 21:54:05 +0100	[thread overview]
Message-ID: <24b575ea075ae923992e9ce86b61e8b51629fd29.1625086418.git.asml.silence@gmail.com> (raw)
In-Reply-To: <[email protected]>

Whenever possible we don't want to fallback a request. task_work_add()
will be fine if the task is exiting, so don't check for PF_EXITING,
there is anyway only a relatively small gap between setting the flag
and doing the final task_work_run().

Also add likely for the hot path.

Signed-off-by: Pavel Begunkov <[email protected]>
---
 fs/io_uring.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index 5fab427305e3..1893a4229dbb 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -1990,9 +1990,6 @@ static int io_req_task_work_add(struct io_kiocb *req)
 	unsigned long flags;
 	int ret = 0;
 
-	if (unlikely(tsk->flags & PF_EXITING))
-		return -ESRCH;
-
 	WARN_ON_ONCE(!tctx);
 
 	spin_lock_irqsave(&tctx->task_lock, flags);
@@ -2000,7 +1997,7 @@ static int io_req_task_work_add(struct io_kiocb *req)
 	spin_unlock_irqrestore(&tctx->task_lock, flags);
 
 	/* task_work already pending, we're done */
-	if (test_bit(0, &tctx->task_state) ||
+	if (likely(test_bit(0, &tctx->task_state)) ||
 	    test_and_set_bit(0, &tctx->task_state))
 		return 0;
 
@@ -2011,8 +2008,7 @@ static int io_req_task_work_add(struct io_kiocb *req)
 	 * will do the job.
 	 */
 	notify = (req->ctx->flags & IORING_SETUP_SQPOLL) ? TWA_NONE : TWA_SIGNAL;
-
-	if (!task_work_add(tsk, &tctx->task_work, notify)) {
+	if (likely(!task_work_add(tsk, &tctx->task_work, notify))) {
 		wake_up_process(tsk);
 		return 0;
 	}
-- 
2.32.0


  parent reply	other threads:[~2021-06-30 20:54 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-30 20:54 [PATCH 5.14 0/3] fallback fix and task_work cleanup Pavel Begunkov
2021-06-30 20:54 ` [PATCH 1/3] io_uring: fix stuck fallback reqs Pavel Begunkov
2021-06-30 20:54 ` [PATCH 2/3] io_uring: simplify task_work func Pavel Begunkov
2021-06-30 20:54 ` Pavel Begunkov [this message]
2021-06-30 21:17   ` [PATCH 3/3] io_uring: tweak io_req_task_work_add Jens Axboe
2021-06-30 21:19     ` Pavel Begunkov
2021-06-30 21:22       ` Jens Axboe
2021-06-30 21:38         ` Pavel Begunkov
2021-06-30 21:45           ` Jens Axboe
2021-06-30 21:56             ` Jens Axboe
2021-06-30 22:04               ` Pavel Begunkov
2021-06-30 22:10               ` Pavel Begunkov
2021-06-30 22:11                 ` Jens Axboe
2021-06-30 22:53                   ` Pavel Begunkov
2021-06-30 21:57             ` Pavel Begunkov
2021-06-30 21:57               ` Jens Axboe
2021-06-30 21:18 ` [PATCH 5.14 0/3] fallback fix and task_work cleanup Jens Axboe
2021-06-30 21:20   ` Pavel Begunkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=24b575ea075ae923992e9ce86b61e8b51629fd29.1625086418.git.asml.silence@gmail.com \
    [email protected] \
    [email protected] \
    [email protected] \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox