From: Pavel Begunkov <[email protected]>
To: Jens Axboe <[email protected]>,
[email protected], [email protected]
Subject: [PATCH 5/5] io_uring: batch put_task_struct()
Date: Tue, 14 Jul 2020 02:41:56 +0300 [thread overview]
Message-ID: <15a2db7fa57e5e78ed2677d21bb70dd3d32f8deb.1594683622.git.asml.silence@gmail.com> (raw)
In-Reply-To: <[email protected]>
Each put_task_struct() is an atomic_dec. Do that in batches.
Tested io_uring-bench(iopoll,QD=128) with a custom nullblk, where
added ->iopoll() is not optimised at all:
before: 529504 IOPS
after: 538415 IOPS
diff: ~1.8%
Signed-off-by: Pavel Begunkov <[email protected]>
---
fs/io_uring.c | 28 ++++++++++++++++++++++++++--
1 file changed, 26 insertions(+), 2 deletions(-)
diff --git a/fs/io_uring.c b/fs/io_uring.c
index 6f767781351f..3216cc00061b 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -1761,8 +1761,18 @@ static void io_free_req(struct io_kiocb *req)
struct req_batch {
void *reqs[IO_IOPOLL_BATCH];
int to_free;
+
+ struct task_struct *task;
+ int task_refs;
};
+static void io_init_req_batch(struct req_batch *rb)
+{
+ rb->to_free = 0;
+ rb->task_refs = 0;
+ rb->task = NULL;
+}
+
static void __io_req_free_batch_flush(struct io_ring_ctx *ctx,
struct req_batch *rb)
{
@@ -1776,6 +1786,10 @@ static void io_req_free_batch_finish(struct io_ring_ctx *ctx,
{
if (rb->to_free)
__io_req_free_batch_flush(ctx, rb);
+ if (rb->task) {
+ put_task_struct_many(rb->task, rb->task_refs);
+ rb->task = NULL;
+ }
}
static void io_req_free_batch(struct req_batch *rb, struct io_kiocb *req)
@@ -1787,6 +1801,16 @@ static void io_req_free_batch(struct req_batch *rb, struct io_kiocb *req)
if (req->flags & REQ_F_LINK_HEAD)
io_queue_next(req);
+ if (req->flags & REQ_F_TASK_PINNED) {
+ if (req->task != rb->task && rb->task) {
+ put_task_struct_many(rb->task, rb->task_refs);
+ rb->task = req->task;
+ rb->task_refs = 0;
+ }
+ rb->task_refs++;
+ req->flags &= ~REQ_F_TASK_PINNED;
+ }
+
io_dismantle_req(req);
rb->reqs[rb->to_free++] = req;
if (unlikely(rb->to_free == ARRAY_SIZE(rb->reqs)))
@@ -1809,7 +1833,7 @@ static void io_submit_flush_completions(struct io_comp_state *cs)
spin_unlock_irq(&ctx->completion_lock);
io_cqring_ev_posted(ctx);
- rb.to_free = 0;
+ io_init_req_batch(&rb);
for (i = 0; i < nr; ++i) {
req = cs->reqs[i];
if (refcount_dec_and_test(&req->refs))
@@ -1973,7 +1997,7 @@ static void io_iopoll_complete(struct io_ring_ctx *ctx, unsigned int *nr_events,
/* order with ->result store in io_complete_rw_iopoll() */
smp_rmb();
- rb.to_free = 0;
+ io_init_req_batch(&rb);
while (!list_empty(done)) {
int cflags = 0;
--
2.24.0
next prev parent reply other threads:[~2020-07-13 23:44 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-13 23:41 [PATCH 0/5] batch completion + freeing improvements Pavel Begunkov
2020-07-13 23:41 ` [PATCH 1/5] io_uring: move io_req_complete() definition Pavel Begunkov
2020-07-13 23:41 ` [PATCH 2/5] io_uring: replace list with array for compl batch Pavel Begunkov
2020-07-13 23:41 ` [PATCH 3/5] io_uring: batch free in batched completion Pavel Begunkov
2020-07-13 23:41 ` [PATCH 4/5] tasks: add put_task_struct_many() Pavel Begunkov
2020-07-13 23:41 ` Pavel Begunkov [this message]
2020-07-14 1:08 ` [PATCH 0/5] batch completion + freeing improvements Jens Axboe
2020-07-14 7:15 ` Pavel Begunkov
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=15a2db7fa57e5e78ed2677d21bb70dd3d32f8deb.1594683622.git.asml.silence@gmail.com \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
/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