Skip to content

Commit 3a0a690

Browse files
isilenceaxboe
authored andcommitted
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 <[email protected]> Link: https://lore.kernel.org/r/90653a3a5de4107e3a00536fa4c2ea5f2c38a4ac.1618916549.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <[email protected]>
1 parent eb37267 commit 3a0a690

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

fs/io_uring.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1601,7 +1601,7 @@ static void io_req_complete_post(struct io_kiocb *req, long res,
16011601
static inline bool io_req_needs_clean(struct io_kiocb *req)
16021602
{
16031603
return req->flags & (REQ_F_BUFFER_SELECTED | REQ_F_NEED_CLEANUP |
1604-
REQ_F_POLLED);
1604+
REQ_F_POLLED | REQ_F_INFLIGHT);
16051605
}
16061606

16071607
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)
17171717
{
17181718
unsigned int flags = req->flags;
17191719

1720+
if (io_req_needs_clean(req))
1721+
io_clean_op(req);
17201722
if (!(flags & REQ_F_FIXED_FILE))
17211723
io_put_file(req->file);
1722-
if (io_req_needs_clean(req) || (req->flags & REQ_F_INFLIGHT)) {
1723-
io_clean_op(req);
1724-
if (req->flags & REQ_F_INFLIGHT) {
1725-
struct io_uring_task *tctx = req->task->io_uring;
1726-
1727-
atomic_dec(&tctx->inflight_tracked);
1728-
req->flags &= ~REQ_F_INFLIGHT;
1729-
}
1730-
}
17311724
if (req->fixed_rsrc_refs)
17321725
percpu_ref_put(req->fixed_rsrc_refs);
17331726
if (req->async_data)
@@ -6057,6 +6050,12 @@ static void io_clean_op(struct io_kiocb *req)
60576050
kfree(req->apoll);
60586051
req->apoll = NULL;
60596052
}
6053+
if (req->flags & REQ_F_INFLIGHT) {
6054+
struct io_uring_task *tctx = req->task->io_uring;
6055+
6056+
atomic_dec(&tctx->inflight_tracked);
6057+
req->flags &= ~REQ_F_INFLIGHT;
6058+
}
60606059
}
60616060

60626061
static int io_issue_sqe(struct io_kiocb *req, unsigned int issue_flags)

0 commit comments

Comments
 (0)