* [PATCH v4] io_uring/futex: Factor out common free logic into io_free_ifd()
@ 2025-01-25 23:28 Sidong Yang
2025-01-26 2:06 ` lizetao
0 siblings, 1 reply; 2+ messages in thread
From: Sidong Yang @ 2025-01-25 23:28 UTC (permalink / raw)
To: io-uring, Jens Axboe, lizetao; +Cc: Sidong Yang
This patch introduces io_free_ifd() that try to cache or free
io_futex_data. It could be used for completion. It also could be used
for error path in io_futex_wait(). Old code just release the ifd but it
could be cached.
Signed-off-by: Sidong Yang <[email protected]>
---
v2: use io_free_ifd() for completion
v3: format, inline, remove reduntant init.
v4: inline static -> static inline format
---
io_uring/futex.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/io_uring/futex.c b/io_uring/futex.c
index e29662f039e1..6d724435cf23 100644
--- a/io_uring/futex.c
+++ b/io_uring/futex.c
@@ -44,6 +44,12 @@ void io_futex_cache_free(struct io_ring_ctx *ctx)
io_alloc_cache_free(&ctx->futex_cache, kfree);
}
+static inline 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);
+}
+
static void __io_futex_complete(struct io_kiocb *req, struct io_tw_state *ts)
{
req->async_data = NULL;
@@ -57,8 +63,7 @@ static void io_futex_complete(struct io_kiocb *req, struct io_tw_state *ts)
struct io_ring_ctx *ctx = req->ctx;
io_tw_lock(ctx, ts);
- if (!io_alloc_cache_put(&ctx->futex_cache, ifd))
- kfree(ifd);
+ io_free_ifd(ctx, ifd);
__io_futex_complete(req, ts);
}
@@ -321,7 +326,7 @@ int io_futex_wait(struct io_kiocb *req, unsigned int issue_flags)
{
struct io_futex *iof = io_kiocb_to_cmd(req, struct io_futex);
struct io_ring_ctx *ctx = req->ctx;
- struct io_futex_data *ifd = NULL;
+ struct io_futex_data *ifd;
struct futex_hash_bucket *hb;
int ret;
@@ -353,13 +358,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] 2+ messages in thread
* RE: [PATCH v4] io_uring/futex: Factor out common free logic into io_free_ifd()
2025-01-25 23:28 [PATCH v4] io_uring/futex: Factor out common free logic into io_free_ifd() Sidong Yang
@ 2025-01-26 2:06 ` lizetao
0 siblings, 0 replies; 2+ messages in thread
From: lizetao @ 2025-01-26 2:06 UTC (permalink / raw)
To: Sidong Yang; +Cc: io-uring, Jens Axboe
> -----Original Message-----
> From: Sidong Yang <[email protected]>
> Sent: Sunday, January 26, 2025 7:28 AM
> To: io-uring <[email protected]>; Jens Axboe <[email protected]>; lizetao
> <[email protected]>
> Cc: Sidong Yang <[email protected]>
> Subject: [PATCH v4] io_uring/futex: Factor out common free logic into
> io_free_ifd()
>
> This patch introduces io_free_ifd() that try to cache or free io_futex_data. It
> could be used for completion. It also could be used for error path in
> io_futex_wait(). Old code just release the ifd but it could be cached.
>
> Signed-off-by: Sidong Yang <[email protected]>
> ---
> v2: use io_free_ifd() for completion
> v3: format, inline, remove reduntant init.
> v4: inline static -> static inline format
> ---
> io_uring/futex.c | 13 +++++++++----
> 1 file changed, 9 insertions(+), 4 deletions(-)
>
> diff --git a/io_uring/futex.c b/io_uring/futex.c index
> e29662f039e1..6d724435cf23 100644
> --- a/io_uring/futex.c
> +++ b/io_uring/futex.c
> @@ -44,6 +44,12 @@ void io_futex_cache_free(struct io_ring_ctx *ctx)
> io_alloc_cache_free(&ctx->futex_cache, kfree); }
>
> +static inline 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);
> +}
> +
> static void __io_futex_complete(struct io_kiocb *req, struct io_tw_state *ts)
> {
> req->async_data = NULL;
> @@ -57,8 +63,7 @@ static void io_futex_complete(struct io_kiocb *req, struct
> io_tw_state *ts)
> struct io_ring_ctx *ctx = req->ctx;
>
> io_tw_lock(ctx, ts);
> - if (!io_alloc_cache_put(&ctx->futex_cache, ifd))
> - kfree(ifd);
> + io_free_ifd(ctx, ifd);
> __io_futex_complete(req, ts);
> }
>
> @@ -321,7 +326,7 @@ int io_futex_wait(struct io_kiocb *req, unsigned int
> issue_flags) {
> struct io_futex *iof = io_kiocb_to_cmd(req, struct io_futex);
> struct io_ring_ctx *ctx = req->ctx;
> - struct io_futex_data *ifd = NULL;
> + struct io_futex_data *ifd;
> struct futex_hash_bucket *hb;
> int ret;
>
> @@ -353,13 +358,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
Reviewed-by: Li Zetao <[email protected]>
--
Li Zetao
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-01-26 2:06 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-25 23:28 [PATCH v4] io_uring/futex: Factor out common free logic into io_free_ifd() Sidong Yang
2025-01-26 2:06 ` lizetao
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox