Skip to content

queue: add opt-in requeue helper for SQ_REWIND - #1626

Open
carrerasdarren-cell wants to merge 1 commit into
axboe:masterfrom
carrerasdarren-cell:fix/sq-rewind-partial-submit
Open

queue: add opt-in requeue helper for SQ_REWIND#1626
carrerasdarren-cell wants to merge 1 commit into
axboe:masterfrom
carrerasdarren-cell:fix/sq-rewind-partial-submit

Conversation

@carrerasdarren-cell

@carrerasdarren-cell carrerasdarren-cell commented Aug 5, 2026

Copy link
Copy Markdown

IORING_SETUP_SQ_REWIND clears liburing's local SQ tail before entering the kernel. If a submission is short, the caller may either abandon the unconsumed entries or choose to retry them. Retrying requires relocating those entries to the beginning of the SQ.

This adds io_uring_sq_requeue() as an explicit opt-in helper. The application records io_uring_sq_ready() before submission, then passes that count and the submission return value to the helper before acquiring any new SQEs.

Submission-and-wait paths also stop internally resubmitting an unrelocated SQ_REWIND remainder. Without that guard, a short timed submission can submit already-consumed slots again.

The regression covers:

  • the default abandon policy and explicit requeue policy;
  • ordinary and fixed 128-byte SQEs;
  • partial and fully failed submissions;
  • timed submission with duplicate-completion detection;
  • a pure wait with locally pending work; and
  • the regular circular-ring behavior as a control.

Validation:

  • Linux 7.0.0-28-generic
  • normal GCC build and FFI symbol check
  • ASan/UBSan build
  • focused regression plus nine adjacent submission/SQ tests in both builds

@krisman

krisman commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

I don't think this should be done by default on a short submit. We might not want to requeue, in which case relocating the requests would be a waste of time. Perhaps the relocation could be exposed as a helper in io_uring and let userspace call it if they want.

A short IORING_SETUP_SQ_REWIND submission leaves any unconsumed
entries after the returned count, while liburing resets its local tail
before entering the kernel. Retrying those entries requires moving them
back to index zero.

Add io_uring_sq_requeue() so applications can opt into that relocation
after a short or failed submit. Keep the default short-submit policy
unchanged. Stop submission-and-wait helpers from internally resubmitting
an unrelocated SQ_REWIND remainder, which would otherwise submit
already-consumed slots again.

Cover the default and opt-in policies, ordinary and fixed 128-byte SQEs,
timed submission without duplicate completions, failed submission, and
the regular-ring control.

Fixes: c22129c ("src/queue: Add support for non circular SQ")
Signed-off-by: Darren Carreras <283775510+carrerasdarren-cell@users.noreply.github.com>
@carrerasdarren-cell
carrerasdarren-cell force-pushed the fix/sq-rewind-partial-submit branch from a6800c4 to 11051b1 Compare August 5, 2026 21:07
@carrerasdarren-cell carrerasdarren-cell changed the title queue: preserve unconsumed SQEs with SQ_REWIND queue: add opt-in requeue helper for SQ_REWIND Aug 5, 2026
@carrerasdarren-cell

Copy link
Copy Markdown
Author

Agreed. I updated the patch so a short SQ_REWIND submit is abandoned by default and added io_uring_sq_requeue() as an explicit opt-in helper.

I also stopped the submission-and-wait loop from internally submitting an unrelocated remainder, since that can resubmit the already-consumed prefix. The revised regression covers both policies, partial and failed submits, fixed 128-byte SQEs, and timed-submit duplicate detection. Normal and ASan/UBSan builds plus ten focused tests pass on Linux 7.0.

I force-pushed the revised single commit. I am happy to adjust the helper name or signature if you prefer a different API shape.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants