From: Pavel Begunkov <asml.silence@gmail.com>
To: io-uring@vger.kernel.org
Cc: asml.silence@gmail.com, axboe@kernel.dk
Subject: [PATCH liburing 1/2] src/queue: Add support for non circular SQ
Date: Wed, 21 Jan 2026 22:23:21 +0000 [thread overview]
Message-ID: <494ec4d2a87b5e57ca8d006bc36f04cb98d2dc8a.1769034107.git.asml.silence@gmail.com> (raw)
In-Reply-To: <cover.1769034107.git.asml.silence@gmail.com>
With IORING_SETUP_SQ_REWIND, the kernel doesn't use the SQ headers and
always submits SQEs with indices in a range [0, nr_submit), where
nr_submit is the syscall argument. Add liburing support for that.
The head is now kept to be 0, and tail effectively tracks the number of
entries to submit, which matches the normal formula
to_submit = (tail - head) mod N
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
src/include/liburing.h | 5 ++++-
src/include/liburing/io_uring.h | 12 ++++++++++++
src/queue.c | 5 +++++
3 files changed, 21 insertions(+), 1 deletion(-)
diff --git a/src/include/liburing.h b/src/include/liburing.h
index 8a882a08..4758c955 100644
--- a/src/include/liburing.h
+++ b/src/include/liburing.h
@@ -1918,9 +1918,12 @@ IOURINGINLINE struct io_uring_sqe *_io_uring_get_sqe(struct io_uring *ring)
LIBURING_NOEXCEPT
{
struct io_uring_sq *sq = &ring->sq;
- unsigned head = io_uring_load_sq_head(ring), tail = sq->sqe_tail;
+ unsigned head = 0, tail = sq->sqe_tail;
struct io_uring_sqe *sqe;
+ if (!(ring->flags & IORING_SETUP_SQ_REWIND))
+ head = io_uring_load_sq_head(ring);
+
if (tail - head >= sq->ring_entries)
return NULL;
diff --git a/src/include/liburing/io_uring.h b/src/include/liburing/io_uring.h
index 8e8b8e6a..2696b43d 100644
--- a/src/include/liburing/io_uring.h
+++ b/src/include/liburing/io_uring.h
@@ -233,6 +233,18 @@ enum io_uring_sqe_flags_bit {
*/
#define IORING_SETUP_SQE_MIXED (1U << 19)
+/*
+ * When set, io_uring ignores SQ head and tail and fetches SQEs to submit
+ * starting from index 0 instead from the index stored in the head pointer.
+ * IOW, the user should place all SQE at the beginning of the SQ memory
+ * before issuing a submission syscall.
+ *
+ * It requires IORING_SETUP_NO_SQARRAY and is incompatible with
+ * IORING_SETUP_SQPOLL. The user must also never change the SQ head and tail
+ * values and keep it set to 0. Any other value is undefined behaviour.
+ */
+#define IORING_SETUP_SQ_REWIND (1U << 20)
+
enum io_uring_op {
IORING_OP_NOP,
IORING_OP_READV,
diff --git a/src/queue.c b/src/queue.c
index c8ada7e8..00995ace 100644
--- a/src/queue.c
+++ b/src/queue.c
@@ -205,6 +205,11 @@ static unsigned __io_uring_flush_sq(struct io_uring *ring)
struct io_uring_sq *sq = &ring->sq;
unsigned tail = sq->sqe_tail;
+ if (ring->flags & IORING_SETUP_SQ_REWIND) {
+ sq->sqe_tail = 0;
+ return tail;
+ }
+
if (sq->sqe_head != tail) {
sq->sqe_head = tail;
/*
--
2.52.0
next prev parent reply other threads:[~2026-01-21 22:23 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-21 22:23 [PATCH liburing 0/2] Add support for IORING_SETUP_SQ_REWIND Pavel Begunkov
2026-01-21 22:23 ` Pavel Begunkov [this message]
2026-01-21 22:23 ` [PATCH liburing 2/2] tests: add SETUP_SQ_REWIND tests Pavel Begunkov
2026-01-22 22:59 ` [PATCH liburing 0/2] Add support for IORING_SETUP_SQ_REWIND Jens Axboe
2026-01-22 23:05 ` Jens Axboe
2026-01-23 14:14 ` Pavel Begunkov
2026-01-23 19:04 ` Jens Axboe
2026-01-24 10:44 ` Pavel Begunkov
2026-01-24 15:12 ` Jens Axboe
2026-01-24 16:37 ` Pavel Begunkov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=494ec4d2a87b5e57ca8d006bc36f04cb98d2dc8a.1769034107.git.asml.silence@gmail.com \
--to=asml.silence@gmail.com \
--cc=axboe@kernel.dk \
--cc=io-uring@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox