io_uring/futex: Recycle ifd on failure
PATCH 1/1 io_uring/futex: Recycle ifd on failure
The failure path doesn't recycle the ifd on FUTEX_WAIT for no good reason. If we move the free above done_unlock, we are even already holding the submit lock. Recycle it.
--- io_uring/futex.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)
io_uring/futex.c +10 -8
@@ -321,20 +321,22 @@ int io_futex_wait(struct io_kiocb *req, unsigned int issue_flags) ret =futex_wait_setup (iof->uaddr, iof->futex_val, iof->futex_flags, &ifd->q,NULL ,NULL ); -if (!ret) { -hlist_add_head (&req->hash_node, &ctx->futex_list); -io_ring_submit_unlock (ctx, issue_flags); +if (ret) + goto free_async; -return IOU_ISSUE_SKIP_COMPLETE ; - } +hlist_add_head (&req->hash_node, &ctx->futex_list); +io_ring_submit_unlock (ctx, issue_flags); +return IOU_ISSUE_SKIP_COMPLETE ; + +free_async: +io_cache_free (&ctx->futex_cache, ifd); +io_req_async_data_clear (req,0 ); done_unlock:io_ring_submit_unlock (ctx, issue_flags); done: -if (ret <0 ) -req_set_fail (req); +req_set_fail (req);io_req_set_res (req, ret,0 ); -io_req_async_data_free (req);return IOU_COMPLETE ; }
Signature · 1 line
2.55.0
Jens Axboe
maintainerQuoted 3 lines · Gabriel Krisman Bertazi
The failure path doesn't recycle the ifd on
FUTEX_WAITfor no good reason. If we move the free abovedone_unlock, we are even already holding the submit lock. Recycle it.
Does it matter? For performance, it should not, unless you have a benchmark that deliberately ends up with futex_wait_setup() failing. Any normal/fast path will have all of these succeed.
Is the motivation just to unify the cleanup, or..?
Signature · 1 line
Jens Axboe
Quoted 10 lines · Jens Axboe
Quoted 3 lines · Gabriel Krisman Bertazi
The failure path doesn't recycle the ifd on
FUTEX_WAITfor no good reason. If we move the free abovedone_unlock, we are even already holding the submit lock. Recycle it.Does it matter? For performance, it should not, unless you have a benchmark that deliberately ends up with
futex_wait_setup()failing. Any normal/fast path will have all of these succeed.Is the motivation just to unify the cleanup, or..?
Because recycling is good for the world :)
It is a cleanup. A todo in my list is recycling objects as much as we can. for instance, in the generic cleanup path we could be recycling for various objects. I'll send it as a larger series.
Signature · 1 line
Gabriel Krisman Bertazi
Quoted 10 lines · Jens Axboe
Quoted 3 lines · Gabriel Krisman Bertazi
The failure path doesn't recycle the ifd on
FUTEX_WAITfor no good reason. If we move the free abovedone_unlock, we are even already holding the submit lock. Recycle it.Does it matter? For performance, it should not, unless you have a benchmark that deliberately ends up with
futex_wait_setup()failing. Any normal/fast path will have all of these succeed.Is the motivation just to unify the cleanup, or..?
Because recycling is good for the world :)
It is a cleanup. A todo in my list is recycling objects as much as we can. for instance, in the generic cleanup path we could be recycling for various objects. I'll send those as part of a larger series.
Signature · 1 line
Gabriel Krisman Bertazi