Skip to content

Commit 31af27c

Browse files
isilenceaxboe
authored andcommitted
io_uring: don't count rqs failed after current one
When checking for draining with __req_need_defer(), it tries to match how many requests were sent before a current one with number of already completed. Dropped SQEs are included in req->sequence, and they won't ever appear in CQ. To compensate for that, __req_need_defer() substracts ctx->cached_sq_dropped. However, what it should really use is number of SQEs dropped __before__ the current one. In other words, any submitted request shouldn't shouldn't affect dequeueing from the drain queue of previously submitted ones. Instead of saving proper ctx->cached_sq_dropped in each request, substract from req->sequence it at initialisation, so it includes number of properly submitted requests. note: it also changes behaviour of timeouts, but 1. it's already diverge from the description because of using SQ 2. the description is ambiguous regarding dropped SQEs Signed-off-by: Pavel Begunkov <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent b55ce73 commit 31af27c

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

fs/io_uring.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -957,8 +957,8 @@ static inline bool __req_need_defer(struct io_kiocb *req)
957957
{
958958
struct io_ring_ctx *ctx = req->ctx;
959959

960-
return req->sequence != ctx->cached_cq_tail + ctx->cached_sq_dropped
961-
+ atomic_read(&ctx->cached_cq_overflow);
960+
return req->sequence != ctx->cached_cq_tail
961+
+ atomic_read(&ctx->cached_cq_overflow);
962962
}
963963

964964
static inline bool req_need_defer(struct io_kiocb *req)
@@ -5801,7 +5801,7 @@ static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req,
58015801
* it can be used to mark the position of the first IO in the
58025802
* link list.
58035803
*/
5804-
req->sequence = ctx->cached_sq_head;
5804+
req->sequence = ctx->cached_sq_head - ctx->cached_sq_dropped;
58055805
req->opcode = READ_ONCE(sqe->opcode);
58065806
req->user_data = READ_ONCE(sqe->user_data);
58075807
req->io = NULL;

0 commit comments

Comments
 (0)