io-uring.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pavel Begunkov <asml.silence@gmail.com>
To: Jens Axboe <axboe@kernel.dk>, io-uring@vger.kernel.org
Subject: [PATCH 05/12] io_uring: improve submit_state.ios_left accounting
Date: Sat, 10 Oct 2020 18:34:09 +0100	[thread overview]
Message-ID: <b16b486d3eaafa271e9a7c4877d7105cd3d2f85c.1602350806.git.asml.silence@gmail.com> (raw)
In-Reply-To: <cover.1602350805.git.asml.silence@gmail.com>

state->ios_left isn't decremented for requests that don't need a file,
so it might be larger than number of SQEs left. That in some
circumstances makes us to grab more files that is needed so imposing
extra put.
Deaccount one ios_left for each request.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
 fs/io_uring.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index ffdaea55e820..250eefbe13cb 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -2581,7 +2581,6 @@ static struct file *__io_file_get(struct io_submit_state *state, int fd)
 	if (state->file) {
 		if (state->fd == fd) {
 			state->has_refs--;
-			state->ios_left--;
 			return state->file;
 		}
 		__io_state_file_put(state);
@@ -2591,8 +2590,7 @@ static struct file *__io_file_get(struct io_submit_state *state, int fd)
 		return NULL;
 
 	state->fd = fd;
-	state->ios_left--;
-	state->has_refs = state->ios_left;
+	state->has_refs = state->ios_left - 1;
 	return state->file;
 }
 
@@ -6386,7 +6384,7 @@ static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req,
 		       struct io_submit_state *state)
 {
 	unsigned int sqe_flags;
-	int id;
+	int id, ret;
 
 	req->opcode = READ_ONCE(sqe->opcode);
 	req->user_data = READ_ONCE(sqe->user_data);
@@ -6432,7 +6430,9 @@ static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req,
 	if (!io_op_defs[req->opcode].needs_file)
 		return 0;
 
-	return io_req_set_file(state, req, READ_ONCE(sqe->fd));
+	ret = io_req_set_file(state, req, READ_ONCE(sqe->fd));
+	state->ios_left--;
+	return ret;
 }
 
 static int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr)
-- 
2.24.0


  parent reply	other threads:[~2020-10-10 23:12 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-10 17:34 [PATCH 00/12] bundled cleanups and improvements Pavel Begunkov
2020-10-10 17:34 ` [PATCH 01/12] io_uring: don't io_prep_async_work() linked reqs Pavel Begunkov
2020-10-10 18:45   ` Pavel Begunkov
2020-10-10 18:49     ` Jens Axboe
2020-10-10 18:55       ` Pavel Begunkov
2020-10-10 17:34 ` [PATCH 02/12] io_uring: clean up ->files grabbing Pavel Begunkov
2020-10-10 17:34 ` [PATCH 03/12] io_uring: kill extra check in fixed io_file_get() Pavel Begunkov
2020-10-10 17:34 ` [PATCH 04/12] io_uring: simplify io_file_get() Pavel Begunkov
2020-10-10 17:34 ` Pavel Begunkov [this message]
2020-10-10 17:34 ` [PATCH 06/12] io_uring: use a separate struct for timeout_remove Pavel Begunkov
2020-10-10 17:34 ` [PATCH 07/12] io_uring: remove timeout.list after hrtimer cancel Pavel Begunkov
2020-10-10 17:34 ` [PATCH 08/12] io_uring: clean leftovers after splitting issue Pavel Begunkov
2020-10-10 17:34 ` [PATCH 09/12] io_uring: don't delay io_init_req() error check Pavel Begunkov
2020-10-10 17:34 ` [PATCH 10/12] io_uring: clean file_data access in files_register Pavel Begunkov
2020-10-10 17:34 ` [PATCH 11/12] io_uring: refactor *files_register()'s error paths Pavel Begunkov
2020-10-10 17:34 ` [PATCH 12/12] io_uring: keep a pointer ref_node in file_data Pavel Begunkov
2020-10-10 18:48 ` [PATCH 00/12] bundled cleanups and improvements Jens Axboe

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=b16b486d3eaafa271e9a7c4877d7105cd3d2f85c.1602350806.git.asml.silence@gmail.com \
    --to=asml.silence@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=io-uring@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).