Skip to contentSkip to conversation

io_uring: don't free request to slab

PATCH Superseded Hao Xu 2 participants 4 messages Aug 25, 2021

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Hao Xu

author
#0 lore raw

PATCH 1/1 io_uring: don't free request to slab

It's not neccessary to free the request back to slab when we fail to get sqe, just update state->free_reqs pointer.

---
 fs/io_uring.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/io_uring.c +1 -1
index 74b606990d7e..ce66a9ce2b43 100644
@@ -6899,7 +6899,7 @@ static int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr)
 		}
 		sqe = io_get_sqe(ctx);
 		if (unlikely(!sqe)) {
-			kmem_cache_free(req_cachep, req);
+			ctx->submit_state.free_reqs++;
 			break;
 		}
 		/* will complete beyond this point, count as submitted */
Signature · 1 line
2.24.4
#1 lore raw
Quoted 2 lines · Hao Xu

It's not neccessary to free the request back to slab when we fail to get sqe, just update state->free_reqs pointer.

It's a bit hackish because depends on the request being drawn from the array in a particular way. How about returning it into state->free_list. That thing is as cold as it can get, only buggy apps can hit it.

Quoted 19 lines
---
 fs/io_uring.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/io_uring.c +1 -1
index 74b606990d7e..ce66a9ce2b43 100644
@@ -6899,7 +6899,7 @@ static int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr)
 		}
 		sqe = io_get_sqe(ctx);
 		if (unlikely(!sqe)) {
-			kmem_cache_free(req_cachep, req);
+			ctx->submit_state.free_reqs++;
 			break;
 		}
 		/* will complete beyond this point, count as submitted */
Signature · 1 line
Pavel Begunkov
author
#2 lore raw
Quoted 6 lines · Pavel Begunkov
Quoted 2 lines · Hao Xu

It's not neccessary to free the request back to slab when we fail to get sqe, just update state->free_reqs pointer.

It's a bit hackish because depends on the request being drawn from the array in a particular way. How about returning it

It seems a req is always allocated from state->reqs, so it should be ok? I actually didn't understand 'hackish' here, do you mean io_submit_sqes() shouldn't move state->free_reqs which is req caches' internal implementation?

Quoted 3 lines

into state->free_list. That thing is as cold as it can get, only buggy apps can hit it.

#3 lore raw
Quoted 11 lines · Hao Xu
Quoted 6 lines · Pavel Begunkov
Quoted 2 lines · Hao Xu

It's not neccessary to free the request back to slab when we fail to get sqe, just update state->free_reqs pointer.

It's a bit hackish because depends on the request being drawn from the array in a particular way. How about returning it

It seems a req is always allocated from state->reqs, so it should be ok? I actually didn't understand 'hackish' here, do you mean io_submit_sqes() shouldn't move state->free_reqs which is req caches' internal implementation?

I mean it uses implicit knowledge of how io_alloc_req() works, which may and actually will change. It's just always too easy to forget about that little one-off thing while changing another chunk.

To give an example, if one decides to remake it and first serve requests from state->free_list and only when it's empty look into state->reqs, it's too easy to forget opening a pretty severe vulnerability.

If there is not much profit from it comparing to the risks, I'd personally prefer to go with a safer way.

Quoted 3 lines
Quoted 3 lines

into state->free_list. That thing is as cold as it can get, only buggy apps can hit it.

Signature · 1 line
Pavel Begunkov