From: Lu Hongfei <luhongfei@vivo.com>
To: Jens Axboe <axboe@kernel.dk>,
Pavel Begunkov <asml.silence@gmail.com>,
io-uring@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: opensource.kernel@vivo.com, luhongfei@vivo.com
Subject: [PATCH] io_uring: A new function has been defined to make get/put exist in pairs
Date: Thu, 6 Jul 2023 17:32:08 +0800 [thread overview]
Message-ID: <20230706093208.6072-1-luhongfei@vivo.com> (raw)
A new function called io_put_task_refs has been defined for pairing
with io_get_task_refs.
In io_submit_sqes(), when req is not fully sent(i.e. left != 0), it is
necessary to call the io_put_task_refs() to recover the current process's
cached_refs and pair it with the io_get_task_refs(), which is easy to
understand and looks more regular.
Signed-off-by: Lu Hongfei <luhongfei@vivo.com>
---
io_uring/io_uring.c | 2 +-
io_uring/io_uring.h | 5 +++++
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index e8096d502a7c..43844bc2bc62 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -2421,7 +2421,7 @@ int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr)
/* try again if it submitted nothing and can't allocate a req */
if (!ret && io_req_cache_empty(ctx))
ret = -EAGAIN;
- current->io_uring->cached_refs += left;
+ io_put_task_refs(left);
}
io_submit_state_end(ctx);
diff --git a/io_uring/io_uring.h b/io_uring/io_uring.h
index d3606d30cf6f..bf01c56322c9 100644
--- a/io_uring/io_uring.h
+++ b/io_uring/io_uring.h
@@ -342,6 +342,11 @@ static inline void io_get_task_refs(int nr)
io_task_refs_refill(tctx);
}
+static inline void io_put_task_refs(int nr)
+{
+ current->io_uring->cached_refs += nr;
+}
+
static inline bool io_req_cache_empty(struct io_ring_ctx *ctx)
{
return !ctx->submit_state.free_list.next;
--
2.39.0
next reply other threads:[~2023-07-06 9:32 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-06 9:32 Lu Hongfei [this message]
2023-07-06 14:05 ` [PATCH] io_uring: A new function has been defined to make get/put exist in pairs 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=20230706093208.6072-1-luhongfei@vivo.com \
--to=luhongfei@vivo.com \
--cc=asml.silence@gmail.com \
--cc=axboe@kernel.dk \
--cc=io-uring@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=opensource.kernel@vivo.com \
/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).