public inbox for [email protected]
 help / color / mirror / Atom feed
* [PATCH] io-uring: futex: cache io_futex_data than kfree
@ 2025-01-23 10:50 Sidong Yang
  2025-01-23 13:36 ` Jens Axboe
  0 siblings, 1 reply; 5+ messages in thread
From: Sidong Yang @ 2025-01-23 10:50 UTC (permalink / raw)
  To: io-uring; +Cc: Sidong Yang

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 <[email protected]>
---
 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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-01-24 15:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-23 10:50 [PATCH] io-uring: futex: cache io_futex_data than kfree Sidong Yang
2025-01-23 13:36 ` Jens Axboe
2025-01-24  1:15   ` Sidong Yang
2025-01-24 13:37     ` Jens Axboe
2025-01-24 15:08       ` Sidong Yang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox