From: Sidong Yang <sidong.yang@furiosa.ai>
To: io-uring <io-uring@vger.kernel.org>
Cc: Sidong Yang <sidong.yang@furiosa.ai>
Subject: [PATCH] io-uring: futex: cache io_futex_data than kfree
Date: Thu, 23 Jan 2025 10:50:06 +0000 [thread overview]
Message-ID: <20250123105008.212752-1-sidong.yang@furiosa.ai> (raw)
If futex_wait_setup() fails in io_futex_wait(), Old code just releases
io_futex_data. This patch tries to cache io_futex_data before kfree.
Signed-off-by: Sidong Yang <sidong.yang@furiosa.ai>
---
io_uring/futex.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/io_uring/futex.c b/io_uring/futex.c
index e29662f039e1..217a38498c36 100644
--- a/io_uring/futex.c
+++ b/io_uring/futex.c
@@ -262,6 +262,13 @@ static struct io_futex_data *io_alloc_ifd(struct io_ring_ctx *ctx)
return kmalloc(sizeof(struct io_futex_data), GFP_NOWAIT);
}
+static void io_free_ifd(struct io_ring_ctx *ctx, struct io_futex_data *ifd)
+{
+ if (!io_alloc_cache_put(&ctx->futex_cache, ifd)) {
+ kfree(ifd);
+ }
+}
+
int io_futexv_wait(struct io_kiocb *req, unsigned int issue_flags)
{
struct io_futex *iof = io_kiocb_to_cmd(req, struct io_futex);
@@ -353,13 +360,13 @@ int io_futex_wait(struct io_kiocb *req, unsigned int issue_flags)
return IOU_ISSUE_SKIP_COMPLETE;
}
+ io_free_ifd(ctx, ifd);
done_unlock:
io_ring_submit_unlock(ctx, issue_flags);
done:
if (ret < 0)
req_set_fail(req);
io_req_set_res(req, ret, 0);
- kfree(ifd);
return IOU_OK;
}
--
2.43.0
next reply other threads:[~2025-01-23 10:50 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-23 10:50 Sidong Yang [this message]
2025-01-23 13:36 ` [PATCH] io-uring: futex: cache io_futex_data than kfree Jens Axboe
2025-01-24 1:15 ` Sidong Yang
2025-01-24 13:37 ` Jens Axboe
2025-01-24 15:08 ` Sidong Yang
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=20250123105008.212752-1-sidong.yang@furiosa.ai \
--to=sidong.yang@furiosa.ai \
--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