From 3a0a690235923b838390500fd46edc23bed092e0 Mon Sep 17 00:00:00 2001 From: Pavel Begunkov Date: Tue, 20 Apr 2021 12:03:31 +0100 Subject: [PATCH] io_uring: move inflight un-tracking into cleanup REQ_F_INFLIGHT deaccounting doesn't do any spinlocking or resource freeing anymore, so it's safe to move it into the normal cleanup flow, i.e. into io_clean_op(), so making it cleaner. Also move io_req_needs_clean() to be first in io_dismantle_req() so it doesn't reload req->flags. Signed-off-by: Pavel Begunkov Link: https://lore.kernel.org/r/90653a3a5de4107e3a00536fa4c2ea5f2c38a4ac.1618916549.git.asml.silence@gmail.com Signed-off-by: Jens Axboe --- fs/io_uring.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index 58f12bfbfb44..34c1864eee21 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -1601,7 +1601,7 @@ static void io_req_complete_post(struct io_kiocb *req, long res, static inline bool io_req_needs_clean(struct io_kiocb *req) { return req->flags & (REQ_F_BUFFER_SELECTED | REQ_F_NEED_CLEANUP | - REQ_F_POLLED); + REQ_F_POLLED | REQ_F_INFLIGHT); } static void io_req_complete_state(struct io_kiocb *req, long res, @@ -1717,17 +1717,10 @@ static void io_dismantle_req(struct io_kiocb *req) { unsigned int flags = req->flags; + if (io_req_needs_clean(req)) + io_clean_op(req); if (!(flags & REQ_F_FIXED_FILE)) io_put_file(req->file); - if (io_req_needs_clean(req) || (req->flags & REQ_F_INFLIGHT)) { - io_clean_op(req); - if (req->flags & REQ_F_INFLIGHT) { - struct io_uring_task *tctx = req->task->io_uring; - - atomic_dec(&tctx->inflight_tracked); - req->flags &= ~REQ_F_INFLIGHT; - } - } if (req->fixed_rsrc_refs) percpu_ref_put(req->fixed_rsrc_refs); if (req->async_data) @@ -6057,6 +6050,12 @@ static void io_clean_op(struct io_kiocb *req) kfree(req->apoll); req->apoll = NULL; } + if (req->flags & REQ_F_INFLIGHT) { + struct io_uring_task *tctx = req->task->io_uring; + + atomic_dec(&tctx->inflight_tracked); + req->flags &= ~REQ_F_INFLIGHT; + } } static int io_issue_sqe(struct io_kiocb *req, unsigned int issue_flags)