Skip to contentSkip to conversation

io_uring/futex: Recycle ifd on failure

PATCH In review Gabriel Krisman Bertazi 2 participants 4 messages Sep 2 io_uring

lore
Share & tools
lore
#0 lore raw

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
index eaee14242a3a..6389bd2f0399 100644
@@ -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
maintainer
#1 lore raw
Quoted 3 lines · Gabriel Krisman Bertazi

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.

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
#2 lore raw
Quoted 10 lines · Jens Axboe
Quoted 3 lines · Gabriel Krisman Bertazi

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.

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
#3 lore raw
In reply to Jens Axboe
Quoted 10 lines · Jens Axboe
Quoted 3 lines · Gabriel Krisman Bertazi

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.

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