From: Jens Axboe <[email protected]>
To: [email protected]
Cc: [email protected], Jens Axboe <[email protected]>
Subject: [PATCH 4/5] io_uring: wire up bio allocation cache
Date: Tue, 10 Aug 2021 10:37:27 -0600 [thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
Initialize a bio allocation cache, and mark it as being used for
IOPOLL. We could use it for non-polled IO as well, but it'd need some
locking and probably would negate much of the win in that case.
We start with IOPOLL, as completions are locked by the ctx lock anyway.
So no further locking is needed there.
This brings an IOPOLL gen2 Optane QD=128 workload from ~3.0M IOPS to
~3.3M IOPS.
Signed-off-by: Jens Axboe <[email protected]>
---
fs/io_uring.c | 40 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 40 insertions(+)
diff --git a/fs/io_uring.c b/fs/io_uring.c
index f35b54f016f3..60316cfc712a 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -324,6 +324,10 @@ struct io_submit_state {
/* inline/task_work completion list, under ->uring_lock */
struct list_head free_list;
+#ifdef CONFIG_BLOCK
+ struct bio_alloc_cache bio_cache;
+#endif
+
/*
* File reference cache
*/
@@ -1201,6 +1205,9 @@ static struct io_ring_ctx *io_ring_ctx_alloc(struct io_uring_params *p)
init_llist_head(&ctx->rsrc_put_llist);
INIT_LIST_HEAD(&ctx->tctx_list);
INIT_LIST_HEAD(&ctx->submit_state.free_list);
+#ifdef CONFIG_BLOCK
+ bio_alloc_cache_init(&ctx->submit_state.bio_cache);
+#endif
INIT_LIST_HEAD(&ctx->locked_free_list);
INIT_DELAYED_WORK(&ctx->fallback_work, io_fallback_req_func);
return ctx;
@@ -2267,6 +2274,8 @@ static void io_iopoll_complete(struct io_ring_ctx *ctx, unsigned int *nr_events,
if (READ_ONCE(req->result) == -EAGAIN && resubmit &&
!(req->flags & REQ_F_DONT_REISSUE)) {
req->iopoll_completed = 0;
+ /* Don't use cache for async retry, not locking safe */
+ req->rw.kiocb.ki_flags &= ~IOCB_ALLOC_CACHE;
req_ref_get(req);
io_req_task_queue_reissue(req);
continue;
@@ -2684,6 +2693,31 @@ static inline __u64 ptr_to_u64(void *ptr)
return (__u64)(unsigned long)ptr;
}
+static void io_mark_alloc_cache(struct io_kiocb *req)
+{
+#ifdef CONFIG_BLOCK
+ struct kiocb *kiocb = &req->rw.kiocb;
+ struct block_device *bdev = NULL;
+
+ if (S_ISBLK(file_inode(kiocb->ki_filp)->i_mode))
+ bdev = I_BDEV(kiocb->ki_filp->f_mapping->host);
+ else if (S_ISREG(file_inode(kiocb->ki_filp)->i_mode))
+ bdev = kiocb->ki_filp->f_inode->i_sb->s_bdev;
+
+ /*
+ * If the lower level device doesn't support polled IO, then
+ * we cannot safely use the alloc cache. This really should
+ * be a failure case for polled IO...
+ */
+ if (!bdev ||
+ !test_bit(QUEUE_FLAG_POLL, &bdev_get_queue(bdev)->queue_flags))
+ return;
+
+ kiocb->ki_flags |= IOCB_ALLOC_CACHE;
+ kiocb->ki_bio_cache = &req->ctx->submit_state.bio_cache;
+#endif /* CONFIG_BLOCK */
+}
+
static int io_prep_rw(struct io_kiocb *req, const struct io_uring_sqe *sqe)
{
struct io_ring_ctx *ctx = req->ctx;
@@ -2726,6 +2760,7 @@ static int io_prep_rw(struct io_kiocb *req, const struct io_uring_sqe *sqe)
return -EOPNOTSUPP;
kiocb->ki_flags |= IOCB_HIPRI;
+ io_mark_alloc_cache(req);
kiocb->ki_complete = io_complete_rw_iopoll;
req->iopoll_completed = 0;
} else {
@@ -2792,6 +2827,8 @@ static void kiocb_done(struct kiocb *kiocb, ssize_t ret,
if (check_reissue && (req->flags & REQ_F_REISSUE)) {
req->flags &= ~REQ_F_REISSUE;
if (io_resubmit_prep(req)) {
+ /* Don't use cache for async retry, not locking safe */
+ req->rw.kiocb.ki_flags &= ~IOCB_ALLOC_CACHE;
req_ref_get(req);
io_req_task_queue_reissue(req);
} else {
@@ -8640,6 +8677,9 @@ static void io_req_caches_free(struct io_ring_ctx *ctx)
state->free_reqs = 0;
}
+#ifdef CONFIG_BLOCK
+ bio_alloc_cache_destroy(&state->bio_cache);
+#endif
io_flush_cached_locked_reqs(ctx, state);
io_req_cache_free(&state->free_list);
mutex_unlock(&ctx->uring_lock);
--
2.32.0
next prev parent reply other threads:[~2021-08-10 16:37 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-10 16:37 [PATCHSET v3 0/5] Enable bio recycling for polled IO Jens Axboe
2021-08-10 16:37 ` [PATCH 1/5] bio: add allocation cache abstraction Jens Axboe
2021-08-11 8:34 ` Christoph Hellwig
2021-08-10 16:37 ` [PATCH 2/5] io_uring: use kiocb->private to hold rw_len Jens Axboe
2021-08-11 11:40 ` Christoph Hellwig
2021-08-10 16:37 ` [PATCH 3/5] fs: add ki_bio_cache pointer to struct kiocb Jens Axboe
2021-08-10 16:37 ` Jens Axboe [this message]
2021-08-10 16:37 ` [PATCH 5/5] block: enable use of bio allocation cache Jens Axboe
2021-08-10 16:44 ` [PATCHSET v3 0/5] Enable bio recycling for polled IO Jens Axboe
2021-08-11 8:26 ` Christoph Hellwig
2021-08-11 11:13 ` Christoph Hellwig
2021-08-11 15:05 ` Jens Axboe
2021-08-11 15:08 ` Christoph Hellwig
2021-08-11 15:06 ` Ming Lei
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 \
[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