Skip to content

Commit

Permalink
io_uring: move inflight un-tracking into cleanup
Browse files Browse the repository at this point in the history
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 <asml.silence@gmail.com>
Link: https://lore.kernel.org/r/90653a3a5de4107e3a00536fa4c2ea5f2c38a4ac.1618916549.git.asml.silence@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
Pavel Begunkov authored and Jens Axboe committed Apr 20, 2021
1 parent eb37267 commit 3a0a690
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions fs/io_uring.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 3a0a690

Please sign in to comment.