From: Zhengyuan Liu <liuzhengyuan@kylinos.cn>
To: axboe@kernel.dk
Cc: linux-block@vger.kernel.org
Subject: [PATCH 3/3] io_uring: use kmem_cache to alloc sqe
Date: Sat, 13 Jul 2019 12:54:54 +0800 [thread overview]
Message-ID: <20190713045454.2929-1-liuzhengyuan@kylinos.cn> (raw)
As we introduced three lists(async, defer, link), there could been
many sqe allocation. A natural idea is using kmem_cache to satisfy
the allocation just like io_kiocb does.
Signed-off-by: Zhengyuan Liu <liuzhengyuan@kylinos.cn>
---
fs/io_uring.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/fs/io_uring.c b/fs/io_uring.c
index 392cbf777f25..c325193a20bd 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -368,6 +368,7 @@ struct io_submit_state {
static void io_sq_wq_submit_work(struct work_struct *work);
static struct kmem_cache *req_cachep;
+static struct kmem_cache *sqe_cachep;
static const struct file_operations io_uring_fops;
@@ -1673,14 +1674,14 @@ static int io_req_defer(struct io_ring_ctx *ctx, struct io_kiocb *req,
if (!io_sequence_defer(ctx, req) && list_empty(&ctx->defer_list))
return 0;
- sqe_copy = kmalloc(sizeof(*sqe_copy), GFP_KERNEL);
+ sqe_copy = kmem_cache_alloc(sqe_cachep, GFP_KERNEL | __GFP_NOWARN);
if (!sqe_copy)
return -EAGAIN;
spin_lock_irq(&ctx->completion_lock);
if (!io_sequence_defer(ctx, req) && list_empty(&ctx->defer_list)) {
spin_unlock_irq(&ctx->completion_lock);
- kfree(sqe_copy);
+ kmem_cache_free(sqe_cachep, req);
return 0;
}
@@ -1845,7 +1846,7 @@ static void io_sq_wq_submit_work(struct work_struct *work)
}
/* async context always use a copy of the sqe */
- kfree(sqe);
+ kmem_cache_free(sqe_cachep, (void *)sqe);
/* req from defer and link list needn't dec async_list->cnt */
if (req->flags & (REQ_F_IO_DRAINED | REQ_F_LINKED))
@@ -1991,7 +1992,7 @@ static int io_queue_sqe(struct io_ring_ctx *ctx, struct io_kiocb *req,
if (ret == -EAGAIN && !(req->flags & REQ_F_NOWAIT)) {
struct io_uring_sqe *sqe_copy;
- sqe_copy = kmalloc(sizeof(*sqe_copy), GFP_KERNEL);
+ sqe_copy = kmem_cache_alloc(sqe_cachep, GFP_KERNEL | __GFP_NOWARN);
if (sqe_copy) {
struct async_list *list;
@@ -2076,12 +2077,13 @@ static void io_submit_sqe(struct io_ring_ctx *ctx, struct sqe_submit *s,
if (*link) {
struct io_kiocb *prev = *link;
- sqe_copy = kmemdup(s->sqe, sizeof(*sqe_copy), GFP_KERNEL);
+ sqe_copy = kmem_cache_alloc(sqe_cachep, GFP_KERNEL | __GFP_NOWARN);
if (!sqe_copy) {
ret = -EAGAIN;
goto err_req;
}
+ memcpy(sqe_copy, s->sqe, sizeof(*sqe_copy));
s->sqe = sqe_copy;
memcpy(&req->submit, s, sizeof(*s));
list_add_tail(&req->list, &prev->link_list);
@@ -3470,6 +3472,7 @@ SYSCALL_DEFINE4(io_uring_register, unsigned int, fd, unsigned int, opcode,
static int __init io_uring_init(void)
{
req_cachep = KMEM_CACHE(io_kiocb, SLAB_HWCACHE_ALIGN | SLAB_PANIC);
+ sqe_cachep = KMEM_CACHE(io_uring_sqe, SLAB_HWCACHE_ALIGN | SLAB_PANIC);
return 0;
};
__initcall(io_uring_init);
--
2.19.1
next reply other threads:[~2019-07-13 4:55 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-13 4:54 Zhengyuan Liu [this message]
2019-07-13 21:44 ` [PATCH 3/3] io_uring: use kmem_cache to alloc sqe Jens Axboe
[not found] ` <5d2bf52d.1c69fb81.af3a2.b57fSMTPIN_ADDED_BROKEN@mx.google.com>
2019-07-15 3:51 ` Jens Axboe
[not found] ` <5d2c1314.1c69fb81.ecfb1.bf96SMTPIN_ADDED_BROKEN@mx.google.com>
2019-07-15 13:52 ` 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=20190713045454.2929-1-liuzhengyuan@kylinos.cn \
--to=liuzhengyuan@kylinos.cn \
--cc=axboe@kernel.dk \
--cc=linux-block@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).