aboutsummaryrefslogtreecommitdiffstats
path: root/fs/io_uring.c
diff options
context:
space:
mode:
authorPavel Begunkov <asml.silence@gmail.com>2020-11-20 15:50:50 +0000
committerJens Axboe <axboe@kernel.dk>2020-12-09 12:04:01 -0700
commit6e1271e60c1d5e822fd1a32a56d52d9ae1823e62 (patch)
tree499ef5d3dfac0f37a3742e718f4cb5e672ba2563 /fs/io_uring.c
parentio_uring: check kthread stopped flag when sq thread is unparked (diff)
downloadlinux-dev-6e1271e60c1d5e822fd1a32a56d52d9ae1823e62.tar.xz
linux-dev-6e1271e60c1d5e822fd1a32a56d52d9ae1823e62.zip
io_uring: change submit file state invariant
Keep submit state invariant of whether there are file refs left based on state->nr_refs instead of (state->file==NULL), and always check against the first one. It's easier to track and allows to remove 1 if. It also automatically leaves struct submit_state in a consistent state after io_submit_state_end(), that's not used yet but nice. btw rename has_refs to file_refs for more clarity. Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'fs/io_uring.c')
-rw-r--r--fs/io_uring.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/fs/io_uring.c b/fs/io_uring.c
index 6f18b5f27404..a83593cadcc9 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -762,7 +762,7 @@ struct io_submit_state {
*/
struct file *file;
unsigned int fd;
- unsigned int has_refs;
+ unsigned int file_refs;
unsigned int ios_left;
};
@@ -2756,16 +2756,15 @@ static void io_iopoll_req_issued(struct io_kiocb *req, bool in_async)
wake_up(&ctx->sq_data->wait);
}
-static void __io_state_file_put(struct io_submit_state *state)
+static inline void __io_state_file_put(struct io_submit_state *state)
{
- if (state->has_refs)
- fput_many(state->file, state->has_refs);
- state->file = NULL;
+ fput_many(state->file, state->file_refs);
+ state->file_refs = 0;
}
static inline void io_state_file_put(struct io_submit_state *state)
{
- if (state->file)
+ if (state->file_refs)
__io_state_file_put(state);
}
@@ -2779,19 +2778,19 @@ static struct file *__io_file_get(struct io_submit_state *state, int fd)
if (!state)
return fget(fd);
- if (state->file) {
+ if (state->file_refs) {
if (state->fd == fd) {
- state->has_refs--;
+ state->file_refs--;
return state->file;
}
__io_state_file_put(state);
}
state->file = fget_many(fd, state->ios_left);
- if (!state->file)
+ if (unlikely(!state->file))
return NULL;
state->fd = fd;
- state->has_refs = state->ios_left - 1;
+ state->file_refs = state->ios_left - 1;
return state->file;
}
@@ -6601,7 +6600,7 @@ static void io_submit_state_start(struct io_submit_state *state,
INIT_LIST_HEAD(&state->comp.list);
state->comp.ctx = ctx;
state->free_reqs = 0;
- state->file = NULL;
+ state->file_refs = 0;
state->ios_left = max_ios;
}